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:
@@ -0,0 +1,9 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="48dp"
|
||||
android:height="48dp"
|
||||
android:viewportWidth="48"
|
||||
android:viewportHeight="48">
|
||||
<path
|
||||
android:fillColor="#FF000000"
|
||||
android:pathData="M24,1Q28.2,1 31.125,3.975Q34.05,6.95 34.05,11.2V14.9H36.55Q38.5,14.9 39.9,16.3Q41.3,17.7 41.3,19.65V40.45Q41.3,42.4 39.9,43.775Q38.5,45.15 36.55,45.15H11.45Q9.5,45.15 8.125,43.775Q6.75,42.4 6.75,40.45V19.65Q6.75,17.7 8.125,16.3Q9.5,14.9 11.45,14.9H13.95V11.2Q13.95,6.95 16.875,3.975Q19.8,1 24,1ZM24,5.75Q21.75,5.75 20.2,7.3Q18.65,8.85 18.65,11.2V14.9H29.35V11.2Q29.35,8.85 27.825,7.3Q26.3,5.75 24,5.75ZM11.45,40.45H36.55Q36.55,40.45 36.55,40.45Q36.55,40.45 36.55,40.45V19.65Q36.55,19.65 36.55,19.65Q36.55,19.65 36.55,19.65H11.45Q11.45,19.65 11.45,19.65Q11.45,19.65 11.45,19.65V40.45Q11.45,40.45 11.45,40.45Q11.45,40.45 11.45,40.45ZM24,26.2Q22.4,26.2 21.275,27.425Q20.15,28.65 20.15,30.15Q20.15,31.7 21.275,32.8Q22.4,33.9 24,33.9Q25.6,33.9 26.725,32.8Q27.85,31.7 27.85,30.15Q27.85,28.65 26.725,27.425Q25.6,26.2 24,26.2ZM11.45,19.65Q11.45,19.65 11.45,19.65Q11.45,19.65 11.45,19.65V40.45Q11.45,40.45 11.45,40.45Q11.45,40.45 11.45,40.45Q11.45,40.45 11.45,40.45Q11.45,40.45 11.45,40.45V19.65Q11.45,19.65 11.45,19.65Q11.45,19.65 11.45,19.65Z"/>
|
||||
</vector>
|
||||
@@ -0,0 +1,9 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="48dp"
|
||||
android:height="48dp"
|
||||
android:viewportWidth="48"
|
||||
android:viewportHeight="48">
|
||||
<path
|
||||
android:fillColor="#FF000000"
|
||||
android:pathData="M13.95,11.2Q13.95,6.8 16.875,3.9Q19.8,1 24,1Q28.2,1 31.125,3.925Q34.05,6.85 34.05,11.2V14.9H36.55Q38.55,14.9 39.925,16.275Q41.3,17.65 41.3,19.65V40.45Q41.3,42.4 39.925,43.775Q38.55,45.15 36.55,45.15H11.45Q9.45,45.15 8.1,43.775Q6.75,42.4 6.75,40.45V19.65Q6.75,17.65 8.1,16.275Q9.45,14.9 11.45,14.9H29.35V11.2Q29.35,8.8 27.8,7.275Q26.25,5.75 24,5.75Q21.75,5.75 20.2,7.275Q18.65,8.8 18.65,11.2ZM11.45,40.45H36.55Q36.55,40.45 36.55,40.45Q36.55,40.45 36.55,40.45V19.65Q36.55,19.65 36.55,19.65Q36.55,19.65 36.55,19.65H11.45Q11.45,19.65 11.45,19.65Q11.45,19.65 11.45,19.65V40.45Q11.45,40.45 11.45,40.45Q11.45,40.45 11.45,40.45ZM24,26.2Q22.4,26.2 21.275,27.425Q20.15,28.65 20.15,30.15Q20.15,31.7 21.275,32.8Q22.4,33.9 24,33.9Q25.6,33.9 26.725,32.8Q27.85,31.7 27.85,30.15Q27.85,28.65 26.725,27.425Q25.6,26.2 24,26.2ZM11.45,19.65Q11.45,19.65 11.45,19.65Q11.45,19.65 11.45,19.65V40.45Q11.45,40.45 11.45,40.45Q11.45,40.45 11.45,40.45Q11.45,40.45 11.45,40.45Q11.45,40.45 11.45,40.45V19.65Q11.45,19.65 11.45,19.65Q11.45,19.65 11.45,19.65Z"/>
|
||||
</vector>
|
||||
@@ -44,6 +44,7 @@
|
||||
<string name="max_folder_rows">Max. Folder Rows</string>
|
||||
<string name="home_screen_grid">Home Screen Grid</string>
|
||||
<string name="home_screen_lock">Lock Home Screen</string>
|
||||
<string name="home_screen_unlock">Unlock Home Screen</string>
|
||||
<string name="columns">Columns</string>
|
||||
<string name="grid">Grid</string>
|
||||
<string name="rows">Rows</string>
|
||||
|
||||
@@ -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