Example usage for android.text.style StyleSpan StyleSpan

List of usage examples for android.text.style StyleSpan StyleSpan

Introduction

In this page you can find the example usage for android.text.style StyleSpan StyleSpan.

Prototype

public StyleSpan(@NonNull Parcel src) 

Source Link

Document

Creates a StyleSpan from a parcel.

Usage

From source file:com.dimasdanz.kendalipintu.util.CommonUtilities.java

public static void generateNotification(Context context, String message, String time, String info) {
    try {/*www .  ja va 2s .  c om*/
        NotificationManager manager;
        int notificationID = 73;

        Bitmap largeIcon = BitmapFactory.decodeResource(context.getResources(),
                R.drawable.ic_stat_notification);

        Notification.Builder builder = new Notification.Builder(context);
        Intent resultIntent = new Intent(context, LogActivity.class);
        TaskStackBuilder stackBuilder = TaskStackBuilder.create(context);

        stackBuilder.addParentStack(LogActivity.class);
        stackBuilder.addNextIntent(resultIntent);

        PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
        Spannable sb = new SpannableString(message + " " + time + "-" + info);
        sb.setSpan(new StyleSpan(android.graphics.Typeface.BOLD), 0, message.length(),
                Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);

        builder.setAutoCancel(true);
        builder.setDefaults(Notification.DEFAULT_LIGHTS | Notification.DEFAULT_SOUND);
        builder.setContentTitle(context.getString(R.string.notification_title));
        builder.setContentText(sb);
        builder.setTicker(context.getString(R.string.notification_ticker));
        builder.setNumber(++msgCounter);
        builder.setSmallIcon(R.drawable.ic_stat_notification);
        builder.setLargeIcon(largeIcon);
        builder.setContentIntent(resultPendingIntent);

        if (msgCounter > 1) {
            Notification.InboxStyle inboxStyle = new Notification.InboxStyle();
            if (msgCounter > 6) {
                name[0] = new SpannableString("...");
                name[1] = name[2];
                name[2] = name[3];
                name[3] = name[4];
                name[4] = name[5];
                name[5] = sb;
            } else {
                name[msgCounter - 1] = sb;
            }

            inboxStyle.setBigContentTitle(context.getString(R.string.notification_title));
            inboxStyle.setSummaryText(
                    msgCounter + " " + context.getString(R.string.notification_title) + " Baru");

            for (int i = name.length; i > 0; i--) {
                inboxStyle.addLine(name[i - 1]);
            }

            builder.setStyle(inboxStyle);
            builder.setContentText(msgCounter + " " + context.getString(R.string.notification_title) + " Baru");
        } else {
            name[0] = sb;
        }
        manager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
        manager.notify(notificationID, builder.build());
    } catch (NullPointerException e) {
        e.printStackTrace();
    }

}

From source file:cat.mvmike.minimalcalendarwidget.service.DayService.java

private static void setInstanceNumber(final Context context, final RemoteViews cellRv, final String dayOfMonth,
        final boolean isToday, final int found) {

    Symbol symbols = ConfigurationService.getInstancesSymbols(context);
    Character[] symbolArray = symbols.getArray();

    int max = symbolArray.length - 1;
    String symbol = String.valueOf(found > max ? symbolArray[max] : symbolArray[found]);
    String dayOfMonthSpSt = PADDING + (dayOfMonth.length() == 1 ? dayOfMonth + DOUBLE_PADDING : dayOfMonth)
            + PADDING + symbol;//from  w  w w. jav  a  2 s.  c o m
    SpannableString daySpSt = new SpannableString(dayOfMonthSpSt);
    daySpSt.setSpan(new StyleSpan(Typeface.BOLD), dayOfMonthSpSt.length() - 1, dayOfMonthSpSt.length(),
            Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);

    int color;
    if (isToday) {
        color = ContextCompat.getColor(context, R.color.instances_today);
        daySpSt.setSpan(new StyleSpan(Typeface.BOLD), 0, dayOfMonthSpSt.length() - 1,
                Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    } else {
        color = ContextCompat.getColor(context,
                ConfigurationService.getInstancesSymbolsColours(context).getHexValue());
    }

    daySpSt.setSpan(new ForegroundColorSpan(color), dayOfMonthSpSt.length() - 1, dayOfMonthSpSt.length(),
            Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    daySpSt.setSpan(new RelativeSizeSpan(symbols.getRelativeSize()), dayOfMonthSpSt.length() - 1,
            dayOfMonthSpSt.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);

    cellRv.setTextViewText(android.R.id.text1, daySpSt);
}

From source file:com.github.michalbednarski.intentslab.browser.RegisteredReceiverFetcher.java

@Override
Object getEntries(Context context) {
    try {/*from  w  w w  . ja  v a 2 s  . c om*/
        final Categorizer<RegisteredReceiverInfo> categorizer = new ProcessCategorizer();
        (new RegisteredReceiversParser(mExcludeProtected) {
            @Override
            protected void onReceiverFound(RegisteredReceiverInfo receiverInfo) {
                categorizer.add(receiverInfo);
            }
        }).parse(context);
        return categorizer.getResult();
    } catch (SecurityException e) {
        // Create message about error
        SpannableStringBuilder ssb = new SpannableStringBuilder(
                context.getString(R.string.registered_receivers_denied));
        ssb.append("\n");
        int commandStart = ssb.length();
        if (ComponentFetcher.DEVELOPMENT_PERMISSIONS_SUPPORTED) {
            ssb.append("pm grant ").append(context.getPackageName()).append(" android.permission.DUMP");
        } else {
            ssb.append(RemoteEntryPoint.getScriptFile(context).getAbsolutePath());
        }
        int commandEnd = ssb.length();
        ssb.setSpan(new StyleSpan(Typeface.BOLD), commandStart, commandEnd, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        return new CustomError(ssb);
    } catch (Throwable e) {
        e.printStackTrace();
        return new CustomError(Utils.describeException(e));
    }
}

From source file:org.mariotaku.twidere.view.NameView.java

public NameView(final Context context, final AttributeSet attrs, final int defStyleAttr) {
    super(context, attrs, defStyleAttr);
    setSpannableFactory(new SafeSpannableFactory());
    setEditableFactory(new SafeEditableFactory());
    setEllipsize(TextUtils.TruncateAt.END);
    final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.NameView, defStyleAttr, 0);
    setPrimaryTextColor(a.getColor(R.styleable.NameView_nv_primaryTextColor, 0));
    setSecondaryTextColor(a.getColor(R.styleable.NameView_nv_secondaryTextColor, 0));
    setTwoLine(a.getBoolean(R.styleable.NameView_nv_twoLine, false));
    mPrimaryTextStyle = new StyleSpan(a.getInt(R.styleable.NameView_nv_primaryTextStyle, 0));
    mSecondaryTextStyle = new StyleSpan(a.getInt(R.styleable.NameView_nv_secondaryTextStyle, 0));
    a.recycle();//from w w  w .  j a  v  a 2 s . c  o  m
    setNameFirst(true);
    if (isInEditMode()) {
        setName("Name");
        setScreenName("@screenname");
        updateText();
    }
}

From source file:fyp.hkust.facet.activity.SettingsActivity.java

private void convertPreferenceToUseCustomFont(Preference somePreference) {
    Typeface fontType = FontManager.getTypeface(getApplicationContext(), FontManager.APP_FONT);

    CustomTypeFaceSpan customTypefaceSpan = new CustomTypeFaceSpan("", fontType);

    SpannableStringBuilder ss;/*from  w w  w. j ava  2  s .  c  om*/
    if (somePreference.getTitle() != null) {
        ss = new SpannableStringBuilder(somePreference.getTitle().toString());
        ss.setSpan(new StyleSpan(Typeface.BOLD), 0, ss.length(), 0);
        ss.setSpan(customTypefaceSpan, 0, ss.length(), Spanned.SPAN_EXCLUSIVE_INCLUSIVE);
        somePreference.setTitle(ss);
    }

    if (somePreference.getSummary() != null) {
        ss = new SpannableStringBuilder(somePreference.getSummary().toString());
        ss.setSpan(customTypefaceSpan, 0, ss.length(), Spanned.SPAN_EXCLUSIVE_INCLUSIVE);
        somePreference.setSummary(ss);
    }
}

From source file:com.bdevlin.apps.ui.fragments.HelpListFragment.java

private void updateText() {
    // mHelpText = (TextView) getView().findViewById(R.id.help_text);
    mHelpText = (WebView) getView().findViewById(R.id.webView1);
    mHelpText.getSettings().setJavaScriptEnabled(false);

    CharSequence text = Utils.bold(Utils.italic(getResources().getString(R.string.about_eula)),
            Utils.color(Color.RED, getResources().getString(R.string.about_licenses)));
    CharSequence yourHtml = "<table>table</table>";

    CharSequence content = getContent();
    ;//from  w w w .j  a  va  2 s  . com
    SpannedString sstr = SpannedString.valueOf(content);
    SpannedString message = SpannedString.valueOf(mMessage);
    SpannedString message2 = SpannedString.valueOf(text);
    SpannedString message3 = SpannedString.valueOf(yourHtml);

    SpannableStringBuilder aboutBody = new SpannableStringBuilder();
    aboutBody.append(Html.fromHtml(Html.toHtml(message)));
    aboutBody.append(Html.fromHtml(Html.toHtml(message2)));
    aboutBody.append(Html.fromHtml(Html.toHtml(message3)));
    aboutBody.append(Html.fromHtml(Html.toHtml(sstr)));
    aboutBody.setSpan(new StyleSpan(Typeface.ITALIC), 0, aboutBody.length(), 0);
    // mHelpText.setText(aboutBody);
    // mHelpText.loadData(Html.toHtml(aboutBody), "text/html", null);

    mHelpText.loadUrl("file:///android_asset/" + mTitle + ".html", null);

    //mHelpText.loadUrl("http://www.choosemyplate.gov/tools-supertracker");

}

From source file:org.solovyev.android.calculator.widget.CalculatorWidget.java

@Nonnull
private SpannedString initCursorString(@Nonnull Context context) {
    if (cursorString == null) {
        final SpannableString s = App.colorString("|",
                ContextCompat.getColor(context, R.color.cpp_widget_cursor));
        // this will override any other style span (f.e. italic)
        s.setSpan(new StyleSpan(Typeface.NORMAL), 0, 1, SpannableString.SPAN_EXCLUSIVE_EXCLUSIVE);
        cursorString = new SpannedString(s);
    }// ww w. j  a  v  a 2  s.c  om
    return cursorString;
}

From source file:com.supermario.kanjilookandlearn.view.ScreenSlidePageFragment.java

private void initView() {
    initId();/*www .  j a v a  2s.c o  m*/

    rootLayout.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            onCardClick(v);
        }
    });
    imageView.setImageDrawable(Utils.getDrawableFromAssets(getActivity(), kanjiItem.image));
    kanjiFaceTextView.setText(kanjiItem.kanji);

    // a SpannableStringBuilder containing text to display
    SpannableStringBuilder sb = new SpannableStringBuilder(kanjiItem.remember);

    // create a bold StyleSpan to be used on the SpannableStringBuilder
    StyleSpan b = new StyleSpan(android.graphics.Typeface.BOLD); // Span to make text bold

    int index = kanjiItem.remember.indexOf(kanjiItem.meanVietnamese);
    if (index >= 0) {
        // set only the name part of the SpannableStringBuilder to be bold --> 16, 16 + name.length()
        sb.setSpan(b, index, index + kanjiItem.meanVietnamese.length(), Spannable.SPAN_INCLUSIVE_INCLUSIVE);
    }

    kunyomiTextView.setText(kanjiItem.kunyomi);
    onyomiTextView.setText(kanjiItem.onyomi);

    rememberTextView.setText(sb);

    //        try {
    //            strokeWebView.loadDataWithBaseURL(null,Utils.getStringFromInputStream(Utils.getInputStreamFromAssets(getActivity(), "04e00")), "text/html", "UTF-8", null);
    //        } catch (IOException e) {
    //            e.printStackTrace();
    //        }

    if (kanjiItem.favorite == 1) {
        favoriteImageView.setImageResource(R.drawable.icon_favorite_active);
    } else {
        favoriteImageView.setImageResource(R.drawable.icon_favorite_inactive);
    }

    favoriteImageView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (kanjiItem.favorite == 0) {
                kanjiItem.favorite = 1;
                favoriteImageView.setImageResource(R.drawable.icon_favorite_active);
            } else {
                kanjiItem.favorite = 0;
                favoriteImageView.setImageResource(R.drawable.icon_favorite_inactive);
            }
            KanjiProvider.updateFavorite(getActivity(), kanjiItem);
        }
    });
}

From source file:com.oasisfeng.nevo.decorators.StackDecorator.java

@Override
public void apply(final StatusBarNotificationEvo evolved) throws RemoteException {
    final Collection<StatusBarNotificationEvo> history = getArchivedNotifications(evolved.getKey(),
            KMaxNumLines);/*from   www .  j  a  v a  2  s  .  c  om*/
    if (history.size() <= 1)
        return;
    final INotification evolved_n = evolved.notification();
    final IBundle evolved_extras = evolved_n.extras();
    if (evolved_extras.containsKey(EXTRA_TEXT_LINES))
        return; // Never stack already inbox-styled notification.

    final Calendar calendar = Calendar.getInstance();
    final List<CharSequence> lines = new ArrayList<>(KMaxNumLines);
    long previous_when = 0;
    final long latest_when = evolved_n.getWhen();
    for (final StatusBarNotificationEvo sbn : history) {
        final INotification n = sbn.notification();
        final CharSequence text = n.extras().getCharSequence(NotificationCompat.EXTRA_TEXT);
        if (text == null)
            continue;

        final long when = n.getWhen();
        if (when == latest_when || Math.abs(when - previous_when) <= KMinIntervalToShowTimestamp)
            lines.add(text);
        else { // Add time-stamp
            final SpannableStringBuilder line = new SpannableStringBuilder();
            calendar.setTimeInMillis(when);
            final String time_text = String.format((Locale) null, "%1$02d:%2$02d ", calendar.get(HOUR_OF_DAY),
                    calendar.get(MINUTE));
            line.append(time_text);
            line.append(text);
            line.setSpan(new StyleSpan(Typeface.BOLD), 0, 5, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
            lines.add(line);
        }
        previous_when = when;
    }
    if (lines.isEmpty())
        return;
    Collections.reverse(lines); // Latest first, since earliest lines will be trimmed by InboxStyle.

    final CharSequence title = evolved_extras.getCharSequence(NotificationCompat.EXTRA_TITLE);
    evolved_extras.putCharSequence(NotificationCompat.EXTRA_TITLE_BIG, title);
    evolved_extras.putCharSequenceArray(EXTRA_TEXT_LINES, lines);

    evolved_n.setBigContentView(buildBigContentView(evolved.getPackageName(), title, lines));
}

From source file:com.normalexception.app.rx8club.view.profile.ProfileViewArrayAdapter.java

public View getView(int position, View convertView, ViewGroup parent) {
    View vi = convertView;/*ww  w.j a  v  a  2s  .  com*/
    if (vi == null) {
        vi = new TextView(sourceFragment.getActivity());
    }

    TextView tv = (TextView) vi;
    final ProfileModel pm = data.get(position);
    String text = String.format("%s\n%s", pm.getName(), pm.getText());
    SpannableString spanString = new SpannableString(text);
    spanString.setSpan(new StyleSpan(Typeface.BOLD), 0, text.indexOf("\n"), 0);
    spanString.setSpan(new StyleSpan(Typeface.ITALIC), text.indexOf("\n") + 1, text.length(), 0);
    tv.setText(spanString);
    tv.setPadding(1, 10, 1, 10);
    tv.setBackgroundColor(Color.DKGRAY);
    tv.setTextColor(Color.WHITE);
    tv.setTextSize(10);
    tv.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View arg0) {
            Bundle args = new Bundle();
            args.putString("link", pm.getLink());
            args.putString("title", pm.getName());
            FragmentUtils.fragmentTransaction(sourceFragment.getActivity(), ThreadFragment.newInstance(), false,
                    true, args);
        }
    });

    return vi;
}