diff options
author | twellington <twellington@chromium.org> | 2016-02-03 16:47:37 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-02-04 00:48:58 +0000 |
commit | e5d3ee84dcf748465979c281f909ded08d49a942 (patch) | |
tree | ed726151b728814c56ac4a764d7cde6ee7fb56d5 | |
parent | ad971272a4d3c8125b58cc2a909496d519e0afbf (diff) | |
download | chromium_src-e5d3ee84dcf748465979c281f909ded08d49a942.zip chromium_src-e5d3ee84dcf748465979c281f909ded08d49a942.tar.gz chromium_src-e5d3ee84dcf748465979c281f909ded08d49a942.tar.bz2 |
Make DeviceFormFactor calculations non-static
Rather than caching the DeviceFormFactor isTablet boolean, recalculate
it every time it is requested. This allows for different activities
to have different isTablet versions, as well as a single activity to
change its value after it has been resized.
BUG=583117
Review URL: https://codereview.chromium.org/1660303003
Cr-Commit-Position: refs/heads/master@{#373398}
7 files changed, 34 insertions, 47 deletions
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/compositor/CompositorViewHolder.java b/chrome/android/java/src/org/chromium/chrome/browser/compositor/CompositorViewHolder.java index ef57345..7f881eb 100644 --- a/chrome/android/java/src/org/chromium/chrome/browser/compositor/CompositorViewHolder.java +++ b/chrome/android/java/src/org/chromium/chrome/browser/compositor/CompositorViewHolder.java @@ -113,6 +113,7 @@ public class CompositorViewHolder extends FrameLayout private View mView; private TabObserver mTabObserver; + private boolean mIsTablet; private boolean mEnableCompositorTabStrip; // Cache objects that should not be created frequently. @@ -204,6 +205,7 @@ public class CompositorViewHolder extends FrameLayout }; mEnableCompositorTabStrip = DeviceFormFactor.isTablet(getContext()); + mIsTablet = DeviceFormFactor.isTablet(getContext()); addOnLayoutChangeListener(new OnLayoutChangeListener() { @Override @@ -499,7 +501,7 @@ public class CompositorViewHolder extends FrameLayout if (mLayoutManager != null) { mLayoutManager.onUpdate(); - if (!DeviceFormFactor.isTablet(getContext()) && mControlContainer != null) { + if (!mIsTablet && mControlContainer != null) { if (mProgressBarDrawingInfo == null) mProgressBarDrawingInfo = new DrawingInfo(); mControlContainer.getProgressBarDrawingInfo(mProgressBarDrawingInfo); } else { diff --git a/chrome/android/java/src/org/chromium/chrome/browser/init/AsyncInitializationActivity.java b/chrome/android/java/src/org/chromium/chrome/browser/init/AsyncInitializationActivity.java index 807e4b4..bb851b9 100644 --- a/chrome/android/java/src/org/chromium/chrome/browser/init/AsyncInitializationActivity.java +++ b/chrome/android/java/src/org/chromium/chrome/browser/init/AsyncInitializationActivity.java @@ -175,10 +175,6 @@ public abstract class AsyncInitializationActivity extends AppCompatActivity impl return; } - // TODO(twellington): Move this call to #onConfigurationChanged() after we start handling - // activity resizes. See crbug.com/583117 for context. - DeviceFormFactor.onConfigurationChanged(); - super.onCreate(savedInstanceState); mOnCreateTimestampMs = SystemClock.elapsedRealtime(); mOnCreateTimestampUptimeMs = SystemClock.uptimeMillis(); diff --git a/chrome/android/java/src/org/chromium/chrome/browser/ntp/NewTabPage.java b/chrome/android/java/src/org/chromium/chrome/browser/ntp/NewTabPage.java index d781c3e..8765170 100644 --- a/chrome/android/java/src/org/chromium/chrome/browser/ntp/NewTabPage.java +++ b/chrome/android/java/src/org/chromium/chrome/browser/ntp/NewTabPage.java @@ -135,6 +135,8 @@ public class NewTabPage // Whether destroy() has been called. private boolean mIsDestroyed; + private boolean mIsTablet; + /** * Allows clients to listen for updates to the scroll changes of the search box on the * NTP. @@ -579,6 +581,8 @@ public class NewTabPage mNewTabPageView.initialize(mNewTabPageManager, isInSingleUrlBarMode(activity), mSearchProviderHasLogo); + mIsTablet = DeviceFormFactor.isTablet(activity); + RecordHistogram.recordBooleanHistogram( "NewTabPage.MobileIsUserOnline", NetworkChangeNotifier.isOnline()); } @@ -628,7 +632,7 @@ public class NewTabPage } private boolean isInSingleUrlBarMode(Context context) { - if (DeviceFormFactor.isTablet(context)) return false; + if (mIsTablet) return false; if (mOptOutPromoShown) return false; return mSearchProviderHasLogo; diff --git a/chrome/android/java/src/org/chromium/chrome/browser/ntp/RecentTabsExpandableListView.java b/chrome/android/java/src/org/chromium/chrome/browser/ntp/RecentTabsExpandableListView.java index 8614c90..905b40a0 100644 --- a/chrome/android/java/src/org/chromium/chrome/browser/ntp/RecentTabsExpandableListView.java +++ b/chrome/android/java/src/org/chromium/chrome/browser/ntp/RecentTabsExpandableListView.java @@ -21,12 +21,14 @@ public class RecentTabsExpandableListView extends ExpandableListView { private int mMaxListViewWidth; private int mSavedListPosition = 0; private int mSavedListTop = 0; + private boolean mIsTablet; /** * Constructor for inflating from XML. */ public RecentTabsExpandableListView(Context context, AttributeSet attrs) { super(context, attrs); + mIsTablet = DeviceFormFactor.isTablet(context); } @Override @@ -38,7 +40,7 @@ public class RecentTabsExpandableListView extends ExpandableListView { @Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { - if (!DeviceFormFactor.isTablet(getContext())) { + if (!mIsTablet) { super.onMeasure(widthMeasureSpec, heightMeasureSpec); return; } diff --git a/chrome/android/java/src/org/chromium/chrome/browser/omnibox/LocationBarLayout.java b/chrome/android/java/src/org/chromium/chrome/browser/omnibox/LocationBarLayout.java index 33b0a66..2363949 100644 --- a/chrome/android/java/src/org/chromium/chrome/browser/omnibox/LocationBarLayout.java +++ b/chrome/android/java/src/org/chromium/chrome/browser/omnibox/LocationBarLayout.java @@ -242,6 +242,8 @@ public class LocationBarLayout extends FrameLayout implements OnClickListener, private Runnable mShowSuggestions; + private boolean mIsTablet; + /** * Listener for receiving the messages related with interacting with the omnibox during startup. */ @@ -670,11 +672,12 @@ public class LocationBarLayout extends FrameLayout implements OnClickListener, public LocationBarLayout(Context context, AttributeSet attrs) { super(context, attrs); + mIsTablet = DeviceFormFactor.isTablet(context); + LayoutInflater.from(context).inflate(R.layout.location_bar, this, true); mNavigationButton = (ImageView) findViewById(R.id.navigation_button); assert mNavigationButton != null : "Missing navigation type view."; - mNavigationButtonType = DeviceFormFactor.isTablet(context) - ? NavigationButtonType.PAGE : NavigationButtonType.EMPTY; + mNavigationButtonType = mIsTablet ? NavigationButtonType.PAGE : NavigationButtonType.EMPTY; mSecurityButton = (ImageButton) findViewById(R.id.security_button); mSecurityIconType = ConnectionSecurityLevel.NONE; @@ -972,8 +975,7 @@ public class LocationBarLayout extends FrameLayout implements OnClickListener, } if (mUrlFocusChangeListener != null) mUrlFocusChangeListener.onUrlFocusChange(hasFocus); - changeLocationBarIcon( - (!DeviceFormFactor.isTablet(getContext()) || !hasFocus) && isSecurityButtonShown()); + changeLocationBarIcon((!mIsTablet || !hasFocus) && isSecurityButtonShown()); mUrlBar.setCursorVisible(hasFocus); if (mQueryInTheOmnibox) mUrlBar.setSelection(mUrlBar.getSelectionEnd()); @@ -1132,15 +1134,14 @@ public class LocationBarLayout extends FrameLayout implements OnClickListener, // Updates the navigation button based on the URL string private void updateNavigationButton() { - boolean isTablet = DeviceFormFactor.isTablet(getContext()); NavigationButtonType type = NavigationButtonType.EMPTY; - if (isTablet && !mSuggestionItems.isEmpty()) { + if (mIsTablet && !mSuggestionItems.isEmpty()) { // If there are suggestions showing, show the icon for the default suggestion. type = suggestionTypeToNavigationButtonType( mSuggestionItems.get(0).getSuggestion()); } else if (mQueryInTheOmnibox) { type = NavigationButtonType.MAGNIFIER; - } else if (isTablet) { + } else if (mIsTablet) { type = NavigationButtonType.PAGE; } @@ -1246,8 +1247,7 @@ public class LocationBarLayout extends FrameLayout implements OnClickListener, * @param enabled Whether the security button should be displayed. */ private void updateSecurityButton(boolean enabled) { - changeLocationBarIcon(enabled - && (!DeviceFormFactor.isTablet(getContext()) || !mUrlHasFocus)); + changeLocationBarIcon(enabled && (!mIsTablet || !mUrlHasFocus)); mSecurityButtonShown = enabled; updateLocationBarIconContainerVisibility(); } diff --git a/chrome/android/java/src/org/chromium/chrome/browser/omnibox/SuggestionView.java b/chrome/android/java/src/org/chromium/chrome/browser/omnibox/SuggestionView.java index 6ee89bb..a238a0a 100644 --- a/chrome/android/java/src/org/chromium/chrome/browser/omnibox/SuggestionView.java +++ b/chrome/android/java/src/org/chromium/chrome/browser/omnibox/SuggestionView.java @@ -93,6 +93,8 @@ class SuggestionView extends ViewGroup { private final int mPhoneUrlBarLeftOffsetPx; private final int mPhoneUrlBarLeftOffsetRtlPx; + private boolean mIsTablet; + /** * Constructs a new omnibox suggestion view. * @@ -177,6 +179,8 @@ class SuggestionView extends ViewGroup { TypedValue.COMPLEX_UNIT_DIP, PHONE_URL_BAR_LEFT_OFFSET_RTL_DP, getContext().getResources().getDisplayMetrics())); + + mIsTablet = DeviceFormFactor.isTablet(context); } @Override @@ -485,7 +489,7 @@ class SuggestionView extends ViewGroup { } classifications.add(0, new MatchClassification(0, MatchClassificationStyle.NONE)); - if (DeviceFormFactor.isTablet(getContext())) { + if (mIsTablet) { TextPaint tp = mContentsView.mTextLine1.getPaint(); mContentsView.mRequiredWidth = tp.measureText(fillIntoEdit, 0, fillIntoEdit.length()); @@ -688,7 +692,7 @@ class SuggestionView extends ViewGroup { protected void onDraw(Canvas canvas) { super.onDraw(canvas); - if (DeviceFormFactor.isTablet(getContext())) { + if (mIsTablet) { // Use the same image transform matrix as the navigation icon to ensure the same // scaling, which requires centering vertically based on the height of the // navigation icon view and not the image itself. @@ -768,7 +772,7 @@ class SuggestionView extends ViewGroup { mTextLeft = getSuggestionTextLeftPosition(); mTextRight = getSuggestionTextRightPosition(); boolean isRTL = ApiCompatibilityUtils.isLayoutRtl(this); - if (DeviceFormFactor.isTablet(getContext())) { + if (mIsTablet) { int textWidth = isRTL ? mTextRight : (r - l - mTextLeft); final float maxRequiredWidth = mSuggestionDelegate.getMaxRequiredWidth(); final float maxMatchContentsWidth = mSuggestionDelegate.getMaxMatchContentsWidth(); @@ -806,7 +810,7 @@ class SuggestionView extends ViewGroup { } private int getUrlBarLeftOffset() { - if (DeviceFormFactor.isTablet(getContext())) { + if (mIsTablet) { mUrlBar.getLocationOnScreen(mViewPositionHolder); return mViewPositionHolder[0]; } else { diff --git a/ui/android/java/src/org/chromium/ui/base/DeviceFormFactor.java b/ui/android/java/src/org/chromium/ui/base/DeviceFormFactor.java index 2077159..da99957 100644 --- a/ui/android/java/src/org/chromium/ui/base/DeviceFormFactor.java +++ b/ui/android/java/src/org/chromium/ui/base/DeviceFormFactor.java @@ -19,42 +19,21 @@ public class DeviceFormFactor { private static final int MINIMUM_TABLET_WIDTH_DP = 600; private static final int MINIMUM_LARGE_TABLET_WIDTH_DP = 720; - private static Boolean sIsTablet = null; - private static Boolean sIsLargeTablet = null; - /** * @param context Android's context. - * @return Whether the app is should treat the device as a tablet for layout. + * @return Whether the app should treat the device as a tablet for layout. */ @CalledByNative public static boolean isTablet(Context context) { - if (sIsTablet == null) { - int minimumScreenWidthDp = context.getResources().getConfiguration() - .smallestScreenWidthDp; - sIsTablet = minimumScreenWidthDp >= MINIMUM_TABLET_WIDTH_DP; - } - return sIsTablet; + int minimumScreenWidthDp = context.getResources().getConfiguration().smallestScreenWidthDp; + return minimumScreenWidthDp >= MINIMUM_TABLET_WIDTH_DP; } /** - * @return True if the current device's minimum dimension is larger than 720dp. + * @return True if the current screen's minimum dimension is larger than 720dp. */ public static boolean isLargeTablet(Context context) { - if (sIsLargeTablet == null) { - int minimumScreenWidthDp = context.getResources().getConfiguration() - .smallestScreenWidthDp; - sIsLargeTablet = minimumScreenWidthDp >= MINIMUM_LARGE_TABLET_WIDTH_DP; - } - return sIsLargeTablet; - } - - /** - * Resets form factor information. This method should be called due to a smallestScreenWidthDp - * change in the {@link android.content.res.Configuration}. - */ - public static void onConfigurationChanged() { - sIsTablet = null; - sIsLargeTablet = null; + int minimumScreenWidthDp = context.getResources().getConfiguration().smallestScreenWidthDp; + return minimumScreenWidthDp >= MINIMUM_LARGE_TABLET_WIDTH_DP; } - } |