Java Code Examples for androidx.appcompat.widget.AppCompatEditText#setInputType()

The following examples show how to use androidx.appcompat.widget.AppCompatEditText#setInputType() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ViewUtils.java    From SmartFlasher with GNU General Public License v3.0 5 votes vote down vote up
public static Dialog dialogEditText(String text, final DialogInterface.OnClickListener negativeListener,
                                    final OnDialogEditTextListener onDialogEditTextListener, int inputType,
                                    Context context) {
    LinearLayout layout = new LinearLayout(context);
    int padding = (int) context.getResources().getDimension(R.dimen.dialog_padding);
    layout.setPadding(padding, padding, padding, padding);

    final AppCompatEditText editText = new AppCompatEditText(context);
    editText.setGravity(Gravity.CENTER);
    editText.setLayoutParams(new LinearLayout.LayoutParams(
            ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
    if (text != null) {
        editText.append(text);
    }
    editText.setSingleLine(true);
    if (inputType >= 0) {
        editText.setInputType(inputType);
    }

    layout.addView(editText);

    Dialog dialog = new Dialog(context).setView(layout);
    if (negativeListener != null) {
        dialog.setNegativeButton(context.getString(R.string.cancel), negativeListener);
    }
    if (onDialogEditTextListener != null) {
        dialog.setPositiveButton(context.getString(R.string.ok), (dialog1, which)
                -> onDialogEditTextListener.onClick(Objects.requireNonNull(editText.getText()).toString()))
                .setOnDismissListener(dialog1 -> {
                    if (negativeListener != null) {
                        negativeListener.onClick(dialog1, 0);
                    }
                });
    }
    return dialog;
}
 
Example 2
Source File: SettingsFragment.java    From SmartPack-Kernel-Manager with GNU General Public License v3.0 5 votes vote down vote up
private void deletePasswordDialog(final String password) {
    if (password.isEmpty()) {
        Utils.snackbar(mRootView, getString(R.string.set_password_first));
        return;
    }

    mDeletePassword = password;

    LinearLayout linearLayout = new LinearLayout(getActivity());
    linearLayout.setOrientation(LinearLayout.VERTICAL);
    linearLayout.setGravity(Gravity.CENTER);
    int padding = Math.round(getResources().getDimension(R.dimen.dialog_padding));
    linearLayout.setPadding(padding, padding, padding, padding);

    final AppCompatEditText mPassword = new AppCompatEditText(requireActivity());
    mPassword.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);
    mPassword.setHint(getString(R.string.password));
    linearLayout.addView(mPassword);

    new Dialog(requireActivity()).setView(linearLayout)
            .setPositiveButton(getString(R.string.ok), (dialogInterface, i) -> {
                if (!Objects.requireNonNull(mPassword.getText()).toString().equals(Utils.decodeString(password))) {
                    Utils.snackbar(mRootView, getString(R.string.password_wrong));
                    return;
                }

                Prefs.saveString("password", "", getActivity());
                if (mFingerprint != null) {
                    mFingerprint.setEnabled(false);
                }
            }).setOnDismissListener(dialogInterface -> mDeletePassword = null).show();
}
 
Example 3
Source File: ViewUtils.java    From SmartPack-Kernel-Manager with GNU General Public License v3.0 5 votes vote down vote up
public static Dialog dialogEditText(String text, final DialogInterface.OnClickListener negativeListener,
                                    final OnDialogEditTextListener onDialogEditTextListener, int inputType,
                                    Context context) {
    LinearLayout layout = new LinearLayout(context);
    int padding = (int) context.getResources().getDimension(R.dimen.dialog_padding);
    layout.setPadding(padding, padding, padding, padding);

    final AppCompatEditText editText = new AppCompatEditText(context);
    editText.setGravity(Gravity.CENTER);
    editText.setLayoutParams(new LinearLayout.LayoutParams(
            ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
    if (text != null) {
        editText.append(text);
    }
    editText.setSingleLine(true);
    if (inputType >= 0) {
        editText.setInputType(inputType);
    }

    layout.addView(editText);

    Dialog dialog = new Dialog(context).setView(layout);
    if (negativeListener != null) {
        dialog.setNegativeButton(context.getString(R.string.cancel), negativeListener);
    }
    if (onDialogEditTextListener != null) {
        dialog.setPositiveButton(context.getString(R.string.ok), (dialog1, which)
                -> onDialogEditTextListener.onClick(Objects.requireNonNull(editText.getText()).toString()))
                .setOnDismissListener(dialog1 -> {
                    if (negativeListener != null) {
                        negativeListener.onClick(dialog1, 0);
                    }
                });
    }
    return dialog;
}
 
Example 4
Source File: SettingsFragment.java    From MTweaks-KernelAdiutorMOD with GNU General Public License v3.0 5 votes vote down vote up
private void deletePasswordDialog(final String password) {
    if (password.isEmpty()) {
        Utils.toast(getString(R.string.set_password_first), getActivity());
        return;
    }

    mDeletePassword = password;

    LinearLayout linearLayout = new LinearLayout(getActivity());
    linearLayout.setOrientation(LinearLayout.VERTICAL);
    linearLayout.setGravity(Gravity.CENTER);
    int padding = Math.round(getResources().getDimension(R.dimen.dialog_padding));
    linearLayout.setPadding(padding, padding, padding, padding);

    final AppCompatEditText mPassword = new AppCompatEditText(getActivity());
    mPassword.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);
    mPassword.setHint(getString(R.string.password));
    linearLayout.addView(mPassword);

    new Dialog(getActivity()).setView(linearLayout)
            .setPositiveButton(getString(R.string.ok), (dialogInterface, i) -> {
                if (!mPassword.getText().toString().equals(Utils.decodeString(password))) {
                    Utils.toast(getString(R.string.password_wrong), getActivity());
                    return;
                }

                AppSettings.resetPassword(getActivity());
                if (mFingerprint != null) {
                    mFingerprint.setEnabled(false);
                }
            })
            .setOnDismissListener(dialogInterface -> mDeletePassword = null).show();
}
 
Example 5
Source File: ViewUtils.java    From MTweaks-KernelAdiutorMOD with GNU General Public License v3.0 5 votes vote down vote up
public static Dialog dialogEditText(String text, final DialogInterface.OnClickListener negativeListener,
                                    final OnDialogEditTextListener onDialogEditTextListener, int inputType,
                                    Context context) {
    LinearLayout layout = new LinearLayout(context);
    int padding = (int) context.getResources().getDimension(R.dimen.dialog_padding);
    layout.setPadding(padding, padding, padding, padding);

    final AppCompatEditText editText = new AppCompatEditText(context);
    editText.setGravity(Gravity.CENTER);
    editText.setLayoutParams(new LinearLayout.LayoutParams(
            ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
    if (text != null) {
        editText.append(text);
    }
    editText.setSingleLine(true);
    if (inputType >= 0) {
        editText.setInputType(inputType);
    }

    layout.addView(editText);

    Dialog dialog = new Dialog(context).setView(layout);
    if (negativeListener != null) {
        dialog.setNegativeButton(context.getString(R.string.cancel), negativeListener);
    }
    if (onDialogEditTextListener != null) {
        dialog.setPositiveButton(context.getString(R.string.ok), (dialog1, which)
                -> onDialogEditTextListener.onClick(editText.getText().toString()))
                .setOnDismissListener(dialog1 -> {
                    if (negativeListener != null) {
                        negativeListener.onClick(dialog1, 0);
                    }
                });
    }
    return dialog;
}
 
Example 6
Source File: CreatePlaylistDialogFragment.java    From Jockey with Apache License 2.0 5 votes vote down vote up
private void onCreateDialogLayout(@Nullable String restoredName) {
    mInputLayout = new TextInputLayout(getContext());
    mEditText = new AppCompatEditText(getContext());

    mEditText.setInputType(InputType.TYPE_CLASS_TEXT);
    mEditText.setHint(R.string.hint_playlist_name);
    mEditText.setText(restoredName);

    mInputLayout.addView(mEditText);
    mInputLayout.setErrorEnabled(true);

    mEditText.addTextChangedListener(this);
}
 
Example 7
Source File: SettingsFragment.java    From SmartPack-Kernel-Manager with GNU General Public License v3.0 4 votes vote down vote up
private void editPasswordDialog(final String oldPass) {
    mOldPassword = oldPass;

    LinearLayout linearLayout = new LinearLayout(getActivity());
    linearLayout.setOrientation(LinearLayout.VERTICAL);
    linearLayout.setGravity(Gravity.CENTER);
    int padding = Math.round(getResources().getDimension(R.dimen.dialog_padding));
    linearLayout.setPadding(padding, padding, padding, padding);

    final AppCompatEditText oldPassword = new AppCompatEditText(requireActivity());
    if (!oldPass.isEmpty()) {
        oldPassword.setInputType(InputType.TYPE_CLASS_TEXT
                | InputType.TYPE_TEXT_VARIATION_PASSWORD);
        oldPassword.setHint(getString(R.string.old_password));
        linearLayout.addView(oldPassword);
    }

    final AppCompatEditText newPassword = new AppCompatEditText(requireActivity());
    newPassword.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);
    newPassword.setHint(getString(R.string.new_password));
    linearLayout.addView(newPassword);

    final AppCompatEditText confirmNewPassword = new AppCompatEditText(requireActivity());
    confirmNewPassword.setInputType(InputType.TYPE_CLASS_TEXT
            | InputType.TYPE_TEXT_VARIATION_PASSWORD);
    confirmNewPassword.setHint(getString(R.string.confirm_new_password));
    linearLayout.addView(confirmNewPassword);

    new Dialog(requireActivity()).setView(linearLayout)
            .setNegativeButton(getString(R.string.cancel), (dialogInterface, i) -> {
            })
            .setPositiveButton(getString(R.string.ok), (dialogInterface, i) -> {
                if (!oldPass.isEmpty() && !Objects.requireNonNull(oldPassword.getText()).toString().equals(Utils
                        .decodeString(oldPass))) {
                    Utils.snackbar(mRootView, getString(R.string.old_password_wrong));
                    return;
                }

                if (Objects.requireNonNull(newPassword.getText()).toString().isEmpty()) {
                    Utils.snackbar(mRootView, getString(R.string.password_empty));
                    return;
                }

                if (!newPassword.getText().toString().equals(Objects.requireNonNull(confirmNewPassword.getText())
                        .toString())) {
                    Utils.snackbar(mRootView, getString(R.string.password_not_match));
                    return;
                }

                if (newPassword.getText().toString().length() > 32) {
                    Utils.snackbar(mRootView, getString(R.string.password_too_long));
                    return;
                }

                Prefs.saveString("password", Utils.encodeString(newPassword.getText()
                        .toString()), getActivity());
                if (mFingerprint != null) {
                    mFingerprint.setEnabled(true);
                }
            }).setOnDismissListener(dialogInterface -> mOldPassword = null).show();
}
 
Example 8
Source File: SettingsFragment.java    From MTweaks-KernelAdiutorMOD with GNU General Public License v3.0 4 votes vote down vote up
private void editPasswordDialog(final String oldPass) {
    mOldPassword = oldPass;

    LinearLayout linearLayout = new LinearLayout(getActivity());
    linearLayout.setOrientation(LinearLayout.VERTICAL);
    linearLayout.setGravity(Gravity.CENTER);
    int padding = Math.round(getResources().getDimension(R.dimen.dialog_padding));
    linearLayout.setPadding(padding, padding, padding, padding);

    final AppCompatEditText oldPassword = new AppCompatEditText(getActivity());
    if (!oldPass.isEmpty()) {
        oldPassword.setInputType(InputType.TYPE_CLASS_TEXT
                | InputType.TYPE_TEXT_VARIATION_PASSWORD);
        oldPassword.setHint(getString(R.string.old_password));
        linearLayout.addView(oldPassword);
    }

    final AppCompatEditText newPassword = new AppCompatEditText(getActivity());
    newPassword.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);
    newPassword.setHint(getString(R.string.new_password));
    linearLayout.addView(newPassword);

    final AppCompatEditText confirmNewPassword = new AppCompatEditText(getActivity());
    confirmNewPassword.setInputType(InputType.TYPE_CLASS_TEXT
            | InputType.TYPE_TEXT_VARIATION_PASSWORD);
    confirmNewPassword.setHint(getString(R.string.confirm_new_password));
    linearLayout.addView(confirmNewPassword);

    new Dialog(getActivity()).setView(linearLayout)
            .setNegativeButton(getString(R.string.cancel), (dialogInterface, i) -> {
            })
            .setPositiveButton(getString(R.string.ok), (dialogInterface, i) -> {
                if (!oldPass.isEmpty() && !oldPassword.getText().toString().equals(Utils
                        .decodeString(oldPass))) {
                    Utils.toast(getString(R.string.old_password_wrong), getActivity());
                    return;
                }

                if (newPassword.getText().toString().isEmpty()) {
                    Utils.toast(getString(R.string.password_empty), getActivity());
                    return;
                }

                if (!newPassword.getText().toString().equals(confirmNewPassword.getText()
                        .toString())) {
                    Utils.toast(getString(R.string.password_not_match), getActivity());
                    return;
                }

                if (newPassword.getText().toString().length() > 32) {
                    Utils.toast(getString(R.string.password_too_long), getActivity());
                    return;
                }

                AppSettings.savePassword(Utils.encodeString(newPassword.getText()
                        .toString()), getActivity());
                if (mFingerprint != null) {
                    mFingerprint.setEnabled(true);
                }
            })
            .setOnDismissListener(dialogInterface -> mOldPassword = null).show();
}
 
Example 9
Source File: RuleViewModel.java    From Jockey with Apache License 2.0 4 votes vote down vote up
private void showValueDialog() {
    /*
         Ideally, the View that this ViewHolder wraps would have the EditText directly
         in it without doing the trickery below where it disguises a TextView as an EditText
         and opens an AlertDialog, but there are severe penalties with nesting EditTexts in
         a RecyclerView with a LinearLayoutManager. With no code in the ReyclerView
         Adapter's .onBindViewHolder() method, GC will kick in frequently when scrolling
         to free ~2MB from the heap while pausing for around 60ms (which may also be
         complimented by extra layout calls with the EditText). This has been previously
         reported to Google's AOSP bug tracker which provides more insight into this problem
         https://code.google.com/p/android/issues/detail?id=82586 (closed Feb '15)
         There are some workarounds to this issue, but the most practical suggestions that
         keep the previously mentioned layout are to use a ListView or to extend EditText
         or LinearLayout Manager (which either cause problems in themselves, don't work,
         or both).
         The solution used here simply avoids the problem all together by not nesting an
         EditText in a RecyclerView. When an EditText is needed, the user is prompted with
         an AlertDialog. It's not the best UX, but it's the most practical one for now.
         10/8/15
     */

    TextInputLayout inputLayout = new TextInputLayout(mContext);
    AppCompatEditText editText = new AppCompatEditText(mContext);

    editText.setInputType(mEnumeratedRule.getInputType());
    inputLayout.addView(editText);

    Resources res = mContext.getResources();

    String type = res.getStringArray(R.array.auto_plist_types)[getSelectedType()];
    String match = res.getString(mEnumeratedRule.getNameRes()).toLowerCase();

    AlertDialog valueDialog = new AlertDialog.Builder(mContext)
            .setMessage(type + " " + match)
            .setView(inputLayout)
            .setNegativeButton(R.string.action_cancel, null)
            .setPositiveButton(R.string.action_done,
                    (dialog, which) -> {
                        String value = editText.getText().toString().trim();
                        if (editText.getInputType() == InputType.TYPE_CLASS_NUMBER) {
                            // Verify the input if this rule needs a numeric value
                            if (TextUtils.isDigitsOnly(value)) {
                                mFactory.setValue(value);
                            } else {
                                // If the user inputted something that's not a number, reset it
                                mFactory.setValue("0");
                            }
                        } else {
                            mFactory.setValue(value);
                        }
                        apply();
                        notifyPropertyChanged(BR.valueText);
                    })
            .create();

    valueDialog.getWindow().setSoftInputMode(SOFT_INPUT_STATE_VISIBLE);

    valueDialog.show();

    int padding = (int) mContext.getResources().getDimension(R.dimen.alert_padding);
    ((View) inputLayout.getParent()).setPadding(
            padding - inputLayout.getPaddingLeft(), 0,
            padding - inputLayout.getPaddingRight(), 0);

    editText.setText(mFactory.getValue());
    editText.setSelection(mFactory.getValue().length());
    editText.setOnEditorActionListener((v, actionId, event) -> {
        if (actionId == KeyEvent.KEYCODE_ENDCALL) {
            valueDialog.getButton(DialogInterface.BUTTON_POSITIVE).callOnClick();
        }
        return false;
    });
}