OSDN Git Service

Bring back the ability to lock the device's screen on Android 9 and later
authorBraden Farmer <farmerbb@gmail.com>
Sat, 16 Nov 2019 04:16:27 +0000 (21:16 -0700)
committerBraden Farmer <farmerbb@gmail.com>
Sat, 16 Nov 2019 04:16:27 +0000 (21:16 -0700)
16 files changed:
app/src/androidx86/AndroidManifest.xml
app/src/main/java/com/farmerbb/taskbar/activity/ContextMenuActivity.java
app/src/main/java/com/farmerbb/taskbar/activity/HomeActivityDelegate.java
app/src/main/java/com/farmerbb/taskbar/activity/KeyboardShortcutActivityLockDevice.java [new file with mode: 0644]
app/src/main/java/com/farmerbb/taskbar/activity/MainActivity.java
app/src/main/java/com/farmerbb/taskbar/fragment/AdvancedFragment.java
app/src/main/java/com/farmerbb/taskbar/util/U.java
app/src/main/res/values-de-v28/strings.xml [new file with mode: 0644]
app/src/main/res/values-ja-v28/strings.xml [new file with mode: 0644]
app/src/main/res/values-nl-v28/strings.xml [new file with mode: 0644]
app/src/main/res/values-ru-v28/strings.xml [new file with mode: 0644]
app/src/main/res/values-tr-v28/strings.xml [new file with mode: 0644]
app/src/main/res/values-v28/strings.xml [new file with mode: 0644]
app/src/main/res/values-zh-rCN-v28/strings.xml [new file with mode: 0644]
app/src/main/res/xml/tb_pref_context_menu_overflow.xml
app/src/playstore/AndroidManifest.xml

index 43c0181..e01b303 100644 (file)
             </intent-filter>
         </activity>
         <activity
+            android:name=".activity.KeyboardShortcutActivityLockDevice"
+            android:label="${appName}"
+            android:documentLaunchMode="always"
+            android:excludeFromRecents="true"
+            android:launchMode="singleTask"
+            android:enabled="false"
+            android:theme="@android:style/Theme.NoDisplay">
+            <intent-filter>
+                <action android:name="android.intent.action.MAIN"/>
+
+                <category android:name="android.intent.category.DEFAULT"/>
+                <category android:name="android.intent.category.APP_CALENDAR" />
+            </intent-filter>
+        </activity>
+        <activity
             android:name=".activity.ContextMenuActivity"
             android:documentLaunchMode="always"
             android:excludeFromRecents="true"
index a109c17..a92ab5a 100644 (file)
@@ -283,6 +283,11 @@ public class ContextMenuActivity extends PreferenceActivity implements Preferenc
             else
                 getPreferenceScreen().removePreference(findPreference("power_menu"));
 
+            if(!U.isLibrary(this) && Build.VERSION.SDK_INT >= Build.VERSION_CODES.P)
+                findPreference("lock_device").setOnPreferenceClickListener(this);
+            else
+                getPreferenceScreen().removePreference(findPreference("lock_device"));
+
             if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.M)
                 findPreference("file_manager").setOnPreferenceClickListener(this);
             else
@@ -663,6 +668,13 @@ public class ContextMenuActivity extends PreferenceActivity implements Preferenc
                 shouldHideTaskbar = true;
                 contextMenuFix = false;
                 break;
+            case "lock_device":
+                U.lockDevice(this);
+
+                showStartMenu = false;
+                shouldHideTaskbar = true;
+                contextMenuFix = false;
+                break;
             case "power_menu":
                 U.sendAccessibilityAction(this, AccessibilityService.GLOBAL_ACTION_POWER_DIALOG);
 
index acb4c8d..3570aa1 100644 (file)
@@ -41,6 +41,7 @@ import androidx.appcompat.app.AppCompatActivity;
 import android.util.SparseArray;
 import android.view.Display;
 import android.view.DragEvent;
+import android.view.GestureDetector;
 import android.view.Gravity;
 import android.view.LayoutInflater;
 import android.view.MotionEvent;
@@ -263,6 +264,84 @@ public class HomeActivityDelegate extends AppCompatActivity implements UIHost {
 
         layout.setFitsSystemWindows(true);
 
+        if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.P 
+                && isDesktopIconsEnabled
+                && !U.isLibrary(this)) {
+            final GestureDetector detector = new GestureDetector(this, new GestureDetector.OnGestureListener() {
+                @Override
+                public boolean onSingleTapUp(MotionEvent e) {
+                    return false;
+                }
+
+                @Override
+                public void onShowPress(MotionEvent e) {}
+
+                @Override
+                public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {
+                    return false;
+                }
+
+                @Override
+                public void onLongPress(MotionEvent e) {}
+
+                @Override
+                public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
+                    return false;
+                }
+
+                @Override
+                public boolean onDown(MotionEvent e) {
+                    return false;
+                }
+            });
+
+            detector.setOnDoubleTapListener(new GestureDetector.OnDoubleTapListener() {
+                @Override
+                public boolean onDoubleTap(MotionEvent e) {
+                    if(!pref.getBoolean("dont_show_double_tap_dialog", false)) {
+                        if(pref.getBoolean("double_tap_to_sleep", false)) {
+                            U.lockDevice(HomeActivityDelegate.this);
+                        } else {
+                            AlertDialog.Builder builder = new AlertDialog.Builder(U.wrapContext(HomeActivityDelegate.this));
+                            builder.setTitle(R.string.tb_double_tap_to_sleep)
+                                    .setMessage(R.string.tb_enable_double_tap_to_sleep)
+                                    .setNegativeButton(pref.getBoolean("double_tap_dialog_shown", false)
+                                            ? R.string.tb_action_dont_show_again
+                                            : R.string.tb_action_cancel, (dialog, which) -> pref.edit().putBoolean(pref.getBoolean("double_tap_dialog_shown", false)
+                                            ? "dont_show_double_tap_dialog"
+                                            : "double_tap_dialog_shown", true).apply())
+                                    .setPositiveButton(R.string.tb_action_ok, (dialog, which) -> {
+                                        pref.edit().putBoolean("double_tap_to_sleep", true).apply();
+                                        U.lockDevice(HomeActivityDelegate.this);
+                                    });
+
+                            AlertDialog dialog = builder.create();
+                            dialog.show();
+                        }
+                    }
+
+                    return false;
+                }
+
+                @Override
+                public boolean onDoubleTapEvent(MotionEvent e) {
+                    return false;
+                }
+
+                @Override
+                public boolean onSingleTapConfirmed(MotionEvent e) {
+                    return false;
+                }
+
+            });
+
+            layout.setOnTouchListener((v, event) -> {
+                detector.onTouchEvent(event);
+
+                return false;
+            });
+        }
+
         if((this instanceof HomeActivity ||
                 this instanceof SecondaryHomeActivity
                 || U.isLauncherPermanentlyEnabled(this))
diff --git a/app/src/main/java/com/farmerbb/taskbar/activity/KeyboardShortcutActivityLockDevice.java b/app/src/main/java/com/farmerbb/taskbar/activity/KeyboardShortcutActivityLockDevice.java
new file mode 100644 (file)
index 0000000..f5e3775
--- /dev/null
@@ -0,0 +1,42 @@
+/* Copyright 2019 Braden Farmer
+ *
+ * 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.
+ */
+
+package com.farmerbb.taskbar.activity;
+
+import android.app.Activity;
+import android.content.Intent;
+import android.os.Bundle;
+
+import com.farmerbb.taskbar.util.U;
+
+import java.util.Set;
+
+public class KeyboardShortcutActivityLockDevice extends Activity {
+
+    @Override
+    protected void onCreate(Bundle savedInstanceState) {
+        super.onCreate(savedInstanceState);
+
+        if(Intent.ACTION_MAIN.equals(getIntent().getAction())) {
+            Intent selector = getIntent().getSelector();
+            Set<String> categories = selector != null ? selector.getCategories() : getIntent().getCategories();
+
+            if(categories.contains(Intent.CATEGORY_APP_CALENDAR))
+                U.lockDevice(this);
+        }
+
+        finish();
+    }
+}
index 27b0517..999854d 100644 (file)
@@ -136,6 +136,15 @@ public class MainActivity extends AppCompatActivity {
                             ? PackageManager.COMPONENT_ENABLED_STATE_ENABLED
                             : PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
                     PackageManager.DONT_KILL_APP);
+
+            if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
+                ComponentName component6 = new ComponentName(this, KeyboardShortcutActivityLockDevice.class);
+                getPackageManager().setComponentEnabledSetting(component6,
+                        pref.getBoolean("keyboard_shortcut", false)
+                                ? PackageManager.COMPONENT_ENABLED_STATE_ENABLED
+                                : PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
+                        PackageManager.DONT_KILL_APP);
+            }
         }
 
         if(!launcherEnabled)
index 9b5e580..c7db12a 100644 (file)
@@ -27,6 +27,7 @@ import android.content.SharedPreferences;
 import android.content.pm.PackageManager;
 import android.content.res.Configuration;
 import android.net.Uri;
+import android.os.Build;
 import android.os.Bundle;
 import android.os.Handler;
 import android.preference.CheckBoxPreference;
@@ -43,6 +44,7 @@ import android.widget.LinearLayout;
 import com.farmerbb.taskbar.BuildConfig;
 import com.farmerbb.taskbar.R;
 import com.farmerbb.taskbar.activity.ClearDataActivity;
+import com.farmerbb.taskbar.activity.KeyboardShortcutActivityLockDevice;
 import com.farmerbb.taskbar.activity.NavigationBarButtonsActivity;
 import com.farmerbb.taskbar.activity.SecondaryHomeActivity;
 import com.farmerbb.taskbar.activity.dark.ClearDataActivityDark;
@@ -201,6 +203,13 @@ public class AdvancedFragment extends SettingsFragment implements Preference.OnP
                 getActivity().getPackageManager().setComponentEnabledSetting(component,
                         ((CheckBoxPreference) p).isChecked() ? PackageManager.COMPONENT_ENABLED_STATE_ENABLED : PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
                         PackageManager.DONT_KILL_APP);
+
+                if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
+                    ComponentName component2 = new ComponentName(getActivity(), KeyboardShortcutActivityLockDevice.class);
+                    getActivity().getPackageManager().setComponentEnabledSetting(component2,
+                            ((CheckBoxPreference) p).isChecked() ? PackageManager.COMPONENT_ENABLED_STATE_ENABLED : PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
+                            PackageManager.DONT_KILL_APP);
+                }
                 break;
             case "dashboard_grid_size":
                 AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
index 8b6e7c1..1f2800c 100644 (file)
@@ -16,6 +16,7 @@
 package com.farmerbb.taskbar.util;
 
 import android.Manifest;
+import android.accessibilityservice.AccessibilityService;
 import android.annotation.SuppressLint;
 import android.annotation.TargetApi;
 import android.app.ActivityManager;
@@ -164,6 +165,11 @@ public class U {
         return dialog;
     }
 
+    @TargetApi(Build.VERSION_CODES.P)
+    public static void lockDevice(Context context) {
+        sendAccessibilityAction(context, AccessibilityService.GLOBAL_ACTION_LOCK_SCREEN);
+    }
+
     public static void sendAccessibilityAction(Context context, int action) {
         sendAccessibilityAction(context, action, null);
     }
diff --git a/app/src/main/res/values-de-v28/strings.xml b/app/src/main/res/values-de-v28/strings.xml
new file mode 100644 (file)
index 0000000..cf94c5a
--- /dev/null
@@ -0,0 +1,21 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright 2019 Braden Farmer
+
+     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.
+-->
+
+<resources>
+
+    <string name="tb_pref_description_keyboard_shortcut">Taskbar starten / anhalten\n - Super + M / Suche + M\n\nGerät sperren\n - Super + L / Suche + L\n\nStartmenü anzeigen\n - Super / Suche\n(Muss in den Einstellungen als Suchassistent festgelegt werden)</string>
+
+</resources>
diff --git a/app/src/main/res/values-ja-v28/strings.xml b/app/src/main/res/values-ja-v28/strings.xml
new file mode 100644 (file)
index 0000000..3656f51
--- /dev/null
@@ -0,0 +1,21 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright 2019 Braden Farmer
+
+     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.
+-->
+
+<resources>
+
+    <string name="tb_pref_description_keyboard_shortcut">Taskbar の開始/停止\n&#8226; Winキー+M, 検索+M\n\nデバイスのロック\n&#8226; Winキー+L, 検索+L\n\nスタートメニューを表示\n&#8226; Winキー, 検索\n(設定で Taskbar を検索アシスタントとして設定が必要)</string>
+
+</resources>
\ No newline at end of file
diff --git a/app/src/main/res/values-nl-v28/strings.xml b/app/src/main/res/values-nl-v28/strings.xml
new file mode 100644 (file)
index 0000000..1340d8f
--- /dev/null
@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright 2019 Braden Farmer
+
+     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.
+-->
+
+<resources>
+
+    <string name="tb_pref_description_keyboard_shortcut">Taakbalk starten/stoppen: &#160; {fou_social-windows} + M &#160; {fou_magnifying-glass} + M\n\nApparaat vergrendelen: &#160; {fou_social-windows} + L &#160; {fou_magnifying-glass} + L\n\nStartmenu tonen: &#160; {fou_social-windows} &#160; {fou_magnifying-glass}\n(Taakbalk moet hiervoor worden ingesteld als assistent-app in de Instellingen)</string>
+    <string name="tb_pref_description_keyboard_shortcut_alt">Taakbalk starten/stoppen\n&#8226; WinKey+M / Search+M\n\nApparaat vergrendelen\n&#8226; WinKey+L / Search+L\n\nStartmenu tonen\n&#8226; WinKey / Search\n(Taakbalk moet hiervoor worden ingesteld als assistent-app in de Instellingen)</string>
+
+</resources>
diff --git a/app/src/main/res/values-ru-v28/strings.xml b/app/src/main/res/values-ru-v28/strings.xml
new file mode 100644 (file)
index 0000000..fde7e88
--- /dev/null
@@ -0,0 +1,21 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright 2019 Braden Farmer
+
+     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.
+-->
+
+<resources>
+
+    <string name="tb_pref_description_keyboard_shortcut">Запуск/остановка Taskbar\n&#8226; WinKey+M, Search+M\n\nЗаблокировать устройство\n&#8226; WinKey+L, Search+L\n\nПоказать меню\n&#8226; WinKey, Search\n(нужно установить Taskbar ассистентом по умолчанию)</string>
+
+</resources>
\ No newline at end of file
diff --git a/app/src/main/res/values-tr-v28/strings.xml b/app/src/main/res/values-tr-v28/strings.xml
new file mode 100644 (file)
index 0000000..436b5d0
--- /dev/null
@@ -0,0 +1,34 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright 2019 Braden Farmer
+
+     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.
+-->
+
+<resources>
+<string name="tb_pref_description_keyboard_shortcut">"Taskbar başlat/durdur:   {fou_social-windows} + M   {fou_magnifying-glass} + M
+
+Cihaz kilitlemr:   {fou_social-windows} + L   {fou_magnifying-glass} + L
+
+Başlat menüsünü gösterme:   {fou_social-windows}   {fou_magnifying-glass}
+(ayarlarda Taskbar yardımcı uygulaması olarak ayarlanmasını gerektirir)"</string>
+<string name="tb_pref_description_keyboard_shortcut_alt">"Taskbar başlat/durdur
+• WinKey+M / Search+M
+
+Cihaz kilitle
+• WinKey+L / Search+L
+
+Başlat menüsü gösterme
+• WinKey / Search
+(ayarlarda Taskbar yardımcı uygulaması olarak ayarlanmasını gerektirir)"</string>
+
+</resources>
\ No newline at end of file
diff --git a/app/src/main/res/values-v28/strings.xml b/app/src/main/res/values-v28/strings.xml
new file mode 100644 (file)
index 0000000..81a3a68
--- /dev/null
@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright 2019 Braden Farmer
+
+     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.
+-->
+
+<resources>
+
+    <string name="tb_pref_description_keyboard_shortcut">Start/stop Taskbar: &#160; {fou_social-windows} + M &#160; {fou_magnifying-glass} + M\n\nLock device: &#160; {fou_social-windows} + L &#160; {fou_magnifying-glass} + L\n\nShow start menu: &#160; {fou_social-windows} &#160; {fou_magnifying-glass}\n(requires Taskbar to be set as the assist app in Settings)</string>
+    <string name="tb_pref_description_keyboard_shortcut_alt">Start/stop Taskbar\n&#8226; WinKey+M / Search+M\n\nLock device\n&#8226; WinKey+L / Search+L\n\nShow start menu\n&#8226; WinKey / Search\n(requires Taskbar to be set as the assist app in Settings)</string>
+
+</resources>
diff --git a/app/src/main/res/values-zh-rCN-v28/strings.xml b/app/src/main/res/values-zh-rCN-v28/strings.xml
new file mode 100644 (file)
index 0000000..ddd3097
--- /dev/null
@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright 2019 Braden Farmer
+
+     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.
+-->
+
+<resources>
+
+    <string name="tb_pref_description_keyboard_shortcut">开始/停止任务栏: &#160; {fou_social-windows} + M &#160; {fou_magnifying-glass} + M\n\n锁定设备: &#160; {fou_social-windows} + L &#160; {fou_magnifying-glass} + L\n\n显示开始菜单: &#160; {fou_social-windows} &#160; {fou_magnifying-glass}\n(需要在设置中将任务栏设为辅助应用)</string>
+    <string name="tb_pref_description_keyboard_shortcut_alt">开始/停止任务栏\n&#8226; WinKey+M / Search+M\n\n锁定设备\n&#8226; WinKey+L / Search+L\n\n显示开始菜单\n&#8226; WinKey / Search\n(requires Taskbar to be set as the assist app in Settings)</string>
+
+</resources>
\ No newline at end of file
index 3d46051..6392656 100644 (file)
         android:title="@string/tb_volume" />
 
     <Preference
+        android:key="lock_device"
+        android:title="@string/tb_lock_device" />
+
+    <Preference
         android:key="file_manager"
         android:title="@string/tb_file_manager" />
 
index 5693034..1ea3f16 100644 (file)
             </intent-filter>
         </activity>
         <activity
+            android:name=".activity.KeyboardShortcutActivityLockDevice"
+            android:label="${appName}"
+            android:documentLaunchMode="always"
+            android:excludeFromRecents="true"
+            android:launchMode="singleTask"
+            android:enabled="false"
+            android:theme="@android:style/Theme.NoDisplay">
+            <intent-filter>
+                <action android:name="android.intent.action.MAIN"/>
+
+                <category android:name="android.intent.category.DEFAULT"/>
+                <category android:name="android.intent.category.APP_CALENDAR" />
+            </intent-filter>
+        </activity>
+        <activity
             android:name=".activity.ContextMenuActivity"
             android:documentLaunchMode="always"
             android:excludeFromRecents="true"