Search in sources :

Example 36 with InputFilter

use of android.text.InputFilter in project NoteText by ViWu.

the class MainMenu method renameDialog.

private void renameDialog(String setName) {
    final EditText textField = new EditText(MainMenu.this);
    AlertDialog.Builder alert = new AlertDialog.Builder(MainMenu.this);
    alert.setMessage("Enter New Name of the Set");
    alert.setTitle("Rename Set");
    alert.setView(textField);
    textField.setText(setName);
    int cursorPos = setName.length();
    textField.setSelection(cursorPos);
    textField.setSelectAllOnFocus(true);
    textField.requestFocus();
    final InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
    imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, InputMethodManager.HIDE_IMPLICIT_ONLY);
    textField.setFilters(new InputFilter[] { new InputFilter.LengthFilter(25) });
    alert.setPositiveButton("Ok", new DialogInterface.OnClickListener() {

        public void onClick(DialogInterface dialog, int whichButton) {
            String newName = textField.getText().toString();
            if (newName.length() > 0)
                fileRename(Names.get(position), newName);
            else {
                String msg = "Rename set failed! Set names need to be at least one character long!";
                errorDialog(msg);
            }
            imm.toggleSoftInput(InputMethodManager.HIDE_IMPLICIT_ONLY, InputMethodManager.RESULT_UNCHANGED_SHOWN);
        }
    });
    alert.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {

        public void onClick(DialogInterface dialog, int whichButton) {
            imm.toggleSoftInput(InputMethodManager.HIDE_IMPLICIT_ONLY, InputMethodManager.RESULT_UNCHANGED_SHOWN);
        }
    });
    alert.show();
}
Also used : EditText(android.widget.EditText) AlertDialog(android.support.v7.app.AlertDialog) InputFilter(android.text.InputFilter) DialogInterface(android.content.DialogInterface) InputMethodManager(android.view.inputmethod.InputMethodManager)

Example 37 with InputFilter

use of android.text.InputFilter in project MLib by DaoBillTang.

the class CommonTextView method initText.

/**
 * 初始化textView
 *
 * @param textView     对象
 * @param layoutParams 对象
 * @param id           id
 * @param textColor    颜色值
 * @param textSize     字体大小
 * @return 返回
 */
public TextView initText(TextView textView, LayoutParams layoutParams, int id, int textColor, int textSize) {
    if (textView == null) {
        textView = new TextView(mContext);
        textView.setId(id);
        textView.setLayoutParams(layoutParams);
        textView.setTextColor(textColor);
        textView.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
        // textView.setGravity(Gravity.CENTER);
        textView.setLines(mSetLines);
        textView.setSingleLine(mSetSingleLine);
        // textView.setMaxEms(mSetMaxEms);
        // textView.setEllipsize(TextUtils.TruncateAt.END);
        textView.setFilters(new InputFilter[] { new InputFilter.LengthFilter(mSetMaxEms) });
        addView(textView);
    }
    return textView;
}
Also used : InputFilter(android.text.InputFilter) TextView(android.widget.TextView)

Example 38 with InputFilter

use of android.text.InputFilter in project collect by opendatakit.

the class FormEndView method init.

private void init(Context context, boolean instanceComplete) {
    inflate(context, R.layout.form_entry_end, this);
    ((TextView) findViewById(R.id.description)).setText(context.getString(R.string.save_enter_data_description, formTitle));
    EditText saveAs = findViewById(R.id.save_name);
    // disallow carriage returns in the name
    InputFilter returnFilter = (source, start, end, dest, dstart, dend) -> FormNameUtils.normalizeFormName(source.toString().substring(start, end), true);
    saveAs.setFilters(new InputFilter[] { returnFilter });
    saveAs.setText(defaultInstanceName);
    saveAs.addTextChangedListener(new TextWatcher() {

        @Override
        public void afterTextChanged(Editable s) {
            listener.onSaveAsChanged(s.toString());
        }

        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
        }
    });
    final CheckBox markAsFinalized = findViewById(R.id.mark_finished);
    markAsFinalized.setChecked(instanceComplete);
    findViewById(R.id.save_exit_button).setOnClickListener(v -> {
        listener.onSaveClicked(markAsFinalized.isChecked());
    });
}
Also used : EditText(android.widget.EditText) FormNameUtils(org.odk.collect.android.utilities.FormNameUtils) Context(android.content.Context) TextView(android.widget.TextView) CheckBox(android.widget.CheckBox) FrameLayout(android.widget.FrameLayout) R(org.odk.collect.android.R) InputFilter(android.text.InputFilter) Editable(android.text.Editable) EditText(android.widget.EditText) TextWatcher(android.text.TextWatcher) InputFilter(android.text.InputFilter) CheckBox(android.widget.CheckBox) TextWatcher(android.text.TextWatcher) Editable(android.text.Editable) TextView(android.widget.TextView)

Example 39 with InputFilter

use of android.text.InputFilter in project collect by opendatakit.

the class ServerPreferencesFragment method addGooglePreferences.

public void addGooglePreferences() {
    addPreferencesFromResource(R.xml.google_preferences);
    selectedGoogleAccountPreference = findPreference(KEY_SELECTED_GOOGLE_ACCOUNT);
    EditTextPreference googleSheetsUrlPreference = (EditTextPreference) findPreference(ProjectKeys.KEY_GOOGLE_SHEETS_URL);
    googleSheetsUrlPreference.setOnBindEditTextListener(editText -> editText.setFilters(new InputFilter[] { new ControlCharacterFilter(), new WhitespaceFilter() }));
    googleSheetsUrlPreference.setOnPreferenceChangeListener(createChangeListener());
    String currentGoogleSheetsURL = googleSheetsUrlPreference.getText();
    if (currentGoogleSheetsURL != null && currentGoogleSheetsURL.length() > 0) {
        googleSheetsUrlPreference.setSummary(currentGoogleSheetsURL + "\n\n" + getString(R.string.google_sheets_url_hint));
    }
    initAccountPreferences();
}
Also used : WhitespaceFilter(org.odk.collect.android.preferences.filters.WhitespaceFilter) InputFilter(android.text.InputFilter) EditTextPreference(androidx.preference.EditTextPreference) ControlCharacterFilter(org.odk.collect.android.preferences.filters.ControlCharacterFilter)

Example 40 with InputFilter

use of android.text.InputFilter in project collect by opendatakit.

the class StringWidgetUtils method adjustEditTextAnswerToDecimalWidget.

public static void adjustEditTextAnswerToDecimalWidget(EditText answerText, FormEntryPrompt prompt) {
    boolean useThousandSeparator = Appearances.useThousandSeparator(prompt);
    if (useThousandSeparator) {
        answerText.addTextChangedListener(new ThousandsSeparatorTextWatcher(answerText));
    }
    answerText.setInputType(InputType.TYPE_NUMBER_FLAG_DECIMAL);
    // only numbers are allowed
    answerText.setKeyListener(new DigitsKeyListener(true, true));
    // only 15 characters allowed
    InputFilter[] fa = new InputFilter[1];
    fa[0] = new InputFilter.LengthFilter(15);
    if (useThousandSeparator) {
        fa[0] = new InputFilter.LengthFilter(19);
    }
    answerText.setFilters(fa);
    Double d = getDoubleAnswerValueFromIAnswerData(prompt.getAnswerValue());
    if (d != null) {
        // truncate to 15 digits max in US locale
        // use US locale because DigitsKeyListener can't be localized before API 26
        NumberFormat nf = NumberFormat.getNumberInstance(Locale.US);
        nf.setMaximumFractionDigits(15);
        nf.setMaximumIntegerDigits(15);
        nf.setGroupingUsed(false);
        String formattedValue = nf.format(d);
        answerText.setText(formattedValue);
        Selection.setSelection(answerText.getText(), answerText.getText().length());
    }
}
Also used : InputFilter(android.text.InputFilter) DigitsKeyListener(android.text.method.DigitsKeyListener) ThousandsSeparatorTextWatcher(org.odk.collect.android.listeners.ThousandsSeparatorTextWatcher) NumberFormat(java.text.NumberFormat)

Aggregations

InputFilter (android.text.InputFilter)86 EditText (android.widget.EditText)31 TextView (android.widget.TextView)27 View (android.view.View)26 DialogInterface (android.content.DialogInterface)18 AlertDialog (android.app.AlertDialog)17 Paint (android.graphics.Paint)12 Editable (android.text.Editable)12 Spanned (android.text.Spanned)10 TextPaint (android.text.TextPaint)10 LinearLayout (android.widget.LinearLayout)10 TextWatcher (android.text.TextWatcher)9 Bundle (android.os.Bundle)8 SpannableStringBuilder (android.text.SpannableStringBuilder)8 ImageView (android.widget.ImageView)8 SmallTest (android.test.suitebuilder.annotation.SmallTest)7 Button (android.widget.Button)7 Context (android.content.Context)6 AlertDialog (android.support.v7.app.AlertDialog)6 Utf8ByteLengthFilter (com.android.settings.bluetooth.Utf8ByteLengthFilter)6