List of usage examples for android.text.style ImageSpan ImageSpan
public ImageSpan(@NonNull Context context, @DrawableRes int resourceId)
From source file:android_network.hetnet.vpn_service.AdapterRule.java
private void markPro(MenuItem menu, String sku) { if (true) {//w w w .j av a2s. com 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); } }
From source file:eu.faircode.netguard.ActivitySettings.java
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(/* w w w. j a va 2 s .c o m*/ 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); } }
From source file:org.miaowo.miaowo.util.Html.java
private static void startImg(Editable text, Attributes attributes, Html.ImageGetter img, Context context) { String src = attributes.getValue("", "src"); Drawable d = null;//from w w w . j a va 2 s .com if (img != null) { d = img.getDrawable(src); } if (d == null) { d = ResourcesCompat.getDrawable(context.getResources(), R.drawable.unknown_image, null); d.setBounds(0, 0, d.getIntrinsicWidth(), d.getIntrinsicHeight()); } int len = text.length(); text.append("\uFFFC"); text.setSpan(new ImageSpan(d, src), len, text.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); }
From source file:android_network.hetnet.vpn_service.ActivitySettings.java
private void markPro(Preference pref, String sku) { if (sku == null) { SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); boolean dark = prefs.getBoolean("dark_theme", false); SpannableStringBuilder ssb = new SpannableStringBuilder(" " + pref.getTitle()); ssb.setSpan(//w w w.j a va 2 s . co m 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); } }
From source file:org.sirimangalo.meditationplus.ActivityMain.java
private void populateOnline(JSONArray onlines) { if (onlines.length() == 0) { onlineList.setVisibility(View.GONE); return;//from ww w.j a v a2 s . com } onlineList.setVisibility(View.VISIBLE); ArrayList<JSONObject> onlineArray = new ArrayList<JSONObject>(); ArrayList<String> onlineNamesArray = new ArrayList<String>(); // collect into array for (int i = 0; i < onlines.length(); i++) { try { JSONObject a = onlines.getJSONObject(i); onlineArray.add(a); onlineNamesArray.add(a.getString("username")); } catch (JSONException e) { e.printStackTrace(); } } String text = getString(R.string.online) + " "; // add spans int pos = text.length(); // start after "Online: " text += TextUtils.join(", ", onlineNamesArray); Spannable span = new SpannableString(text); span.setSpan(new StyleSpan(Typeface.BOLD), 0, pos, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); // bold the "Online: " Drawable android = context.getResources().getDrawable(R.drawable.android); android.setBounds(0, 0, 48, 32); for (JSONObject oneOnA : onlineArray) { try { final String oneOn = oneOnA.getString("username"); int end = pos + oneOn.length(); boolean isMed = false; for (int j = 0; j < jsonList.length(); j++) { JSONObject user = jsonList.getJSONObject(j); String username = user.getString("username"); if (username.equals(oneOn)) isMed = true; } if (oneOnA.getString("source").equals("android")) { ImageSpan image = new ImageSpan(android, ImageSpan.ALIGN_BASELINE); span.setSpan(image, pos - 1, pos, Spannable.SPAN_INCLUSIVE_EXCLUSIVE); } ClickableSpan clickable = new ClickableSpan() { @Override public void onClick(View widget) { showProfile(oneOn); } }; span.setSpan(clickable, pos, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); span.setSpan(new UnderlineSpan() { public void updateDrawState(TextPaint tp) { tp.setUnderlineText(false); } }, pos, end, 0); span.setSpan(new ForegroundColorSpan(isMed ? 0xFF009900 : 0xFFFF9900), pos, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); pos += oneOn.length() + 2; } catch (JSONException e) { e.printStackTrace(); } } onlineList.setText(span); onlineList.setMovementMethod(LinkMovementMethod.getInstance()); }