summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJoey Rizzoli <joey@lineageos.org>2017-11-09 16:05:00 +0100
committerArne Coucheron <arco68@gmail.com>2018-01-19 00:27:13 +0100
commit97105a6eb4de7a9ec0509b5c60c05ab0f4aef08c (patch)
treea06bb7480f538ffae254a6928902cf982aa11b39 /src
parentaca5a8bc95c1461419039a2041a8a54a84f49790 (diff)
downloadandroid_packages_apps_Trebuchet-97105a6eb4de7a9ec0509b5c60c05ab0f4aef08c.tar.gz
android_packages_apps_Trebuchet-97105a6eb4de7a9ec0509b5c60c05ab0f4aef08c.tar.bz2
android_packages_apps_Trebuchet-97105a6eb4de7a9ec0509b5c60c05ab0f4aef08c.zip
Launcher3: custom grid
Signed-off-by: Arne Coucheron <arco68@gmail.com> Signed-off-by: Joey Rizzoli <joey@lineageos.org>
Diffstat (limited to 'src')
-rw-r--r--src/com/android/launcher3/DeviceProfile.java2
-rw-r--r--src/com/android/launcher3/InvariantDeviceProfile.java41
-rw-r--r--src/com/android/launcher3/SettingsActivity.java99
-rw-r--r--src/com/android/launcher3/Utilities.java28
-rw-r--r--src/com/android/launcher3/allapps/AllAppsContainerView.java8
5 files changed, 165 insertions, 13 deletions
diff --git a/src/com/android/launcher3/DeviceProfile.java b/src/com/android/launcher3/DeviceProfile.java
index 69ee03e9e..3ca03a86d 100644
--- a/src/com/android/launcher3/DeviceProfile.java
+++ b/src/com/android/launcher3/DeviceProfile.java
@@ -444,7 +444,7 @@ public class DeviceProfile {
}
public void updateAppsViewNumCols() {
- allAppsNumCols = allAppsNumPredictiveCols = inv.numColumns;
+ allAppsNumCols = allAppsNumPredictiveCols = inv.numColumnsDrawer;
}
/** Returns the width and height of the search bar, ignoring any padding. */
diff --git a/src/com/android/launcher3/InvariantDeviceProfile.java b/src/com/android/launcher3/InvariantDeviceProfile.java
index 7a431986d..592f8550a 100644
--- a/src/com/android/launcher3/InvariantDeviceProfile.java
+++ b/src/com/android/launcher3/InvariantDeviceProfile.java
@@ -18,11 +18,13 @@ package com.android.launcher3;
import android.annotation.TargetApi;
import android.content.Context;
+import android.content.SharedPreferences;
import android.content.res.Configuration;
import android.content.res.TypedArray;
import android.content.res.XmlResourceParser;
import android.graphics.Point;
import android.util.DisplayMetrics;
+import android.util.Pair;
import android.util.Xml;
import android.view.Display;
import android.view.WindowManager;
@@ -45,6 +47,9 @@ public class InvariantDeviceProfile {
private static final float ICON_SIZE_DEFINED_IN_APP_DP = 48;
+ private static final String KEY_GRID_SIZE = "pref_grid_size";
+ private static final String KEY_GRID_CUSTOM = "pref_grid_custom";
+
// Constants that affects the interpolation curve between statically defined device profile
// buckets.
private static float KNEARESTNEIGHBOR = 3;
@@ -65,6 +70,11 @@ public class InvariantDeviceProfile {
public int numColumns;
/**
+ * Number of icons per row in the drawer
+ */
+ public int numColumnsDrawer;
+
+ /**
* The minimum number of predicted apps in all apps.
*/
@Deprecated
@@ -97,20 +107,22 @@ public class InvariantDeviceProfile {
public InvariantDeviceProfile() {
}
- public InvariantDeviceProfile(InvariantDeviceProfile p) {
- this(p.name, p.minWidthDps, p.minHeightDps, p.numRows, p.numColumns,
+ public InvariantDeviceProfile(Context context, InvariantDeviceProfile p) {
+ this(context, p.name, p.minWidthDps, p.minHeightDps, p.numRows, p.numColumns, p.numColumnsDrawer,
p.numFolderRows, p.numFolderColumns, p.minAllAppsPredictionColumns,
p.iconSize, p.landscapeIconSize, p.iconTextSize, p.numHotseatIcons,
p.defaultLayoutId, p.demoModeLayoutId);
}
- InvariantDeviceProfile(String n, float w, float h, int r, int c, int fr, int fc, int maapc,
- float is, float lis, float its, int hs, int dlId, int dmlId) {
+ InvariantDeviceProfile(Context context, String n, float w, float h, int r, int c, int cd,
+ int fr, int fc, int maapc, float is, float lis, float its, int hs,
+ int dlId, int dmlId) {
name = n;
minWidthDps = w;
minHeightDps = h;
numRows = r;
numColumns = c;
+ numColumnsDrawer = cd;
numFolderRows = fr;
numFolderColumns = fc;
minAllAppsPredictionColumns = maapc;
@@ -120,6 +132,8 @@ public class InvariantDeviceProfile {
numHotseatIcons = hs;
defaultLayoutId = dlId;
demoModeLayoutId = dmlId;
+
+ setGridSize(context);
}
@TargetApi(23)
@@ -140,11 +154,12 @@ public class InvariantDeviceProfile {
ArrayList<InvariantDeviceProfile> closestProfiles = findClosestDeviceProfiles(
minWidthDps, minHeightDps, getPredefinedDeviceProfiles(context));
InvariantDeviceProfile interpolatedDeviceProfileOut =
- invDistWeightedInterpolate(minWidthDps, minHeightDps, closestProfiles);
+ invDistWeightedInterpolate(context, minWidthDps, minHeightDps, closestProfiles);
InvariantDeviceProfile closestProfile = closestProfiles.get(0);
numRows = closestProfile.numRows;
numColumns = closestProfile.numColumns;
+ numColumnsDrawer = closestProfile.numColumnsDrawer;
numHotseatIcons = closestProfile.numHotseatIcons;
defaultLayoutId = closestProfile.defaultLayoutId;
demoModeLayoutId = closestProfile.demoModeLayoutId;
@@ -200,11 +215,13 @@ public class InvariantDeviceProfile {
int numColumns = a.getInt(R.styleable.InvariantDeviceProfile_numColumns, 0);
float iconSize = a.getFloat(R.styleable.InvariantDeviceProfile_iconSize, 0);
profiles.add(new InvariantDeviceProfile(
+ context,
a.getString(R.styleable.InvariantDeviceProfile_name),
a.getFloat(R.styleable.InvariantDeviceProfile_minWidthDps, 0),
a.getFloat(R.styleable.InvariantDeviceProfile_minHeightDps, 0),
numRows,
numColumns,
+ a.getInt(R.styleable.InvariantDeviceProfile_numColumnsDrawer, numColumns),
a.getInt(R.styleable.InvariantDeviceProfile_numFolderRows, numRows),
a.getInt(R.styleable.InvariantDeviceProfile_numFolderColumns, numColumns),
a.getInt(R.styleable.InvariantDeviceProfile_minAllAppsPredictionColumns, numColumns),
@@ -283,7 +300,7 @@ public class InvariantDeviceProfile {
}
// Package private visibility for testing.
- InvariantDeviceProfile invDistWeightedInterpolate(float width, float height,
+ InvariantDeviceProfile invDistWeightedInterpolate(Context context, float width, float height,
ArrayList<InvariantDeviceProfile> points) {
float weights = 0;
@@ -294,7 +311,7 @@ public class InvariantDeviceProfile {
InvariantDeviceProfile out = new InvariantDeviceProfile();
for (int i = 0; i < points.size() && i < KNEARESTNEIGHBOR; ++i) {
- p = new InvariantDeviceProfile(points.get(i));
+ p = new InvariantDeviceProfile(context, points.get(i));
float w = weight(width, height, p.minWidthDps, p.minHeightDps, WEIGHT_POWER);
weights += w;
out.add(p.multiply(w));
@@ -339,6 +356,16 @@ public class InvariantDeviceProfile {
return (float) (WEIGHT_EFFICIENT / Math.pow(d, pow));
}
+ private void setGridSize(Context context) {
+ SharedPreferences prefs = Utilities.getPrefs(context);
+ String defaultGridSize = Utilities.getGridValue(numColumns, numRows);
+ String properSize = prefs.getString(KEY_GRID_SIZE, defaultGridSize);
+
+ Pair<Integer, Integer> values = Utilities.extractCustomGrid(properSize);
+ numColumns = values.first;
+ numRows = values.second;
+ }
+
/**
* As a ratio of screen height, the total distance we want the parallax effect to span
* horizontally
diff --git a/src/com/android/launcher3/SettingsActivity.java b/src/com/android/launcher3/SettingsActivity.java
index 811defe0e..4adac74bd 100644
--- a/src/com/android/launcher3/SettingsActivity.java
+++ b/src/com/android/launcher3/SettingsActivity.java
@@ -27,11 +27,18 @@ import android.content.ContentResolver;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
+import android.app.AlarmManager;
+import android.app.PendingIntent;
+import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.ListPreference;
import android.preference.Preference;
import android.preference.PreferenceFragment;
import android.provider.Settings;
+import android.util.Pair;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.widget.NumberPicker;
import com.android.launcher3.graphics.IconShapeOverride;
import com.android.launcher3.notification.NotificationListener;
@@ -49,6 +56,9 @@ public class SettingsActivity extends Activity {
/** Hidden field Settings.Secure.ENABLED_NOTIFICATION_LISTENERS */
private static final String NOTIFICATION_ENABLED_LISTENERS = "enabled_notification_listeners";
+ // Grid size
+ private static final String KEY_GRID_SIZE = "pref_grid_size";
+
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@@ -64,11 +74,18 @@ public class SettingsActivity extends Activity {
/**
* This fragment shows the launcher preferences.
*/
- public static class LauncherSettingsFragment extends PreferenceFragment {
+ public static class LauncherSettingsFragment extends PreferenceFragment
+ implements SharedPreferences.OnSharedPreferenceChangeListener {
private SystemDisplayRotationLockObserver mRotationLockObserver;
private IconBadgingObserver mIconBadgingObserver;
+ private SharedPreferences mPrefs;
+
+ private Preference mGridPref;
+
+ private boolean mShouldRestart = false;
+
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@@ -117,6 +134,19 @@ public class SettingsActivity extends Activity {
getPreferenceScreen().removePreference(iconShapeOverride);
}
}
+
+ mGridPref = findPreference(KEY_GRID_SIZE);
+ if (mGridPref != null) {
+ mGridPref.setOnPreferenceClickListener(preference -> {
+ setCustomGridSize();
+ return true;
+ });
+
+ mGridPref.setSummary(mPrefs.getString(KEY_GRID_SIZE, getDefaulGridSize()));
+ }
+
+ mPrefs = Utilities.getPrefs(getActivity().getApplicationContext());
+ mPrefs.registerOnSharedPreferenceChangeListener(this);
}
@Override
@@ -129,8 +159,75 @@ public class SettingsActivity extends Activity {
mIconBadgingObserver.unregister();
mIconBadgingObserver = null;
}
+ mPrefs.unregisterOnSharedPreferenceChangeListener(this);
+
+ if (mShouldRestart) {
+ triggerRestart();
+ }
super.onDestroy();
}
+
+ @Override
+ public void onSharedPreferenceChanged(SharedPreferences prefs, String key) {
+ if (KEY_GRID_SIZE.equals(key)) {
+ mGridPref.setSummary(mPrefs.getString(KEY_GRID_SIZE, getDefaulGridSize()));
+ mShouldRestart = true;
+ }
+ }
+
+ private void setCustomGridSize() {
+ int minValue = 3;
+ int maxValue = 9;
+
+ String storedValue = mPrefs.getString(KEY_GRID_SIZE, "4x4");
+ Pair<Integer, Integer> currentValues = Utilities.extractCustomGrid(storedValue);
+
+ LayoutInflater inflater = (LayoutInflater)
+ getActivity().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
+ if (inflater == null) {
+ return;
+ }
+ View contentView = inflater.inflate(R.layout.dialog_custom_grid, null);
+ NumberPicker columnPicker = (NumberPicker)
+ contentView.findViewById(R.id.dialog_grid_column);
+ NumberPicker rowPicker = (NumberPicker)
+ contentView.findViewById(R.id.dialog_grid_row);
+
+ columnPicker.setMinValue(minValue);
+ rowPicker.setMinValue(minValue);
+ columnPicker.setMaxValue(maxValue);
+ rowPicker.setMaxValue(maxValue);
+ columnPicker.setValue(currentValues.first);
+ rowPicker.setValue(currentValues.second);
+
+ new AlertDialog.Builder(getActivity())
+ .setTitle(R.string.grid_size_text)
+ .setMessage(R.string.grid_size_custom_message)
+ .setView(contentView)
+ .setPositiveButton(R.string.grid_size_custom_positive, (dialog, i) -> {
+ String newValues = Utilities.getGridValue(columnPicker.getValue(),
+ rowPicker.getValue());
+ mPrefs.edit().putString(KEY_GRID_SIZE, newValues).apply();
+ })
+ .show();
+ }
+
+ private String getDefaulGridSize() {
+ InvariantDeviceProfile profile = new InvariantDeviceProfile(getActivity());
+ return Utilities.getGridValue(profile.numColumns, profile.numRows);
+ }
+
+ private void triggerRestart() {
+ Context context = getActivity().getApplicationContext();
+ Intent intent = new Intent(Intent.ACTION_MAIN);
+ intent.addCategory(Intent.CATEGORY_HOME);
+ intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
+ PendingIntent pi = PendingIntent.getActivity(context, 41, intent,
+ PendingIntent.FLAG_CANCEL_CURRENT);
+ AlarmManager manager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
+ manager.set(AlarmManager.RTC, java.lang.System.currentTimeMillis() + 1, pi);
+ java.lang.System.exit(0);
+ }
}
/**
diff --git a/src/com/android/launcher3/Utilities.java b/src/com/android/launcher3/Utilities.java
index b6876f670..d2421f6c4 100644
--- a/src/com/android/launcher3/Utilities.java
+++ b/src/com/android/launcher3/Utilities.java
@@ -127,6 +127,10 @@ public final class Utilities {
public static final String ALLOW_ROTATION_PREFERENCE_KEY = "pref_allowRotation";
+ private static final String GRID_VALUE_SEPARATOR = "x";
+ private static final int GRID_ROW_VALUE_DEFAULT = 4;
+ private static final int GRID_COLUMN_VALUE_DEFAULT = 5;
+
public static boolean isPropertyEnabled(String propertyName) {
return Log.isLoggable(propertyName, Log.VERBOSE);
}
@@ -655,4 +659,28 @@ public final class Utilities {
return hashSet;
}
+ public static Pair<Integer, Integer> extractCustomGrid(String value) {
+ int columns = GRID_COLUMN_VALUE_DEFAULT;
+ int rows = GRID_ROW_VALUE_DEFAULT;
+ String[] values = value.split(GRID_VALUE_SEPARATOR);
+
+ if (values.length == 2) {
+ try {
+ columns = Integer.parseInt(values[0]);
+ rows = Integer.parseInt(values[1]);
+ } catch (NumberFormatException e) {
+ // Ignore and fallback to default
+ columns = GRID_COLUMN_VALUE_DEFAULT;
+ rows = GRID_ROW_VALUE_DEFAULT;
+ }
+ }
+
+ return new Pair<>(columns, rows);
+
+ }
+
+ public static String getGridValue(int columns, int rows) {
+ return String.format(Locale.ENGLISH, "%1$d%2$s%3$d", columns,
+ GRID_VALUE_SEPARATOR, rows);
+ }
}
diff --git a/src/com/android/launcher3/allapps/AllAppsContainerView.java b/src/com/android/launcher3/allapps/AllAppsContainerView.java
index 4eba5c6df..2ba4b8631 100644
--- a/src/com/android/launcher3/allapps/AllAppsContainerView.java
+++ b/src/com/android/launcher3/allapps/AllAppsContainerView.java
@@ -249,10 +249,10 @@ public class AllAppsContainerView extends BaseContainerView implements DragSourc
// Update the number of items in the grid before we measure the view
grid.updateAppsViewNumCols();
- if (mNumAppsPerRow != grid.inv.numColumns ||
- mNumPredictedAppsPerRow != grid.inv.numColumns) {
- mNumAppsPerRow = grid.inv.numColumns;
- mNumPredictedAppsPerRow = grid.inv.numColumns;
+ if (mNumAppsPerRow != grid.inv.numColumnsDrawer ||
+ mNumPredictedAppsPerRow != grid.inv.numColumnsDrawer) {
+ mNumAppsPerRow = grid.inv.numColumnsDrawer;
+ mNumPredictedAppsPerRow = grid.inv.numColumnsDrawer;
mAppsRecyclerView.setNumAppsPerRow(grid, mNumAppsPerRow);
mAdapter.setNumAppsPerRow(mNumAppsPerRow);