androidx.appcompat.widget.AppCompatEditText Java Examples

The following examples show how to use androidx.appcompat.widget.AppCompatEditText. 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: EditTextPreference.java    From MaterialPreferenceLibrary with Apache License 2.0 6 votes vote down vote up
@Override
protected void init(final Context context, final AttributeSet attrs, final int defStyleAttr, final int defStyleRes) {
    super.init(context, attrs, defStyleAttr, defStyleRes);
    mEditText = new AppCompatEditText(context, attrs);

    // Give it an ID so it can be saved/restored
    mEditText.setId(android.R.id.edit);

    /*
     * The preference framework and view framework both have an 'enabled'
     * attribute. Most likely, the 'enabled' specified in this XML is for
     * the preference framework, but it was also given to the view framework.
     * We reset the enabled state.
     */
    mEditText.setEnabled(true);
    setDialogLayoutResource(R.layout.mpl__edittext_dialog_preference);
}
 
Example #2
Source File: UserFeedbackView.java    From applivery-android-sdk with Apache License 2.0 6 votes vote down vote up
private void initViewElements(View view) {

        cancelButton = (ImageButton) view.findViewById(R.id.applivery_feedback_cancel_button);
        okButton = (ImageButton) view.findViewById(R.id.applivery_feedback_ok_button);
        sendButton = (ImageButton) view.findViewById(R.id.applivery_feedback_send_button);
        feedbackButton = (LinearLayout) view.findViewById(R.id.applivery_tab_button_selector_feedback);
        bugButton = (LinearLayout) view.findViewById(R.id.applivery_tab_button_selector_bug);
        screenshot = (DrawingImageView) view.findViewById(R.id.appliveryScreenShot);
        feedbackImage = (ImageView) view.findViewById(R.id.applivery_feedback_image);
        feedbackMessage = (AppCompatEditText) view.findViewById(R.id.applivery_feedback_description);
        screenShotSwitch = (SwitchCompat) view.findViewById(R.id.attach_screenshot_switch);

        initViewState();

        initElementActions();
    }
 
Example #3
Source File: FilterView.java    From mimi-reader with Apache License 2.0 6 votes vote down vote up
private void init(Context context) {
    inflate(context, R.layout.post_filter_view, this);

    activeBoard = (AppCompatSpinner) findViewById(R.id.active_board);
    activeBoard.setOnItemSelectedListener(onBoardClicked());

    nameInput = (AppCompatEditText) findViewById(R.id.filter_name);
    filterInput = (AppCompatEditText) findViewById(R.id.filter_text);
    highlightCheckBox = (AppCompatCheckBox) findViewById(R.id.highlight_checkbox);

    saveButton = (AppCompatButton) findViewById(R.id.save_button);

    saveButton.setOnClickListener(this);
    findViewById(R.id.edit_button).setOnClickListener(this);
    findViewById(R.id.cancel_button).setOnClickListener(this);
}
 
Example #4
Source File: FullNumberFragment.java    From CountryCodePicker with Apache License 2.0 6 votes vote down vote up
private void assignView() {
    //load number
    editTextLoadFullNumber=(AppCompatEditText) getView().findViewById(R.id.editText_loadFullNumber);
    editTextLoadCarrierNumber=(AppCompatEditText)getView().findViewById(R.id.editText_loadCarrierNumber);
    ccpLoadNumber=(CountryCodePicker)getView().findViewById(R.id.ccp_loadFullNumber);
    buttonLoadNumber=(Button)getView().findViewById(R.id.button_loadFullNumber);

    //get number
    editTextGetCarrierNumber=(AppCompatEditText)getView().findViewById(R.id.editText_getCarrierNumber);
    editTextGetFullNumber=(AppCompatEditText)getView().findViewById(R.id.editText_getFullNumber);
    buttonGetNumber=(Button)getView().findViewById(R.id.button_getFullNumber);
    buttonGetNumberWithPlus=(Button)getView().findViewById(R.id.button_getFullNumberWithPlus);
    ccpGetNumber=(CountryCodePicker)getView().findViewById(R.id.ccp_getFullNumber);

    buttonNext=(Button)getView().findViewById(R.id.button_next);
}
 
Example #5
Source File: EditorActivity.java    From SmartPack-Kernel-Manager with GNU General Public License v3.0 6 votes vote down vote up
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_editor);

    initToolBar();
    String title = getIntent().getStringExtra(TITLE_INTENT);
    if (title != null) {
        Objects.requireNonNull(getSupportActionBar()).setTitle(title);
    }

    CharSequence text = getIntent().getCharSequenceExtra(TEXT_INTENT);
    mEditText = (AppCompatEditText) findViewById(R.id.edittext);
    if (text != null) {
        mEditText.append(text);
    }
}
 
Example #6
Source File: TintHelper.java    From a with GNU General Public License v3.0 5 votes vote down vote up
@SuppressLint("RestrictedApi")
public static void setTint(@NonNull AppCompatEditText editText, @ColorInt int color, boolean useDarker) {
    final ColorStateList editTextColorStateList = new ColorStateList(new int[][]{
            new int[]{-android.R.attr.state_enabled},
            new int[]{android.R.attr.state_enabled, -android.R.attr.state_pressed, -android.R.attr.state_focused},
            new int[]{}
    }, new int[]{
            ContextCompat.getColor(editText.getContext(), useDarker ? R.color.ate_text_disabled_dark : R.color.ate_text_disabled_light),
            ContextCompat.getColor(editText.getContext(), useDarker ? R.color.ate_control_normal_dark : R.color.ate_control_normal_light),
            color
    });
    editText.setSupportBackgroundTintList(editTextColorStateList);
    setCursorTint(editText, color);
}
 
Example #7
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 #8
Source File: SearchViewModel.java    From CloudReader with Apache License 2.0 5 votes vote down vote up
@BindingAdapter("android:textSelection")
    public static void textSelection(AppCompatEditText tv, ObservableField<String> value) {
        if (!TextUtils.isEmpty(tv.getText())) {
//            tv.setText(value.get());
            // Set the cursor to the end of the text
            tv.setSelection(tv.getText().length());
        }
    }
 
Example #9
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 #10
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 #11
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 #12
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 #13
Source File: BaseDialog.java    From NewFastFrame with Apache License 2.0 5 votes vote down vote up
/**
 * 设置编辑列表VIEW
 *
 * @param names 编辑view 的name
 * @return this
 */
public BaseDialog setEditViewsName(List<String> names) {
    if (middleLayout.getChildCount() > 0) {
        middleLayout.removeAllViews();
    }

    for (String name :
            names) {
        TextView textView = new TextView(getContext());
        textView.setText(name);
        textView.setTextColor(getContext().getResources().getColor(R.color.base_color_text_black));
        AppCompatEditText editText = new AppCompatEditText(getContext(), null, android.R.attr.editTextStyle);
        editText.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
        editText.setHint("请输入" + name);
        editText.setPadding(10, 0, 0, 0);
        editText.setHintTextColor(Color.BLUE);
        LinearLayout child = new LinearLayout(getContext());
        LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        child.setOrientation(LinearLayout.HORIZONTAL);
        child.setGravity(Gravity.CENTER_VERTICAL);
        child.setLayoutParams(params);
        child.addView(textView);
        child.addView(editText);
        middleLayout.addView(child);
    }
    return this;
}
 
Example #14
Source File: CustomKeyboard.java    From SSForms with GNU General Public License v3.0 5 votes vote down vote up
private void showCustomKeyboard(View v, AppCompatEditText edittext) {
    mKeyboardView.setVisibility(View.VISIBLE);

    OnCustomKeyboardActionListener mOnKeyboardActionListener = new OnCustomKeyboardActionListener(edittext, mKeyboardView);
    mKeyboardView.setOnKeyboardActionListener(mOnKeyboardActionListener);

    mKeyboardView.setEnabled(true);
    if (v != null)
        ((InputMethodManager) mHostActivity.getSystemService(Activity.INPUT_METHOD_SERVICE)).hideSoftInputFromWindow(v.getWindowToken(), 0);
}
 
Example #15
Source File: ComposeActivity.java    From lttrs-android with Apache License 2.0 5 votes vote down vote up
private void requestFocusAndOpenKeyboard(AppCompatEditText editText) {
    editText.requestFocus();
    final InputMethodManager inputMethodManager = getSystemService(InputMethodManager.class);
    if (inputMethodManager != null) {
        inputMethodManager.showSoftInput(editText, InputMethodManager.SHOW_IMPLICIT);
    }
}
 
Example #16
Source File: FormAdapter.java    From SSForms with GNU General Public License v3.0 5 votes vote down vote up
private void setTimePicker(final AppCompatEditText editText, final int position, final LinearLayout layoutRow) {

        editText.setFocusableInTouchMode(false);

        editText.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                editText.requestFocus();
                InputMethodManager imm = (InputMethodManager) mContext.getSystemService(Context.INPUT_METHOD_SERVICE);
                imm.showSoftInput(editText, InputMethodManager.SHOW_IMPLICIT);
            }
        });

        layoutRow.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                // saves clicked position for further reference
                clickedPosition = position;
                // prepares time picker dialog
                TimePickerDialog timePickerDialog = new TimePickerDialog(mContext,
                       time,
                        mCalendarCurrentDate.get(Calendar.HOUR_OF_DAY),
                        mCalendarCurrentDate.get(Calendar.MINUTE),
                        true);
                // display the picker
                timePickerDialog.show();
            }
        });

    }
 
Example #17
Source File: FormAdapter.java    From SSForms with GNU General Public License v3.0 5 votes vote down vote up
private void setDatePicker(final AppCompatEditText editText, final int position, final LinearLayout layoutRow) {
    editText.setFocusableInTouchMode(false);

    editText.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            editText.requestFocus();
            InputMethodManager imm = (InputMethodManager) mContext.getSystemService(Context.INPUT_METHOD_SERVICE);
            imm.showSoftInput(editText, InputMethodManager.SHOW_IMPLICIT);
        }
    });

    layoutRow.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            clickedPosition = position;
            DatePickerDialog datePickerDialog = new DatePickerDialog(mContext,
                    date,
                    mCalendarCurrentDate.get(Calendar.YEAR),
                    mCalendarCurrentDate.get(Calendar.MONTH),
                    mCalendarCurrentDate.get(Calendar.DAY_OF_MONTH));

            // this could be used to set a minimum date
            // datePickerDialog.getDatePicker().setMinDate(System.currentTimeMillis() - 1000);

            // display the picker
            datePickerDialog.show();
        }
    });

}
 
Example #18
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 #19
Source File: CustomIpActivity.java    From netanalysis-sdk-android with Apache License 2.0 5 votes vote down vote up
@Override
public void onClick(View v) {
    switch (v.getId()) {
        case R.id.txt_submit: {
            Set<String> ipSet = new ArraySet<>();
            customIPs.clear();
            for (AppCompatEditText edit : edits) {
                String ip;
                if (edit.getText() == null || TextUtils.isEmpty(ip = edit.getText().toString().trim()))
                    continue;
                
                ipSet.add(ip);
                customIPs.add(ip);
            }
            mSharedPreferences.edit()
                    .putStringSet("custom_ips", ipSet)
                    .apply();
            
            Intent result = new Intent();
            result.putStringArrayListExtra("custom_ips", (ArrayList<String>) customIPs);
            setResult(RESULT_OK, result);
            finish();
            
            break;
        }
    }
}
 
Example #20
Source File: StarkSpinner.java    From SSForms with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void onFinishInflate() {
    super.onFinishInflate();
    mRevealContainerCardView = (CardView) findViewById(R.id.CrdVw_RevealContainer);
    mRevealContainerCardView.setOnClickListener(mOnRevelViewClickListener);
    mRevealItem = (LinearLayout) findViewById(R.id.FrmLt_SelectedItem);
    mStartSearchImageView = (IconTextView) findViewById(R.id.ImgVw_StartSearch);

    mContainerCardView = (CardView) findViewById(R.id.CrdVw_Container);
    mSearchEditText = (AppCompatEditText) findViewById(R.id.EdtTxt_SearchEditText);
    mDoneSearchImageView = (IconTextView) findViewById(R.id.ImgVw_DoneSearch);
    init();
}
 
Example #21
Source File: TintHelper.java    From MyBookshelf with GNU General Public License v3.0 5 votes vote down vote up
@SuppressLint("RestrictedApi")
public static void setTint(@NonNull AppCompatEditText editText, @ColorInt int color, boolean useDarker) {
    final ColorStateList editTextColorStateList = new ColorStateList(new int[][]{
            new int[]{-android.R.attr.state_enabled},
            new int[]{android.R.attr.state_enabled, -android.R.attr.state_pressed, -android.R.attr.state_focused},
            new int[]{}
    }, new int[]{
            ContextCompat.getColor(editText.getContext(), useDarker ? R.color.ate_text_disabled_dark : R.color.ate_text_disabled_light),
            ContextCompat.getColor(editText.getContext(), useDarker ? R.color.ate_control_normal_dark : R.color.ate_control_normal_light),
            color
    });
    editText.setSupportBackgroundTintList(editTextColorStateList);
    setCursorTint(editText, color);
}
 
Example #22
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 #23
Source File: TintHelper.java    From a with GNU General Public License v3.0 4 votes vote down vote up
@SuppressWarnings("deprecation")
public static void setTintAuto(final @NonNull View view, final @ColorInt int color,
                               boolean background, final boolean isDark) {
    if (!background) {
        if (view instanceof RadioButton)
            setTint((RadioButton) view, color, isDark);
        else if (view instanceof SeekBar)
            setTint((SeekBar) view, color, isDark);
        else if (view instanceof ProgressBar)
            setTint((ProgressBar) view, color);
        else if (view instanceof AppCompatEditText)
            setTint((AppCompatEditText) view, color, isDark);
        else if (view instanceof CheckBox)
            setTint((CheckBox) view, color, isDark);
        else if (view instanceof ImageView)
            setTint((ImageView) view, color);
        else if (view instanceof Switch)
            setTint((Switch) view, color, isDark);
        else if (view instanceof SwitchCompat)
            setTint((SwitchCompat) view, color, isDark);
        else if (view instanceof SearchView) {
            int iconIdS[] = new int[]{androidx.appcompat.R.id.search_button, androidx.appcompat.R.id.search_close_btn,};
            for (int iconId : iconIdS) {
                ImageView icon = view.findViewById(iconId);
                if (icon != null) {
                    setTint(icon, color);
                }
            }

        } else {
            background = true;
        }

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP &&
                !background && view.getBackground() instanceof RippleDrawable) {
            // Ripples for the above views (e.g. when you tap and hold a switch or checkbox)
            RippleDrawable rd = (RippleDrawable) view.getBackground();
            @SuppressLint("PrivateResource") final int unchecked = ContextCompat.getColor(view.getContext(),
                    isDark ? R.color.ripple_material_dark : R.color.ripple_material_light);
            final int checked = ColorUtil.adjustAlpha(color, 0.4f);
            final ColorStateList sl = new ColorStateList(
                    new int[][]{
                            new int[]{-android.R.attr.state_activated, -android.R.attr.state_checked},
                            new int[]{android.R.attr.state_activated},
                            new int[]{android.R.attr.state_checked}
                    },
                    new int[]{
                            unchecked,
                            checked,
                            checked
                    }
            );
            rd.setColor(sl);
        }
    }
    if (background) {
        // Need to tint the background of a view
        if (view instanceof FloatingActionButton || view instanceof Button) {
            setTintSelector(view, color, false, isDark);
        } else if (view.getBackground() != null) {
            Drawable drawable = view.getBackground();
            if (drawable != null) {
                drawable = createTintedDrawable(drawable, color);
                ViewUtil.setBackgroundCompat(view, drawable);
            }
        }
    }
}
 
Example #24
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;
    });
}
 
Example #25
Source File: TintHelper.java    From MyBookshelf with GNU General Public License v3.0 4 votes vote down vote up
@SuppressWarnings("deprecation")
public static void setTintAuto(final @NonNull View view, final @ColorInt int color,
                               boolean background, final boolean isDark) {
    if (!background) {
        if (view instanceof RadioButton)
            setTint((RadioButton) view, color, isDark);
        else if (view instanceof SeekBar)
            setTint((SeekBar) view, color, isDark);
        else if (view instanceof ProgressBar)
            setTint((ProgressBar) view, color);
        else if (view instanceof AppCompatEditText)
            setTint((AppCompatEditText) view, color, isDark);
        else if (view instanceof CheckBox)
            setTint((CheckBox) view, color, isDark);
        else if (view instanceof ImageView)
            setTint((ImageView) view, color);
        else if (view instanceof Switch)
            setTint((Switch) view, color, isDark);
        else if (view instanceof SwitchCompat)
            setTint((SwitchCompat) view, color, isDark);
        else if (view instanceof SearchView) {
            int iconIdS[] = new int[]{androidx.appcompat.R.id.search_button, androidx.appcompat.R.id.search_close_btn,};
            for (int iconId : iconIdS) {
                ImageView icon = view.findViewById(iconId);
                if (icon != null) {
                    setTint(icon, color);
                }
            }

        } else {
            background = true;
        }

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP &&
                !background && view.getBackground() instanceof RippleDrawable) {
            // Ripples for the above views (e.g. when you tap and hold a switch or checkbox)
            RippleDrawable rd = (RippleDrawable) view.getBackground();
            @SuppressLint("PrivateResource") final int unchecked = ContextCompat.getColor(view.getContext(),
                    isDark ? R.color.ripple_material_dark : R.color.ripple_material_light);
            final int checked = ColorUtil.adjustAlpha(color, 0.4f);
            final ColorStateList sl = new ColorStateList(
                    new int[][]{
                            new int[]{-android.R.attr.state_activated, -android.R.attr.state_checked},
                            new int[]{android.R.attr.state_activated},
                            new int[]{android.R.attr.state_checked}
                    },
                    new int[]{
                            unchecked,
                            checked,
                            checked
                    }
            );
            rd.setColor(sl);
        }
    }
    if (background) {
        // Need to tint the background of a view
        if (view instanceof FloatingActionButton || view instanceof Button) {
            setTintSelector(view, color, false, isDark);
        } else if (view.getBackground() != null) {
            Drawable drawable = view.getBackground();
            if (drawable != null) {
                drawable = createTintedDrawable(drawable, color);
                ViewUtil.setBackgroundCompat(view, drawable);
            }
        }
    }
}
 
Example #26
Source File: ViewUtils.java    From MTweaks-KernelAdiutorMOD with GNU General Public License v3.0 4 votes vote down vote up
public static Dialog dialogEditTexts(String text, String text2, String hint, String hint2,
                                     final DialogInterface.OnClickListener negativeListener,
                                     final onDialogEditTextsListener onDialogEditTextListener,
                                     Context context) {
    LinearLayout layout = new LinearLayout(context);
    layout.setOrientation(LinearLayout.VERTICAL);
    int padding = (int) context.getResources().getDimension(R.dimen.dialog_padding);
    layout.setPadding(padding, padding, padding, padding);

    final AppCompatEditText editText = new AppCompatEditText(context);
    editText.setLayoutParams(new LinearLayout.LayoutParams(
            ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
    if (text != null) {
        editText.append(text);
    }
    if (hint != null) {
        editText.setHint(hint);
    }
    editText.setSingleLine(true);

    final AppCompatEditText editText2 = new AppCompatEditText(context);
    editText2.setLayoutParams(new LinearLayout.LayoutParams(
            LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT));
    if (text2 != null) {
        editText2.setText(text2);
    }
    if (hint2 != null) {
        editText2.setHint(hint2);
    }
    editText2.setSingleLine(true);

    layout.addView(editText);
    layout.addView(editText2);

    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(), editText2.getText().toString()))
                .setOnDismissListener(dialog1 -> {
                    if (negativeListener != null) {
                        negativeListener.onClick(dialog1, 0);
                    }
                });
    }
    return dialog;
}
 
Example #27
Source File: FileExplorerDialog.java    From GetApk with MIT License 4 votes vote down vote up
@Override
public boolean onMenuItemClick(MenuItem item) {
    int id = item.getItemId();
    switch (id) {
        case R.id.confirm:
            mBuilder.pathSelectListener.onSelected((String) mPathTV.getText());
            dismiss();
            break;
        case R.id.create:
            new AlertDialog.Builder(getContext())
                    .setTitle(R.string.new_create_folder)
                    .setView(R.layout.item_edit)
                    .setNegativeButton(R.string.cancel, null)
                    .setPositiveButton(R.string.new_create, new OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            AppCompatEditText editText = ((AppCompatDialog) dialog).findViewById(R.id.name_et);
                            String name = editText.getText().toString();
                            if (TextUtils.isEmpty(name)) {
                                name = getContext().getString(R.string.new_create_folder);
                            }
                            try {
                                String path = mPathTV.getText().toString();
                                FileUtil.newCreateFolder(path, name);
                                if (mDisposable != null && !mDisposable.isDisposed()) {
                                    mDisposable.dispose();
                                }
                                mDisposable = mPresenter.getFiles(path);
                                addDisposable(mDisposable);
                            } catch (IOException e) {
                                e.printStackTrace();
                            }

                        }
                    })
                    .show().setCanceledOnTouchOutside(false);
            break;
    }

    return true;
}
 
Example #28
Source File: MainActivity.java    From SSForms with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void callbackTextFEReturn(String value, AppCompatEditText object, Object tag) {
    String sMessageToast = String.format("CONTROL : FormElement - VALUE %s", value);
    showToastMessage(sMessageToast);
}
 
Example #29
Source File: ViewUtils.java    From SmartPack-Kernel-Manager with GNU General Public License v3.0 4 votes vote down vote up
public static Dialog dialogEditTexts(String text, String text2, String hint, String hint2,
                                     final DialogInterface.OnClickListener negativeListener,
                                     final onDialogEditTextsListener onDialogEditTextListener,
                                     Context context) {
    LinearLayout layout = new LinearLayout(context);
    layout.setOrientation(LinearLayout.VERTICAL);
    int padding = (int) context.getResources().getDimension(R.dimen.dialog_padding);
    layout.setPadding(padding, padding, padding, padding);

    final AppCompatEditText editText = new AppCompatEditText(context);
    editText.setLayoutParams(new LinearLayout.LayoutParams(
            ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
    if (text != null) {
        editText.append(text);
    }
    if (hint != null) {
        editText.setHint(hint);
    }
    editText.setSingleLine(true);

    final AppCompatEditText editText2 = new AppCompatEditText(context);
    editText2.setLayoutParams(new LinearLayout.LayoutParams(
            LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT));
    if (text2 != null) {
        editText2.setText(text2);
    }
    if (hint2 != null) {
        editText2.setHint(hint2);
    }
    editText2.setSingleLine(true);

    layout.addView(editText);
    layout.addView(editText2);

    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(), Objects.requireNonNull(editText2.getText()).toString()))
                .setOnDismissListener(dialog1 -> {
                    if (negativeListener != null) {
                        negativeListener.onClick(dialog1, 0);
                    }
                });
    }
    return dialog;
}
 
Example #30
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();
}