From a3c74d10a7d6e2ae8520e73176f939011e726ccf Mon Sep 17 00:00:00 2001 From: Tony Wickham Date: Fri, 23 Oct 2015 11:43:47 -0700 Subject: Setting correct height for search bar widget options bundle. - Seperate search bar height from its top and bottom paddings - Report this height plus 8dps top and bottom for the widget options - Use a separate bottom padding to adjust spacing between QSB and the workspace - Add tests to verify the height of the search bar in both normal and tall modes (ran on Nexus 6, 7, and 10) Change-Id: Ia7557785d1b38194eee869d0460456e8f33447d5 --- .../launcher3/InvariantDeviceProfileTest.java | 75 ++++++++++++++++++++-- 1 file changed, 71 insertions(+), 4 deletions(-) (limited to 'tests') diff --git a/tests/src/com/android/launcher3/InvariantDeviceProfileTest.java b/tests/src/com/android/launcher3/InvariantDeviceProfileTest.java index a99ae4f95..db3f72f3a 100644 --- a/tests/src/com/android/launcher3/InvariantDeviceProfileTest.java +++ b/tests/src/com/android/launcher3/InvariantDeviceProfileTest.java @@ -15,15 +15,14 @@ */ package com.android.launcher3; +import android.content.res.Resources; +import android.graphics.Point; import android.graphics.PointF; +import android.graphics.Rect; import android.test.AndroidTestCase; import android.test.suitebuilder.annotation.SmallTest; import android.util.Log; -import com.android.launcher3.DeviceProfile; -import com.android.launcher3.InvariantDeviceProfile; -import com.android.launcher3.util.FocusLogic; - import java.util.ArrayList; /** @@ -123,4 +122,72 @@ public class InvariantDeviceProfileTest extends AndroidTestCase { // Add more tests for other devices, however, running them once on a single device is enough // for verifying that for a platform version, the WindowManager and DisplayMetrics is // working as intended. + + /** + * Make sure that the height for the QSB is what we expect in normal mode. + */ + public void testQsbNormalHeight() { + Resources resources = getContext().getResources(); + DeviceProfile landscapeProfile = mInvariantProfile.landscapeProfile; + DeviceProfile portraitProfile = mInvariantProfile.portraitProfile; + landscapeProfile.setSearchBarHeight(LauncherCallbacks.SEARCH_BAR_HEIGHT_NORMAL); + portraitProfile.setSearchBarHeight(LauncherCallbacks.SEARCH_BAR_HEIGHT_NORMAL); + Rect portraitBounds = portraitProfile.getSearchBarBounds(true); // RTL shouldn't matter. + int portraitHeight = (int) Utilities.dpiFromPx(portraitBounds.height(), + resources.getDisplayMetrics()); + Rect landscapeBounds = landscapeProfile.getSearchBarBounds(true); // RTL shouldn't matter. + int landscapeHeight = (int) Utilities.dpiFromPx(landscapeBounds.height(), + resources.getDisplayMetrics()); + if (portraitProfile.isTablet) { + assertEquals(8 + 48 + 24, portraitHeight); + } else { + assertEquals(8 + 48 + 12, portraitHeight); + } + // Make sure the height that we pass in the widget options bundle is the height of the + // search bar + 8dps padding top and bottom. + Point portraitDimens = portraitProfile.getSearchBarDimensForWidgetOpts(resources); + int portraitWidgetOptsHeight = portraitDimens.y; + Point landscapeDimens = landscapeProfile.getSearchBarDimensForWidgetOpts(resources); + int landscapeWidgetOptsHeight = landscapeDimens.y; + assertEquals(8 + 48 + 8, (int) Utilities.dpiFromPx(portraitWidgetOptsHeight, + resources.getDisplayMetrics())); + if (!landscapeProfile.isVerticalBarLayout()) { + assertEquals(portraitHeight, landscapeHeight); + assertEquals(portraitWidgetOptsHeight, landscapeWidgetOptsHeight); + } + } + + /** + * Make sure that the height for the QSB is what we expect in tall mode. + */ + public void testQsbTallHeight() { + Resources resources = getContext().getResources(); + DeviceProfile landscapeProfile = mInvariantProfile.landscapeProfile; + DeviceProfile portraitProfile = mInvariantProfile.portraitProfile; + landscapeProfile.setSearchBarHeight(LauncherCallbacks.SEARCH_BAR_HEIGHT_TALL); + portraitProfile.setSearchBarHeight(LauncherCallbacks.SEARCH_BAR_HEIGHT_TALL); + Rect portraitBounds = portraitProfile.getSearchBarBounds(true); // RTL shouldn't matter. + int portraitHeight = (int) Utilities.dpiFromPx(portraitBounds.height(), + resources.getDisplayMetrics()); + Rect landscapeBounds = landscapeProfile.getSearchBarBounds(true); // RTL shouldn't matter. + int landscapeHeight = (int) Utilities.dpiFromPx(landscapeBounds.height(), + resources.getDisplayMetrics()); + if (portraitProfile.isTablet) { + assertEquals(8 + 80 + 24, portraitHeight); + } else { + assertEquals(8 + 80 + 2, portraitHeight); + } + // Make sure the height that we pass in the widget options bundle is the height of the + // search bar + 8dps padding top and bottom. + Point portraitDimens = portraitProfile.getSearchBarDimensForWidgetOpts(resources); + int portraitWidgetOptsHeight = portraitDimens.y; + Point landscapeDimens = landscapeProfile.getSearchBarDimensForWidgetOpts(resources); + int landscapeWidgetOptsHeight = landscapeDimens.y; + assertEquals(8 + 80 + 8, (int) Utilities.dpiFromPx(portraitWidgetOptsHeight, + resources.getDisplayMetrics())); + if (!landscapeProfile.isVerticalBarLayout()) { + assertEquals(portraitHeight, landscapeHeight); + assertEquals(portraitWidgetOptsHeight, landscapeWidgetOptsHeight); + } + } } -- cgit v1.2.3