use of android.text.style.ForegroundColorSpan in project Anki-Android by Ramblurr.
the class CompatV11 method setSubtitle.
@Override
public void setSubtitle(Activity activity, String title, boolean inverted) {
ActionBar ab = activity.getActionBar();
if (ab != null) {
if (inverted) {
CharacterStyle span = new ForegroundColorSpan(activity.getResources().getColor(inverted ? R.color.white : R.color.black));
SpannableStringBuilder ssb = new SpannableStringBuilder(title);
ssb.setSpan(span, 0, ssb.length(), 0);
ab.setSubtitle(ssb);
} else {
ab.setSubtitle(title);
}
}
}
use of android.text.style.ForegroundColorSpan in project Anki-Android by Ramblurr.
the class CompatV11 method setTitle.
@Override
public void setTitle(Activity activity, String title, boolean inverted) {
ActionBar ab = activity.getActionBar();
if (ab != null) {
CharacterStyle span = new ForegroundColorSpan(activity.getResources().getColor(inverted ? R.color.white : R.color.black));
SpannableStringBuilder ssb = new SpannableStringBuilder(title);
ssb.setSpan(span, 0, ssb.length(), 0);
ab.setTitle(ssb);
}
}
use of android.text.style.ForegroundColorSpan in project KeepScore by nolanlawson.
the class AbstractHistoryTableFragment method createHistoryItemView.
protected View createHistoryItemView(ViewGroup parent, HistoryItem historyItem, int layoutResId, int rowId, boolean weightIsOne, Activity activity) {
View view = getInflater().inflate(layoutResId, parent, false);
// alternating colors for the background, from gray to white
view.setBackgroundColor(getResources().getColor(rowId % 2 == 0 ? android.R.color.background_light : R.color.light_gray));
TextView textView1 = (TextView) view.findViewById(android.R.id.text1);
TextView textView2 = (TextView) view.findViewById(android.R.id.text2);
if (historyItem == null) {
// null indicates to leave the text views empty
setDummyTextView(textView1);
setDummyTextView(textView2);
return weightIsOne ? setLayoutWeightToOne(view) : view;
}
textView2.setVisibility(View.VISIBLE);
if (historyItem.isHideDelta()) {
setDummyTextView(textView1);
// set as gone to ensure that
textView1.setVisibility(View.GONE);
// the first line isn't too tall
// when we use
// history_item_tall.xml
} else {
int delta = historyItem.getDelta();
SpannableString deltaSpannable = new SpannableString(IntegerUtil.toCharSequenceWithSign(delta));
int colorResId = delta >= 0 ? (PreferenceHelper.getGreenTextPreference(activity) ? // green
ColorScheme.Light.getGreenPositiveColorResId() : // blue
ColorScheme.Light.getPositiveColorResId()) : // red
ColorScheme.Light.getNegativeColorResId();
ForegroundColorSpan colorSpan = new ForegroundColorSpan(getResources().getColor(colorResId));
deltaSpannable.setSpan(colorSpan, 0, deltaSpannable.length(), Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
textView1.setVisibility(View.VISIBLE);
textView1.setText(deltaSpannable);
}
textView2.setText(Long.toString(historyItem.getRunningTotal()));
return weightIsOne ? setLayoutWeightToOne(view) : view;
}
use of android.text.style.ForegroundColorSpan in project KeepScore by nolanlawson.
the class AutofitTextView method onMeasure.
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
int height = getHeight() - getCompoundPaddingBottom() - getCompoundPaddingTop();
int maxNumLines = (height / getLineHeight());
if (maxNumLines >= 2) {
String oldText = getText().toString();
int cutoffIndex = StringUtil.getNthIndexOf('\n', oldText, maxNumLines);
if (cutoffIndex != -1) {
// cut off the text
int startOfLastLine = StringUtil.getNthIndexOf('\n', oldText, maxNumLines - 1);
// make the last line semi-transparent, to indicate that there
// are more results left
// (similar to the ellipsize effect in normal text views, but
// vertical)
// get the original color (blue or red)
ForegroundColorSpan[] foregroundColorSpans = ((SpannedString) getText()).getSpans(startOfLastLine + 1, cutoffIndex, ForegroundColorSpan.class);
// make an alpha-ized gradient out of the original color
int originalColor = foregroundColorSpans[0].getForegroundColor();
int startColor = (START_ALPHA << 24) | (0x00FFFFFF & originalColor);
int endColor = (END_ALPHA << 24) | (0x00FFFFFF & originalColor);
int numLines = StringUtil.count(getText().subSequence(0, cutoffIndex).toString(), "\n");
float startY = (numLines * getLineHeight());
float endY = startY + getLineHeight();
// build up a new spannable
SpannableStringBuilder builder = new SpannableStringBuilder().append(getText().subSequence(0, startOfLastLine)).append(getText().subSequence(startOfLastLine, cutoffIndex).toString());
builder.setSpan(new TopDownGradientSpan(startColor, endColor, startY, endY), startOfLastLine, cutoffIndex, 0);
setText(builder);
}
}
}
use of android.text.style.ForegroundColorSpan in project FlexibleAdapter by davideas.
the class Utils method highlightText.
/**
* Sets a spannable text with the accent color (if available) into the provided TextView.
* <p>Internally calls {@link #fetchAccentColor(Context, int)}.</p>
*
* @param context context
* @param textView the TextView to transform
* @param originalText the original text which the transformation is applied to
* @param constraint the text to highlight
* @param defColor the default color in case accentColor is not found
* @see #fetchAccentColor(Context, int)
* @deprecated Use
* {@link #highlightText(TextView, String, String, int)} OR
* {@link #highlightText(TextView, String, String)}
*/
@Deprecated
public static void highlightText(@NonNull Context context, @NonNull TextView textView, String originalText, String constraint, @ColorInt int defColor) {
if (originalText == null)
originalText = "";
if (constraint == null)
constraint = "";
int i = originalText.toLowerCase(Locale.getDefault()).indexOf(constraint.toLowerCase(Locale.getDefault()));
if (i != -1) {
Spannable spanText = Spannable.Factory.getInstance().newSpannable(originalText);
spanText.setSpan(new ForegroundColorSpan(fetchAccentColor(context, defColor)), i, i + constraint.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
spanText.setSpan(new StyleSpan(Typeface.BOLD), i, i + constraint.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
textView.setText(spanText, TextView.BufferType.SPANNABLE);
} else {
textView.setText(originalText, TextView.BufferType.NORMAL);
}
}
Aggregations