List of usage examples for android.text TextPaint setUnderlineText
public void setUnderlineText(boolean underlineText)
From source file:Main.java
/** * Make UI TextView a html link.// www . ja va 2s . c o m * * @param context the context * @param textView the text view * @param html the html containing link info */ public static void makeTextViewAHTMLLink(final Context context, TextView textView, String html) { textView.setLinksClickable(true); textView.setMovementMethod(LinkMovementMethod.getInstance()); CharSequence sequence = Html.fromHtml(html); SpannableStringBuilder spannableStringBuilder = new SpannableStringBuilder(sequence); URLSpan[] urls = spannableStringBuilder.getSpans(0, sequence.length(), URLSpan.class); for (final URLSpan urlSpan : urls) { int start = spannableStringBuilder.getSpanStart(urlSpan); int end = spannableStringBuilder.getSpanEnd(urlSpan); int flags = spannableStringBuilder.getSpanFlags(urlSpan); ClickableSpan clickable = new ClickableSpan() { public void onClick(View view) { Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(urlSpan.getURL())); context.startActivity(intent); } @Override public void updateDrawState(TextPaint textPaint) { super.updateDrawState(textPaint); textPaint.setUnderlineText(false); } }; spannableStringBuilder.removeSpan(urlSpan); spannableStringBuilder.setSpan(clickable, start, end, flags); } textView.setText(spannableStringBuilder); }
From source file:com.keylesspalace.tusky.util.LinkHelper.java
/** * Finds links, mentions, and hashtags in a piece of text and makes them clickable, associating * them with callbacks to notify when they're clicked. * * @param view the returned text will be put in * @param content containing text with mentions, links, or hashtags * @param mentions any '@' mentions which are known to be in the content * @param listener to notify about particular spans that are clicked *//*from w w w .ja v a 2s. co m*/ public static void setClickableText(TextView view, Spanned content, @Nullable Status.Mention[] mentions, final LinkListener listener) { SpannableStringBuilder builder = new SpannableStringBuilder(content); URLSpan[] urlSpans = content.getSpans(0, content.length(), URLSpan.class); for (URLSpan span : urlSpans) { int start = builder.getSpanStart(span); int end = builder.getSpanEnd(span); int flags = builder.getSpanFlags(span); CharSequence text = builder.subSequence(start, end); if (text.charAt(0) == '#') { final String tag = text.subSequence(1, text.length()).toString(); ClickableSpan newSpan = new ClickableSpan() { @Override public void onClick(View widget) { listener.onViewTag(tag); } @Override public void updateDrawState(TextPaint ds) { super.updateDrawState(ds); ds.setUnderlineText(false); } }; builder.removeSpan(span); builder.setSpan(newSpan, start, end, flags); } else if (text.charAt(0) == '@' && mentions != null && mentions.length > 0) { String accountUsername = text.subSequence(1, text.length()).toString(); /* There may be multiple matches for users on different instances with the same * username. If a match has the same domain we know it's for sure the same, but if * that can't be found then just go with whichever one matched last. */ String id = null; for (Status.Mention mention : mentions) { if (mention.localUsername.equalsIgnoreCase(accountUsername)) { id = mention.id; if (mention.url.contains(getDomain(span.getURL()))) { break; } } } if (id != null) { final String accountId = id; ClickableSpan newSpan = new ClickableSpan() { @Override public void onClick(View widget) { listener.onViewAccount(accountId); } @Override public void updateDrawState(TextPaint ds) { super.updateDrawState(ds); ds.setUnderlineText(false); } }; builder.removeSpan(span); builder.setSpan(newSpan, start, end, flags); } } else { ClickableSpan newSpan = new CustomURLSpan(span.getURL()); builder.removeSpan(span); builder.setSpan(newSpan, start, end, flags); } } view.setText(builder); view.setLinksClickable(true); view.setMovementMethod(LinkMovementMethod.getInstance()); }
From source file:com.todoroo.astrid.adapter.UpdateAdapter.java
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//w w w . j a va 2s . co m 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; }
From source file:com.lloydtorres.stately.helpers.SpoilerSpan.java
@Override public void updateDrawState(TextPaint ds) { ds.setUnderlineText(false); ds.setColor(ContextCompat.getColor(context, R.color.colorPrimary)); }
From source file:com.lloydtorres.stately.helpers.URLSpanNoUnderline.java
@Override public void updateDrawState(TextPaint ds) { super.updateDrawState(ds); ds.setUnderlineText(false); ds.setColor(ContextCompat.getColor(context, R.color.colorPrimary)); }
From source file:com.lloydtorres.stately.helpers.links.NameListSpan.java
@Override public void updateDrawState(TextPaint ds) { super.updateDrawState(ds); ds.setUnderlineText(false); ds.setColor(RaraHelper.getThemeLinkColour(context)); }
From source file:com.github.guwenk.smuradio.SignInDialog.java
@Override public Dialog onCreateDialog(Bundle savedInstanceState) { builder = new AlertDialog.Builder(getActivity()); View signInDialogView = getActivity().getLayoutInflater().inflate(R.layout.dialog_sign_in, null); builder.setView(signInDialogView);/*from w w w. j av a 2 s . c o m*/ builder.setMessage(R.string.upload_your_song); checkBox = (CheckBox) signInDialogView.findViewById(R.id.checkBox2); int currentOrientation = getResources().getConfiguration().orientation; if (currentOrientation == Configuration.ORIENTATION_LANDSCAPE) { getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE); } else { getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT); } check1 = false; check2 = false; check3 = false; // Log.d(AuthTag, "onCreateDialog " + check1 + " " + check2 + " " + check3); this.mGoogleApiClient = OrderActivity.getmGoogleApiClient(); mAuth = FirebaseAuth.getInstance(); selectFileButton = (Button) signInDialogView.findViewById(R.id.selectFileButton); selectFileButton.setOnClickListener(new customButtonClickListener()); signInButton = (SignInButton) signInDialogView.findViewById(R.id.sign_in_button); signInButton.setStyle(SignInButton.SIZE_WIDE, SignInButton.COLOR_AUTO); signInButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { signIn(); } }); builder.setPositiveButton(getString(R.string.next), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { // TODO upload song } }); builder.setNegativeButton(R.string.close, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { } }); SpannableString ss = new SpannableString(getString(R.string.you_accepting_license_agreement)); ClickableSpan clickableSpan = new ClickableSpan() { @Override public void onClick(View textView) { Log.d(AuthTag, "click"); LicenseDialog licenseDialog = new LicenseDialog(); licenseDialog.show(getFragmentManager(), "Sing in dialog"); } @Override public void updateDrawState(TextPaint ds) { super.updateDrawState(ds); ds.setUnderlineText(true); } }; ss.setSpan(clickableSpan, 14, ss.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); TextView textView = (TextView) signInDialogView.findViewById(R.id.textView); textView.setText(ss); textView.setMovementMethod(LinkMovementMethod.getInstance()); textView.setHighlightColor(Color.TRANSPARENT); checkBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { check2 = isChecked; Log.d(AuthTag, "Checked: " + isChecked); buttonStatus(); } }); mStorageRef = FirebaseStorage.getInstance().getReference(); alert = builder.create(); return alert; }
From source file:org.mozilla.gecko.home.HistoryPanel.java
/** * Make Span that is clickable, italicized, and underlined * between the string markers <code>FORMAT_S1</code> and * <code>FORMAT_S2</code>.//from w w w. ja va 2 s .c o m * * @param text String to format * @return formatted SpannableStringBuilder, or null if there * is not any text to format. */ private SpannableStringBuilder formatHintText(String text) { // Set formatting as marked by string placeholders. final int underlineStart = text.indexOf(FORMAT_S1); final int underlineEnd = text.indexOf(FORMAT_S2); // Check that there is text to be formatted. if (underlineStart >= underlineEnd) { return null; } final SpannableStringBuilder ssb = new SpannableStringBuilder(text); // Set italicization. ssb.setSpan(new StyleSpan(Typeface.ITALIC), 0, ssb.length(), 0); // Set clickable text. final ClickableSpan clickableSpan = new ClickableSpan() { @Override public void onClick(View widget) { Telemetry.sendUIEvent(TelemetryContract.Event.ACTION, TelemetryContract.Method.HOMESCREEN, "hint-private-browsing"); try { final JSONObject json = new JSONObject(); json.put("type", "Menu:Open"); EventDispatcher.getInstance().dispatchEvent(json, null); } catch (JSONException e) { Log.e(LOGTAG, "Error forming JSON for Private Browsing contextual hint", e); } } }; ssb.setSpan(clickableSpan, 0, text.length(), 0); // Remove underlining set by ClickableSpan. final UnderlineSpan noUnderlineSpan = new UnderlineSpan() { @Override public void updateDrawState(TextPaint textPaint) { textPaint.setUnderlineText(false); } }; ssb.setSpan(noUnderlineSpan, 0, text.length(), 0); // Add underlining for "Private Browsing". ssb.setSpan(new UnderlineSpan(), underlineStart, underlineEnd, 0); ssb.delete(underlineEnd, underlineEnd + FORMAT_S2.length()); ssb.delete(underlineStart, underlineStart + FORMAT_S1.length()); return ssb; }
From source file:org.sirimangalo.meditationplus.AdapterCommit.java
@Override public View getView(final int position, View convertView, ViewGroup parent) { LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); View rowView = inflater.inflate(R.layout.list_item_commit, parent, false); final View shell = rowView.findViewById(R.id.detail_shell); rowView.setOnClickListener(new View.OnClickListener() { @Override/*w ww. j a va 2 s . com*/ public void onClick(View view) { boolean visible = shell.getVisibility() == View.VISIBLE; shell.setVisibility(visible ? View.GONE : View.VISIBLE); context.setCommitVisible(position, !visible); } }); final JSONObject p = values.get(position); TextView title = (TextView) rowView.findViewById(R.id.title); TextView descV = (TextView) rowView.findViewById(R.id.desc); TextView defV = (TextView) rowView.findViewById(R.id.def); TextView usersV = (TextView) rowView.findViewById(R.id.users); TextView youV = (TextView) rowView.findViewById(R.id.you); try { if (p.getBoolean("open")) shell.setVisibility(View.VISIBLE); title.setText(p.getString("title")); descV.setText(p.getString("description")); String length = p.getString("length"); String time = p.getString("time"); final String cid = p.getString("cid"); String def = ""; boolean repeat = false; if (length.indexOf(":") > 0) { repeat = true; String[] lengtha = length.split(":"); def += lengtha[0] + " minutes walking and " + lengtha[1] + " minutes sitting"; } else def += length + " minutes total meditation"; String period = p.getString("period"); String day = p.getString("day"); if (period.equals("daily")) { if (repeat) def += " every day"; else def += " per day"; } else if (period.equals("weekly")) { if (repeat) def += " every " + dow[Integer.parseInt(day)]; else def += " per week"; } else if (period.equals("monthly")) { if (repeat) def += " on the " + day + (day.substring(day.length() - 1).equals("1") ? "st" : (day.substring(day.length() - 1).equals("2") ? "nd" : (day.substring(day.length() - 1).equals("3") ? "rd" : "th"))) + " day of the month"; else def += " per month"; } else if (period.equals("yearly")) { if (repeat) def += " on the " + day + (day.substring(day.length() - 1).equals("1") ? "st" : (day.substring(day.length() - 1).equals("2") ? "nd" : (day.substring(day.length() - 1).equals("3") ? "rd" : "th"))) + " day of the year"; else def += " per year"; } if (!time.equals("any")) { Calendar utc = Calendar.getInstance(TimeZone.getTimeZone("UTC")); utc.set(Calendar.HOUR_OF_DAY, Integer.parseInt(time.split(":")[0])); utc.set(Calendar.MINUTE, Integer.parseInt(time.split(":")[1])); Calendar here = Calendar.getInstance(); here.setTimeInMillis(utc.getTimeInMillis()); int hours = here.get(Calendar.HOUR_OF_DAY); int minutes = here.get(Calendar.MINUTE); def += " at " + (time.length() == 4 ? "0" : "") + time.replace(":", "") + "h UTC <i>(" + (hours > 12 ? hours - 12 : hours) + ":" + ((minutes < 10 ? "0" : "") + minutes) + " " + (hours > 11 && hours < 24 ? "PM" : "AM") + " your time)</i>"; } defV.setText(Html.fromHtml(def)); JSONObject usersJ = p.getJSONObject("users"); ArrayList<String> committedArray = new ArrayList<String>(); // collect into array for (int i = 0; i < usersJ.names().length(); i++) { try { String j = usersJ.names().getString(i); String k = j; // if(j.equals(p.getString("creator"))) // k = "["+j+"]"; committedArray.add(k); } catch (JSONException e) { e.printStackTrace(); } } String text = context.getString(R.string.committed) + " "; // add spans int committed = -1; int pos = text.length(); // start after "Committed: " text += TextUtils.join(", ", committedArray); Spannable span = new SpannableString(text); span.setSpan(new StyleSpan(Typeface.BOLD), 0, pos, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); // bold the "Online: " for (int i = 0; i < committedArray.size(); i++) { try { final String oneCom = committedArray.get(i); String userCom = usersJ.getString(oneCom); //String userCom = usersJ.getString(oneCom.replace("[", "").replace("]", "")); //if(oneCom.replace("[","").replace("]","").equals(loggedUser)) if (oneCom.equals(loggedUser)) committed = Integer.parseInt(userCom); int end = pos + oneCom.length(); ClickableSpan clickable = new ClickableSpan() { @Override public void onClick(View widget) { context.showProfile(oneCom); } }; span.setSpan(clickable, pos, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); span.setSpan(new UnderlineSpan() { public void updateDrawState(TextPaint tp) { tp.setUnderlineText(false); } }, pos, end, 0); String color = Utils.makeRedGreen(Integer.parseInt(userCom), true); span.setSpan(new ForegroundColorSpan(Color.parseColor("#FF" + color)), pos, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); pos += oneCom.length() + 2; } catch (JSONException e) { e.printStackTrace(); } } usersV.setText(span); usersV.setMovementMethod(new LinkMovementMethod()); if (loggedUser != null && loggedUser.length() > 0) { LinearLayout bl = (LinearLayout) rowView.findViewById(R.id.commit_buttons); if (!usersJ.has(loggedUser)) { Button commitB = new Button(context); commitB.setId(R.id.commit_button); commitB.setText(R.string.commit); commitB.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { ArrayList<NameValuePair> nvp = new ArrayList<NameValuePair>(); nvp.add(new BasicNameValuePair("full_update", "true")); context.doSubmit("commitform_" + cid, nvp, true); } }); bl.addView(commitB); } else { Button commitB = new Button(context); commitB.setId(R.id.uncommit_button); commitB.setText(R.string.uncommit); commitB.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { ArrayList<NameValuePair> nvp = new ArrayList<NameValuePair>(); nvp.add(new BasicNameValuePair("full_update", "true")); context.doSubmit("uncommitform_" + cid, nvp, true); } }); bl.addView(commitB); } if (loggedUser.equals(p.getString("creator")) || context.isAdmin) { Button commitB2 = new Button(context); commitB2.setId(R.id.edit_commit_button); commitB2.setText(R.string.edit); commitB2.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Intent i = new Intent(context, ActivityCommit.class); i.putExtra("commitment", p.toString()); context.startActivity(i); } }); bl.addView(commitB2); Button commitB3 = new Button(context); commitB3.setId(R.id.uncommit_button); commitB3.setText(R.string.delete); commitB3.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { ArrayList<NameValuePair> nvp = new ArrayList<NameValuePair>(); nvp.add(new BasicNameValuePair("full_update", "true")); context.doSubmit("delcommitform_" + cid, nvp, true); } }); bl.addView(commitB3); } } if (committed > -1) { int color = Color.parseColor("#FF" + Utils.makeRedGreen(committed, false)); rowView.setBackgroundColor(color); } if (committed != -1) { youV.setText(String.format(context.getString(R.string.you_commit_x), committed)); youV.setVisibility(View.VISIBLE); } } catch (Exception e) { e.printStackTrace(); } return rowView; }
From source file:com.todoroo.astrid.actfm.ActFmLoginActivity.java
protected SpannableString getLinkStringWithCustomInterval(String base, String linkComponent, int start, int endOffset, final OnClickListener listener) { SpannableString link = new SpannableString(String.format("%s %s", //$NON-NLS-1$ base, linkComponent));/*w w w. jav a2 s . c o m*/ ClickableSpan linkSpan = new ClickableSpan() { @Override public void onClick(View widget) { listener.onClick(widget); } @Override public void updateDrawState(TextPaint ds) { ds.setUnderlineText(true); ds.setColor(Color.rgb(68, 68, 68)); } }; link.setSpan(linkSpan, start, link.length() + endOffset, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); return link; }