Search in sources :

Example 41 with InputFilter

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

the class StringWidgetUtils method adjustEditTextAnswerToIntegerWidget.

public static void adjustEditTextAnswerToIntegerWidget(EditText answerText, FormEntryPrompt prompt) {
    boolean useThousandSeparator = Appearances.useThousandSeparator(prompt);
    if (Appearances.useThousandSeparator(prompt)) {
        answerText.addTextChangedListener(new ThousandsSeparatorTextWatcher(answerText));
    }
    answerText.setInputType(InputType.TYPE_NUMBER_FLAG_SIGNED);
    // only allows numbers and no periods
    answerText.setKeyListener(new DigitsKeyListener(true, false));
    // ints can only hold 2,147,483,648. we allow 999,999,999
    InputFilter[] fa = new InputFilter[1];
    fa[0] = new InputFilter.LengthFilter(9);
    if (useThousandSeparator) {
        // 11 since for a nine digit number , their will be 2 separators.
        fa[0] = new InputFilter.LengthFilter(11);
    }
    answerText.setFilters(fa);
    Integer i = getIntegerAnswerValueFromIAnswerData(prompt.getAnswerValue());
    if (i != null) {
        answerText.setText(String.format(Locale.US, "%d", i));
        Selection.setSelection(answerText.getText(), answerText.getText().toString().length());
    }
}
Also used : InputFilter(android.text.InputFilter) DigitsKeyListener(android.text.method.DigitsKeyListener) ThousandsSeparatorTextWatcher(org.odk.collect.android.listeners.ThousandsSeparatorTextWatcher)

Example 42 with InputFilter

use of android.text.InputFilter in project AnimeTaste by daimajia.

the class PlayActivity method comment.

public void comment() {
    MobclickAgent.onEvent(mContext, "comment");
    if (mUser.isLogin() == false) {
        new AlertDialog.Builder(this).setTitle(R.string.choose_login).setItems(new String[] { getString(R.string.weibo), getString(R.string.qq) }, new DialogInterface.OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which) {
                switch(which) {
                    case 0:
                        new SocialPlatform(mContext).auth(SinaWeibo.NAME, mAuthHandler);
                        break;
                    case 1:
                        new SocialPlatform(mContext).auth(QZone.NAME, mAuthHandler);
                        break;
                    default:
                        break;
                }
            }
        }).setNegativeButton(R.string.cancel_login, null).show();
    } else {
        final EditText editText = new EditText(mContext);
        editText.setHeight(mContext.getResources().getDimensionPixelSize(R.dimen.comment_edit_height));
        editText.setFilters(new InputFilter[] { new InputFilter.LengthFilter(250) });
        editText.setGravity(Gravity.LEFT | Gravity.TOP);
        AlertDialog.Builder commentDialog = new AlertDialog.Builder(mContext).setTitle(R.string.publish_comment).setView(editText).setNegativeButton(R.string.cancel_publish, null).setPositiveButton(R.string.publish, null);
        final AlertDialog dialog = commentDialog.create();
        dialog.show();
        dialog.getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                final String content = editText.getText().toString();
                if (content.length() == 0) {
                    Toast.makeText(mContext, R.string.comment_nothing, Toast.LENGTH_SHORT).show();
                } else if (content.length() < 5) {
                    Toast.makeText(mContext, R.string.comment_too_short, Toast.LENGTH_SHORT).show();
                } else {
                    new CommentThread(content).start();
                    dialog.dismiss();
                }
            }
        });
    }
}
Also used : EditText(android.widget.EditText) AlertDialog(android.app.AlertDialog) SocialPlatform(com.zhan_dui.auth.SocialPlatform) InputFilter(android.text.InputFilter) DialogInterface(android.content.DialogInterface) ImageView(android.widget.ImageView) GifMovieView(com.basv.gifmoviewview.widget.GifMovieView) View(android.view.View) TextView(android.widget.TextView) BVideoView(com.baidu.cyberplayer.core.BVideoView) SuppressLint(android.annotation.SuppressLint) OnClickListener(android.view.View.OnClickListener)

Example 43 with InputFilter

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

the class TextView method onInitializeAccessibilityNodeInfoInternal.

/** @hide */
@Override
public void onInitializeAccessibilityNodeInfoInternal(AccessibilityNodeInfo info) {
    super.onInitializeAccessibilityNodeInfoInternal(info);
    final boolean isPassword = hasPasswordTransformationMethod();
    info.setPassword(isPassword);
    info.setText(getTextForAccessibility());
    if (mBufferType == BufferType.EDITABLE) {
        info.setEditable(true);
        if (isEnabled()) {
            info.addAction(AccessibilityNodeInfo.AccessibilityAction.ACTION_SET_TEXT);
        }
    }
    if (mEditor != null) {
        info.setInputType(mEditor.mInputType);
        if (mEditor.mError != null) {
            info.setContentInvalid(true);
            info.setError(mEditor.mError);
        }
    }
    if (!TextUtils.isEmpty(mText)) {
        info.addAction(AccessibilityNodeInfo.ACTION_NEXT_AT_MOVEMENT_GRANULARITY);
        info.addAction(AccessibilityNodeInfo.ACTION_PREVIOUS_AT_MOVEMENT_GRANULARITY);
        info.setMovementGranularities(AccessibilityNodeInfo.MOVEMENT_GRANULARITY_CHARACTER | AccessibilityNodeInfo.MOVEMENT_GRANULARITY_WORD | AccessibilityNodeInfo.MOVEMENT_GRANULARITY_LINE | AccessibilityNodeInfo.MOVEMENT_GRANULARITY_PARAGRAPH | AccessibilityNodeInfo.MOVEMENT_GRANULARITY_PAGE);
        info.addAction(AccessibilityNodeInfo.ACTION_SET_SELECTION);
    }
    if (isFocused()) {
        if (canCopy()) {
            info.addAction(AccessibilityNodeInfo.ACTION_COPY);
        }
        if (canPaste()) {
            info.addAction(AccessibilityNodeInfo.ACTION_PASTE);
        }
        if (canCut()) {
            info.addAction(AccessibilityNodeInfo.ACTION_CUT);
        }
        if (canShare()) {
            info.addAction(new AccessibilityNodeInfo.AccessibilityAction(ACCESSIBILITY_ACTION_SHARE, getResources().getString(com.android.internal.R.string.share)));
        }
        if (canProcessText()) {
            // also implies mEditor is not null.
            mEditor.mProcessTextIntentActionsHandler.onInitializeAccessibilityNodeInfo(info);
        }
    }
    // Check for known input filter types.
    final int numFilters = mFilters.length;
    for (int i = 0; i < numFilters; i++) {
        final InputFilter filter = mFilters[i];
        if (filter instanceof InputFilter.LengthFilter) {
            info.setMaxTextLength(((InputFilter.LengthFilter) filter).getMax());
        }
    }
    if (!isSingleLine()) {
        info.setMultiLine(true);
    }
}
Also used : InputFilter(android.text.InputFilter) AccessibilityNodeInfo(android.view.accessibility.AccessibilityNodeInfo) TextPaint(android.text.TextPaint) Paint(android.graphics.Paint)

Example 44 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 45 with InputFilter

use of android.text.InputFilter in project android_frameworks_base by AOSPA.

the class TextView method setFilters.

/**
     * Sets the list of input filters on the specified Editable,
     * and includes mInput in the list if it is an InputFilter.
     */
private void setFilters(Editable e, InputFilter[] filters) {
    if (mEditor != null) {
        final boolean undoFilter = mEditor.mUndoInputFilter != null;
        final boolean keyFilter = mEditor.mKeyListener instanceof InputFilter;
        int num = 0;
        if (undoFilter)
            num++;
        if (keyFilter)
            num++;
        if (num > 0) {
            InputFilter[] nf = new InputFilter[filters.length + num];
            System.arraycopy(filters, 0, nf, 0, filters.length);
            num = 0;
            if (undoFilter) {
                nf[filters.length] = mEditor.mUndoInputFilter;
                num++;
            }
            if (keyFilter) {
                nf[filters.length + num] = (InputFilter) mEditor.mKeyListener;
            }
            e.setFilters(nf);
            return;
        }
    }
    e.setFilters(filters);
}
Also used : InputFilter(android.text.InputFilter) TextPaint(android.text.TextPaint) Paint(android.graphics.Paint)

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