diff options
| author | Chris Banes <chrisbanes@google.com> | 2016-06-20 10:38:02 +0100 |
|---|---|---|
| committer | Chris Banes <chrisbanes@google.com> | 2016-06-21 08:09:24 +0000 |
| commit | 3b925c1ab092cf63329845ecad73aa58db24c86d (patch) | |
| tree | a7a8486b65752c83b806cf3ac95c9c3f2743f5ee /core/java/android/widget/Toolbar.java | |
| parent | b809d1cb79b065443a1d8e19b2d5685c7c3383bd (diff) | |
Fix NPE in Toolbar - framework edition
Caused by super constructor calling non-final methods
which Toolbar overrides, and then tries to reference
final variables.
BUG: 28806107
Change-Id: Ieaf5f7611dbbf954e49c31e604aa2f7627248615
Diffstat (limited to 'core/java/android/widget/Toolbar.java')
| -rw-r--r-- | core/java/android/widget/Toolbar.java | 21 |
1 files changed, 15 insertions, 6 deletions
diff --git a/core/java/android/widget/Toolbar.java b/core/java/android/widget/Toolbar.java index 9cdb73ae51ce..0988c928cb26 100644 --- a/core/java/android/widget/Toolbar.java +++ b/core/java/android/widget/Toolbar.java @@ -161,7 +161,7 @@ public class Toolbar extends ViewGroup { private int mTitleMarginTop; private int mTitleMarginBottom; - private final RtlSpacingHelper mContentInsets = new RtlSpacingHelper(); + private RtlSpacingHelper mContentInsets; private int mContentInsetStartWithNavigation; private int mContentInsetEndWithActions; @@ -270,6 +270,7 @@ public class Toolbar extends ViewGroup { final int contentInsetRight = a.getDimensionPixelSize(R.styleable.Toolbar_contentInsetRight, 0); + ensureContentInsets(); mContentInsets.setAbsolute(contentInsetLeft, contentInsetRight); if (contentInsetStart != RtlSpacingHelper.UNDEFINED || @@ -463,13 +464,13 @@ public class Toolbar extends ViewGroup { */ public void setTitleMarginBottom(int margin) { mTitleMarginBottom = margin; - requestLayout(); } @Override public void onRtlPropertiesChanged(@ResolvedLayoutDir int layoutDirection) { super.onRtlPropertiesChanged(layoutDirection); + ensureContentInsets(); mContentInsets.setDirection(layoutDirection == LAYOUT_DIRECTION_RTL); } @@ -1092,6 +1093,7 @@ public class Toolbar extends ViewGroup { * @attr ref android.R.styleable#Toolbar_contentInsetStart */ public void setContentInsetsRelative(int contentInsetStart, int contentInsetEnd) { + ensureContentInsets(); mContentInsets.setRelative(contentInsetStart, contentInsetEnd); } @@ -1112,7 +1114,7 @@ public class Toolbar extends ViewGroup { * @attr ref android.R.styleable#Toolbar_contentInsetStart */ public int getContentInsetStart() { - return mContentInsets.getStart(); + return mContentInsets != null ? mContentInsets.getStart() : 0; } /** @@ -1132,7 +1134,7 @@ public class Toolbar extends ViewGroup { * @attr ref android.R.styleable#Toolbar_contentInsetEnd */ public int getContentInsetEnd() { - return mContentInsets.getEnd(); + return mContentInsets != null ? mContentInsets.getEnd() : 0; } /** @@ -1154,6 +1156,7 @@ public class Toolbar extends ViewGroup { * @attr ref android.R.styleable#Toolbar_contentInsetRight */ public void setContentInsetsAbsolute(int contentInsetLeft, int contentInsetRight) { + ensureContentInsets(); mContentInsets.setAbsolute(contentInsetLeft, contentInsetRight); } @@ -1174,7 +1177,7 @@ public class Toolbar extends ViewGroup { * @attr ref android.R.styleable#Toolbar_contentInsetLeft */ public int getContentInsetLeft() { - return mContentInsets.getLeft(); + return mContentInsets != null ? mContentInsets.getLeft() : 0; } /** @@ -1194,7 +1197,7 @@ public class Toolbar extends ViewGroup { * @attr ref android.R.styleable#Toolbar_contentInsetRight */ public int getContentInsetRight() { - return mContentInsets.getRight(); + return mContentInsets != null ? mContentInsets.getRight() : 0; } /** @@ -2128,6 +2131,12 @@ public class Toolbar extends ViewGroup { } } + private void ensureContentInsets() { + if (mContentInsets == null) { + mContentInsets = new RtlSpacingHelper(); + } + } + /** * Accessor to enable LayoutLib to get ActionMenuPresenter directly. */ |
