Xpose实例分析-变色龙

主要分析状态背景变色那块

ColourChangerMod.java

WindowDecorActionBarHooks.java

ActionBarHooks.java

StatusBarViewHook.java

1.先看看Xposed各个回调具体执行,之前讲了是在XposedBridge的loadModules中执行。

private static void loadModule(String apk, String startClassName) {
......
// call the init(String) method of the module
	final Object moduleInstance = moduleClass.newInstance();
	if (startClassName == null) {//1 initZygote 2 hookLoadPackage 3 hookInitPackageResources
	if (moduleInstance instanceof IXposedHookZygoteInit) {
               //IXposedHookZygoteInit
	       IXposedHookZygoteInit.StartupParam param = new IXposedHookZygoteInit.StartupParam();
		param.modulePath = apk;
		((IXposedHookZygoteInit) moduleInstance).initZygote(param); 
	}
       if (moduleInstance instanceof IXposedHookLoadPackage)
                //IXposedHookLoadPackage
		hookLoadPackage(new IXposedHookLoadPackage.Wrapper((IXposedHookLoadPackage) moduleInstance));
        if (moduleInstance instanceof IXposedHookInitPackageResources)
               //IXposedHookInitPackageResources
		hookInitPackageResources(new IXposedHookInitPackageResources.Wrapper((IXposedHookInitPackageResources) moduleInstance));
	} else {
		if (moduleInstance instanceof IXposedHookCmdInit) {
                        //IXposedHookCmdInit
			IXposedHookCmdInit.StartupParam param = new IXposedHookCmdInit.StartupParam();
			param.modulePath = apk;
			param.startClassName = startClassName;
			((IXposedHookCmdInit) moduleInstance).initCmdApp(param);
			}
		}
......
}
ColourChangerMod.java

@Override
public void initZygote(StartupParam startupParam) throws Throwable {
......
      if (Utils.hasActionBar())
	new ActionBarHooks(mSettingsHelper);
}

@Override
public void handleLoadPackage(LoadPackageParam lpparam) throws Throwable {
......
        //hook actionbar here
	if (!lpparam.packageName.equals("com.android.systemui")) {
		new WindowDecorActionBarHooks(mSettingsHelper, lpparam);
			return;
	}
}
WindowDecorActionBarHooks.javat和ActionBarHooks.java差不多

public WindowDecorActionBarHooks(SettingsHelper settingsHelper, XC_LoadPackage.LoadPackageParam lpparam) {
......
         findAndHookMethod(WindowDecorActionBar, "setBackgroundDrawable", Drawable.class, new XC_MethodHook() {
......
                   Drawable drawable = (Drawable) param.args[0];//获得Drawable 
                   int color = Utils.getMainColorFromActionBarDrawable(drawable);//获得颜色
                  ColourChangerMod.sendColorChangeIntent(color, Utils.getIconColorForColor(color, defaultNormal, nvertedIconTint, mSettingsHelper.getHsvMax()), actionBar.getContext());//发送广播变色
}
}
ColourChangerMod.java收到广播后调用setStatusBarTint进行变色,ColourChangerMod类中之前提到的handleLoadPackage中对StatusBarView也进行了hook,StatusBarViewHook.java

@Override
protected void afterHookedMethod(MethodHookParam param) throws Throwable {
	mInstance.setStatusBarView((View) param.thisObject);
}
//ColourChangerMod.java
public void setStatusBarView(View view) {
	mStatusBarView = view;
	Utils.setViewBackground(mStatusBarView, mGradientDrawable);
}
//最后
public static void setViewBackground(View view, Drawable drawable) {
	if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN) {
		view.setBackground(drawable);
	} else {
		view.setBackgroundDrawable(drawable);
	}
}








评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值