summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authornebkat <nebkat@teamhacksung.org>2012-03-25 12:34:24 +0100
committerRicardo Cerqueira <cyanogenmod@cerqueira.org>2012-08-07 02:28:42 +0100
commitbde2a5aff1430c5623c332c5b09ce153a03c34a4 (patch)
treedb085e08a5537b9f2226aadb118d694d74594c5c /src
parenta2a53e7e46d4655045f4bc2c8e8811fe6961e610 (diff)
downloadandroid_packages_apps_Trebuchet-bde2a5aff1430c5623c332c5b09ce153a03c34a4.tar.gz
android_packages_apps_Trebuchet-bde2a5aff1430c5623c332c5b09ce153a03c34a4.tar.bz2
android_packages_apps_Trebuchet-bde2a5aff1430c5623c332c5b09ce153a03c34a4.zip
Preferences: Grid Size
Change-Id: I51bec0a0c29421fc389f7b656496ba1467758892
Diffstat (limited to 'src')
-rw-r--r--src/com/cyanogenmod/trebuchet/Workspace.java60
-rw-r--r--src/com/cyanogenmod/trebuchet/preference/PreferencesProvider.java18
2 files changed, 56 insertions, 22 deletions
diff --git a/src/com/cyanogenmod/trebuchet/Workspace.java b/src/com/cyanogenmod/trebuchet/Workspace.java
index 3a1ed323f..12f9d5de7 100644
--- a/src/com/cyanogenmod/trebuchet/Workspace.java
+++ b/src/com/cyanogenmod/trebuchet/Workspace.java
@@ -300,28 +300,9 @@ 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
- TypedArray actionBarSizeTypedArray =
- context.obtainStyledAttributes(new int[] { android.R.attr.actionBarSize });
- DisplayMetrics displayMetrics = res.getDisplayMetrics();
- final float actionBarHeight = actionBarSizeTypedArray.getDimension(0, 0f);
- final float systemBarHeight = res.getDimension(R.dimen.status_bar_height);
- final float smallestScreenDim = res.getConfiguration().smallestScreenWidthDp *
- displayMetrics.density;
-
- 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 =
@@ -338,6 +319,12 @@ public class Workspace extends SmoothPagedView
setOnHierarchyChangeListener(this);
+ // 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);
@@ -357,6 +344,35 @@ public class Workspace extends SmoothPagedView
}
}
+ 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 });
+ DisplayMetrics displayMetrics = res.getDisplayMetrics();
+ final float actionBarHeight = actionBarSizeTypedArray.getDimension(0, 0f);
+ final float systemBarHeight = res.getDimension(R.dimen.status_bar_height);
+ final float smallestScreenDim = res.getConfiguration().smallestScreenWidthDp *
+ displayMetrics.density;
+
+ 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 13cee1224..ab4e06eda 100644
--- a/src/com/cyanogenmod/trebuchet/preference/PreferencesProvider.java
+++ b/src/com/cyanogenmod/trebuchet/preference/PreferencesProvider.java
@@ -25,6 +25,24 @@ public final class PreferencesProvider {
public static final String PREFERENCES_CHANGED = "preferences_changed";
public static class Interface {
public static class Homescreen {
+ 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 boolean getShowSearchBar(Context context) {
final SharedPreferences preferences = context.getSharedPreferences(PREFERENCES_KEY, 0);
return preferences.getBoolean("ui_homescreen_general_search", true);