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;
}
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;
}
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);
}
}
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));
}
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;
}
}
Aggregations