OSDN Git Service

No need to show a notification after all
authorBraden Farmer <farmerbb@gmail.com>
Tue, 24 Nov 2020 06:12:10 +0000 (23:12 -0700)
committerBraden Farmer <farmerbb@gmail.com>
Tue, 24 Nov 2020 06:17:26 +0000 (23:17 -0700)
12 files changed:
app/src/main/java/com/farmerbb/taskbar/receiver/KeyboardChangeReceiver.java [deleted file]
app/src/main/java/com/farmerbb/taskbar/service/DisableKeyboardService.java
app/src/main/res/values-de/strings.xml
app/src/main/res/values-es/strings.xml
app/src/main/res/values-ja/strings.xml
app/src/main/res/values-nl/strings.xml
app/src/main/res/values-pl/strings.xml
app/src/main/res/values-ru/strings.xml
app/src/main/res/values-tr/strings.xml
app/src/main/res/values-zh-rCN/strings.xml
app/src/main/res/values/strings.xml
app/src/playstore/AndroidManifest.xml

diff --git a/app/src/main/java/com/farmerbb/taskbar/receiver/KeyboardChangeReceiver.java b/app/src/main/java/com/farmerbb/taskbar/receiver/KeyboardChangeReceiver.java
deleted file mode 100644 (file)
index d39f606..0000000
+++ /dev/null
@@ -1,30 +0,0 @@
-/* Copyright 2020 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.receiver;
-
-import android.content.BroadcastReceiver;
-import android.content.Context;
-import android.content.Intent;
-import android.view.inputmethod.InputMethodManager;
-
-public class KeyboardChangeReceiver extends BroadcastReceiver {
-
-    @Override
-    public void onReceive(Context context, Intent intent) {
-        InputMethodManager imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
-        imm.showInputMethodPicker();
-    }
-}
\ No newline at end of file
index a449d00..89dbfee 100644 (file)
 package com.farmerbb.taskbar.service;
 
 import android.annotation.TargetApi;
-import android.app.KeyguardManager;
-import android.app.NotificationChannel;
-import android.app.NotificationManager;
-import android.app.PendingIntent;
-import android.app.admin.DevicePolicyManager;
-import android.content.Context;
-import android.content.Intent;
 import android.content.res.Configuration;
 import android.hardware.display.DisplayManager;
 import android.inputmethodservice.InputMethodService;
 import android.os.Build;
-import androidx.core.app.NotificationCompat;
 import android.text.InputType;
 import android.view.inputmethod.EditorInfo;
-import android.view.inputmethod.InputMethodManager;
 
 import com.farmerbb.taskbar.R;
-import com.farmerbb.taskbar.receiver.KeyboardChangeReceiver;
 import com.farmerbb.taskbar.util.U;
 
-import java.util.Random;
-
 public class DisableKeyboardService extends InputMethodService {
 
-    Integer notificationId;
-
     @Override
     public boolean onShowInputRequested(int flags, boolean configChange) {
         return false;
@@ -79,72 +65,22 @@ public class DisableKeyboardService extends InputMethodService {
         manager.registerDisplayListener(listener, null);
     }
 
-    @TargetApi(Build.VERSION_CODES.O)
     @Override
-    public void onStartInput(EditorInfo attribute, boolean restarting) {
-        boolean isEditingText = attribute.inputType != InputType.TYPE_NULL;
-        boolean hasHardwareKeyboard = getResources().getConfiguration().keyboard != Configuration.KEYBOARD_NOKEYS;
-
-        if(notificationId == null && isEditingText && !hasHardwareKeyboard) {
-            Intent keyboardChangeIntent = new Intent(this, KeyboardChangeReceiver.class);
-            PendingIntent keyboardChangePendingIntent = PendingIntent.getBroadcast(this, 0, keyboardChangeIntent, PendingIntent.FLAG_UPDATE_CURRENT);
-
-            String id = getClass().getSimpleName();
-            CharSequence name = getString(R.string.tb_desktop_mode_ime_fix);
-            int importance = NotificationManager.IMPORTANCE_DEFAULT;
-
-            NotificationManager nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
-            nm.createNotificationChannel(new NotificationChannel(id, name, importance));
-
-            NotificationCompat.Builder notification = new NotificationCompat.Builder(this, id)
-                    .setContentIntent(keyboardChangePendingIntent)
-                    .setSmallIcon(android.R.drawable.stat_sys_warning)
-                    .setContentTitle(getString(R.string.tb_disabling_soft_keyboard))
-                    .setContentText(getString(R.string.tb_tap_to_change_keyboards))
-                    .setOngoing(true)
-                    .setShowWhen(false);
-
-            notificationId = new Random().nextInt();
-            nm.notify(notificationId, notification.build());
-
-            boolean autoShowInputMethodPicker = false;
-            if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
-                DevicePolicyManager devicePolicyManager = (DevicePolicyManager) getSystemService(DEVICE_POLICY_SERVICE);
-                switch(devicePolicyManager.getStorageEncryptionStatus()) {
-                    case DevicePolicyManager.ENCRYPTION_STATUS_ACTIVE:
-                    case DevicePolicyManager.ENCRYPTION_STATUS_ACTIVE_PER_USER:
-                        break;
-                    default:
-                        autoShowInputMethodPicker = true;
-                        break;
-                }
-            }
-
-            KeyguardManager keyguardManager = (KeyguardManager) getSystemService(KEYGUARD_SERVICE);
-            if(keyguardManager.inKeyguardRestrictedInputMode() && autoShowInputMethodPicker) {
-                InputMethodManager imm = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE);
-                imm.showInputMethodPicker();
-            }
-        } else if(notificationId != null && !isEditingText) {
-            NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
-            nm.cancel(notificationId);
+    public void onDestroy() {
+        DisplayManager manager = (DisplayManager) getSystemService(DISPLAY_SERVICE);
+        manager.unregisterDisplayListener(listener);
 
-            notificationId = null;
-        }
+        super.onDestroy();
     }
 
     @Override
-    public void onDestroy() {
-        if(notificationId != null) {
-            NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
-            nm.cancel(notificationId);
+    public void onStartInput(EditorInfo attribute, boolean restarting) {
+        boolean isEditingText = attribute.inputType != InputType.TYPE_NULL;
+        boolean hasHardwareKeyboard = getResources().getConfiguration().keyboard != Configuration.KEYBOARD_NOKEYS;
 
-            notificationId = null;
+        if(isEditingText && !hasHardwareKeyboard) {
+            U.showToast(this, R.string.tb_desktop_mode_ime_fix_toast_alt);
+            checkIfShouldDisable();
         }
-
-        DisplayManager manager = (DisplayManager) getSystemService(DISPLAY_SERVICE);
-        manager.unregisterDisplayListener(listener);
-
-        super.onDestroy();
     }
 }
\ No newline at end of file
index 67323b0..b7b409f 100644 (file)
     <string name="tb_desktop_mode_ime_fix_title">Enable input method fix</string>
     <string name="tb_desktop_mode_ime_fix_summary">Fixes visual glitches caused by input methods on Android 11. Requires you to temporarily set Taskbar as your input method each time desktop mode starts.</string>
     <string name="tb_desktop_mode_ime_fix_toast">Open desktop mode settings to enable a fix for visual glitches caused by input methods</string>
-    <string name="tb_disabling_soft_keyboard">Disabling soft keyboard</string>
-    <string name="tb_tap_to_change_keyboards">Tap to change keyboards</string>
+    <string name="tb_desktop_mode_ime_fix_toast_alt">Start desktop mode first before enabling the input method fix</string>
 
     <string name="tb_rom">ROM</string>
 </resources>
index 9cf0b16..4527263 100644 (file)
     <string name="tb_desktop_mode_ime_fix_title">Enable input method fix</string>
     <string name="tb_desktop_mode_ime_fix_summary">Fixes visual glitches caused by input methods on Android 11. Requires you to temporarily set Taskbar as your input method each time desktop mode starts.</string>
     <string name="tb_desktop_mode_ime_fix_toast">Open desktop mode settings to enable a fix for visual glitches caused by input methods</string>
-    <string name="tb_disabling_soft_keyboard">Disabling soft keyboard</string>
-    <string name="tb_tap_to_change_keyboards">Tap to change keyboards</string>
+    <string name="tb_desktop_mode_ime_fix_toast_alt">Start desktop mode first before enabling the input method fix</string>
 
     <string name="tb_rom">ROM</string>
 </resources>
index 75fa368..2e05be9 100644 (file)
     <string name="tb_desktop_mode_ime_fix_title">Enable input method fix</string>
     <string name="tb_desktop_mode_ime_fix_summary">Fixes visual glitches caused by input methods on Android 11. Requires you to temporarily set Taskbar as your input method each time desktop mode starts.</string>
     <string name="tb_desktop_mode_ime_fix_toast">Open desktop mode settings to enable a fix for visual glitches caused by input methods</string>
-    <string name="tb_disabling_soft_keyboard">Disabling soft keyboard</string>
-    <string name="tb_tap_to_change_keyboards">Tap to change keyboards</string>
+    <string name="tb_desktop_mode_ime_fix_toast_alt">Start desktop mode first before enabling the input method fix</string>
 
     <string name="tb_rom">ROM</string>
 </resources>
\ No newline at end of file
index 6bbf1c4..1dc1e06 100644 (file)
     <string name="tb_desktop_mode_ime_fix_title">Enable input method fix</string>
     <string name="tb_desktop_mode_ime_fix_summary">Fixes visual glitches caused by input methods on Android 11. Requires you to temporarily set Taskbar as your input method each time desktop mode starts.</string>
     <string name="tb_desktop_mode_ime_fix_toast">Open desktop mode settings to enable a fix for visual glitches caused by input methods</string>
-    <string name="tb_disabling_soft_keyboard">Disabling soft keyboard</string>
-    <string name="tb_tap_to_change_keyboards">Tap to change keyboards</string>
+    <string name="tb_desktop_mode_ime_fix_toast_alt">Start desktop mode first before enabling the input method fix</string>
 
     <string name="tb_rom">ROM</string>
 </resources>
index b248edc..7764e24 100644 (file)
@@ -505,8 +505,7 @@ W takim przypadku może być konieczne flashowanie niestandardowego ROM-u w celu
     <string name="tb_desktop_mode_ime_fix_title">Enable input method fix</string>
     <string name="tb_desktop_mode_ime_fix_summary">Fixes visual glitches caused by input methods on Android 11. Requires you to temporarily set Taskbar as your input method each time desktop mode starts.</string>
     <string name="tb_desktop_mode_ime_fix_toast">Open desktop mode settings to enable a fix for visual glitches caused by input methods</string>
-    <string name="tb_disabling_soft_keyboard">Disabling soft keyboard</string>
-    <string name="tb_tap_to_change_keyboards">Tap to change keyboards</string>
+    <string name="tb_desktop_mode_ime_fix_toast_alt">Start desktop mode first before enabling the input method fix</string>
 
     <string name="tb_rom">ROM</string>
 </resources>
index fdee5c5..6cd0d97 100644 (file)
     <string name="tb_desktop_mode_ime_fix_title">Enable input method fix</string>
     <string name="tb_desktop_mode_ime_fix_summary">Fixes visual glitches caused by input methods on Android 11. Requires you to temporarily set Taskbar as your input method each time desktop mode starts.</string>
     <string name="tb_desktop_mode_ime_fix_toast">Open desktop mode settings to enable a fix for visual glitches caused by input methods</string>
-    <string name="tb_disabling_soft_keyboard">Disabling soft keyboard</string>
-    <string name="tb_tap_to_change_keyboards">Tap to change keyboards</string>
+    <string name="tb_desktop_mode_ime_fix_toast_alt">Start desktop mode first before enabling the input method fix</string>
 
     <string name="tb_rom">ROM</string>
 </resources>
\ No newline at end of file
index 0ccbf89..43cbba8 100644 (file)
@@ -480,8 +480,7 @@ Bu durumda, bu cihazdaki serbest biçimli modu kullanmak için özel bir ROM fla
     <string name="tb_desktop_mode_ime_fix_title">Enable input method fix</string>
     <string name="tb_desktop_mode_ime_fix_summary">Fixes visual glitches caused by input methods on Android 11. Requires you to temporarily set Taskbar as your input method each time desktop mode starts.</string>
     <string name="tb_desktop_mode_ime_fix_toast">Open desktop mode settings to enable a fix for visual glitches caused by input methods</string>
-    <string name="tb_disabling_soft_keyboard">Disabling soft keyboard</string>
-    <string name="tb_tap_to_change_keyboards">Tap to change keyboards</string>
+    <string name="tb_desktop_mode_ime_fix_toast_alt">Start desktop mode first before enabling the input method fix</string>
 
     <string name="tb_rom">ROM</string>
 </resources>
index 16c8a8d..e235517 100644 (file)
     <string name="tb_desktop_mode_ime_fix_title">Enable input method fix</string>
     <string name="tb_desktop_mode_ime_fix_summary">Fixes visual glitches caused by input methods on Android 11. Requires you to temporarily set Taskbar as your input method each time desktop mode starts.</string>
     <string name="tb_desktop_mode_ime_fix_toast">Open desktop mode settings to enable a fix for visual glitches caused by input methods</string>
-    <string name="tb_disabling_soft_keyboard">Disabling soft keyboard</string>
-    <string name="tb_tap_to_change_keyboards">Tap to change keyboards</string>
+    <string name="tb_desktop_mode_ime_fix_toast_alt">Start desktop mode first before enabling the input method fix</string>
 
     <string name="tb_rom">ROM</string>
 </resources>
index 7d8d097..8045fc7 100644 (file)
     <string name="tb_desktop_mode_ime_fix_title">Enable input method fix</string>
     <string name="tb_desktop_mode_ime_fix_summary">Fixes visual glitches caused by input methods on Android 11. Requires you to temporarily set Taskbar as your input method each time desktop mode starts.</string>
     <string name="tb_desktop_mode_ime_fix_toast">Open desktop mode settings to enable a fix for visual glitches caused by input methods</string>
-    <string name="tb_disabling_soft_keyboard">Disabling soft keyboard</string>
-    <string name="tb_tap_to_change_keyboards">Tap to change keyboards</string>
+    <string name="tb_desktop_mode_ime_fix_toast_alt">Start desktop mode first before enabling the input method fix</string>
 
     <string name="tb_rom">ROM</string>
 </resources>
index 324b9be..9ab02ae 100644 (file)
                 <action android:name="com.twofortyfouram.locale.intent.action.QUERY_CONDITION" />
             </intent-filter>
         </receiver>
-        <receiver
-            android:name=".receiver.KeyboardChangeReceiver"
-            android:enabled="false"
-            android:exported="true" />
 
         <provider
             android:name="androidx.core.content.FileProvider"