summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoey <joey@lineageos.org>2018-02-04 11:36:32 +0100
committerJoey <joey@lineageos.org>2018-02-05 19:54:40 +0000
commit1b2f8875b149fa27f80b6945cb51a5476e709a8b (patch)
tree296e016387f4813a96aca6b6f92d7e60ef7704f9
parent8463529145791249bb7118fe96482a5e8e58eac4 (diff)
downloadandroid_packages_apps_Trebuchet-1b2f8875b149fa27f80b6945cb51a5476e709a8b.tar.gz
android_packages_apps_Trebuchet-1b2f8875b149fa27f80b6945cb51a5476e709a8b.tar.bz2
android_packages_apps_Trebuchet-1b2f8875b149fa27f80b6945cb51a5476e709a8b.zip
Trebuchet: allow disabling workspace edit
Change-Id: I503e19cbc512eac0e4a8c8bccc16a6ccc0e805da Signed-off-by: Joey <joey@lineageos.org>
-rw-r--r--res/drawable/ic_settings_edit.xml25
-rw-r--r--res/values/lineage_strings.xml4
-rw-r--r--res/xml/launcher_preferences.xml9
-rw-r--r--src/com/android/launcher3/Launcher.java2
-rw-r--r--src/com/android/launcher3/SettingsActivity.java2
-rw-r--r--src/com/android/launcher3/Utilities.java5
-rw-r--r--src/com/android/launcher3/dragndrop/DragController.java10
-rw-r--r--src/com/android/launcher3/popup/SystemShortcut.java5
-rw-r--r--src/com/android/launcher3/shortcuts/ShortcutsItemView.java3
9 files changed, 63 insertions, 2 deletions
diff --git a/res/drawable/ic_settings_edit.xml b/res/drawable/ic_settings_edit.xml
new file mode 100644
index 000000000..ff4b07f23
--- /dev/null
+++ b/res/drawable/ic_settings_edit.xml
@@ -0,0 +1,25 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ Copyright (C) 2018 The LineageOS Project
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+ android:width="@dimen/settings_icon_size"
+ android:height="@dimen/settings_icon_size"
+ android:viewportHeight="24.0"
+ android:viewportWidth="24.0">
+ <path
+ android:fillColor="@color/settings_icons"
+ android:pathData="M3,17.25V21h3.75L17.81,9.94l-3.75,-3.75L3,17.25zM20.71,7.04c0.39,-0.39 0.39,-1.02 0,-1.41l-2.34,-2.34c-0.39,-0.39 -1.02,-0.39 -1.41,0l-1.83,1.83 3.75,3.75 1.83,-1.83z" />
+</vector>
diff --git a/res/values/lineage_strings.xml b/res/values/lineage_strings.xml
index 1b4564c57..e4257ab07 100644
--- a/res/values/lineage_strings.xml
+++ b/res/values/lineage_strings.xml
@@ -68,4 +68,8 @@
<string name="settings_icon_badging_desc_on">A bubble will be displayed above the icon when there\'s a notification</string>
<string name="settings_icon_badging_desc_off">No bubble will be displayed above the icon when there\'s a notification</string>
<string name="settings_feed">Enable feed integration</string>
+ <string name="settings_edit_allow_title">Allow edit</string>
+ <string name="settings_edit_allow_summary_on">Icons and widgets can be added, removed and moved on the homescreen</string>
+ <string name="settings_edit_allow_summary_off">Icons and widgets can\'t be added, removed and moved on the homescreen</string>
+ <string name="settings_edit_widgets_error">It\'s not possible to add widgets to the home screen</string>
</resources>
diff --git a/res/xml/launcher_preferences.xml b/res/xml/launcher_preferences.xml
index 03fc0ed09..45f3b6edc 100644
--- a/res/xml/launcher_preferences.xml
+++ b/res/xml/launcher_preferences.xml
@@ -14,6 +14,15 @@
-->
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
+ <SwitchPreference
+ android:defaultValue="true"
+ android:icon="@drawable/ic_settings_edit"
+ android:key="pref_workspace_edit"
+ android:persistent="true"
+ android:title="@string/settings_edit_allow_title"
+ android:summaryOn="@string/settings_edit_allow_summary_on"
+ android:summaryOff="@string/settings_edit_allow_summary_off" />
+
<PreferenceCategory
android:key="category_home"
android:title="@string/settings_category_home">
diff --git a/src/com/android/launcher3/Launcher.java b/src/com/android/launcher3/Launcher.java
index b53560d94..0c12469be 100644
--- a/src/com/android/launcher3/Launcher.java
+++ b/src/com/android/launcher3/Launcher.java
@@ -1091,6 +1091,8 @@ public class Launcher extends BaseActivity
mLauncherCallbacks.onResume();
}
+ mWidgetsButton.setVisibility(Utilities.isWorkspaceEditAllowed(getApplicationContext()) ?
+ View.VISIBLE : View.GONE);
}
@Override
diff --git a/src/com/android/launcher3/SettingsActivity.java b/src/com/android/launcher3/SettingsActivity.java
index 8ae76a81a..8cab471e5 100644
--- a/src/com/android/launcher3/SettingsActivity.java
+++ b/src/com/android/launcher3/SettingsActivity.java
@@ -31,7 +31,6 @@ import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.ApplicationInfo;
-import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.preference.ListPreference;
@@ -62,6 +61,7 @@ public class SettingsActivity extends Activity {
private static final String KEY_SHOW_DRAWER_LABELS = "pref_drawer_show_labels";
static final String KEY_FEED_INTEGRATION = "pref_feed_integration";
+ public static final String KEY_WORKSPACE_EDIT = "pref_workspace_edit";
static final String EXTRA_SCHEDULE_RESTART = "extraScheduleRestart";
diff --git a/src/com/android/launcher3/Utilities.java b/src/com/android/launcher3/Utilities.java
index 300df43c6..bbfc06dbe 100644
--- a/src/com/android/launcher3/Utilities.java
+++ b/src/com/android/launcher3/Utilities.java
@@ -703,4 +703,9 @@ public final class Utilities {
SharedPreferences prefs = getPrefs(context.getApplicationContext());
return prefs.getBoolean(SettingsActivity.KEY_FEED_INTEGRATION, false);
}
+
+ public static boolean isWorkspaceEditAllowed(Context context) {
+ SharedPreferences prefs = getPrefs(context.getApplicationContext());
+ return prefs.getBoolean(SettingsActivity.KEY_WORKSPACE_EDIT, true);
+ }
}
diff --git a/src/com/android/launcher3/dragndrop/DragController.java b/src/com/android/launcher3/dragndrop/DragController.java
index b8527148b..4341e8bbe 100644
--- a/src/com/android/launcher3/dragndrop/DragController.java
+++ b/src/com/android/launcher3/dragndrop/DragController.java
@@ -35,6 +35,7 @@ import com.android.launcher3.ItemInfo;
import com.android.launcher3.Launcher;
import com.android.launcher3.R;
import com.android.launcher3.ShortcutInfo;
+import com.android.launcher3.Utilities;
import com.android.launcher3.accessibility.DragViewStateAnnouncer;
import com.android.launcher3.util.ItemInfoMatcher;
import com.android.launcher3.util.Thunk;
@@ -391,7 +392,14 @@ public class DragController implements DragDriver.EventListener, TouchController
* Call this from a drag source view.
*/
public boolean onControllerInterceptTouchEvent(MotionEvent ev) {
- if (mOptions != null && mOptions.isAccessibleDrag) {
+ boolean isEditDisabled = !Utilities.isWorkspaceEditAllowed(
+ mLauncher.getApplicationContext());
+
+ if ((mOptions != null && mOptions.isAccessibleDrag) || isEditDisabled) {
+ if (isEditDisabled) {
+ cancelDrag();
+ }
+
return false;
}
diff --git a/src/com/android/launcher3/popup/SystemShortcut.java b/src/com/android/launcher3/popup/SystemShortcut.java
index 587c6682d..0f7519838 100644
--- a/src/com/android/launcher3/popup/SystemShortcut.java
+++ b/src/com/android/launcher3/popup/SystemShortcut.java
@@ -12,6 +12,7 @@ import com.android.launcher3.InfoDropTarget;
import com.android.launcher3.ItemInfo;
import com.android.launcher3.Launcher;
import com.android.launcher3.R;
+import com.android.launcher3.Utilities;
import com.android.launcher3.model.WidgetItem;
import com.android.launcher3.util.PackageUserKey;
import com.android.launcher3.widget.WidgetsBottomSheet;
@@ -56,6 +57,10 @@ public abstract class SystemShortcut extends ItemInfo {
@Override
public View.OnClickListener getOnClickListener(final Launcher launcher,
final ItemInfo itemInfo) {
+ if (!Utilities.isWorkspaceEditAllowed(launcher.getApplicationContext())) {
+ return null;
+ }
+
final List<WidgetItem> widgets = launcher.getWidgetsForPackageUser(new PackageUserKey(
itemInfo.getTargetComponent().getPackageName(), itemInfo.user));
if (widgets == null) {
diff --git a/src/com/android/launcher3/shortcuts/ShortcutsItemView.java b/src/com/android/launcher3/shortcuts/ShortcutsItemView.java
index b4fa04e42..1df780d4e 100644
--- a/src/com/android/launcher3/shortcuts/ShortcutsItemView.java
+++ b/src/com/android/launcher3/shortcuts/ShortcutsItemView.java
@@ -34,6 +34,7 @@ import com.android.launcher3.ItemInfo;
import com.android.launcher3.Launcher;
import com.android.launcher3.LauncherAnimUtils;
import com.android.launcher3.R;
+import com.android.launcher3.Utilities;
import com.android.launcher3.anim.PropertyListBuilder;
import com.android.launcher3.anim.RoundedRectRevealOutlineProvider;
import com.android.launcher3.dragndrop.DragOptions;
@@ -110,6 +111,8 @@ public class ShortcutsItemView extends PopupItemView implements View.OnLongClick
if (!mLauncher.isDraggingEnabled()) return false;
// Return early if an item is already being dragged (e.g. when long-pressing two shortcuts)
if (mLauncher.getDragController().isDragging()) return false;
+ // Return early if workspace edit is disabled
+ if (!Utilities.isWorkspaceEditAllowed(mLauncher.getApplicationContext())) return false;
// Long clicked on a shortcut.
DeepShortcutView sv = (DeepShortcutView) v.getParent();