Automatically show and hide keyboard in CredentialsPreference
This commit is contained in:
parent
a20dc326bc
commit
5059abf2d0
2 changed files with 29 additions and 0 deletions
|
@ -44,6 +44,7 @@ import android.widget.Toast;
|
|||
|
||||
import org.shadowice.flocke.andotp.R;
|
||||
import org.shadowice.flocke.andotp.Utilities.Settings;
|
||||
import org.shadowice.flocke.andotp.Utilities.UIHelper;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
@ -220,6 +221,9 @@ public class CredentialsPreference extends DialogPreference
|
|||
private void updateLayout() {
|
||||
if (value == AuthMethod.NONE) {
|
||||
credentialsLayout.setVisibility(View.GONE);
|
||||
|
||||
UIHelper.hideKeyboard(getContext(), getDialog().getCurrentFocus());
|
||||
|
||||
btnSave.setEnabled(true);
|
||||
} else if (value == AuthMethod.PASSWORD) {
|
||||
credentialsLayout.setVisibility(View.VISIBLE);
|
||||
|
@ -233,6 +237,9 @@ public class CredentialsPreference extends DialogPreference
|
|||
passwordInput.setTransformationMethod(new PasswordTransformationMethod());
|
||||
passwordConfirm.setTransformationMethod(new PasswordTransformationMethod());
|
||||
|
||||
passwordInput.requestFocus();
|
||||
UIHelper.showKeyboard(getContext(), passwordInput);
|
||||
|
||||
btnSave.setEnabled(false);
|
||||
} else if (value == AuthMethod.PIN) {
|
||||
credentialsLayout.setVisibility(View.VISIBLE);
|
||||
|
@ -246,9 +253,15 @@ public class CredentialsPreference extends DialogPreference
|
|||
passwordInput.setTransformationMethod(new PasswordTransformationMethod());
|
||||
passwordConfirm.setTransformationMethod(new PasswordTransformationMethod());
|
||||
|
||||
passwordInput.requestFocus();
|
||||
UIHelper.showKeyboard(getContext(), passwordInput);
|
||||
|
||||
btnSave.setEnabled(false);
|
||||
} else if (value == AuthMethod.DEVICE) {
|
||||
credentialsLayout.setVisibility(View.GONE);
|
||||
|
||||
UIHelper.hideKeyboard(getContext(), getDialog().getCurrentFocus());
|
||||
|
||||
btnSave.setEnabled(true);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,6 +25,8 @@ package org.shadowice.flocke.andotp.Utilities;
|
|||
import android.app.AlertDialog;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.view.View;
|
||||
import android.view.inputmethod.InputMethodManager;
|
||||
|
||||
public class UIHelper {
|
||||
public static void showGenericDialog(Context context, int titleId, int messageId) {
|
||||
|
@ -39,4 +41,18 @@ public class UIHelper {
|
|||
.create()
|
||||
.show();
|
||||
}
|
||||
|
||||
public static void showKeyboard(Context context, View view) {
|
||||
if (view != null) {
|
||||
InputMethodManager imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
|
||||
imm.showSoftInput(view, 0);
|
||||
}
|
||||
}
|
||||
|
||||
public static void hideKeyboard(Context context, View view) {
|
||||
if (view != null) {
|
||||
InputMethodManager imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
|
||||
imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue