Java Code Examples for android.text.TextUtils.copySpansFrom()

The following are Jave code examples for showing how to use copySpansFrom() of the android.text.TextUtils class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: PeSanKita-android   File: RecipientsEditor.java   View Source Code Vote up 6 votes
/**
 * Returns <code>text</code>, modified, if necessary, to ensure that
 * it ends with a token terminator (for example a space or comma).
 * It is a method from the MultiAutoCompleteTextView.Tokenizer interface.
 */
public CharSequence terminateToken(CharSequence text) {
    int i = text.length();

    while (i > 0 && text.charAt(i - 1) == ' ') {
        i--;
    }

    char c;
    if (i > 0 && ((c = text.charAt(i - 1)) == ',' || c == ';')) {
        return text;
    } else {
        // Use the same delimiter the user just typed.
        // This lets them have a mixture of commas and semicolons in their list.
        String separator = mLastSeparator + " ";
        if (text instanceof Spanned) {
            SpannableString sp = new SpannableString(text + separator);
            TextUtils.copySpansFrom((Spanned) text, 0, text.length(),
                                    Object.class, sp, 0);
            return sp;
        } else {
            return text + separator;
        }
    }
}
 
Example 2
Project: orgzly-android   File: SpaceTokenizer.java   View Source Code Vote up 6 votes
@Override
public CharSequence terminateToken(CharSequence text) {
    int i = text.length();

    while (i > 0 && text.charAt(i - 1) == ' ') {
        i--;
    }

    if (i > 0 && text.charAt(i - 1) == ' ') {
        return text;
    } else {
        if (text instanceof Spanned) {
            SpannableString sp = new SpannableString(text + " ");
            TextUtils.copySpansFrom((Spanned) text, 0, text.length(),
                    Object.class, sp, 0);
            return sp;
        } else {
            return text + " ";
        }
    }
}
 
Example 3
Project: EosCommander   File: WhitSpaceTokenizer.java   View Source Code Vote up 6 votes
@Override
public CharSequence terminateToken(CharSequence text) {
    int i = text.length();

    while (i > 0 && Character.isWhitespace(text.charAt(i - 1)) ) {
        i--;
    }

    if (i > 0 && Character.isWhitespace(text.charAt(i - 1)) ) {
        return text;
    } else {
        if (text instanceof Spanned) {
            SpannableString sp = new SpannableString(text + " ");
            TextUtils.copySpansFrom((Spanned) text, 0, text.length(),
                    Object.class, sp, 0);
            return sp;
        } else {
            return text + " ";
        }
    }
}
 
Example 4
Project: robird-reborn   File: UsernameCompleteAdapter.java   View Source Code Vote up 6 votes
public CharSequence terminateToken(CharSequence text) {
    int i = text.length();

    while (i > 0 && text.charAt(i - 1) == ' ') {
        i--;
    }

    if (i > 0 && text.charAt(i - 1) == ' ') {
        return text;
    } else {
        if (text instanceof Spanned) {
            SpannableString sp = new SpannableString(text + " ");
            TextUtils.copySpansFrom((Spanned) text, 0, text.length(),
                    Object.class, sp, 0);
            return sp;
        } else {
            return text + " ";
        }
    }
}
 
Example 5
Project: Ghost-Android   File: ChipsEditText.java   View Source Code Vote up 6 votes
public CharSequence terminateToken(CharSequence text) {
    int i = text.length();
    int lastNonSpaceIdx = i-1;
    while (lastNonSpaceIdx >= 0 && text.charAt(lastNonSpaceIdx) == ' ') {
        --lastNonSpaceIdx;
    }
    if (lastNonSpaceIdx >= 0 && text.charAt(lastNonSpaceIdx-1) == ',') {
        return text;
    } else if (text instanceof Spanned) {
        SpannableString sp = new SpannableString(text + ",");
        TextUtils.copySpansFrom((Spanned) text, 0, text.length(), Object.class, sp, 0);
        return sp;
    } else {
        return text + ",";
    }
}
 
Example 6
Project: Cable-Android   File: RecipientsEditor.java   View Source Code Vote up 6 votes
/**
 * Returns <code>text</code>, modified, if necessary, to ensure that
 * it ends with a token terminator (for example a space or comma).
 * It is a method from the MultiAutoCompleteTextView.Tokenizer interface.
 */
public CharSequence terminateToken(CharSequence text) {
    int i = text.length();

    while (i > 0 && text.charAt(i - 1) == ' ') {
        i--;
    }

    char c;
    if (i > 0 && ((c = text.charAt(i - 1)) == ',' || c == ';')) {
        return text;
    } else {
        // Use the same delimiter the user just typed.
        // This lets them have a mixture of commas and semicolons in their list.
        String separator = mLastSeparator + " ";
        if (text instanceof Spanned) {
            SpannableString sp = new SpannableString(text + separator);
            TextUtils.copySpansFrom((Spanned) text, 0, text.length(),
                                    Object.class, sp, 0);
            return sp;
        } else {
            return text + separator;
        }
    }
}
 
Example 7
Project: Tusky   File: MentionTokenizer.java   View Source Code Vote up 6 votes
@Override
public CharSequence terminateToken(CharSequence text) {
    int i = text.length();
    while (i > 0 && text.charAt(i - 1) == ' ') {
        i--;
    }
    if (i > 0 && text.charAt(i - 1) == ' ') {
        return text;
    } else if (text instanceof Spanned) {
        SpannableString s = new SpannableString(text + " ");
        TextUtils.copySpansFrom((Spanned) text, 0, text.length(), Object.class, s, 0);
        return s;
    } else {
        return text + " ";
    }
}
 
Example 8
Project: stynico   File: ChatActivity.java   View Source Code Vote up 5 votes
public  InputFilter getInputFilterProhibitEmoji()
 {
     InputFilter filter = new InputFilter() {
         @Override
         public CharSequence filter(CharSequence source, int start, int end,
                                    Spanned dest, int dstart, int dend)
{
             StringBuffer buffer = new StringBuffer();
             for (int i = start; i < end; i++)
	{
                 char codePoint = source.charAt(i);
                 if (!getIsEmoji(codePoint))
		{
                     buffer.append(codePoint);
                 }
		else
		{
			//  ToastUtil.show("群组昵称不能含有第三方表情");
                     i++;
                     continue;
                 }
             }
             if (source instanceof Spanned)
	{
                 SpannableString sp = new SpannableString(buffer);
                 TextUtils.copySpansFrom((Spanned) source, start, end, null,
								sp, 0);
                 return sp;
             }
	else
	{
                 return buffer;
             }
         }
     };
     return filter;
 }
 
Example 9
Project: PeSanKita-android   File: EmojiFilter.java   View Source Code Vote up 5 votes
@Override
public CharSequence filter(CharSequence source, int start, int end, Spanned dest, int dstart, int dend)
{
  char[] v = new char[end - start];
  TextUtils.getChars(source, start, end, v, 0);

  Spannable emojified = EmojiProvider.getInstance(view.getContext()).emojify(new String(v), view);

  if (source instanceof Spanned && emojified != null) {
    TextUtils.copySpansFrom((Spanned) source, start, end, null, emojified, 0);
  }

  return emojified;
}
 
Example 10
Project: Nird2   File: EmojiFilter.java   View Source Code Vote up 5 votes
@Nullable
@Override
public CharSequence filter(CharSequence source, int start, int end,
		Spanned dest, int dstart, int dend) {

	char[] v = new char[end - start];
	TextUtils.getChars(source, start, end, v, 0);
	Spannable emojified = EmojiProvider.getInstance(view.getContext())
			.emojify(new String(v), view);
	if (source instanceof Spanned && emojified != null) {
		TextUtils.copySpansFrom((Spanned) source, start, end, null,
				emojified, 0);
	}
	return emojified;
}
 
Example 11
Project: Nird2   File: EmojiFilter.java   View Source Code Vote up 5 votes
@Nullable
@Override
public CharSequence filter(CharSequence source, int start, int end,
		Spanned dest, int dstart, int dend) {

	char[] v = new char[end - start];
	TextUtils.getChars(source, start, end, v, 0);
	Spannable emojified = EmojiProvider.getInstance(view.getContext())
			.emojify(new String(v), view);
	if (source instanceof Spanned && emojified != null) {
		TextUtils.copySpansFrom((Spanned) source, start, end, null,
				emojified, 0);
	}
	return emojified;
}
 
Example 12
Project: Cable-Android   File: EmojiFilter.java   View Source Code Vote up 5 votes
@Override
public CharSequence filter(CharSequence source, int start, int end, Spanned dest, int dstart, int dend)
{
  char[] v = new char[end - start];
  TextUtils.getChars(source, start, end, v, 0);

  Spannable emojified = EmojiProvider.getInstance(view.getContext()).emojify(new String(v), view);

  if (source instanceof Spanned && emojified != null) {
    TextUtils.copySpansFrom((Spanned) source, start, end, null, emojified, 0);
  }

  return emojified;
}
 
Example 13
Project: chromium-for-android-56-debug-video   File: BluetoothChooserDialog.java   View Source Code Vote up 4 votes
/**
 * Show the BluetoothChooserDialog.
 */
@VisibleForTesting
void show() {
    // Emphasize the origin.
    Profile profile = Profile.getLastUsedProfile();
    SpannableString origin = new SpannableString(mOrigin);
    OmniboxUrlEmphasizer.emphasizeUrl(
            origin, mActivity.getResources(), profile, mSecurityLevel, false, true, true);
    // Construct a full string and replace the origin text with emphasized version.
    SpannableString title =
            new SpannableString(mActivity.getString(R.string.bluetooth_dialog_title, mOrigin));
    int start = title.toString().indexOf(mOrigin);
    TextUtils.copySpansFrom(origin, 0, origin.length(), Object.class, title, start);

    String noneFound = mActivity.getString(R.string.bluetooth_not_found);

    SpannableString searching = SpanApplier.applySpans(
            mActivity.getString(R.string.bluetooth_searching),
            new SpanInfo("<link>", "</link>",
                    new BluetoothClickableSpan(LinkType.EXPLAIN_BLUETOOTH, mActivity)));

    String positiveButton = mActivity.getString(R.string.bluetooth_confirm_button);

    SpannableString statusIdleNoneFound = SpanApplier.applySpans(
            mActivity.getString(R.string.bluetooth_not_seeing_it_idle_none_found),
            new SpanInfo("<link1>", "</link1>",
                    new BluetoothClickableSpan(LinkType.EXPLAIN_BLUETOOTH, mActivity)),
            new SpanInfo("<link2>", "</link2>",
                    new BluetoothClickableSpan(LinkType.RESTART_SEARCH, mActivity)));

    SpannableString statusActive = SpanApplier.applySpans(
            mActivity.getString(R.string.bluetooth_not_seeing_it),
            new SpanInfo("<link>", "</link>",
                    new BluetoothClickableSpan(LinkType.EXPLAIN_BLUETOOTH, mActivity)));

    SpannableString statusIdleSomeFound = SpanApplier.applySpans(
            mActivity.getString(R.string.bluetooth_not_seeing_it_idle_some_found),
            new SpanInfo("<link1>", "</link1>",
                    new BluetoothClickableSpan(LinkType.EXPLAIN_BLUETOOTH, mActivity)),
            new SpanInfo("<link2>", "</link2>",
                    new BluetoothClickableSpan(LinkType.RESTART_SEARCH, mActivity)));

    ItemChooserDialog.ItemChooserLabels labels =
            new ItemChooserDialog.ItemChooserLabels(title, searching, noneFound, statusActive,
                    statusIdleNoneFound, statusIdleSomeFound, positiveButton);
    mItemChooserDialog = new ItemChooserDialog(mActivity, this, labels);

    mActivity.registerReceiver(mLocationModeBroadcastReceiver,
            new IntentFilter(LocationManager.MODE_CHANGED_ACTION));
    mIsLocationModeChangedReceiverRegistered = true;
}
 
Example 14
Project: chromium-for-android-56-debug-video   File: UsbChooserDialog.java   View Source Code Vote up 4 votes
/**
 * Shows the UsbChooserDialog.
 *
 * @param activity Activity which is used for launching a dialog.
 * @param origin The origin for the site wanting to connect to the USB device.
 * @param securityLevel The security level of the connection to the site wanting to connect to
 *                      the USB device. For valid values see SecurityStateModel::SecurityLevel.
 */
@VisibleForTesting
void show(Activity activity, String origin, int securityLevel) {
    // Emphasize the origin.
    Profile profile = Profile.getLastUsedProfile();
    SpannableString originSpannableString = new SpannableString(origin);
    OmniboxUrlEmphasizer.emphasizeUrl(originSpannableString, activity.getResources(), profile,
            securityLevel, false /* isInternalPage */, true /* useDarkColors */,
            true /* emphasizeHttpsScheme */);
    // Construct a full string and replace the origin text with emphasized version.
    SpannableString title =
            new SpannableString(activity.getString(R.string.usb_chooser_dialog_prompt, origin));
    int start = title.toString().indexOf(origin);
    TextUtils.copySpansFrom(originSpannableString, 0, originSpannableString.length(),
            Object.class, title, start);

    String searching = "";
    String noneFound = activity.getString(R.string.usb_chooser_dialog_no_devices_found_prompt);
    SpannableString statusActive =
            SpanApplier.applySpans(
                    activity.getString(R.string.usb_chooser_dialog_footnote_text),
                    new SpanInfo("<link>", "</link>", new NoUnderlineClickableSpan() {
                        @Override
                        public void onClick(View view) {
                            if (mNativeUsbChooserDialogPtr == 0) {
                                return;
                            }

                            nativeLoadUsbHelpPage(mNativeUsbChooserDialogPtr);

                            // Get rid of the highlight background on selection.
                            view.invalidate();
                        }
                    }));
    SpannableString statusIdleNoneFound = statusActive;
    SpannableString statusIdleSomeFound = statusActive;
    String positiveButton = activity.getString(R.string.usb_chooser_dialog_connect_button_text);

    ItemChooserDialog.ItemChooserLabels labels =
            new ItemChooserDialog.ItemChooserLabels(title, searching, noneFound, statusActive,
                    statusIdleNoneFound, statusIdleSomeFound, positiveButton);
    mItemChooserDialog = new ItemChooserDialog(activity, this, labels);
}
 
Example 15
Project: GravityBox   File: UnicodeFilter.java   View Source Code Vote up 4 votes
public CharSequence filter(CharSequence source) {
    StringBuilder output = new StringBuilder(source);
    final int sourceLength = source.length();

    for (int i = 0; i < sourceLength; i++) {
        char c = source.charAt(i);

        // Character requires Unicode, try to replace it
        if (!mStripNonDecodableOnly || !gsm.canEncode(c)) {
            String s = String.valueOf(c);

            // Try normalizing the character into Unicode NFKD form and
            // stripping out diacritic mark characters.
            s = Normalizer.normalize(s, Normalizer.Form.NFKD);
            s = diacritics.matcher(s).replaceAll("");

            // Special case characters that don't get stripped by the
            // above technique.
            s = s.replace("Œ", "OE");
            s = s.replace("œ", "oe");
            s = s.replace("Ł", "L");
            s = s.replace("ł", "l");
            s = s.replace("Đ", "DJ");
            s = s.replace("đ", "dj");
            s = s.replace("Α", "A");
            s = s.replace("Β", "B");
            s = s.replace("Ε", "E");
            s = s.replace("Ζ", "Z");
            s = s.replace("Η", "H");
            s = s.replace("Ι", "I");
            s = s.replace("Κ", "K");
            s = s.replace("Μ", "M");
            s = s.replace("Ν", "N");
            s = s.replace("Ο", "O");
            s = s.replace("Ρ", "P");
            s = s.replace("Τ", "T");
            s = s.replace("Υ", "Y");
            s = s.replace("Χ", "X");
            s = s.replace("α", "A");
            s = s.replace("β", "B");
            s = s.replace("γ", "Γ");
            s = s.replace("δ", "Δ");
            s = s.replace("ε", "E");
            s = s.replace("ζ", "Z");
            s = s.replace("η", "H");
            s = s.replace("θ", "Θ");
            s = s.replace("ι", "I");
            s = s.replace("κ", "K");
            s = s.replace("λ", "Λ");
            s = s.replace("μ", "M");
            s = s.replace("ν", "N");
            s = s.replace("ξ", "Ξ");
            s = s.replace("ο", "O");
            s = s.replace("π", "Π");
            s = s.replace("ρ", "P");
            s = s.replace("σ", "Σ");
            s = s.replace("τ", "T");
            s = s.replace("υ", "Y");
            s = s.replace("φ", "Φ");
            s = s.replace("χ", "X");
            s = s.replace("ψ", "Ψ");
            s = s.replace("ω", "Ω");
            s = s.replace("ς", "Σ");

            output.replace(i, i + 1, s);
        }
    }

    // Source is a spanned string, so copy the spans from it
    if (source instanceof Spanned) {
        SpannableString spannedoutput = new SpannableString(output);
        TextUtils.copySpansFrom(
                (Spanned) source, 0, sourceLength, null, spannedoutput, 0);

        return spannedoutput;
    }

    // Source is a vanilla charsequence, so return output as-is
    return output.toString();
}