From d814dab8a891ceba4181078c8aeb63d0602a79ed Mon Sep 17 00:00:00 2001 From: Joshua Soberg Date: Thu, 4 Feb 2021 20:26:20 -0500 Subject: [PATCH] #635 - Reset password input field and refocus if coming back from cancelling authentication --- .../Activities/AuthenticateActivity.java | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/org/shadowice/flocke/andotp/Activities/AuthenticateActivity.java b/app/src/main/java/org/shadowice/flocke/andotp/Activities/AuthenticateActivity.java index 19afcf01..84bfecb9 100644 --- a/app/src/main/java/org/shadowice/flocke/andotp/Activities/AuthenticateActivity.java +++ b/app/src/main/java/org/shadowice/flocke/andotp/Activities/AuthenticateActivity.java @@ -23,6 +23,7 @@ package org.shadowice.flocke.andotp.Activities; import android.app.Fragment; +import android.content.Context; import android.content.Intent; import android.os.Build; import android.os.Bundle; @@ -44,6 +45,7 @@ import android.view.View; import android.view.ViewStub; import android.view.WindowManager.LayoutParams; import android.view.inputmethod.EditorInfo; +import android.view.inputmethod.InputMethodManager; import android.widget.Button; import android.widget.EditText; import android.widget.ProgressBar; @@ -193,12 +195,23 @@ public class AuthenticateActivity extends BaseActivity private void checkBackgroundTask() { TaskFragment taskFragment = findTaskFragment(); - if (taskFragment != null && !taskFragment.task.isCanceled()) { - taskFragment.task.setCallback(this::handleResult); - setupUiForTaskState(true); + if (taskFragment != null) { + if (taskFragment.task.isCanceled()) { + resetPasswordInput(); + } else { + taskFragment.task.setCallback(this::handleResult); + setupUiForTaskState(true); + } } } + private void resetPasswordInput() { + passwordInput.setText(""); + passwordInput.requestFocus(); + InputMethodManager keyboard = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); + keyboard.showSoftInput(passwordInput, 0); + } + @Nullable private TaskFragment findTaskFragment() { return (TaskFragment) getFragmentManager().findFragmentByTag(TAG_TASK_FRAGMENT);