List of usage examples for android.text.style ForegroundColorSpan ForegroundColorSpan
public ForegroundColorSpan(@NonNull Parcel src)
From source file:org.sirimangalo.meditationplus.ActivityMain.java
private void populateMeds(JSONArray meds) { if (findViewById(R.id.med_list) == null) return;//from w w w . jav a2 s . c o m medList = (ListView) findViewById(R.id.med_list); medArray = new ArrayList<JSONObject>(); for (int i = 0; i < meds.length(); i++) { try { JSONObject med = meds.getJSONObject(i); if (med.getString("username").equals(username)) { if (startMeditating) { startMeditating = false; if (lastWalking > 0 || lastSitting > 0) scheduleClient.setAlarmForNotification(lastWalking, lastSitting); } if (med.getString("type").equals("love")) { special = "love"; Spannable span = new SpannableString("LOVE"); span.setSpan(new ForegroundColorSpan(Color.RED), 0, 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); span.setSpan(new ForegroundColorSpan(Color.YELLOW), 1, 2, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); span.setSpan(new ForegroundColorSpan(Color.GREEN), 2, 3, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); span.setSpan(new ForegroundColorSpan(Color.BLUE), 3, 4, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); medButton.setText(span); } else { special = "none"; medButton.setText(R.string.start); } } medArray.add(med); } catch (JSONException e) { e.printStackTrace(); } } TextView emptyText = (TextView) findViewById(android.R.id.empty); medList.setEmptyView(emptyText); AdapterMed adapter = new AdapterMed(this, R.layout.list_item_med, medArray, postHandler); medList.setAdapter(adapter); }
From source file:kr.wdream.storyshop.AndroidUtilities.java
public static SpannableStringBuilder replaceTags(String str, int flag) { try {// ww w . j a v a2s.c om int start; int end; StringBuilder stringBuilder = new StringBuilder(str); if ((flag & FLAG_TAG_BR) != 0) { while ((start = stringBuilder.indexOf("<br>")) != -1) { stringBuilder.replace(start, start + 4, "\n"); } while ((start = stringBuilder.indexOf("<br/>")) != -1) { stringBuilder.replace(start, start + 5, "\n"); } } ArrayList<Integer> bolds = new ArrayList<>(); if ((flag & FLAG_TAG_BOLD) != 0) { while ((start = stringBuilder.indexOf("<b>")) != -1) { stringBuilder.replace(start, start + 3, ""); end = stringBuilder.indexOf("</b>"); if (end == -1) { end = stringBuilder.indexOf("<b>"); } stringBuilder.replace(end, end + 4, ""); bolds.add(start); bolds.add(end); } } ArrayList<Integer> colors = new ArrayList<>(); if ((flag & FLAG_TAG_COLOR) != 0) { while ((start = stringBuilder.indexOf("<c#")) != -1) { stringBuilder.replace(start, start + 2, ""); end = stringBuilder.indexOf(">", start); int color = Color.parseColor(stringBuilder.substring(start, end)); stringBuilder.replace(start, end + 1, ""); end = stringBuilder.indexOf("</c>"); stringBuilder.replace(end, end + 4, ""); colors.add(start); colors.add(end); colors.add(color); } } SpannableStringBuilder spannableStringBuilder = new SpannableStringBuilder(stringBuilder); for (int a = 0; a < bolds.size() / 2; a++) { spannableStringBuilder.setSpan(new TypefaceSpan(AndroidUtilities.getTypeface("fonts/rmedium.ttf")), bolds.get(a * 2), bolds.get(a * 2 + 1), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); } for (int a = 0; a < colors.size() / 3; a++) { spannableStringBuilder.setSpan(new ForegroundColorSpan(colors.get(a * 3 + 2)), colors.get(a * 3), colors.get(a * 3 + 1), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); } return spannableStringBuilder; } catch (Exception e) { FileLog.e("tmessages", e); } return new SpannableStringBuilder(str); }
From source file:org.miaowo.miaowo.util.Html.java
private static void endCssStyle(Editable text) { Strikethrough s = getLast(text, Strikethrough.class); if (s != null) { setSpanFromMark(text, s, new StrikethroughSpan()); }//w ww . ja v a 2 s . co m Background b = getLast(text, Background.class); if (b != null) { setSpanFromMark(text, b, new BackgroundColorSpan(b.mBackgroundColor)); } Foreground f = getLast(text, Foreground.class); if (f != null) { setSpanFromMark(text, f, new ForegroundColorSpan(f.mForegroundColor)); } }
From source file:org.onebusaway.android.report.ui.Open311ProblemFragment.java
/** * Dynamically creates checkboxes/* ww w. ja v a 2 s .c o m*/ * * @param open311Attribute contains the open311 attributes */ private void createMultiValueList(Open311Attribute open311Attribute) { ArrayList<Object> values = (ArrayList<Object>) open311Attribute.getValues(); if (values != null && values.size() > 0) { LayoutInflater inflater = LayoutInflater.from(getActivity()); RelativeLayout layout = (RelativeLayout) inflater.inflate(R.layout.report_issue_multi_value_list_item, null, false); ((ImageView) layout.findViewById(R.id.ri_ic_checkbox)) .setColorFilter(getResources().getColor(R.color.material_gray)); Spannable word = new SpannableString(open311Attribute.getDescription()); ((TextView) layout.findViewById(R.id.rimvli_textView)).setText(word); if (open311Attribute.getRequired()) { Spannable wordTwo = new SpannableString(" *Required"); wordTwo.setSpan(new ForegroundColorSpan(Color.RED), 0, wordTwo.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); ((TextView) layout.findViewById(R.id.rimvli_textView)).append(wordTwo); } // Restore view state from attribute result hash map AttributeValue av = mAttributeValueHashMap.get(open311Attribute.getCode()); LinearLayout cg = (LinearLayout) layout.findViewById(R.id.rimvli_checkBoxGroup); for (int i = 0; i < values.size(); i++) { LinkedHashMap<String, String> value = (LinkedHashMap<String, String>) values.get(i); CheckBox cb = new CheckBox(getActivity()); cg.addView(cb); String attributeKey = ""; String attributeValue = ""; for (LinkedHashMap.Entry<String, String> entry : value.entrySet()) { if (Open311Attribute.NAME.equals(entry.getKey())) { cb.setText(entry.getValue()); if (av != null && av.getValues().contains(entry.getValue())) { cb.setChecked(true); } attributeKey = open311Attribute.getCode() + entry.getValue(); } else if (Open311Attribute.KEY.equals(entry.getKey())) { attributeValue = entry.getValue(); } } mOpen311AttributeKeyNameMap.put(attributeKey, attributeValue); } mInfoLayout.addView(layout); mDynamicAttributeUIMap.put(open311Attribute.getCode(), cg); } }
From source file:com.bt.heliniumstudentapp.MainActivity.java
protected static void setToolbarTitle(AppCompatActivity context, String title, String subtitle) { final Spannable toolbarTitle = new SpannableString(title); toolbarTitle.setSpan(new ForegroundColorSpan(ContextCompat.getColor(context, primaryTextColor)), 0, toolbarTitle.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); try {//from w w w . j a va 2 s . co m context.getSupportActionBar().setTitle(toolbarTitle); } catch (NullPointerException e) { return; } if (subtitle != null) { final Spannable toolbarSubtitle = new SpannableString(subtitle); toolbarSubtitle.setSpan(new ForegroundColorSpan(ContextCompat.getColor(context, secondaryTextColor)), 0, toolbarSubtitle.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); context.getSupportActionBar().setSubtitle(toolbarSubtitle); } }
From source file:org.miaowo.miaowo.util.Html.java
private static void endFont(Editable text) { int len = text.length(); Font f = getLast(text, Font.class); int where = text.getSpanStart(f); text.removeSpan(f);//from w ww . ja va 2 s .c om if (where != len) { if (!TextUtils.isEmpty(f.mColor)) { if (f.mColor.startsWith("@")) { Resources res = Resources.getSystem(); String name = f.mColor.substring(1); int colorRes = res.getIdentifier(name, "color", "android"); if (colorRes != 0) { ColorStateList colors = ResourcesCompat.getColorStateList(res, colorRes, null); text.setSpan(new TextAppearanceSpan(null, 0, 0, colors, null), where, len, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } } else { int c = Color.parseColor(f.mColor); if (c != -1) { text.setSpan(new ForegroundColorSpan(c | 0xFF000000), where, len, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } } } if (f.mFace != null) { text.setSpan(new TypefaceSpan(f.mFace), where, len, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } } }
From source file:com.edible.ocr.CaptureActivity.java
/** * Version of handleOcrContinuousDecode for failed OCR requests. Displays a failure message. * // w w w . jav a 2 s .co m * @param obj Metadata for the failed OCR request. */ void handleOcrContinuousDecode(OcrResultFailure obj) { lastResult = null; viewfinderView.removeResultText(); // Reset the text in the recognized text box. statusViewTop.setText(""); if (CONTINUOUS_DISPLAY_METADATA) { // Color text delimited by '-' as red. statusViewBottom.setTextSize(14); CharSequence cs = setSpanBetweenTokens("OCR: " + sourceLanguageReadable + " - OCR failed - Time required: " + obj.getTimeRequired() + " ms", "-", new ForegroundColorSpan(0xFFFF0000)); statusViewBottom.setText(cs); } }
From source file:org.sirimangalo.meditationplus.ActivityMain.java
private void populateOnline(JSONArray onlines) { if (onlines.length() == 0) { onlineList.setVisibility(View.GONE); return;/*from w ww . j a v a 2s . co m*/ } 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()); }
From source file:com.android.messaging.datamodel.MessageNotificationState.java
static CharSequence applyWarningTextColor(final Context context, final CharSequence text) { if (text == null) { return null; }/*w w w . ja v a 2 s .c o m*/ final SpannableStringBuilder spanBuilder = new SpannableStringBuilder(); spanBuilder.append(text); spanBuilder.setSpan( new ForegroundColorSpan(context.getResources().getColor(R.color.notification_warning_color)), 0, text.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); return spanBuilder; }
From source file:com.nttec.everychan.ui.gallery.GalleryActivity.java
private Spanned getSpannedText(String message) { message = " " + message + " "; SpannableStringBuilder spanned = new SpannableStringBuilder(message); for (Object span : new Object[] { new ForegroundColorSpan(Color.WHITE), new BackgroundColorSpan(Color.parseColor("#88000000")) }) { spanned.setSpan(span, 0, message.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); }//from ww w . j a va 2s. c o m return spanned; }