List of usage examples for android.text.util Linkify addLinks
public static final boolean addLinks(@NonNull TextView text, @LinkifyMask int mask)
From source file:com.cw.litenote.note.Note_adapter.java
private String getHtmlStringWithViewPort(int position, int viewPort) { int mStyle = Note.mStyle; System.out.println("Note_adapter / _getHtmlStringWithViewPort"); String strTitle = db_page.getNoteTitle(position, true); String strBody = db_page.getNoteBody(position, true); String linkUri = db_page.getNoteLinkUri(position, true); // replace note title //TitleBody,YouTube linkWeb linkTitlelinktitle,Gray? boolean bSetGray = false; if (Util.isEmptyString(strTitle) && Util.isEmptyString(strBody)) { if (Util.isYouTubeLink(linkUri)) { strTitle = Util.getYouTubeTitle(linkUri); bSetGray = true;//from w ww .j a va2s. com } else if (linkUri.startsWith("http")) { strTitle = mWebTitle; bSetGray = true; } } Long createTime = db_page.getNoteCreatedTime(position, true); String head = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>" + "<html><head>" + "<meta http-equiv=\"content-type\" content=\"text/html; charset=utf-8\" />"; if (viewPort == VIEW_PORT_BY_NONE) { head = head + "<head>"; } else if (viewPort == VIEW_PORT_BY_DEVICE_WIDTH) { head = head + "<meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">" + "<head>"; } else if (viewPort == VIEW_PORT_BY_SCREEN_WIDTH) { // int screen_width = UtilImage.getScreenWidth(act); int screen_width = 640; head = head + "<meta name=\"viewport\" content=\"width=" + String.valueOf(screen_width) + ", initial-scale=1\">" + "<head>"; } String separatedLineTitle = (!Util.isEmptyString(strTitle)) ? "<hr size=2 color=blue width=99% >" : ""; String separatedLineBody = (!Util.isEmptyString(strBody)) ? "<hr size=1 color=black width=99% >" : ""; // title if (!Util.isEmptyString(strTitle)) { Spannable spanTitle = new SpannableString(strTitle); Linkify.addLinks(spanTitle, Linkify.ALL); spanTitle.setSpan(new AlignmentSpan.Standard(Alignment.ALIGN_CENTER), 0, spanTitle.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); //ref http://stackoverflow.com/questions/3282940/set-color-of-textview-span-in-android if (bSetGray) { ForegroundColorSpan foregroundSpan = new ForegroundColorSpan(Color.GRAY); spanTitle.setSpan(foregroundSpan, 0, spanTitle.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } strTitle = Html.toHtml(spanTitle); } else strTitle = ""; // body if (!Util.isEmptyString(strBody)) { Spannable spanBody = new SpannableString(strBody); Linkify.addLinks(spanBody, Linkify.ALL); strBody = Html.toHtml(spanBody); } else strBody = ""; // set web view text color String colorStr = Integer.toHexString(ColorSet.mText_ColorArray[mStyle]); colorStr = colorStr.substring(2); String bgColorStr = Integer.toHexString(ColorSet.mBG_ColorArray[mStyle]); bgColorStr = bgColorStr.substring(2); return head + "<body color=\"" + bgColorStr + "\">" + "<br>" + //Note: text mode needs this, otherwise title is overlaid "<p align=\"center\"><b>" + "<font color=\"" + colorStr + "\">" + strTitle + "</font>" + "</b></p>" + separatedLineTitle + "<p>" + "<font color=\"" + colorStr + "\">" + strBody + "</font>" + "</p>" + separatedLineBody + "<p align=\"right\">" + "<font color=\"" + colorStr + "\">" + Util.getTimeString(createTime) + "</font>" + "</p>" + "</body></html>"; }
From source file:qr.cloud.qrpedia.MessageViewerActivity.java
private void parseCodeDetailsAndUpdate(Intent launchIntent, String codeContents, boolean updateCode) { // need the format to send when composing a message try {//from www . j a v a 2 s. c om mBarcodeFormat = BarcodeFormat.valueOf(launchIntent.getStringExtra(QRCloudUtils.DATABASE_PROP_FORMAT)); } catch (IllegalArgumentException e) { } // store the type for later analysis try { mBarcodeType = ParsedResultType.valueOf(launchIntent.getStringExtra(QRCloudUtils.DATABASE_PROP_TYPE)); } catch (IllegalArgumentException e) { } // insert/update into the codes database if (updateCode) { updateCode(mCodeHash, codeContents, mBarcodeFormat, mBarcodeType); } // show the code details in a tab int barcodeTitle = launchIntent.getIntExtra(getString(R.string.key_display_title), R.string.result_text); // note: we ignore formatted contents for URLs, as this was breaking case-sensitive links String formattedBarcodeContents = launchIntent.getStringExtra(getString(R.string.key_display_contents)); if (mBarcodeType == ParsedResultType.URI) { if (formattedBarcodeContents.matches("(?i)^http[s]?\\://[a-z\\-]+\\.qrwp\\.org.*$")) { // case-insensitive barcodeTitle = R.string.result_qrpedia; // special display for QRpedia codes } formattedBarcodeContents = codeContents; } // barcodeDetailsBundle = getBarcodeDetailsBundle(mBarcodeFormat, barcodeTitle, formattedBarcodeContents, // barcodeType); // show the code details TextView titleText = (TextView) findViewById(R.id.code_info_title); titleText.setText(getString(R.string.result_type, getString(barcodeTitle))); mCodeContents = (TextView) findViewById(R.id.code_info_contents); mCodeContents.setText(formattedBarcodeContents); // request the product details if applicable if (mBarcodeFormat == BarcodeFormat.UPC_A || mBarcodeFormat == BarcodeFormat.UPC_E || mBarcodeFormat == BarcodeFormat.UPC_EAN_EXTENSION || mBarcodeFormat == BarcodeFormat.EAN_8 || mBarcodeFormat == BarcodeFormat.EAN_13) { if (mProductDetails != null) { setCodeDetails(mProductDetails); } else { try { requestBarcodeDetails(codeContents); } catch (JSONException e) { // problem getting code details - ignore } } } else if (mBarcodeType == ParsedResultType.EMAIL_ADDRESS || mBarcodeType == ParsedResultType.URI || mBarcodeType == ParsedResultType.TEL || mBarcodeType == ParsedResultType.GEO) { // linkify where appropriate Linkify.addLinks(mCodeContents, Linkify.ALL); } // set the correct fonts titleText.setTypeface(Typefaces.get(MessageViewerActivity.this, getString(R.string.default_font_bold))); mCodeContents.setTypeface(Typefaces.get(MessageViewerActivity.this, getString(R.string.default_font))); }
From source file:com.markuspage.android.atimetracker.Tasks.java
private Dialog openAboutDialog() { String versionName = ""; try {//from ww w .j av a 2 s . co m PackageInfo pkginfo = this.getPackageManager().getPackageInfo("com.markuspage.android.atimetracker", 0); versionName = pkginfo.versionName; } catch (NameNotFoundException nnfe) { // Denada } String formattedVersion = getString(R.string.version, versionName); LayoutInflater factory = LayoutInflater.from(this); View about = factory.inflate(R.layout.about, null); TextView version = (TextView) about.findViewById(R.id.version); version.setText(formattedVersion); TextView links = (TextView) about.findViewById(R.id.usage); Linkify.addLinks(links, Linkify.ALL); links = (TextView) about.findViewById(R.id.credits); Linkify.addLinks(links, Linkify.ALL); return new AlertDialog.Builder(Tasks.this).setView(about).setPositiveButton(android.R.string.ok, null) .create(); }
From source file:github.daneren2005.dsub.util.Util.java
private static void showDialog(Context context, int icon, String title, String message) { SpannableString ss = new SpannableString(message); Linkify.addLinks(ss, Linkify.ALL); AlertDialog dialog = new AlertDialog.Builder(context).setIcon(icon).setTitle(title).setMessage(ss) .setPositiveButton(R.string.common_ok, new DialogInterface.OnClickListener() { @Override//from w w w.j a v a2 s . co m public void onClick(DialogInterface dialog, int i) { dialog.dismiss(); } }).show(); ((TextView) dialog.findViewById(android.R.id.message)).setMovementMethod(LinkMovementMethod.getInstance()); }
From source file:github.daneren2005.dsub.util.Util.java
private static void showDialog(Context context, int icon, String title, String message, boolean linkify) { SpannableString ss = new SpannableString(message); if (linkify) { Linkify.addLinks(ss, Linkify.ALL); }/* ww w .j a v a 2 s .co m*/ AlertDialog dialog = new AlertDialog.Builder(context).setIcon(icon).setTitle(title).setMessage(ss) .setPositiveButton(R.string.common_ok, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int i) { dialog.dismiss(); } }).show(); ((TextView) dialog.findViewById(android.R.id.message)).setMovementMethod(LinkMovementMethod.getInstance()); }
From source file:com.tsp.clipsy.audio.RingdroidEditActivity.java
private void handleFatalError(final CharSequence errorInternalName, final CharSequence errorString, final Exception exception) { Log.i("Ringdroid", "handleFatalError"); SharedPreferences prefs = getPreferences(Context.MODE_PRIVATE); int failureCount = prefs.getInt(PREF_ERROR_COUNT, 0); final SharedPreferences.Editor prefsEditor = prefs.edit(); prefsEditor.putInt(PREF_ERROR_COUNT, failureCount + 1); prefsEditor.commit();//from www . ja va 2s . c o m // Check if we already have a pref for whether or not we can // contact the server. int serverAllowed = prefs.getInt(PREF_ERR_SERVER_ALLOWED, SERVER_ALLOWED_UNKNOWN); if (serverAllowed == SERVER_ALLOWED_NO) { Log.i("Ringdroid", "ERR: SERVER_ALLOWED_NO"); // Just show a simple "write error" message showFinalAlert(exception, errorString); return; } if (serverAllowed == SERVER_ALLOWED_YES) { Log.i("Ringdroid", "SERVER_ALLOWED_YES"); new AlertDialog.Builder(RingdroidEditActivity.this).setTitle(R.string.alert_title_failure) .setMessage(errorString) .setPositiveButton(R.string.alert_ok_button, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { finish(); return; } }).setCancelable(false).show(); return; } // The number of times the user must have had a failure before // we'll ask them. Defaults to 1, and each time they click "Later" // we double and add 1. final int allowServerCheckIndex = prefs.getInt(PREF_ERR_SERVER_CHECK, 1); if (failureCount < allowServerCheckIndex) { Log.i("Ringdroid", "failureCount " + failureCount + " is less than " + allowServerCheckIndex); // Just show a simple "write error" message showFinalAlert(exception, errorString); return; } final SpannableString message = new SpannableString( errorString + ". " + getResources().getText(R.string.error_server_prompt)); Linkify.addLinks(message, Linkify.ALL); AlertDialog dialog = new AlertDialog.Builder(this).setTitle(R.string.alert_title_failure) .setMessage(message).setPositiveButton(R.string.server_yes, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { prefsEditor.putInt(PREF_ERR_SERVER_ALLOWED, SERVER_ALLOWED_YES); prefsEditor.commit(); finish(); return; } }).setNeutralButton(R.string.server_later, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { prefsEditor.putInt(PREF_ERR_SERVER_CHECK, 1 + allowServerCheckIndex * 2); Log.i("Ringdroid", "Won't check again until " + (1 + allowServerCheckIndex * 2) + " errors."); prefsEditor.commit(); finish(); } }).setNegativeButton(R.string.server_never, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { prefsEditor.putInt(PREF_ERR_SERVER_ALLOWED, SERVER_ALLOWED_NO); prefsEditor.commit(); finish(); } }).setCancelable(false).show(); // Make links clicky ((TextView) dialog.findViewById(android.R.id.message)).setMovementMethod(LinkMovementMethod.getInstance()); }
From source file:mobi.omegacentauri.ptimer.PTimerEditActivity.java
private void handleFatalError(final CharSequence errorInternalName, final CharSequence errorString, final Exception exception) { Log.i("Ringdroid", "handleFatalError"); SharedPreferences prefs = getPreferences(Context.MODE_PRIVATE); int failureCount = prefs.getInt(PREF_ERROR_COUNT, 0); final SharedPreferences.Editor prefsEditor = prefs.edit(); prefsEditor.putInt(PREF_ERROR_COUNT, failureCount + 1); prefsEditor.commit();/*from ww w . ja v a 2s. c o m*/ // Check if we already have a pref for whether or not we can // contact the server. int serverAllowed = prefs.getInt(PREF_ERR_SERVER_ALLOWED, SERVER_ALLOWED_UNKNOWN); if (serverAllowed == SERVER_ALLOWED_NO) { Log.i("Ringdroid", "ERR: SERVER_ALLOWED_NO"); // Just show a simple "write error" message showFinalAlert(exception, errorString); return; } if (serverAllowed == SERVER_ALLOWED_YES) { Log.i("Ringdroid", "SERVER_ALLOWED_YES"); new AlertDialog.Builder(PTimerEditActivity.this).setTitle(R.string.alert_title_failure) .setMessage(errorString) .setPositiveButton(R.string.alert_ok_button, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { sendErrToServerAndFinish(errorInternalName, exception); return; } }).setCancelable(false).show(); return; } // The number of times the user must have had a failure before // we'll ask them. Defaults to 1, and each time they click "Later" // we double and add 1. final int allowServerCheckIndex = prefs.getInt(PREF_ERR_SERVER_CHECK, 1); if (failureCount < allowServerCheckIndex) { Log.i("Ringdroid", "failureCount " + failureCount + " is less than " + allowServerCheckIndex); // Just show a simple "write error" message showFinalAlert(exception, errorString); return; } final SpannableString message = new SpannableString( errorString + ". " + getResources().getText(R.string.error_server_prompt)); Linkify.addLinks(message, Linkify.ALL); AlertDialog dialog = new AlertDialog.Builder(this).setTitle(R.string.alert_title_failure) .setMessage(message).setPositiveButton(R.string.server_yes, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { prefsEditor.putInt(PREF_ERR_SERVER_ALLOWED, SERVER_ALLOWED_YES); prefsEditor.commit(); sendErrToServerAndFinish(errorInternalName, exception); } }).setNeutralButton(R.string.server_later, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { prefsEditor.putInt(PREF_ERR_SERVER_CHECK, 1 + allowServerCheckIndex * 2); Log.i("Ringdroid", "Won't check again until " + (1 + allowServerCheckIndex * 2) + " errors."); prefsEditor.commit(); finish(); } }).setNegativeButton(R.string.server_never, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { prefsEditor.putInt(PREF_ERR_SERVER_ALLOWED, SERVER_ALLOWED_NO); prefsEditor.commit(); finish(); } }).setCancelable(false).show(); // Make links clicky ((TextView) dialog.findViewById(android.R.id.message)).setMovementMethod(LinkMovementMethod.getInstance()); }
From source file:com.android.mms.ui.ComposeMessageActivity.java
private final void addCallAndContactMenuItems(ContextMenu menu, MsgListMenuClickListener l, MessageItem msgItem) {//from w w w . j a v a 2s . c o m if (TextUtils.isEmpty(msgItem.mBody)) { return; } SpannableString msg = new SpannableString(msgItem.mBody); Linkify.addLinks(msg, Linkify.ALL); ArrayList<String> uris = MessageUtils.extractUris(msg.getSpans(0, msg.length(), URLSpan.class)); // Remove any dupes so they don't get added to the menu multiple times HashSet<String> collapsedUris = new HashSet<String>(); for (String uri : uris) { collapsedUris.add(uri.toLowerCase()); } for (String uriString : collapsedUris) { String prefix = null; int sep = uriString.indexOf(":"); if (sep >= 0) { prefix = uriString.substring(0, sep); uriString = uriString.substring(sep + 1); } Uri contactUri = null; boolean knownPrefix = true; if ("mailto".equalsIgnoreCase(prefix)) { contactUri = getContactUriForEmail(uriString); } else if ("tel".equalsIgnoreCase(prefix)) { contactUri = getContactUriForPhoneNumber(uriString); } else { knownPrefix = false; } if (knownPrefix && contactUri == null) { Intent intent = ConversationList.createAddContactIntent(uriString); String addContactString = getString(R.string.menu_add_address_to_contacts, uriString); menu.add(0, MENU_ADD_ADDRESS_TO_CONTACTS, 0, addContactString).setOnMenuItemClickListener(l) .setIntent(intent); } } }
From source file:com.SpeechEd.SpeechEdEditActivity.java
private void handleFatalError(final CharSequence errorInternalName, final CharSequence errorString, final Exception exception) { Log.i("Speech-Ed", "handleFatalError"); SharedPreferences prefs = getPreferences(Context.MODE_PRIVATE); int failureCount = prefs.getInt(PREF_ERROR_COUNT, 0); final SharedPreferences.Editor prefsEditor = prefs.edit(); prefsEditor.putInt(PREF_ERROR_COUNT, failureCount + 1); prefsEditor.commit();/* w w w . j av a 2 s .com*/ // Check if we already have a pref for whether or not we can // contact the server. int serverAllowed = prefs.getInt(PREF_ERR_SERVER_ALLOWED, SERVER_ALLOWED_UNKNOWN); if (serverAllowed == SERVER_ALLOWED_NO) { Log.i("Speech-Ed", "ERR: SERVER_ALLOWED_NO"); // Just show a simple "write error" message showFinalAlert(exception, errorString); return; } if (serverAllowed == SERVER_ALLOWED_YES) { Log.i("Speech-Ed", "SERVER_ALLOWED_YES"); new AlertDialog.Builder(SpeechEdEditActivity.this).setTitle(R.string.alert_title_failure) .setMessage(errorString) .setPositiveButton(R.string.alert_ok_button, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { sendErrToServerAndFinish(errorInternalName, exception); return; } }).setCancelable(false).show(); return; } // The number of times the user must have had a failure before // we'll ask them. Defaults to 1, and each time they click "Later" // we double and add 1. final int allowServerCheckIndex = prefs.getInt(PREF_ERR_SERVER_CHECK, 1); if (failureCount < allowServerCheckIndex) { Log.i("Speech-Ed", "failureCount " + failureCount + " is less than " + allowServerCheckIndex); // Just show a simple "write error" message showFinalAlert(exception, errorString); return; } final SpannableString message = new SpannableString( errorString + ". " + getResources().getText(R.string.error_server_prompt)); Linkify.addLinks(message, Linkify.ALL); AlertDialog dialog = new AlertDialog.Builder(this).setTitle(R.string.alert_title_failure) .setMessage(message).setPositiveButton(R.string.server_yes, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { prefsEditor.putInt(PREF_ERR_SERVER_ALLOWED, SERVER_ALLOWED_YES); prefsEditor.commit(); sendErrToServerAndFinish(errorInternalName, exception); } }).setNeutralButton(R.string.server_later, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { prefsEditor.putInt(PREF_ERR_SERVER_CHECK, 1 + allowServerCheckIndex * 2); Log.i("Speech-Ed", "Won't check again until " + (1 + allowServerCheckIndex * 2) + " errors."); prefsEditor.commit(); finish(); } }).setNegativeButton(R.string.server_never, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { prefsEditor.putInt(PREF_ERR_SERVER_ALLOWED, SERVER_ALLOWED_NO); prefsEditor.commit(); finish(); } }).setCancelable(false).show(); // Make links clicky ((TextView) dialog.findViewById(android.R.id.message)).setMovementMethod(LinkMovementMethod.getInstance()); }
From source file:com.Beat.RingdroidEditActivity.java
private void handleFatalError(final CharSequence errorInternalName, final CharSequence errorString, final Exception exception) { Log.i("Ringdroid", "handleFatalError"); SharedPreferences prefs = getPreferences(Context.MODE_PRIVATE); int failureCount = prefs.getInt(PREF_ERROR_COUNT, 0); final SharedPreferences.Editor prefsEditor = prefs.edit(); prefsEditor.putInt(PREF_ERROR_COUNT, failureCount + 1); prefsEditor.commit();/*from ww w . ja va2 s . com*/ // Check if we already have a pref for whether or not we can // contact the server. int serverAllowed = prefs.getInt(PREF_ERR_SERVER_ALLOWED, SERVER_ALLOWED_UNKNOWN); if (serverAllowed == SERVER_ALLOWED_NO) { Log.i("Ringdroid", "ERR: SERVER_ALLOWED_NO"); // Just show a simple "write error" message showFinalAlert(exception, errorString); return; } if (serverAllowed == SERVER_ALLOWED_YES) { Log.i("Ringdroid", "SERVER_ALLOWED_YES"); new AlertDialog.Builder(RingdroidEditActivity.this).setTitle(R.string.alert_title_failure) .setMessage(errorString) .setPositiveButton(R.string.alert_ok_button, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { sendErrToServerAndFinish(errorInternalName, exception); return; } }).setCancelable(false).show(); return; } // The number of times the user must have had a failure before // we'll ask them. Defaults to 1, and each time they click "Later" // we double and add 1. final int allowServerCheckIndex = prefs.getInt(PREF_ERR_SERVER_CHECK, 1); if (failureCount < allowServerCheckIndex) { Log.i("Ringdroid", "failureCount " + failureCount + " is less than " + allowServerCheckIndex); // Just show a simple "write error" message showFinalAlert(exception, errorString); return; } final SpannableString message = new SpannableString( errorString + ". " + getResources().getText(R.string.error_server_prompt)); Linkify.addLinks(message, Linkify.ALL); AlertDialog dialog = new AlertDialog.Builder(this).setTitle(R.string.alert_title_failure) .setMessage(message).setPositiveButton(R.string.server_yes, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { prefsEditor.putInt(PREF_ERR_SERVER_ALLOWED, SERVER_ALLOWED_YES); prefsEditor.commit(); sendErrToServerAndFinish(errorInternalName, exception); } }).setNeutralButton(R.string.server_later, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { prefsEditor.putInt(PREF_ERR_SERVER_CHECK, 1 + allowServerCheckIndex * 2); Log.i("Ringdroid", "Won't check again until " + (1 + allowServerCheckIndex * 2) + " errors."); prefsEditor.commit(); finish(); } }).setNegativeButton(R.string.server_never, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { prefsEditor.putInt(PREF_ERR_SERVER_ALLOWED, SERVER_ALLOWED_NO); prefsEditor.commit(); finish(); } }).setCancelable(false).show(); // Make links clicky ((TextView) dialog.findViewById(android.R.id.message)).setMovementMethod(LinkMovementMethod.getInstance()); }