Skip to content

Commit

Permalink
Added Border to mouse (with a toggle) //I'm unable to describe this
Browse files Browse the repository at this point in the history
and some minor changes
  • Loading branch information
sweenwolf committed Mar 12, 2021
1 parent 10d3a24 commit 9448cb6
Show file tree
Hide file tree
Showing 14 changed files with 525 additions and 217 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ android {
applicationId "io.github.virresh.matvt"
minSdkVersion 24
targetSdkVersion 29
versionCode 101
versionName '1.0.2'
versionCode 103
versionName '1.0.3'

}

Expand Down
Binary file added app/release/MATVT_1.0.3.apk
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,8 @@ public boolean perform (KeyEvent keyEvent) {
waitToChange();
if (isEnabled){
isInScrollMode = !isInScrollMode;
Toast.makeText(mService, "Scroll Mode " + isInScrollMode, Toast.LENGTH_SHORT).show();
Toast.makeText(mService, isInScrollMode ? "Scroll Mode: Enabled" : "Scroll Mode: Disabled",
Toast.LENGTH_SHORT).show();
return true;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import androidx.annotation.NonNull;

import io.github.virresh.matvt.helper.Helper;
import io.github.virresh.matvt.view.MouseCursorView;
import io.github.virresh.matvt.view.OverlayView;

Expand Down Expand Up @@ -62,24 +63,46 @@ public void reappear () {
}
}

public static boolean isBordered = false;

public void move (int direction, int momentum) {
int movementX = (int) (dirX[direction] * ((momentum)));
int movementY = (int) (dirY[direction] * ((momentum)));

mPointerLocation.x += movementX;
if (mPointerLocation.x > mPointerLayerView.getWidth()) {
mPointerLocation.x -= mPointerLayerView.getWidth();
}
else if (mPointerLocation.x < 0) {
mPointerLocation.x += mPointerLayerView.getWidth();
// free mode
if (!isBordered) {
mPointerLocation.x += movementX;
if (mPointerLocation.x > mPointerLayerView.getWidth()) {
mPointerLocation.x -= mPointerLayerView.getWidth();
} else if (mPointerLocation.x < 0) {
mPointerLocation.x += mPointerLayerView.getWidth();
}

mPointerLocation.y += movementY;
if (mPointerLocation.y > mPointerLayerView.getHeight()) {
mPointerLocation.y -= mPointerLayerView.getHeight();
} else if (mPointerLocation.y < 0) {
mPointerLocation.y += mPointerLayerView.getHeight();
}
}

mPointerLocation.y += movementY;
if (mPointerLocation.y > mPointerLayerView.getHeight()) {
mPointerLocation.y -= mPointerLayerView.getHeight();
}
else if (mPointerLocation.y < 0) {
mPointerLocation.y += mPointerLayerView.getHeight();
else {

if (mPointerLocation.x + movementX >= 0 && mPointerLocation.x + movementX <= mPointerLayerView.getWidth())
mPointerLocation.x += movementX;
else {
if (mPointerLocation.x < (mPointerLayerView.getWidth() / 2f))
mPointerLocation.x = 0;
else mPointerLocation.x = mPointerLayerView.getWidth();
}

if (mPointerLocation.y + movementY >= 0 && mPointerLocation.y + movementY <= mPointerLayerView.getHeight())
mPointerLocation.y += movementY;
else {
if (mPointerLocation.y < (mPointerLayerView.getHeight() / 2f)) {
mPointerLocation.y = 0;
} else mPointerLocation.y = mPointerLayerView.getHeight();
}
}

mCursorView.updatePosition(mPointerLocation);
Expand Down
13 changes: 10 additions & 3 deletions app/src/main/java/io/github/virresh/matvt/gui/GuiActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.SeekBar;
Expand All @@ -27,14 +28,15 @@
import java.util.List;

import io.github.virresh.matvt.R;
import io.github.virresh.matvt.engine.impl.PointerControl;
import io.github.virresh.matvt.helper.Helper;

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

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

EditText et_override;
Expand All @@ -60,6 +62,7 @@ protected void onCreate(Bundle savedInstanceState) {
bt_override = findViewById(R.id.bt_override);
et_override = findViewById(R.id.et_override);
cb_override = findViewById(R.id.cb_override);
cb_mouse_bordered = findViewById(R.id.cb_border_window);
sp_mouse_icon = findViewById(R.id.sp_mouse_icon);
dsbar_mouse_size = findViewById(R.id.dsbar_mouse_size);
dsbar_scroll_speed = findViewById(R.id.dsbar_mouse_scspeed);
Expand Down Expand Up @@ -136,6 +139,11 @@ public void onStartTrackingTouch(SeekBar seekBar) {}
public void onStopTrackingTouch(SeekBar seekBar) {}
});

cb_mouse_bordered.setOnCheckedChangeListener((compoundButton, b) -> {
Helper.setMouseBordered(getApplicationContext(), b);
PointerControl.isBordered = b;
});

populateText();
findViewById(R.id.gui_setup_perm).setOnClickListener(view -> askPermissions());
}
Expand All @@ -159,10 +167,9 @@ private void checkValues(IconStyleSpinnerAdapter adapter) {

private void showBossLayout(boolean status) {
if (status) boss_override.setVisibility(View.VISIBLE);
else boss_override.setVisibility(View.INVISIBLE);
else boss_override.setVisibility(View.GONE);
}


private void askPermissions() {
if (Helper.isOverlayDisabled(this)) {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.core.content.ContextCompat;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
Expand All @@ -23,7 +25,7 @@
// in case similar dropdowns are needed in future

public class IconStyleSpinnerAdapter extends ArrayAdapter<String> {
private List<String> objects;
private final List<String> objects;
private Context context;
public static Map<String, Integer> textToResourceIdMap = new HashMap<String, Integer>();

Expand All @@ -39,7 +41,7 @@ public IconStyleSpinnerAdapter(@NonNull Context context, int resource, int textV
}

public static List<String> getResourceList () {
return textToResourceIdMap.keySet().stream().collect(Collectors.toList());
return new ArrayList<>(textToResourceIdMap.keySet());
}

@Override
Expand Down Expand Up @@ -74,12 +76,8 @@ public View getCustomView(int position, View convertView, ViewGroup parent, bool
String selection = objects.get(position);

label.setText(selection);
icon.setImageDrawable(context.getDrawable(textToResourceIdMap.getOrDefault(selection, R.drawable.pointer)));

if (setBackcolor) {
label.setBackground(context.getDrawable(R.drawable.focus_selector));
}

textToResourceIdMap.getOrDefault(selection , R.drawable.pointer);
icon.setImageDrawable(ContextCompat.getDrawable(context, textToResourceIdMap.getOrDefault(selection, R.drawable.pointer)));
return row;
}
}
16 changes: 15 additions & 1 deletion app/src/main/java/io/github/virresh/matvt/helper/Helper.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,14 @@ public class Helper {
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";
static final String PREF_KEY_MOUSE_BORDERED = "MOUSE_BORDERED";

public static boolean isAccessibilityDisabled(Context ctx) {
return !isAccServiceInstalled(ctx.getPackageName() + "/.services.MouseEventService", ctx);
}

public static boolean isAnotherServiceInstalled(Context ctx) {
String fireTVSettings = "com.wolf.firetvsettings/.HomeService";
String fireTVSettings = "com.wolf.firetvsettings/.main.services.HomeService";
String buttonMapper = "flar2.homebutton/.a.i";
return isAccServiceInstalled(fireTVSettings, ctx) || isAccServiceInstalled(buttonMapper, ctx);
}
Expand Down Expand Up @@ -111,4 +112,17 @@ public static void setScrollSpeed(Context ctx, int val) {
}


@SuppressLint("ApplySharedPref")
public static void setMouseBordered(Context ctx, Boolean val) {
SharedPreferences sp = ctx.getSharedPreferences(PREFS_ID, Context.MODE_PRIVATE);
SharedPreferences.Editor editor = sp.edit();
editor.putBoolean(PREF_KEY_MOUSE_BORDERED, val);
editor.commit();
}

public static boolean getMouseBordered(Context ctx) {
SharedPreferences sp = ctx.getSharedPreferences(PREFS_ID, Context.MODE_PRIVATE);
return sp.getBoolean(PREF_KEY_MOUSE_BORDERED, false);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import java.util.logging.Logger;

import io.github.virresh.matvt.engine.impl.MouseEmulationEngine;
import io.github.virresh.matvt.engine.impl.PointerControl;
import io.github.virresh.matvt.helper.Helper;
import io.github.virresh.matvt.view.OverlayView;

Expand Down Expand Up @@ -40,6 +41,7 @@ public void onInterrupt() {}
protected void onServiceConnected() {
super.onServiceConnected();
bossKey = KeyEvent.KEYCODE_VOLUME_MUTE;
PointerControl.isBordered = Helper.getMouseBordered(this);
scrollSpeed = Helper.getScrollSpeed(this);
if (Helper.isOverriding(this)) bossKey = Helper.getOverrideValue(this);
if (Settings.canDrawOverlays(this)) init();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import android.graphics.drawable.BitmapDrawable;
import android.view.View;

import androidx.core.content.ContextCompat;

import io.github.virresh.matvt.R;
import io.github.virresh.matvt.gui.IconStyleSpinnerAdapter;
import io.github.virresh.matvt.helper.Helper;
Expand All @@ -34,13 +36,11 @@ public MouseCursorView(Context context) {
setBitmap(context);
}

private BitmapDrawable setBitmap(Context context) {
@SuppressLint("UseCompatLoadingForDrawables")
BitmapDrawable bp = (BitmapDrawable) context.getDrawable(pointerDrawableReference);
private void setBitmap(Context context) {
BitmapDrawable bp = (BitmapDrawable) ContextCompat.getDrawable(context, pointerDrawableReference);
Bitmap originalBitmap = bp.getBitmap();
BitmapDrawable d = new BitmapDrawable(getResources(), Bitmap.createScaledBitmap(originalBitmap, 50 * pointerSizeReference, 50 * pointerSizeReference, true));
mPointerBitmap = d.getBitmap();
return d;
}

public void updateFromPreferences() {
Expand Down
File renamed without changes.
4 changes: 1 addition & 3 deletions app/src/main/res/drawable/focus_selector.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@color/colorAccent" android:state_focused="true"/>
<item android:drawable="@color/black" android:state_focused="false"/>
<item android:drawable="@color/blue" />
<item android:drawable="@color/colorPrimaryDark" android:state_focused="false"/>
</selector>
Loading

0 comments on commit 9448cb6

Please sign in to comment.