From cbb2973b3663ef33c6917793cc11795a9c435d1b Mon Sep 17 00:00:00 2001 From: str4d Date: Thu, 20 Feb 2014 10:35:22 +0000 Subject: [PATCH] Linkify .i2p URLs --- res/layout/fragment_about.xml | 16 +++---- res/values/strings.xml | 6 +-- src/net/i2p/android/router/AboutDialog.java | 11 +++++ .../i2p/android/router/util/I2Patterns.java | 43 +++++++++++++++++++ 4 files changed, 65 insertions(+), 11 deletions(-) create mode 100644 src/net/i2p/android/router/util/I2Patterns.java diff --git a/res/layout/fragment_about.xml b/res/layout/fragment_about.xml index c35b12cae..cacec4686 100644 --- a/res/layout/fragment_about.xml +++ b/res/layout/fragment_about.xml @@ -26,10 +26,10 @@ android:textStyle="bold" /> + android:text="@string/url_project" /> + android:text="@string/url_android_forum" /> + android:text="@string/url_android_forum" /> + android:text="@string/url_donate" /> diff --git a/res/values/strings.xml b/res/values/strings.xml index 9371f128a..dab79f4c2 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -107,13 +107,13 @@ About Version: Project Home: - https://geti2p.net/ + https://geti2p.net | http://i2p-projekt.i2p Bugs and Support: - http://zzz.i2p/ + http://zzz.i2p Help Wanted! Want to help make the app better? Volunteer on the Android forum: Want to donate money or bitcoins to buy more Android devices for development and testing? Go to: - https://geti2p.net/en/donate + https://geti2p.net/en/donate | http://i2p-projekt.i2p/en/donate Help diff --git a/src/net/i2p/android/router/AboutDialog.java b/src/net/i2p/android/router/AboutDialog.java index 3bb432659..e2e2d9bcf 100644 --- a/src/net/i2p/android/router/AboutDialog.java +++ b/src/net/i2p/android/router/AboutDialog.java @@ -1,11 +1,13 @@ package net.i2p.android.router; import net.i2p.android.router.R; +import net.i2p.android.router.util.I2Patterns; import net.i2p.android.router.util.Util; import android.app.AlertDialog; import android.app.Dialog; import android.os.Bundle; import android.support.v4.app.DialogFragment; +import android.text.util.Linkify; import android.view.LayoutInflater; import android.view.View; import android.widget.TextView; @@ -20,6 +22,15 @@ public class AboutDialog extends DialogFragment { TextView tv = (TextView)view.findViewById(R.id.about_version); tv.setText(currentVersion); + tv = (TextView)view.findViewById(R.id.url_project); + Linkify.addLinks(tv, I2Patterns.I2P_WEB_URL, "http://"); + tv = (TextView)view.findViewById(R.id.url_android_bugs); + Linkify.addLinks(tv, I2Patterns.I2P_WEB_URL, "http://"); + tv = (TextView)view.findViewById(R.id.url_android_volunteer); + Linkify.addLinks(tv, I2Patterns.I2P_WEB_URL, "http://"); + tv = (TextView)view.findViewById(R.id.url_donate); + Linkify.addLinks(tv, I2Patterns.I2P_WEB_URL, "http://"); + AlertDialog.Builder b = new AlertDialog.Builder(getActivity()); b.setTitle(R.string.menu_about) .setView(view); diff --git a/src/net/i2p/android/router/util/I2Patterns.java b/src/net/i2p/android/router/util/I2Patterns.java new file mode 100644 index 000000000..827e533be --- /dev/null +++ b/src/net/i2p/android/router/util/I2Patterns.java @@ -0,0 +1,43 @@ +package net.i2p.android.router.util; + +import java.util.regex.Pattern; + +import android.util.Patterns; + +public class I2Patterns { + /** + * The double-parentheses are needed because the included + * pattern has an additional closing parenthesis. + */ + public static final String I2P_TOP_LEVEL_DOMAIN_STR_FOR_WEB_URL = + "(?:(" + + Patterns.TOP_LEVEL_DOMAIN_STR_FOR_WEB_URL + + "|i2p))"; + + /** + * Regular expression pattern to match most part of RFC 3987 + * Internationalized URLs, aka IRIs. Commonly used Unicode characters are + * added. + * Copied from android.util.Patterns + */ + public static final Pattern I2P_WEB_URL = Pattern.compile( + "((?:(http|https|Http|Https|rtsp|Rtsp):\\/\\/(?:(?:[a-zA-Z0-9\\$\\-\\_\\.\\+\\!\\*\\'\\(\\)" + + "\\,\\;\\?\\&\\=]|(?:\\%[a-fA-F0-9]{2})){1,64}(?:\\:(?:[a-zA-Z0-9\\$\\-\\_" + + "\\.\\+\\!\\*\\'\\(\\)\\,\\;\\?\\&\\=]|(?:\\%[a-fA-F0-9]{2})){1,25})?\\@)?)?" + + "((?:(?:[" + Patterns.GOOD_IRI_CHAR + "][" + Patterns.GOOD_IRI_CHAR + "\\-]{0,64}\\.)+" // named host + + I2P_TOP_LEVEL_DOMAIN_STR_FOR_WEB_URL + + "|(?:(?:25[0-5]|2[0-4]" // or ip address + + "[0-9]|[0-1][0-9]{2}|[1-9][0-9]|[1-9])\\.(?:25[0-5]|2[0-4][0-9]" + + "|[0-1][0-9]{2}|[1-9][0-9]|[1-9]|0)\\.(?:25[0-5]|2[0-4][0-9]|[0-1]" + + "[0-9]{2}|[1-9][0-9]|[1-9]|0)\\.(?:25[0-5]|2[0-4][0-9]|[0-1][0-9]{2}" + + "|[1-9][0-9]|[0-9])))" + + "(?:\\:\\d{1,5})?)" // plus option port number + + "(\\/(?:(?:[" + Patterns.GOOD_IRI_CHAR + "\\;\\/\\?\\:\\@\\&\\=\\#\\~" // plus option query params + + "\\-\\.\\+\\!\\*\\'\\(\\)\\,\\_])|(?:\\%[a-fA-F0-9]{2}))*)?" + + "(?:\\b|$)"); // and finally, a word boundary or end of + // input. This is to stop foo.sure from + // matching as foo.su + + private I2Patterns() { + } +}