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

The following examples show how to use android.text.TextUtils#copySpansFrom() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ChipsEditText.java    From quill with MIT License 6 votes vote down vote up
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 2
Source File: RecipientsEditor.java    From bcm-android with GNU General Public License v3.0 6 votes vote down vote up
/**
 * 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 3
Source File: MultiAutoCompleteTextView.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
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 4
Source File: AutoCompleteFunctionEditText.java    From ncalc with GNU General Public License v3.0 6 votes vote down vote up
@Override
public CharSequence terminateToken(CharSequence text) {
    int i = text.length();

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

    if (i > 0 && Character.isJavaIdentifierStart(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
Source File: WhitSpaceTokenizer.java    From EosCommander with MIT License 6 votes vote down vote up
@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 6
Source File: AtTokenizer.java    From fanfouapp-opensource with Apache License 2.0 6 votes vote down vote up
@Override
public CharSequence terminateToken(final 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) {
            final SpannableString sp = new SpannableString(text);
            TextUtils.copySpansFrom((Spanned) text, 0, text.length(),
                    Object.class, sp, 0);
            return sp;
        } else {
            return text + " ";
        }
    }
}
 
Example 7
Source File: SpaceTokenizer.java    From fanfouapp-opensource with Apache License 2.0 6 votes vote down vote up
@Override
public CharSequence terminateToken(final 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) {
            final SpannableString sp = new SpannableString(text + " ");
            TextUtils.copySpansFrom((Spanned) text, 0, text.length(),
                    Object.class, sp, 0);
            return sp;
        } else {
            return text + " ";
        }
    }
}
 
Example 8
Source File: EmojiFilter.java    From bcm-android with GNU General Public License v3.0 5 votes vote down vote up
@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 9
Source File: AllCapsTransformationMethod.java    From Carbon with Apache License 2.0 5 votes vote down vote up
@Override
public CharSequence getTransformation(CharSequence source, View view) {
    if (source == null)
        return null;
    if (source instanceof Spanned) {
        SpannableString string = new SpannableString(source.toString().toUpperCase(locale));
        TextUtils.copySpansFrom((Spanned) source, 0, source.length(), null, string, 0);
        return string;
    }
    return source.toString().toUpperCase(locale);
}
 
Example 10
Source File: ChatActivity.java    From stynico with MIT License 5 votes vote down vote up
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 11
Source File: MnemonicActivity.java    From GreenBits with GNU General Public License v3.0 5 votes vote down vote up
public CharSequence terminateToken(final CharSequence t) {
    int cursor = t.length();

    while (cursor > 0 && isspace(t, cursor - 1))
        cursor--;
    if (cursor > 0 && isspace(t, cursor - 1))
        return t;
    if (t instanceof Spanned) {
        final SpannableString sp = new SpannableString(t + " ");
        TextUtils.copySpansFrom((Spanned) t, 0, t.length(), Object.class, sp, 0);
        return sp;
    }
    return t + " ";
}
 
Example 12
Source File: UsernameTokenizer.java    From Onosendai with Apache License 2.0 5 votes vote down vote up
@Override
public CharSequence terminateToken (final CharSequence text) {
	int i = text.length();
	while (i > 0 && text.charAt(i - 1) == ' ') {
		i--;
	}
	if (i > 0 && text.charAt(i - 1) == ' ') return text;
	if (text instanceof Spanned) {
		final SpannableString sp = new SpannableString(text + " ");
		TextUtils.copySpansFrom((Spanned) text, 0, text.length(), Object.class, sp, 0);
		return sp;
	}
	return text + " ";
}
 
Example 13
Source File: BluetoothChooserDialog.java    From delion with Apache License 2.0 4 votes vote down vote up
/**
 * 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 message = mActivity.getString(R.string.bluetooth_not_found);
    SpannableString noneFound = SpanApplier.applySpans(
            message, new SpanInfo("<link>", "</link>",
                             new BluetoothClickableSpan(LinkType.RESTART_SEARCH, mActivity)));

    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("<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,
                    statusIdleNoneFound, statusIdleSomeFound, positiveButton);
    mItemChooserDialog = new ItemChooserDialog(mActivity, this, labels);

    mActivity.registerReceiver(mLocationModeBroadcastReceiver,
            new IntentFilter(LocationManager.MODE_CHANGED_ACTION));
}
 
Example 14
Source File: SpanUtils.java    From TokenAutoComplete with Apache License 2.0 4 votes vote down vote up
@Nullable
public static Spanned ellipsizeWithSpans(@Nullable CharSequence prefix, @Nullable CountSpan countSpan,
                                       int tokenCount, @NonNull TextPaint paint,
                                       @NonNull CharSequence originalText, float maxWidth) {

    float countWidth = 0;
    if (countSpan != null) {
        //Assume the largest possible number of items for measurement
        countSpan.setCount(tokenCount);
        countWidth = countSpan.getCountTextWidthForPaint(paint);
    }

    EllipsizeCallback ellipsizeCallback = new EllipsizeCallback();
    CharSequence tempEllipsized = TextUtils.ellipsize(originalText, paint, maxWidth - countWidth,
            TextUtils.TruncateAt.END, false, ellipsizeCallback);
    SpannableStringBuilder ellipsized = new SpannableStringBuilder(tempEllipsized);
    if (tempEllipsized instanceof Spanned) {
        TextUtils.copySpansFrom((Spanned)tempEllipsized, 0, tempEllipsized.length(), Object.class, ellipsized, 0);
    }

    if (prefix != null && prefix.length() > ellipsizeCallback.start) {
        //We ellipsized part of the prefix, so put it back
        ellipsized.replace(0, ellipsizeCallback.start, prefix);
        ellipsizeCallback.end = ellipsizeCallback.end + prefix.length() - ellipsizeCallback.start;
        ellipsizeCallback.start = prefix.length();
    }

    if (ellipsizeCallback.start != ellipsizeCallback.end) {

        if (countSpan != null) {
            int visibleCount = ellipsized.getSpans(0, ellipsized.length(), TokenCompleteTextView.TokenImageSpan.class).length;
            countSpan.setCount(tokenCount - visibleCount);
            ellipsized.replace(ellipsizeCallback.start, ellipsized.length(), countSpan.getCountText());
            ellipsized.setSpan(countSpan, ellipsizeCallback.start, ellipsized.length(),
                    Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        }
        return ellipsized;
    }
    //No ellipses necessary
    return null;
}
 
Example 15
Source File: UsbChooserDialog.java    From AndroidChromium with Apache License 2.0 4 votes vote down vote up
/**
 * 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 16
Source File: BluetoothChooserDialog.java    From AndroidChromium with Apache License 2.0 4 votes vote down vote up
/**
 * 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 17
Source File: UsbChooserDialog.java    From delion with Apache License 2.0 4 votes vote down vote up
/**
 * 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 statusIdleNoneFound =
            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 statusIdleSomeFound = statusIdleNoneFound;
    String positiveButton = activity.getString(R.string.usb_chooser_dialog_connect_button_text);

    ItemChooserDialog.ItemChooserLabels labels =
            new ItemChooserDialog.ItemChooserLabels(title, searching, noneFound,
                    statusIdleNoneFound, statusIdleSomeFound, positiveButton);
    mItemChooserDialog = new ItemChooserDialog(activity, this, labels);
}
 
Example 18
Source File: UnicodeFilter.java    From GravityBox with Apache License 2.0 4 votes vote down vote up
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();
}
 
Example 19
Source File: UsbChooserDialog.java    From 365browser with Apache License 2.0 4 votes vote down vote up
/**
 * 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 20
Source File: BluetoothChooserDialog.java    From 365browser with Apache License 2.0 4 votes vote down vote up
/**
 * 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),
                    new SpanInfo("<link1>", "</link1>",
                            new BluetoothClickableSpan(LinkType.EXPLAIN_BLUETOOTH, mActivity)),
                    new SpanInfo("<link2>", "</link2>",
                            new BluetoothClickableSpan(LinkType.RESTART_SEARCH, mActivity)));

    SpannableString statusActive = searching;

    SpannableString statusIdleSomeFound = statusIdleNoneFound;

    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;
}