From bcbd8548dc9218e8b4227bec07a6d69b0c27cd70 Mon Sep 17 00:00:00 2001 From: Brian Nicholson Date: Tue, 6 Mar 2012 15:08:55 -0800 Subject: [PATCH] Bug 725990 - Add link support to doorhangers. r=margaret --- mobile/android/base/DoorHanger.java | 26 +++++++++++++++++++ .../base/resources/layout/doorhanger.xml | 1 + .../android/base/resources/values/colors.xml | 1 + 3 files changed, 28 insertions(+) diff --git a/mobile/android/base/DoorHanger.java b/mobile/android/base/DoorHanger.java index 6650e8c48fec..372fba2f0906 100644 --- a/mobile/android/base/DoorHanger.java +++ b/mobile/android/base/DoorHanger.java @@ -39,6 +39,10 @@ package org.mozilla.gecko; import android.content.Context; +import android.text.SpannableString; +import android.text.method.LinkMovementMethod; +import android.text.style.ForegroundColorSpan; +import android.text.style.URLSpan; import android.view.LayoutInflater; import android.view.View; import android.widget.Button; @@ -140,6 +144,28 @@ public class DoorHanger extends LinearLayout implements Button.OnClickListener { try { mTimeout = options.getLong("timeout"); } catch (JSONException e) { } + + try { + JSONObject link = options.getJSONObject("link"); + String title = mTextView.getText().toString(); + String linkLabel = link.getString("label"); + String linkUrl = link.getString("url"); + SpannableString titleWithLink = new SpannableString(title + " " + linkLabel); + URLSpan linkSpan = new URLSpan(linkUrl) { + @Override + public void onClick(View view) { + GeckoApp.mAppContext.loadUrlInTab(this.getURL()); + } + }; + + // prevent text outside the link from flashing when clicked + ForegroundColorSpan colorSpan = new ForegroundColorSpan(mTextView.getCurrentTextColor()); + titleWithLink.setSpan(colorSpan, 0, title.length(), 0); + + titleWithLink.setSpan(linkSpan, title.length() + 1, titleWithLink.length(), 0); + mTextView.setText(titleWithLink); + mTextView.setMovementMethod(LinkMovementMethod.getInstance()); + } catch (JSONException e) { } } // This method checks with persistence and timeout options to see if diff --git a/mobile/android/base/resources/layout/doorhanger.xml b/mobile/android/base/resources/layout/doorhanger.xml index 46b81842ddd4..9df165dcdf4b 100644 --- a/mobile/android/base/resources/layout/doorhanger.xml +++ b/mobile/android/base/resources/layout/doorhanger.xml @@ -6,6 +6,7 @@ android:layout_height="wrap_content" android:textAppearance="?android:attr/textAppearanceMedium" android:textColor="?android:attr/textColorPrimary" + android:textColorLink="@color/doorhanger_link" android:padding="10dp"/> #ffffff #000000 #ffffff + #ACC4D5