diff options
Diffstat (limited to 'src/com/android/launcher2/Workspace.java')
-rw-r--r-- | src/com/android/launcher2/Workspace.java | 43 |
1 files changed, 14 insertions, 29 deletions
diff --git a/src/com/android/launcher2/Workspace.java b/src/com/android/launcher2/Workspace.java index 7d1ee1943..e0472fc0d 100644 --- a/src/com/android/launcher2/Workspace.java +++ b/src/com/android/launcher2/Workspace.java @@ -52,7 +52,6 @@ import android.graphics.drawable.Drawable; 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; @@ -272,42 +271,28 @@ public class Workspace extends SmoothPagedView R.styleable.Workspace, defStyle, 0); if (LauncherApplication.isScreenLarge()) { + // Determine number of rows/columns dynamically + // TODO: This code currently fails on tablets with an aspect ratio < 1.3. + // Around that ratio we should make cells the same size in portrait and + // landscape 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); + final float actionBarHeight = actionBarSizeTypedArray.getDimension(0, 0f); + final float systemBarHeight = res.getDimension(R.dimen.status_bar_height); + final float smallestScreenDim = res.getConfiguration().smallestScreenWidthDp; - if (heightDp > widthDp) { - float temp = widthDp; - widthDp = heightDp; - heightDp = temp; + cellCountX = 1; + while (CellLayout.widthInPortrait(res, cellCountX + 1) <= smallestScreenDim) { + cellCountX++; } - 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 = 1; + while (actionBarHeight + CellLayout.heightInLandscape(res, cellCountY + 1) + <= smallestScreenDim - systemBarHeight) { + cellCountY++; } - cellCountY = Math.min(cellCountYLand, cellCountYPort); } // if the value is manually specified, use that instead |