From 38d1b0b3520243505a4a1469b5730e0b9c7e24ce Mon Sep 17 00:00:00 2001 From: Michael Jurka Date: Tue, 5 Apr 2011 14:50:34 -0700 Subject: Determine # of rows/columns based on screen size DO NOT MERGE Change-Id: Ie45206b0a414d9e9b6b1d25e597eadb638a9ad47 --- res/layout-large-land/workspace.xml | 30 +++++++++++++++++ res/layout-large-land/workspace_screen.xml | 13 +++---- res/layout-large-port/workspace.xml | 30 +++++++++++++++++ res/layout-large-port/workspace_screen.xml | 13 +++---- res/layout-large/launcher.xml | 31 +++++------------ res/values-large-land/dimens.xml | 6 ---- res/values-large-port/dimens.xml | 6 ---- res/values-large/dimens.xml | 24 +++++++++++-- src/com/android/launcher2/CellLayout.java | 54 ++++++++++++++++++++++++++++++ src/com/android/launcher2/Workspace.java | 49 +++++++++++++++++++++++++-- 10 files changed, 205 insertions(+), 51 deletions(-) create mode 100644 res/layout-large-land/workspace.xml create mode 100644 res/layout-large-port/workspace.xml diff --git a/res/layout-large-land/workspace.xml b/res/layout-large-land/workspace.xml new file mode 100644 index 000000000..e8ea782ee --- /dev/null +++ b/res/layout-large-land/workspace.xml @@ -0,0 +1,30 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/res/layout-large-land/workspace_screen.xml b/res/layout-large-land/workspace_screen.xml index e983b7920..25b05e903 100644 --- a/res/layout-large-land/workspace_screen.xml +++ b/res/layout-large-land/workspace_screen.xml @@ -24,9 +24,10 @@ launcher:cellWidth="@dimen/workspace_cell_width" launcher:cellHeight="@dimen/workspace_cell_height" - launcher:widthGap="@dimen/workspace_width_gap" - launcher:heightGap="@dimen/workspace_height_gap" - launcher:yAxisStartPadding="15dip" - launcher:yAxisEndPadding="15dip" - launcher:xAxisStartPadding="25dip" - launcher:xAxisEndPadding="25dip" /> + launcher:widthGap="@dimen/workspace_width_gap_land" + launcher:heightGap="@dimen/workspace_height_gap_land" + + launcher:xAxisStartPadding="@dimen/workspace_x_axis_start_padding_land" + launcher:xAxisEndPadding="@dimen/workspace_x_axis_end_padding_land" + launcher:yAxisStartPadding="@dimen/workspace_y_axis_start_padding_land" + launcher:yAxisEndPadding="@dimen/workspace_y_axis_end_padding_land" /> diff --git a/res/layout-large-port/workspace.xml b/res/layout-large-port/workspace.xml new file mode 100644 index 000000000..ccd7d3312 --- /dev/null +++ b/res/layout-large-port/workspace.xml @@ -0,0 +1,30 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/res/layout-large-port/workspace_screen.xml b/res/layout-large-port/workspace_screen.xml index 406441d00..e33c6123e 100644 --- a/res/layout-large-port/workspace_screen.xml +++ b/res/layout-large-port/workspace_screen.xml @@ -24,9 +24,10 @@ launcher:cellWidth="@dimen/workspace_cell_width" launcher:cellHeight="@dimen/workspace_cell_height" - launcher:widthGap="@dimen/workspace_width_gap" - launcher:heightGap="@dimen/workspace_height_gap" - launcher:yAxisStartPadding="25dip" - launcher:yAxisEndPadding="25dip" - launcher:xAxisStartPadding="15dip" - launcher:xAxisEndPadding="15dip"/> + launcher:widthGap="@dimen/workspace_width_gap_port" + launcher:heightGap="@dimen/workspace_height_gap_port" + + launcher:xAxisStartPadding="@dimen/workspace_x_axis_start_padding_port" + launcher:xAxisEndPadding="@dimen/workspace_x_axis_end_padding_port" + launcher:yAxisStartPadding="@dimen/workspace_y_axis_start_padding_port" + launcher:yAxisEndPadding="@dimen/workspace_y_axis_end_padding_port" /> diff --git a/res/layout-large/launcher.xml b/res/layout-large/launcher.xml index acf62f906..25ef36328 100644 --- a/res/layout-large/launcher.xml +++ b/res/layout-large/launcher.xml @@ -22,31 +22,10 @@ android:layout_width="match_parent" android:layout_height="match_parent"> - - - - - - - - - - - + android:layout_height="match_parent" /> + + 100dip - - 32dp - 2dp - - 50dp - 480dp 420dp diff --git a/res/values-large-port/dimens.xml b/res/values-large-port/dimens.xml index e696e3449..47cac78e8 100644 --- a/res/values-large-port/dimens.xml +++ b/res/values-large-port/dimens.xml @@ -19,12 +19,6 @@ or right while you're dragging. --> 40dp - - 0dp - 32dp - - 64dp - 800dp 420dp diff --git a/res/values-large/dimens.xml b/res/values-large/dimens.xml index 2b9769716..0c0d60e24 100644 --- a/res/values-large/dimens.xml +++ b/res/values-large/dimens.xml @@ -18,9 +18,23 @@ 96dip 96dip + 25dip + 25dip + 15dip + 15dip + 15dip + 15dip + 25dip + 25dip + - 0dp - 0dp + 32dp + 2dp + 0dp + 32dp + + 50dp + 64dp 10dp @@ -44,6 +58,9 @@ 0dip 4dip + 7 + 5 + 12dip 16dip @@ -51,6 +68,9 @@ 20dip 20dip + + 48dip + 196dp 140dp diff --git a/src/com/android/launcher2/CellLayout.java b/src/com/android/launcher2/CellLayout.java index 1111c53c7..d0fe5951c 100644 --- a/src/com/android/launcher2/CellLayout.java +++ b/src/com/android/launcher2/CellLayout.java @@ -269,6 +269,60 @@ public class CellLayout extends ViewGroup { addView(mChildren); } + static int widthInPortrait(Resources r, int numCells) { + // We use this method from Workspace to figure out how many rows/columns Launcher should + // have. We ignore the left/right padding on CellLayout because it turns out in our design + // the padding extends outside the visible screen size, but it looked fine anyway. + // However, we make sure there's at least enough space for the crosshairs at either + // edge to be rendered (half the crosshair is sticking out on either side) + int cellWidth = r.getDimensionPixelSize(R.dimen.workspace_cell_width); + int widthGap = r.getDimensionPixelSize(R.dimen.workspace_width_gap_port); + int crosshairsSize = r.getDrawable(R.drawable.gardening_crosshairs).getIntrinsicWidth(); + + return widthGap * (numCells - 1) + cellWidth * numCells + crosshairsSize; + } + + static int widthInLandscape(Resources r, int numCells) { + // We use this method from Workspace to figure out how many rows/columns Launcher should + // have. We ignore the left/right padding on CellLayout because it turns out in our design + // the padding extends outside the visible screen size, but it looked fine anyway. + // However, we make sure there's at least enough space for the crosshairs at either + // edge to be rendered (half the crosshair is sticking out on either side) + int cellWidth = r.getDimensionPixelSize(R.dimen.workspace_cell_width); + int widthGap = r.getDimensionPixelSize(R.dimen.workspace_width_gap_land); + int crosshairsSize = r.getDrawable(R.drawable.gardening_crosshairs).getIntrinsicWidth(); + + return widthGap * (numCells - 1) + cellWidth * numCells + crosshairsSize; + } + + static int heightInPortrait(Resources r, int numCells) { + // We use this method from Workspace to figure out how many rows/columns Launcher should + // have. We ignore the left/right padding on CellLayout because it turns out in our design + // the padding extends outside the visible screen size, but it looked fine anyway. + // However, we make sure there's at least enough space for the crosshairs at the bottom + // to be rendered (half the crosshair is sticking out); we don't worry about the top + // crosshair since it can bleed into the action bar space + int cellHeight = r.getDimensionPixelSize(R.dimen.workspace_cell_height); + int heightGap = r.getDimensionPixelSize(R.dimen.workspace_height_gap_port); + int crosshairsSize = r.getDrawable(R.drawable.gardening_crosshairs).getIntrinsicHeight(); + + return heightGap * (numCells - 1) + cellHeight * numCells + (crosshairsSize + 1) / 2; + } + + static int heightInLandscape(Resources r, int numCells) { + // We use this method from Workspace to figure out how many rows/columns Launcher should + // have. We ignore the left/right padding on CellLayout because it turns out in our design + // the padding extends outside the visible screen size, but it looked fine anyway. + // However, we make sure there's at least enough space for the crosshairs at the bottom + // to be rendered (half the crosshair is sticking out); we don't worry about the top + // crosshair since it can bleed into the action bar space + int cellHeight = r.getDimensionPixelSize(R.dimen.workspace_cell_height); + int heightGap = r.getDimensionPixelSize(R.dimen.workspace_height_gap_land); + int crosshairsSize = r.getDrawable(R.drawable.gardening_crosshairs).getIntrinsicHeight(); + + return heightGap * (numCells - 1) + cellHeight * numCells + (crosshairsSize + 1) / 2; + } + private void invalidateBubbleTextView(BubbleTextView icon) { final int padding = icon.getPressedOrFocusedBackgroundPadding(); invalidate(icon.getLeft() - padding, diff --git a/src/com/android/launcher2/Workspace.java b/src/com/android/launcher2/Workspace.java index e7865d26f..4fdac4d2b 100644 --- a/src/com/android/launcher2/Workspace.java +++ b/src/com/android/launcher2/Workspace.java @@ -53,6 +53,7 @@ import android.net.Uri; import android.os.IBinder; import android.os.Parcelable; import android.util.AttributeSet; +import android.util.DisplayMetrics; import android.util.Log; import android.util.Pair; import android.view.Display; @@ -255,10 +256,54 @@ public class Workspace extends SmoothPagedView mWallpaperManager = WallpaperManager.getInstance(context); + int cellCountX = DEFAULT_CELL_COUNT_X; + int cellCountY = DEFAULT_CELL_COUNT_Y; + TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.Workspace, defStyle, 0); - int cellCountX = a.getInt(R.styleable.Workspace_cellCountX, DEFAULT_CELL_COUNT_X); - int cellCountY = a.getInt(R.styleable.Workspace_cellCountY, DEFAULT_CELL_COUNT_Y); + + if (LauncherApplication.isScreenXLarge()) { + final Resources res = context.getResources(); + final DisplayMetrics dm = res.getDisplayMetrics(); + float widthDp = dm.widthPixels / dm.density; + float heightDp = dm.heightPixels / dm.density; + + final float statusBarHeight = res.getDimension(R.dimen.status_bar_height); + TypedArray actionBarSizeTypedArray = + context.obtainStyledAttributes(new int[] { android.R.attr.actionBarSize }); + float actionBarHeight = actionBarSizeTypedArray.getDimension(0, 0f); + + if (heightDp > widthDp) { + float temp = widthDp; + widthDp = heightDp; + heightDp = temp; + } + int cellCountXLand = 1; + int cellCountXPort = 1; + while (2*mPageSpacing + CellLayout.widthInLandscape(res, cellCountXLand + 1) <= widthDp) { + cellCountXLand++; + } + while (CellLayout.widthInPortrait(res, cellCountXPort + 1) <= heightDp) { + cellCountXPort++; + } + cellCountX = Math.min(cellCountXLand, cellCountXPort); + + int cellCountYLand = 1; + int cellCountYPort = 1; + while (statusBarHeight + actionBarHeight + + CellLayout.heightInLandscape(res, cellCountYLand + 1) <= heightDp) { + cellCountYLand++; + } + while (statusBarHeight + actionBarHeight + + CellLayout.heightInPortrait(res, cellCountYPort + 1) <= widthDp) { + cellCountYPort++; + } + cellCountY = Math.min(cellCountYLand, cellCountYPort); + } + + // if the value is manually specified, use that instead + cellCountX = a.getInt(R.styleable.Workspace_cellCountX, cellCountX); + cellCountY = a.getInt(R.styleable.Workspace_cellCountY, cellCountY); mDefaultPage = a.getInt(R.styleable.Workspace_defaultScreen, 1); a.recycle(); -- cgit v1.2.3