From 6eb7d31e07b8ef797e2f012f74d5764584d246b4 Mon Sep 17 00:00:00 2001
From: Jan-Felix Schmakeit
Date: Mon, 25 Mar 2013 17:43:41 +1100
Subject: Added TextLinkify sample
Change-Id: Ib325c12dffe9491f93ad763a85c2fa1bbf2d7ff1
---
views/TextLinkify/AndroidManifest.xml | 43 +++++++
views/TextLinkify/TextLinkify/build.gradle | 18 +++
.../TextLinkify/src/main/AndroidManifest.xml | 43 +++++++
.../android/views/textlinkify/MainActivity.java | 138 +++++++++++++++++++++
.../src/main/res/drawable-hdpi/ic_launcher.png | Bin 0 -> 4609 bytes
.../src/main/res/drawable-mdpi/ic_launcher.png | Bin 0 -> 2788 bytes
.../src/main/res/drawable-xhdpi/ic_launcher.png | Bin 0 -> 6597 bytes
.../src/main/res/drawable-xxhdpi/ic_launcher.png | Bin 0 -> 11663 bytes
.../src/main/res/layout/activity_main.xml | 72 +++++++++++
.../src/main/res/values-sw600dp/dimens.xml | 24 ++++
.../src/main/res/values-sw720dp-land/dimens.xml | 25 ++++
.../TextLinkify/src/main/res/values-v11/styles.xml | 27 ++++
.../TextLinkify/src/main/res/values/dimens.xml | 23 ++++
.../TextLinkify/src/main/res/values/strings.xml | 42 +++++++
.../TextLinkify/src/main/res/values/styles.xml | 40 ++++++
views/TextLinkify/build.gradle | 1 +
views/TextLinkify/settings.gradle | 2 +
views/TextLinkify/textLinkify.jd | 15 +++
18 files changed, 513 insertions(+)
create mode 100644 views/TextLinkify/AndroidManifest.xml
create mode 100644 views/TextLinkify/TextLinkify/build.gradle
create mode 100644 views/TextLinkify/TextLinkify/src/main/AndroidManifest.xml
create mode 100644 views/TextLinkify/TextLinkify/src/main/java/com/example/android/views/textlinkify/MainActivity.java
create mode 100644 views/TextLinkify/TextLinkify/src/main/res/drawable-hdpi/ic_launcher.png
create mode 100644 views/TextLinkify/TextLinkify/src/main/res/drawable-mdpi/ic_launcher.png
create mode 100644 views/TextLinkify/TextLinkify/src/main/res/drawable-xhdpi/ic_launcher.png
create mode 100644 views/TextLinkify/TextLinkify/src/main/res/drawable-xxhdpi/ic_launcher.png
create mode 100644 views/TextLinkify/TextLinkify/src/main/res/layout/activity_main.xml
create mode 100644 views/TextLinkify/TextLinkify/src/main/res/values-sw600dp/dimens.xml
create mode 100644 views/TextLinkify/TextLinkify/src/main/res/values-sw720dp-land/dimens.xml
create mode 100644 views/TextLinkify/TextLinkify/src/main/res/values-v11/styles.xml
create mode 100644 views/TextLinkify/TextLinkify/src/main/res/values/dimens.xml
create mode 100644 views/TextLinkify/TextLinkify/src/main/res/values/strings.xml
create mode 100644 views/TextLinkify/TextLinkify/src/main/res/values/styles.xml
create mode 100644 views/TextLinkify/build.gradle
create mode 100644 views/TextLinkify/settings.gradle
create mode 100644 views/TextLinkify/textLinkify.jd
(limited to 'views')
diff --git a/views/TextLinkify/AndroidManifest.xml b/views/TextLinkify/AndroidManifest.xml
new file mode 100644
index 00000000..0bf9b973
--- /dev/null
+++ b/views/TextLinkify/AndroidManifest.xml
@@ -0,0 +1,43 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/views/TextLinkify/TextLinkify/build.gradle b/views/TextLinkify/TextLinkify/build.gradle
new file mode 100644
index 00000000..5bef5eeb
--- /dev/null
+++ b/views/TextLinkify/TextLinkify/build.gradle
@@ -0,0 +1,18 @@
+buildscript {
+ repositories {
+ mavenCentral()
+ }
+ dependencies {
+ classpath 'com.android.tools.build:gradle:0.5.+'
+ }
+}
+apply plugin: 'android'
+
+dependencies {
+ compile "com.android.support:support-v4:18.0.+"
+}
+
+android {
+ compileSdkVersion 18
+ buildToolsVersion "18.0.0"
+}
diff --git a/views/TextLinkify/TextLinkify/src/main/AndroidManifest.xml b/views/TextLinkify/TextLinkify/src/main/AndroidManifest.xml
new file mode 100644
index 00000000..0bf9b973
--- /dev/null
+++ b/views/TextLinkify/TextLinkify/src/main/AndroidManifest.xml
@@ -0,0 +1,43 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/views/TextLinkify/TextLinkify/src/main/java/com/example/android/views/textlinkify/MainActivity.java b/views/TextLinkify/TextLinkify/src/main/java/com/example/android/views/textlinkify/MainActivity.java
new file mode 100644
index 00000000..9e5a7c9d
--- /dev/null
+++ b/views/TextLinkify/TextLinkify/src/main/java/com/example/android/views/textlinkify/MainActivity.java
@@ -0,0 +1,138 @@
+/*
+ * Copyright 2013 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.example.android.views.textlinkify;
+
+import android.app.Activity;
+import android.graphics.Typeface;
+import android.os.Bundle;
+import android.text.Html;
+import android.text.SpannableString;
+import android.text.Spanned;
+import android.text.method.LinkMovementMethod;
+import android.text.style.StyleSpan;
+import android.text.style.URLSpan;
+import android.widget.TextView;
+
+/**
+ * This sample demonstrates how clickable links can be added to a
+ * {@link TextView}.
+ *
+ * This can be done in three ways:
+ *
+ * - Automatically: Text added to a TextView can automatically be linkified by enabling
+ * autoLinking. In XML, use the android:autoLink property, programatically call
+ * {@link android.widget.TextView#setAutoLinkMask(int)} using an option from
+ * {@link android.text.util.Linkify}
+ *
+ * - Parsing a String as HTML: See {@link Html#fromHtml(String)})
+ *
+ * - Manually by constructing a {@link android.text.SpannableString}: Consisting of
+ * {@link android.text.style.StyleSpan} and {@link android.text.style.URLSpan} objects that
+ * are contained within a {@link android.text.SpannableString}
+ *
+ *
+ */
+public class MainActivity extends Activity {
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+
+ setContentView(R.layout.activity_main);
+
+ // BEGIN_INCLUDE(text_auto_linkify)
+ /*
+ * text_auto_linkify shows the android:autoLink property, which
+ * automatically linkifies things like URLs and phone numbers
+ * found in the text. No java code is needed to make this
+ * work.
+ * This can also be enabled programmatically by calling
+ * .setAutoLinkMask(Linkify.ALL) before the text is set on the TextView.
+ *
+ * See android.text.util.Linkify for other options, for example only
+ * auto-linking email addresses or phone numbers
+ */
+ // END_INCLUDE(text_auto_linkify)
+
+ // BEGIN_INCLUDE(text_html_resource)
+ /*
+ * text_html_resource has links specified by putting anchor tags () in the string
+ * resource. By default these links will appear but not
+ * respond to user input. To make them active, you need to
+ * call setMovementMethod() on the TextView object.
+ */
+ TextView textViewResource = (TextView) findViewById(R.id.text_html_resource);
+ textViewResource.setText(
+ Html.fromHtml(getResources().getString(R.string.link_text_manual)));
+ textViewResource.setMovementMethod(LinkMovementMethod.getInstance());
+ // END_INCLUDE(text_html_resource)
+
+ // BEGIN_INCLUDE(text_html_program)
+ /*
+ * text_html_program shows creating text with links from HTML in the Java
+ * code, rather than from a string resource. Note that for a
+ * fixed string, using a (localizable) resource as shown above
+ * is usually a better way to go; this example is intended to
+ * illustrate how you might display text that came from a
+ * dynamic source (eg, the network).
+ */
+ TextView textViewHtml = (TextView) findViewById(R.id.text_html_program);
+ textViewHtml.setText(
+ Html.fromHtml(
+ "text_html_program: Constructed from HTML programmatically."
+ + " Text with a link "
+ + "created in the Java source code using HTML."));
+ textViewHtml.setMovementMethod(LinkMovementMethod.getInstance());
+ // END_INCLUDE(text_html_program)
+
+ // BEGIN_INCLUDE(text_spannable)
+ /*
+ * text_spannable illustrates constructing a styled string containing a
+ * link without using HTML at all. Again, for a fixed string
+ * you should probably be using a string resource, not a
+ * hardcoded value.
+ */
+ SpannableString ss = new SpannableString(
+ "text_spannable: Manually created spans. Click here to dial the phone.");
+
+ /*
+ * Make the first 38 characters bold by applying a StyleSpan with bold typeface.
+ *
+ * Characters 45 to 49 (the word "here") is made clickable by applying a URLSpan
+ * pointing to a telephone number. Clicking it opens the "tel:" URL that starts the dialer.
+ *
+ * The SPAN_EXCLUSIVE_EXCLUSIVE flag defines this span as exclusive, which means
+ * that it will not expand to include text inserted on either side of this span.
+ */
+ ss.setSpan(new StyleSpan(Typeface.BOLD), 0, 39,
+ Spanned.SPAN_INCLUSIVE_INCLUSIVE);
+ ss.setSpan(new URLSpan("tel:4155551212"), 40 + 6, 40 + 10,
+ Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
+
+ TextView textViewSpan = (TextView) findViewById(R.id.text_spannable);
+ textViewSpan.setText(ss);
+
+ /*
+ * Set the movement method to move between links in this TextView.
+ * This means that the user traverses through links in this TextView, automatically
+ * handling appropriate scrolling and key commands.
+ */
+ textViewSpan.setMovementMethod(LinkMovementMethod.getInstance());
+ // END_INCLUDE(text_spannable)
+ }
+
+}
diff --git a/views/TextLinkify/TextLinkify/src/main/res/drawable-hdpi/ic_launcher.png b/views/TextLinkify/TextLinkify/src/main/res/drawable-hdpi/ic_launcher.png
new file mode 100644
index 00000000..eae36bc1
Binary files /dev/null and b/views/TextLinkify/TextLinkify/src/main/res/drawable-hdpi/ic_launcher.png differ
diff --git a/views/TextLinkify/TextLinkify/src/main/res/drawable-mdpi/ic_launcher.png b/views/TextLinkify/TextLinkify/src/main/res/drawable-mdpi/ic_launcher.png
new file mode 100644
index 00000000..f727f489
Binary files /dev/null and b/views/TextLinkify/TextLinkify/src/main/res/drawable-mdpi/ic_launcher.png differ
diff --git a/views/TextLinkify/TextLinkify/src/main/res/drawable-xhdpi/ic_launcher.png b/views/TextLinkify/TextLinkify/src/main/res/drawable-xhdpi/ic_launcher.png
new file mode 100644
index 00000000..51199d30
Binary files /dev/null and b/views/TextLinkify/TextLinkify/src/main/res/drawable-xhdpi/ic_launcher.png differ
diff --git a/views/TextLinkify/TextLinkify/src/main/res/drawable-xxhdpi/ic_launcher.png b/views/TextLinkify/TextLinkify/src/main/res/drawable-xxhdpi/ic_launcher.png
new file mode 100644
index 00000000..c49ec6a7
Binary files /dev/null and b/views/TextLinkify/TextLinkify/src/main/res/drawable-xxhdpi/ic_launcher.png differ
diff --git a/views/TextLinkify/TextLinkify/src/main/res/layout/activity_main.xml b/views/TextLinkify/TextLinkify/src/main/res/layout/activity_main.xml
new file mode 100644
index 00000000..8f35a705
--- /dev/null
+++ b/views/TextLinkify/TextLinkify/src/main/res/layout/activity_main.xml
@@ -0,0 +1,72 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/views/TextLinkify/TextLinkify/src/main/res/values-sw600dp/dimens.xml b/views/TextLinkify/TextLinkify/src/main/res/values-sw600dp/dimens.xml
new file mode 100644
index 00000000..686fe891
--- /dev/null
+++ b/views/TextLinkify/TextLinkify/src/main/res/values-sw600dp/dimens.xml
@@ -0,0 +1,24 @@
+
+
+
+
+
+
+
diff --git a/views/TextLinkify/TextLinkify/src/main/res/values-sw720dp-land/dimens.xml b/views/TextLinkify/TextLinkify/src/main/res/values-sw720dp-land/dimens.xml
new file mode 100644
index 00000000..560bd44e
--- /dev/null
+++ b/views/TextLinkify/TextLinkify/src/main/res/values-sw720dp-land/dimens.xml
@@ -0,0 +1,25 @@
+
+
+
+
+
+ 128dp
+
+
diff --git a/views/TextLinkify/TextLinkify/src/main/res/values-v11/styles.xml b/views/TextLinkify/TextLinkify/src/main/res/values-v11/styles.xml
new file mode 100644
index 00000000..91f45232
--- /dev/null
+++ b/views/TextLinkify/TextLinkify/src/main/res/values-v11/styles.xml
@@ -0,0 +1,27 @@
+
+
+
+
+
+
+
+
diff --git a/views/TextLinkify/TextLinkify/src/main/res/values/dimens.xml b/views/TextLinkify/TextLinkify/src/main/res/values/dimens.xml
new file mode 100644
index 00000000..3b1975a0
--- /dev/null
+++ b/views/TextLinkify/TextLinkify/src/main/res/values/dimens.xml
@@ -0,0 +1,23 @@
+
+
+
+
+
+ 16dp
+ 16dp
+
+
diff --git a/views/TextLinkify/TextLinkify/src/main/res/values/strings.xml b/views/TextLinkify/TextLinkify/src/main/res/values/strings.xml
new file mode 100644
index 00000000..371ee69a
--- /dev/null
+++ b/views/TextLinkify/TextLinkify/src/main/res/values/strings.xml
@@ -0,0 +1,42 @@
+
+
+
+
+
+ TextLinkify Sample
+ This sample illustrates how links can be added to a TextView.
+ \nThis can be done either automatically by setting the autoLink property
+ or explicitly.
+ text_auto_linkify: Various kinds
+ of data that will be auto-linked.
+ In this text are some things that are actionable. For instance,
+ you can click on http://www.google.com and it will launch the
+ web browser. You can click on google.com too. If you
+ click on (415) 555-1212 it should dial the phone. Or just write
+ foobar@example.com for an e-mail link. If you have a URI like
+ http://www.example.com/lala/foobar@example.com you should get the
+ full link not the e-mail address. Or you can put a location
+ like 1600 Amphitheatre Parkway, Mountain View, CA 94043. To summarize:
+ https://www.google.com, or 650-253-0000, somebody@example.com,
+ or 9606 North MoPac Expressway, Suite 400, Austin, TX 78759.
+ text_html_resource:
+ Explicit links using <a> markup.
+ This has markup for a link specified
+ via an <a> tag. Use a \"tel:\" URL
+ to dial a phone number.]]>
+
+
diff --git a/views/TextLinkify/TextLinkify/src/main/res/values/styles.xml b/views/TextLinkify/TextLinkify/src/main/res/values/styles.xml
new file mode 100644
index 00000000..91da12c4
--- /dev/null
+++ b/views/TextLinkify/TextLinkify/src/main/res/values/styles.xml
@@ -0,0 +1,40 @@
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/views/TextLinkify/build.gradle b/views/TextLinkify/build.gradle
new file mode 100644
index 00000000..495c5038
--- /dev/null
+++ b/views/TextLinkify/build.gradle
@@ -0,0 +1 @@
+// Top-level build file where you can add configuration options common to all sub-projects/modules.
diff --git a/views/TextLinkify/settings.gradle b/views/TextLinkify/settings.gradle
new file mode 100644
index 00000000..20429823
--- /dev/null
+++ b/views/TextLinkify/settings.gradle
@@ -0,0 +1,2 @@
+include ':TextLinkify'
+
diff --git a/views/TextLinkify/textLinkify.jd b/views/TextLinkify/textLinkify.jd
new file mode 100644
index 00000000..ca39b7b2
--- /dev/null
+++ b/views/TextLinkify/textLinkify.jd
@@ -0,0 +1,15 @@
+page.title=Linkify Sample
+@jd:body
+This sample demonstrates how clickable links can be added to a
+ TextView.
+ This can be done automatically (see
+
+TextView#setAutoLinkMask(int)), explicitly by parsing a String as
+ HTML (see
+
+ Html#fromHtml(String)) or using a
+ SpannableString
+ consisting of
+ StyleSpan
+ and URLSpan
+ objects.
\ No newline at end of file
--
cgit v1.2.3