Bug 725990 - Add link support to doorhangers. r=margaret
authorBrian Nicholson <bnicholson@mozilla.com>
Tue, 06 Mar 2012 15:08:55 -0800
changeset 88416 55051c4e95c7ea0d508cd707a5d40fe1536dea6e
parent 88415 9c66a3ed924a6d6fc3ab192cc14e7e10cfe0bbdf
child 88417 4091b2b24293f47d1d6e3774dcd75b6673f7e77b
push id22194
push usermak77@bonardo.net
push dateWed, 07 Mar 2012 09:33:54 +0000
treeherdermozilla-central@8ef88a69f861 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmargaret
bugs725990
milestone13.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 725990 - Add link support to doorhangers. r=margaret
mobile/android/base/DoorHanger.java
mobile/android/base/resources/layout/doorhanger.xml
mobile/android/base/resources/values/colors.xml
--- a/mobile/android/base/DoorHanger.java
+++ b/mobile/android/base/DoorHanger.java
@@ -34,16 +34,20 @@
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
 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;
 import android.widget.LinearLayout;
 import android.widget.TextView;
 
 import org.json.JSONObject;
 import org.json.JSONException;
@@ -135,16 +139,38 @@ public class DoorHanger extends LinearLa
     public void setOptions(JSONObject options) {
         try {
             mPersistence = options.getInt("persistence");
         } catch (JSONException e) { }
 
         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
     // it's okay to remove a doorhanger.
     public boolean shouldRemove() {
         // If persistence is set to -1, the doorhanger will never be
         // automatically removed.
         if (mPersistence != 0) {
--- a/mobile/android/base/resources/layout/doorhanger.xml
+++ b/mobile/android/base/resources/layout/doorhanger.xml
@@ -1,16 +1,17 @@
 <?xml version="1.0" encoding="utf-8"?>
 <merge xmlns:android="http://schemas.android.com/apk/res/android">
 
     <TextView android:id="@+id/doorhanger_title"
               android:layout_width="fill_parent"
               android:layout_height="wrap_content"
               android:textAppearance="?android:attr/textAppearanceMedium"
               android:textColor="?android:attr/textColorPrimary"
+              android:textColorLink="@color/doorhanger_link"
               android:padding="10dp"/>
 
     <LinearLayout android:id="@+id/doorhanger_choices"
                   style="@android:style/ButtonBar"
                   android:layout_width="fill_parent"
                   android:layout_height="wrap_content"
                   android:orientation="horizontal"/>
 
--- a/mobile/android/base/resources/values/colors.xml
+++ b/mobile/android/base/resources/values/colors.xml
@@ -1,8 +1,9 @@
 <?xml version="1.0" encoding="utf-8"?>
 <resources>
   <color name="splash_background">#000000</color>
   <color name="splash_msgfont">#ffffff</color>
   <color name="splash_urlfont">#000000</color>
   <color name="splash_content">#ffffff</color>
+  <color name="doorhanger_link">#ACC4D5</color>
 </resources>