use of android.text.style.ImageSpan in project android_frameworks_base by AOSPA.
the class RestrictedLockUtils method setMenuItemAsDisabledByAdmin.
/**
* Set the menu item as disabled by admin by adding a restricted padlock at the end of the
* text and set the click listener which will send an intent to show the admin support details
* dialog. If the admin is null, remove the padlock and disabled color span. When the admin is
* null, we also set the OnMenuItemClickListener to null, so if you want to set a custom
* OnMenuItemClickListener, set it after calling this method.
*/
public static void setMenuItemAsDisabledByAdmin(final Context context, final MenuItem item, final EnforcedAdmin admin) {
SpannableStringBuilder sb = new SpannableStringBuilder(item.getTitle());
removeExistingRestrictedSpans(sb);
if (admin != null) {
final int disabledColor = context.getColor(R.color.disabled_text_color);
sb.setSpan(new ForegroundColorSpan(disabledColor), 0, sb.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
ImageSpan image = new RestrictedLockImageSpan(context);
sb.append(" ", image, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
sendShowAdminSupportDetailsIntent(context, admin);
return true;
}
});
} else {
item.setOnMenuItemClickListener(null);
}
item.setTitle(sb);
}
use of android.text.style.ImageSpan in project DanmakuFlameMaster by Bilibili.
the class MainActivity method createSpannable.
private SpannableStringBuilder createSpannable(Drawable drawable) {
String text = "bitmap";
SpannableStringBuilder spannableStringBuilder = new SpannableStringBuilder(text);
//ImageSpan.ALIGN_BOTTOM);
ImageSpan span = new ImageSpan(drawable);
spannableStringBuilder.setSpan(span, 0, text.length(), Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
spannableStringBuilder.append("图文混排");
spannableStringBuilder.setSpan(new BackgroundColorSpan(Color.parseColor("#8A2233B1")), 0, spannableStringBuilder.length(), Spannable.SPAN_INCLUSIVE_INCLUSIVE);
return spannableStringBuilder;
}
use of android.text.style.ImageSpan in project NetGuard by M66B.
the class AdapterRule method markPro.
private void markPro(MenuItem menu, String sku) {
if (sku == null || !IAB.isPurchased(sku, context)) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
boolean dark = prefs.getBoolean("dark_theme", false);
SpannableStringBuilder ssb = new SpannableStringBuilder(" " + menu.getTitle());
ssb.setSpan(new ImageSpan(context, dark ? R.drawable.ic_shopping_cart_white_24dp : R.drawable.ic_shopping_cart_black_24dp), 0, 1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
menu.setTitle(ssb);
}
}
use of android.text.style.ImageSpan in project NetGuard by M66B.
the class ActivitySettings method markPro.
private void markPro(Preference pref, String sku) {
if (sku == null || !IAB.isPurchased(sku, this)) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
boolean dark = prefs.getBoolean("dark_theme", false);
SpannableStringBuilder ssb = new SpannableStringBuilder(" " + pref.getTitle());
ssb.setSpan(new ImageSpan(this, dark ? R.drawable.ic_shopping_cart_white_24dp : R.drawable.ic_shopping_cart_black_24dp), 0, 1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
pref.setTitle(ssb);
}
}
use of android.text.style.ImageSpan in project android_frameworks_base by AOSPA.
the class SmileyParser method getSpannableString.
/**
* Retrieves the parsed text as a spannable string object.
* @param context the context for fetching smiley resources.
* @return the spannable string as CharSequence.
*/
public CharSequence getSpannableString(Context context) {
SpannableStringBuilder builder = new SpannableStringBuilder();
if (getPartCount() == 0) {
return "";
}
// should have only one part since we parse smiley only
Part part = getPart(0);
ArrayList<Token> tokens = part.getTokens();
int len = tokens.size();
for (int i = 0; i < len; i++) {
Token token = tokens.get(i);
int start = builder.length();
builder.append(token.getRawText());
if (token.getType() == AbstractMessageParser.Token.Type.SMILEY) {
int resid = mRes.getSmileyRes(token.getRawText());
if (resid != -1) {
builder.setSpan(new ImageSpan(context, resid), start, builder.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
}
}
}
return builder;
}
Aggregations