diff options
Diffstat (limited to 'src/com/android/launcher3/DeviceProfile.java')
-rw-r--r-- | src/com/android/launcher3/DeviceProfile.java | 718 |
1 files changed, 179 insertions, 539 deletions
diff --git a/src/com/android/launcher3/DeviceProfile.java b/src/com/android/launcher3/DeviceProfile.java index d6aadcee1..774594fe2 100644 --- a/src/com/android/launcher3/DeviceProfile.java +++ b/src/com/android/launcher3/DeviceProfile.java @@ -19,155 +19,102 @@ package com.android.launcher3; import android.appwidget.AppWidgetHostView; import android.content.ComponentName; import android.content.Context; -import android.content.res.Configuration; import android.content.res.Resources; import android.graphics.Paint; import android.graphics.Paint.FontMetrics; import android.graphics.Point; -import android.graphics.PointF; import android.graphics.Rect; import android.util.DisplayMetrics; -import android.view.Display; import android.view.Gravity; -import android.view.Surface; import android.view.View; import android.view.ViewGroup; import android.view.ViewGroup.LayoutParams; import android.view.ViewGroup.MarginLayoutParams; -import android.view.WindowManager; import android.widget.FrameLayout; import android.widget.LinearLayout; -import java.util.ArrayList; -import java.util.Collections; -import java.util.Comparator; - - -class DeviceProfileQuery { - DeviceProfile profile; - float widthDps; - float heightDps; - float value; - PointF dimens; - - DeviceProfileQuery(DeviceProfile p, float v) { - widthDps = p.minWidthDps; - heightDps = p.minHeightDps; - value = v; - dimens = new PointF(widthDps, heightDps); - profile = p; - } -} - public class DeviceProfile { - public static interface DeviceProfileCallbacks { - public void onAvailableSizeChanged(DeviceProfile grid); - } - String name; - float minWidthDps; - float minHeightDps; - float numRows; - float numColumns; - float numHotseatIcons; - float iconSize; - private float iconTextSize; - private int iconDrawablePaddingOriginalPx; - private float hotseatIconSize; - - int defaultLayoutId; - - boolean isLandscape; - boolean isTablet; - boolean isLargeTablet; - boolean isLayoutRtl; - boolean transposeLayoutWithOrientation; - - int desiredWorkspaceLeftRightMarginPx; - int edgeMarginPx; - Rect defaultWidgetPadding; - - int widthPx; - int heightPx; - int availableWidthPx; - int availableHeightPx; - int defaultPageSpacingPx; - - int overviewModeMinIconZoneHeightPx; - int overviewModeMaxIconZoneHeightPx; - int overviewModeBarItemWidthPx; - int overviewModeBarSpacerWidthPx; - float overviewModeIconZoneRatio; - float overviewModeScaleFactor; - - int iconSizePx; - int iconTextSizePx; - int iconDrawablePaddingPx; - int cellWidthPx; - int cellHeightPx; - int allAppsIconSizePx; - int allAppsIconTextSizePx; - int allAppsCellWidthPx; - int allAppsCellHeightPx; - int allAppsCellPaddingPx; - int folderBackgroundOffset; - int folderIconSizePx; - int folderCellWidthPx; - int folderCellHeightPx; - int hotseatCellWidthPx; - int hotseatCellHeightPx; - int hotseatIconSizePx; - int hotseatBarHeightPx; - int hotseatAllAppsRank; - int allAppsNumRows; - int allAppsNumCols; - int searchBarSpaceWidthPx; - int searchBarSpaceHeightPx; - int pageIndicatorHeightPx; - int allAppsButtonVisualSize; - - float dragViewScale; - - int allAppsShortEdgeCount = -1; - int allAppsLongEdgeCount = -1; - - private ArrayList<DeviceProfileCallbacks> mCallbacks = new ArrayList<DeviceProfileCallbacks>(); - - DeviceProfile(String n, float w, float h, float r, float c, - float is, float its, float hs, float his, int dlId) { - // Ensure that we have an odd number of hotseat items (since we need to place all apps) - if (!LauncherAppState.isDisableAllApps() && hs % 2 == 0) { - throw new RuntimeException("All Device Profiles must have an odd number of hotseat spaces"); - } + public final InvariantDeviceProfile inv; + + // Device properties + public final boolean isTablet; + public final boolean isLargeTablet; + public final boolean isPhone; + public final boolean transposeLayoutWithOrientation; + + // Device properties in current orientation + public final boolean isLandscape; + public final int widthPx; + public final int heightPx; + public final int availableWidthPx; + public final int availableHeightPx; + + // Overview mode + private final int overviewModeMinIconZoneHeightPx; + private final int overviewModeMaxIconZoneHeightPx; + private final int overviewModeBarItemWidthPx; + private final int overviewModeBarSpacerWidthPx; + private final float overviewModeIconZoneRatio; + + // Workspace + private int desiredWorkspaceLeftRightMarginPx; + public final int edgeMarginPx; + public final Rect defaultWidgetPadding; + private final int pageIndicatorHeightPx; + private final int defaultPageSpacingPx; + private float dragViewScale; + + // Workspace icons + public int iconSizePx; + public int iconTextSizePx; + public int iconDrawablePaddingPx; + public int iconDrawablePaddingOriginalPx; + + public int cellWidthPx; + public int cellHeightPx; + + // Folder + public int folderBackgroundOffset; + public int folderIconSizePx; + public int folderCellWidthPx; + public int folderCellHeightPx; + + // Hotseat + public int hotseatCellWidthPx; + public int hotseatCellHeightPx; + public int hotseatIconSizePx; + private int hotseatBarHeightPx; + + // All apps + public int allAppsNumCols; + public int allAppsNumPredictiveCols; + public int allAppsButtonVisualSize; + public final int allAppsIconSizePx; + public final int allAppsIconTextSizePx; + + // QSB + private int searchBarSpaceWidthPx; + private int searchBarSpaceHeightPx; + + public DeviceProfile(Context context, InvariantDeviceProfile inv, + Point minSize, Point maxSize, + int width, int height, boolean isLandscape) { + + this.inv = inv; + this.isLandscape = isLandscape; - name = n; - minWidthDps = w; - minHeightDps = h; - numRows = r; - numColumns = c; - iconSize = is; - iconTextSize = its; - numHotseatIcons = hs; - hotseatIconSize = his; - defaultLayoutId = dlId; - } + Resources res = context.getResources(); + DisplayMetrics dm = res.getDisplayMetrics(); - DeviceProfile() { - } + // Constants from resources + isTablet = res.getBoolean(R.bool.is_tablet); + isLargeTablet = res.getBoolean(R.bool.is_large_tablet); + isPhone = !isTablet && !isLargeTablet; - DeviceProfile(Context context, - ArrayList<DeviceProfile> profiles, - float minWidth, float minHeight, - int wPx, int hPx, - int awPx, int ahPx, - Resources res) { - DisplayMetrics dm = res.getDisplayMetrics(); - ArrayList<DeviceProfileQuery> points = - new ArrayList<DeviceProfileQuery>(); + // Some more constants transposeLayoutWithOrientation = res.getBoolean(R.bool.hotseat_transpose_layout_with_orientation); - minWidthDps = minWidth; - minHeightDps = minHeight; ComponentName cn = new ComponentName(context.getPackageName(), this.getClass().getName()); @@ -178,8 +125,6 @@ public class DeviceProfile { res.getDimensionPixelSize(R.dimen.dynamic_grid_page_indicator_height); defaultPageSpacingPx = res.getDimensionPixelSize(R.dimen.dynamic_grid_workspace_page_spacing); - allAppsCellPaddingPx = - res.getDimensionPixelSize(R.dimen.dynamic_grid_all_apps_cell_padding); overviewModeMinIconZoneHeightPx = res.getDimensionPixelSize(R.dimen.dynamic_grid_overview_min_icon_zone_height); overviewModeMaxIconZoneHeightPx = @@ -190,190 +135,71 @@ public class DeviceProfile { res.getDimensionPixelSize(R.dimen.dynamic_grid_overview_bar_spacer_width); overviewModeIconZoneRatio = res.getInteger(R.integer.config_dynamic_grid_overview_icon_zone_percentage) / 100f; - overviewModeScaleFactor = - res.getInteger(R.integer.config_dynamic_grid_overview_scale_percentage) / 100f; - - // Find the closes profile given the width/height - for (DeviceProfile p : profiles) { - points.add(new DeviceProfileQuery(p, 0f)); - } - DeviceProfile closestProfile = findClosestDeviceProfile(minWidth, minHeight, points); - - // Snap to the closest row count - numRows = closestProfile.numRows; - - // Snap to the closest column count - numColumns = closestProfile.numColumns; - - // Snap to the closest hotseat size - numHotseatIcons = closestProfile.numHotseatIcons; - hotseatAllAppsRank = (int) (numHotseatIcons / 2); - - // Snap to the closest default layout id - defaultLayoutId = closestProfile.defaultLayoutId; - - // Interpolate the icon size - points.clear(); - for (DeviceProfile p : profiles) { - points.add(new DeviceProfileQuery(p, p.iconSize)); - } - iconSize = invDistWeightedInterpolate(minWidth, minHeight, points); - - // AllApps uses the original non-scaled icon size - allAppsIconSizePx = DynamicGrid.pxFromDp(iconSize, dm); - - // Interpolate the icon text size - points.clear(); - for (DeviceProfile p : profiles) { - points.add(new DeviceProfileQuery(p, p.iconTextSize)); - } - iconTextSize = invDistWeightedInterpolate(minWidth, minHeight, points); iconDrawablePaddingOriginalPx = res.getDimensionPixelSize(R.dimen.dynamic_grid_icon_drawable_padding); + // AllApps uses the original non-scaled icon text size - allAppsIconTextSizePx = DynamicGrid.pxFromDp(iconTextSize, dm); + allAppsIconTextSizePx = Utilities.pxFromDp(inv.iconTextSize, dm); - // Interpolate the hotseat icon size - points.clear(); - for (DeviceProfile p : profiles) { - points.add(new DeviceProfileQuery(p, p.hotseatIconSize)); + // AllApps uses the original non-scaled icon size + allAppsIconSizePx = Utilities.pxFromDp(inv.iconSize, dm); + + // Determine sizes. + widthPx = width; + heightPx = height; + if (isLandscape) { + availableWidthPx = maxSize.x; + availableHeightPx = minSize.y; + } else { + availableWidthPx = minSize.x; + availableHeightPx = maxSize.y; } - // Hotseat - hotseatIconSize = invDistWeightedInterpolate(minWidth, minHeight, points); - - // If the partner customization apk contains any grid overrides, apply them - applyPartnerDeviceProfileOverrides(context, dm); // Calculate the remaining vars - updateFromConfiguration(context, res, wPx, hPx, awPx, ahPx); - updateAvailableDimensions(context); + updateAvailableDimensions(dm, res); computeAllAppsButtonSize(context); } /** - * Apply any Partner customization grid overrides. - * - * Currently we support: all apps row / column count. - */ - private void applyPartnerDeviceProfileOverrides(Context ctx, DisplayMetrics dm) { - Partner p = Partner.get(ctx.getPackageManager()); - if (p != null) { - DeviceProfile partnerDp = p.getDeviceProfileOverride(dm); - if (partnerDp != null) { - if (partnerDp.numRows > 0 && partnerDp.numColumns > 0) { - numRows = partnerDp.numRows; - numColumns = partnerDp.numColumns; - } - if (partnerDp.allAppsShortEdgeCount > 0 && partnerDp.allAppsLongEdgeCount > 0) { - allAppsShortEdgeCount = partnerDp.allAppsShortEdgeCount; - allAppsLongEdgeCount = partnerDp.allAppsLongEdgeCount; - } - if (partnerDp.iconSize > 0) { - iconSize = partnerDp.iconSize; - // AllApps uses the original non-scaled icon size - allAppsIconSizePx = DynamicGrid.pxFromDp(iconSize, dm); - } - } - } - } - - /** * Determine the exact visual footprint of the all apps button, taking into account scaling * and internal padding of the drawable. */ private void computeAllAppsButtonSize(Context context) { Resources res = context.getResources(); float padding = res.getInteger(R.integer.config_allAppsButtonPaddingPercent) / 100f; - LauncherAppState app = LauncherAppState.getInstance(); allAppsButtonVisualSize = (int) (hotseatIconSizePx * (1 - padding)); } - void addCallback(DeviceProfileCallbacks cb) { - mCallbacks.add(cb); - cb.onAvailableSizeChanged(this); - } - void removeCallback(DeviceProfileCallbacks cb) { - mCallbacks.remove(cb); - } - - private int getDeviceOrientation(Context context) { - WindowManager windowManager = (WindowManager) - context.getSystemService(Context.WINDOW_SERVICE); - Resources resources = context.getResources(); - DisplayMetrics dm = resources.getDisplayMetrics(); - Configuration config = resources.getConfiguration(); - int rotation = windowManager.getDefaultDisplay().getRotation(); - - boolean isLandscape = (config.orientation == Configuration.ORIENTATION_LANDSCAPE) && - (rotation == Surface.ROTATION_0 || rotation == Surface.ROTATION_180); - boolean isRotatedPortrait = (config.orientation == Configuration.ORIENTATION_PORTRAIT) && - (rotation == Surface.ROTATION_90 || rotation == Surface.ROTATION_270); - if (isLandscape || isRotatedPortrait) { - return CellLayout.LANDSCAPE; - } else { - return CellLayout.PORTRAIT; - } - } - - private void updateAvailableDimensions(Context context) { - WindowManager windowManager = (WindowManager) - context.getSystemService(Context.WINDOW_SERVICE); - Display display = windowManager.getDefaultDisplay(); - Resources resources = context.getResources(); - DisplayMetrics dm = resources.getDisplayMetrics(); - Configuration config = resources.getConfiguration(); - - // There are three possible configurations that the dynamic grid accounts for, portrait, - // landscape with the nav bar at the bottom, and landscape with the nav bar at the side. - // To prevent waiting for fitSystemWindows(), we make the observation that in landscape, - // the height is the smallest height (either with the nav bar at the bottom or to the - // side) and otherwise, the height is simply the largest possible height for a portrait - // device. - Point size = new Point(); - Point smallestSize = new Point(); - Point largestSize = new Point(); - display.getSize(size); - display.getCurrentSizeRange(smallestSize, largestSize); - availableWidthPx = size.x; - if (config.orientation == Configuration.ORIENTATION_LANDSCAPE) { - availableHeightPx = smallestSize.y; - } else { - availableHeightPx = largestSize.y; - } - + private void updateAvailableDimensions(DisplayMetrics dm, Resources res) { // Check to see if the icons fit in the new available height. If not, then we need to // shrink the icon size. float scale = 1f; int drawablePadding = iconDrawablePaddingOriginalPx; - updateIconSize(1f, drawablePadding, resources, dm); - float usedHeight = (cellHeightPx * numRows); + updateIconSize(1f, drawablePadding, res, dm); + float usedHeight = (cellHeightPx * inv.numRows); - Rect workspacePadding = getWorkspacePadding(); + // We only care about the top and bottom workspace padding, which is not affected by RTL. + Rect workspacePadding = getWorkspacePadding(false /* isLayoutRtl */); int maxHeight = (availableHeightPx - workspacePadding.top - workspacePadding.bottom); if (usedHeight > maxHeight) { scale = maxHeight / usedHeight; drawablePadding = 0; } - updateIconSize(scale, drawablePadding, resources, dm); - - // Make the callbacks - for (DeviceProfileCallbacks cb : mCallbacks) { - cb.onAvailableSizeChanged(this); - } + updateIconSize(scale, drawablePadding, res, dm); } - private void updateIconSize(float scale, int drawablePadding, Resources resources, + private void updateIconSize(float scale, int drawablePadding, Resources res, DisplayMetrics dm) { - iconSizePx = (int) (DynamicGrid.pxFromDp(iconSize, dm) * scale); - iconTextSizePx = (int) (DynamicGrid.pxFromSp(iconTextSize, dm) * scale); + iconSizePx = (int) (Utilities.pxFromDp(inv.iconSize, dm) * scale); + iconTextSizePx = (int) (Utilities.pxFromSp(inv.iconTextSize, dm) * scale); iconDrawablePaddingPx = drawablePadding; - hotseatIconSizePx = (int) (DynamicGrid.pxFromDp(hotseatIconSize, dm) * scale); + hotseatIconSizePx = (int) (Utilities.pxFromDp(inv.hotseatIconSize, dm) * scale); // Search Bar searchBarSpaceWidthPx = Math.min(widthPx, - resources.getDimensionPixelSize(R.dimen.dynamic_grid_search_bar_max_width)); + res.getDimensionPixelSize(R.dimen.dynamic_grid_search_bar_max_width)); searchBarSpaceHeightPx = getSearchBarTopOffset() - + resources.getDimensionPixelSize(R.dimen.dynamic_grid_search_bar_height); + + res.getDimensionPixelSize(R.dimen.dynamic_grid_search_bar_height); // Calculate the actual text height Paint textPaint = new Paint(); @@ -381,7 +207,7 @@ public class DeviceProfile { FontMetrics fm = textPaint.getFontMetrics(); cellWidthPx = iconSizePx; cellHeightPx = iconSizePx + iconDrawablePaddingPx + (int) Math.ceil(fm.bottom - fm.top); - final float scaleDps = resources.getDimensionPixelSize(R.dimen.dragViewScale); + final float scaleDps = res.getDimensionPixelSize(R.dimen.dragViewScale); dragViewScale = (iconSizePx + scaleDps) / iconSizePx; // Hotseat @@ -394,123 +220,27 @@ public class DeviceProfile { folderCellHeightPx = cellHeightPx + edgeMarginPx; folderBackgroundOffset = -edgeMarginPx; folderIconSizePx = iconSizePx + 2 * -folderBackgroundOffset; - - // All Apps - allAppsCellWidthPx = allAppsIconSizePx; - allAppsCellHeightPx = allAppsIconSizePx + drawablePadding + iconTextSizePx; - int maxLongEdgeCellCount = - resources.getInteger(R.integer.config_dynamic_grid_max_long_edge_cell_count); - int maxShortEdgeCellCount = - resources.getInteger(R.integer.config_dynamic_grid_max_short_edge_cell_count); - int minEdgeCellCount = - resources.getInteger(R.integer.config_dynamic_grid_min_edge_cell_count); - int maxRows = (isLandscape ? maxShortEdgeCellCount : maxLongEdgeCellCount); - int maxCols = (isLandscape ? maxLongEdgeCellCount : maxShortEdgeCellCount); - - if (allAppsShortEdgeCount > 0 && allAppsLongEdgeCount > 0) { - allAppsNumRows = isLandscape ? allAppsShortEdgeCount : allAppsLongEdgeCount; - allAppsNumCols = isLandscape ? allAppsLongEdgeCount : allAppsShortEdgeCount; - } else { - allAppsNumRows = (availableHeightPx - pageIndicatorHeightPx) / - (allAppsCellHeightPx + allAppsCellPaddingPx); - allAppsNumRows = Math.max(minEdgeCellCount, Math.min(maxRows, allAppsNumRows)); - allAppsNumCols = (availableWidthPx) / - (allAppsCellWidthPx + allAppsCellPaddingPx); - allAppsNumCols = Math.max(minEdgeCellCount, Math.min(maxCols, allAppsNumCols)); - } } - void updateFromConfiguration(Context context, Resources resources, int wPx, int hPx, - int awPx, int ahPx) { - Configuration configuration = resources.getConfiguration(); - isLandscape = (configuration.orientation == Configuration.ORIENTATION_LANDSCAPE); - isTablet = resources.getBoolean(R.bool.is_tablet); - isLargeTablet = resources.getBoolean(R.bool.is_large_tablet); - if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN_MR1) { - isLayoutRtl = (configuration.getLayoutDirection() == View.LAYOUT_DIRECTION_RTL); - } else { - isLayoutRtl = false; - } - widthPx = wPx; - heightPx = hPx; - availableWidthPx = awPx; - availableHeightPx = ahPx; - - updateAvailableDimensions(context); - } - - private float dist(PointF p0, PointF p1) { - return (float) Math.sqrt((p1.x - p0.x)*(p1.x-p0.x) + - (p1.y-p0.y)*(p1.y-p0.y)); - } - - private float weight(PointF a, PointF b, - float pow) { - float d = dist(a, b); - if (d == 0f) { - return Float.POSITIVE_INFINITY; - } - return (float) (1f / Math.pow(d, pow)); - } - - /** Returns the closest device profile given the width and height and a list of profiles */ - private DeviceProfile findClosestDeviceProfile(float width, float height, - ArrayList<DeviceProfileQuery> points) { - return findClosestDeviceProfiles(width, height, points).get(0).profile; - } - - /** Returns the closest device profiles ordered by closeness to the specified width and height */ - private ArrayList<DeviceProfileQuery> findClosestDeviceProfiles(float width, float height, - ArrayList<DeviceProfileQuery> points) { - final PointF xy = new PointF(width, height); - - // Sort the profiles by their closeness to the dimensions - ArrayList<DeviceProfileQuery> pointsByNearness = points; - Collections.sort(pointsByNearness, new Comparator<DeviceProfileQuery>() { - public int compare(DeviceProfileQuery a, DeviceProfileQuery b) { - return (int) (dist(xy, a.dimens) - dist(xy, b.dimens)); - } - }); - - return pointsByNearness; - } - - private float invDistWeightedInterpolate(float width, float height, - ArrayList<DeviceProfileQuery> points) { - float sum = 0; - float weights = 0; - float pow = 5; - float kNearestNeighbors = 3; - final PointF xy = new PointF(width, height); - - ArrayList<DeviceProfileQuery> pointsByNearness = findClosestDeviceProfiles(width, height, - points); - - for (int i = 0; i < pointsByNearness.size(); ++i) { - DeviceProfileQuery p = pointsByNearness.get(i); - if (i < kNearestNeighbors) { - float w = weight(xy, p.dimens, pow); - if (w == Float.POSITIVE_INFINITY) { - return p.value; - } - weights += w; - } - } - - for (int i = 0; i < pointsByNearness.size(); ++i) { - DeviceProfileQuery p = pointsByNearness.get(i); - if (i < kNearestNeighbors) { - float w = weight(xy, p.dimens, pow); - sum += w * p.value / weights; - } - } - - return sum; + /** + * @param recyclerViewWidth the available width of the AllAppsRecyclerView + */ + public void updateAppsViewNumCols(Resources res, int recyclerViewWidth) { + int appsViewLeftMarginPx = + res.getDimensionPixelSize(R.dimen.all_apps_grid_view_start_margin); + int allAppsCellWidthGap = + res.getDimensionPixelSize(R.dimen.all_apps_icon_width_gap); + int availableAppsWidthPx = (recyclerViewWidth > 0) ? recyclerViewWidth : availableWidthPx; + int numAppsCols = (availableAppsWidthPx - appsViewLeftMarginPx) / + (allAppsIconSizePx + allAppsCellWidthGap); + int numPredictiveAppCols = Math.max(inv.minAllAppsPredictionColumns, numAppsCols); + allAppsNumCols = numAppsCols; + allAppsNumPredictiveCols = numPredictiveAppCols; } /** Returns the search bar top offset */ - int getSearchBarTopOffset() { - if (isTablet() && !isVerticalBarLayout()) { + private int getSearchBarTopOffset() { + if (isTablet && !isVerticalBarLayout()) { return 4 * edgeMarginPx; } else { return 2 * edgeMarginPx; @@ -518,14 +248,9 @@ public class DeviceProfile { } /** Returns the search bar bounds in the current orientation */ - Rect getSearchBarBounds() { - return getSearchBarBounds(isLandscape ? CellLayout.LANDSCAPE : CellLayout.PORTRAIT); - } - /** Returns the search bar bounds in the specified orientation */ - Rect getSearchBarBounds(int orientation) { + public Rect getSearchBarBounds(boolean isLayoutRtl) { Rect bounds = new Rect(); - if (orientation == CellLayout.LANDSCAPE && - transposeLayoutWithOrientation) { + if (isLandscape && transposeLayoutWithOrientation) { if (isLayoutRtl) { bounds.set(availableWidthPx - searchBarSpaceHeightPx, edgeMarginPx, availableWidthPx, availableHeightPx - edgeMarginPx); @@ -534,16 +259,14 @@ public class DeviceProfile { availableHeightPx - edgeMarginPx); } } else { - if (isTablet()) { + if (isTablet) { // Pad the left and right of the workspace to ensure consistent spacing // between all icons - int width = (orientation == CellLayout.LANDSCAPE) - ? Math.max(widthPx, heightPx) - : Math.min(widthPx, heightPx); + int width = getCurrentWidth(); // XXX: If the icon size changes across orientations, we will have to take // that into account here too. int gap = (int) ((width - 2 * edgeMarginPx - - (numColumns * cellWidthPx)) / (2 * (numColumns + 1))); + (inv.numColumns * cellWidthPx)) / (2 * (inv.numColumns + 1))); bounds.set(edgeMarginPx + gap, getSearchBarTopOffset(), availableWidthPx - (edgeMarginPx + gap), searchBarSpaceHeightPx); @@ -557,36 +280,11 @@ public class DeviceProfile { return bounds; } - /** Returns the bounds of the workspace page indicators. */ - Rect getWorkspacePageIndicatorBounds(Rect insets) { - Rect workspacePadding = getWorkspacePadding(); - if (isLandscape && transposeLayoutWithOrientation) { - if (isLayoutRtl) { - return new Rect(workspacePadding.left, workspacePadding.top, - workspacePadding.left + pageIndicatorHeightPx, - heightPx - workspacePadding.bottom - insets.bottom); - } else { - int pageIndicatorLeft = widthPx - workspacePadding.right; - return new Rect(pageIndicatorLeft, workspacePadding.top, - pageIndicatorLeft + pageIndicatorHeightPx, - heightPx - workspacePadding.bottom - insets.bottom); - } - } else { - int pageIndicatorTop = heightPx - insets.bottom - workspacePadding.bottom; - return new Rect(workspacePadding.left, pageIndicatorTop, - widthPx - workspacePadding.right, pageIndicatorTop + pageIndicatorHeightPx); - } - } - /** Returns the workspace padding in the specified orientation */ - Rect getWorkspacePadding() { - return getWorkspacePadding(isLandscape ? CellLayout.LANDSCAPE : CellLayout.PORTRAIT); - } - Rect getWorkspacePadding(int orientation) { - Rect searchBarBounds = getSearchBarBounds(orientation); + Rect getWorkspacePadding(boolean isLayoutRtl) { + Rect searchBarBounds = getSearchBarBounds(isLayoutRtl); Rect padding = new Rect(); - if (orientation == CellLayout.LANDSCAPE && - transposeLayoutWithOrientation) { + if (isLandscape && transposeLayoutWithOrientation) { // Pad the left and right of the workspace with search/hotseat bar sizes if (isLayoutRtl) { padding.set(hotseatBarHeightPx, edgeMarginPx, @@ -596,22 +294,18 @@ public class DeviceProfile { hotseatBarHeightPx, edgeMarginPx); } } else { - if (isTablet()) { + if (isTablet) { // Pad the left and right of the workspace to ensure consistent spacing // between all icons float gapScale = 1f + (dragViewScale - 1f) / 2f; - int width = (orientation == CellLayout.LANDSCAPE) - ? Math.max(widthPx, heightPx) - : Math.min(widthPx, heightPx); - int height = (orientation != CellLayout.LANDSCAPE) - ? Math.max(widthPx, heightPx) - : Math.min(widthPx, heightPx); + int width = getCurrentWidth(); + int height = getCurrentHeight(); int paddingTop = searchBarBounds.bottom; int paddingBottom = hotseatBarHeightPx + pageIndicatorHeightPx; - int availableWidth = Math.max(0, width - (int) ((numColumns * cellWidthPx) + - (numColumns * gapScale * cellWidthPx))); + int availableWidth = Math.max(0, width - (int) ((inv.numColumns * cellWidthPx) + + (inv.numColumns * gapScale * cellWidthPx))); int availableHeight = Math.max(0, height - paddingTop - paddingBottom - - (int) (2 * numRows * cellHeightPx)); + - (int) (2 * inv.numRows * cellHeightPx)); padding.set(availableWidth / 2, paddingTop + availableHeight / 2, availableWidth / 2, paddingBottom + availableHeight / 2); } else { @@ -625,31 +319,23 @@ public class DeviceProfile { return padding; } - int getWorkspacePageSpacing(int orientation) { - if ((orientation == CellLayout.LANDSCAPE && - transposeLayoutWithOrientation) || isLargeTablet()) { + private int getWorkspacePageSpacing(boolean isLayoutRtl) { + if ((isLandscape && transposeLayoutWithOrientation) || isLargeTablet) { // In landscape mode the page spacing is set to the default. return defaultPageSpacingPx; } else { // In portrait, we want the pages spaced such that there is no // overhang of the previous / next page into the current page viewport. // We assume symmetrical padding in portrait mode. - return Math.max(defaultPageSpacingPx, 2 * getWorkspacePadding().left); + return Math.max(defaultPageSpacingPx, 2 * getWorkspacePadding(isLayoutRtl).left); } } - Rect getOverviewModeButtonBarRect() { + int getOverviewModeButtonBarHeight() { int zoneHeight = (int) (overviewModeIconZoneRatio * availableHeightPx); zoneHeight = Math.min(overviewModeMaxIconZoneHeightPx, Math.max(overviewModeMinIconZoneHeightPx, zoneHeight)); - return new Rect(0, availableHeightPx - zoneHeight, 0, availableHeightPx); - } - - float getOverviewModeScale() { - Rect workspacePadding = getWorkspacePadding(); - Rect overviewBar = getOverviewModeButtonBarRect(); - int pageSpace = availableHeightPx - workspacePadding.top - workspacePadding.bottom; - return (overviewModeScaleFactor * (pageSpace - overviewBar.height())) / pageSpace; + return zoneHeight; } // The rect returned will be extended to below the system ui that covers the workspace @@ -663,32 +349,26 @@ public class DeviceProfile { } } - int calculateCellWidth(int width, int countX) { + public static int calculateCellWidth(int width, int countX) { return width / countX; } - int calculateCellHeight(int height, int countY) { + public static int calculateCellHeight(int height, int countY) { return height / countY; } - boolean isPhone() { - return !isTablet && !isLargeTablet; - } - boolean isTablet() { - return isTablet; - } - boolean isLargeTablet() { - return isLargeTablet; - } - + /** + * When {@code true}, hotseat is on the bottom row when in landscape mode. + * If {@code false}, hotseat is on the right column when in landscape mode. + */ boolean isVerticalBarLayout() { return isLandscape && transposeLayoutWithOrientation; } boolean shouldFadeAdjacentWorkspaceScreens() { - return isVerticalBarLayout() || isLargeTablet(); + return isVerticalBarLayout() || isLargeTablet; } - int getVisibleChildCount(ViewGroup parent) { + private int getVisibleChildCount(ViewGroup parent) { int visibleChildren = 0; for (int i = 0; i < parent.getChildCount(); i++) { if (parent.getChildAt(i).getVisibility() != View.GONE) { @@ -700,25 +380,31 @@ public class DeviceProfile { public void layout(Launcher launcher) { FrameLayout.LayoutParams lp; - Resources res = launcher.getResources(); boolean hasVerticalBarLayout = isVerticalBarLayout(); + final boolean isLayoutRtl = Utilities.isRtl(launcher.getResources()); // Layout the search bar space - View searchBar = launcher.getSearchBar(); + View searchBar = launcher.getSearchDropTargetBar(); lp = (FrameLayout.LayoutParams) searchBar.getLayoutParams(); if (hasVerticalBarLayout) { - // Vertical search bar space - lp.gravity = Gravity.TOP | Gravity.LEFT; + // Vertical search bar space -- The search bar is fixed in the layout to be on the left + // of the screen regardless of RTL + lp.gravity = Gravity.LEFT; lp.width = searchBarSpaceHeightPx; - lp.height = LayoutParams.WRAP_CONTENT; LinearLayout targets = (LinearLayout) searchBar.findViewById(R.id.drag_target_bar); targets.setOrientation(LinearLayout.VERTICAL); + FrameLayout.LayoutParams targetsLp = (FrameLayout.LayoutParams) targets.getLayoutParams(); + targetsLp.gravity = Gravity.TOP; + targetsLp.height = LayoutParams.WRAP_CONTENT; + } else { // Horizontal search bar space - lp.gravity = Gravity.TOP | Gravity.CENTER_HORIZONTAL; - lp.width = searchBarSpaceWidthPx; + lp.gravity = Gravity.TOP; lp.height = searchBarSpaceHeightPx; + + LinearLayout targets = (LinearLayout) searchBar.findViewById(R.id.drag_target_bar); + targets.getLayoutParams().width = searchBarSpaceWidthPx; } searchBar.setLayoutParams(lp); @@ -726,22 +412,22 @@ public class DeviceProfile { PagedView workspace = (PagedView) launcher.findViewById(R.id.workspace); lp = (FrameLayout.LayoutParams) workspace.getLayoutParams(); lp.gravity = Gravity.CENTER; - int orientation = isLandscape ? CellLayout.LANDSCAPE : CellLayout.PORTRAIT; - Rect padding = getWorkspacePadding(orientation); + Rect padding = getWorkspacePadding(isLayoutRtl); workspace.setLayoutParams(lp); workspace.setPadding(padding.left, padding.top, padding.right, padding.bottom); - workspace.setPageSpacing(getWorkspacePageSpacing(orientation)); + workspace.setPageSpacing(getWorkspacePageSpacing(isLayoutRtl)); // Layout the hotseat View hotseat = launcher.findViewById(R.id.hotseat); lp = (FrameLayout.LayoutParams) hotseat.getLayoutParams(); if (hasVerticalBarLayout) { - // Vertical hotseat - lp.gravity = Gravity.END; + // Vertical hotseat -- The hotseat is fixed in the layout to be on the right of the + // screen regardless of RTL + lp.gravity = Gravity.RIGHT; lp.width = hotseatBarHeightPx; lp.height = LayoutParams.MATCH_PARENT; hotseat.findViewById(R.id.layout).setPadding(0, 2 * edgeMarginPx, 0, 2 * edgeMarginPx); - } else if (isTablet()) { + } else if (isTablet) { // Pad the hotseat with the workspace padding calculated above lp.gravity = Gravity.BOTTOM; lp.width = LayoutParams.MATCH_PARENT; @@ -777,68 +463,10 @@ public class DeviceProfile { } } - // Layout AllApps - AppsCustomizeTabHost host = (AppsCustomizeTabHost) - launcher.findViewById(R.id.apps_customize_pane); - if (host != null) { - // Center the all apps page indicator - int pageIndicatorHeight = (int) (pageIndicatorHeightPx * Math.min(1f, - (allAppsIconSizePx / DynamicGrid.DEFAULT_ICON_SIZE_PX))); - pageIndicator = host.findViewById(R.id.apps_customize_page_indicator); - if (pageIndicator != null) { - LinearLayout.LayoutParams lllp = (LinearLayout.LayoutParams) pageIndicator.getLayoutParams(); - lllp.width = LayoutParams.WRAP_CONTENT; - lllp.height = pageIndicatorHeight; - pageIndicator.setLayoutParams(lllp); - } - - AppsCustomizePagedView pagedView = (AppsCustomizePagedView) - host.findViewById(R.id.apps_customize_pane_content); - - FrameLayout fakePageContainer = (FrameLayout) - host.findViewById(R.id.fake_page_container); - FrameLayout fakePage = (FrameLayout) host.findViewById(R.id.fake_page); - - padding = new Rect(); - if (pagedView != null) { - // Constrain the dimensions of all apps so that it does not span the full width - int paddingLR = (availableWidthPx - (allAppsCellWidthPx * allAppsNumCols)) / - (2 * (allAppsNumCols + 1)); - int paddingTB = (availableHeightPx - (allAppsCellHeightPx * allAppsNumRows)) / - (2 * (allAppsNumRows + 1)); - paddingLR = Math.min(paddingLR, (int)((paddingLR + paddingTB) * 0.75f)); - paddingTB = Math.min(paddingTB, (int)((paddingLR + paddingTB) * 0.75f)); - int maxAllAppsWidth = (allAppsNumCols * (allAppsCellWidthPx + 2 * paddingLR)); - int gridPaddingLR = (availableWidthPx - maxAllAppsWidth) / 2; - // Only adjust the side paddings on landscape phones, or tablets - if ((isTablet() || isLandscape) && gridPaddingLR > (allAppsCellWidthPx / 4)) { - padding.left = padding.right = gridPaddingLR; - } - - // The icons are centered, so we can't just offset by the page indicator height - // because the empty space will actually be pageIndicatorHeight + paddingTB - padding.bottom = Math.max(0, pageIndicatorHeight - paddingTB); - - pagedView.setWidgetsPageIndicatorPadding(pageIndicatorHeight); - fakePage.setBackground(res.getDrawable(R.drawable.quantum_panel)); - - // Horizontal padding for the whole paged view - int pagedFixedViewPadding = - res.getDimensionPixelSize(R.dimen.apps_customize_horizontal_padding); - - padding.left += pagedFixedViewPadding; - padding.right += pagedFixedViewPadding; - - pagedView.setPadding(padding.left, padding.top, padding.right, padding.bottom); - fakePageContainer.setPadding(padding.left, padding.top, padding.right, padding.bottom); - - } - } - // Layout the Overview Mode ViewGroup overviewMode = launcher.getOverviewPanel(); if (overviewMode != null) { - Rect r = getOverviewModeButtonBarRect(); + int overviewButtonBarHeight = getOverviewModeButtonBarHeight(); lp = (FrameLayout.LayoutParams) overviewMode.getLayoutParams(); lp.gravity = Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM; @@ -847,7 +475,7 @@ public class DeviceProfile { int maxWidth = totalItemWidth + (visibleChildCount-1) * overviewModeBarSpacerWidthPx; lp.width = Math.min(availableWidthPx, maxWidth); - lp.height = r.height(); + lp.height = overviewButtonBarHeight; overviewMode.setLayoutParams(lp); if (lp.width > totalItemWidth && visibleChildCount > 1) { @@ -875,4 +503,16 @@ public class DeviceProfile { } } } + + private int getCurrentWidth() { + return isLandscape + ? Math.max(widthPx, heightPx) + : Math.min(widthPx, heightPx); + } + + private int getCurrentHeight() { + return isLandscape + ? Math.min(widthPx, heightPx) + : Math.max(widthPx, heightPx); + } } |