Java Code Examples for android.text.style.TextAppearanceSpan

The following are top voted examples for showing how to use android.text.style.TextAppearanceSpan. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: MultiContactPicker   File: MultiContactPickerAdapter.java   Source Code and License 6 votes vote down vote up
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);
    }
}
 
Example 2
Project: Applozic-Android-Chat-Sample   File: QuickConversationAdapter.java   Source Code and License 6 votes vote down vote up
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);
}
 
Example 3
Project: Applozic-Android-Chat-Sample   File: ChannelFragment.java   Source Code and License 6 votes vote down vote up
/**
 * 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);
}
 
Example 4
Project: Applozic-Android-Chat-Sample   File: ContactsListFragment.java   Source Code and License 6 votes vote down vote up
/**
 * 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);
}
 
Example 5
Project: Applozic-Android-Chat-Sample   File: ContactSelectionFragment.java   Source Code and License 6 votes vote down vote up
/**
 * 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);
}
 
Example 6
Project: Applozic-Android-Chat-Sample   File: AppContactFragment.java   Source Code and License 6 votes vote down vote up
/**
 * 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);
}
 
Example 7
Project: Applozic-Android-Chat-Sample   File: QuickConversationAdapter.java   Source Code and License 6 votes vote down vote up
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);
}
 
Example 8
Project: Applozic-Android-Chat-Sample   File: ChannelFragment.java   Source Code and License 6 votes vote down vote up
/**
 * 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);
}
 
Example 9
Project: Applozic-Android-Chat-Sample   File: ContactsListFragment.java   Source Code and License 6 votes vote down vote up
/**
 * 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);
}
 
Example 10
Project: Applozic-Android-Chat-Sample   File: ContactSelectionFragment.java   Source Code and License 6 votes vote down vote up
/**
 * 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);
}
 
Example 11
Project: Applozic-Android-Chat-Sample   File: AppContactFragment.java   Source Code and License 6 votes vote down vote up
/**
 * 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);
}
 
Example 12
Project: android_packages_apps_tv   File: ScheduledRecordingPresenter.java   Source Code and License 6 votes vote down vote up
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);
}
 
Example 13
Project: android_packages_apps_tv   File: DvrDetailsFragment.java   Source Code and License 6 votes vote down vote up
/**
 * 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;
}
 
Example 14
Project: myapplication   File: FindSearchAdapter.java   Source Code and License 6 votes vote down vote up
@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));
    }
 
Example 15
Project: EasyGank   File: DailyDetailAdapter.java   Source Code and License 6 votes vote down vote up
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;
}
 
Example 16
Project: margarita   File: ContactFragment.java   Source Code and License 6 votes vote down vote up
/**
 * 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);
}
 
Example 17
Project: Applozic-Android-SDK   File: QuickConversationAdapter.java   Source Code and License 6 votes vote down vote up
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);
}
 
Example 18
Project: Applozic-Android-SDK   File: ChannelFragment.java   Source Code and License 6 votes vote down vote up
/**
 * 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);
}
 
Example 19
Project: Applozic-Android-SDK   File: ContactsListFragment.java   Source Code and License 6 votes vote down vote up
/**
 * 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);
}
 
Example 20
Project: Applozic-Android-SDK   File: ContactSelectionFragment.java   Source Code and License 6 votes vote down vote up
/**
 * 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);
}
 
Example 21
Project: Applozic-Android-SDK   File: AppContactFragment.java   Source Code and License 6 votes vote down vote up
/**
 * 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);
}
 
Example 22
Project: Handbook_for_Melee   File: SearchAdapter.java   Source Code and License 6 votes vote down vote up
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);
    }
}
 
Example 23
Project: CampusFeedv2   File: ContactsListFragment.java   Source Code and License 6 votes vote down vote up
/**
 * 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);
}
 
Example 24
Project: incant   File: Incant.java   Source Code and License 6 votes vote down vote up
@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);
}
 
Example 25
Project: sms_DualCard   File: MessagingNotification.java   Source Code and License 6 votes vote down vote up
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;
}
 
Example 26
Project: sms_DualCard   File: MessagingNotification.java   Source Code and License 6 votes vote down vote up
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;
}
 
Example 27
Project: sms_DualCard   File: MessagingNotification.java   Source Code and License 6 votes vote down vote up
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;
}
 
Example 28
Project: WayHoo   File: QueryCityActivity.java   Source Code and License 6 votes vote down vote up
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;
}
 
Example 29
Project: egg-android   File: AUtil.java   Source Code and License 6 votes vote down vote up
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);

}
 
Example 30
Project: lifeograph-android   File: ActivityEntry.java   Source Code and License 6 votes vote down vote up
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
    }
}
 
Example 31
Project: HoloIRC   File: NotificationUtils.java   Source Code and License 6 votes vote down vote up
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;
}
 
Example 32
Project: codeexamples-android   File: MainActivity.java   Source Code and License 6 votes vote down vote up
@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);
}
 
Example 33
Project: CountDownView   File: CountDownView.java   Source Code and License 6 votes vote down vote up
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);
}
 
Example 34
Project: android-aosp-mms   File: MessagingNotification.java   Source Code and License 6 votes vote down vote up
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;
}
 
Example 35
Project: android-aosp-mms   File: MessagingNotification.java   Source Code and License 6 votes vote down vote up
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;
}
 
Example 36
Project: android-aosp-mms   File: MessagingNotification.java   Source Code and License 6 votes vote down vote up
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;
}
 
Example 37
Project: DebugOverlay-Android   File: MemInfoViewModule.java   Source Code and License 5 votes vote down vote up
@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);
    }
}
 
Example 38
Project: CSipSimple   File: SuggestionsAdapter.java   Source Code and License 5 votes vote down vote up
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;
}
 
Example 39
Project: markor   File: MarkdownHeaderSpanCreator.java   Source Code and License 5 votes vote down vote up
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);
}
 
Example 40
Project: markor   File: Highlighter.java   Source Code and License 5 votes vote down vote up
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);
}
 
Example 41
Project: Protein   File: AboutFragment.java   Source Code and License 5 votes vote down vote up
@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);

    toolbar.setNavigationIcon(R.drawable.ic_arrow_back_white_24dp);
    toolbar.getNavigationIcon().setColorFilter(
            getResources().getColor(R.color.icon_grey), PorterDuff.Mode.SRC_ATOP);
    toolbar.setNavigationOnClickListener(v -> getActivity().onBackPressed());

    int padding = getResources().getDimensionPixelSize(R.dimen.about_header_padding);
    bannerImage.setPadding(padding, padding, padding, padding);
    Glide.with(this)
            .load(R.drawable.egg)
            .into(bannerImage);

    Spannable span = new SpannableString(title.getContext().getString(R.string.about_title));
    span.setSpan(new TextAppearanceSpan(title.getContext(),
                    R.style.ProteinTextAppearance_Regular_XXL_Primary), 0, 7,
            Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    span.setSpan(new TextAppearanceSpan(title.getContext(),
                    R.style.ProteinTextAppearance_Regular_L_Hint), 7, span.length(),
            Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    title.setText(span);
    versionName.setText(versionName.getContext().getString(R.string.about_version, BuildConfig.VERSION_NAME));

    layoutGe.setOnClickListener(aboutOnClickListener);
    layoutMelodie.setOnClickListener(aboutOnClickListener);
    layoutOthers.setOnClickListener(aboutOnClickListener);
    versionLayout.setOnClickListener(aboutOnClickListener);
    licenseLayout.setOnClickListener(aboutOnClickListener);
    shareLayout.setOnClickListener(aboutOnClickListener);
}
 
Example 42
Project: SpanEZ   File: SpanEZTest.java   Source Code and License 5 votes vote down vote up
@SuppressWarnings("ResourceType")
@Test
public void appearance_should_add_only_one_span() {
    spanBuilder.appearance(range, INTEGER_ARG)
               .apply();

    verify((SpanEZ) spanBuilder, times(1))
            .addSpan(isA(TargetRange.class), isA(TextAppearanceSpan.class));
}
 
Example 43
Project: buildAPKsApps   File: RecipientsEditor.java   Source Code and License 5 votes vote down vote up
RecipientsEditorTokenizer(Context context, MultiAutoCompleteTextView list) {
    mInflater = LayoutInflater.from(context);
    mList = list;

    final int size = android.R.style.TextAppearance_Small;
    final int color = 8;//android.R.styleable.Theme_textColorSecondary;
    mLabelSpan = new TextAppearanceSpan(context, size, color);
    mTypeSpan = new TextAppearanceSpan(context, size, color);
}
 
Example 44
Project: CurveView   File: CurveView.java   Source Code and License 5 votes vote down vote up
public Mark(String content, int gravity, int marginStart, int marginTop, int marginEnd, int marginBottom, TextAppearanceSpan mTextAppearanceSpan) {
    this.content = content;
    this.gravity = gravity;
    this.marginStart = marginStart;
    this.marginEnd = marginEnd;
    this.marginTop = marginTop;
    this.marginBottom = marginBottom;
    this.textAppearanceSpan = mTextAppearanceSpan;
}
 
Example 45
Project: spanner   File: Spans.java   Source Code and License 5 votes vote down vote up
/**
 * @see android.text.style.TextAppearanceSpan#TextAppearanceSpan(String, int, int, ColorStateList, ColorStateList)
 */
public static Span appearance(@Nullable final String family, final int style, final int size, @Nullable final ColorStateList color, @Nullable final ColorStateList linkColor) {
    return new Span(new SpanBuilder() {
        @Override
        public Object build() {
            return new TextAppearanceSpan(family, style, size, color, linkColor);
        }
    });
}
 
Example 46
Project: boohee_v5.6   File: SuggestionsAdapter.java   Source Code and License 5 votes vote down vote up
private CharSequence formatUrl(CharSequence url) {
    if (this.mUrlColor == null) {
        TypedValue colorValue = new TypedValue();
        this.mContext.getTheme().resolveAttribute(R.attr.textColorSearchUrl, colorValue, true);
        this.mUrlColor = this.mContext.getResources().getColorStateList(colorValue.resourceId);
    }
    SpannableString text = new SpannableString(url);
    text.setSpan(new TextAppearanceSpan(null, 0, 0, this.mUrlColor, null), 0, url.length(), 33);
    return text;
}
 
Example 47
Project: social-app-android   File: ProfileActivity.java   Source Code and License 5 votes vote down vote up
private Spannable buildCounterSpannable(String label, int value) {
    SpannableStringBuilder contentString = new SpannableStringBuilder();
    contentString.append(String.valueOf(value));
    contentString.append("\n");
    int start = contentString.length();
    contentString.append(label);
    contentString.setSpan(new TextAppearanceSpan(this, R.style.TextAppearance_Second_Light), start, contentString.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    return contentString;
}
 
Example 48
Project: hintcase   File: SimpleHintContentHolder.java   Source Code and License 5 votes vote down vote up
private View getTextViewTitle(Context context) {
    LinearLayout.LayoutParams linearLayoutParamsTitle =
            new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
                    ViewGroup.LayoutParams.WRAP_CONTENT);
    linearLayoutParamsTitle.setMargins(0, 20, 0, 20);
    TextView textViewTitle = new TextView(context);
    textViewTitle.setLayoutParams(linearLayoutParamsTitle);
    textViewTitle.setGravity(Gravity.CENTER_HORIZONTAL);
    SpannableString spannableStringTitle= new SpannableString(contentTitle);
    TextAppearanceSpan titleTextAppearanceSpan = new TextAppearanceSpan(context, titleStyleId);
    spannableStringTitle.setSpan(titleTextAppearanceSpan, 0, spannableStringTitle.length(), 0);
    textViewTitle.setText(spannableStringTitle);
    return textViewTitle;
}
 
Example 49
Project: hintcase   File: SimpleHintContentHolder.java   Source Code and License 5 votes vote down vote up
private View getTextViewDescription(Context context) {
    LinearLayout.LayoutParams linearLayoutParamsText =
            new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
                    ViewGroup.LayoutParams.WRAP_CONTENT);
    TextView textViewDescription = new TextView(context);
    textViewDescription.setLayoutParams(linearLayoutParamsText);
    textViewDescription.setGravity(Gravity.CENTER_HORIZONTAL);
    SpannableString spannableStringText= new SpannableString(contentText);
    TextAppearanceSpan textTextAppearanceSpan = new TextAppearanceSpan(context, textStyleId);
    spannableStringText.setSpan(textTextAppearanceSpan, 0, spannableStringText.length(), 0);
    textViewDescription.setText(spannableStringText);
    return textViewDescription;
}
 
Example 50
Project: hintcase   File: CustomHintContentHolder.java   Source Code and License 5 votes vote down vote up
private View getTextViewTitle(Context context) {
    LinearLayout.LayoutParams linearLayoutParamsTitle =
            new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
                    ViewGroup.LayoutParams.WRAP_CONTENT);
    linearLayoutParamsTitle.setMargins(0, 0, 0, 20);
    TextView textViewTitle = new TextView(context);
    textViewTitle.setLayoutParams(linearLayoutParamsTitle);
    textViewTitle.setGravity(Gravity.CENTER_HORIZONTAL);
    SpannableString spannableStringTitle= new SpannableString(contentTitle);
    TextAppearanceSpan titleTextAppearanceSpan = new TextAppearanceSpan(context, titleStyleId);
    spannableStringTitle.setSpan(titleTextAppearanceSpan, 0, spannableStringTitle.length(), 0);
    textViewTitle.setText(spannableStringTitle);
    return textViewTitle;
}
 
Example 51
Project: hintcase   File: CustomHintContentHolder.java   Source Code and License 5 votes vote down vote up
private View getTextViewDescription(Context context) {
    LinearLayout.LayoutParams linearLayoutParamsText =
            new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
                    ViewGroup.LayoutParams.WRAP_CONTENT);
    TextView textViewDescription = new TextView(context);
    textViewDescription.setLayoutParams(linearLayoutParamsText);
    textViewDescription.setGravity(Gravity.CENTER_HORIZONTAL);
    SpannableString spannableStringText= new SpannableString(contentText);
    TextAppearanceSpan textTextAppearanceSpan = new TextAppearanceSpan(context, textStyleId);
    spannableStringText.setSpan(textTextAppearanceSpan, 0, spannableStringText.length(), 0);
    textViewDescription.setText(spannableStringText);
    return textViewDescription;
}
 
Example 52
Project: solved-hacking-problem   File: da.java   Source Code and License 5 votes vote down vote up
private CharSequence m2687b(CharSequence charSequence) {
    if (this.f1492r == null) {
        TypedValue typedValue = new TypedValue();
        this.d.getTheme().resolveAttribute(C0233b.textColorSearchUrl, typedValue, true);
        this.f1492r = this.d.getResources().getColorStateList(typedValue.resourceId);
    }
    CharSequence spannableString = new SpannableString(charSequence);
    spannableString.setSpan(new TextAppearanceSpan(null, 0, 0, this.f1492r, null), 0, charSequence.length(), 33);
    return spannableString;
}
 
Example 53
Project: solved-hacking-problem   File: da.java   Source Code and License 5 votes vote down vote up
private CharSequence m2687b(CharSequence charSequence) {
    if (this.f1492r == null) {
        TypedValue typedValue = new TypedValue();
        this.d.getTheme().resolveAttribute(C0233b.textColorSearchUrl, typedValue, true);
        this.f1492r = this.d.getResources().getColorStateList(typedValue.resourceId);
    }
    CharSequence spannableString = new SpannableString(charSequence);
    spannableString.setSpan(new TextAppearanceSpan(null, 0, 0, this.f1492r, null), 0, charSequence.length(), 33);
    return spannableString;
}
 
Example 54
Project: android-common-util-light   File: StyledText.java   Source Code and License 5 votes vote down vote up
public StyledText appendComplex(CharSequence text,String family,int style,int size,
		int normalSelectorId,int linkSelectorId,Context context){
	Resources res = context.getResources();
	ColorStateList normalColorState = res.getColorStateList(normalSelectorId);
	ColorStateList linkColorState = res.getColorStateList(linkSelectorId);
	return append(text, new TextAppearanceSpan(family, style, size, normalColorState,linkColorState));
}
 
Example 55
Project: android-common-util-light   File: StyledText.java   Source Code and License 5 votes vote down vote up
/**
 * @param family 3种字体 eg:{@linkplain StyledText#FAMILY_MONOSPACE} 
 * @param style  eg: android.graphics.Typeface.BOLD_ITALIC
 * @param normalColors 颜色数组:包括 正常颜色,选中颜色,按压颜色
 * @param linkColors   颜色数组:包括 正常颜色,选中颜色,按压颜色
 * @param text the text
 * @param size the size
 * @param context the context
 * @return this
 */
public StyledText appendComplex(CharSequence text,String family,int style,int size,
		int[] normalColors,int[] linkColors,Context context){
	if(normalColors.length!=3 || linkColors.length!=3)
		throw new IllegalArgumentException();
	
	ColorStateList normalColorState = SelectorUtil.getSelectorColor(context,
			normalColors[0], normalColors[1], normalColors[2]);
	ColorStateList linkColorState = SelectorUtil.getSelectorColor(context,
			linkColors[0], linkColors[1], linkColors[2]);
	
	return append(text, new TextAppearanceSpan(family, style, size, normalColorState,linkColorState));
}
 
Example 56
Project: permissionsModule   File: SuggestionsAdapter.java   Source Code and License 5 votes vote down vote up
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_ox, 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;
}
 
Example 57
Project: android_packages_apps_tv   File: ProgramItemView.java   Source Code and License 5 votes vote down vote up
private void initIfNeeded() {
    if (sVisibleThreshold != 0) {
        return;
    }
    Resources res = getContext().getResources();

    sVisibleThreshold = res.getDimensionPixelOffset(
            R.dimen.program_guide_table_item_visible_threshold);

    sItemPadding = res.getDimensionPixelOffset(R.dimen.program_guide_table_item_padding);
    sCompoundDrawablePadding = res.getDimensionPixelOffset(
            R.dimen.program_guide_table_item_compound_drawable_padding);

    ColorStateList programTitleColor = ColorStateList.valueOf(res.getColor(
            R.color.program_guide_table_item_program_title_text_color, null));
    ColorStateList grayedOutProgramTitleColor = res.getColorStateList(
            R.color.program_guide_table_item_grayed_out_program_text_color, null);
    ColorStateList episodeTitleColor = ColorStateList.valueOf(res.getColor(
            R.color.program_guide_table_item_program_episode_title_text_color, null));
    ColorStateList grayedOutEpisodeTitleColor = ColorStateList.valueOf(res.getColor(
            R.color.program_guide_table_item_grayed_out_program_episode_title_text_color,
            null));
    int programTitleSize = res.getDimensionPixelSize(
            R.dimen.program_guide_table_item_program_title_font_size);
    int episodeTitleSize = res.getDimensionPixelSize(
            R.dimen.program_guide_table_item_program_episode_title_font_size);

    sProgramTitleStyle = new TextAppearanceSpan(null, 0, programTitleSize, programTitleColor,
            null);
    sGrayedOutProgramTitleStyle = new TextAppearanceSpan(null, 0, programTitleSize,
            grayedOutProgramTitleColor, null);
    sEpisodeTitleStyle = new TextAppearanceSpan(null, 0, episodeTitleSize, episodeTitleColor,
            null);
    sGrayedOutEpisodeTitleStyle = new TextAppearanceSpan(null, 0, episodeTitleSize,
            grayedOutEpisodeTitleColor, null);
}
 
Example 58
Project: android_packages_apps_tv   File: RecordingDetailsFragment.java   Source Code and License 5 votes vote down vote up
private DetailsContent createDetailsContent() {
    Channel channel = TvApplication.getSingletons(getContext()).getChannelDataManager()
            .getChannel(mRecording.getChannelId());
    SpannableString title = mRecording.getProgramTitleWithEpisodeNumber(getContext()) == null ?
            null : new SpannableString(mRecording
            .getProgramTitleWithEpisodeNumber(getContext()));
    if (TextUtils.isEmpty(title)) {
        title = new SpannableString(channel != null ? channel.getDisplayName()
                : getContext().getResources().getString(
                R.string.no_program_information));
    } else {
        String programTitle = mRecording.getProgramTitle();
        title.setSpan(new TextAppearanceSpan(getContext(),
                R.style.text_appearance_card_view_episode_number), programTitle == null ? 0
                : programTitle.length(), title.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    }
    String description = !TextUtils.isEmpty(mRecording.getProgramDescription()) ?
            mRecording.getProgramDescription() :  mRecording.getProgramLongDescription();
    if (TextUtils.isEmpty(description)) {
        description = channel != null ? channel.getDescription() : null;
    }
    return new DetailsContent.Builder()
            .setTitle(title)
            .setStartTimeUtcMillis(mRecording.getStartTimeMs())
            .setEndTimeUtcMillis(mRecording.getEndTimeMs())
            .setDescription(description)
            .setImageUris(mRecording.getProgramPosterArtUri(),
                    mRecording.getProgramThumbnailUri(), channel)
            .build();
}
 
Example 59
Project: Derpibooru   File: ImageTagView.java   Source Code and License 5 votes vote down vote up
private void setTextSpanStyle(int tagNameSpanStyle) {
    String numberOfImages = String.format(" (%d)", mTag.getNumberOfImages());

    Spannable text = new SpannableString(mTag.getName() + numberOfImages);
    text.setSpan(new TextAppearanceSpan(getContext(), tagNameSpanStyle), 0,
                 mTag.getName().length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    text.setSpan(new TextAppearanceSpan(getContext(), R.style.ImageTagNumberOfImages), mTag.getName().length(),
                 (mTag.getName().length() + numberOfImages.length()), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);

    textTag.setText(text, TextView.BufferType.SPANNABLE);
}
 
Example 60
Project: darksms   File: SuggestionsAdapter.java   Source Code and License 5 votes vote down vote up
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;
}