继承自 ImageView
KeyButtonDrawable
intensity为0时按键颜色为白色。
intensity为1时黑色为的调用堆栈:
java.lang.NullPointerException: Attempt to invoke virtual method 'int java.lang.String.length()' on a null object referenceat com.android.systemui.statusbar.policy.KeyButtonView.setDarkIntensity(KeyButtonView.java:459)at com.android.systemui.statusbar.phone.ButtonDispatcher.setDarkIntensity(ButtonDispatcher.java:225)at com.android.systemui.statusbar.phone.NavigationBarTransitions.applyDarkIntensity(NavigationBarTransitions.java:192)at com.android.systemui.statusbar.phone.LightBarTransitionsController.dispatchDark(LightBarTransitionsController.java:200)at com.android.systemui.statusbar.phone.LightBarTransitionsController.setIconTintInternal(LightBarTransitionsController.java:196)at com.android.systemui.statusbar.phone.LightBarTransitionsController.lambda$animateIconTint$0(LightBarTransitionsController.java:187)at com.android.systemui.statusbar.phone.LightBarTransitionsController.lambda$animateIconTint$0$LightBarTransitionsController(Unknown Source:0)at com.android.systemui.statusbar.phone.-$$Lambda$LightBarTransitionsController$PJRveQsGC7aANrqdSv3tRYb3x7c.onAnimationUpdate(Unknown Source:2)at android.animation.ValueAnimator.animateValue(ValueAnimator.java:1566)at android.animation.ValueAnimator.animateBasedOnTime(ValueAnimator.java:1357)at android.animation.ValueAnimator.doAnimationFrame(ValueAnimator.java:1489)at android.animation.AnimationHandler.doAnimationFrame(AnimationHandler.java:146)at android.animation.AnimationHandler.access$100(AnimationHandler.java:37)at android.animation.AnimationHandler$1.doFrame(AnimationHandler.java:54)at android.view.Choreographer$CallbackRecord.run(Choreographer.java:970)at android.view.Choreographer.doCallbacks(Choreographer.java:796)at android.view.Choreographer.doFrame(Choreographer.java:727)at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:957)at android.os.Handler.handleCallback(Handler.java:938)at android.os.Handler.dispatchMessage(Handler.java:99)at android.os.Looper.loop(Looper.java:223)at android.app.ActivityThread.main(ActivityThread.java:7677)at java.lang.reflect.Method.invoke(Native Method)at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)
Process: com.android.systemui, PID: 644
java.lang.NullPointerException: Attempt to invoke virtual method 'int java.lang.String.length()' on a null object referenceat com.android.systemui.statusbar.phone.LightBarTransitionsController.animateIconTint(LightBarTransitionsController.java:180)at com.android.systemui.statusbar.phone.LightBarTransitionsController.setIconsDark(LightBarTransitionsController.java:160)at com.android.systemui.statusbar.phone.LightBarController.updateStatus(LightBarController.java:223)at com.android.systemui.statusbar.phone.LightBarController.onStatusBarModeChanged(LightBarController.java:125)at com.android.systemui.statusbar.phone.LightBarController.onStatusBarAppearanceChanged(LightBarController.java:118)at com.android.systemui.statusbar.phone.StatusBar.onSystemBarAppearanceChanged(StatusBar.java:2299)at com.android.systemui.statusbar.CommandQueue$H.handleMessage(CommandQueue.java:1234)at android.os.Handler.dispatchMessage(Handler.java:106)at android.os.Looper.loop(Looper.java:223)at android.app.ActivityThread.main(ActivityThread.java:7677)at java.lang.reflect.Method.invoke(Native Method)at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)
哪里调用StatusBar的onSystemBarAppearanceChanged方法?
DisplayPolicy调用 onSystemBarAppearanceChanged 方法
待续。
public void setDarkIntensity(float intensity) {mState.mDarkIntensity = intensity;final int color = (int) ArgbEvaluator.getInstance().evaluate(intensity, mState.mLightColor, mState.mDarkColor);updateShadowAlpha();setColorFilter(new PorterDuffColorFilter(color, Mode.SRC_ATOP));
}
java.lang.NullPointerException: Attempt to invoke virtual method 'int java.lang.String.length()' on a null object referenceat com.android.systemui.statusbar.policy.KeyButtonDrawable.setColorFilter(KeyButtonDrawable.java:205)at com.android.systemui.statusbar.policy.KeyButtonDrawable.setDarkIntensity(KeyButtonDrawable.java:128)at com.android.systemui.statusbar.policy.KeyButtonView.setImageDrawable(KeyButtonView.java:353)at com.android.systemui.statusbar.phone.ButtonDispatcher.setImageDrawable(ButtonDispatcher.java:140)at com.android.systemui.statusbar.phone.NavigationBarView.updateNavButtonIcons(NavigationBarView.java:695)at com.android.systemui.statusbar.phone.NavigationBarView.reorient(NavigationBarView.java:1085)at com.android.systemui.statusbar.phone.NavigationBarView.onAttachedToWindow(NavigationBarView.java:1205)at android.view.View.dispatchAttachedToWindow(View.java:20479)at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:3489)at android.view.ViewGroup.addViewInner(ViewGroup.java:5278)at android.view.ViewGroup.addView(ViewGroup.java:5064)at android.view.ViewGroup.addView(ViewGroup.java:5004)at android.view.ViewGroup.addView(ViewGroup.java:4976)at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1308)at android.app.FragmentManagerImpl.addAddedFragments(FragmentManager.java:2431)at android.app.FragmentManagerImpl.executeOpsTogether(FragmentManager.java:2210)at android.app.FragmentManagerImpl.removeRedundantOperationsAndExecute(FragmentManager.java:2166)at android.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:2067)at android.app.FragmentManagerImpl$1.run(FragmentManager.java:742)at android.os.Handler.handleCallback(Handler.java:938)at android.os.Handler.dispatchMessage(Handler.java:99)at android.os.Looper.loop(Looper.java:223)at android.app.ActivityThread.main(ActivityThread.java:7677)at java.lang.reflect.Method.invoke(Native Method)at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)
KeyButtonDrawable的创建过程:
Process: com.android.systemui, PID: 644
android.view.InflateException: Binary XML file line #20 in com.android.systemui:layout/navigation_bar: Attempt to
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'int java.lang.String.length()' on a at com.android.systemui.statusbar.policy.KeyButtonDrawable.<init>(KeyButtonDrawable.java:108)at com.android.systemui.statusbar.policy.KeyButtonDrawable.<init>(KeyButtonDrawable.java:102)at com.android.systemui.statusbar.policy.KeyButtonDrawable.create(KeyButtonDrawable.java:512)at com.android.systemui.statusbar.policy.KeyButtonDrawable.create(KeyButtonDrawable.java:495)at com.android.systemui.statusbar.policy.KeyButtonDrawable.create(KeyButtonDrawable.java:476)at com.android.systemui.statusbar.policy.KeyButtonDrawable.create(KeyButtonDrawable.java:486)at com.android.systemui.statusbar.phone.NavigationBarView.getDrawable(NavigationBarView.java:607)at com.android.systemui.statusbar.phone.NavigationBarView.updateIcons(NavigationBarView.java:528)at com.android.systemui.statusbar.phone.NavigationBarView.reloadNavIcons(NavigationBarView.java:519)at com.android.systemui.statusbar.phone.NavigationBarView.onFinishInflate(NavigationBarView.java:931)at android.view.LayoutInflater.rInflate(LayoutInflater.java:1134)at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:1082)at android.view.LayoutInflater.inflate(LayoutInflater.java:680)at android.view.LayoutInflater.inflate(LayoutInflater.java:532)at com.android.systemui.statusbar.phone.NavigationBarFragment.onCreateView(NavigationBarFragment.java:496)at android.app.Fragment.performCreateView(Fragment.java:2505)at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1303)at android.app.FragmentManagerImpl.addAddedFragments(FragmentManager.java:2431)at android.app.FragmentManagerImpl.executeOpsTogether(FragmentManager.java:2210)at android.app.FragmentManagerImpl.removeRedundantOperationsAndExecute(FragmentManager.java:2166)at android.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:2067)at android.app.FragmentManagerImpl$1.run(FragmentManager.java:742)at android.os.Handler.handleCallback(Handler.java:938)at android.os.Handler.dispatchMessage(Handler.java:99)at android.os.Looper.loop(Looper.java:223)at android.app.ActivityThread.main(ActivityThread.java:7677)at java.lang.reflect.Method.invoke(Native Method)at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
在创建NavigationBarFragment的时候,获取 mDockedIcon的时候创建了一个KeyButtonDrawable。
Home Drawable的创建过程:
NavigationBarView 的 getHomeDrawable方法。
Home Button的创建过程:
home.xml 定义了 home 按键, 其图标是NavigationBarView的 mHomeDefaultIcon。
NavigationBarInflaterView的 createView方法inflate了一个 home 。
KeyButtonDrawable 绘制
canvas.drawBitmap(mState.mLastDrawnIcon, null, bounds, mIconPaint);
mLastDrawnIcon 就是资源文件的icon,