Search in sources :

Example 76 with InputFilter

use of android.text.InputFilter in project AndroidChromium by JackyAndroid.

the class EditorView method addFieldViewToEditor.

private View addFieldViewToEditor(ViewGroup parent, final EditorFieldModel fieldModel) {
    View childView = null;
    if (fieldModel.getInputTypeHint() == EditorFieldModel.INPUT_TYPE_HINT_ICONS) {
        childView = new EditorIconsField(mContext, parent, fieldModel).getLayout();
    } else if (fieldModel.getInputTypeHint() == EditorFieldModel.INPUT_TYPE_HINT_LABEL) {
        childView = new EditorLabelField(mContext, parent, fieldModel).getLayout();
    } else if (fieldModel.getInputTypeHint() == EditorFieldModel.INPUT_TYPE_HINT_DROPDOWN) {
        Runnable prepareEditorRunnable = new Runnable() {

            @Override
            public void run() {
                // The fields may have changed.
                prepareEditor();
                if (mObserverForTest != null)
                    mObserverForTest.onPaymentRequestReadyToEdit();
            }
        };
        EditorDropdownField dropdownView = new EditorDropdownField(mContext, parent, fieldModel, prepareEditorRunnable);
        mFieldViews.add(dropdownView);
        mDropdownFields.add(dropdownView.getDropdown());
        childView = dropdownView.getLayout();
    } else if (fieldModel.getInputTypeHint() == EditorFieldModel.INPUT_TYPE_HINT_CHECKBOX) {
        final CheckBox checkbox = new CheckBox(mLayout.getContext());
        checkbox.setId(R.id.payments_edit_checkbox);
        checkbox.setText(fieldModel.getLabel());
        checkbox.setChecked(fieldModel.isChecked());
        checkbox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                fieldModel.setIsChecked(isChecked);
                if (mObserverForTest != null)
                    mObserverForTest.onPaymentRequestReadyToEdit();
            }
        });
        childView = checkbox;
    } else {
        InputFilter filter = null;
        TextWatcher formatter = null;
        if (fieldModel.getInputTypeHint() == EditorFieldModel.INPUT_TYPE_HINT_CREDIT_CARD) {
            filter = mCardNumberInputFilter;
            formatter = mCardNumberFormatter;
        } else if (fieldModel.getInputTypeHint() == EditorFieldModel.INPUT_TYPE_HINT_PHONE) {
            formatter = mPhoneFormatter;
        }
        EditorTextField inputLayout = new EditorTextField(mContext, fieldModel, mEditorActionListener, filter, formatter, mObserverForTest);
        mFieldViews.add(inputLayout);
        EditText input = inputLayout.getEditText();
        mEditableTextFields.add(input);
        if (fieldModel.getInputTypeHint() == EditorFieldModel.INPUT_TYPE_HINT_CREDIT_CARD) {
            assert mCardInput == null;
            mCardInput = input;
        } else if (fieldModel.getInputTypeHint() == EditorFieldModel.INPUT_TYPE_HINT_PHONE) {
            assert mPhoneInput == null;
            mPhoneInput = input;
        }
        childView = inputLayout;
    }
    parent.addView(childView);
    return childView;
}
Also used : EditText(android.widget.EditText) InputFilter(android.text.InputFilter) CheckBox(android.widget.CheckBox) PhoneNumberFormattingTextWatcher(android.telephony.PhoneNumberFormattingTextWatcher) CreditCardNumberFormattingTextWatcher(org.chromium.chrome.browser.preferences.autofill.CreditCardNumberFormattingTextWatcher) TextWatcher(android.text.TextWatcher) View(android.view.View) FadingShadowView(org.chromium.chrome.browser.widget.FadingShadowView) TextView(android.widget.TextView) CompoundButton(android.widget.CompoundButton)

Example 77 with InputFilter

use of android.text.InputFilter in project hypertrack-live-android by hypertrack.

the class Verify method initView.

private void initView() {
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    toolbar.setNavigationIcon(R.drawable.ic_arrow_back_white_24dp);
    otpEditText = (EditText) findViewById(R.id.otp_edit_text);
    verifyOTP = (Button) findViewById(R.id.verify_otp);
    progressBar = (ProgressBar) findViewById(R.id.progress_bar);
    timerText = (TextView) findViewById(R.id.timer);
    verifyOTP.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            if (HTTextUtils.isEmpty(otpEditText.getText().toString())) {
                Toast.makeText(Verify.this, "Please enter OTP", Toast.LENGTH_SHORT).show();
                return;
            }
            showProgress(true);
            presenter.verifyOTP(otpEditText.getText().toString(), Verify.this);
        }
    });
    timerText.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            if (timerText.isClickable()) {
                presenter.resendOTP(Verify.this);
                showProgress(true);
            }
        }
    });
    otpEditText.setFilters(new InputFilter[] { new InputFilter.LengthFilter(4) });
    otpEditText.requestFocus();
    otpEditText.addTextChangedListener(new TextWatcher() {

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

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

        @Override
        public void afterTextChanged(Editable s) {
            if (!HTTextUtils.isEmpty(otpEditText.getText().toString())) {
                if (otpEditText.getText().length() == 4) {
                    showProgress(true);
                    presenter.verifyOTP(otpEditText.getText().toString(), Verify.this);
                    verifyOTP.setText("Verifying...");
                } else {
                    verifyOTP.setText("Verify");
                }
            } else {
                verifyOTP.setText("Verify");
            }
        }
    });
    Utils.showKeyboard(this, otpEditText);
}
Also used : InputFilter(android.text.InputFilter) TextWatcher(android.text.TextWatcher) Editable(android.text.Editable) View(android.view.View) TextView(android.widget.TextView) Toolbar(android.support.v7.widget.Toolbar)

Example 78 with InputFilter

use of android.text.InputFilter in project android_packages_apps_Settings by SudaMod.

the class Utf8ByteLengthFilterTest method testFilter.

@SmallTest
public void testFilter() {
    // Define the variables
    CharSequence source;
    SpannableStringBuilder dest;
    // Constructor to create a LengthFilter
    InputFilter lengthFilter = new Utf8ByteLengthFilter(10);
    InputFilter[] filters = { lengthFilter };
    // filter() implicitly invoked. If the total length > filter length, the filter will
    // cut off the source CharSequence from beginning to fit the filter length.
    source = "abc";
    dest = new SpannableStringBuilder("abcdefgh");
    dest.setFilters(filters);
    dest.insert(1, source);
    String expectedString1 = "aabbcdefgh";
    assertEquals(expectedString1, dest.toString());
    dest.replace(5, 8, source);
    String expectedString2 = "aabbcabcgh";
    assertEquals(expectedString2, dest.toString());
    dest.insert(2, source);
    assertEquals(expectedString2, dest.toString());
    dest.delete(1, 3);
    String expectedString3 = "abcabcgh";
    assertEquals(expectedString3, dest.toString());
    dest.append("12345");
    String expectedString4 = "abcabcgh12";
    assertEquals(expectedString4, dest.toString());
    // 2 Chinese chars == 6 bytes in UTF-8
    source = "\u60a8\u597d";
    dest.replace(8, 10, source);
    assertEquals(expectedString3, dest.toString());
    dest.replace(0, 1, source);
    String expectedString5 = "\u60a8bcabcgh";
    assertEquals(expectedString5, dest.toString());
    dest.replace(0, 4, source);
    String expectedString6 = "\u60a8\u597dbcgh";
    assertEquals(expectedString6, dest.toString());
    // 2 Latin-1 chars == 4 bytes in UTF-8
    source = "\u00a3\u00a5";
    dest.delete(2, 6);
    dest.insert(0, source);
    String expectedString7 = "\u00a3\u00a5\u60a8\u597d";
    assertEquals(expectedString7, dest.toString());
    dest.replace(2, 3, source);
    String expectedString8 = "\u00a3\u00a5\u00a3\u597d";
    assertEquals(expectedString8, dest.toString());
    dest.replace(3, 4, source);
    String expectedString9 = "\u00a3\u00a5\u00a3\u00a3\u00a5";
    assertEquals(expectedString9, dest.toString());
    // filter() explicitly invoked
    dest = new SpannableStringBuilder("abcdefgh");
    CharSequence beforeFilterSource = "TestLengthFilter";
    String expectedAfterFilter = "TestLength";
    CharSequence actualAfterFilter = lengthFilter.filter(beforeFilterSource, 0, beforeFilterSource.length(), dest, 0, dest.length());
    assertEquals(expectedAfterFilter, actualAfterFilter);
}
Also used : Utf8ByteLengthFilter(com.android.settings.bluetooth.Utf8ByteLengthFilter) InputFilter(android.text.InputFilter) SpannableStringBuilder(android.text.SpannableStringBuilder) SmallTest(android.test.suitebuilder.annotation.SmallTest)

Example 79 with InputFilter

use of android.text.InputFilter in project malp by gateship-one.

the class EditProfileFragment method onCreateView.

@Override
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    // Inflate the layout for this fragment
    View rootView = inflater.inflate(R.layout.fragment_edit_profile, container, false);
    mProfilenameView = rootView.findViewById(R.id.fragment_profile_profilename);
    mHostnameView = rootView.findViewById(R.id.fragment_profile_hostname);
    mPasswordView = rootView.findViewById(R.id.fragment_profile_password);
    mPortView = rootView.findViewById(R.id.fragment_profile_port);
    mStreamingURLView = rootView.findViewById(R.id.fragment_profile_streaming_url);
    mStreamingEnabledView = rootView.findViewById(R.id.fragment_profile_streaming_enabled);
    mHTTPCoverRegexView = rootView.findViewById(R.id.fragment_profile_cover_regex);
    mHTTPCoverEnabledView = rootView.findViewById(R.id.fragment_profile_http_covers_enabled);
    // Set to maximum tcp port
    InputFilter portFilter = new PortNumberFilter();
    mPortView.setFilters(new InputFilter[] { portFilter });
    /* Check if an artistname/albumame was given in the extras */
    Bundle args = getArguments();
    if (null != args) {
        mOldProfile = args.getParcelable(EXTRA_PROFILE);
        if (mOldProfile != null) {
            mProfilename = mOldProfile.getProfileName();
            mHostname = mOldProfile.getHostname();
            mPassword = mOldProfile.getPassword();
            mPort = mOldProfile.getPort();
            mStreamingURL = mOldProfile.getStreamingURL();
            mStreamingEnabled = mOldProfile.getStreamingEnabled();
            mHTTPCoverRegex = mOldProfile.getHTTPRegex();
            mHTTPCoverEnabled = mOldProfile.getHTTPCoverEnabled();
            mProfilenameView.setText(mProfilename);
        } else {
            mHostname = "";
            mProfilename = "";
            mPassword = "";
            mPort = 6600;
            mStreamingEnabled = false;
            mStreamingURL = "";
            mHTTPCoverEnabled = false;
            mHTTPCoverRegex = "";
            mProfilenameView.setText(getString(R.string.fragment_profile_default_name));
        }
    }
    mHostnameView.setText(mHostname);
    mPasswordView.setText(mPassword);
    mPortView.setText(String.valueOf(mPort));
    // Show/Hide streaming url view depending on state
    mStreamingEnabledView.setChecked(mStreamingEnabled);
    mStreamingEnabledView.setOnCheckedChangeListener((buttonView, isChecked) -> {
        if (isChecked) {
            if (mStreamingURLView.getText().toString().isEmpty()) {
                // Check if a text was already set otherwise show an example
                mStreamingURL = "http://" + mHostnameView.getText().toString() + ":8080";
                mStreamingURLView.setText(mStreamingURL);
            }
            mStreamingURLView.setVisibility(View.VISIBLE);
        } else {
            mStreamingURLView.setVisibility(View.GONE);
        }
    });
    if (!mStreamingEnabled) {
        mStreamingURLView.setVisibility(View.GONE);
    }
    mStreamingURLView.setText(mStreamingURL);
    // Show/Hide HTTP cover regex view depending on state
    mHTTPCoverEnabledView.setChecked(mHTTPCoverEnabled);
    mHTTPCoverEnabledView.setOnCheckedChangeListener((buttonView, isChecked) -> {
        if (isChecked) {
            mHTTPCoverRegexView.setText(mHTTPCoverRegex);
            mHTTPCoverRegexView.setVisibility(View.VISIBLE);
        } else {
            mHTTPCoverRegexView.setVisibility(View.GONE);
        }
    });
    if (!mHTTPCoverEnabled) {
        mHTTPCoverRegexView.setVisibility(View.GONE);
    }
    mHTTPCoverRegexView.setText(mHTTPCoverRegex);
    mProfilenameView.setSelectAllOnFocus(true);
    setHasOptionsMenu(true);
    // Return the ready inflated and configured fragment view.
    return rootView;
}
Also used : InputFilter(android.text.InputFilter) Bundle(android.os.Bundle) View(android.view.View)

Example 80 with InputFilter

use of android.text.InputFilter in project SightRemote by TebbeUbben.

the class EditBRProfileActivity method onOptionsItemSelected.

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    if (item.getItemId() == android.R.id.home) {
        finish();
        return true;
    } else if (item.getItemId() == R.id.edit_br_nav_done) {
        (confirmationDialog = new ConfirmationDialog(this, HTMLUtil.getHTML(R.string.edit_br_profile_confirmation), () -> {
            showManualOverlay();
            List<ConfigurationBlock> blocks = new ArrayList<>();
            blocks.add(nameBlock);
            profileBlock.setProfileBlocks(FixedSizeProfileBlock.convertToRelative(profileBlocks));
            blocks.add(profileBlock);
            WriteConfigurationTaskRunner taskRunner = new WriteConfigurationTaskRunner(getServiceConnector(), blocks);
            showLoadingIndicator();
            taskRunner.fetch(this);
        })).show();
    } else if (item.getItemId() == R.id.edit_br_nav_edit_name) {
        EditText editName = new EditText(this);
        editName.setInputType(InputType.TYPE_CLASS_TEXT);
        editName.setFilters(new InputFilter[] { new InputFilter.LengthFilter(21) });
        editName.setText(nameBlock.getName());
        AlertDialog alertDialog = new AlertDialog.Builder(this).setTitle(R.string.edit_name).setMessage(R.string.leave_empty_for_default_value).setView(editName).setPositiveButton(R.string.okay, ((dialog, which) -> {
            nameBlock.setName(editName.getText().toString());
            adjustTitle();
        })).setNegativeButton(R.string.cancel, null).create();
        alertDialog.show();
    }
    return super.onOptionsItemSelected(item);
}
Also used : EditText(android.widget.EditText) AlertDialog(android.support.v7.app.AlertDialog) Bundle(android.os.Bundle) ConfigurationBlock(sugar.free.sightparser.applayer.descriptors.configuration_blocks.ConfigurationBlock) TaskRunner(sugar.free.sightparser.handling.TaskRunner) BRProfile4Block(sugar.free.sightparser.applayer.descriptors.configuration_blocks.BRProfile4Block) EditBRBlockDialog(sugar.free.sightremote.utils.EditBRBlockDialog) SerializationUtils(sugar.free.sightparser.SerializationUtils) BRProfile2Block(sugar.free.sightparser.applayer.descriptors.configuration_blocks.BRProfile2Block) MenuItem(android.view.MenuItem) ArrayList(java.util.ArrayList) BRProfileAdapter(sugar.free.sightremote.adapters.BRProfileAdapter) MaxBRAmountBlock(sugar.free.sightparser.applayer.descriptors.configuration_blocks.MaxBRAmountBlock) MenuInflater(android.view.MenuInflater) Toast(android.widget.Toast) Menu(android.view.Menu) BRProfileBlockAdapter(sugar.free.sightremote.adapters.BRProfileBlockAdapter) Status(sugar.free.sightparser.pipeline.Status) BRProfile3Block(sugar.free.sightparser.applayer.descriptors.configuration_blocks.BRProfile3Block) FixedSizeProfileBlock(sugar.free.sightremote.utils.FixedSizeProfileBlock) FactoryMinBRAmountBlock(sugar.free.sightparser.applayer.descriptors.configuration_blocks.FactoryMinBRAmountBlock) InputType(android.text.InputType) HTMLUtil(sugar.free.sightremote.utils.HTMLUtil) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) NameBlock(sugar.free.sightparser.applayer.descriptors.configuration_blocks.NameBlock) CustomEvent(com.crashlytics.android.answers.CustomEvent) RecyclerView(android.support.v7.widget.RecyclerView) BRProfileBlock(sugar.free.sightparser.applayer.descriptors.configuration_blocks.BRProfileBlock) List(java.util.List) R(sugar.free.sightremote.R) AlertDialog(android.support.v7.app.AlertDialog) ReadConfigurationTaskRunner(sugar.free.sightparser.handling.taskrunners.ReadConfigurationTaskRunner) BRProfile5Block(sugar.free.sightparser.applayer.descriptors.configuration_blocks.BRProfile5Block) BRProfile1Block(sugar.free.sightparser.applayer.descriptors.configuration_blocks.BRProfile1Block) Answers(com.crashlytics.android.answers.Answers) Nullable(android.support.annotation.Nullable) InputFilter(android.text.InputFilter) EditText(android.widget.EditText) WriteConfigurationTaskRunner(sugar.free.sightparser.handling.taskrunners.WriteConfigurationTaskRunner) ConfirmationDialog(sugar.free.sightremote.dialogs.ConfirmationDialog) ConfigurationBlock(sugar.free.sightparser.applayer.descriptors.configuration_blocks.ConfigurationBlock) InputFilter(android.text.InputFilter) ArrayList(java.util.ArrayList) WriteConfigurationTaskRunner(sugar.free.sightparser.handling.taskrunners.WriteConfigurationTaskRunner) ConfirmationDialog(sugar.free.sightremote.dialogs.ConfirmationDialog)

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