diff options
author | nebkat <nebkat@teamhacksung.org> | 2012-03-25 12:34:24 +0100 |
---|---|---|
committer | nebkat <nebkat@teamhacksung.org> | 2012-03-25 12:34:24 +0100 |
commit | d40cdc0757e25598ab1cecb2085fd80da05e3692 (patch) | |
tree | bc6415e08e9f6ae2f0254b50e65efdaea7819650 /src/com | |
parent | df8a328877c370ecbbb359da4811e4fae5dfb892 (diff) | |
download | android_packages_apps_Trebuchet-d40cdc0757e25598ab1cecb2085fd80da05e3692.tar.gz android_packages_apps_Trebuchet-d40cdc0757e25598ab1cecb2085fd80da05e3692.tar.bz2 android_packages_apps_Trebuchet-d40cdc0757e25598ab1cecb2085fd80da05e3692.zip |
Preferences: Grid Size
Change-Id: I51bec0a0c29421fc389f7b656496ba1467758892
Diffstat (limited to 'src/com')
-rw-r--r-- | src/com/cyanogenmod/trebuchet/Workspace.java | 56 | ||||
-rw-r--r-- | src/com/cyanogenmod/trebuchet/preference/PreferencesProvider.java | 18 |
2 files changed, 54 insertions, 20 deletions
diff --git a/src/com/cyanogenmod/trebuchet/Workspace.java b/src/com/cyanogenmod/trebuchet/Workspace.java index bca48f6c7..94c80fea2 100644 --- a/src/com/cyanogenmod/trebuchet/Workspace.java +++ b/src/com/cyanogenmod/trebuchet/Workspace.java @@ -306,26 +306,9 @@ public class Workspace extends PagedView final Resources res = context.getResources(); 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 - TypedArray actionBarSizeTypedArray = - context.obtainStyledAttributes(new int[] { android.R.attr.actionBarSize }); - final float actionBarHeight = actionBarSizeTypedArray.getDimension(0, 0f); - final float systemBarHeight = res.getDimension(R.dimen.status_bar_height); - final float smallestScreenDim = res.getConfiguration().smallestScreenWidthDp; - - cellCountX = 1; - while (CellLayout.widthInPortrait(res, cellCountX + 1) <= smallestScreenDim) { - cellCountX++; - } - - cellCountY = 1; - while (actionBarHeight + CellLayout.heightInLandscape(res, cellCountY + 1) - <= smallestScreenDim - systemBarHeight) { - cellCountY++; - } + int[] cellCount = getCellCountsForLarge(context); + cellCountX = cellCount[0]; + cellCountY = cellCount[1]; } mSpringLoadedShrinkFactor = @@ -337,6 +320,12 @@ public class Workspace extends PagedView cellCountY = a.getInt(R.styleable.Workspace_cellCountY, cellCountY); a.recycle(); + // if there is a value set it the preferences, use that instead + if (!LauncherApplication.isScreenLarge()) { + cellCountX = PreferencesProvider.Interface.Homescreen.getCellCountX(context, cellCountX); + cellCountY = PreferencesProvider.Interface.Homescreen.getCellCountY(context, cellCountY); + } + LauncherModel.updateWorkspaceLayoutCells(cellCountX, cellCountY); setHapticFeedbackEnabled(false); @@ -368,6 +357,33 @@ public class Workspace extends PagedView setMotionEventSplittingEnabled(true); } + public static int[] getCellCountsForLarge(Context context) { + int[] cellCount = new int[2]; + + final Resources res = context.getResources(); + // 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 + TypedArray actionBarSizeTypedArray = + context.obtainStyledAttributes(new int[] { android.R.attr.actionBarSize }); + final float actionBarHeight = actionBarSizeTypedArray.getDimension(0, 0f); + final float systemBarHeight = res.getDimension(R.dimen.status_bar_height); + final float smallestScreenDim = res.getConfiguration().smallestScreenWidthDp; + + cellCount[0] = 1; + while (CellLayout.widthInPortrait(res, cellCount[0] + 1) <= smallestScreenDim) { + cellCount[0]++; + } + + cellCount[1] = 1; + while (actionBarHeight + CellLayout.heightInLandscape(res, cellCount[1] + 1) + <= smallestScreenDim - systemBarHeight) { + cellCount[1]++; + } + return cellCount; + } + // estimate the size of a widget with spans hSpan, vSpan. return MAX_VALUE for each // dimension if unsuccessful public int[] estimateItemSize(int hSpan, int vSpan, diff --git a/src/com/cyanogenmod/trebuchet/preference/PreferencesProvider.java b/src/com/cyanogenmod/trebuchet/preference/PreferencesProvider.java index ba3ccb19b..2b68ffdcd 100644 --- a/src/com/cyanogenmod/trebuchet/preference/PreferencesProvider.java +++ b/src/com/cyanogenmod/trebuchet/preference/PreferencesProvider.java @@ -38,6 +38,24 @@ public final class PreferencesProvider { final SharedPreferences preferences = context.getSharedPreferences(PREFERENCES_KEY, 0); return preferences.getInt("ui_homescreen_default_screen", def + 1) - 1; } + public static int getCellCountX(Context context, int def) { + final SharedPreferences preferences = context.getSharedPreferences(PREFERENCES_KEY, 0); + String[] values = preferences.getString("ui_homescreen_grid", "0|" + def).split("\\|"); + try { + return Integer.parseInt(values[1]); + } catch (NumberFormatException e) { + return def; + } + } + public static int getCellCountY(Context context, int def) { + final SharedPreferences preferences = context.getSharedPreferences(PREFERENCES_KEY, 0); + String[] values = preferences.getString("ui_homescreen_grid", def + "|0").split("\\|");; + try { + return Integer.parseInt(values[0]); + } catch (NumberFormatException e) { + return def; + } + } public static int getScreenPaddingVertical(Context context) { final SharedPreferences preferences = context.getSharedPreferences(PREFERENCES_KEY, 0); return (int)((float) preferences.getInt("ui_homescreen_screen_padding_vertical", 0) * 3.0f * |