Search in sources :

Example 76 with SpannableString

use of android.text.SpannableString in project letterpress by Pixplicity.

the class FontUtil method applyTypeface.

@NonNull
public static SpannableString applyTypeface(@NonNull final String text, @NonNull final Typeface typeface) {
    SpannableString spannableString = new SpannableString(text);
    FontSpan span = new FontSpan(typeface);
    spannableString.setSpan(span, 0, spannableString.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    return spannableString;
}
Also used : SpannableString(android.text.SpannableString) NonNull(android.support.annotation.NonNull)

Example 77 with SpannableString

use of android.text.SpannableString in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class ClearDefaultsPreference method updateUI.

public boolean updateUI(PreferenceViewHolder view) {
    boolean hasBindAppWidgetPermission = mAppWidgetManager.hasBindAppWidgetPermission(mAppEntry.info.packageName);
    TextView autoLaunchView = (TextView) view.findViewById(R.id.auto_launch);
    boolean autoLaunchEnabled = AppUtils.hasPreferredActivities(mPm, mPackageName) || isDefaultBrowser(mPackageName) || AppUtils.hasUsbDefaults(mUsbManager, mPackageName);
    if (!autoLaunchEnabled && !hasBindAppWidgetPermission) {
        resetLaunchDefaultsUi(autoLaunchView);
    } else {
        boolean useBullets = hasBindAppWidgetPermission && autoLaunchEnabled;
        if (hasBindAppWidgetPermission) {
            autoLaunchView.setText(R.string.auto_launch_label_generic);
        } else {
            autoLaunchView.setText(R.string.auto_launch_label);
        }
        Context context = getContext();
        CharSequence text = null;
        int bulletIndent = context.getResources().getDimensionPixelSize(R.dimen.installed_app_details_bullet_offset);
        if (autoLaunchEnabled) {
            CharSequence autoLaunchEnableText = context.getText(R.string.auto_launch_enable_text);
            SpannableString s = new SpannableString(autoLaunchEnableText);
            if (useBullets) {
                s.setSpan(new BulletSpan(bulletIndent), 0, autoLaunchEnableText.length(), 0);
            }
            text = (text == null) ? TextUtils.concat(s, "\n") : TextUtils.concat(text, "\n", s, "\n");
        }
        if (hasBindAppWidgetPermission) {
            CharSequence alwaysAllowBindAppWidgetsText = context.getText(R.string.always_allow_bind_appwidgets_text);
            SpannableString s = new SpannableString(alwaysAllowBindAppWidgetsText);
            if (useBullets) {
                s.setSpan(new BulletSpan(bulletIndent), 0, alwaysAllowBindAppWidgetsText.length(), 0);
            }
            text = (text == null) ? TextUtils.concat(s, "\n") : TextUtils.concat(text, "\n", s, "\n");
        }
        autoLaunchView.setText(text);
        mActivitiesButton.setEnabled(true);
    }
    return true;
}
Also used : Context(android.content.Context) SpannableString(android.text.SpannableString) BulletSpan(android.text.style.BulletSpan) TextView(android.widget.TextView)

Example 78 with SpannableString

use of android.text.SpannableString in project android_frameworks_base by ResurrectionRemix.

the class LinkSpec method addLinks.

/**
     *  Applies a regex to the text of a TextView turning the matches into
     *  links.  If links are found then UrlSpans are applied to the link
     *  text match areas, and the movement method for the text is changed
     *  to LinkMovementMethod.
     *
     *  @param text TextView whose text is to be marked-up with links.
     *  @param pattern Regex pattern to be used for finding links.
     *  @param defaultScheme The default scheme to be prepended to links if the link does not
     *                       start with one of the <code>schemes</code> given.
     *  @param schemes Array of schemes (eg <code>http://</code>) to check if the link found
     *                 contains a scheme. Passing a null or empty value means prepend defaultScheme
     *                 to all links.
     *  @param matchFilter  The filter that is used to allow the client code additional control
     *                      over which pattern matches are to be converted into links.
     *  @param transformFilter Filter to allow the client code to update the link found.
     */
public static final void addLinks(@NonNull TextView text, @NonNull Pattern pattern, @Nullable String defaultScheme, @Nullable String[] schemes, @Nullable MatchFilter matchFilter, @Nullable TransformFilter transformFilter) {
    SpannableString spannable = SpannableString.valueOf(text.getText());
    boolean linksAdded = addLinks(spannable, pattern, defaultScheme, schemes, matchFilter, transformFilter);
    if (linksAdded) {
        text.setText(spannable);
        addLinkMovementMethod(text);
    }
}
Also used : SpannableString(android.text.SpannableString)

Example 79 with SpannableString

use of android.text.SpannableString in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class DataUsageSummary method formatTitle.

private static CharSequence formatTitle(Context context, String template, long usageLevel) {
    final SpannableString amountTemplate = new SpannableString(context.getString(com.android.internal.R.string.fileSizeSuffix).replace("%1$s", "^1").replace("%2$s", "^2"));
    verySmallSpanExcept(amountTemplate, "^1");
    final Formatter.BytesResult usedResult = Formatter.formatBytes(context.getResources(), usageLevel, Formatter.FLAG_SHORTER);
    final CharSequence formattedUsage = TextUtils.expandTemplate(amountTemplate, usedResult.value, usedResult.units);
    final SpannableString fullTemplate = new SpannableString(template.replace("%1$s", "^1"));
    verySmallSpanExcept(fullTemplate, "^1");
    return TextUtils.expandTemplate(fullTemplate, BidiFormatter.getInstance().unicodeWrap(formattedUsage));
}
Also used : SpannableString(android.text.SpannableString) Formatter(android.text.format.Formatter) BidiFormatter(android.text.BidiFormatter)

Example 80 with SpannableString

use of android.text.SpannableString in project UltimateAndroid by cymcsg.

the class PagerTitleStrip method changeSpanString.

//    Handler textHandler=new Handler(){
//        /**
//         * Subclasses must implement this to receive messages.
//         *
//         * @param msg
//         */
//        @Override
//        public void handleMessage(Message msg) {
//            super.handleMessage(msg);
//            if (msg.what==1){
//                Bundle bundle=msg.getData();
//                mCurrText.setText(
//                        changeSpanString(bundle.getString("string"), bundle.getInt("int"), 1) );
//            }else{
//                mCurrText.setText(null);
//            }
//        }
//    };
SpannableString changeSpanString(String temp, int position, int color) {
    try {
        temp = temp.replaceAll("-", " - ");
        SpannableString ss = new SpannableString(temp);
        Matrix matrix = new Matrix();
        matrix.postRotate(180);
        Bitmap bitmaporg = BitmapFactory.decodeResource(getResources(), R.drawable.ico_arrow2x);
        if (color == 2) {
            bitmaporg = BitmapFactory.decodeResource(getResources(), R.drawable.ico_arrow_grey2x);
        }
        Bitmap resizedBitmap = Bitmap.createBitmap(bitmaporg, 0, 0, bitmaporg.getWidth(), bitmaporg.getHeight(), matrix, true);
        BitmapDrawable bmd = new BitmapDrawable(getResources(), resizedBitmap);
        BitmapDrawable bm = new BitmapDrawable(getResources(), bitmaporg);
        Drawable drawable = position == 0 ? bm : bmd;
        drawable.setBounds(0, 0, drawable.getIntrinsicWidth() * 12 / 10, drawable.getIntrinsicHeight() * 12 / 10);
        ImageSpan imageSpan = new ImageSpan(drawable, ImageSpan.ALIGN_BASELINE);
        ss.setSpan(imageSpan, temp.indexOf("-"), temp.indexOf("-") + 1, Spanned.SPAN_INCLUSIVE_INCLUSIVE);
        return ss;
    } catch (Exception e) {
        e.printStackTrace();
        Logs.e(e, "");
        return null;
    }
}
Also used : SpannableString(android.text.SpannableString) Bitmap(android.graphics.Bitmap) Matrix(android.graphics.Matrix) BitmapDrawable(android.graphics.drawable.BitmapDrawable) Drawable(android.graphics.drawable.Drawable) BitmapDrawable(android.graphics.drawable.BitmapDrawable) ImageSpan(android.text.style.ImageSpan)

Aggregations

SpannableString (android.text.SpannableString)325 TextView (android.widget.TextView)61 Spannable (android.text.Spannable)60 View (android.view.View)57 StyleSpan (android.text.style.StyleSpan)53 ForegroundColorSpan (android.text.style.ForegroundColorSpan)47 TextPaint (android.text.TextPaint)25 Spanned (android.text.Spanned)24 TextAppearanceSpan (android.text.style.TextAppearanceSpan)21 Paint (android.graphics.Paint)20 RelativeSizeSpan (android.text.style.RelativeSizeSpan)19 ImageView (android.widget.ImageView)19 Bundle (android.os.Bundle)17 TypedValue (android.util.TypedValue)17 SmallTest (android.test.suitebuilder.annotation.SmallTest)16 Intent (android.content.Intent)15 SpannableStringBuilder (android.text.SpannableStringBuilder)15 ClickableSpan (android.text.style.ClickableSpan)14 URLSpan (android.text.style.URLSpan)13 LayoutInflater (android.view.LayoutInflater)13