當前位置: 首頁>>代碼示例>>Java>>正文


Java Spannable.toString方法代碼示例

本文整理匯總了Java中android.text.Spannable.toString方法的典型用法代碼示例。如果您正苦於以下問題:Java Spannable.toString方法的具體用法?Java Spannable.toString怎麽用?Java Spannable.toString使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在android.text.Spannable的用法示例。


在下文中一共展示了Spannable.toString方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: invalidateSpannables

import android.text.Spannable; //導入方法依賴的package包/類
public void invalidateSpannables() {
    log("invalidating all spannables -- consider everything nullified");
    final Spannable spans = getText();
    final String text = spans.toString();

    // Remove existing spans
    for (CharacterStyle style : mSpans) {
        spans.removeSpan(style);
    }

    // Loop over the text, looking for new spans
    for (int i = 0; i < text.length(); i++) {
        for (SpanComponent component : mComponents) {
            String equation = component.parse(text.substring(i));
            if (equation != null) {
                MathSpannable span = component.getSpan(equation);
                spans.setSpan(span, i, i + equation.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
                i += equation.length();
                break;
            }
        }
    }

    setSelection(getSelectionStart());
}
 
開發者ID:tranleduy2000,項目名稱:floating_calc,代碼行數:26,代碼來源:CalculatorEditText.java

示例2: matchMention

import android.text.Spannable; //導入方法依賴的package包/類
public static Spannable matchMention(Spannable spannable) {
    String text = spannable.toString();

    Pattern pattern = Pattern.compile(MATCH_MENTION);
    Matcher matcher = pattern.matcher(text);

    while (matcher.find()) {
        String str = matcher.group();
        int matcherStart = matcher.start();
        int matcherEnd = matcher.end();
        spannable.setSpan(new RichEditText.TagSpan(str), matcherStart, matcherEnd, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        log("matchMention:" + str + " " + matcherStart + " " + matcherEnd);
    }

    return spannable;
}
 
開發者ID:hsj-xiaokang,項目名稱:OSchina_resources_android,代碼行數:17,代碼來源:RichEditText.java

示例3: matchTopic

import android.text.Spannable; //導入方法依賴的package包/類
public static Spannable matchTopic(Spannable spannable) {
    String text = spannable.toString();

    Pattern pattern = Pattern.compile(MATCH_TOPIC);
    Matcher matcher = pattern.matcher(text);

    while (matcher.find()) {
        String str = matcher.group();
        int matcherStart = matcher.start();
        int matcherEnd = matcher.end();
        spannable.setSpan(new RichEditText.TagSpan(str), matcherStart, matcherEnd, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        log("matchTopic:" + str + " " + matcherStart + " " + matcherEnd);
    }

    return spannable;
}
 
開發者ID:hsj-xiaokang,項目名稱:OSchina_resources_android,代碼行數:17,代碼來源:RichEditText.java

示例4: displayEmoji

import android.text.Spannable; //導入方法依賴的package包/類
public static Spannable displayEmoji(Resources res, Spannable spannable, int size) {
    String str = spannable.toString();

    if (!str.contains(":") && !str.contains("[")) {
        return spannable;
    }

    if (size == 0)
        size = (int) TDevice.spToPx(res, 20);

    Pattern pattern = Pattern.compile("(\\[[^\\[\\]:\\s\\n]+\\])|(:[^:\\[\\]\\s\\n]+:)");
    Matcher matcher = pattern.matcher(str);
    while (matcher.find()) {
        String emojiStr = matcher.group();
        if (TextUtils.isEmpty(emojiStr)) continue;
        int resId = getEmojiResId(emojiStr);
        if (resId <= 0) continue;
        Drawable drawable = res.getDrawable(resId);
        if (drawable == null) continue;
        drawable.setBounds(0, 0, size, size);

        ImageSpan span = new ImageSpan(drawable, ImageSpan.ALIGN_BOTTOM);
        spannable.setSpan(span, matcher.start(), matcher.end(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    }

    return spannable;
}
 
開發者ID:hsj-xiaokang,項目名稱:OSchina_resources_android,代碼行數:28,代碼來源:InputHelper.java

示例5: prepareFormat

import android.text.Spannable; //導入方法依賴的package包/類
private CharSequence prepareFormat(Spannable s) {
    SpannableString ret = new SpannableString(s.toString());
    for (Object span : s.getSpans(0, s.length(), CharacterStyle.class)) {
        if ((ret.getSpanFlags(span) & Spannable.SPAN_COMPOSING) != 0)
            continue;
        ret.setSpan(span, s.getSpanStart(span), s.getSpanEnd(span), s.getSpanFlags(span) & Spanned.SPAN_PRIORITY);
    }
    return ret;
}
 
開發者ID:MCMrARM,項目名稱:revolution-irc,代碼行數:10,代碼來源:MessageFormatSettingsActivity.java

示例6: onItemClick

import android.text.Spannable; //導入方法依賴的package包/類
/**
 * Simple event to raise when the component is clicked. Implementation of
 * AdapterView.OnItemClickListener
 */
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
  Spannable item = (Spannable) parent.getAdapter().getItem(position);
  this.selection = item.toString();
  this.selectionIndex = adapterCopy.getPosition(item) + 1; // AI lists are 1-based

  AfterPicking();
}
 
開發者ID:mit-cml,項目名稱:appinventor-extensions,代碼行數:13,代碼來源:ListView.java

示例7: highlightSpans

import android.text.Spannable; //導入方法依賴的package包/類
/** Takes text containing mentions and hashtags and makes them the given colour. */
public static void highlightSpans(Spannable text, int colour) {
    // Strip all existing colour spans.
    int n = text.length();
    ForegroundColorSpan[] oldSpans = text.getSpans(0, n, ForegroundColorSpan.class);
    for (int i = oldSpans.length - 1; i >= 0; i--) {
        text.removeSpan(oldSpans[i]);
    }
    // Colour the mentions and hashtags.
    String string = text.toString();
    int start;
    int end = 0;
    while (end < n) {
        char[] chars = { '#', '@' };
        FindCharsResult found = findStart(string, end, chars);
        start = found.stringIndex;
        if (start < 0) {
            break;
        }
        if (found.charIndex == 0) {
            end = findEndOfHashtag(string, start);
        } else if (found.charIndex == 1) {
            end = findEndOfMention(string, start);
        } else {
            break;
        }
        if (end < 0) {
            break;
        }
        text.setSpan(new ForegroundColorSpan(colour), start, end,
                Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
    }
}
 
開發者ID:Vavassor,項目名稱:Tusky,代碼行數:34,代碼來源:SpanUtils.java

示例8: notifyImpl

import android.text.Spannable; //導入方法依賴的package包/類
private void notifyImpl(Context context, OwnerInfo ownerInfo) {
    String url = "vk.com/" + place;
    Commented commented = LinkHelper.findCommentedFrom(url);

    if (commented == null) {
        return;
    }

    String subText = null;
    switch (commented.getSourceType()) {
        case CommentedType.PHOTO:
            subText = context.getString(R.string.commented_to_photo);
            break;
        case CommentedType.VIDEO:
            subText = context.getString(R.string.commented_to_video);
            break;
        case CommentedType.POST:
            subText = context.getString(R.string.commented_to_post);
            break;
        case CommentedType.TOPIC:
            // not supported
            break;
    }

    if (subText == null) {
        return;
    }

    Spannable snannedText = OwnerLinkSpanFactory.withSpans(text, true, false, null);
    String targetText = snannedText == null ? null : snannedText.toString();

    Owner owner = ownerInfo.getOwner();

    final NotificationManager nManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
    if (Utils.hasOreo()){
        nManager.createNotificationChannel(AppNotificationChannels.getCommentsChannel(context));
    }

    NotificationCompat.Builder builder = new NotificationCompat.Builder(context, AppNotificationChannels.COMMENTS_CHANNEL_ID)
            .setSmallIcon(R.drawable.ic_notify_statusbar)
            .setLargeIcon(ownerInfo.getAvatar())
            .setContentTitle(owner.getFullName())
            .setContentText(targetText)
            .setSubText(subText)
            .setStyle(new NotificationCompat.BigTextStyle().bigText(targetText))
            .setAutoCancel(true);

    builder.setPriority(NotificationCompat.PRIORITY_HIGH);

    int aid = Settings.get()
            .accounts()
            .getCurrent();

    Intent intent = new Intent(context, MainActivity.class);
    intent.putExtra(Extra.PLACE, PlaceFactory.getCommentsPlace(aid, commented, reply_id));
    intent.setAction(MainActivity.ACTION_OPEN_PLACE);
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

    PendingIntent contentIntent = PendingIntent.getActivity(context, reply_id, intent, PendingIntent.FLAG_CANCEL_CURRENT);
    builder.setContentIntent(contentIntent);

    Notification notification = builder.build();

    configOtherPushNotification(notification);
    nManager.notify(place, NotificationHelper.NOTIFICATION_COMMENT_ID, notification);
}
 
開發者ID:PhoenixDevTeam,項目名稱:Phoenix-for-VK,代碼行數:67,代碼來源:CommentGCMMessage.java

示例9: notifyImpl

import android.text.Spannable; //導入方法依賴的package包/類
private void notifyImpl(Context context, @NonNull Owner owner, Bitmap bitmap){
    String url = "vk.com/" + place;
    Commented commented = LinkHelper.findCommentedFrom(url);

    if(commented == null){
        Logger.e(TAG, "Unknown place: " + place);
        return;
    }

    Spannable snannedText = OwnerLinkSpanFactory.withSpans(text, true, false, null);
    String targetText = snannedText == null ? null : snannedText.toString();

    final NotificationManager nManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
    if (Utils.hasOreo()){
        nManager.createNotificationChannel(AppNotificationChannels.getCommentsChannel(context));
    }
    NotificationCompat.Builder builder = new NotificationCompat.Builder(context, AppNotificationChannels.COMMENTS_CHANNEL_ID)
            .setSmallIcon(R.drawable.ic_notify_statusbar)
            .setLargeIcon(bitmap)
            .setContentTitle(owner.getFullName())
            .setContentText(targetText)
            .setSubText(context.getString(R.string.in_reply_to_your_comment))
            .setStyle(new NotificationCompat.BigTextStyle().bigText(targetText))
            .setAutoCancel(true);

    builder.setPriority(NotificationCompat.PRIORITY_HIGH);

    int aid = Settings.get()
            .accounts()
            .getCurrent();

    Intent intent = new Intent(context, MainActivity.class);
    intent.putExtra(Extra.PLACE, PlaceFactory.getCommentsPlace(aid, commented, reply_id));
    intent.setAction(MainActivity.ACTION_OPEN_PLACE);
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

    PendingIntent contentIntent = PendingIntent.getActivity(context, reply_id, intent, PendingIntent.FLAG_CANCEL_CURRENT);
    builder.setContentIntent(contentIntent);
    Notification notification = builder.build();

    configOtherPushNotification(notification);
    nManager.notify(place, NotificationHelper.NOTIFICATION_REPLY_ID, notification);
}
 
開發者ID:PhoenixDevTeam,項目名稱:Phoenix-for-VK,代碼行數:44,代碼來源:ReplyGCMMessage.java


注:本文中的android.text.Spannable.toString方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。