/** * Returns a SpannableString of the enabled days in an alarm,<br> * where the days are differently colored if enabled/disabled. * * @param alarm the alarm to make text for. * @return the string. */ public static final SpannableString makeEnabledDaysText(final Alarm alarm) { // Compute weekday names & join. String[] names = DateTextUtils.getWeekdayNames(ENABLED_DAYS_INDICE_LENGTH, Locale.getDefault()); SpannableString text = new SpannableString(StringUtils.WS_JOINER.join(names)); // Create spans for enabled days. boolean[] enabledDays = alarm.getEnabledDays(); if (enabledDays.length != names.length || names.length != 7) { throw new AssertionError("A week has 7 days, wrong array lengths!"); } int enabledColor = Color.WHITE; int disabledColor = SFApplication.get().getResources().getColor(R.color.nearly_background_text); int start = 0; for (int i = 0; i < enabledDays.length; i++) { boolean enabled = enabledDays[i]; int length = names[i].length(); int color = enabled ? enabledColor : disabledColor; text.setSpan(new ForegroundColorSpan(color), start, start + length, 0); start += length + 1; } return text; }
@Override public View getView(final int position, View convertView, ViewGroup parent) { if (convertView == null) { convertView = inflateLayout(); } TextView title = (TextView) convertView.findViewById(R.id.tv_search_result_title); TextView net = (TextView) convertView.findViewById(R.id.tv_search_result_original_net); TextView time = (TextView) convertView.findViewById(R.id.tv_search_result_time); SpannableString s = new SpannableString(mList.get(position).getTitle()); Pattern p = Pattern.compile(keyword); Matcher m = p.matcher(s); while (m.find()) { int start = m.start(); int end = m.end(); s.setSpan( new ForegroundColorSpan(mContext.getResources().getColor(R.color.orange)), start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); } title.setText(s); net.setText(mList.get(position).getSite()); time.setText(formatTime(mList.get(position).getCreateTime())); return convertView; }
public void load(View v) { BufferedReader br = null; try { br = new BufferedReader(new FileReader(mFile)); int len = Integer.parseInt(br.readLine()); BackgroundColorSpan[] spans = new BackgroundColorSpan[len]; int[] starts = new int[len]; int[] ends = new int[len]; for (int i = 0; i < len; i++) { String[] tokens = br.readLine().split(","); starts[i] = Integer.parseInt(tokens[0]); ends[i] = Integer.parseInt(tokens[1]); int color = Integer.parseInt(tokens[2]); spans[i] = new BackgroundColorSpan(color); } mText = br.readLine(); SpannableString s = new SpannableString(mText); for (int i = 0; i < len; i++) { s.setSpan(spans[i], starts[i], ends[i], Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } mTextView.setText(s); } catch (IOException e) { Log.e(TAG, "IO error", e); } finally { closeQuietly(br); } }
private void updateViews() { if (mTitle != null) { // Link the title to the entry URL SpannableString link = new SpannableString(mTitle); if (mUrl != null) { int start = 0; int end = mTitle.length(); int flags = 0; link.setSpan(new URLSpan(mUrl), start, end, flags); } mTitleView.setText(link); // Show the content, or the summary if no content is available. String body = !TextUtils.isEmpty(mContent) ? mContent : !TextUtils.isEmpty(mSummary) ? mSummary : ""; // Show the feed title in the window decorator. if (!TextUtils.isEmpty(mTitle)) { setTitle(mTitle); } else { Context context = getContext(); setTitle(context.getText(R.string.atom_title_entry)); } // Use loadDataWithBaseURL instead of loadData for unsanitized HTML: // http://code.google.com/p/android/issues/detail?id=1733 mContentView.clearView(); mContentView.loadDataWithBaseURL(null, body, MIME_TYPE, ENCODING, null); } }
public static SpannableString getSpannableString( String str, int firstIndex, int endIndex, Object style) { SpannableString spannableString = new SpannableString(str); spannableString.setSpan(style, firstIndex, endIndex, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); return spannableString; }
private void populateAdditionalStyles(LinkedTreeMap<String, Object> bean, SpannableString ss) { ArrayList<Integer> styles = (ArrayList<Integer>) bean.get("styles"); if (styles != null && styles.size() != 0) { ArrayList<Integer> starts = (ArrayList<Integer>) bean.get("starts"); ArrayList<Integer> ends = (ArrayList<Integer>) bean.get("ends"); for (int i = 0; i < styles.size(); i++) { int style = gson2Int(styles.get(i)); switch (style) { case ToolBar.StyleButton.HIGHLIGHT: ss.setSpan( new BackgroundColorSpan(Color.YELLOW), gson2Int(starts.get(i)), gson2Int(ends.get(i)), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); break; case ToolBar.StyleButton.UNDERLINE: ss.setSpan( new UnderlineSpan(), gson2Int(starts.get(i)), gson2Int(ends.get(i)), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); break; case ToolBar.StyleButton.STROKE: ss.setSpan( new StrikethroughSpan(), gson2Int(starts.get(i)), gson2Int(ends.get(i)), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); break; default: break; } } } }
/** 对spanableString进行正则判断,如果符合要求,则以表情图片代替 */ public static void dealExpression( Context context, SpannableString spannableString, Pattern patten, int start) throws Exception { Matcher matcher = patten.matcher(spannableString); while (matcher.find()) { String key = matcher.group(); Log.d("Key", key); if (matcher.start() < start) { continue; } Field field = R.drawable.class.getDeclaredField( "emoji_" + key.substring(key.indexOf("]") + 1, key.lastIndexOf("["))); int resId = Integer.parseInt(field.get(null).toString()); if (resId != 0) { Bitmap bitmap = BitmapFactory.decodeResource(context.getResources(), resId); ImageSpan imageSpan = new ImageSpan(bitmap); int end = matcher.start() + key.length(); spannableString.setSpan( imageSpan, matcher.start(), end, Spannable.SPAN_INCLUSIVE_EXCLUSIVE); if (end < spannableString.length()) { dealExpression(context, spannableString, patten, end); } break; } } }
/** 微博文字转表情 */ public static SpannableString text2Emotion(Context context, String key) { SpannableString spannable = new SpannableString(key); InputStream inputStream = null; Drawable drawable = null; try { inputStream = context.getAssets().open(TweetImageSpan.EMOTIONS_DIR + TweetImageSpan.EMOTIONS.get(key)); drawable = Drawable.createFromStream(inputStream, null); } catch (IOException e) { Log.e(TAG, "load emotion error!", e); } finally { if (inputStream != null) { try { inputStream.close(); } catch (IOException e) { Log.e(TAG, "close input error!", e); } } } if (drawable != null) { drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight()); ImageSpan span = new ImageSpan(drawable, ImageSpan.ALIGN_BASELINE); spannable.setSpan(span, 0, key.length(), Spannable.SPAN_INCLUSIVE_EXCLUSIVE); } return spannable; }
@Override public View onCreateView( LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { if (savedInstanceState != null) { mSquadId = savedInstanceState.getInt(SQUAD_ID); } SquadsDefinition defn = SquadsDefinition.getSquadsDefnInstance(getSherlockActivity()); Squad squad = defn.getSquad(mSquadId); View layout = inflater.inflate(R.layout.squad_write_up, null); TextView writeUpTv = (TextView) layout.findViewById(R.id.writeUpTV); writeUpTv.setText(squad.getWriteUp(getSherlockActivity())); TextView predictionTv = (TextView) layout.findViewById(R.id.predictionTv); String prediction = getSherlockActivity().getResources().getString(R.string.prediction); String fullPrediction = prediction + " " + squad.getPredictionString(getSherlockActivity()); SpannableString spannablePred = new SpannableString(fullPrediction); spannablePred.setSpan(new StyleSpan(Typeface.BOLD), 0, prediction.length(), 0); predictionTv.setText(spannablePred); return layout; }
public CharSequence getPageTitle(int position) { /* switch(position){ case 0: return "Tab 1"; case 1: return "Tab 2"; case 2: return "Tab 3"; } return null; */ // let's add an image // Generate title based on item position // return tabTitles[position]; // getDrawable(int i) is deprecated, use getDrawable(int i, Theme theme) for min SDK >=21 // or ContextCompat.getDrawable(Context context, int id) if you want support for older // versions. // Drawable image = context.getResources().getDrawable(iconIds[position], context.getTheme()); // Drawable image = context.getResources().getDrawable(imageResId[position]); Drawable image = ContextCompat.getDrawable(context, images[position]); image.setBounds(0, 0, image.getIntrinsicWidth(), image.getIntrinsicHeight()); SpannableString sb = new SpannableString(" " + strings[position]); ImageSpan imageSpan = new ImageSpan(image, ImageSpan.ALIGN_BOTTOM); sb.setSpan(imageSpan, 0, 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); return sb; }
private static void addDetectedValueHeader( @NonNull ListView listView, @StringRes int labelRes, @NonNull String labelKey, @NonNull String labelValue, @NonNull String value, @NonNull Icon icon) { final TextView textView = (TextView) LayoutInflater.from(listView.getContext()) .inflate(R.layout.edx_selectable_list_item, listView, false); { final SpannableString labelValueSpan = new SpannableString(labelValue); labelValueSpan.setSpan( new ForegroundColorSpan( listView.getResources().getColor(R.color.edx_grayscale_neutral_dark)), 0, labelValueSpan.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); textView.setText( ResourceUtil.getFormattedString( listView.getContext().getResources(), labelRes, labelKey, labelValueSpan)); } Context context = textView.getContext(); TextViewCompat.setCompoundDrawablesRelativeWithIntrinsicBounds( textView, new IconDrawable(context, icon) .sizeRes(context, R.dimen.edx_base) .colorRes(context, R.color.edx_grayscale_neutral_light), null, null, null); listView.addHeaderView(textView, new FormOption(labelValue, value), true); }
@Override public View getView(int position, View convertView, ViewGroup parent) { View item = inflater.inflate(R.layout.time_settings_item, null); if (position < times.size()) { SpannableString ss = new SpannableString( times.get(position) + " " + getString(R.string.min) + " (+" + increments.get(position) + getString(R.string.secPerMove) + ")"); ss.setSpan(new ForegroundColorSpan(0xFF000000), 0, 6, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); ss.setSpan( new ForegroundColorSpan(0xFF666666), 6, ss.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); ((TextView) item).setText(ss); } return item; }
@Override public View getDropDownView(int position, View convertView, ViewGroup parent) { View item = inflater.inflate(R.layout.time_settings_dropdown_item, null); item.setMinimumHeight(60); if (position >= times.size()) { ((CheckedTextView) item).setText(getText(R.string.customTime)); } else { SpannableString ss = new SpannableString( times.get(position) + " " + getString(R.string.min) + " (+" + increments.get(position) + getString(R.string.secPerMove) + ")"); ss.setSpan(new ForegroundColorSpan(0xFF000000), 0, 6, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); ss.setSpan( new ForegroundColorSpan(0xFF666666), 6, ss.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); ((CheckedTextView) item).setText(ss); } return item; }
public static SpannableString getCustomFace(final Context context, Bitmap bmp, String strFileName, ClickableSpan clickSpan) { if (null == context || null == bmp || isEmptyStr(strFileName)) return null; String str = "/c[\""; str += strFileName; str += "\"]"; // int cx = bmp.getWidth(); // int cy = bmp.getHeight(); // // Drawable drawable = new BitmapDrawable(bmp); // drawable.setBounds(0, 0, cx, cy); // ImageSpan imgSpan = new ImageSpan(drawable, ImageSpan.ALIGN_BASELINE); ImageSpan imgSpan = new ImageSpan(context, bmp, ImageSpan.ALIGN_BASELINE); SpannableString spanStr = new SpannableString(str); spanStr.setSpan(imgSpan, 0, str.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); if (clickSpan != null) { // ClickableSpan[] click_spans = spanStr.getSpans(0, str.length(), ClickableSpan.class); // if (click_spans.length != 0) { // for(ClickableSpan c_span : click_spans) { // spanStr.removeSpan(c_span); // } // } spanStr.setSpan(clickSpan, 0, str.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); } return spanStr; }
/** * 根据传入的字变换大小 * * @param text * @return */ public static SpannableString spanTextStyle(String text, float firstSize, float secondSize) { // TODO if (StringUtils.isEmpty(text)) { text = "0.00"; } double money = Double.parseDouble(text); DecimalFormat df = new DecimalFormat("0.00"); text = df.format(money); SpannableString mspTest = new SpannableString(text); int dot = text.indexOf('.'); if (dot > 0 && dot < text.length()) { mspTest.setSpan( new RelativeSizeSpan(firstSize), 0, dot, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); // 0.5f表示默认字体大小的一半 mspTest.setSpan( new RelativeSizeSpan(secondSize), dot, text.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); } else { mspTest.setSpan( new RelativeSizeSpan(firstSize), 0, text.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); } return mspTest; }
public final void run() { View localView = cy.b(this.gom); int i; String str2; if (this.val$visible) { i = 0; localView.setVisibility(i); String str1 = this.gom.getString(n.bpe); if (!cj.hX(this.dPV)) break label160; str2 = this.gom.getString(n.bpd); label55: if (this.eeS == null) break label169; SpannableString localSpannableString = new SpannableString(str2 + str1); localSpannableString.setSpan( new ForegroundColorSpan(-10119449), str2.length(), str2.length() + str1.length(), 33); cy.c(this.gom).setText(localSpannableString); } while (true) { cy.b(this.gom).invalidate(); cy.d(this.gom).invalidate(); return; i = 8; break; label160: str2 = this.dPV; break label55; label169: cy.c(this.gom).setText(str2); } }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_maps); SpannableString s = new SpannableString("Pregled svih ruta"); s.setSpan( new TypefaceSpan(this, "Choplin.otf"), 0, s.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); mToolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(mToolbar); getSupportActionBar().setDisplayShowHomeEnabled(true); getSupportActionBar().setTitle(s); mRecyclerView = (RecyclerView) findViewById(R.id.my_recycler_view); LinearLayoutManager llm = new LinearLayoutManager(this); mRecyclerView.setLayoutManager(llm); NavigationDrawerFragment drawerFragment = (NavigationDrawerFragment) getSupportFragmentManager().findFragmentById(R.id.fragment_navigation_drawer); drawerFragment.setUp( R.id.fragment_navigation_drawer, (DrawerLayout) findViewById(R.id.drawer_layout), mToolbar); initializeData(); }
/** * toSpannableString * * @return SpannableString * @throws */ public static SpannableString toSpannableString(Context context, String text) { if (!TextUtils.isEmpty(text)) { SpannableString spannableString = new SpannableString(text); int start = 0; Pattern pattern = Pattern.compile("\\\\ue[a-z0-9]{3}", Pattern.CASE_INSENSITIVE); Matcher matcher = pattern.matcher(text); while (matcher.find()) { String faceText = matcher.group(); String key = faceText.substring(1); BitmapFactory.Options options = new BitmapFactory.Options(); Bitmap bitmap = BitmapFactory.decodeResource( context.getResources(), context.getResources().getIdentifier(key, "drawable", context.getPackageName()), options); ImageSpan imageSpan = new ImageSpan(context, bitmap); int startIndex = text.indexOf(faceText, start); int endIndex = startIndex + faceText.length(); if (startIndex >= 0) spannableString.setSpan( imageSpan, startIndex, endIndex, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); start = (endIndex - 1); } return spannableString; } else { return new SpannableString(""); } }
@Override public View getView(int position, View convertView, ViewGroup parent) { // 1. Create inflater LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); // 2. Get rowView from inflater View rowView = inflater.inflate(R.layout.list_item, parent, false); // 3. Get the two text view from the rowView labelView = (TextView) rowView.findViewById(R.id.anchor_name); valueView = (TextView) rowView.findViewById(R.id.client_name); descView = (TextView) rowView.findViewById(R.id.campaign_id); labelView.setOnClickListener( new AnchorListener( itemsArrayList.get(position).getAnchorName(), itemsArrayList.get(position).getClientName(), itemsArrayList.get(position).getAnchorCreationDate(), itemsArrayList.get(position).getClientWebsiteAddress(), itemsArrayList.get(position).getClientInfo())); SpannableString content = new SpannableString(itemsArrayList.get(position).getAnchorName()); content.setSpan(new UnderlineSpan(), 0, content.length(), 0); labelView.setText(content); // 4. Set the text for textView valueView.setText(itemsArrayList.get(position).getClientName()); descView.setText(itemsArrayList.get(position).getCampaignStatusDescription()); // 5. return rowView return rowView; }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_full_screen_map); SpannableString s = new SpannableString("Pregled obliznjih ruta"); s.setSpan( new TypefaceSpan(this, "Choplin.otf"), 0, s.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); doubleClickIndicator = false; mMarkers = new ArrayList<>(); buildGoogleApiClient(); SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map); mapFragment.getMapAsync(this); mGoogleMap = mapFragment.getMap(); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); getSupportActionBar().setDisplayShowHomeEnabled(true); getSupportActionBar().setTitle(s); NavigationDrawerFragment drawerFragment = (NavigationDrawerFragment) getSupportFragmentManager().findFragmentById(R.id.fragment_navigation_drawer); drawerFragment.setUp( R.id.fragment_navigation_drawer, (DrawerLayout) findViewById(R.id.drawer_layout), toolbar); }
protected static CharSequence buildTickerMessage( Context context, String address, String subject, String body) { String displayAddress = Contact.get(address, true).getName(); StringBuilder buf = new StringBuilder( displayAddress == null ? "" : displayAddress.replace('\n', ' ').replace('\r', ' ')); buf.append(':').append(' '); int offset = buf.length(); if (!TextUtils.isEmpty(subject)) { subject = subject.replace('\n', ' ').replace('\r', ' '); buf.append(subject); buf.append(' '); } if (!TextUtils.isEmpty(body)) { body = body.replace('\n', ' ').replace('\r', ' '); buf.append(body); } SpannableString spanText = new SpannableString(buf.toString()); spanText.setSpan(new StyleSpan(Typeface.BOLD), 0, offset, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); return spanText; }
@Override public void onViewCreated(View view, Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); SpannableString string = new SpannableString("(点击查看示例)"); string.setSpan( new ClickableSpan() { @Override public void onClick(View widget) { if (togglePageListener != null) { togglePageListener.onToggleToGifSample(); } } @Override public void updateDrawState(TextPaint ds) { ds.setColor(Color.parseColor("#0000ff")); super.updateDrawState(ds); } }, 0, string.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); gifIntroTextView.setMovementMethod(LinkMovementMethod.getInstance()); gifIntroTextView.append(string); }
/** * 组合消息文本 * * @param name * @param body * @return */ public static SpannableString parsePostpan(String name, String body, String action) { SpannableString sp = null; int start = 0; int end = 0; if (StringUtils.isEmpty(action)) { sp = new SpannableString(name + ":" + body); end = name.length(); } else { sp = new SpannableString(action + name + ":" + body); start = action.length(); end = start + name.length(); } // 设置用户名字体加粗、高亮 sp.setSpan( new StyleSpan(android.graphics.Typeface.BOLD), start, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); sp.setSpan( new ForegroundColorSpan(Color.parseColor("#0e5986")), start, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); return sp; }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_highscore); /* Use application class to maintain global state. */ sqaApp = (SimpsonsQuizApp) getApplication(); // set custom font for ActionBar Title SpannableString s = new SpannableString(getString(R.string.title_activity_highscore)); s.setSpan( new TypefaceSpan(this, "Simpsonfont.ttf"), 0, s.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); if (getActionBar() != null) { // Update the action bar title with the TypefaceSpan instance getActionBar().setTitle(s); } layout = (TableLayout) findViewById(R.id.highscore_layout); LoadHighscoreTask lht = new LoadHighscoreTask(); lht.execute(); }
private void setupActionBar() { ActionBar actionBar = getActionBar(); actionBar.setDisplayShowCustomEnabled(true); actionBar.setDisplayShowTitleEnabled(false); actionBar.setHomeButtonEnabled(false); actionBar.setDisplayHomeAsUpEnabled(false); LayoutInflater inflator = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE); View actionBarCustomView = inflator.inflate(R.layout.white_action_bar, null); actionBarCustomView.findViewById(R.id.home_icon_container).setVisibility(View.VISIBLE); actionBar.setCustomView(actionBarCustomView); SpannableString s = new SpannableString(getString(R.string.redeem)); s.setSpan( new TypefaceSpan( getApplicationContext(), CommonLib.BOLD_FONT_FILENAME, getResources().getColor(R.color.white), getResources().getDimension(R.dimen.size16)), 0, s.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); TextView title = (TextView) actionBarCustomView.findViewById(R.id.title); ((RelativeLayout.LayoutParams) actionBarCustomView.findViewById(R.id.back_icon).getLayoutParams()) .setMargins(width / 40, 0, 0, 0); actionBarCustomView.findViewById(R.id.title).setPadding(width / 20, 0, width / 40, 0); title.setText(s); }
@AfterViews void crateData() { this.titleButton.setText("用户登录"); this.titleButton.setVisibility(View.VISIBLE); this.rightButton.setVisibility(View.INVISIBLE); this.backButton.setVisibility(View.VISIBLE); this.backButton.setText("返回"); this.backButton.setTextColor(Color.WHITE); SpannableString span = new SpannableString(this.registerButton.getText()); ForegroundColorSpan fgcs = new ForegroundColorSpan(getResources().getColor(R.color.second_red)); span.setSpan(fgcs, span.length() - 2, span.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); this.registerButton.setText(span); mAutoCheck.setOnClickListener( new OnClickListener() { @Override public void onClick(View v) { auto = !auto; mAutoCheck.setChecked(auto); } }); mUser = User.lastLoginUser(mContext); if (mUser == null) { mUser = new User(); mUser.setUserName(""); mUser.setPassword(""); } else { } initUI(); initData(); }
private void appendLog(String message, String targetFragment) { log.append(message); if (EXPECTED_TARGET_FRAGMENT.equals(targetFragment)) { SpannableString span = new SpannableString(targetFragment); span.setSpan( new ForegroundColorSpan(COLOR_OK), 0, targetFragment.length(), Spanned.SPAN_INCLUSIVE_EXCLUSIVE); log.append(span); } else { SpannableString span = new SpannableString(targetFragment); span.setSpan( new ForegroundColorSpan(COLOR_NOK), 0, targetFragment.length(), Spanned.SPAN_INCLUSIVE_EXCLUSIVE); log.append(span); } log.append("\n\n"); if (logView != null) { logView.setText(log); } }
public void clickText() { SpannableString ss = new SpannableString("New User? Click To Register."); ClickableSpan clickableSpan = new ClickableSpan() { @Override public void onClick(View clicktext) { startActivity(new Intent(SignInActivity.this, SignUpActivity.class)); } @Override public void updateDrawState(TextPaint ds) { super.updateDrawState(ds); ds.setUnderlineText(false); } }; ss.setSpan(clickableSpan, 10, 15, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); ss.setSpan( new ForegroundColorSpan(Color.parseColor("#0E89EB")), 10, 15, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); clicktext.setText(ss); clicktext.setMovementMethod(LinkMovementMethod.getInstance()); clicktext.setHighlightColor(Color.BLUE); }
private static CharSequence getLinkSpan( final AstridActivity activity, UserActivity update, String targetName, String linkColor, String linkType) { if (TASK_LINK_TYPE.equals(linkType)) { final String taskId = update.getValue(UserActivity.TARGET_ID); if (RemoteModel.isValidUuid(taskId)) { SpannableString taskSpan = new SpannableString(targetName); taskSpan.setSpan( new ClickableSpan() { @Override public void onClick(View widget) { if (activity != null) // TODO: This shouldn't happen, but sometimes does activity.onTaskListItemClicked(taskId); } @Override public void updateDrawState(TextPaint ds) { super.updateDrawState(ds); ds.setUnderlineText(false); } }, 0, targetName.length(), Spanned.SPAN_INCLUSIVE_EXCLUSIVE); return taskSpan; } else { return Html.fromHtml(linkify(targetName, linkColor)); } } return null; }
public static CharSequence getBoldedString(String value) { SpannableString spanned = new SpannableString(value); spanned.setSpan( new StyleSpan(Typeface.BOLD), 0, spanned.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); return spanned; }