This repository has been archived by the owner on Sep 15, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: new dialog for selectable copying
- Loading branch information
Showing
4 changed files
with
101 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
80 changes: 80 additions & 0 deletions
80
app/src/main/java/gm/tieba/tabswitch/hooker/add/SelectClipboard.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
package gm.tieba.tabswitch.hooker.add; | ||
|
||
import android.app.Activity; | ||
import android.app.AlertDialog; | ||
import android.content.ClipboardManager; | ||
import android.content.Context; | ||
import android.view.View; | ||
import android.view.WindowManager; | ||
import android.widget.TextView; | ||
|
||
import androidx.annotation.NonNull; | ||
|
||
import java.util.List; | ||
|
||
import de.robv.android.xposed.XC_MethodReplacement; | ||
import de.robv.android.xposed.XposedHelpers; | ||
import gm.tieba.tabswitch.XposedContext; | ||
import gm.tieba.tabswitch.dao.AcRules; | ||
import gm.tieba.tabswitch.hooker.IHooker; | ||
import gm.tieba.tabswitch.hooker.Obfuscated; | ||
import gm.tieba.tabswitch.hooker.deobfuscation.Matcher; | ||
import gm.tieba.tabswitch.hooker.deobfuscation.MatcherProperties; | ||
import gm.tieba.tabswitch.hooker.deobfuscation.SmaliMatcher; | ||
import gm.tieba.tabswitch.util.ClassMatcherUtils; | ||
import gm.tieba.tabswitch.util.DisplayUtils; | ||
import gm.tieba.tabswitch.util.ReflectUtils; | ||
|
||
public class SelectClipboard extends XposedContext implements IHooker, Obfuscated { | ||
@NonNull | ||
@Override | ||
public String key() { | ||
return "select_clipboard"; | ||
} | ||
|
||
@Override | ||
public List<? extends Matcher> matchers() { | ||
return List.of( | ||
new SmaliMatcher("Landroid/text/ClipboardManager;->setText(Ljava/lang/CharSequence;)V", | ||
MatcherProperties.create().useClassMatcher(ClassMatcherUtils.className("com.baidu.tieba.tbadkCore.data.PostData"))) | ||
); | ||
} | ||
|
||
public void hook() throws Throwable { | ||
AcRules.findRule(matchers(), (matcher, clazz, method) -> { | ||
switch (matcher) { | ||
case "PostData/Landroid/text/ClipboardManager;->setText(Ljava/lang/CharSequence;)V": | ||
XposedHelpers.findAndHookMethod(clazz, sClassLoader, method, new XC_MethodReplacement() { | ||
@Override | ||
protected Object replaceHookedMethod(MethodHookParam param) throws Throwable { | ||
Object tbRichText = ReflectUtils.getObjectField(param.thisObject, "com.baidu.tbadk.widget.richText.TbRichText"); | ||
|
||
Activity currentActivity = ReflectUtils.getCurrentActivity(); | ||
AlertDialog alert = new AlertDialog.Builder(currentActivity, DisplayUtils.isLightMode(getContext()) ? | ||
android.R.style.Theme_DeviceDefault_Light_Dialog_Alert : android.R.style.Theme_DeviceDefault_Dialog_Alert) | ||
.setTitle("自由复制").setMessage(tbRichText.toString()) | ||
.setNeutralButton("复制全部", (dialogInterface, i) -> { | ||
ClipboardManager clipboardManager = (ClipboardManager) ReflectUtils.getTbadkCoreApplicationInst().getSystemService(Context.CLIPBOARD_SERVICE); | ||
clipboardManager.setText(tbRichText.toString()); | ||
}) | ||
.setPositiveButton("完成", null).create(); | ||
alert.show(); | ||
|
||
View messageView = alert.findViewById(android.R.id.message); | ||
if (messageView instanceof TextView) { | ||
((TextView) messageView).setTextIsSelectable(true); | ||
} | ||
|
||
WindowManager.LayoutParams layoutParams = new WindowManager.LayoutParams(); | ||
layoutParams.copyFrom(alert.getWindow().getAttributes()); | ||
layoutParams.width = DisplayUtils.getDisplayWidth(getContext()); | ||
alert.getWindow().setAttributes(layoutParams); | ||
|
||
return null; | ||
} | ||
}); | ||
break; | ||
} | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters