Linkify .i2p URLs

This commit is contained in:
str4d
2014-02-20 10:35:22 +00:00
parent f360ab4d5d
commit cbb2973b36
4 changed files with 65 additions and 11 deletions

View File

@ -26,10 +26,10 @@
android:textStyle="bold" /> android:textStyle="bold" />
<TextView <TextView
android:id="@+id/url_project"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:text="@string/url_project" android:text="@string/url_project" />
android:autoLink="web" />
<TextView <TextView
android:layout_width="match_parent" android:layout_width="match_parent"
@ -38,10 +38,10 @@
android:textStyle="bold" /> android:textStyle="bold" />
<TextView <TextView
android:id="@+id/url_android_bugs"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:text="@string/url_android_forum" android:text="@string/url_android_forum" />
android:autoLink="web" />
<TextView <TextView
android:layout_width="match_parent" android:layout_width="match_parent"
@ -55,10 +55,10 @@
android:text="@string/about_volunteer" /> android:text="@string/about_volunteer" />
<TextView <TextView
android:id="@+id/url_android_volunteer"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:text="@string/url_android_forum" android:text="@string/url_android_forum" />
android:autoLink="web" />
<TextView <TextView
android:layout_width="match_parent" android:layout_width="match_parent"
@ -66,10 +66,10 @@
android:text="@string/about_donate" /> android:text="@string/about_donate" />
<TextView <TextView
android:id="@+id/url_donate"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:text="@string/url_donate" android:text="@string/url_donate" />
android:autoLink="web" />
</LinearLayout> </LinearLayout>

View File

@ -107,13 +107,13 @@
<string name="menu_about">About</string> <string name="menu_about">About</string>
<string name="about_version">Version:</string> <string name="about_version">Version:</string>
<string name="about_project">Project Home:</string> <string name="about_project">Project Home:</string>
<string name="url_project" translatable="false">https://geti2p.net/</string> <string name="url_project" translatable="false">https://geti2p.net | http://i2p-projekt.i2p</string>
<string name="about_bugs">Bugs and Support:</string> <string name="about_bugs">Bugs and Support:</string>
<string name="url_android_forum" translatable="false">http://zzz.i2p/</string> <string name="url_android_forum" translatable="false">http://zzz.i2p</string>
<string name="about_helpwanted">Help Wanted!</string> <string name="about_helpwanted">Help Wanted!</string>
<string name="about_volunteer">Want to help make the app better? Volunteer on the Android forum:</string> <string name="about_volunteer">Want to help make the app better? Volunteer on the Android forum:</string>
<string name="about_donate">Want to donate money or bitcoins to buy more Android devices for development and testing? Go to:</string> <string name="about_donate">Want to donate money or bitcoins to buy more Android devices for development and testing? Go to:</string>
<string name="url_donate" translatable="false">https://geti2p.net/en/donate</string> <string name="url_donate" translatable="false">https://geti2p.net/en/donate | http://i2p-projekt.i2p/en/donate</string>
<string name="menu_help">Help</string> <string name="menu_help">Help</string>

View File

@ -1,11 +1,13 @@
package net.i2p.android.router; package net.i2p.android.router;
import net.i2p.android.router.R; import net.i2p.android.router.R;
import net.i2p.android.router.util.I2Patterns;
import net.i2p.android.router.util.Util; import net.i2p.android.router.util.Util;
import android.app.AlertDialog; import android.app.AlertDialog;
import android.app.Dialog; import android.app.Dialog;
import android.os.Bundle; import android.os.Bundle;
import android.support.v4.app.DialogFragment; import android.support.v4.app.DialogFragment;
import android.text.util.Linkify;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.widget.TextView; import android.widget.TextView;
@ -20,6 +22,15 @@ public class AboutDialog extends DialogFragment {
TextView tv = (TextView)view.findViewById(R.id.about_version); TextView tv = (TextView)view.findViewById(R.id.about_version);
tv.setText(currentVersion); 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()); AlertDialog.Builder b = new AlertDialog.Builder(getActivity());
b.setTitle(R.string.menu_about) b.setTitle(R.string.menu_about)
.setView(view); .setView(view);

View File

@ -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() {
}
}