[3.3.0][魔方] WindowManager#addView方式和PopupWindow#setContentView两种方式的aop替换,添加对View焦点事件的变化监听以响应魔方按键指令
This commit is contained in:
@@ -3,16 +3,16 @@ package com.mogo.launcher.lancet;
|
|||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.app.Dialog;
|
import android.app.Dialog;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.util.Log;
|
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
|
import android.view.ViewTreeObserver;
|
||||||
import android.view.Window;
|
import android.view.Window;
|
||||||
import android.view.WindowManager;
|
import android.view.WindowManager;
|
||||||
|
import android.widget.PopupWindow;
|
||||||
|
|
||||||
import androidx.annotation.Keep;
|
import androidx.annotation.Keep;
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
|
|
||||||
import com.knightboost.lancet.api.Origin;
|
import com.knightboost.lancet.api.Origin;
|
||||||
import com.knightboost.lancet.api.Scope;
|
import com.knightboost.lancet.api.Scope;
|
||||||
import com.knightboost.lancet.api.This;
|
import com.knightboost.lancet.api.This;
|
||||||
@@ -24,6 +24,7 @@ import com.knightboost.lancet.api.annotations.TargetMethod;
|
|||||||
import com.knightboost.lancet.api.annotations.Weaver;
|
import com.knightboost.lancet.api.annotations.Weaver;
|
||||||
import com.mogo.eagle.core.function.api.devatools.mofang.IMoGoMoFangProvider;
|
import com.mogo.eagle.core.function.api.devatools.mofang.IMoGoMoFangProvider;
|
||||||
import com.mogo.eagle.core.function.call.devatools.CallerDevaToolsManager;
|
import com.mogo.eagle.core.function.call.devatools.CallerDevaToolsManager;
|
||||||
|
import com.mogo.launcher.R;
|
||||||
|
|
||||||
@Keep
|
@Keep
|
||||||
@Weaver
|
@Weaver
|
||||||
@@ -58,31 +59,90 @@ public class WindowCallbackLancet {
|
|||||||
return dialog;
|
return dialog;
|
||||||
}
|
}
|
||||||
|
|
||||||
// @TargetClass(value = "android.view.WindowManager",scope = Scope.SELF)
|
@TargetClass(value = "android.view.WindowManager",scope = Scope.SELF)
|
||||||
// @TargetMethod(methodName = "addView")
|
@TargetMethod(methodName = "addView")
|
||||||
// @ReplaceInvoke
|
@ReplaceInvoke
|
||||||
// public static void proxyWindowManagerAddView(WindowManager manager, View view, ViewGroup.LayoutParams params) {
|
public static void proxyWindowManagerAddView(WindowManager manager, View view, ViewGroup.LayoutParams params) {
|
||||||
// manager.addView(view, params);
|
view.addOnAttachStateChangeListener(new View.OnAttachStateChangeListener() {
|
||||||
// Log.d("XXXXXX", "--- add view ---- 1 ---");
|
private final GlobalFocusChangedListener listener = new GlobalFocusChangedListener();
|
||||||
// IMoGoMoFangProvider mofang = CallerDevaToolsManager.INSTANCE.mofang();
|
private boolean isAdd = false;
|
||||||
// if (mofang != null) {
|
@Override
|
||||||
// Log.d("XXXXXX", "--- add view ---- 2 ---");
|
public void onViewAttachedToWindow(@NonNull View v) {
|
||||||
// Window.Callback callback = mofang.provideWindowCallback(null);
|
try {
|
||||||
// view.addOnAttachStateChangeListener(new View.OnAttachStateChangeListener() {
|
v.getViewTreeObserver().addOnGlobalFocusChangeListener(listener);
|
||||||
// @Override
|
isAdd = true;
|
||||||
// public void onViewAttachedToWindow(@NonNull View v) {
|
} catch (Throwable t) {
|
||||||
// Log.d("XXXXXX", "--- add view ---- 3 ---");
|
t.printStackTrace();
|
||||||
// v.setOnKeyListener((v1, keyCode, event) -> {
|
}
|
||||||
// Log.d("XXXXXX", "--- add view ---- 4 ---");
|
}
|
||||||
// return callback.dispatchKeyEvent(event);
|
@Override
|
||||||
// });
|
public void onViewDetachedFromWindow(@NonNull View v) {
|
||||||
// }
|
try {
|
||||||
//
|
if (isAdd) {
|
||||||
// @Override
|
v.getViewTreeObserver().removeOnGlobalFocusChangeListener(listener);
|
||||||
// public void onViewDetachedFromWindow(@NonNull View v) {
|
}
|
||||||
//
|
} catch (Throwable t) {
|
||||||
// }
|
t.printStackTrace();
|
||||||
// });
|
}
|
||||||
// }
|
}
|
||||||
// }
|
});
|
||||||
|
manager.addView(view, params);
|
||||||
|
}
|
||||||
|
|
||||||
|
@TargetClass(value = "android.widget.PopupWindow",scope = Scope.ALL)
|
||||||
|
@TargetMethod(methodName = "setContentView")
|
||||||
|
@ReplaceInvoke
|
||||||
|
public static void proxyPopupWindowSetContentView(PopupWindow window, View view) {
|
||||||
|
view.addOnAttachStateChangeListener(new View.OnAttachStateChangeListener() {
|
||||||
|
private final GlobalFocusChangedListener listener = new GlobalFocusChangedListener();
|
||||||
|
private boolean isAdd = false;
|
||||||
|
@Override
|
||||||
|
public void onViewAttachedToWindow(@NonNull View v) {
|
||||||
|
try {
|
||||||
|
v.getViewTreeObserver().addOnGlobalFocusChangeListener(listener);
|
||||||
|
isAdd = true;
|
||||||
|
} catch (Throwable t) {
|
||||||
|
t.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public void onViewDetachedFromWindow(@NonNull View v) {
|
||||||
|
try {
|
||||||
|
if (isAdd) {
|
||||||
|
v.getViewTreeObserver().removeOnGlobalFocusChangeListener(listener);
|
||||||
|
}
|
||||||
|
} catch (Throwable t) {
|
||||||
|
t.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
window.setContentView(view);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class GlobalFocusChangedListener implements ViewTreeObserver.OnGlobalFocusChangeListener {
|
||||||
|
|
||||||
|
private Window.Callback mCallBack = null;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onGlobalFocusChanged(View oldFocus, View newFocus) {
|
||||||
|
if (newFocus != null) {
|
||||||
|
Object tag = newFocus.getTag(R.id.on_key_set);
|
||||||
|
if (tag == null) {
|
||||||
|
newFocus.setTag(R.id.on_key_set, 1);
|
||||||
|
newFocus.setOnKeyListener((v, keyCode, event) -> {
|
||||||
|
if (mCallBack == null) {
|
||||||
|
IMoGoMoFangProvider mofang = CallerDevaToolsManager.INSTANCE.mofang();
|
||||||
|
if (mofang != null) {
|
||||||
|
mCallBack = mofang.provideWindowCallback(null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (mCallBack != null) {
|
||||||
|
return mCallBack.dispatchKeyEvent(event);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
4
app/src/main/res/values/ids.xml
Normal file
4
app/src/main/res/values/ids.xml
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<resources>
|
||||||
|
<item name="on_key_set" type="id" />
|
||||||
|
</resources>
|
||||||
Reference in New Issue
Block a user