Example usage for android.text.method PasswordTransformationMethod getInstance

List of usage examples for android.text.method PasswordTransformationMethod getInstance

Introduction

In this page you can find the example usage for android.text.method PasswordTransformationMethod getInstance.

Prototype

public static PasswordTransformationMethod getInstance() 

Source Link

Usage

From source file:android.support.design.widget.TextInputLayout.java

void passwordVisibilityToggleRequested() {
    if (mPasswordToggleEnabled) {
        // Store the current cursor position
        final int selection = mEditText.getSelectionEnd();

        if (hasPasswordTransformation()) {
            mEditText.setTransformationMethod(null);
            mPasswordToggledVisible = true;
        } else {/*from   w  w  w.j  a v a  2s . c o  m*/
            mEditText.setTransformationMethod(PasswordTransformationMethod.getInstance());
            mPasswordToggledVisible = false;
        }

        mPasswordToggleView.setChecked(mPasswordToggledVisible);

        // And restore the cursor position
        mEditText.setSelection(selection);
    }
}

From source file:com.commonsware.cwac.crossport.design.widget.TextInputLayout.java

private void passwordVisibilityToggleRequested(boolean shouldSkipAnimations) {
    if (mPasswordToggleEnabled) {
        // Store the current cursor position
        final int selection = mEditText.getSelectionEnd();

        if (hasPasswordTransformation()) {
            mEditText.setTransformationMethod(null);
            mPasswordToggledVisible = true;
        } else {/*w w w.  j  ava2s  .  co m*/
            mEditText.setTransformationMethod(PasswordTransformationMethod.getInstance());
            mPasswordToggledVisible = false;
        }

        mPasswordToggleView.setChecked(mPasswordToggledVisible);
        if (shouldSkipAnimations) {
            mPasswordToggleView.jumpDrawablesToCurrentState();
        }

        // And restore the cursor position
        mEditText.setSelection(selection);
    }
}

From source file:org.telegram.ui.PassportActivity.java

private void createPasswordInterface(Context context) {
    TLRPC.User botUser = null;//from w  ww  .  ja va 2 s.co m
    if (currentForm != null) {
        for (int a = 0; a < currentForm.users.size(); a++) {
            TLRPC.User user = currentForm.users.get(a);
            if (user.id == currentBotId) {
                botUser = user;
                break;
            }
        }
    } else {
        botUser = UserConfig.getInstance(currentAccount).getCurrentUser();
    }

    FrameLayout frameLayout = (FrameLayout) fragmentView;

    actionBar.setTitle(LocaleController.getString("TelegramPassport", R.string.TelegramPassport));

    emptyView = new EmptyTextProgressView(context);
    emptyView.showProgress();
    frameLayout.addView(emptyView,
            LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));

    passwordAvatarContainer = new FrameLayout(context);
    linearLayout2.addView(passwordAvatarContainer, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, 100));

    BackupImageView avatarImageView = new BackupImageView(context);
    avatarImageView.setRoundRadius(AndroidUtilities.dp(32));
    passwordAvatarContainer.addView(avatarImageView,
            LayoutHelper.createFrame(64, 64, Gravity.CENTER, 0, 8, 0, 0));

    AvatarDrawable avatarDrawable = new AvatarDrawable(botUser);
    TLRPC.FileLocation photo = null;
    if (botUser.photo != null) {
        photo = botUser.photo.photo_small;
    }
    avatarImageView.setImage(photo, "50_50", avatarDrawable, botUser);

    passwordRequestTextView = new TextInfoPrivacyCell(context);
    passwordRequestTextView.getTextView().setGravity(Gravity.CENTER_HORIZONTAL);
    if (currentBotId == 0) {
        passwordRequestTextView
                .setText(LocaleController.getString("PassportSelfRequest", R.string.PassportSelfRequest));
    } else {
        passwordRequestTextView.setText(AndroidUtilities.replaceTags(LocaleController
                .formatString("PassportRequest", R.string.PassportRequest, UserObject.getFirstName(botUser))));
    }
    ((FrameLayout.LayoutParams) passwordRequestTextView.getTextView()
            .getLayoutParams()).gravity = Gravity.CENTER_HORIZONTAL;
    linearLayout2.addView(passwordRequestTextView,
            LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT,
                    (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP, 21, 0, 21, 0));

    noPasswordImageView = new ImageView(context);
    noPasswordImageView.setImageResource(R.drawable.no_password);
    noPasswordImageView.setColorFilter(new PorterDuffColorFilter(
            Theme.getColor(Theme.key_chat_messagePanelIcons), PorterDuff.Mode.MULTIPLY));
    linearLayout2.addView(noPasswordImageView, LayoutHelper.createLinear(LayoutHelper.WRAP_CONTENT,
            LayoutHelper.WRAP_CONTENT, Gravity.TOP | Gravity.CENTER_HORIZONTAL, 0, 13, 0, 0));

    noPasswordTextView = new TextView(context);
    noPasswordTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14);
    noPasswordTextView.setGravity(Gravity.CENTER_HORIZONTAL);
    noPasswordTextView.setPadding(AndroidUtilities.dp(21), AndroidUtilities.dp(10), AndroidUtilities.dp(21),
            AndroidUtilities.dp(17));
    noPasswordTextView.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteGrayText4));
    noPasswordTextView.setText(LocaleController.getString("TelegramPassportCreatePasswordInfo",
            R.string.TelegramPassportCreatePasswordInfo));
    linearLayout2.addView(noPasswordTextView,
            LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT,
                    (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP, 21, 10, 21, 0));

    noPasswordSetTextView = new TextView(context);
    noPasswordSetTextView.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlueText5));
    noPasswordSetTextView.setGravity(Gravity.CENTER);
    noPasswordSetTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16);
    noPasswordSetTextView.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
    noPasswordSetTextView.setText(LocaleController.getString("TelegramPassportCreatePassword",
            R.string.TelegramPassportCreatePassword));
    linearLayout2.addView(noPasswordSetTextView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 24,
            (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP, 21, 9, 21, 0));
    noPasswordSetTextView.setOnClickListener(v -> {
        TwoStepVerificationActivity activity = new TwoStepVerificationActivity(currentAccount, 1);
        activity.setCloseAfterSet(true);
        activity.setCurrentPasswordInfo(new byte[0], currentPassword);
        presentFragment(activity);
    });

    inputFields = new EditTextBoldCursor[1];
    inputFieldContainers = new ViewGroup[1];
    for (int a = 0; a < 1; a++) {
        inputFieldContainers[a] = new FrameLayout(context);
        linearLayout2.addView(inputFieldContainers[a],
                LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, 50));
        inputFieldContainers[a].setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundWhite));

        inputFields[a] = new EditTextBoldCursor(context);
        inputFields[a].setTag(a);
        inputFields[a].setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16);
        inputFields[a].setHintTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteHintText));
        inputFields[a].setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlackText));
        inputFields[a].setBackgroundDrawable(null);
        inputFields[a].setCursorColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlackText));
        inputFields[a].setCursorSize(AndroidUtilities.dp(20));
        inputFields[a].setCursorWidth(1.5f);
        inputFields[a].setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);
        inputFields[a].setMaxLines(1);
        inputFields[a].setLines(1);
        inputFields[a].setSingleLine(true);
        inputFields[a].setTransformationMethod(PasswordTransformationMethod.getInstance());
        inputFields[a].setTypeface(Typeface.DEFAULT);
        inputFields[a].setImeOptions(EditorInfo.IME_ACTION_DONE | EditorInfo.IME_FLAG_NO_EXTRACT_UI);
        inputFields[a].setPadding(0, 0, 0, AndroidUtilities.dp(6));
        inputFields[a].setGravity(LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT);
        inputFieldContainers[a].addView(inputFields[a], LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT,
                LayoutHelper.WRAP_CONTENT, Gravity.LEFT | Gravity.TOP, 21, 12, 21, 6));

        inputFields[a].setOnEditorActionListener((textView, i, keyEvent) -> {
            if (i == EditorInfo.IME_ACTION_NEXT || i == EditorInfo.IME_ACTION_DONE) {
                doneItem.callOnClick();
                return true;
            }
            return false;
        });
        inputFields[a].setCustomSelectionActionModeCallback(new ActionMode.Callback() {
            public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
                return false;
            }

            public void onDestroyActionMode(ActionMode mode) {
            }

            public boolean onCreateActionMode(ActionMode mode, Menu menu) {
                return false;
            }

            public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
                return false;
            }
        });
    }

    passwordInfoRequestTextView = new TextInfoPrivacyCell(context);
    passwordInfoRequestTextView.setBackgroundDrawable(Theme.getThemedDrawable(context,
            R.drawable.greydivider_bottom, Theme.key_windowBackgroundGrayShadow));
    passwordInfoRequestTextView.setText(
            LocaleController.formatString("PassportRequestPasswordInfo", R.string.PassportRequestPasswordInfo));
    linearLayout2.addView(passwordInfoRequestTextView,
            LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));

    passwordForgotButton = new TextView(context);
    passwordForgotButton.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlueText4));
    passwordForgotButton.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14);
    passwordForgotButton.setText(LocaleController.getString("ForgotPassword", R.string.ForgotPassword));
    passwordForgotButton.setPadding(0, 0, 0, 0);
    linearLayout2.addView(passwordForgotButton, LayoutHelper.createLinear(LayoutHelper.WRAP_CONTENT, 30,
            (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP, 21, 0, 21, 0));
    passwordForgotButton.setOnClickListener(v -> {
        if (currentPassword.has_recovery) {
            needShowProgress();
            TLRPC.TL_auth_requestPasswordRecovery req = new TLRPC.TL_auth_requestPasswordRecovery();
            int reqId = ConnectionsManager.getInstance(currentAccount).sendRequest(req,
                    (response, error) -> AndroidUtilities.runOnUIThread(() -> {
                        needHideProgress();
                        if (error == null) {
                            final TLRPC.TL_auth_passwordRecovery res = (TLRPC.TL_auth_passwordRecovery) response;
                            AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
                            builder.setMessage(LocaleController.formatString("RestoreEmailSent",
                                    R.string.RestoreEmailSent, res.email_pattern));
                            builder.setTitle(LocaleController.getString("AppName", R.string.AppName));
                            builder.setPositiveButton(LocaleController.getString("OK", R.string.OK),
                                    (dialogInterface, i) -> {
                                        TwoStepVerificationActivity fragment = new TwoStepVerificationActivity(
                                                currentAccount, 1);
                                        fragment.setRecoveryParams(currentPassword);
                                        currentPassword.email_unconfirmed_pattern = res.email_pattern;
                                        presentFragment(fragment);
                                    });
                            Dialog dialog = showDialog(builder.create());
                            if (dialog != null) {
                                dialog.setCanceledOnTouchOutside(false);
                                dialog.setCancelable(false);
                            }
                        } else {
                            if (error.text.startsWith("FLOOD_WAIT")) {
                                int time = Utilities.parseInt(error.text);
                                String timeString;
                                if (time < 60) {
                                    timeString = LocaleController.formatPluralString("Seconds", time);
                                } else {
                                    timeString = LocaleController.formatPluralString("Minutes", time / 60);
                                }
                                showAlertWithText(LocaleController.getString("AppName", R.string.AppName),
                                        LocaleController.formatString("FloodWaitTime", R.string.FloodWaitTime,
                                                timeString));
                            } else {
                                showAlertWithText(LocaleController.getString("AppName", R.string.AppName),
                                        error.text);
                            }
                        }
                    }), ConnectionsManager.RequestFlagFailOnServerErrors
                            | ConnectionsManager.RequestFlagWithoutLogin);
            ConnectionsManager.getInstance(currentAccount).bindRequestToGuid(reqId, classGuid);
        } else {
            if (getParentActivity() == null) {
                return;
            }
            AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
            builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), null);
            builder.setNegativeButton(
                    LocaleController.getString("RestorePasswordResetAccount",
                            R.string.RestorePasswordResetAccount),
                    (dialog, which) -> Browser.openUrl(getParentActivity(),
                            "https://telegram.org/deactivate?phone="
                                    + UserConfig.getInstance(currentAccount).getClientPhone()));
            builder.setTitle(LocaleController.getString("RestorePasswordNoEmailTitle",
                    R.string.RestorePasswordNoEmailTitle));
            builder.setMessage(LocaleController.getString("RestorePasswordNoEmailText",
                    R.string.RestorePasswordNoEmailText));
            showDialog(builder.create());
        }
    });

    updatePasswordInterface();
}