Skip to content

Commit

Permalink
Fix Animation Control for Android 4.2
Browse files Browse the repository at this point in the history
1) Somehow Android 4.2 throws MethodNotFoundError even though it
clearly exists. So I added a backup method in case of a throwable.

(Kept original because XposedHelpers.findAndHookMethod uses cachine
while hookAllMethods don't Animation Controls is run every activity
change is we need to prevent performance loss if possible)

2) JB has an extra boolean in setAnimation method
  • Loading branch information
zst123 committed Dec 12, 2013
1 parent d7e0018 commit 5eb8b7f
Showing 1 changed file with 44 additions and 18 deletions.
62 changes: 44 additions & 18 deletions src/com/zst/xposed/xuimod/mods/AnimationControlsMod.java
Expand Up @@ -119,25 +119,47 @@ protected void afterHookedMethod(MethodHookParam param) throws Throwable {
}

private static void hookloadAnimation_animAttr(LoadPackageParam o, Class<?> clazz) {
XposedHelpers.findAndHookMethod(clazz, "loadAnimation",
WindowManager.LayoutParams.class, int.class, new XC_MethodHook(){
@Override
protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
int animAttr = (Integer) param.args[1];
if (animAttr >= 0) {
if (!mIsResId) return;

if (animAttr != 0) {
param.setResult(AnimationUtils.loadAnimation(mContext, animAttr));
}else{
param.setResult(null);
try {
XposedHelpers.findAndHookMethod(clazz, "loadAnimation",
WindowManager.LayoutParams.class, int.class, new XC_MethodHook() {
@Override
protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
int animAttr = (Integer) param.args[1];
if (animAttr >= 0) {
if (!mIsResId) return;

if (animAttr != 0) {
param.setResult(AnimationUtils
.loadAnimation(mContext, animAttr));
} else {
param.setResult(null);
}
/* If it equals zero, return null and skip the method since we have
* to skip the getCachedAnimations if mIsResId is true
*/
}
/* If it equals zero, return null and skip the method since we have
* to skip the getCachedAnimations if mIsResId is true
*/
}
}
});
});
} catch (Throwable e) {
XposedBridge.hookAllMethods(clazz, "loadAnimation", new XC_MethodHook() {
@Override
protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
if (param.args.length != 2) return;
if (param.args[0] instanceof WindowManager.LayoutParams
&& param.args[1] instanceof Integer) {
int animAttr = (Integer) param.args[1];
if (animAttr >= 0) {
if (!mIsResId) return;
if (animAttr != 0) {
param.setResult(AnimationUtils.loadAnimation(mContext, animAttr));
} else {
param.setResult(null);
}
}
}
}
});
}
}

// Checks API level
Expand Down Expand Up @@ -214,7 +236,11 @@ protected void afterHookedMethod(MethodHookParam param) throws Throwable {
Animation anim = (Animation) animator.getClass().getDeclaredField("animation")
.get(animator);
if (anim != null) {
XposedHelpers.callMethod(animator, "setAnimation", applyDuration(anim));
if ((Build.VERSION.SDK_INT <= 15)) {
XposedHelpers.callMethod(animator, "setAnimation", applyDuration(anim));
} else { // JB
XposedHelpers.callMethod(animator, "setAnimation", applyDuration(anim), false);
}
param.setResult(true);
}
}
Expand Down

0 comments on commit 5eb8b7f

Please sign in to comment.