|
|
@@ -1,15 +1,22 @@
|
|
|
package com.example.modifier;
|
|
|
|
|
|
import android.accessibilityservice.AccessibilityServiceInfo;
|
|
|
+import android.annotation.SuppressLint;
|
|
|
+import android.content.Context;
|
|
|
import android.content.Intent;
|
|
|
import android.content.pm.ApplicationInfo;
|
|
|
import android.content.pm.PackageManager;
|
|
|
+import android.graphics.Color;
|
|
|
import android.graphics.PixelFormat;
|
|
|
import android.net.Uri;
|
|
|
import android.os.Build;
|
|
|
+import android.util.DisplayMetrics;
|
|
|
import android.util.Log;
|
|
|
+import android.view.GestureDetector;
|
|
|
import android.view.Gravity;
|
|
|
import android.view.LayoutInflater;
|
|
|
+import android.view.MotionEvent;
|
|
|
+import android.view.View;
|
|
|
import android.view.WindowManager;
|
|
|
import android.view.accessibility.AccessibilityEvent;
|
|
|
import android.view.accessibility.AccessibilityNodeInfo;
|
|
|
@@ -19,16 +26,18 @@ import androidx.annotation.NonNull;
|
|
|
import androidx.appcompat.view.ContextThemeWrapper;
|
|
|
|
|
|
import com.example.modifier.databinding.FloatingWindowBinding;
|
|
|
+import com.google.android.material.color.DynamicColors;
|
|
|
+import com.google.android.material.color.DynamicColorsOptions;
|
|
|
|
|
|
import org.json.JSONArray;
|
|
|
import org.json.JSONException;
|
|
|
import org.json.JSONObject;
|
|
|
|
|
|
-import java.net.URISyntaxException;
|
|
|
import java.util.Optional;
|
|
|
import java.util.concurrent.ScheduledExecutorService;
|
|
|
import java.util.concurrent.ScheduledFuture;
|
|
|
import java.util.concurrent.ScheduledThreadPoolExecutor;
|
|
|
+import java.util.concurrent.atomic.AtomicReference;
|
|
|
|
|
|
import io.socket.client.IO;
|
|
|
import io.socket.client.Socket;
|
|
|
@@ -235,6 +244,7 @@ public class ModifierService extends android.accessibilityservice.AccessibilityS
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ @SuppressLint("ClickableViewAccessibility")
|
|
|
@Override
|
|
|
protected void onServiceConnected() {
|
|
|
super.onServiceConnected();
|
|
|
@@ -248,7 +258,15 @@ public class ModifierService extends android.accessibilityservice.AccessibilityS
|
|
|
info.notificationTimeout = 100;
|
|
|
this.setServiceInfo(info);
|
|
|
|
|
|
+ DisplayMetrics displayMetrics = new DisplayMetrics();
|
|
|
WindowManager windowManager = (WindowManager) getSystemService(WINDOW_SERVICE);
|
|
|
+ windowManager.getDefaultDisplay().getMetrics(displayMetrics);
|
|
|
+ int height = displayMetrics.heightPixels;
|
|
|
+ int width = displayMetrics.widthPixels;
|
|
|
+ int maxX = width - Utils.dp2px(this, 150);
|
|
|
+ int maxY = height - Utils.dp2px(this, 100);
|
|
|
+
|
|
|
+
|
|
|
FrameLayout mLayout = new FrameLayout(this);
|
|
|
WindowManager.LayoutParams layoutParams = new WindowManager.LayoutParams();
|
|
|
layoutParams.type = WindowManager.LayoutParams.TYPE_ACCESSIBILITY_OVERLAY;
|
|
|
@@ -259,11 +277,36 @@ public class ModifierService extends android.accessibilityservice.AccessibilityS
|
|
|
layoutParams.x = 0;
|
|
|
layoutParams.y = 800;
|
|
|
layoutParams.gravity = Gravity.START | Gravity.TOP;
|
|
|
- ContextThemeWrapper newContext = new ContextThemeWrapper(getApplicationContext(), R.style.AppTheme);
|
|
|
+
|
|
|
+ Context newContext = DynamicColors.wrapContextIfAvailable(getApplicationContext(), R.style.AppTheme);
|
|
|
LayoutInflater inflater = LayoutInflater.from(newContext);
|
|
|
binding = FloatingWindowBinding.inflate(inflater, mLayout, true);
|
|
|
windowManager.addView(mLayout, layoutParams);
|
|
|
|
|
|
+ AtomicReference<Float> downX = new AtomicReference<>(0f);
|
|
|
+ AtomicReference<Float> downY = new AtomicReference<>(0f);
|
|
|
+ AtomicReference<Integer> downParamX = new AtomicReference<>(0);
|
|
|
+ AtomicReference<Integer> downParamY = new AtomicReference<>(0);
|
|
|
+
|
|
|
+ binding.floatingWindow.setOnTouchListener((v, event) -> {
|
|
|
+ switch (event.getAction()) {
|
|
|
+ case MotionEvent.ACTION_DOWN:
|
|
|
+ downX.set(event.getRawX());
|
|
|
+ downY.set(event.getRawY());
|
|
|
+ downParamX.set(layoutParams.x);
|
|
|
+ downParamY.set(layoutParams.y);
|
|
|
+ return true;
|
|
|
+
|
|
|
+ case MotionEvent.ACTION_MOVE:
|
|
|
+ layoutParams.x = (int) Math.min(Math.max(downParamX.get() + (event.getRawX() - downX.get()), 0), maxX);
|
|
|
+ layoutParams.y = (int) Math.min(Math.max(downParamY.get() + (event.getRawY() - downY.get()), 0), maxY);
|
|
|
+ windowManager.updateViewLayout(mLayout, layoutParams);
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+ });
|
|
|
+
|
|
|
+
|
|
|
binding.swConnect.setChecked(true);
|
|
|
binding.swConnect.setOnCheckedChangeListener((buttonView, isChecked) -> {
|
|
|
if (isChecked) {
|