]> git.ktnx.net Git - mobile-ledger-staging.git/commitdiff
make soft keyboard appear when new transaction description/account gets focus
authorDamyan Ivanov <dam+mobileledger@ktnx.net>
Sun, 10 Nov 2019 17:39:09 +0000 (19:39 +0200)
committerDamyan Ivanov <dam+mobileledger@ktnx.net>
Sun, 10 Nov 2019 17:39:09 +0000 (19:39 +0200)
this is used when the focus is given artificially, when date is picked
(and focus goes to the transaction description) and when a transaction
description is selected from the drop down (and focus goes to the first
account name)

app/src/main/java/net/ktnx/mobileledger/ui/activity/NewTransactionItemHolder.java
app/src/main/java/net/ktnx/mobileledger/utils/Misc.java

index 4bf75d0000e7093d120f695843fb7d945d7b9fa6..81487af661a1f4b7dcc9c9539f1991755c32eba8 100644 (file)
 
 package net.ktnx.mobileledger.ui.activity;
 
 
 package net.ktnx.mobileledger.ui.activity;
 
-import android.content.Context;
 import android.text.Editable;
 import android.text.TextWatcher;
 import android.view.View;
 import android.view.inputmethod.EditorInfo;
 import android.text.Editable;
 import android.text.TextWatcher;
 import android.view.View;
 import android.view.inputmethod.EditorInfo;
-import android.view.inputmethod.InputMethodManager;
 import android.widget.AutoCompleteTextView;
 import android.widget.FrameLayout;
 import android.widget.LinearLayout;
 import android.widget.AutoCompleteTextView;
 import android.widget.FrameLayout;
 import android.widget.LinearLayout;
@@ -41,6 +39,7 @@ import net.ktnx.mobileledger.model.MobileLedgerProfile;
 import net.ktnx.mobileledger.ui.DatePickerFragment;
 import net.ktnx.mobileledger.utils.Logger;
 import net.ktnx.mobileledger.utils.MLDB;
 import net.ktnx.mobileledger.ui.DatePickerFragment;
 import net.ktnx.mobileledger.utils.Logger;
 import net.ktnx.mobileledger.utils.MLDB;
+import net.ktnx.mobileledger.utils.Misc;
 
 import java.util.Calendar;
 import java.util.Date;
 
 import java.util.Calendar;
 import java.util.Date;
@@ -153,11 +152,20 @@ class NewTransactionItemHolder extends RecyclerView.ViewHolder
             if ((index != null) && index.equals(getAdapterPosition())) {
                 switch (item.getType()) {
                     case generalData:
             if ((index != null) && index.equals(getAdapterPosition())) {
                 switch (item.getType()) {
                     case generalData:
-                        tvDate.requestFocus();
+                        // bad idea - double pop-up, and not really necessary.
+                        // the user can tap the input to get the calendar
+                        //if (!tvDate.hasFocus()) tvDate.requestFocus();
+                        boolean focused = tvDescription.requestFocus();
+                        tvDescription.dismissDropDown();
+                        if (focused) Misc.showSoftKeyboard(
+                                (NewTransactionActivity) tvDescription.getContext());
                         break;
                     case transactionRow:
                         break;
                     case transactionRow:
-                        tvAccount.requestFocus();
+                        focused = tvAccount.requestFocus();
                         tvAccount.dismissDropDown();
                         tvAccount.dismissDropDown();
+                        if (focused)
+                            Misc.showSoftKeyboard((NewTransactionActivity) tvAccount.getContext());
+
                         break;
                 }
             }
                         break;
                 }
             }
@@ -291,14 +299,9 @@ class NewTransactionItemHolder extends RecyclerView.ViewHolder
         final Calendar c = GregorianCalendar.getInstance();
         c.set(year, month, day);
         item.setDate(c.getTime());
         final Calendar c = GregorianCalendar.getInstance();
         c.set(year, month, day);
         item.setDate(c.getTime());
-        boolean tookFocus = tvDescription.requestFocus();
-        if (tookFocus) {
-            // make the keyboard appear
-            InputMethodManager imm = (InputMethodManager) tvDate.getContext()
-                                                                .getSystemService(
-                                                                        Context.INPUT_METHOD_SERVICE);
-            imm.toggleSoftInput(InputMethodManager.SHOW_IMPLICIT, 0);
-        }
+        boolean focused = tvDescription.requestFocus();
+        if (focused) Misc.showSoftKeyboard((NewTransactionActivity) tvAccount.getContext());
+
     }
     @Override
     public void descriptionSelected(String description) {
     }
     @Override
     public void descriptionSelected(String description) {
index ee6f5a746cf0f44761ee29bbf3bf3774084bc192..3fae49f1665a6e28bd583a67d5564e351b9878b7 100644 (file)
 
 package net.ktnx.mobileledger.utils;
 
 
 package net.ktnx.mobileledger.utils;
 
+import android.app.Activity;
+import android.view.WindowManager;
+
+import androidx.fragment.app.Fragment;
+
 public class Misc {
     public static boolean isZero(float f) {
         return (f < 0.005) && (f > -0.005);
     }
 public class Misc {
     public static boolean isZero(float f) {
         return (f < 0.005) && (f > -0.005);
     }
+    public static void showSoftKeyboard(Activity activity) {
+        // make the keyboard appear
+        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);
+    }
 }
 }