]> git.ktnx.net Git - mobile-ledger-staging.git/blobdiff - app/src/main/java/net/ktnx/mobileledger/utils/Misc.java
Misc.showSoftKeyboard: handle fragemtn.getActivity() returning null
[mobile-ledger-staging.git] / app / src / main / java / net / ktnx / mobileledger / utils / Misc.java
index 3fae49f1665a6e28bd583a67d5564e351b9878b7..b28900f9320850e7a0ccb88d6a80aa8f8e2f271a 100644 (file)
 package net.ktnx.mobileledger.utils;
 
 import android.app.Activity;
+import android.content.res.Configuration;
 import android.view.WindowManager;
 
 import androidx.fragment.app.Fragment;
+import androidx.fragment.app.FragmentActivity;
 
 public class Misc {
     public static boolean isZero(float f) {
@@ -28,13 +30,16 @@ public class Misc {
     }
     public static void showSoftKeyboard(Activity activity) {
         // make the keyboard appear
-        activity.getWindow()
-                .setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
+        Configuration cf = activity.getResources()
+                                   .getConfiguration();
+        if (cf.keyboard == Configuration.KEYBOARD_NOKEYS ||
+            cf.keyboardHidden == Configuration.KEYBOARDHIDDEN_YES)
+            activity.getWindow()
+                    .setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
     }
     public static void showSoftKeyboard(Fragment fragment) {
-        // make the keyboard appear
-        fragment.getActivity()
-                .getWindow()
-                .setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
+        final FragmentActivity activity = fragment.getActivity();
+        if (activity != null)
+            showSoftKeyboard(activity);
     }
 }