Java Code Examples for android.support.v7.widget.AppCompatEditText#setInputType()

The following examples show how to use android.support.v7.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: MainActivity.java    From KA27 with Apache License 2.0 6 votes vote down vote up
/**
 * Dialog which asks the user to enter his password
 *
 * @param password current encoded password
 */
private void askPassword(final String password) {
    LinearLayout linearLayout = new LinearLayout(this);
    linearLayout.setOrientation(LinearLayout.VERTICAL);
    linearLayout.setGravity(Gravity.CENTER);
    linearLayout.setPadding(30, 20, 30, 20);

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

    new AlertDialog.Builder(this).setView(linearLayout).setCancelable(false)
        .setPositiveButton(getString(R.string.ok), new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialogInterface, int i) {
                if (mPassword.getText().toString().equals(Utils.decodeString(password)))
                    new Task().execute();
                else {
                    Utils.toast(getString(R.string.password_wrong), MainActivity.this);
                    finish();
                }
            }
        }).show();
}
 
Example 2
Source File: MainActivity.java    From kernel_adiutor with Apache License 2.0 6 votes vote down vote up
/**
 * Dialog which asks the user to enter his password
 *
 * @param password current encoded password
 */
private void askPassword(final String password) {
    LinearLayout linearLayout = new LinearLayout(this);
    linearLayout.setOrientation(LinearLayout.VERTICAL);
    linearLayout.setGravity(Gravity.CENTER);
    linearLayout.setPadding(30, 20, 30, 20);

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

    new AlertDialog.Builder(this).setView(linearLayout).setCancelable(false)
            .setPositiveButton(getString(R.string.ok), new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialogInterface, int i) {
                    if (mPassword.getText().toString().equals(Utils.decodeString(password)))
                        new Task().execute();
                    else {
                        Utils.toast(getString(R.string.password_wrong), MainActivity.this);
                        finish();
                    }
                }
            }).show();
}
 
Example 3
Source File: FragmentMatrixInput.java    From ncalc with GNU General Public License v3.0 5 votes vote down vote up
private void createLayoutMatrix(int col, int row, ViewGroup viewGroup) {
    viewGroup.removeAllViews();
    @IdRes int index = 1;
    for (int i = 0; i < row; i++) {
        for (int j = 0; j < col; j++) {
            AppCompatEditText editText = new AppCompatEditText(getContext());
            editText.setHint("[" + i + "," + j + "]");
            RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(
                    RelativeLayout.LayoutParams.WRAP_CONTENT,
                    RelativeLayout.LayoutParams.WRAP_CONTENT);
            editText.setSingleLine(true);
            editText.setInputType(InputType.TYPE_NUMBER_FLAG_DECIMAL);
            editText.setId(index);
            if (isDebug) {
                editText.setText(String.valueOf(random.nextInt(200) - 100));
            }
            if (j == 0) {
                params.addRule(RelativeLayout.ALIGN_PARENT_LEFT, RelativeLayout.TRUE);
            } else {
                params.addRule(RelativeLayout.RIGHT_OF, index - 1);
            }

            if (i == 0) {
                params.addRule(RelativeLayout.ALIGN_PARENT_TOP, RelativeLayout.TRUE);
            } else {
                params.addRule(RelativeLayout.BELOW, index - col);
            }
            editText.setLayoutParams(params);
            viewGroup.addView(editText);
            index++;
        }
    }

}
 
Example 4
Source File: FormElementTextMultiLineViewHolder.java    From FormMaster with Apache License 2.0 5 votes vote down vote up
public FormElementTextMultiLineViewHolder(View v, FormItemEditTextListener listener) {
    super(v);
    mTextViewTitle = (AppCompatTextView) v.findViewById(R.id.formElementTitle);
    mEditTextValue = (AppCompatEditText) v.findViewById(R.id.formElementValue);
    mFormCustomEditTextListener = listener;
    mEditTextValue.addTextChangedListener(mFormCustomEditTextListener);
    mEditTextValue.setMaxLines(4);
    mEditTextValue.setSingleLine(false);
    mEditTextValue.setInputType(InputType.TYPE_CLASS_TEXT|InputType.TYPE_TEXT_FLAG_MULTI_LINE);
}
 
Example 5
Source File: SettingsFragment.java    From KA27 with Apache License 2.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;
    }

    LinearLayout linearLayout = new LinearLayout(getActivity());
    linearLayout.setOrientation(LinearLayout.VERTICAL);
    linearLayout.setGravity(Gravity.CENTER);
    linearLayout.setPadding(30, 20, 30, 20);

    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 AlertDialog.Builder(getActivity(),
            (Utils.DARKTHEME ? R.style.AlertDialogStyleDark : R.style.AlertDialogStyleLight)).setView(linearLayout)
        .setPositiveButton(getString(R.string.ok), new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialogInterface, int i) {
                if (!mPassword.getText().toString().equals(Utils.decodeString(password))) {
                    Utils.toast(getString(R.string.password_wrong), getActivity());
                    return;
                }

                Utils.saveString("password", "", getActivity());
            }
        }).show();
}
 
Example 6
Source File: SettingsFragment.java    From kernel_adiutor with Apache License 2.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;
    }

    LinearLayout linearLayout = new LinearLayout(getActivity());
    linearLayout.setOrientation(LinearLayout.VERTICAL);
    linearLayout.setGravity(Gravity.CENTER);
    linearLayout.setPadding(30, 20, 30, 20);

    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 AlertDialog.Builder(getActivity()).setView(linearLayout)
            .setPositiveButton(getString(R.string.ok), new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialogInterface, int i) {
                    if (!mPassword.getText().toString().equals(Utils.decodeString(password))) {
                        Utils.toast(getString(R.string.password_wrong), getActivity());
                        return;
                    }

                    Utils.saveString("password", "", getActivity());
                }
            }).show();
}
 
Example 7
Source File: SettingsFragment.java    From KernelAdiutor 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 8
Source File: QuestionnaireView.java    From QuestionnaireView with MIT License 4 votes vote down vote up
private void drawInnerViews(Context context, AttributeSet attrs){
    float density = context.getResources().getDisplayMetrics().density;
    int value16 = (int)(16*density);
    int value10 = (int)(10*density);
    int value40 = (int)(40*density);
    LayoutParams mainLayoutParams = new LayoutParams(
            LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
    mainLayoutParams.setMargins(value16,value16,value16,value16);
    setLayoutParams(mainLayoutParams);

    //creation & addition of webview
    webview = new WebView(context, attrs);
    webview.setId(android.R.id.content);
    webview.setLayoutParams(
            new LayoutBuilder()
                    .addWidth(LayoutParams.MATCH_PARENT)
                    .addHeight(LayoutParams.WRAP_CONTENT)
                    .setMargin(value10,value40,0,0)
                    .create()
    );
    webview.getSettings();
    webview.setBackgroundColor(Color.argb(0,0,0,0));
    addView(webview);

    //creation of list view
    listView = new ListView(context, attrs);
    listView.setId(android.R.id.list);
    listView.setLayoutParams(
            new LayoutBuilder()
                    .addWidth(LayoutParams.MATCH_PARENT)
                    .addHeight(LayoutParams.WRAP_CONTENT)
                    .setMargin(0,value10,0,0)
                    .addRule(BELOW, webview.getId() )
                    .create()
    );
    addView(listView );

    //creation & addition of editText
    editTv = new AppCompatEditText(context, attrs);
    editTv.setVisibility(GONE);
    editTv.setId(android.R.id.text1);
    editTv.setLayoutParams(
            new LayoutBuilder()
                    .addWidth(LayoutParams.MATCH_PARENT)
                    .addHeight(LayoutParams.WRAP_CONTENT)
                    .setMargin(value10, value10, 0, 0)
                    .addRule(BELOW, webview.getId())
                    .create()
    );
    editTv.setInputType(InputType.TYPE_CLASS_TEXT);
    editTv.setImeOptions(EditorInfo.IME_ACTION_DONE);
    addView(editTv );

}
 
Example 9
Source File: SettingsFragment.java    From KernelAdiutor 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();
}