Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Configurable confirm key #94

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ public class MouseEmulationEngine {

public static int bossKey;

public static int confirmKey;

public static int scrollSpeed;

public static boolean isBossKeyDisabled;
Expand Down Expand Up @@ -317,7 +319,7 @@ else if (movementCodeMap.containsKey(keyEvent.getKeyCode()))
attachTimer(movementCodeMap.get(keyEvent.getKeyCode()));
consumed = true;
}
else if(keyEvent.getKeyCode() == KeyEvent.KEYCODE_DPAD_CENTER) {
else if(keyEvent.getKeyCode() == confirmKey) {
// just consume this event to prevent propagation
DPAD_Center_Init_Point = new Point((int) mPointerControl.getPointerLocation().x, (int) mPointerControl.getPointerLocation().y);
DPAD_SELECT_PRESSED = true;
Expand All @@ -332,7 +334,7 @@ else if (keyEvent.getAction() == KeyEvent.ACTION_UP) {
detachPreviousTimer();
consumed = true;
}
else if (keyEvent.getKeyCode() == KeyEvent.KEYCODE_DPAD_CENTER) {
else if (keyEvent.getKeyCode() == confirmKey) {
DPAD_SELECT_PRESSED = false;
detachPreviousTimer();
// if (keyEvent.getEventTime() - keyEvent.getDownTime() > 500) {
Expand Down
38 changes: 30 additions & 8 deletions app/src/main/java/io/github/virresh/matvt/gui/GuiActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,16 @@
import io.github.virresh.matvt.helper.KeyDetection;

import static io.github.virresh.matvt.engine.impl.MouseEmulationEngine.bossKey;
import static io.github.virresh.matvt.engine.impl.MouseEmulationEngine.confirmKey;
import static io.github.virresh.matvt.engine.impl.MouseEmulationEngine.scrollSpeed;

public class GuiActivity extends AppCompatActivity {
CountDownTimer repopulate;
CheckBox cb_mouse_bordered, cb_disable_bossKey, cb_behaviour_bossKey;
TextView gui_acc_perm, gui_acc_serv, gui_overlay_perm, gui_overlay_serv, gui_about;

EditText et_override;
Button bt_saveBossKeyValue;
EditText et_boss_override, et_confirm_override;
Button bt_saveBossKeyValue, bt_saveConfirmKeyValue;

Spinner sp_mouse_icon;
SeekBar dsbar_mouse_size;
Expand All @@ -57,7 +58,10 @@ protected void onCreate(Bundle savedInstanceState) {
gui_about = findViewById(R.id.gui_about);

bt_saveBossKeyValue = findViewById(R.id.bt_saveBossKey);
et_override = findViewById(R.id.et_override);
et_boss_override = findViewById(R.id.et_boss_override);

bt_saveConfirmKeyValue = findViewById(R.id.bt_saveConfirmKey);
et_confirm_override = findViewById(R.id.et_confirm_override);

cb_mouse_bordered = findViewById(R.id.cb_border_window);
cb_disable_bossKey = findViewById(R.id.cb_disable_bossKey);
Expand All @@ -78,7 +82,7 @@ protected void onCreate(Bundle savedInstanceState) {
checkValues(iconStyleSpinnerAdapter);

bt_saveBossKeyValue.setOnClickListener(view -> {
String dat = et_override.getText().toString();
String dat = et_boss_override.getText().toString();
dat = dat.replaceAll("[^0-9]", "");
int keyValue; if (dat.isEmpty()) keyValue = KeyEvent.KEYCODE_VOLUME_MUTE;
else keyValue = Integer.parseInt(dat);
Expand All @@ -89,7 +93,17 @@ protected void onCreate(Bundle savedInstanceState) {
Toast.makeText(this, "New Boss key is : "+keyValue, Toast.LENGTH_SHORT).show();
});


bt_saveConfirmKeyValue.setOnClickListener(view -> {
String dat = et_confirm_override.getText().toString();
dat = dat.replaceAll("[^0-9]", "");
int keyValue; if (dat.isEmpty()) keyValue = KeyEvent.KEYCODE_ENTER;
else keyValue = Integer.parseInt(dat);
isConfirmKeyChanged();
Helper.setOverrideStatus(this, isConfirmKeyChanged());
Helper.setConfirmKeyValue(this, keyValue);
confirmKey = keyValue;
Toast.makeText(this, "New confirm key is : "+keyValue, Toast.LENGTH_SHORT).show();
});

sp_mouse_icon.setOnItemSelectedListener(new OnItemSelectedListener() {
// the listener is set after setting initial value to avoid echo if any
Expand Down Expand Up @@ -165,10 +179,16 @@ private boolean isBossKeyChanged() {
return Helper.getBossKeyValue(this) != 164;
}

private boolean isConfirmKeyChanged() {
return Helper.getBossKeyValue(this) != 23;
}

private void checkValues(IconStyleSpinnerAdapter adapter) {
Context ctx = getApplicationContext();
String val = String.valueOf(Helper.getBossKeyValue(ctx));
et_override.setText(val);
et_boss_override.setText(val);
String val2 = String.valueOf(Helper.getConfirmKeyValue(ctx));
et_confirm_override.setText(val2);
String iconStyle = Helper.getMouseIconPref(ctx);
sp_mouse_icon.setSelection(adapter.getPosition(iconStyle));

Expand Down Expand Up @@ -259,8 +279,10 @@ protected void onResume() {
//Checking services status
checkServiceStatus();

if (et_override != null)
et_override.setText(Helper.getBossKeyValue(this)+"");
if (et_boss_override != null)
et_boss_override.setText(Helper.getBossKeyValue(this)+"");
if (et_confirm_override != null)
et_confirm_override.setText(Helper.getConfirmKeyValue(this)+"");
}

private void checkServiceStatus() {
Expand Down
14 changes: 14 additions & 0 deletions app/src/main/java/io/github/virresh/matvt/helper/Helper.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public class Helper {
static final String PREFS_ID = "MATVT";
static final String PREF_KEY_CB_OVERRIDE_STAT = "CB_OVERRIDE_STAT";
static final String PREF_KEY_CB_OVERRIDE_VAL = "CB_OVERRIDE_VAL";
static final String PREF_KEY_CFB_OVERRIDE_VAL = "CFB_OVERRIDE_VAL";
static final String PREF_KEY_MOUSE_ICON = "MOUSE_ICON";
static final String PREF_KEY_MOUSE_SIZE = "MOUSE_SIZE";
static final String PREF_KEY_SCROLL_SPEED = "SCROLL_SPEED";
Expand Down Expand Up @@ -69,6 +70,11 @@ public static int getBossKeyValue(Context ctx) {
return sp.getInt(PREF_KEY_CB_OVERRIDE_VAL, 164);
}

public static int getConfirmKeyValue(Context ctx) {
SharedPreferences sp = ctx.getSharedPreferences(PREFS_ID, Context.MODE_PRIVATE);
return sp.getInt(PREF_KEY_CFB_OVERRIDE_VAL, 23);
}

@SuppressLint("ApplySharedPref")
public static void setBossKeyValue(Context ctx, int val) {
SharedPreferences sp = ctx.getSharedPreferences(PREFS_ID, Context.MODE_PRIVATE);
Expand All @@ -77,6 +83,14 @@ public static void setBossKeyValue(Context ctx, int val) {
editor.commit();
}

@SuppressLint("ApplySharedPref")
public static void setConfirmKeyValue(Context ctx, int val) {
SharedPreferences sp = ctx.getSharedPreferences(PREFS_ID, Context.MODE_PRIVATE);
SharedPreferences.Editor editor = sp.edit();
editor.putInt(PREF_KEY_CFB_OVERRIDE_VAL, val);
editor.commit();
}

public static String getMouseIconPref(Context ctx) {
SharedPreferences sp = ctx.getSharedPreferences(PREFS_ID, Context.MODE_PRIVATE);
return sp.getString(PREF_KEY_MOUSE_ICON, "default");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import io.github.virresh.matvt.view.OverlayView;

import static io.github.virresh.matvt.engine.impl.MouseEmulationEngine.bossKey;
import static io.github.virresh.matvt.engine.impl.MouseEmulationEngine.confirmKey;
import static io.github.virresh.matvt.engine.impl.MouseEmulationEngine.scrollSpeed;

public class MouseEventService extends AccessibilityService {
Expand Down Expand Up @@ -44,6 +45,7 @@ protected void onServiceConnected() {
super.onServiceConnected();
Log.i(TAG_NAME, "Starting service initialization sequence. App version " + BuildConfig.VERSION_NAME);
bossKey = KeyEvent.KEYCODE_VOLUME_MUTE;
confirmKey = KeyEvent.KEYCODE_DPAD_CENTER;
PointerControl.isBordered = Helper.getMouseBordered(this);
scrollSpeed = Helper.getScrollSpeed(this);
MouseEmulationEngine.isBossKeyDisabled = Helper.isBossKeyDisabled(this);
Expand Down
91 changes: 73 additions & 18 deletions app/src/main/res/layout/activity_main_gui.xml
Original file line number Diff line number Diff line change
Expand Up @@ -242,65 +242,65 @@
android:textSize="20sp" />

<LinearLayout
android:weightSum="1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
android:weightSum="1">

<TextView
android:textAlignment="center"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="30dp"
android:layout_marginRight="30dp"
android:textSize="20sp"
android:layout_weight="0.20"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Boss Key"
android:textAlignment="center"
android:textColor="@color/white"
android:textColorHint="@color/white_2"
android:text="Boss Key"/>
android:textSize="20sp" />

<EditText
android:textAlignment="center"
android:layout_marginLeft="30dp"
android:layout_marginRight="30dp"
android:id="@+id/et_override"
android:id="@+id/et_boss_override"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginLeft="30dp"
android:layout_marginRight="30dp"
android:layout_weight="0.20"
android:buttonTint="@color/white"
android:hint="(Default: 164)"
android:inputType="number"
android:nextFocusRight="@id/bt_detect"
android:textAlignment="center"
android:textColor="@color/white"
android:textColorHint="@color/white_2"
android:textSize="20sp"
tools:ignore="RtlCompat" />

<Button
android:layout_marginLeft="30dp"
android:layout_marginRight="30dp"
android:onClick="callDetect"
android:id="@+id/bt_detect"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="30dp"
android:layout_marginRight="30dp"
android:layout_weight="0.30"
android:background="@drawable/bg_button"
android:buttonTint="@color/white"
android:nextFocusLeft="@id/et_override"
android:nextFocusLeft="@id/et_boss_override"
android:nextFocusRight="@id/bt_saveBossKey"
android:onClick="callDetect"
android:text="DETECT"
android:textColor="@color/white"
android:textSize="20sp" />


<Button
android:layout_marginLeft="30dp"
android:layout_marginRight="30dp"
android:id="@+id/bt_saveBossKey"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="30dp"
android:layout_marginRight="30dp"
android:layout_weight="0.30"
android:background="@drawable/bg_button"
android:buttonTint="@color/white"
Expand All @@ -310,5 +310,60 @@
android:textSize="20sp" />

</LinearLayout>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:orientation="horizontal"
android:weightSum="1">

<TextView
android:layout_width="72dp"
android:layout_height="wrap_content"
android:layout_marginLeft="30dp"
android:layout_marginRight="30dp"
android:layout_weight="0.20"
android:text="Confirm Key"
android:textAlignment="center"
android:textColor="@color/white"
android:textColorHint="@color/white_2"
android:textSize="20sp" />

<EditText
android:id="@+id/et_confirm_override"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginLeft="30dp"
android:layout_marginRight="30dp"
android:layout_weight="0.20"
android:buttonTint="@color/white"
android:hint="(Default: 23)"
android:inputType="number"
android:nextFocusRight="@id/bt_saveConfirmKey"
android:textAlignment="center"
android:textColor="@color/white"
android:textColorHint="@color/white_2"
android:textSize="20sp"
tools:ignore="RtlCompat" />


<Button
android:id="@+id/bt_saveConfirmKey"
android:layout_width="119dp"
android:layout_height="wrap_content"
android:layout_marginLeft="30dp"
android:layout_marginRight="30dp"
android:layout_weight="0.20"
android:background="@drawable/bg_button"
android:buttonTint="@color/white"
android:nextFocusLeft="@id/et_confirm_override"
android:text="SAVE"
android:textColor="@color/white"
android:textSize="20sp" />

</LinearLayout>

</LinearLayout>
</ScrollView>