diff --git a/lawnchair/res/drawable/ic_lock.xml b/lawnchair/res/drawable/ic_lock.xml
new file mode 100644
index 0000000000..cd1042e1a0
--- /dev/null
+++ b/lawnchair/res/drawable/ic_lock.xml
@@ -0,0 +1,9 @@
+
+
+
diff --git a/lawnchair/res/drawable/ic_lock_open.xml b/lawnchair/res/drawable/ic_lock_open.xml
new file mode 100644
index 0000000000..be031f848f
--- /dev/null
+++ b/lawnchair/res/drawable/ic_lock_open.xml
@@ -0,0 +1,9 @@
+
+
+
diff --git a/lawnchair/res/values/strings.xml b/lawnchair/res/values/strings.xml
index f6b807e0fe..0cdb3e89fa 100644
--- a/lawnchair/res/values/strings.xml
+++ b/lawnchair/res/values/strings.xml
@@ -44,6 +44,7 @@
Max. Folder Rows
Home Screen Grid
Lock Home Screen
+ Unlock Home Screen
Columns
Grid
Rows
diff --git a/src/com/android/launcher3/views/OptionsPopupView.java b/src/com/android/launcher3/views/OptionsPopupView.java
index 1d94aa66cd..4a48a23935 100644
--- a/src/com/android/launcher3/views/OptionsPopupView.java
+++ b/src/com/android/launcher3/views/OptionsPopupView.java
@@ -22,12 +22,12 @@ import static com.android.launcher3.logging.StatsLogManager.LauncherEvent.IGNORE
import static com.android.launcher3.logging.StatsLogManager.LauncherEvent.LAUNCHER_SETTINGS_BUTTON_TAP_OR_LONGPRESS;
import static com.android.launcher3.logging.StatsLogManager.LauncherEvent.LAUNCHER_WIDGETSTRAY_BUTTON_TAP_OR_LONGPRESS;
+import android.annotation.SuppressLint;
import android.content.Context;
import android.content.Intent;
import android.graphics.Rect;
import android.graphics.RectF;
import android.graphics.drawable.Drawable;
-import android.text.TextUtils;
import android.util.ArrayMap;
import android.util.AttributeSet;
import android.view.MotionEvent;
@@ -58,6 +58,10 @@ import java.util.ArrayList;
import java.util.List;
import app.lawnchair.preferences2.PreferenceManager2;
+import kotlin.coroutines.CoroutineContext;
+import kotlinx.coroutines.BuildersKt;
+import kotlinx.coroutines.CoroutineStart;
+import kotlinx.coroutines.GlobalScope;
/**
* Popup shown on long pressing an empty space in launcher
@@ -182,13 +186,20 @@ public class OptionsPopupView extends ArrowPopup
* Returns the list of supported actions
*/
public static ArrayList getOptions(Launcher launcher) {
+ PreferenceManager2 preferenceManager2 = PreferenceManager2.getInstance(launcher);
+ boolean lockHomeScreen = PreferenceExtensionsKt.firstBlocking(preferenceManager2.getLockHomeScreen());
+
ArrayList options = new ArrayList<>();
+ options.add(new OptionItem(launcher,
+ lockHomeScreen ? R.string.home_screen_unlock : R.string.home_screen_lock,
+ lockHomeScreen ? R.drawable.ic_lock_open : R.drawable.ic_lock,
+ IGNORE,
+ OptionsPopupView::toggleHomeScreenLock));
options.add(new OptionItem(launcher,
R.string.settings_button_text,
R.drawable.ic_setting,
LAUNCHER_SETTINGS_BUTTON_TAP_OR_LONGPRESS,
OptionsPopupView::startSettings));
- boolean lockHomeScreen = PreferenceExtensionsKt.firstBlocking(PreferenceManager2.INSTANCE.get(launcher).getLockHomeScreen());
if (!lockHomeScreen && !WidgetsModel.GO_DISABLE_WIDGETS) {
options.add(new OptionItem(launcher,
R.string.widget_button_text,
@@ -262,6 +273,20 @@ public class OptionsPopupView extends ArrowPopup
return launcher.startActivitySafely(v, intent, placeholderInfo(intent));
}
+ @SuppressLint("UnsafeOptInUsageWarning")
+ private static boolean toggleHomeScreenLock(View v) {
+ Context context = v.getContext();
+ PreferenceManager2 preferenceManager2 = PreferenceManager2.getInstance(context);
+ GlobalScope globalScope = GlobalScope.INSTANCE;
+ CoroutineContext coroutineContext = globalScope.getCoroutineContext();
+ BuildersKt.launch(globalScope,
+ coroutineContext,
+ CoroutineStart.DEFAULT,
+ (coroutineScope, continuation) -> PreferenceExtensionsKt.toggle(preferenceManager2.getLockHomeScreen(), continuation)
+ );
+ return true;
+ }
+
static WorkspaceItemInfo placeholderInfo(Intent intent) {
WorkspaceItemInfo placeholderInfo = new WorkspaceItemInfo();
placeholderInfo.intent = intent;