Skip to content
Permalink
Browse files

Backport Animation Controls for ICS/JB

Recents Page Open/Close animations do not work on ICS.
  • Loading branch information...
zst123 committed Dec 8, 2013
1 parent 9fb74de commit 5be4556b98724391557cd9eb48e28297d660e4d8
@@ -65,17 +65,6 @@ protected void onCreate(Bundle savedInstanceState) {
findPreference(Common.KEY_NOTIFICATION_CHOOSE_COLOR).setOnPreferenceClickListener(this);

final boolean sdk17 = Build.VERSION.SDK_INT >= 17;
final boolean sdk18 = Build.VERSION.SDK_INT >= 18;

Preference animation_control = findPreference(Common.KEY_ANIMATION_CONTROLS_PREF_SCREEN);
String summary = getResources().getString(R.string.anim_controls_main_summary);
if (!sdk18) { /* if not Android 4.3, use unsupported summary text */
summary = String.format(getResources().getString
(R.string.version_unsupported), "4.3", Build.VERSION.RELEASE);
}
animation_control.setSummary(summary);
animation_control.setEnabled(sdk18);
animation_control.setOnPreferenceClickListener(this);

Preference qs_random_color = findPreference(Common.KEY_NOTIFICATION_CHOOSE_COLOR);
String qs_summary = getResources().getString(R.string.notif_quick_settings_random_summary);
@@ -38,6 +38,7 @@
import android.content.IntentFilter;
import android.content.res.XModuleResources;
import android.content.res.XmlResourceParser;
import android.os.Build;
import android.view.WindowManager;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
@@ -67,8 +68,15 @@ public static void handleLoadPackage(LoadPackageParam lpparam){
mPref.reload();
Class<?> appTransition;
try{
appTransition = findClass("com.android.server.wm.AppTransition",
lpparam.classLoader);
if (Build.VERSION.SDK_INT >= 18) {
//Android 4.3 onwards
appTransition = findClass("com.android.server.wm.AppTransition",
lpparam.classLoader);
} else {
//Android 4.2 and below
appTransition = findClass("com.android.server.wm.WindowManagerService",
lpparam.classLoader);
}
}catch(Throwable e){
return;
//If can't find the class, return so other mods executed after this
@@ -89,8 +97,12 @@ protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
param.setResult(null);
}
};
XposedBridge.hookAllMethods(hookClass, "overridePendingAppTransitionScaleUp", checkNoOverrideAndReturn);
XposedBridge.hookAllMethods(hookClass, "overridePendingAppTransitionThumb", checkNoOverrideAndReturn);
try {
XposedBridge.hookAllMethods(hookClass, "overridePendingAppTransitionScaleUp", checkNoOverrideAndReturn);
XposedBridge.hookAllMethods(hookClass, "overridePendingAppTransitionThumb", checkNoOverrideAndReturn);
} catch (Throwable t){
// Method not found, user is on ICS
}
XposedBridge.hookAllMethods(hookClass, "overridePendingAppTransition", checkNoOverrideAndReturn);
}

@@ -128,7 +140,87 @@ protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
});
}

// Checks API level
private static void hookloadAnimation_mIsResId_mNextAppTransitionType(LoadPackageParam o, Class<?> cls) {
if (Build.VERSION.SDK_INT >= 18) {
hookNewLoadAnimation(o, cls);
} else {
hookOldApplyAnimationLocked(o, cls);
}
}

// Android 4.2 and below
private static void hookOldApplyAnimationLocked(LoadPackageParam o, final Class<?> cls) {
Class<?> appWindowToken = findClass("com.android.server.wm.AppWindowToken", o.classLoader);
XposedHelpers.findAndHookMethod(cls, "applyAnimationLocked", appWindowToken,
WindowManager.LayoutParams.class, int.class, boolean.class, new XC_MethodHook() {
@Override
protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
boolean displayFrozen = (Boolean) cls.getDeclaredField("mDisplayFrozen")
.get(param.thisObject);
boolean displayEnabled = (Boolean) cls.getDeclaredField("mDisplayEnabled")
.get(param.thisObject);
Object policy = cls.getDeclaredField("mPolicy").get(param.thisObject);
boolean screenOn = (Boolean) XposedHelpers.callMethod(policy, "isScreenOnFully");

if ((!displayFrozen && displayEnabled && screenOn) == false) {
return;
}

final Object window_token = param.args[0];
final WindowManager.LayoutParams lp = (WindowManager.LayoutParams) param.args[1];
final int transit = (Integer) param.args[2];
final boolean enter = (Boolean) param.args[3];

if ((Build.VERSION.SDK_INT <= 15)) { // ICS
String nextAppTransitionPackage = (String) Common.getReflection(
param.thisObject, "mNextAppTransitionPackage");
if (nextAppTransitionPackage == null) {
Animation anim = retrieveAnimation(lp, transit, enter);
if (anim != null) {
XposedHelpers.callMethod(window_token, "setAnimation", applyDuration(anim));
param.setResult(true);
}
}
} else { // JB 4.1/4.2
int type = (Integer) Common.getReflection(param.thisObject,
"mNextAppTransitionType");
if (type == AppTransitionConstants.NEXT_TRANSIT_TYPE_CUSTOM ||
type == AppTransitionConstants.NEXT_TRANSIT_TYPE_SCALE_UP ||
type == AppTransitionConstants.NEXT_TRANSIT_TYPE_SCALE_UP)
return;
Animation result = retrieveAnimation(lp, transit, enter);
Object appAnimator = window_token.getClass().getDeclaredField("mAppAnimator")
.get(window_token);
if (result != null) {
XposedHelpers.callMethod(appAnimator, "setAnimation",
applyDuration(result), false);
param.setResult(true);
}
}
}

@Override
protected void afterHookedMethod(MethodHookParam param) throws Throwable {
// To set duration for default animation also.
Object animator;
if ((Build.VERSION.SDK_INT <= 15)) { // ICS
animator = param.args[0];
} else { // JB
final Object window_token = param.args[0];
animator = window_token.getClass().getDeclaredField("mAppAnimator")
.get(window_token);
}
Animation anim = (Animation) animator.getClass().getDeclaredField("animation")
.get(animator);
XposedHelpers.callMethod(animator, "setAnimation", applyDuration(anim));
param.setResult(applyDuration((Animation) param.getResult()));
}
});
}

// Android 4.3 onwards only
private static void hookNewLoadAnimation(LoadPackageParam o, Class<?> cls) {
XposedHelpers.findAndHookMethod(cls, "loadAnimation", WindowManager.LayoutParams.class,
int.class, boolean.class, int.class, int.class, new XC_MethodHook(){
@Override

0 comments on commit 5be4556

Please sign in to comment.
You can’t perform that action at this time.