Java 类android.text.style.TextAppearanceSpan 实例源码

项目:MultiContactPicker    文件:MultiContactPickerAdapter.java   
private void highlightTerm(TextView tv, String query, String originalString){
    if (query != null && !query.isEmpty()) {
        int startPos = originalString.toLowerCase().indexOf(query.toLowerCase());
        int endPos = startPos + query.length();
        if (startPos != -1) {
            Spannable spannable = new SpannableString(originalString);
            ColorStateList blackColor = new ColorStateList(new int[][]{new int[]{}}, new int[]{Color.BLACK});
            TextAppearanceSpan highlightSpan = new TextAppearanceSpan(null, Typeface.BOLD, -1, blackColor, null);
            spannable.setSpan(highlightSpan, startPos, endPos, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
            tv.setText(spannable);
        } else {
            tv.setText(originalString);
        }
    } else {
        tv.setText(originalString);
    }
}
项目:Applozic-Android-Chat-Sample    文件:QuickConversationAdapter.java   
public QuickConversationAdapter(final Context context, List<Message> messageList, EmojiconHandler emojiconHandler) {
    this.context = context;
    this.emojiconHandler = emojiconHandler;
    this.contactService = new AppContactService(context);
    this.messageDatabaseService = new MessageDatabaseService(context);
    this.messageList = messageList;
    contactImageLoader = new ImageLoader(context, ImageUtils.getLargestScreenDimension((Activity) context)) {
        @Override
        protected Bitmap processBitmap(Object data) {
            return contactService.downloadContactImage((Activity) context, (Contact) data);
        }
    };
    contactImageLoader.addImageCache(((FragmentActivity) context).getSupportFragmentManager(), 0.1f);
    contactImageLoader.setImageFadeIn(false);
    channelImageLoader = new ImageLoader(context, ImageUtils.getLargestScreenDimension((Activity) context)) {
        @Override
        protected Bitmap processBitmap(Object data) {
            return contactService.downloadGroupImage((Activity) context, (Channel) data);
        }
    };
    channelImageLoader.addImageCache(((FragmentActivity) context).getSupportFragmentManager(), 0.1f);
    channelImageLoader.setImageFadeIn(false);
    final String alphabet = context.getString(R.string.alphabet);
    mAlphabetIndexer = new AlphabetIndexer(null, 1, alphabet);
    highlightTextSpan = new TextAppearanceSpan(context, R.style.searchTextHiglight);
}
项目:Applozic-Android-Chat-Sample    文件:ChannelFragment.java   
/**
 * Instantiates a new Contacts Adapter.
 *
 * @param context A context that has access to the app's layout.
 */
public ChannelAdapter(Context context) {
    super(context, null, 0);
    this.context = context;
    // Stores inflater for use later
    mInflater = LayoutInflater.from(context);
    final String alphabet = context.getString(R.string.alphabet);

    // Instantiates a new AlphabetIndexer bound to the column used to sort contact names.
    // The cursor is left null, because it has not yet been retrieved.
    mAlphabetIndexer = new AlphabetIndexer(null, 1, alphabet);

    // Defines a span for highlighting the part of a display name that matches the search
    // string
    highlightTextSpan = new TextAppearanceSpan(getActivity(), R.style.searchTextHiglight);
}
项目:Applozic-Android-Chat-Sample    文件:ContactsListFragment.java   
/**
 * Instantiates a new Contacts Adapter.
 *
 * @param context A context that has access to the app's layout.
 */
public ContactsAdapter(Context context) {
    super(context, null, 0);

    // Stores inflater for use later
    mInflater = LayoutInflater.from(context);

    // Loads a string containing the English alphabet. To fully localize the app, provide a
    // strings.xml file in res/values-<x> directories, where <x> is a locale. In the file,
    // define a string with android:name="alphabet" and contents set to all of the
    // alphabetic characters in the language in their proper sort order, in upper case if
    // applicable.
    final String alphabet = context.getString(R.string.alphabet);

    // Instantiates a new AlphabetIndexer bound to the column used to sort contact names.
    // The cursor is left null, because it has not yet been retrieved.
    mAlphabetIndexer = new AlphabetIndexer(null, ContactsQuery.SORT_KEY, alphabet);

    // Defines a span for highlighting the part of a display name that matches the search
    // string
    highlightTextSpan = new TextAppearanceSpan(getActivity(), R.style.searchTextHiglight);
}
项目:Applozic-Android-Chat-Sample    文件:ContactSelectionFragment.java   
/**
 * Instantiates a new Contacts Adapter.
 *
 * @param context A context that has access to the app's layout.
 */
public ContactsAdapter(Context context) {
    super(context, null, 0);
    this.context = context;
    userIdList = new ArrayList<String>();
    // Stores inflater for use later
    mInflater = LayoutInflater.from(context);
    // Loads a string containing the English alphabet. To fully localize the app, provide a
    // strings.xml file in res/values-<x> directories, where <x> is a locale. In the file,
    // define a string with android:name="alphabet" and contents set to all of the
    // alphabetic characters in the language in their proper sort order, in upper case if
    // applicable.
    final String alphabet = context.getString(R.string.alphabet);

    // Instantiates a new AlphabetIndexer bound to the column used to sort contact names.
    // The cursor is left null, because it has not yet been retrieved.
    mAlphabetIndexer = new AlphabetIndexer(null, 1, alphabet);

    // Defines a span for highlighting the part of a display name that matches the search
    // string
    highlightTextSpan = new TextAppearanceSpan(context, R.style.searchTextHiglight);
}
项目:Applozic-Android-Chat-Sample    文件:AppContactFragment.java   
/**
 * Instantiates a new Contacts Adapter.
 *
 * @param context A context that has access to the app's layout.
 */
public ContactsAdapter(Context context) {
    super(context, null, 0);
    this.context = context;
    // Stores inflater for use later
    mInflater = LayoutInflater.from(context);
    // Loads a string containing the English alphabet. To fully localize the app, provide a
    // strings.xml file in res/values-<x> directories, where <x> is a locale. In the file,
    // define a string with android:name="alphabet" and contents set to all of the
    // alphabetic characters in the language in their proper sort order, in upper case if
    // applicable.
    final String alphabet = context.getString(R.string.alphabet);

    // Instantiates a new AlphabetIndexer bound to the column used to sort contact names.
    // The cursor is left null, because it has not yet been retrieved.
    mAlphabetIndexer = new AlphabetIndexer(null, 1, alphabet);

    // Defines a span for highlighting the part of a display name that matches the search
    // string
    highlightTextSpan = new TextAppearanceSpan(getActivity(), R.style.searchTextHiglight);
}
项目:Applozic-Android-Chat-Sample    文件:QuickConversationAdapter.java   
public QuickConversationAdapter(final Context context, List<Message> messageList, EmojiconHandler emojiconHandler) {
    this.context = context;
    this.emojiconHandler = emojiconHandler;
    this.contactService = new AppContactService(context);
    this.messageDatabaseService = new MessageDatabaseService(context);
    this.messageList = messageList;
    contactImageLoader = new ImageLoader(context, ImageUtils.getLargestScreenDimension((Activity) context)) {
        @Override
        protected Bitmap processBitmap(Object data) {
            return contactService.downloadContactImage((Activity) context, (Contact) data);
        }
    };
    contactImageLoader.addImageCache(((FragmentActivity) context).getSupportFragmentManager(), 0.1f);
    contactImageLoader.setImageFadeIn(false);
    channelImageLoader = new ImageLoader(context, ImageUtils.getLargestScreenDimension((Activity) context)) {
        @Override
        protected Bitmap processBitmap(Object data) {
            return contactService.downloadGroupImage((Activity) context, (Channel) data);
        }
    };
    channelImageLoader.addImageCache(((FragmentActivity) context).getSupportFragmentManager(), 0.1f);
    channelImageLoader.setImageFadeIn(false);
    final String alphabet = context.getString(R.string.alphabet);
    mAlphabetIndexer = new AlphabetIndexer(null, 1, alphabet);
    highlightTextSpan = new TextAppearanceSpan(context, R.style.searchTextHiglight);
}
项目:Applozic-Android-Chat-Sample    文件:ChannelFragment.java   
/**
 * Instantiates a new Contacts Adapter.
 *
 * @param context A context that has access to the app's layout.
 */
public ChannelAdapter(Context context) {
    super(context, null, 0);
    this.context = context;
    // Stores inflater for use later
    mInflater = LayoutInflater.from(context);
    final String alphabet = context.getString(R.string.alphabet);

    // Instantiates a new AlphabetIndexer bound to the column used to sort contact names.
    // The cursor is left null, because it has not yet been retrieved.
    mAlphabetIndexer = new AlphabetIndexer(null, 1, alphabet);

    // Defines a span for highlighting the part of a display name that matches the search
    // string
    highlightTextSpan = new TextAppearanceSpan(getActivity(), R.style.searchTextHiglight);
}
项目:Applozic-Android-Chat-Sample    文件:ContactsListFragment.java   
/**
 * Instantiates a new Contacts Adapter.
 *
 * @param context A context that has access to the app's layout.
 */
public ContactsAdapter(Context context) {
    super(context, null, 0);

    // Stores inflater for use later
    mInflater = LayoutInflater.from(context);

    // Loads a string containing the English alphabet. To fully localize the app, provide a
    // strings.xml file in res/values-<x> directories, where <x> is a locale. In the file,
    // define a string with android:name="alphabet" and contents set to all of the
    // alphabetic characters in the language in their proper sort order, in upper case if
    // applicable.
    final String alphabet = context.getString(R.string.alphabet);

    // Instantiates a new AlphabetIndexer bound to the column used to sort contact names.
    // The cursor is left null, because it has not yet been retrieved.
    mAlphabetIndexer = new AlphabetIndexer(null, ContactsQuery.SORT_KEY, alphabet);

    // Defines a span for highlighting the part of a display name that matches the search
    // string
    highlightTextSpan = new TextAppearanceSpan(getActivity(), R.style.searchTextHiglight);
}
项目:Applozic-Android-Chat-Sample    文件:ContactSelectionFragment.java   
/**
 * Instantiates a new Contacts Adapter.
 *
 * @param context A context that has access to the app's layout.
 */
public ContactsAdapter(Context context) {
    super(context, null, 0);
    this.context = context;
    userIdList = new ArrayList<String>();
    // Stores inflater for use later
    mInflater = LayoutInflater.from(context);
    // Loads a string containing the English alphabet. To fully localize the app, provide a
    // strings.xml file in res/values-<x> directories, where <x> is a locale. In the file,
    // define a string with android:name="alphabet" and contents set to all of the
    // alphabetic characters in the language in their proper sort order, in upper case if
    // applicable.
    final String alphabet = context.getString(R.string.alphabet);

    // Instantiates a new AlphabetIndexer bound to the column used to sort contact names.
    // The cursor is left null, because it has not yet been retrieved.
    mAlphabetIndexer = new AlphabetIndexer(null, 1, alphabet);

    // Defines a span for highlighting the part of a display name that matches the search
    // string
    highlightTextSpan = new TextAppearanceSpan(context, R.style.searchTextHiglight);
}
项目:Applozic-Android-Chat-Sample    文件:AppContactFragment.java   
/**
 * Instantiates a new Contacts Adapter.
 *
 * @param context A context that has access to the app's layout.
 */
public ContactsAdapter(Context context) {
    super(context, null, 0);
    this.context = context;
    // Stores inflater for use later
    mInflater = LayoutInflater.from(context);
    // Loads a string containing the English alphabet. To fully localize the app, provide a
    // strings.xml file in res/values-<x> directories, where <x> is a locale. In the file,
    // define a string with android:name="alphabet" and contents set to all of the
    // alphabetic characters in the language in their proper sort order, in upper case if
    // applicable.
    final String alphabet = context.getString(R.string.alphabet);

    // Instantiates a new AlphabetIndexer bound to the column used to sort contact names.
    // The cursor is left null, because it has not yet been retrieved.
    mAlphabetIndexer = new AlphabetIndexer(null, 1, alphabet);

    // Defines a span for highlighting the part of a display name that matches the search
    // string
    highlightTextSpan = new TextAppearanceSpan(getActivity(), R.style.searchTextHiglight);
}
项目:android_packages_apps_tv    文件:ScheduledRecordingPresenter.java   
private void setTitleAndImage(RecordingCardView cardView, ScheduledRecording recording) {
    Channel channel = mChannelDataManager.getChannel(recording.getChannelId());
    SpannableString title = recording.getProgramTitleWithEpisodeNumber(mContext) == null ?
            null : new SpannableString(recording.getProgramTitleWithEpisodeNumber(mContext));
    if (TextUtils.isEmpty(title)) {
        title = new SpannableString(channel != null ? channel.getDisplayName()
                : mContext.getResources().getString(R.string.no_program_information));
    } else {
        String programTitle = recording.getProgramTitle();
        title.setSpan(new TextAppearanceSpan(mContext,
                R.style.text_appearance_card_view_episode_number),
                programTitle == null ? 0 : programTitle.length(), title.length(),
                Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    }
    String imageUri = recording.getProgramPosterArtUri();
    boolean isChannelLogo = false;
    if (TextUtils.isEmpty(imageUri)) {
        imageUri = channel != null ?
                TvContract.buildChannelLogoUri(channel.getId()).toString() : null;
        isChannelLogo = true;
    }
    cardView.setTitle(title);
    cardView.setImageUri(imageUri, isChannelLogo);
}
项目:android_packages_apps_tv    文件:DvrDetailsFragment.java   
/**
 * Returns program title with episode number. If the program is null, returns channel name.
 */
protected CharSequence getTitleFromProgram(BaseProgram program, Channel channel) {
    String titleWithEpisodeNumber = program.getTitleWithEpisodeNumber(getContext());
    SpannableString title = titleWithEpisodeNumber == null ? null
            : new SpannableString(titleWithEpisodeNumber);
    if (TextUtils.isEmpty(title)) {
        title = new SpannableString(channel != null ? channel.getDisplayName()
                : getContext().getResources().getString(
                R.string.no_program_information));
    } else {
        String programTitle = program.getTitle();
        title.setSpan(new TextAppearanceSpan(getContext(),
                R.style.text_appearance_card_view_episode_number), programTitle == null ? 0
                : programTitle.length(), title.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    }
    return title;
}
项目:myapplication    文件:FindSearchAdapter.java   
@Override
    public void onBindViewHolder(FindSearchAdapter.ItemHolder holder, int position) {
//        String typeAndWhoStr = "<font color=\"#666666\"> ( "
//                + mDatas.get(position).getType()
//                + " via." + mDatas.get(position).getWho() + ")  </font>";

        int textColor = Color.parseColor("#4d000000");

        String textStr = mDatas.get(position).getDesc() + " ("
                + " via. " + mDatas.get(position).getWho() + ")";
        SpannableStringBuilder spannableStringBuilder = new SpannableStringBuilder(textStr);
//        spannableStringBuilder.setSpan(new ForegroundColorSpan(textColor),
//                textStr.lastIndexOf("("), textStr.lastIndexOf(")") + 1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        spannableStringBuilder.setSpan(new TextAppearanceSpan(context, R.style.text_span_style),
                textStr.lastIndexOf("("), textStr.lastIndexOf(")") + 1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);

        holder.searchResultContentTv.setText(spannableStringBuilder);

//        holder.searchResultContentTv.setText(mDatas.get(position).getDesc() + " ("
//                + mDatas.get(position).getType()
//                + " via." + mDatas.get(position).getWho() + ")");

        // 将数据保存在itemView的Tag中,以便点击时进行获取
        holder.itemView.setTag(mDatas.get(position));
    }
项目:EasyGank    文件:DailyDetailAdapter.java   
private TextView createCardItemText(BaseGankData baseGankData) {
    TextView itemText = (TextView) LayoutInflater.from(this.context)
                                                 .inflate(R.layout.view_card_item, null);
    itemText.setPadding(this.cardItemPadding, this.cardItemPadding, this.cardItemPadding,
            this.cardItemPadding);
    String content = baseGankData.desc.trim() +
            "   " +
            String.format(this.viaModel, baseGankData.who);
    SpannableStringBuilder ssb = new SpannableStringBuilder(content);
    ssb.setSpan(new TextAppearanceSpan("serif", Typeface.ITALIC, this.viaTextSize,
                    this.viaColorStateList, this.viaColorStateList), content.indexOf(this.viaModelKey),
            content.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
    itemText.setText(ssb);
    itemText.setTag(R.id.tag_card_item_url, baseGankData.url);
    itemText.setTag(R.id.tag_card_item_desc, baseGankData.desc.trim());
    itemText.setTag(R.id.tag_card_item_type, baseGankData.type);
    itemText.setOnClickListener(v -> {
        if (DailyDetailAdapter.this.onCardItemClickListener != null) {
            DailyDetailAdapter.this.onCardItemClickListener.onCardItemOnClick(
                    (String) v.getTag(R.id.tag_card_item_type),
                    (String) v.getTag(R.id.tag_card_item_desc),
                    (String) v.getTag(R.id.tag_card_item_url));
        }
    });
    return itemText;
}
项目:margarita    文件:ContactFragment.java   
/**
 * Instantiates a new Contacts Adapter.
 * @param context A context that has access to the app's layout.
 */
public ContactsAdapter(Context context) {
    super(context, null, 0);

    // Stores inflater for use later
    mInflater = LayoutInflater.from(context);

    // Loads a string containing the English alphabet. To fully localize the app, provide a
    // strings.xml file in res/values-<x> directories, where <x> is a locale. In the file,
    // define a string with android:name="alphabet" and contents set to all of the
    // alphabetic characters in the language in their proper sort order, in upper case if
    // applicable.
    final String alphabet = context.getString(R.string.alphabet);

    // Instantiates a new AlphabetIndexer bound to the column used to sort contact names.
    // The cursor is left null, because it has not yet been retrieved.
    mAlphabetIndexer = new AlphabetIndexer(null, ContactsQuery.SORT_KEY, alphabet);

    // Defines a span for highlighting the part of a display name that matches the search
    // string
    highlightTextSpan = new TextAppearanceSpan(getActivity(), R.style.searchTextHiglight);
}
项目:Applozic-Android-SDK    文件:QuickConversationAdapter.java   
public QuickConversationAdapter(final Context context, List<Message> messageList, EmojiconHandler emojiconHandler) {
    this.context = context;
    this.emojiconHandler = emojiconHandler;
    this.contactService = new AppContactService(context);
    this.messageDatabaseService = new MessageDatabaseService(context);
    this.messageList = messageList;
    contactImageLoader = new ImageLoader(context, ImageUtils.getLargestScreenDimension((Activity) context)) {
        @Override
        protected Bitmap processBitmap(Object data) {
            return contactService.downloadContactImage((Activity) context, (Contact) data);
        }
    };
    contactImageLoader.addImageCache(((FragmentActivity) context).getSupportFragmentManager(), 0.1f);
    contactImageLoader.setImageFadeIn(false);
    channelImageLoader = new ImageLoader(context, ImageUtils.getLargestScreenDimension((Activity) context)) {
        @Override
        protected Bitmap processBitmap(Object data) {
            return contactService.downloadGroupImage((Activity) context, (Channel) data);
        }
    };
    channelImageLoader.addImageCache(((FragmentActivity) context).getSupportFragmentManager(), 0.1f);
    channelImageLoader.setImageFadeIn(false);
    final String alphabet = context.getString(R.string.alphabet);
    mAlphabetIndexer = new AlphabetIndexer(null, 1, alphabet);
    highlightTextSpan = new TextAppearanceSpan(context, R.style.searchTextHiglight);
}
项目:Applozic-Android-SDK    文件:ChannelFragment.java   
/**
 * Instantiates a new Contacts Adapter.
 *
 * @param context A context that has access to the app's layout.
 */
public ChannelAdapter(Context context) {
    super(context, null, 0);
    this.context = context;
    // Stores inflater for use later
    mInflater = LayoutInflater.from(context);
    final String alphabet = context.getString(R.string.alphabet);

    // Instantiates a new AlphabetIndexer bound to the column used to sort contact names.
    // The cursor is left null, because it has not yet been retrieved.
    mAlphabetIndexer = new AlphabetIndexer(null, 1, alphabet);

    // Defines a span for highlighting the part of a display name that matches the search
    // string
    highlightTextSpan = new TextAppearanceSpan(getActivity(), R.style.searchTextHiglight);
}
项目:Applozic-Android-SDK    文件:ContactsListFragment.java   
/**
 * Instantiates a new Contacts Adapter.
 *
 * @param context A context that has access to the app's layout.
 */
public ContactsAdapter(Context context) {
    super(context, null, 0);

    // Stores inflater for use later
    mInflater = LayoutInflater.from(context);

    // Loads a string containing the English alphabet. To fully localize the app, provide a
    // strings.xml file in res/values-<x> directories, where <x> is a locale. In the file,
    // define a string with android:name="alphabet" and contents set to all of the
    // alphabetic characters in the language in their proper sort order, in upper case if
    // applicable.
    final String alphabet = context.getString(R.string.alphabet);

    // Instantiates a new AlphabetIndexer bound to the column used to sort contact names.
    // The cursor is left null, because it has not yet been retrieved.
    mAlphabetIndexer = new AlphabetIndexer(null, ContactsQuery.SORT_KEY, alphabet);

    // Defines a span for highlighting the part of a display name that matches the search
    // string
    highlightTextSpan = new TextAppearanceSpan(getActivity(), R.style.searchTextHiglight);
}
项目:Applozic-Android-SDK    文件:ContactSelectionFragment.java   
/**
 * Instantiates a new Contacts Adapter.
 *
 * @param context A context that has access to the app's layout.
 */
public ContactsAdapter(Context context) {
    super(context, null, 0);
    this.context = context;
    userIdList = new ArrayList<String>();
    // Stores inflater for use later
    mInflater = LayoutInflater.from(context);
    // Loads a string containing the English alphabet. To fully localize the app, provide a
    // strings.xml file in res/values-<x> directories, where <x> is a locale. In the file,
    // define a string with android:name="alphabet" and contents set to all of the
    // alphabetic characters in the language in their proper sort order, in upper case if
    // applicable.
    final String alphabet = context.getString(R.string.alphabet);

    // Instantiates a new AlphabetIndexer bound to the column used to sort contact names.
    // The cursor is left null, because it has not yet been retrieved.
    mAlphabetIndexer = new AlphabetIndexer(null, 1, alphabet);

    // Defines a span for highlighting the part of a display name that matches the search
    // string
    highlightTextSpan = new TextAppearanceSpan(context, R.style.searchTextHiglight);
}
项目:Applozic-Android-SDK    文件:AppContactFragment.java   
/**
 * Instantiates a new Contacts Adapter.
 *
 * @param context A context that has access to the app's layout.
 */
public ContactsAdapter(Context context) {
    super(context, null, 0);
    this.context = context;
    // Stores inflater for use later
    mInflater = LayoutInflater.from(context);
    // Loads a string containing the English alphabet. To fully localize the app, provide a
    // strings.xml file in res/values-<x> directories, where <x> is a locale. In the file,
    // define a string with android:name="alphabet" and contents set to all of the
    // alphabetic characters in the language in their proper sort order, in upper case if
    // applicable.
    final String alphabet = context.getString(R.string.alphabet);

    // Instantiates a new AlphabetIndexer bound to the column used to sort contact names.
    // The cursor is left null, because it has not yet been retrieved.
    mAlphabetIndexer = new AlphabetIndexer(null, 1, alphabet);

    // Defines a span for highlighting the part of a display name that matches the search
    // string
    highlightTextSpan = new TextAppearanceSpan(getActivity(), R.style.searchTextHiglight);
}
项目:Handbook_for_Melee    文件:SearchAdapter.java   
private void highlight(String search, String originalText, TextView textView) {
    int startPos = originalText.toLowerCase(Locale.US).indexOf(search.toLowerCase(Locale.US));
    int endPos = startPos + search.length();

    if(startPos != -1){
        Spannable spannable = new SpannableString(originalText);
        ColorStateList yellowColor = new ColorStateList(new int[][]{new int[]{}}, new
                int[]{ContextCompat.getColor(mContext, R.color.overscroll_color)});
        TextAppearanceSpan highlightSpan = new TextAppearanceSpan(null, Typeface.BOLD, -1,
                yellowColor, null);

        spannable.setSpan(highlightSpan, startPos, endPos, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        textView.setText(spannable);
    } else {
        textView.setText(originalText);
    }
}
项目:CampusFeedv2    文件:ContactsListFragment.java   
/**
 * Instantiates a new Contacts Adapter.
 * @param context A context that has access to the app's layout.
 */
public ContactsAdapter(Context context) {
    super(context, null, 0);

    // Stores inflater for use later
    mInflater = LayoutInflater.from(context);

    // Loads a string containing the English alphabet. To fully localize the app, provide a
    // strings.xml file in res/values-<x> directories, where <x> is a locale. In the file,
    // define a string with android:name="alphabet" and contents set to all of the
    // alphabetic characters in the language in their proper sort order, in upper case if
    // applicable.
    final String alphabet = context.getString(R.string.alphabet);

    // Instantiates a new AlphabetIndexer bound to the column used to sort contact names.
    // The cursor is left null, because it has not yet been retrieved.
    mAlphabetIndexer = new AlphabetIndexer(null, ContactsQuery.SORT_KEY, alphabet);

    // Defines a span for highlighting the part of a display name that matches the search
    // string
    highlightTextSpan = new TextAppearanceSpan(getActivity(), R.style.searchTextHiglight);
}
项目:incant    文件:Incant.java   
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    storyLister = new StoryLister(this);
    storyList = (ListView) findViewById(R.id.storylist);
    storyListAdapter = new StoryListAdapter();

    storyList.setAdapter(storyListAdapter);

    titleStyle = new TextAppearanceSpan(this, R.style.story_title);
    authorStyle = new TextAppearanceSpan(this, R.style.story_author);
    headlineStyle = new TextAppearanceSpan(this, R.style.story_headline);
    descriptionStyle = new TextAppearanceSpan(this, R.style.story_description);
    saveTimeStyle = new TextAppearanceSpan(this, R.style.story_save_time);
    downloadTimeStyle = new TextAppearanceSpan(this, R.style.story_download_time);

    coverImageCache = new LruCache<String,Bitmap>(10);
}
项目:sms_DualCard    文件:MessagingNotification.java   
public CharSequence formatPictureMessage(Context context) {
    final TextAppearanceSpan notificationSubjectSpan = new TextAppearanceSpan(
            context, R.style.NotificationPrimaryText);

    // Change multiple newlines (with potential white space between), into a single new line
    final String message =
            !TextUtils.isEmpty(mMessage) ? mMessage.replaceAll("\\n\\s+", "\n") : "";

    // Show the subject or the message (if no subject)
    SpannableStringBuilder spannableStringBuilder = new SpannableStringBuilder();
    if (!TextUtils.isEmpty(mSubject)) {
        spannableStringBuilder.append(mSubject);
        spannableStringBuilder.setSpan(notificationSubjectSpan, 0, mSubject.length(), 0);
    }
    if (message.length() > 0 && spannableStringBuilder.length() == 0) {
        spannableStringBuilder.append(message);
        spannableStringBuilder.setSpan(notificationSubjectSpan, 0, message.length(), 0);
    }
    return spannableStringBuilder;
}
项目:sms_DualCard    文件:MessagingNotification.java   
private static CharSequence formatSenders(Context context,
        ArrayList<NotificationInfo> senders) {
    final TextAppearanceSpan notificationSenderSpan = new TextAppearanceSpan(
            context, R.style.NotificationPrimaryText);

    String separator = context.getString(R.string.enumeration_comma);   // ", "
    SpannableStringBuilder spannableStringBuilder = new SpannableStringBuilder();
    int len = senders.size();
    for (int i = 0; i < len; i++) {
        if (i > 0) {
            spannableStringBuilder.append(separator);
        }
        spannableStringBuilder.append(senders.get(i).mSender.getName());
    }
    spannableStringBuilder.setSpan(notificationSenderSpan, 0,
            spannableStringBuilder.length(), 0);
    return spannableStringBuilder;
}
项目:sms_DualCard    文件:MessagingNotification.java   
private static CharSequence getAttachmentTypeString(Context context, int attachmentType) {
   final TextAppearanceSpan notificationAttachmentSpan = new TextAppearanceSpan(
           context, R.style.NotificationSecondaryText);
   int id = 0;
   switch (attachmentType) {
       case WorkingMessage.AUDIO: id = R.string.attachment_audio; break;
       case WorkingMessage.VIDEO: id = R.string.attachment_video; break;
       case WorkingMessage.SLIDESHOW: id = R.string.attachment_slideshow; break;
       case WorkingMessage.IMAGE: id = R.string.attachment_picture; break;
   }
   if (id > 0) {
       final SpannableString spannableString = new SpannableString(context.getString(id));
       spannableString.setSpan(notificationAttachmentSpan,
               0, spannableString.length(), 0);
       return spannableString;
   }
   return null;
}
项目:WayHoo    文件:QueryCityActivity.java   
public CharSequence formatBigMessage(String city) {
    final TextAppearanceSpan notificationSubjectSpan = new TextAppearanceSpan(
            this, R.style.NotificationPrimaryText);

    // Change multiple newlines (with potential white space between), into a
    // single new line
    final String message = !TextUtils.isEmpty(city) ? city : "";
    String afterStr = "(点击重新定位)";
    SpannableStringBuilder spannableStringBuilder = new SpannableStringBuilder(
            message);
    if (!TextUtils.isEmpty(afterStr)) {
        spannableStringBuilder.append(afterStr);
        spannableStringBuilder.setSpan(notificationSubjectSpan,
                message.length(), message.length() + afterStr.length(), 0);
    }
    return spannableStringBuilder;
}
项目:egg-android    文件:AUtil.java   
public static void makeClickableTagsSpannable(Context context, SpannableStringBuilder span, String word, int textAppearance, final Runnable onClick) {
    //ForegroundColorSpan color_theme = new ForegroundColorSpan(color);
    TextAppearanceSpan appearanceSpan = new TextAppearanceSpan(context, textAppearance);
    int start = span.length();
    span.append(word);
    int end = span.length();
    span.setSpan(new ClickableSpan() {
        @Override
        public void onClick(View widget) {
            if (onClick != null) {
                onClick.run();
            }
        }

        @Override
        public void updateDrawState(TextPaint ds) {
            //ds.setColor(ds.linkColor);
            //ds.setUnderlineText(false);
        }
    }, start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    span.setSpan(appearanceSpan,
            start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);

}
项目:lifeograph-android    文件:ActivityEntry.java   
private void apply_heading() {
    int end = 0;
    if( mEditText.getText().charAt( 0 ) != '\n' )
        end = mEditText.getText().toString().indexOf( '\n' );
    if( end == -1 )
        end = mEditText.getText().length();

    addSpan( new TextAppearanceSpan( this, R.style.headingSpan ), 0, end,
             Spanned.SPAN_INTERMEDIATE );
    addSpan( new ForegroundColorSpan( m_ptr2entry.get_theme().color_heading ), 0, end, 0 );

    if( !mFlagSetTextOperation ) {
        m_ptr2entry.m_name = mEditText.getText().toString().substring( 0, end );
        // handle_entry_title_changed() will not be used here in Android
    }
}
项目:HoloIRC    文件:NotificationUtils.java   
private static CharSequence prependHighlightedText(Context context,
        String prefix, CharSequence message) {
    if (message == null || prefix == null) {
        return message;
    }

    TextAppearanceSpan highlightSpan = new TextAppearanceSpan(context,
            R.style.TextAppearance_StatusBar_EventContent_Emphasized);

    SpannableStringBuilder builder = new SpannableStringBuilder();
    builder.append(prefix);
    builder.setSpan(highlightSpan, 0, builder.length(), 0);
    builder.append(" ");
    builder.append(message);

    return builder;
}
项目:codeexamples-android    文件:MainActivity.java   
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    TextView textView = (TextView) findViewById(R.id.input);
    String header = "This is the header";
    String description = "This is the description";

    Spannable styledText = new SpannableString(header + "\n" + description);
    TextAppearanceSpan span1 = new TextAppearanceSpan(this,
            R.style.textHeader);
    TextAppearanceSpan span2 = new TextAppearanceSpan(this,
            R.style.textbody);
    styledText.setSpan(span1, 0, header.length(),
            Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    styledText.setSpan(span2, header.length() + 1, header.length() + 1
            + description.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    textView.setText(styledText);
}
项目:CountDownView    文件:CountDownView.java   
private void init(@Nullable AttributeSet attrs) {
    textPaint.setColor(Color.BLACK);

    int textSize;
    int startDuration;
    int textAppearanceRef;
    TypedArray ta = getContext().obtainStyledAttributes(attrs, R.styleable.CountDownView);
    startDuration = ta.getInt(R.styleable.CountDownView_startDuration, 0);
    textSize = ta.getDimensionPixelSize(R.styleable.CountDownView_android_textSize, (int) dpToPx(12, getResources()));
    textAppearanceRef = ta.getResourceId(R.styleable.CountDownView_android_textAppearance, 0);
    ta.recycle();

    textPaint.setTextSize(textSize);
    if (textAppearanceRef != 0) {
        textAppearanceSpan = new TextAppearanceSpan(getContext(), textAppearanceRef);
        textPaint.setTextSize(textAppearanceSpan.getTextSize());
    }
    setStartDuration(startDuration);
}
项目:android-aosp-mms    文件:MessagingNotification.java   
public CharSequence formatPictureMessage(Context context) {
    final TextAppearanceSpan notificationSubjectSpan = new TextAppearanceSpan(
            context, R.style.NotificationPrimaryText);

    // Change multiple newlines (with potential white space between), into a single new line
    final String message =
            !TextUtils.isEmpty(mMessage) ? mMessage.replaceAll("\\n\\s+", "\n") : "";

    // Show the subject or the message (if no subject)
    SpannableStringBuilder spannableStringBuilder = new SpannableStringBuilder();
    if (!TextUtils.isEmpty(mSubject)) {
        spannableStringBuilder.append(mSubject);
        spannableStringBuilder.setSpan(notificationSubjectSpan, 0, mSubject.length(), 0);
    }
    if (message.length() > 0 && spannableStringBuilder.length() == 0) {
        spannableStringBuilder.append(message);
        spannableStringBuilder.setSpan(notificationSubjectSpan, 0, message.length(), 0);
    }
    return spannableStringBuilder;
}
项目:android-aosp-mms    文件:MessagingNotification.java   
private static CharSequence formatSenders(Context context,
        ArrayList<NotificationInfo> senders) {
    final TextAppearanceSpan notificationSenderSpan = new TextAppearanceSpan(
            context, R.style.NotificationPrimaryText);

    String separator = context.getString(R.string.enumeration_comma);   // ", "
    SpannableStringBuilder spannableStringBuilder = new SpannableStringBuilder();
    int len = senders.size();
    for (int i = 0; i < len; i++) {
        if (i > 0) {
            spannableStringBuilder.append(separator);
        }
        spannableStringBuilder.append(senders.get(i).mSender.getName());
    }
    spannableStringBuilder.setSpan(notificationSenderSpan, 0,
            spannableStringBuilder.length(), 0);
    return spannableStringBuilder;
}
项目:android-aosp-mms    文件:MessagingNotification.java   
private static CharSequence getAttachmentTypeString(Context context, int attachmentType) {
   final TextAppearanceSpan notificationAttachmentSpan = new TextAppearanceSpan(
           context, R.style.NotificationSecondaryText);
   int id = 0;
   switch (attachmentType) {
       case WorkingMessage.AUDIO: id = R.string.attachment_audio; break;
       case WorkingMessage.VIDEO: id = R.string.attachment_video; break;
       case WorkingMessage.SLIDESHOW: id = R.string.attachment_slideshow; break;
       case WorkingMessage.IMAGE: id = R.string.attachment_picture; break;
   }
   if (id > 0) {
       final SpannableString spannableString = new SpannableString(context.getString(id));
       spannableString.setSpan(notificationAttachmentSpan,
               0, spannableString.length(), 0);
       return spannableString;
   }
   return null;
}
项目:DebugOverlay-Android    文件:MemInfoViewModule.java   
@Override
public void onDataAvailable(MemInfo data) {
    ActivityManager.MemoryInfo systemMemInfo = data.getSystemMemInfo();
    Debug.MemoryInfo procMemInfo = data.getProcessMemInfo();

    if (DebugOverlay.isDebugLoggingEnabled()) {
        Log.d(TAG, "MemTotal(MB):" + DECIMAL_FORMAT.format(systemMemInfo.totalMem / 1048576f));
        Log.d(TAG, "MemAvail(MB):" + DECIMAL_FORMAT.format(systemMemInfo.availMem / 1048576f));
        Log.d(TAG, "MemThreshold(MB):" + DECIMAL_FORMAT.format(systemMemInfo.threshold / 1048576f));
        Log.d(TAG, "TotalPss(MB):" + DECIMAL_FORMAT.format(procMemInfo.getTotalPss() / 1024f));
        Log.d(TAG, "TotalPrivateDirty(MB):" + DECIMAL_FORMAT.format(procMemInfo.getTotalPrivateDirty() / 1024f));
    }

    if (memInfoTxtView != null) {
        StringBuilder builder = new StringBuilder(HEADER);
        builder.append(DECIMAL_FORMAT.format(systemMemInfo.availMem / 1048576f)).append(" ")
                .append(DECIMAL_FORMAT.format(procMemInfo.getTotalPss() / 1024f)).append(" ")
                .append(DECIMAL_FORMAT.format(procMemInfo.getTotalPrivateDirty() / 1024f));

        SpannableStringBuilder spannableBuilder = new SpannableStringBuilder(builder.toString());
        if (systemMemInfo.lowMemory) {
            spannableBuilder.setSpan(
                    new TextAppearanceSpan(memInfoTxtView.getContext(), R.style.debugoverlay_LowMemoryTextAppearance),
                    HEADER.length(),
                    spannableBuilder.length(),
                    Spannable.SPAN_EXCLUSIVE_EXCLUSIVE
            );
        }
        memInfoTxtView.setText(spannableBuilder);
    }
}
项目:CSipSimple    文件:SuggestionsAdapter.java   
private CharSequence formatUrl(CharSequence url) {
    if (mUrlColor == null) {
        // Lazily get the URL color from the current theme.
        TypedValue colorValue = new TypedValue();
        mContext.getTheme().resolveAttribute(R.attr.textColorSearchUrl, colorValue, true);
        mUrlColor = mContext.getResources().getColorStateList(colorValue.resourceId);
    }

    SpannableString text = new SpannableString(url);
    text.setSpan(new TextAppearanceSpan(null, 0, 0, mUrlColor, null),
            0, url.length(),
            Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    return text;
}
项目:markor    文件:MarkdownHeaderSpanCreator.java   
public ParcelableSpan create(Matcher m, int iM) {
    final char[] charSequence = extractMatchingRange(m);
    Float proportion = calculateProportionBasedOnHeaderType(charSequence);
    Float size = calculateAdjustedSize(proportion);
    return new TextAppearanceSpan(_highlighter._fontType, Typeface.BOLD, (int) size.byteValue(),
            ColorStateList.valueOf(_color), null);
}
项目:markor    文件:Highlighter.java   
protected void clearSpans(Editable editable) {
    clearCharacterSpanType(editable, TextAppearanceSpan.class);
    clearCharacterSpanType(editable, ForegroundColorSpan.class);
    clearCharacterSpanType(editable, BackgroundColorSpan.class);
    clearCharacterSpanType(editable, StrikethroughSpan.class);
    clearCharacterSpanType(editable, RelativeSizeSpan.class);
    clearCharacterSpanType(editable, StyleSpan.class);
    clearCharacterSpanType(editable, ColorUnderlineSpan.class);
    clearParagraphSpanType(editable, LineBackgroundSpan.class);
    clearParagraphSpanType(editable, LineHeightSpan.class);
}