package com.ceco.gm2.gravitybox;

import de.robv.android.xposed.XC_MethodHook;
import de.robv.android.xposed.XSharedPreferences;
import de.robv.android.xposed.XposedBridge;
import de.robv.android.xposed.XposedHelpers;

public class ModElectronBeam {
    private static final String TAG = "ModElectronBeam";
    private static final String CLASS_DISPLAY_POWER_STATE = "com.android.server.power.DisplayPowerState";

    public static void initZygote(final XSharedPreferences prefs) {
        try {
            final Class<?> clsDisplayPowerState = XposedHelpers.findClass(CLASS_DISPLAY_POWER_STATE, null);

            XposedHelpers.findAndHookMethod(clsDisplayPowerState, "prepareElectronBeam", int.class, 
                    new XC_MethodHook() {
                @Override
                protected void beforeHookedMethod(final MethodHookParam param) throws Throwable {
                    prefs.reload();
                    int ebMode = 
                            prefs.getBoolean(GravityBoxSettings.PREF_KEY_CRT_OFF_EFFECT, false) ? 1 : 2;
                    param.args[0] = ebMode;
                }
                
            });
            
        } catch (Exception e) {
            XposedBridge.log(e);
        }
    }
}
@@ -29,16 +29,58 @@
 box;%0D%0A%0D%0A
+import android.animation.ObjectAnimator;%0D%0A
 import d
@@ -117,16 +117,16 @@
 dHook;%0D%0A
-
 import d
@@ -457,16 +457,133 @@
 State%22;%0D
+%0A    private static final String CLASS_DISPLAY_POWER_CONTROLLER = %22com.android.server.power.DisplayPowerController%22;%0D
 %0A%0D%0A    p
@@ -769,16 +769,134 @@
  null);%0D
+%0A            final Class%3C?%3E clsDisplaPowerController = XposedHelpers.findClass(CLASS_DISPLAY_POWER_CONTROLLER, null);%0D
 %0A%0D%0A     
@@ -1434,24 +1434,26 @@
        %7D);%0D%0A
+%0D%0A
             
@@ -1444,32 +1444,560 @@
 %0D%0A%0D%0A            
+XposedHelpers.findAndHookMethod(clsDisplaPowerController, %22initialize%22, new XC_MethodHook() %7B%0D%0A%0D%0A                @Override%0D%0A                protected void afterHookedMethod(final MethodHookParam param) throws Throwable %7B%0D%0A                    ObjectAnimator oa = (ObjectAnimator) %0D%0A                            XposedHelpers.getObjectField(param.thisObject, %22mElectronBeamOffAnimator%22);%0D%0A                    if (oa != null) %7B%0D%0A                        oa.setDuration(400);%0D%0A                    %7D%0D%0A                %7D%0D%0A            %7D);
 %0D%0A        %7D catc

fix CRT screen off animation On some ROMs, the duration of ElectronBeam Off animation is set too low preventing CRT screen off effect to work. Let's use default AOSP value - 400ms