Search in sources :

Example 71 with InputFilter

use of android.text.InputFilter in project Conversations by siacs.

the class EditMessage method onTextContextMenuItem.

@Override
public boolean onTextContextMenuItem(int id) {
    if (id == android.R.id.paste) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            return super.onTextContextMenuItem(android.R.id.pasteAsPlainText);
        } else {
            Editable editable = getEditableText();
            InputFilter[] filters = editable.getFilters();
            InputFilter[] tempFilters = new InputFilter[filters != null ? filters.length + 1 : 1];
            if (filters != null) {
                System.arraycopy(filters, 0, tempFilters, 1, filters.length);
            }
            tempFilters[0] = SPAN_FILTER;
            editable.setFilters(tempFilters);
            try {
                return super.onTextContextMenuItem(id);
            } finally {
                editable.setFilters(filters);
            }
        }
    } else {
        return super.onTextContextMenuItem(id);
    }
}
Also used : InputFilter(android.text.InputFilter) Editable(android.text.Editable)

Example 72 with InputFilter

use of android.text.InputFilter in project AntennaPod by AntennaPod.

the class NumberPickerPreference method onClick.

@Override
protected void onClick() {
    super.onClick();
    View view = View.inflate(context, R.layout.numberpicker, null);
    EditText number = view.findViewById(R.id.number);
    number.setText(getSharedPreferences().getString(getKey(), "" + defaultValue));
    number.setFilters(new InputFilter[] { (source, start, end, dest, dstart, dend) -> {
        try {
            String newVal = dest.toString().substring(0, dstart) + dest.toString().substring(dend);
            newVal = newVal.substring(0, dstart) + source.toString() + newVal.substring(dstart);
            int input = Integer.parseInt(newVal);
            if (input >= minValue && input <= maxValue) {
                return null;
            }
        } catch (NumberFormatException nfe) {
            nfe.printStackTrace();
        }
        return "";
    } });
    AlertDialog dialog = new AlertDialog.Builder(context).setTitle(getTitle()).setView(view).setNegativeButton(android.R.string.cancel, null).setPositiveButton(android.R.string.ok, (dialogInterface, i) -> {
        try {
            String numberString = number.getText().toString();
            int value = Integer.parseInt(numberString);
            if (value < minValue || value > maxValue) {
                return;
            }
            getSharedPreferences().edit().putString(getKey(), "" + value).apply();
            if (getOnPreferenceChangeListener() != null) {
                getOnPreferenceChangeListener().onPreferenceChange(this, value);
            }
        } catch (NumberFormatException e) {
        // Do not set value
        }
    }).create();
    dialog.show();
    dialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
}
Also used : EditText(android.widget.EditText) AlertDialog(androidx.appcompat.app.AlertDialog) Context(android.content.Context) AlertDialog(androidx.appcompat.app.AlertDialog) AttributeSet(android.util.AttributeSet) R(de.danoeh.antennapod.R) WindowManager(android.view.WindowManager) View(android.view.View) InputFilter(android.text.InputFilter) Preference(androidx.preference.Preference) EditText(android.widget.EditText) View(android.view.View)

Example 73 with InputFilter

use of android.text.InputFilter in project routerkeygenAndroid by routerkeygen.

the class ManualInputFragment method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    final String macAddress;
    if (getArguments().containsKey(MAC_ADDRESS_ARG))
        macAddress = getArguments().getString(MAC_ADDRESS_ARG);
    else
        macAddress = null;
    final View root = inflater.inflate(R.layout.fragment_manual_input, container, false);
    mainView = root.findViewById(R.id.manual_root);
    loading = root.findViewById(R.id.loading_spinner);
    final String[] routers = getResources().getStringArray(R.array.supported_routers);
    ArrayAdapter<String> adapter = new ArrayAdapter<>(getActivity(), android.R.layout.simple_dropdown_item_1line, routers);
    final AutoCompleteTextView edit = (AutoCompleteTextView) root.findViewById(R.id.manual_autotext);
    edit.setAdapter(adapter);
    edit.setThreshold(1);
    edit.requestFocus();
    final InputFilter filterSSID = new InputFilter() {

        public CharSequence filter(CharSequence source, int start, int end, Spanned dest, int dstart, int dend) {
            for (int i = start; i < end; i++) {
                if (!Character.isLetterOrDigit(source.charAt(i)) && source.charAt(i) != '-' && source.charAt(i) != '_' && source.charAt(i) != ' ') {
                    return "";
                }
            }
            return null;
        }
    };
    edit.setFilters(new InputFilter[] { filterSSID });
    final EditText[] macs = new EditText[6];
    root.findViewById(R.id.manual_mac_root).setVisibility(View.VISIBLE);
    edit.setImeOptions(EditorInfo.IME_ACTION_NEXT);
    macs[0] = (EditText) root.findViewById(R.id.input_mac_pair1);
    macs[1] = (EditText) root.findViewById(R.id.input_mac_pair2);
    macs[2] = (EditText) root.findViewById(R.id.input_mac_pair3);
    macs[3] = (EditText) root.findViewById(R.id.input_mac_pair4);
    macs[4] = (EditText) root.findViewById(R.id.input_mac_pair5);
    macs[5] = (EditText) root.findViewById(R.id.input_mac_pair6);
    if (macAddress != null) {
        macs[0].setText(macAddress.substring(0, 2));
        macs[1].setText(macAddress.substring(2, 4));
        macs[2].setText(macAddress.substring(4, 6));
        macs[3].setText(macAddress.substring(6, 8));
        macs[4].setText(macAddress.substring(8, 10));
        macs[5].setText(macAddress.substring(10, 12));
    }
    final InputFilter filterMac = new InputFilter() {

        public CharSequence filter(CharSequence source, int start, int end, Spanned dest, int dstart, int dend) {
            if (dstart >= 2)
                return "";
            if (source.length() > 2)
                // max 2 chars
                return "";
            for (int i = start; i < end; i++) {
                if (Character.digit(source.charAt(i), 16) == -1) {
                    return "";
                }
            }
            if (source.length() + dstart > 2)
                return source.subSequence(0, 2 - dstart);
            return null;
        }
    };
    for (final EditText mac : macs) {
        mac.setFilters(new InputFilter[] { filterMac });
        mac.addTextChangedListener(new TextWatcher() {

            public void onTextChanged(CharSequence s, int start, int before, int count) {
            }

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

            public void afterTextChanged(Editable e) {
                if (e.length() != 2)
                    return;
                for (int i = 0; i < 6; ++i) {
                    if (macs[i].getText().length() >= 2)
                        continue;
                    macs[i].requestFocus();
                    return;
                }
            }
        });
    }
    Button calc = (Button) root.findViewById(R.id.bt_calc);
    calc.setOnClickListener(new View.OnClickListener() {

        @TargetApi(Build.VERSION_CODES.HONEYCOMB)
        public void onClick(View v) {
            String ssid = edit.getText().toString().trim();
            StringBuilder mac = new StringBuilder();
            boolean warnUnused = false;
            for (EditText m : macs) {
                final String mText = m.getText().toString();
                if (mText.length() > 0)
                    warnUnused = true;
                mac.append(mText);
                if (!m.equals(macs[5]))
                    // do not add this for the
                    mac.append(":");
            // last one
            }
            if (mac.length() < 17) {
                mac.setLength(0);
                if (warnUnused)
                    Toast.makeText(getActivity(), R.string.msg_invalid_mac, Toast.LENGTH_SHORT).show();
            }
            KeygenMatcherTask matcher = new KeygenMatcherTask(ssid, mac.toString().toUpperCase(Locale.getDefault()));
            if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.GINGERBREAD_MR1) {
                matcher.execute();
            } else {
                matcher.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
            }
        }
    });
    Button cancel = (Button) root.findViewById(R.id.bt_cancel);
    cancel.setOnClickListener(new View.OnClickListener() {

        public void onClick(View v) {
            getActivity().onBackPressed();
        }
    });
    return root;
}
Also used : EditText(android.widget.EditText) InputFilter(android.text.InputFilter) View(android.view.View) AutoCompleteTextView(android.widget.AutoCompleteTextView) Spanned(android.text.Spanned) Button(android.widget.Button) TextWatcher(android.text.TextWatcher) Editable(android.text.Editable) TargetApi(android.annotation.TargetApi) ArrayAdapter(android.widget.ArrayAdapter) AutoCompleteTextView(android.widget.AutoCompleteTextView)

Example 74 with InputFilter

use of android.text.InputFilter in project SocialTokenAutoComplete by bitjjj.

the class TokenCompleteTextView method init.

private void init() {
    setTokenizer(new MultiAutoCompleteTextView.CommaTokenizer());
    objects = new ArrayList<Object>();
    Editable text = getText();
    assert null != text;
    spanWatcher = new TokenSpanWatcher();
    resetListeners();
    setTextIsSelectable(false);
    setLongClickable(false);
    // In theory, get the soft keyboard to not supply suggestions.
    setInputType(InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS | InputType.TYPE_TEXT_FLAG_AUTO_COMPLETE);
    setOnEditorActionListener(this);
    setFilters(new InputFilter[] { new InputFilter() {

        @Override
        public CharSequence filter(CharSequence source, int start, int end, Spanned dest, int dstart, int dend) {
            // Detect single commas, remove them and complete the current token instead
            if (source.length() == 1 && source.charAt(0) == SPLITOR) {
                performCompletion();
                return "";
            }
            // We need to not do anything when we would delete the prefix
            if (dstart < prefix.length() && dend == prefix.length()) {
                return prefix.substring(dstart, dend);
            }
            return null;
        }
    } });
    // We had _Parent style during initialization to handle an edge case in the parent
    // now we can switch to Clear, usually the best choice
    setDeletionStyle(TokenDeleteStyle.Clear);
    initialized = true;
}
Also used : InputFilter(android.text.InputFilter) MultiAutoCompleteTextView(android.widget.MultiAutoCompleteTextView) Editable(android.text.Editable) Spanned(android.text.Spanned) Paint(android.graphics.Paint)

Example 75 with InputFilter

use of android.text.InputFilter in project bitcoin-wallet by bitcoin-wallet.

the class SettingsFragment method onCreate.

@Override
public void onCreate(final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    addPreferencesFromResource(R.xml.preference_settings);
    backgroundThread = new HandlerThread("backgroundThread", Process.THREAD_PRIORITY_BACKGROUND);
    backgroundThread.start();
    backgroundHandler = new Handler(backgroundThread.getLooper());
    final ListPreference syncModePreference = (ListPreference) findPreference(Configuration.PREFS_KEY_SYNC_MODE);
    syncModePreference.setEntryValues(new CharSequence[] { Configuration.SyncMode.CONNECTION_FILTER.name(), Configuration.SyncMode.FULL.name() });
    syncModePreference.setEntries(new CharSequence[] { Html.fromHtml(getString(R.string.preferences_sync_mode_labels_connection_filter)), Html.fromHtml(getString(R.string.preferences_sync_mode_labels_full)) });
    if (!application.fullSyncCapable())
        removeOrDisablePreference(syncModePreference);
    trustedPeerPreference = (EditTextPreference) findPreference(Configuration.PREFS_KEY_TRUSTED_PEERS);
    trustedPeerPreference.setOnPreferenceChangeListener(this);
    trustedPeerPreference.setDialogMessage(getString(R.string.preferences_trusted_peer_dialog_message) + "\n\n" + getString(R.string.preferences_trusted_peer_dialog_message_multiple));
    trustedPeerOnlyPreference = findPreference(Configuration.PREFS_KEY_TRUSTED_PEERS_ONLY);
    trustedPeerOnlyPreference.setOnPreferenceChangeListener(this);
    final Preference enableExchangeRatesPreference = findPreference(Configuration.PREFS_KEY_ENABLE_EXCHANGE_RATES);
    if (!Constants.ENABLE_EXCHANGE_RATES)
        removeOrDisablePreference(enableExchangeRatesPreference);
    final Preference dataUsagePreference = findPreference(Configuration.PREFS_KEY_DATA_USAGE);
    dataUsagePreference.setIntent(new Intent(Settings.ACTION_IGNORE_BACKGROUND_DATA_RESTRICTIONS_SETTINGS, Uri.parse("package:" + application.getPackageName())));
    if (dataUsagePreference.getIntent() == null || pm.resolveActivity(dataUsagePreference.getIntent(), 0) == null)
        removeOrDisablePreference(dataUsagePreference);
    final Preference notificationsPreference = findPreference(Configuration.PREFS_KEY_NOTIFICATIONS);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O)
        notificationsPreference.setIntent(new Intent(Settings.ACTION_APP_NOTIFICATION_SETTINGS).putExtra(Settings.EXTRA_APP_PACKAGE, application.getPackageName()));
    if (notificationsPreference.getIntent() == null || pm.resolveActivity(notificationsPreference.getIntent(), 0) == null)
        removeOrDisablePreference(notificationsPreference);
    ownNamePreference = findPreference(Configuration.PREFS_KEY_OWN_NAME);
    ownNamePreference.setOnPreferenceChangeListener(this);
    bluetoothAddressPreference = (EditTextPreference) findPreference(Configuration.PREFS_KEY_BLUETOOTH_ADDRESS);
    bluetoothAddressPreference.setOnPreferenceChangeListener(this);
    final InputFilter.AllCaps allCaps = Build.VERSION.SDK_INT >= Build.VERSION_CODES.O_MR1 ? new InputFilter.AllCaps(Locale.US) : new InputFilter.AllCaps();
    final InputFilter.LengthFilter maxLength = new InputFilter.LengthFilter(BLUETOOTH_ADDRESS_LENGTH);
    final RestrictToHex hex = new RestrictToHex();
    bluetoothAddressPreference.getEditText().setFilters(new InputFilter[] { maxLength, allCaps, hex });
    bluetoothAddressPreference.getEditText().addTextChangedListener(colonFormat);
    updateTrustedPeer();
    updateOwnName();
    updateBluetoothAddress();
}
Also used : InputFilter(android.text.InputFilter) HandlerThread(android.os.HandlerThread) EditTextPreference(android.preference.EditTextPreference) ListPreference(android.preference.ListPreference) Preference(android.preference.Preference) Handler(android.os.Handler) Intent(android.content.Intent) ListPreference(android.preference.ListPreference)

Aggregations

InputFilter (android.text.InputFilter)93 EditText (android.widget.EditText)33 View (android.view.View)31 TextView (android.widget.TextView)31 DialogInterface (android.content.DialogInterface)19 AlertDialog (android.app.AlertDialog)17 Editable (android.text.Editable)14 Paint (android.graphics.Paint)12 Bundle (android.os.Bundle)11 TextWatcher (android.text.TextWatcher)11 LinearLayout (android.widget.LinearLayout)11 Spanned (android.text.Spanned)10 TextPaint (android.text.TextPaint)10 ImageView (android.widget.ImageView)9 SpannableStringBuilder (android.text.SpannableStringBuilder)8 Intent (android.content.Intent)7 Nullable (android.support.annotation.Nullable)7 SmallTest (android.test.suitebuilder.annotation.SmallTest)7 Button (android.widget.Button)7 Context (android.content.Context)6