Skip to content

Commit

Permalink
feat: Introduce option to toggle opening editor as overlay
Browse files Browse the repository at this point in the history
  • Loading branch information
Xtr126 committed Mar 7, 2024
1 parent 44d1e21 commit 0790eef
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 17 deletions.
5 changes: 3 additions & 2 deletions app/src/main/java/xtr/keymapper/editor/EditorActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import xtr.keymapper.IRemoteService;
import xtr.keymapper.R;
import xtr.keymapper.TouchPointer;
import xtr.keymapper.keymap.KeymapConfig;
import xtr.keymapper.profiles.ProfileSelector;
import xtr.keymapper.server.RemoteServiceHelper;

Expand All @@ -43,7 +44,8 @@ public void onCreate(Bundle savedInstanceState) {

ProfileSelector.OnProfileSelectedListener listener = profile -> {
editor = new EditorUI(this, profile);
editor.open();
KeymapConfig keymapConfig = new KeymapConfig(this);
editor.open(keymapConfig.editorOverlay);

if (getEvent())
// Can receive key events from remote service
Expand Down Expand Up @@ -77,7 +79,6 @@ public void onServiceConnected(ComponentName className,
// service is active and a profile is selected
listener.onProfileSelected(pointerOverlay.selectedProfile);
} else {
listener.onProfileSelected(null);
// service is not active, show profile selection dialog
ProfileSelector.select(EditorActivity.this, listener);
}
Expand Down
21 changes: 19 additions & 2 deletions app/src/main/java/xtr/keymapper/editor/EditorUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import android.annotation.SuppressLint;
import android.content.Context;
import android.graphics.PixelFormat;
import android.os.Handler;
import android.os.Looper;
import android.view.KeyEvent;
Expand Down Expand Up @@ -60,6 +61,7 @@ public class EditorUI extends OnKeyEventListener.Stub {
private final Handler mHandler = new Handler(Looper.getMainLooper());
private final String profileName;
private KeymapProfile profile;
private boolean overlayOpen;

public EditorUI (Context context, String profileName) {
this.context = context;
Expand All @@ -76,17 +78,31 @@ public EditorUI (Context context, String profileName) {
setupButtons();
}

public void open() {
public void open(boolean overlayWindow) {
loadKeymap();
if (mainView.getWindowToken() == null && mainView.getParent() == null)
((EditorActivity)context).setContentView(mainView);
if (overlayWindow) openOverlayWindow();
else ((EditorActivity)context).setContentView(mainView);

if (!onHideListener.getEvent()) {
mainView.setOnKeyListener(this::onKey);
mainView.setFocusable(true);
}
}

public void openOverlayWindow() {
if (overlayOpen) removeView(mainView);
WindowManager mWindowManager = context.getSystemService(WindowManager.class);
WindowManager.LayoutParams mParams = new WindowManager.LayoutParams(
WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.MATCH_PARENT,
WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY,
WindowManager.LayoutParams.FLAG_FULLSCREEN |
WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN,
PixelFormat.TRANSLUCENT);
mWindowManager.addView(mainView, mParams);
overlayOpen = true;
}

public boolean onKey(View v, int keyCode, KeyEvent event) {
if (keyInFocus != null) {
String key = String.valueOf(event.getDisplayLabel());
Expand Down Expand Up @@ -127,6 +143,7 @@ public void hideView() {
}

private void removeView(ViewGroup view) {
if (overlayOpen) context.getSystemService(WindowManager.class).removeView(view);
view.removeAllViews();
view.invalidate();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceStat
binding.mouseAimRightClick.setChecked(keymapConfig.rightClickMouseAim);
binding.autoProfileSwitch.setChecked(keymapConfig.disableAutoProfiling);
binding.useShizuku.setChecked(keymapConfig.useShizuku);
binding.editorOverlay.setChecked(keymapConfig.editorOverlay);

loadKeyboardShortcuts();
binding.launchEditor.setOnKeyListener(this::onKey);
Expand Down Expand Up @@ -205,6 +206,7 @@ public void onDestroyView() {
keymapConfig.keyGraveMouseAim = binding.mouseAimKeyGrave.isChecked();
keymapConfig.disableAutoProfiling = binding.autoProfileSwitch.isChecked();
keymapConfig.useShizuku = binding.useShizuku.isChecked();
keymapConfig.editorOverlay = binding.editorOverlay.isChecked();

keymapConfig.dpadRadiusMultiplier = binding.sliderDpad.getValue();

Expand Down
6 changes: 5 additions & 1 deletion app/src/main/java/xtr/keymapper/keymap/KeymapConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class KeymapConfig implements Parcelable {
public Float mouseSensitivity, scrollSpeed;
public Float dpadRadiusMultiplier;
public boolean ctrlMouseWheelZoom, ctrlDragMouseGesture, rightClickMouseAim, keyGraveMouseAim;
public boolean disableAutoProfiling , useShizuku;
public boolean disableAutoProfiling, useShizuku, editorOverlay;

public int pauseResumeShortcutKey, launchEditorShortcutKey, switchProfileShortcutKey;
public int swipeDelayMs;
Expand Down Expand Up @@ -72,6 +72,7 @@ protected KeymapConfig(Parcel in) {
disableAutoProfiling = in.readByte() != 0;
touchpadInputMode = in.readString();
useShizuku = in.readByte() != 0;
editorOverlay = in.readByte() != 0;
pointerMode = in.readString();
}

Expand All @@ -95,6 +96,7 @@ private void loadSharedPrefs() {
mouseAimToggle = sharedPref.getBoolean("mouse_aim_shortcut_toggle", true);
disableAutoProfiling = sharedPref.getBoolean("disable_auto_profile", true);
useShizuku = sharedPref.getBoolean("use_shizuku", false);
editorOverlay = sharedPref.getBoolean("editor_overlay", false);

launchEditorShortcutKey = sharedPref.getInt("launch_editor_shortcut", -1);
pauseResumeShortcutKey = sharedPref.getInt("pause_resume_shortcut", -1);
Expand Down Expand Up @@ -126,6 +128,7 @@ public void applySharedPrefs() {
.putBoolean("mouse_aim_shortcut_toggle", mouseAimToggle)
.putBoolean("disable_auto_profile", disableAutoProfiling)
.putBoolean("use_shizuku", useShizuku)
.putBoolean("editor_overlay", editorOverlay)
.putInt("pause_resume_shortcut", pauseResumeShortcutKey)
.putInt("launch_editor_shortcut", launchEditorShortcutKey)
.putInt("switch_profile_shortcut", switchProfileShortcutKey)
Expand Down Expand Up @@ -180,6 +183,7 @@ public void writeToParcel(@NonNull Parcel dest, int flags) {
dest.writeByte((byte) (disableAutoProfiling ? 1 : 0));
dest.writeString(touchpadInputMode);
dest.writeByte((byte) (useShizuku ? 1 : 0));
dest.writeByte((byte) (editorOverlay ? 1 : 0));
dest.writeString(pointerMode);
}
}
40 changes: 28 additions & 12 deletions app/src/main/res/layout/fragment_settings_dialog.xml
Original file line number Diff line number Diff line change
Expand Up @@ -313,28 +313,35 @@
</com.google.android.material.button.MaterialButtonToggleGroup>
</LinearLayout>

<com.google.android.material.materialswitch.MaterialSwitch
android:id="@+id/auto_profile_switch"
android:layout_width="wrap_content"

<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:checked="true"
android:text="@string/disable_auto_profile" />
android:orientation="horizontal">

<com.google.android.material.materialswitch.MaterialSwitch
android:id="@+id/auto_profile_switch"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:checked="true"
android:text="@string/disable_auto_profile" />

<com.google.android.material.materialswitch.MaterialSwitch
android:id="@+id/use_shizuku"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:checked="false"
android:text="@string/use_shizuku" />
<com.google.android.material.materialswitch.MaterialSwitch
android:id="@+id/use_shizuku"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginLeft="10dp"
android:checked="false"
android:text="@string/use_shizuku" />
</LinearLayout>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">

<TextView
android:layout_width="100dp"
android:layout_width="101dp"
android:layout_height="wrap_content"
android:layout_marginRight="10dp"
android:text="@string/touchpad_input" />
Expand All @@ -353,6 +360,15 @@

</com.google.android.material.textfield.TextInputLayout>

<com.google.android.material.materialswitch.MaterialSwitch
android:id="@+id/editor_overlay"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginLeft="20dp"
android:gravity="end"
android:checked="false"
android:text="@string/open_editor_as_overlay" />

</LinearLayout>

<LinearLayout
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -60,5 +60,6 @@
<string name="launch_app">Launch App</string>
<string name="use_shizuku">Use Shizuku</string>
<string name="pointer">Pointer Mode</string>
<string name="open_editor_as_overlay">Open editor as overlay</string>

</resources>

0 comments on commit 0790eef

Please sign in to comment.