Skip to content
This repository has been archived by the owner on Sep 15, 2024. It is now read-only.

Commit

Permalink
feat: fix transition animation for android 14+
Browse files Browse the repository at this point in the history
  • Loading branch information
mkx173 committed Apr 11, 2024
1 parent 8e16428 commit 93f1e24
Show file tree
Hide file tree
Showing 4 changed files with 175 additions and 94 deletions.
6 changes: 3 additions & 3 deletions app/src/main/java/gm/tieba/tabswitch/XposedInit.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
import gm.tieba.tabswitch.hooker.Obfuscated;
import gm.tieba.tabswitch.hooker.TSPreference;
import gm.tieba.tabswitch.hooker.add.HistoryCache;
import gm.tieba.tabswitch.hooker.add.Ripple;
import gm.tieba.tabswitch.hooker.add.SaveImages;
import gm.tieba.tabswitch.hooker.add.SelectClipboard;
import gm.tieba.tabswitch.hooker.auto.AgreeNum;
Expand All @@ -40,6 +39,7 @@
import gm.tieba.tabswitch.hooker.auto.NotificationDetect;
import gm.tieba.tabswitch.hooker.auto.OpenSign;
import gm.tieba.tabswitch.hooker.auto.OriginSrc;
import gm.tieba.tabswitch.hooker.auto.TransitionAnimation;
import gm.tieba.tabswitch.hooker.deobfuscation.DeobfuscationHelper;
import gm.tieba.tabswitch.hooker.deobfuscation.DeobfuscationHooker;
import gm.tieba.tabswitch.hooker.deobfuscation.Matcher;
Expand Down Expand Up @@ -141,7 +141,6 @@ protected void afterHookedMethod(MethodHookParam param) throws Throwable {
new ContentFilter(),
new FrsPageFilter(),
new HistoryCache(),
new Ripple(),
new SaveImages(),
new AutoSign(),
new OpenSign(),
Expand All @@ -157,7 +156,8 @@ protected void afterHookedMethod(MethodHookParam param) throws Throwable {
new NotificationDetect(),
new PurgeVideo(),
new SelectClipboard(),
new UserFilter()
new UserFilter(),
new TransitionAnimation()
);
final var matchers = new ArrayList<Obfuscated>(hookers.size() + 2);
matchers.add(new TbToast());
Expand Down
30 changes: 21 additions & 9 deletions app/src/main/java/gm/tieba/tabswitch/hooker/TSPreference.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
package gm.tieba.tabswitch.hooker;

import static gm.tieba.tabswitch.hooker.TSPreferenceHelper.createButton;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.Intent;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.Process;
import android.text.TextUtils;
Expand Down Expand Up @@ -84,7 +87,7 @@ protected void afterHookedMethod(final MethodHookParam param) throws Throwable {
final var parent = (RelativeLayout) contentView.getChildAt(0);
final var scroll = (ScrollView) parent.getChildAt(0);
final var containerView = (LinearLayout) scroll.getChildAt(0);
containerView.addView(TSPreferenceHelper.createButton(MAIN, null, true,
containerView.addView(createButton(MAIN, null, true,
v -> startRootPreferenceActivity(activity)), 11);
}
});
Expand Down Expand Up @@ -179,7 +182,7 @@ private LinearLayout createRootPreference(final Activity activity) {
final TSPreferenceHelper.PreferenceLayout preferenceLayout = new TSPreferenceHelper.PreferenceLayout(activity);

preferenceLayout.addView(TSPreferenceHelper.createTextView(isPurgeEnabled ? "轻车简从" : "净化界面"));
preferenceLayout.addView(TSPreferenceHelper.createButton(MODIFY_TAB, null, true, v -> {
preferenceLayout.addView(createButton(MODIFY_TAB, null, true, v -> {
final Intent intent = new Intent().setClassName(activity, PROXY_ACTIVITY);
intent.putExtra("proxyPage", MODIFY_TAB);
activity.startActivity(intent);
Expand All @@ -199,7 +202,6 @@ private LinearLayout createRootPreference(final Activity activity) {

preferenceLayout.addView(TSPreferenceHelper.createTextView(isPurgeEnabled ? "别出新意" : "增加功能"));
preferenceLayout.addView(new SwitchButtonHolder(activity, "浏览历史增加搜索", "history_cache", SwitchButtonHolder.TYPE_SWITCH));
preferenceLayout.addView(new SwitchButtonHolder(activity, "楼层增加点按效果", "ripple", SwitchButtonHolder.TYPE_SWITCH));
preferenceLayout.addView(new SwitchButtonHolder(activity, "长按下载保存全部图片", "save_images", SwitchButtonHolder.TYPE_SWITCH));
preferenceLayout.addView(new SwitchButtonHolder(activity, "弹窗自由复制", "select_clipboard", SwitchButtonHolder.TYPE_SWITCH));

Expand Down Expand Up @@ -245,14 +247,14 @@ private LinearLayout createRootPreference(final Activity activity) {
preferenceLayout.addView(new SwitchButtonHolder(activity, "禁用帖子手势", "forbid_gesture", SwitchButtonHolder.TYPE_SWITCH));
preferenceLayout.addView(new SwitchButtonHolder(activity, "用赞踩差数代替赞数", "agree_num", SwitchButtonHolder.TYPE_SWITCH));
preferenceLayout.addView(new SwitchButtonHolder(activity, "禁止检测通知开启状态", "notification_detect", SwitchButtonHolder.TYPE_SWITCH));
preferenceLayout.addView(TSPreferenceHelper.createButton(TRACE, "希望有一天不再需要贴吧TS", true, v -> {
preferenceLayout.addView(createButton(TRACE, "希望有一天不再需要贴吧TS", true, v -> {
final Intent intent = new Intent().setClassName(activity, PROXY_ACTIVITY);
intent.putExtra("proxyPage", TRACE);
activity.startActivity(intent);
}));

preferenceLayout.addView(TSPreferenceHelper.createTextView(isPurgeEnabled ? "关于就是关于" : "关于"));
preferenceLayout.addView(TSPreferenceHelper.createButton("作者", "GM", true, v -> {
preferenceLayout.addView(createButton("作者", "GM", true, v -> {
sCount++;
if (sCount % 3 == 0) {
TbToast.showTbToast(TSPreferenceHelper.randomToast(), TbToast.LENGTH_SHORT);
Expand All @@ -262,19 +264,19 @@ private LinearLayout createRootPreference(final Activity activity) {
activity.recreate();
}
}));
preferenceLayout.addView(TSPreferenceHelper.createButton("源代码", "想要小星星", true, v -> {
preferenceLayout.addView(createButton("源代码", "想要小星星", true, v -> {
final Intent intent = new Intent();
intent.setAction("android.intent.action.VIEW");
intent.setData(Uri.parse("https://github.com/GuhDoy/TiebaTS"));
activity.startActivity(intent);
}));
preferenceLayout.addView(TSPreferenceHelper.createButton("TG群", "及时获取更新", true, v -> {
preferenceLayout.addView(createButton("TG群", "及时获取更新", true, v -> {
final Intent intent = new Intent();
intent.setAction("android.intent.action.VIEW");
intent.setData(Uri.parse("https://t.me/TabSwitch"));
activity.startActivity(intent);
}));
preferenceLayout.addView(TSPreferenceHelper.createButton("版本", String.format(Locale.CHINA, "%s_%d", BuildConfig.VERSION_NAME, BuildConfig.VERSION_CODE), true, v -> {
preferenceLayout.addView(createButton("版本", String.format(Locale.CHINA, "%s_%d", BuildConfig.VERSION_NAME, BuildConfig.VERSION_CODE), true, v -> {
final Intent intent = new Intent();
intent.setAction("android.intent.action.VIEW");
intent.setData(Uri.parse("https://github.com/GuhDoy/TiebaTS/releases"));
Expand All @@ -290,6 +292,16 @@ private LinearLayout createModifyTabPreference(final Activity activity) {
preferenceLayout.addView(new SwitchButtonHolder(activity, "隐藏进吧", "enter_forum", SwitchButtonHolder.TYPE_SWITCH));
preferenceLayout.addView(new SwitchButtonHolder(activity, "隐藏发帖", "write_thread", SwitchButtonHolder.TYPE_SWITCH));
preferenceLayout.addView(new SwitchButtonHolder(activity, "隐藏消息", "im_message", SwitchButtonHolder.TYPE_SWITCH));
preferenceLayout.addView(TSPreferenceHelper.createTextView("其他"));
SwitchButtonHolder transitionAnimation = new SwitchButtonHolder(activity, "修复过渡动画", "transition_animation", SwitchButtonHolder.TYPE_SWITCH);
transitionAnimation.setOnButtonClickListener(v -> {
if (!(Build.VERSION.SDK_INT >= 34 && DeobfuscationHelper.isTbSatisfyVersionRequirement("12.58.2.1", DeobfuscationHelper.getTbVersion(getContext())))) {
TbToast.showTbToast("当前贴吧版本不支持此功能", TbToast.LENGTH_SHORT);
} else {
transitionAnimation.bdSwitch.changeState();
}
});
preferenceLayout.addView(transitionAnimation);
return preferenceLayout;
}

Expand All @@ -305,7 +317,7 @@ private LinearLayout createHidePreference(final Activity activity) {
preferenceLayout.addView(new SwitchButtonHolder(activity, "检测 Xposed", "check_xposed", SwitchButtonHolder.TYPE_SWITCH));
preferenceLayout.addView(new SwitchButtonHolder(activity, "检测模块", "check_module", SwitchButtonHolder.TYPE_SWITCH));
preferenceLayout.addView(new SwitchButtonHolder(activity, "检测堆栈(重启才能真正生效)", "check_stack_trace", SwitchButtonHolder.TYPE_SWITCH));
preferenceLayout.addView(TSPreferenceHelper.createButton(isPurgeEnabled ? "捏捏尾巴" : "检测模块", String.valueOf(Process.myPid()), true, v ->
preferenceLayout.addView(createButton(isPurgeEnabled ? "捏捏尾巴" : "检测模块", String.valueOf(Process.myPid()), true, v ->
new TraceChecker(preferenceLayout).checkAll()));
TraceChecker.sChildCount = preferenceLayout.getChildCount();
return preferenceLayout;
Expand Down
82 changes: 0 additions & 82 deletions app/src/main/java/gm/tieba/tabswitch/hooker/add/Ripple.java

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
package gm.tieba.tabswitch.hooker.auto;

import android.app.Activity;

import androidx.annotation.NonNull;

import de.robv.android.xposed.XC_MethodReplacement;
import de.robv.android.xposed.XposedHelpers;
import gm.tieba.tabswitch.XposedContext;
import gm.tieba.tabswitch.hooker.IHooker;

public class TransitionAnimation extends XposedContext implements IHooker {

private Class<?> activityPendingTransitionFactory;
private int CHAT_SQUARE_FADE_IN;
private int CHAT_SQUARE_FADE_OUT;
private int RES_BIG_IMAGE_IN_FROM_RIGHT;
private int RES_BIG_IMAGE_OUT_TO_RIGHT;
private int RES_CUSTOM_FADE_IN;
private int RES_CUSTOM_FADE_OUT;
private int RES_CUSTOM_IN_FROM_RIGHT;
private int RES_CUSTOM_OUT_TO_RIGHT;
private int RES_FADE_OUT;
private int RES_NFADE_IN;
private int RES_NORMAL_IN_FROM_BOTTOM;
private int RES_NORMAL_IN_FROM_LEFT;
private int RES_NORMAL_IN_FROM_RIGHT;
private int RES_NORMAL_OUT_TO_BOTTOM;
private int RES_NORMAL_OUT_TO_LEFT;
private int RES_NORMAL_OUT_TO_RIGHT;

@NonNull
@Override
public String key() {
return "transition_animation";
}

@Override
public void hook() throws Throwable {
activityPendingTransitionFactory = XposedHelpers.findClass("com.baidu.tbadk.ActivityPendingTransitionFactory", sClassLoader);

CHAT_SQUARE_FADE_IN = XposedHelpers.getStaticIntField(activityPendingTransitionFactory, "CHAT_SQUARE_FADE_IN");
CHAT_SQUARE_FADE_OUT = XposedHelpers.getStaticIntField(activityPendingTransitionFactory, "CHAT_SQUARE_FADE_OUT");
RES_BIG_IMAGE_IN_FROM_RIGHT = XposedHelpers.getStaticIntField(activityPendingTransitionFactory, "RES_BIG_IMAGE_IN_FROM_RIGHT");
RES_BIG_IMAGE_OUT_TO_RIGHT = XposedHelpers.getStaticIntField(activityPendingTransitionFactory, "RES_BIG_IMAGE_OUT_TO_RIGHT");
RES_CUSTOM_FADE_IN = XposedHelpers.getStaticIntField(activityPendingTransitionFactory, "RES_CUSTOM_FADE_IN");
RES_CUSTOM_FADE_OUT = XposedHelpers.getStaticIntField(activityPendingTransitionFactory, "RES_CUSTOM_FADE_OUT");
RES_CUSTOM_IN_FROM_RIGHT = XposedHelpers.getStaticIntField(activityPendingTransitionFactory, "RES_CUSTOM_IN_FROM_RIGHT");
RES_CUSTOM_OUT_TO_RIGHT = XposedHelpers.getStaticIntField(activityPendingTransitionFactory, "RES_CUSTOM_OUT_TO_RIGHT");
RES_FADE_OUT = XposedHelpers.getStaticIntField(activityPendingTransitionFactory, "RES_FADE_OUT");
RES_NFADE_IN = XposedHelpers.getStaticIntField(activityPendingTransitionFactory, "RES_NFADE_IN");
RES_NORMAL_IN_FROM_BOTTOM = XposedHelpers.getStaticIntField(activityPendingTransitionFactory, "RES_NORMAL_IN_FROM_BOTTOM");
RES_NORMAL_IN_FROM_LEFT = XposedHelpers.getStaticIntField(activityPendingTransitionFactory, "RES_NORMAL_IN_FROM_LEFT");
RES_NORMAL_IN_FROM_RIGHT = XposedHelpers.getStaticIntField(activityPendingTransitionFactory, "RES_NORMAL_IN_FROM_RIGHT");
RES_NORMAL_OUT_TO_BOTTOM = XposedHelpers.getStaticIntField(activityPendingTransitionFactory, "RES_NORMAL_OUT_TO_BOTTOM");
RES_NORMAL_OUT_TO_LEFT = XposedHelpers.getStaticIntField(activityPendingTransitionFactory, "RES_NORMAL_OUT_TO_LEFT");
RES_NORMAL_OUT_TO_RIGHT = XposedHelpers.getStaticIntField(activityPendingTransitionFactory, "RES_NORMAL_OUT_TO_RIGHT");

XposedHelpers.findAndHookMethod(
activityPendingTransitionFactory,
"enterExitAnimation",
"com.baidu.tbadk.TbPageContext", int.class,
new XC_MethodReplacement() {
@Override
protected Object replaceHookedMethod(MethodHookParam param) throws Throwable {
enterExitAnimation(param.args[0], (int) param.args[1]);
return null;
}
}
);

XposedHelpers.findAndHookMethod(
activityPendingTransitionFactory,
"closeAnimation",
"com.baidu.tbadk.TbPageContext", int.class,
new XC_MethodReplacement() {
@Override
protected Object replaceHookedMethod(MethodHookParam param) throws Throwable {
closeAnimation(param.args[0], (int) param.args[1]);
return null;
}
}
);
}

private void enterExitAnimation(Object tbPageContext, int i) {
Activity pageActivity = (Activity) XposedHelpers.callMethod(tbPageContext, "getPageActivity");
if (XposedHelpers.getStaticBooleanField(activityPendingTransitionFactory, "IS_CUSTOM_FROM_THIRD_PARTY")) {
i = 3;
}
switch (i) {
case 0:
pageActivity.overridePendingTransition(0, 0);
return;
case 1:
pageActivity.overridePendingTransition(RES_NORMAL_IN_FROM_RIGHT, RES_FADE_OUT);
return;
case 2:
pageActivity.overridePendingTransition(RES_BIG_IMAGE_IN_FROM_RIGHT, RES_FADE_OUT);
return;
case 3:
pageActivity.overridePendingTransition(RES_CUSTOM_IN_FROM_RIGHT, RES_CUSTOM_FADE_OUT);
return;
case 4:
pageActivity.overridePendingTransition(RES_NORMAL_IN_FROM_BOTTOM, RES_FADE_OUT);
return;
case 5:
pageActivity.overridePendingTransition(CHAT_SQUARE_FADE_IN, CHAT_SQUARE_FADE_OUT);
return;
case 6:
pageActivity.overridePendingTransition(RES_NORMAL_IN_FROM_LEFT, RES_FADE_OUT);
return;
default:
pageActivity.overridePendingTransition(RES_NORMAL_IN_FROM_RIGHT, RES_FADE_OUT);
return;
}
}

private void closeAnimation(Object tbPageContext, int i) {
Activity pageActivity = (Activity) XposedHelpers.callMethod(tbPageContext, "getPageActivity");
if (XposedHelpers.getStaticBooleanField(activityPendingTransitionFactory, "IS_CUSTOM_FROM_THIRD_PARTY")) {
i = 3;
}
switch (i) {
case 0:
pageActivity.overridePendingTransition(0, 0);
return;
case 1:
pageActivity.overridePendingTransition(RES_NFADE_IN, RES_NORMAL_OUT_TO_RIGHT);
return;
case 2:
pageActivity.overridePendingTransition(RES_NFADE_IN, RES_BIG_IMAGE_OUT_TO_RIGHT);
return;
case 3:
pageActivity.overridePendingTransition(RES_CUSTOM_FADE_IN, RES_CUSTOM_OUT_TO_RIGHT);
return;
case 4:
pageActivity.overridePendingTransition(RES_NFADE_IN, RES_NORMAL_OUT_TO_BOTTOM);
return;
case 5:
pageActivity.overridePendingTransition(CHAT_SQUARE_FADE_IN, CHAT_SQUARE_FADE_OUT);
return;
case 6:
pageActivity.overridePendingTransition(RES_NFADE_IN, RES_NORMAL_OUT_TO_LEFT);
return;
default:
pageActivity.overridePendingTransition(RES_NFADE_IN, RES_NORMAL_OUT_TO_RIGHT);
return;
}
}
}

0 comments on commit 93f1e24

Please sign in to comment.