Allow locking/unlocking home screen from home screen menu
Co-authored-by: Daria Hamrah Paytakht <info@dariarnd.ir> Co-authored-by: Patryk Michalik <icontact@patrykmichalik.com>A
This commit is contained in:
4 files changed
+46
-2
No files matched your search
@@ -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<Launcher>
|
||||
* Returns the list of supported actions
|
||||
*/
|
||||
public static ArrayList<OptionItem> getOptions(Launcher launcher) {
|
||||
PreferenceManager2 preferenceManager2 = PreferenceManager2.getInstance(launcher);
|
||||
boolean lockHomeScreen = PreferenceExtensionsKt.firstBlocking(preferenceManager2.getLockHomeScreen());
|
||||
|
||||
ArrayList<OptionItem> 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<Launcher>
|
||||
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;
|
||||
|
||||
Reference in new issue
Block a user