简体   繁体   中英

Xposed - Code Doesn't Change SystemUI Quick Toggles BG as intended

I'm hooking into SystemUI Quick Toggles Background, and changed it according to selected color, i'm trying to change it to a static color first, not changeable one .

The problem is, when doing this code, sometimes it works, sometimes it won't work, checking the log, it's saying the same i typed .

When i lock the phone, it reverts back to original color .

As you can, it's a view, i have dex2jar the SystemUI, and added it as a library to my APK Project, and implemented the class and modified it .

What's the problem in it ?

import android.graphics.drawable.Drawable;
import android.graphics.drawable.GradientDrawable;
import android.graphics.drawable.InsetDrawable;
import android.util.Log;



import com.android.systemui.qs.QSContainer;

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


public class Test2 {

private static QSContainer mQSContainer;
static final int mSystemUIPrimaryColor = ColorsUtils.primary;

public static void hook()
{
    try
    {
        XposedHelpers.findAndHookMethod(QSContainer.class, "onFinishInflate", new XC_MethodHook()
        {
            @Override
            protected void afterHookedMethod(MethodHookParam HookParm)
                    throws Throwable {
                mQSContainer = (QSContainer) HookParm.thisObject;
                Log.i(Test1.TAG,"First Hook, Test2");
                SetUpBackground();
            }
        });
    }
    catch (Exception e)
    {
        XposedBridge.log(e);
    }
}


public static void SetUpBackground()
{
    Log.i(Test1.TAG, "SetUpBackground, Test2");
    GradientDrawable localGradientDrawable = new GradientDrawable();
    localGradientDrawable.setCornerRadius(2.0F);
    localGradientDrawable.setColor(mSystemUIPrimaryColor);
    Drawable localObject = new InsetDrawable(localGradientDrawable, 0, -2, 0, 0);
    mQSContainer.setBackground(localObject);

    //mQSContainer.setBackgroundColor(mSystemUIPrimaryColor);

}

}

My guess is that onFinishInflate is called only once and thus with subsequent redraws, the original will get redrawn. Try to hook the onDraw method of this class and inject the same modification there.

Try and update background in main thread :

// Get a handler that can be used to post to the main thread
Handler mainHandler = new Handler(context.getMainLooper());

Runnable myRunnable = new Runnable() {
    @Override 
    public void run() {
         SetUpBackground();
    } 
};
mainHandler.post(myRunnable);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM