Optimization #2 + Fix Movable Pref
LayoutScaling : Remove useless apply theme methods + moved
FLAG_NOT_TOUCH_MODAL from MovableWindow here. + remove unused imports
HaloFlagInject : Edit SystemUI Flag removing + changed method of
LayoutScaling + remove useless scale method since floatingWindow ref is
in another process
Movable : Remove unused imports
MovableWindow: Fix movable not being disabled properly. Fix systemUI if
not enabled on boot.
diff --git a/src/com/zst/xposed/halo/floatingwindow/HaloFlagInject.java b/src/com/zst/xposed/halo/floatingwindow/HaloFlagInject.java
index 7c857a5..3fea799 100644
--- a/src/com/zst/xposed/halo/floatingwindow/HaloFlagInject.java
+++ b/src/com/zst/xposed/halo/floatingwindow/HaloFlagInject.java
@@ -206,26 +206,19 @@
protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
Activity thiz = (Activity)param.thisObject;
String name = thiz.getWindow().getContext().getPackageName();
- if (name.startsWith("com.android.systemui")) return;
- isHoloFloat = (thiz.getIntent().getFlags() & FLAG_FLOATING_WINDOW) == FLAG_FLOATING_WINDOW;
-
- if(isHoloFloat && floatingWindow){
-
- LayoutScaling.applyThemeLess(thiz.getWindow().getContext(),thiz.getWindow());
+ Intent intent = thiz.getIntent();
+ if (name.startsWith("com.android.systemui")){
+ //How did halo flag get into SystemUI? Remove it.
+ intent.setFlags(intent.getFlags() & ~Res.FLAG_FLOATING_WINDOW);
+ isHoloFloat = false;
+ return;
+ }
+ isHoloFloat = (intent.getFlags() & FLAG_FLOATING_WINDOW) == FLAG_FLOATING_WINDOW;
+ if(isHoloFloat) {
+ LayoutScaling.appleFloating(thiz.getWindow().getContext(),thiz.getWindow());
return;
- }
-
+ }
}
- protected void afterHookedMethod(MethodHookParam param) throws Throwable {
- Activity thiz = (Activity)param.thisObject;
- if(isHoloFloat){
-
- LayoutScaling.applyThemeLess(thiz.getWindow().getContext(),thiz.getWindow());
- return;
- }
-
- }
-
});
@@ -256,14 +249,14 @@
protected void afterHookedMethod(MethodHookParam param) throws Throwable {
Window window = (Window) param.thisObject;
Context context = window.getContext();
-
+ String name = window.getContext().getPackageName();
+ if (name.startsWith("com.android.systemui")) return;
+
if (!(isHoloFloat && floatingWindow)) return;
if (window.getDecorView().getTag(10000) != null) return;
//Return so it doesnt override our custom movable window scaling
- String localClassPackageName = context.getClass().getPackage().getName();
-
- LayoutScaling.applyTheme(context, window,localClassPackageName);
+ LayoutScaling.appleFloating(context, window);
window.getDecorView().setTag(10000, (Object)1);
}
diff --git a/src/com/zst/xposed/halo/floatingwindow/LayoutScaling.java b/src/com/zst/xposed/halo/floatingwindow/LayoutScaling.java
index 6bdcedc..6d80be3 100644
--- a/src/com/zst/xposed/halo/floatingwindow/LayoutScaling.java
+++ b/src/com/zst/xposed/halo/floatingwindow/LayoutScaling.java
@@ -1,14 +1,8 @@
package com.zst.xposed.halo.floatingwindow;
import android.content.Context;
-import android.content.Intent;
-import android.content.pm.ActivityInfo;
-import android.content.pm.ResolveInfo;
-import android.content.res.TypedArray;
import android.util.DisplayMetrics;
-import android.util.TypedValue;
import android.view.Display;
-import android.view.Gravity;
import android.view.Window;
import android.view.WindowManager;
import de.robv.android.xposed.XSharedPreferences;
@@ -16,37 +10,16 @@
public class LayoutScaling {
public static XSharedPreferences pref;
- public static void applyThemeLess(Context context , Window mWindow){
- context.getTheme().applyStyle(R.style.Theme_Halo_FloatingWindow, true);
- appleFloating( context , mWindow);
- }
- public static void applyTheme(Context context , Window mWindow, String class_name ){
- try{
- Intent intent__ = new Intent(context.getPackageManager().getLaunchIntentForPackage(class_name));
- ResolveInfo rInfo = context.getPackageManager().resolveActivity(intent__, 0);
- ActivityInfo info = rInfo.activityInfo;
- TypedArray ta = context.obtainStyledAttributes(info.theme, com.android.internal.R.styleable.Window);
-
- TypedValue backgroundValue = ta.peekValue(com.android.internal.R.styleable.Window_windowBackground);
-
- if (backgroundValue != null && backgroundValue.toString().contains("light")) {
- context.getTheme().applyStyle(R.style.Theme_Halo_FloatingWindowLight, true);
- } else { //Checks if light or dark theme
- context.getTheme().applyStyle(R.style.Theme_Halo_FloatingWindow, true);
- }
-
- ta.recycle();
- }catch(Throwable t){
- context.getTheme().applyStyle(R.style.Theme_Halo_FloatingWindow, true);
- }
- appleFloating( context , mWindow);
- }
+
public static void appleFloating(Context context , Window mWindow){
pref = HaloFlagInject.pref;
pref.reload();
boolean isMovable = pref.getBoolean(Res.KEY_MOVABLE_WINDOW, Res.DEFAULT_MOVABLE_WINDOW);
- if(!isMovable){
- mWindow.setCloseOnTouchOutsideIfNotSet(true);
+ if(isMovable){
+ mWindow.setCloseOnTouchOutside(false);
+ mWindow.addFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL);
+ }else{
+ mWindow.setCloseOnTouchOutsideIfNotSet(true);
}
mWindow.setGravity(pref.getInt(Res.KEY_GRAVITY, Res.DEFAULT_GRAVITY));
mWindow.setFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND,WindowManager.LayoutParams.FLAG_DIM_BEHIND);
@@ -56,7 +29,7 @@
params.alpha = alp;
params.dimAmount = dimm;
- mWindow.setAttributes((android.view.WindowManager.LayoutParams) params);
+ mWindow.setAttributes(params);
scaleFloatingWindow(context,mWindow);
}
diff --git a/src/com/zst/xposed/halo/floatingwindow/MovableWindow.java b/src/com/zst/xposed/halo/floatingwindow/MovableWindow.java
index 2e47f46..e3ccfb6 100644
--- a/src/com/zst/xposed/halo/floatingwindow/MovableWindow.java
+++ b/src/com/zst/xposed/halo/floatingwindow/MovableWindow.java
@@ -77,8 +77,6 @@
@Override
public void handleLoadPackage(LoadPackageParam l) throws Throwable {
- pref.reload();
- if (!pref.getBoolean(Res.KEY_MOVABLE_WINDOW, Res.DEFAULT_MOVABLE_WINDOW)) return;
focusChangeContextFinder(l);
onCreateHook();
inject_dispatchTouchEvent();
@@ -151,6 +149,8 @@
Class<?> hookClass = findClass("com.android.internal.policy.impl.PhoneWindow", lpparam.classLoader);
XposedBridge.hookAllMethods(hookClass, "generateLayout", new XC_MethodHook() {
protected void afterHookedMethod(MethodHookParam param) throws Throwable {
+ pref.reload();
+ if (!pref.getBoolean(Res.KEY_MOVABLE_WINDOW, Res.DEFAULT_MOVABLE_WINDOW)) return;
if (!isHoloFloat) return;
Window window = (Window) param.thisObject;
@@ -274,6 +274,9 @@
private static void inject_dispatchTouchEvent() throws Throwable{
XposedBridge.hookAllMethods(Activity.class, "dispatchTouchEvent", new XC_MethodHook(){
protected void afterHookedMethod(MethodHookParam param) throws Throwable {
+ pref.reload();
+ if (!pref.getBoolean(Res.KEY_MOVABLE_WINDOW, Res.DEFAULT_MOVABLE_WINDOW)) return;
+
Activity a = (Activity)param.thisObject;
boolean isHoloFloat = (a.getIntent().getFlags() & Res.FLAG_FLOATING_WINDOW) == Res.FLAG_FLOATING_WINDOW;
if (!isHoloFloat) return;
@@ -320,9 +323,7 @@
WindowManager.LayoutParams params = mWindow.getAttributes();
params.x = (int)x;
params.y = (int)y;
- mWindow.setCloseOnTouchOutside(false);
- mWindow.addFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL);
- mWindow.setAttributes((android.view.WindowManager.LayoutParams) params);
+ mWindow.setAttributes(params);
}
public static int dp(int dp, Context c){ //convert dp to px
diff --git a/src/com/zst/xposed/halo/floatingwindow/movable/Movable.java b/src/com/zst/xposed/halo/floatingwindow/movable/Movable.java
index 8cf8734..bc70e3d 100644
--- a/src/com/zst/xposed/halo/floatingwindow/movable/Movable.java
+++ b/src/com/zst/xposed/halo/floatingwindow/movable/Movable.java
@@ -1,12 +1,9 @@
package com.zst.xposed.halo.floatingwindow.movable;
-import android.content.Context;
-import android.graphics.Color;
import android.view.Gravity;
import android.view.MotionEvent;
import android.view.View;
import android.view.Window;
-import android.view.WindowManager;
import android.view.WindowManager.LayoutParams;
public class Movable implements View.OnTouchListener {