]> git.ktnx.net Git - mobile-ledger.git/commitdiff
new transaction: show soft keyboard after choosing transaction date
authorDamyan Ivanov <dam+mobileledger@ktnx.net>
Sat, 21 Sep 2019 08:40:58 +0000 (11:40 +0300)
committerDamyan Ivanov <dam+mobileledger@ktnx.net>
Sat, 21 Sep 2019 08:40:58 +0000 (11:40 +0300)
app/src/main/java/net/ktnx/mobileledger/ui/DatePickerFragment.java

index abec8d6d8fb5915234c4981f74564b8be8766ed8..657946302970aefff01c4d4576b5ceff0f395004 100644 (file)
 
 package net.ktnx.mobileledger.ui;
 
+import android.app.Activity;
 import android.app.Dialog;
 import android.os.Bundle;
-import androidx.annotation.NonNull;
-import androidx.appcompat.app.AppCompatDialogFragment;
+import android.view.WindowManager;
 import android.widget.CalendarView;
 import android.widget.TextView;
 
+import androidx.annotation.NonNull;
+import androidx.appcompat.app.AppCompatDialogFragment;
+
 import net.ktnx.mobileledger.R;
 
 import java.util.Calendar;
@@ -96,9 +99,13 @@ public class DatePickerFragment extends AppCompatDialogFragment
         }
         else date.setText(String.format(Locale.US, "%d/%d/%d", year, month + 1, day));
 
-        TextView description = Objects.requireNonNull(getActivity())
-                .findViewById(R.id.new_transaction_description);
-        description.requestFocus();
+        Activity activity = getActivity();
+        if (activity == null) return;
+
+        TextView description = activity.findViewById(R.id.new_transaction_description);
+        boolean tookFocus = description.requestFocus();
+        if (tookFocus) activity.getWindow()
+                .setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
     }
     @Override
     public void onSelectedDayChange(@NonNull CalendarView view, int year, int month,