Skip to content

Commit

Permalink
Merge pull request #17 from HChenX/main
Browse files Browse the repository at this point in the history
[新增] 快速切换上一个应用
  • Loading branch information
HChenX authored Nov 3, 2023
2 parents a187ac9 + 7cd8ac4 commit a344d65
Show file tree
Hide file tree
Showing 6 changed files with 156 additions and 29 deletions.
1 change: 0 additions & 1 deletion app/proguard-rules.pro
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
-keep class com.sevtinge.hyperceiler.utils.Helpers{boolean isModuleActive;}
-keep class com.sevtinge.hyperceiler.utils.Helpers{int XposedVersion;}
-keep class * extends com.sevtinge.hyperceiler.module.base.BaseHook
-keep class * extends com.sevtinge.hyperceiler.utils.hook.HookUtils
-keep class com.sevtinge.hyperceiler.ui.HideAppActivity
-keep class * extends com.sevtinge.hyperceiler.ui.fragment.base.*
-keep class miui.drm.**{*;}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
import com.sevtinge.hyperceiler.module.hook.home.folder.SmallFolderIconBlur;
import com.sevtinge.hyperceiler.module.hook.home.gesture.DoubleTap;
import com.sevtinge.hyperceiler.module.hook.home.gesture.HotSeatSwipe;
import com.sevtinge.hyperceiler.module.hook.home.gesture.QuickBack;
import com.sevtinge.hyperceiler.module.hook.home.gesture.ShakeDevice;
import com.sevtinge.hyperceiler.module.hook.home.layout.HotSeatsHeight;
import com.sevtinge.hyperceiler.module.hook.home.layout.HotSeatsMarginBottom;
Expand Down Expand Up @@ -116,6 +117,7 @@ public void handleLoadPackage() {
initHook(LoadHostDir.INSTANCE);

// 手势
initHook(new QuickBack(), mPrefsMap.getBoolean("home_navigation_quick_back"));
initHook(new DoubleTap(), mPrefsMap.getInt("home_gesture_double_tap_action", 0) > 0);
initHook(new ScreenSwipe(), mPrefsMap.getInt("home_gesture_up_swipe_action", 0) > 0 ||
mPrefsMap.getInt("home_gesture_down_swipe_action", 0) > 0 ||
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
package com.sevtinge.hyperceiler.module.hook.home.gesture;

import android.app.ActivityManager;
import android.app.ActivityOptions;
import android.content.Context;

import com.sevtinge.hyperceiler.module.base.BaseHook;

import java.util.ArrayList;

import de.robv.android.xposed.XposedHelpers;

public class QuickBack extends BaseHook {
@Override
public void init() {
findAndHookMethod("com.miui.home.recents.GestureStubView",
"isDisableQuickSwitch", new MethodHook() {
@Override
protected void before(MethodHookParam param) {
param.setResult(false);
}
}
);

findAndHookMethod("com.miui.home.recents.GestureStubView",
"getNextTask", Context.class, boolean.class, int.class,
new MethodHook() {
@Override
protected void before(MethodHookParam param) {
Context context = (Context) param.args[0];
ActivityManager.RunningTaskInfo runningTask;
Object recentsModel = XposedHelpers.callStaticMethod(findClass("com.miui.home.recents.RecentsModel"), "getInstance", context);
Object taskLoader = XposedHelpers.callMethod(recentsModel, "getTaskLoader");
Object createLoadPlan = XposedHelpers.callMethod(taskLoader, "createLoadPlan", context);
XposedHelpers.callMethod(taskLoader, "preloadTasks", createLoadPlan, -1);
Object taskStack = XposedHelpers.callMethod(createLoadPlan, "getTaskStack");
ActivityOptions activityOptions = null;
if (taskStack == null || (int) XposedHelpers.callMethod(taskStack, "getTaskCount") == 0 || (runningTask = (ActivityManager.RunningTaskInfo) XposedHelpers.callMethod(recentsModel, "getRunningTask")) == null) {
param.setResult(null);
return;
}
ArrayList<?> stackTasks = (ArrayList<?>) XposedHelpers.callMethod(taskStack, "getStackTasks");
int size = stackTasks.size();
Object task = null;
int i2 = 0;
while (true) {
if (i2 >= size - 1) {
break;
} else if ((int) XposedHelpers.getObjectField(XposedHelpers.getObjectField(stackTasks.get(i2), "key"), "id") == runningTask.id) {
task = stackTasks.get(i2 + 1);
break;
} else {
i2++;
}
}
if (task == null && size >= 1 && "com.miui.home".equals(runningTask.baseActivity.getPackageName())) {
task = stackTasks.get(0);
}
if (task != null && XposedHelpers.getObjectField(task, "icon") == null) {
XposedHelpers.setObjectField(task, "icon", XposedHelpers.callMethod(taskLoader, "getAndUpdateActivityIcon",
XposedHelpers.getObjectField(task, "key"),
XposedHelpers.getObjectField(task, "taskDescription"),
context.getResources(), true
));
}
if (!(boolean) param.args[1] || task == null) {
param.setResult(task);
return;
}
int i = (int) param.args[2];
if (i == 0) {
activityOptions = ActivityOptions.makeCustomAnimation(context,
(int) XposedHelpers.callStaticMethod(
findClass("com.miui.home.recents.GestureStubView"),
"getAnimId", context, "recents_quick_switch_left_enter"),
(int) XposedHelpers.callStaticMethod(
findClass("com.miui.home.recents.GestureStubView"),
"getAnimId", context, "recents_quick_switch_left_exit"));
} else if (i == 1) {
activityOptions = ActivityOptions.makeCustomAnimation(context,
(int) XposedHelpers.callStaticMethod(
findClass("com.miui.home.recents.GestureStubView"),
"getAnimId", context, "recents_quick_switch_right_enter"),
(int) XposedHelpers.callStaticMethod(
findClass("com.miui.home.recents.GestureStubView"),
"getAnimId", context, "recents_quick_switch_right_exit"));
}
Object iActivityManager = XposedHelpers.callStaticMethod(findClass("android.app.ActivityManagerNative"), "getDefault");
if (iActivityManager != null) {
try {
if ((int) XposedHelpers.getObjectField(XposedHelpers.getObjectField(task, "key"), "windowingMode") == 3) {
if (activityOptions == null) {
activityOptions = ActivityOptions.makeBasic();
}
activityOptions.getClass().getMethod("setLaunchWindowingMode", Integer.class).invoke(activityOptions, 4);
}
XposedHelpers.callMethod(iActivityManager, "startActivityFromRecents",
XposedHelpers.getObjectField(
XposedHelpers.getObjectField(task, "key"),
"id"),
activityOptions == null ? null : activityOptions.toBundle());
param.setResult(task);
return;
} catch (Exception e) {
logE(TAG, "Error :" + e);
param.setResult(task);
return;
}
}
param.setResult(task);
}
}
);

}
}
2 changes: 2 additions & 0 deletions app/src/main/res/values-zh-rCN/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -806,6 +806,8 @@
<string name="home">系统桌面</string>
<string name="home_gesture">手势与导航</string>
<string name="home_navigation_title">导航</string>
<string name="home_navigation_quick_back">切换上一个应用</string>
<string name="home_navigation_quick_back_more">从屏幕两侧向内滑动并停顿,快速切换上一个应用</string>
<string name="home_navigation_back_area_height">返回手势区域高度</string>
<string name="home_navigation_back_area_width">返回手势区域宽度</string>
<string name="home_gesture_title2">手势</string>
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -790,6 +790,8 @@
<string name="home">System launcher</string>
<string name="home_gesture">Gesture and Navigation</string>
<string name="home_navigation_title">Navigation</string>
<string name="home_navigation_quick_back">Go back to previous app</string>
<string name="home_navigation_quick_back_more">Swipe across the screen starting from the edge to go back to previous app</string>
<string name="home_navigation_back_area_height">Back gesture area height</string>
<string name="home_navigation_back_area_width">Back gesture area width</string>
<string name="home_gesture_title2">Gesture</string>
Expand Down
62 changes: 34 additions & 28 deletions app/src/main/res/xml/home_gesture.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,78 +2,84 @@
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<PreferenceCategory android:title="@string/home_navigation_title">
<SwitchPreference
android:defaultValue="false"
android:key="prefs_key_home_navigation_quick_back"
android:summary="@string/home_navigation_quick_back_more"
android:title="@string/home_navigation_quick_back" />

<SeekBarPreferenceEx
android:title="@string/home_navigation_back_area_height"
android:key="prefs_key_home_navigation_back_area_height"
app:maxValue="100"
app:minValue="10"
android:defaultValue="60"
android:key="prefs_key_home_navigation_back_area_height"
android:title="@string/home_navigation_back_area_height"
app:defaultValueText="@string/array_default"
app:format="%d %%"
app:stepValue="5"
app:showSeekBarValue="true"/>
app:maxValue="100"
app:minValue="10"
app:showSeekBarValue="true"
app:stepValue="5" />

<SeekBarPreferenceEx
android:title="@string/home_navigation_back_area_width"
android:key="prefs_key_home_navigation_back_area_width"
app:maxValue="400"
app:minValue="100"
android:defaultValue="100"
android:key="prefs_key_home_navigation_back_area_width"
android:title="@string/home_navigation_back_area_width"
app:defaultValueText="@string/array_default"
app:format="%d %%"
app:stepValue="5"
app:showSeekBarValue="true"/>
app:maxValue="400"
app:minValue="100"
app:showSeekBarValue="true"
app:stepValue="5" />

</PreferenceCategory>

<PreferenceCategory android:title="@string/home_gesture_title2">
<Preference
android:fragment="com.sevtinge.hyperceiler.ui.fragment.sub.MultiActionSettings"
android:key="prefs_key_home_gesture_double_tap"
android:title="@string/home_gesture_double_tap"
android:summary="@string/home_gesture_double_tap_desc"
android:fragment="com.sevtinge.hyperceiler.ui.fragment.sub.MultiActionSettings"/>
android:title="@string/home_gesture_double_tap" />

<Preference
android:fragment="com.sevtinge.hyperceiler.ui.fragment.sub.MultiActionSettings"
android:key="prefs_key_home_gesture_shake"
android:title="@string/home_gesture_shake"
android:summary="@string/home_gesture_shake_desc"
android:fragment="com.sevtinge.hyperceiler.ui.fragment.sub.MultiActionSettings"/>
android:title="@string/home_gesture_shake" />

<Preference
android:fragment="com.sevtinge.hyperceiler.ui.fragment.sub.MultiActionSettings"
android:key="prefs_key_home_gesture_left_swipe"
android:title="@string/home_gesture_left_swipe"
android:summary="@string/home_gesture_left_swipe_desc"
android:fragment="com.sevtinge.hyperceiler.ui.fragment.sub.MultiActionSettings"/>
android:title="@string/home_gesture_left_swipe" />

<Preference
android:fragment="com.sevtinge.hyperceiler.ui.fragment.sub.MultiActionSettings"
android:key="prefs_key_home_gesture_right_swipe"
android:title="@string/home_gesture_right_swipe"
android:summary="@string/home_gesture_right_swipe_desc"
android:fragment="com.sevtinge.hyperceiler.ui.fragment.sub.MultiActionSettings"/>
android:title="@string/home_gesture_right_swipe" />

<Preference
android:fragment="com.sevtinge.hyperceiler.ui.fragment.sub.MultiActionSettings"
android:key="prefs_key_home_gesture_up_swipe"
android:title="@string/home_gesture_up_swipe"
android:summary="@string/home_gesture_up_swipe_desc"
android:fragment="com.sevtinge.hyperceiler.ui.fragment.sub.MultiActionSettings"/>
android:title="@string/home_gesture_up_swipe" />

<Preference
android:fragment="com.sevtinge.hyperceiler.ui.fragment.sub.MultiActionSettings"
android:key="prefs_key_home_gesture_down_swipe"
android:title="@string/home_gesture_down_swipe"
android:summary="@string/home_gesture_down_swipe_desc"
android:fragment="com.sevtinge.hyperceiler.ui.fragment.sub.MultiActionSettings"/>
android:title="@string/home_gesture_down_swipe" />

<Preference
android:fragment="com.sevtinge.hyperceiler.ui.fragment.sub.MultiActionSettings"
android:key="prefs_key_home_gesture_up_swipe2"
android:title="@string/home_gesture_up_swipe2"
android:summary="@string/home_gesture_up_swipe2_desc"
android:fragment="com.sevtinge.hyperceiler.ui.fragment.sub.MultiActionSettings"/>
android:title="@string/home_gesture_up_swipe2" />

<Preference
android:fragment="com.sevtinge.hyperceiler.ui.fragment.sub.MultiActionSettings"
android:key="prefs_key_home_gesture_down_swipe2"
android:title="@string/home_gesture_down_swipe2"
android:summary="@string/home_gesture_down_swipe2_desc"
android:fragment="com.sevtinge.hyperceiler.ui.fragment.sub.MultiActionSettings"/>
android:title="@string/home_gesture_down_swipe2" />

<!--Preference
android:key="prefs_key_home_gesture_swipe_and_stop"
Expand Down

0 comments on commit a344d65

Please sign in to comment.