From 4543e6fdcf6103f8cbc3e30550bf6a08d76214dd Mon Sep 17 00:00:00 2001 From: Michal Kajda Date: Wed, 10 Jul 2013 11:12:25 -0700 Subject: [PATCH] Bug 889094 - NPE in BrowserToolbar due to late initialization of mFocusOrder. [r=sriram,bnicholson] --- mobile/android/base/BrowserToolbar.java | 53 +++++++++++++------------ 1 file changed, 27 insertions(+), 26 deletions(-) diff --git a/mobile/android/base/BrowserToolbar.java b/mobile/android/base/BrowserToolbar.java index 15f5a5e3bac..940f0123e21 100644 --- a/mobile/android/base/BrowserToolbar.java +++ b/mobile/android/base/BrowserToolbar.java @@ -232,6 +232,16 @@ public class BrowserToolbar extends GeckoRelativeLayout mMenuIcon = (GeckoImageView) findViewById(R.id.menu_icon); mActionItemBar = (LinearLayout) findViewById(R.id.menu_items); mHasSoftMenuButton = !HardwareUtils.hasMenuButton(); + + // We use different layouts on phones and tablets, so adjust the focus + // order appropriately. + if (HardwareUtils.isTablet()) { + mFocusOrder = Arrays.asList(mTabs, mBack, mForward, this, + mSiteSecurity, mReader, mStop, mActionItemBar, mMenu); + } else { + mFocusOrder = Arrays.asList(this, mSiteSecurity, mReader, mStop, + mTabs, mMenu); + } } @Override @@ -419,16 +429,6 @@ public class BrowserToolbar extends GeckoRelativeLayout } }); } - - // We use different layouts on phones and tablets, so adjust the focus - // order appropriately. - if (HardwareUtils.isTablet()) { - mFocusOrder = Arrays.asList(mTabs, mBack, mForward, this, - mSiteSecurity, mReader, mStop, mActionItemBar, mMenu); - } else { - mFocusOrder = Arrays.asList(this, mSiteSecurity, mReader, mStop, - mTabs, mMenu); - } } @Override @@ -893,26 +893,27 @@ public class BrowserToolbar extends GeckoRelativeLayout continue; } - if (prevView != null) { - if (view == mActionItemBar) { - final int childCount = mActionItemBar.getChildCount(); - if (childCount > 1) { - View firstChild = mActionItemBar.getChildAt(0); - firstChild.setNextFocusLeftId(prevView.getId()); - prevView.setNextFocusRightId(firstChild.getId()); + if (view == mActionItemBar) { + final int childCount = mActionItemBar.getChildCount(); + for (int child = 0; child < childCount; child++) { + View childView = mActionItemBar.getChildAt(child); + if (prevView != null) { + childView.setNextFocusLeftId(prevView.getId()); + prevView.setNextFocusRightId(childView.getId()); } - view = mActionItemBar.getChildAt(childCount - 1); + prevView = childView; } - - view.setNextFocusLeftId(prevView.getId()); - prevView.setNextFocusRightId(view.getId()); + } else { + if (prevView != null) { + view.setNextFocusLeftId(prevView.getId()); + prevView.setNextFocusRightId(view.getId()); + } + prevView = view; } + } - if (needsNewFocus) { - requestFocus(); - } - - prevView = view; + if (needsNewFocus) { + requestFocus(); } }