summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--res/values/strings.xml4
-rw-r--r--res/xml/preferences.xml14
-rw-r--r--src/com/cyanogenmod/trebuchet/Workspace.java60
-rw-r--r--src/com/cyanogenmod/trebuchet/preference/PreferencesProvider.java18
4 files changed, 73 insertions, 23 deletions
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 425d54b..c4ca1f8 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -295,6 +295,10 @@ s -->
<string name="preferences_interface_homescreen_title">Homescreen</string>
<string name="preferences_interface_homescreen_general_category">General</string>
<string name="preferences_interface_homescreen_general_search_title">Search Bar</string>
+ <string name="preferences_interface_homescreen_general_grid_title">Grid Size</string>
+ <string name="preferences_interface_homescreen_general_grid_summary">Choose the number of rows/columns on the homescreen</string>
+ <string name="preferences_interface_homescreen_general_grid_rows_title">Rows</string>
+ <string name="preferences_interface_homescreen_general_grid_columns_title">Columns</string>
<string name="preferences_interface_homescreen_general_search_summary">Enable persistent search bar</string>
<string name="preferences_interface_homescreen_general_resize_any_widget_title">Resize any widget</string>
<string name="preferences_interface_homescreen_general_resize_any_widget_summary">Allow resizing of widgets that normally aren\'t resizeable</string>
diff --git a/res/xml/preferences.xml b/res/xml/preferences.xml
index 53be9e0..dcb6379 100644
--- a/res/xml/preferences.xml
+++ b/res/xml/preferences.xml
@@ -14,13 +14,25 @@
limitations under the License.
-->
-<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
+<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
+ xmlns:launcher="http://schemas.android.com/apk/res/com.cyanogenmod.trebuchet">
<!-- UI -->
<PreferenceCategory android:title="@string/preferences_interface_title">
<!-- Homescreen -->
<PreferenceScreen android:key="ui_homescreen"
android:title="@string/preferences_interface_homescreen_title">
<PreferenceCategory android:title="@string/preferences_interface_homescreen_general_category">
+ <com.cyanogenmod.trebuchet.preference.DoubleNumberPickerPreference android:key="ui_homescreen_grid"
+ android:title="@string/preferences_interface_homescreen_general_grid_title"
+ android:summary="@string/preferences_interface_homescreen_general_grid_summary"
+ launcher:pickerTitle1="@string/preferences_interface_homescreen_general_grid_rows_title"
+ launcher:pickerTitle2="@string/preferences_interface_homescreen_general_grid_columns_title"
+ launcher:defaultValue1="4"
+ launcher:defaultValue2="4"
+ launcher:max1="7"
+ launcher:min1="3"
+ launcher:max2="7"
+ launcher:min2="3" />
<CheckBoxPreference android:key="ui_homescreen_general_search"
android:title="@string/preferences_interface_homescreen_general_search_title"
android:summary="@string/preferences_interface_homescreen_general_search_summary"
diff --git a/src/com/cyanogenmod/trebuchet/Workspace.java b/src/com/cyanogenmod/trebuchet/Workspace.java
index 00b50e6..669a41f 100644
--- a/src/com/cyanogenmod/trebuchet/Workspace.java
+++ b/src/com/cyanogenmod/trebuchet/Workspace.java
@@ -306,28 +306,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 });
- final float actionBarHeight = actionBarSizeTypedArray.getDimension(0, 0f);
-
- Point minDims = new Point();
- Point maxDims = new Point();
- mLauncher.getWindowManager().getDefaultDisplay().getCurrentSizeRange(minDims, maxDims);
-
- cellCountX = 1;
- while (CellLayout.widthInPortrait(res, cellCountX + 1) <= minDims.x) {
- cellCountX++;
- }
-
- cellCountY = 1;
- while (actionBarHeight + CellLayout.heightInLandscape(res, cellCountY + 1)
- <= minDims.y) {
- cellCountY++;
- }
+ int[] cellCount = getCellCountsForLarge(context);
+ cellCountX = cellCount[0];
+ cellCountY = cellCount[1];
}
mSpringLoadedShrinkFactor =
@@ -344,6 +325,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);
@@ -362,6 +349,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 13cee12..ab4e06e 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);