3

I have a GuidedStepFragment as an authentication-type fragment in my leanback application.

How do I keep a "password" GuidedAction from revealing the typed-text when the user presses enter or goes to the next Guided Action?

The issue I'm facing is the password is hidden while the user is typing, but revealed when the user goes to the next GuidedAction.

@Override
public void onCreateActions(@NonNull List<GuidedAction> actions, Bundle savedInstanceState) {
    GuidedAction action;
    if (getArguments() != null) {
        type = getArguments().getInt(ARG_TYPE);
    }
    if (type == TYPE_EMAIL) {
        action = new GuidedAction.Builder(getActivity())
                .id(ActionConstants.ACTION_INPUT_EMAIL)
                .editable(true)
                .description(getString(R.string.email_address_hint))
                .editInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS)
                .build();
    } else {
        action = new GuidedAction.Builder(getActivity())
                .id(ActionConstants.ACTION_INPUT_PASS)
                .editable(true)
                .description(getString(R.string.password))
                .editInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD)
                .build();
    }
    actions.add(action);
    action = new GuidedAction.Builder(getActivity())
            .id(ActionConstants.ACTION_CONTINUE)
            .title(R.string.next)
            .hasNext(true) // Shows the small arrow indicating there's something next...
            .build();
    actions.add(action);
}

I have tried overriding setupImeOptions to explicitly set the TransformationMethod on the EditText, but that still doesn't keep the user's password hidden after the user goes to the next Action.

@Override
protected void setupImeOptions(ViewHolder vh, GuidedAction action) {
    switch ((int) action.getId()) {
        case ActionConstants.ACTION_INPUT_PASS :
            vh.getEditableDescriptionView().setTransformationMethod(new PasswordTransformationMethod());
            vh.getEditableTitleView().setTransformationMethod(new PasswordTransformationMethod());
            break;
    }
    super.setupImeOptions(vh, action);
}
dell116
  • 5,835
  • 9
  • 52
  • 70
  • 1
    https://developer.android.com/reference/android/support/v17/leanback/app/GuidedStepFragment, GuidedStepFragment is deprecated class, i think you need to upgrade to GuidedStepSupportFragment – Akash Dubey Dec 07 '18 at 05:38
  • @AkashDubey I'm pretty sure I gave that a try and had the same results, but I'll try again to confirm and report back here. – dell116 Dec 08 '18 at 15:25
  • @dell116 did you find a solution? – Jacob Oct 23 '20 at 21:00

1 Answers1

3

Following code works

GuidedAction.Builder(activity)
            .id(PASSWORD.toLong())
            .title("Password")
            .descriptionEditable(true)
            .descriptionInputType(InputType.TYPE_CLASS_TEXT or InputType.TYPE_TEXT_VARIATION_PASSWORD)
            .descriptionEditInputType(InputType.TYPE_CLASS_TEXT or InputType.TYPE_TEXT_VARIATION_PASSWORD)
            .build()