Clean up and extend the linkify sample.
Change-Id: If9d0451af3bfcdcd8bafb325f4b7978857efab7e
This commit is contained in:
@@ -14,43 +14,55 @@
|
||||
limitations under the License.
|
||||
-->
|
||||
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:orientation="vertical"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<!-- Four TextView widgets, each one displaying text containing links. -->
|
||||
<LinearLayout android:orientation="vertical"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:showDividers="middle"
|
||||
android:divider="?android:attr/listDivider">
|
||||
|
||||
<!-- text1 automatically linkifies things like URLs and phone numbers. -->
|
||||
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@+id/text1"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:autoLink="all"
|
||||
android:text="@string/link_text_auto"
|
||||
/>
|
||||
<!-- Four TextView widgets, each one displaying text containing links. -->
|
||||
|
||||
<!-- text2 uses a string resource containing explicit <a> tags to
|
||||
specify links. -->
|
||||
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@+id/text2"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:text="@string/link_text_manual"
|
||||
/>
|
||||
<!-- text1 automatically linkifies things like URLs and phone numbers. -->
|
||||
<TextView android:id="@+id/text1"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:paddingBottom="8dp"
|
||||
android:autoLink="all"
|
||||
android:textAppearance="?android:attr/textAppearanceMedium"
|
||||
android:text="@string/link_text_auto"
|
||||
/>
|
||||
|
||||
<!-- text3 builds the text in the Java code using HTML. -->
|
||||
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@+id/text3"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
/>
|
||||
<!-- text2 uses a string resource containing explicit <a> tags to
|
||||
specify links. -->
|
||||
<TextView android:id="@+id/text2"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:paddingTop="8dp"
|
||||
android:paddingBottom="8dp"
|
||||
android:textAppearance="?android:attr/textAppearanceMedium"
|
||||
android:text="@string/link_text_manual"
|
||||
/>
|
||||
|
||||
<!-- text4 builds the text in the Java code without using HTML. -->
|
||||
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@+id/text4"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
/>
|
||||
<!-- text3 builds the text in the Java code using HTML. -->
|
||||
<TextView android:id="@+id/text3"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:paddingTop="8dp"
|
||||
android:paddingBottom="8dp"
|
||||
android:textAppearance="?android:attr/textAppearanceMedium"
|
||||
/>
|
||||
|
||||
</LinearLayout>
|
||||
<!-- text4 builds the text in the Java code without using HTML. -->
|
||||
<TextView android:id="@+id/text4"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:paddingTop="8dp"
|
||||
android:textAppearance="?android:attr/textAppearanceMedium"
|
||||
/>
|
||||
|
||||
</LinearLayout>
|
||||
</ScrollView>
|
||||
|
||||
@@ -1019,14 +1019,21 @@
|
||||
<string name="linear_layout_8_b">B</string>
|
||||
<string name="linear_layout_8_c">C</string>
|
||||
<string name="linear_layout_9_button">Button</string>
|
||||
<string name="link_text_auto"><b>text1:</b> This is some text. In
|
||||
<string name="link_text_auto"><b>text1: Various kinds
|
||||
of data that will be auto-linked.</b> 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. And, if you
|
||||
click on (415) 555-1212 it should dial the phone.
|
||||
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.
|
||||
</string>
|
||||
<string name="link_text_manual"><b>text2:</b> This is some other
|
||||
text, with a <a href="http://www.google.com">link</a> specified
|
||||
<string name="link_text_manual"><b>text2: Explicit links using <a> markup.</b>
|
||||
This has markup for a <a href="http://www.google.com">link</a> specified
|
||||
via an <a> tag. Use a \"tel:\" URL
|
||||
to <a href="tel:4155551212">dial a phone number</a>.
|
||||
</string>
|
||||
|
||||
@@ -59,7 +59,7 @@ public class Link extends Activity {
|
||||
TextView t3 = (TextView) findViewById(R.id.text3);
|
||||
t3.setText(
|
||||
Html.fromHtml(
|
||||
"<b>text3:</b> Text with a " +
|
||||
"<b>text3: Constructed from HTML programmatically.</b> Text with a " +
|
||||
"<a href=\"http://www.google.com\">link</a> " +
|
||||
"created in the Java source code using HTML."));
|
||||
t3.setMovementMethod(LinkMovementMethod.getInstance());
|
||||
@@ -70,11 +70,11 @@ public class Link extends Activity {
|
||||
// hardcoded value.
|
||||
|
||||
SpannableString ss = new SpannableString(
|
||||
"text4: Click here to dial the phone.");
|
||||
"text4: Manually created spans. Click here to dial the phone.");
|
||||
|
||||
ss.setSpan(new StyleSpan(Typeface.BOLD), 0, 6,
|
||||
ss.setSpan(new StyleSpan(Typeface.BOLD), 0, 30,
|
||||
Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
|
||||
ss.setSpan(new URLSpan("tel:4155551212"), 13, 17,
|
||||
ss.setSpan(new URLSpan("tel:4155551212"), 31+6, 31+10,
|
||||
Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
|
||||
|
||||
TextView t4 = (TextView) findViewById(R.id.text4);
|
||||
|
||||
Reference in New Issue
Block a user