当前位置: 首页>>代码示例>>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;未经允许,请勿转载。