diff --git a/app/build.gradle b/app/build.gradle index 042cf69..e84e297 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -107,7 +107,6 @@ dependencies { implementation "androidx.constraintlayout:constraintlayout:2.1.4" implementation "androidx.coordinatorlayout:coordinatorlayout:1.2.0" implementation 'com.google.android.material:material:1.12.0' - implementation "com.leinardi.android:speed-dial:3.3.0" implementation 'androidx.webkit:webkit:1.12.1' implementation "com.github.topjohnwu.libsu:core:5.3.0" implementation "com.github.topjohnwu.libsu:service:5.3.0" diff --git a/app/src/main/java/xtr/keymapper/editor/EditorUI.java b/app/src/main/java/xtr/keymapper/editor/EditorUI.java index 92eda7f..75a4171 100644 --- a/app/src/main/java/xtr/keymapper/editor/EditorUI.java +++ b/app/src/main/java/xtr/keymapper/editor/EditorUI.java @@ -33,7 +33,6 @@ import xtr.keymapper.databinding.CrosshairBinding; import xtr.keymapper.databinding.DpadArrowsBinding; import xtr.keymapper.databinding.DpadBinding; -import xtr.keymapper.databinding.KeymapEditorBinding; import xtr.keymapper.databinding.MouseAimConfigBinding; import xtr.keymapper.databinding.ResizableBinding; import xtr.keymapper.dpad.Dpad; @@ -45,7 +44,6 @@ import xtr.keymapper.keymap.KeymapProfileKey; import xtr.keymapper.keymap.KeymapProfiles; import xtr.keymapper.mouse.MouseAimConfig; -import xtr.keymapper.server.RemoteService; import xtr.keymapper.server.RemoteServiceHelper; import xtr.keymapper.swipekey.SwipeKey; import xtr.keymapper.swipekey.SwipeKeyView; @@ -53,7 +51,6 @@ public class EditorUI extends OnKeyEventListener.Stub { private final LayoutInflater layoutInflater; - private final ViewGroup mainView; private KeyInFocus keyInFocus; // Keyboard keys @@ -65,8 +62,6 @@ public class EditorUI extends OnKeyEventListener.Stub { private MovableFrameLayout crosshair; private final MovableFrameLayout[] dpadArray = new MovableFrameLayout[MAX_DPADS]; private final DpadBinding[] dpadBindingArray = new DpadBinding[MAX_DPADS]; - // Default position of new views added - private final KeymapEditorBinding binding; private final Context context; private final OnHideListener onHideListener; private final Handler mHandler = new Handler(Looper.getMainLooper()); @@ -75,7 +70,7 @@ public class EditorUI extends OnKeyEventListener.Stub { private boolean overlayOpen = false; private MovableFrameLayout dpadUdlr; private final SettingsFragment settingsFragment; - private final ViewGroup settingsView; + private final ViewGroup mainView; public static final int START_SETTINGS = 0; public static final int START_EDITOR = 1; @@ -90,18 +85,13 @@ public EditorUI (Context context, OnHideListener onHideListener, String profileN layoutInflater = context.getSystemService(LayoutInflater.class); - binding = KeymapEditorBinding.inflate(layoutInflater); - mainView = binding.getRoot(); settingsFragment = new SettingsFragment(context); - settingsView = settingsFragment.createView(layoutInflater); - settingsFragment.init(startMode); + mainView = settingsFragment.createView(layoutInflater); - binding.speedDial.inflate(R.menu.keymap_editor_menu); - settingsFragment.inflate(R.menu.keymap_editor_menu, startMode, layoutInflater); - - binding.speedDial.open(); - setupButtons(); + settingsFragment.init(startMode); + settingsFragment.inflateMenuResource(startMode, layoutInflater); + settingsFragment.setOnActionSelectedListener(this::onActionSelected); } public void open(boolean overlayWindow) { @@ -111,10 +101,8 @@ public void open(boolean overlayWindow) { else { if (context instanceof EditorActivity) ((Activity)context).setContentView(mainView); - else + else // For MainActivity ((Activity)context).addContentView(mainView, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); - - mainView.addView(settingsView,new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); } if (onHideListener != null && !onHideListener.getEvent()) { @@ -126,7 +114,6 @@ public void open(boolean overlayWindow) { public void openOverlayWindow() { if (overlayOpen) { removeView(mainView); - removeView(settingsView); } WindowManager mWindowManager = context.getSystemService(WindowManager.class); WindowManager.LayoutParams mParams = new WindowManager.LayoutParams( @@ -137,8 +124,6 @@ public void openOverlayWindow() { WindowManager.LayoutParams.FLAG_LAYOUT_INSET_DECOR, PixelFormat.TRANSLUCENT); mWindowManager.addView(mainView, mParams); - mainView.addView(settingsView, mParams); - mainView.bringChildToFront(settingsView); overlayOpen = true; } @@ -170,16 +155,58 @@ public void onKeyEvent(String event) { } + /** + * Called when a CardView has been clicked. + * + * @param id the relevant id of the menu item for the card. + */ + public void onActionSelected(int id) { + // X y coordinates of center of root view + float defaultX = mainView.getPivotX(); + float defaultY = mainView.getPivotY(); + + if (id == R.id.add) { + addKey(defaultX, defaultY); + } + else if (id == R.id.save) { + hideView(); + } + else if (id == R.id.dpad) { + final CharSequence[] items = { "Arrow keys", "WASD Keys", "Custom"}; + MaterialAlertDialogBuilder builder = new MaterialAlertDialogBuilder(context); + builder.setTitle("Select Dpad").setItems(items, (dialog, i) -> { + if (i == 0) addArrowKeysDpad(defaultX, defaultY); + else if (i == 1) addWasdDpad(defaultX, defaultY); + else addDpad(getNextDpadId(), defaultX, defaultY); + }); + AlertDialog dialog = builder.create(); + if (overlayOpen) dialog.getWindow().setType(WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY); + dialog.show(); + } + else if (id == R.id.crosshair) { + profile.mouseAimConfig = new MouseAimConfig(); + addCrosshair(defaultX, defaultY); + } + else if (id == R.id.mouse_left) { + addLeftClick(defaultX, defaultY); + } + else if (id == R.id.swipe_key) { + addSwipeKey(); + } + else if (id == R.id.mouse_right) { + addRightClick(defaultX, defaultY); + } + } public interface OnHideListener { void onHideView(); boolean getEvent(); + } public void hideView() { saveKeymap(); settingsFragment.onDestroyView(); removeView(mainView); - removeView(settingsView); if (onHideListener != null) onHideListener.onHideView(); else RemoteServiceHelper.reloadKeymap(context); } @@ -242,7 +269,7 @@ private void saveKeymap() { if (rightClick != null) { linesToWrite.add(MOUSE_RIGHT + " " + rightClick.getX() + " " + rightClick.getY()); } - + // Keyboard keys floatingKeysMap.forEach((frameLayout, movableFloatingActionKey) -> linesToWrite.add(movableFloatingActionKey.getData())); swipeKeyList.stream().map(swipeKeyView -> new SwipeKey(swipeKeyView).getData()).forEach(linesToWrite::add); @@ -254,50 +281,6 @@ private void saveKeymap() { // Reload keymap if service running } - - public void setupButtons() { - binding.speedDial.setOnActionSelectedListener(actionItem -> { - // X y coordinates of center of root view - float defaultX = mainView.getPivotX(); - float defaultY = mainView.getPivotY(); - - int id = actionItem.getId(); - - if (id == R.id.add) { - addKey(defaultX, defaultY); - } - else if (id == R.id.save) { - hideView(); - } - else if (id == R.id.dpad) { - final CharSequence[] items = { "Arrow keys", "WASD Keys", "Custom"}; - MaterialAlertDialogBuilder builder = new MaterialAlertDialogBuilder(context); - builder.setTitle("Select Dpad").setItems(items, (dialog, i) -> { - if (i == 0) addArrowKeysDpad(defaultX, defaultY); - else if (i == 1) addWasdDpad(defaultX, defaultY); - else addDpad(getNextDpadId(), defaultX, defaultY); - }); - AlertDialog dialog = builder.create(); - if (overlayOpen) dialog.getWindow().setType(WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY); - dialog.show(); - } - else if (id == R.id.crosshair) { - profile.mouseAimConfig = new MouseAimConfig(); - addCrosshair(defaultX, defaultY); - } - else if (id == R.id.mouse_left) { - addLeftClick(defaultX, defaultY); - } - else if (id == R.id.swipe_key) { - addSwipeKey(); - } - else if (id == R.id.mouse_right) { - addRightClick(defaultX, defaultY); - } - return true; - }); - } - private void addWasdDpad(float defaultX, float defaultY) { int i = getNextDpadId(); addDpad(i, defaultX, defaultY); diff --git a/app/src/main/java/xtr/keymapper/editor/SettingsFragment.java b/app/src/main/java/xtr/keymapper/editor/SettingsFragment.java index b93c64f..f752977 100644 --- a/app/src/main/java/xtr/keymapper/editor/SettingsFragment.java +++ b/app/src/main/java/xtr/keymapper/editor/SettingsFragment.java @@ -11,7 +11,7 @@ import android.widget.LinearLayout; import android.widget.PopupMenu; -import androidx.annotation.MenuRes; +import androidx.annotation.IdRes; import androidx.annotation.NonNull; import com.google.android.material.button.MaterialButtonToggleGroup; @@ -25,7 +25,6 @@ import xtr.keymapper.databinding.KeymapEditorItemBinding; import xtr.keymapper.databinding.KeymapEditorLayoutBinding; import xtr.keymapper.keymap.KeymapConfig; -import xtr.keymapper.server.RemoteServiceHelper; public class SettingsFragment { private final KeymapConfig keymapConfig; @@ -33,6 +32,8 @@ public class SettingsFragment { private Map pointerModeMap; private Map touchpadInputModeMap; private final Context context; + private OnCardItemSelectedListener onCardItemSelectedListener; + public SettingsFragment(Context context) { this.context = context; keymapConfig = new KeymapConfig(context); @@ -231,9 +232,9 @@ public void onDestroyView() { binding = null; } - public void inflate(@MenuRes int menuRes, int startMode, LayoutInflater layoutInflater) { + public void inflateMenuResource(int startMode, LayoutInflater layoutInflater) { PopupMenu popupMenu = new PopupMenu(context, new View(context)); - popupMenu.inflate(menuRes); + popupMenu.inflate(R.menu.keymap_editor_menu); Menu menu = popupMenu.getMenu(); if (startMode == EditorUI.START_EDITOR) for (int n = 1; n <= 3; n++) { // n = { 1,2,3 } For dividing between three columns @@ -253,12 +254,32 @@ public void inflate(@MenuRes int menuRes, int startMode, LayoutInflater layoutIn itemBinding.imageView.setImageDrawable(menuItem.getIcon()); itemBinding.title.setText(menuItem.getTitle()); itemBinding.description.setText(menuItem.getContentDescription()); + itemBinding.getRoot().setOnClickListener(v -> onCardItemSelected(menuItem.getItemId())); } } else if (startMode == EditorUI.START_SETTINGS) { KeymapEditorItemBinding itemBinding = KeymapEditorItemBinding.inflate(layoutInflater, binding.L1, true); itemBinding.imageView.setImageResource(R.drawable.ic_baseline_done_36); itemBinding.title.setText(R.string.save); + itemBinding.getRoot().setOnClickListener(v -> onCardItemSelected(R.id.save)); } } + + private void onCardItemSelected(int itemId) { + if (onCardItemSelectedListener != null) + onCardItemSelectedListener.onActionSelected(itemId); + } + + public void setOnActionSelectedListener(OnCardItemSelectedListener l) { + this.onCardItemSelectedListener = l; + } + + public interface OnCardItemSelectedListener { + /** + * Called when a CardView has been clicked. + * + * @param menuItemId the relevant id of the menu item for the card. + */ + void onActionSelected(@IdRes int menuItemId); + } } diff --git a/app/src/main/res/layout/keymap_editor.xml b/app/src/main/res/layout/keymap_editor.xml deleted file mode 100644 index e6d6a8a..0000000 --- a/app/src/main/res/layout/keymap_editor.xml +++ /dev/null @@ -1,22 +0,0 @@ - - - - - - - - -