Bug 1173623 - Update "Learn more" link in Tracking protection to be consistent with other doorhanger links. r=ally
authorChenxia Liu <liuche@mozilla.com>
Wed, 01 Jul 2015 15:29:36 -0700
changeset 275828 d51f71a4ef4f0d4d1b11d81209edad4a13164bb6
parent 275827 2ded281cd414e8799cbebaab4fe2c8178e0bd3dc
child 275829 d028004c974465b9a2419272ae70e0e4a527cfdd
push id3246
push usergijskruitbosch@gmail.com
push dateTue, 07 Jul 2015 09:06:38 +0000
reviewersally
bugs1173623
milestone42.0a1
Bug 1173623 - Update "Learn more" link in Tracking protection to be consistent with other doorhanger links. r=ally
mobile/android/base/resources/layout/doorhanger.xml
mobile/android/base/resources/layout/login_doorhanger.xml
mobile/android/base/toolbar/SiteIdentityPopup.java
mobile/android/base/widget/DefaultDoorHanger.java
mobile/android/base/widget/DoorHanger.java
mobile/android/base/widget/DoorhangerConfig.java
mobile/android/base/widget/LoginDoorHanger.java
--- a/mobile/android/base/resources/layout/doorhanger.xml
+++ b/mobile/android/base/resources/layout/doorhanger.xml
@@ -27,16 +27,25 @@
                       android:layout_marginBottom="@dimen/doorhanger_section_padding_small"
                       android:textAppearance="@style/TextAppearance.DoorHanger.Medium.Light"
                       android:visibility="gone"/>
 
             <ViewStub android:id="@+id/content"
                       android:layout_width="match_parent"
                       android:layout_height="wrap_content"/>
 
+            <TextView android:id="@+id/doorhanger_link"
+                      android:layout_width="match_parent"
+                      android:layout_height="wrap_content"
+                      android:textAppearance="@style/TextAppearance.DoorHanger.Medium"
+                      android:textColor="@color/link_blue"
+                      android:layout_marginTop="@dimen/doorhanger_section_padding_large"
+                      android:layout_marginBottom="@dimen/doorhanger_section_padding_small"
+                      android:visibility="gone"/>
+
         </LinearLayout>
 
     </LinearLayout>
 
     <LinearLayout android:layout_width="match_parent"
                   android:layout_height="wrap_content"
                   android:orientation="horizontal">
 
--- a/mobile/android/base/resources/layout/login_doorhanger.xml
+++ b/mobile/android/base/resources/layout/login_doorhanger.xml
@@ -7,20 +7,11 @@
               android:layout_width="match_parent"
               android:layout_height="wrap_content"
               android:orientation="vertical">
 
     <TextView android:id="@+id/doorhanger_message"
               android:focusable="true"
               android:layout_width="match_parent"
               android:layout_height="wrap_content"
-              android:layout_marginBottom="@dimen/doorhanger_section_padding_large"
               android:textAppearance="@style/TextAppearance.DoorHanger.Medium"/>
 
-    <TextView android:id="@+id/doorhanger_link"
-              android:layout_width="match_parent"
-              android:layout_height="wrap_content"
-              android:textAppearance="@style/TextAppearance.DoorHanger.Medium"
-              android:textColor="@color/link_blue"
-              android:layout_marginBottom="@dimen/doorhanger_section_padding_small"
-              android:visibility="gone"/>
-
 </LinearLayout>
--- a/mobile/android/base/toolbar/SiteIdentityPopup.java
+++ b/mobile/android/base/toolbar/SiteIdentityPopup.java
@@ -324,17 +324,17 @@ public class SiteIdentityPopup extends A
             icon = R.drawable.shield_enabled_doorhanger;
             config.setMessage(mContext.getString(R.string.blocked_mixed_content_message_top) + "\n\n" +
                       mContext.getString(R.string.blocked_mixed_content_message_bottom));
         } else {
             icon = R.drawable.shield_disabled_doorhanger;
             config.setMessage(mContext.getString(R.string.loaded_mixed_content_message));
         }
 
-        config.setLink(mContext.getString(R.string.learn_more), MIXED_CONTENT_SUPPORT_URL, "\n\n");
+        config.setLink(mContext.getString(R.string.learn_more), MIXED_CONTENT_SUPPORT_URL);
         addNotificationButtons(config, blocked);
 
         mMixedContentNotification = DoorHanger.Get(mContext, config);
         mMixedContentNotification.setIcon(icon);
 
         mContent.addView(mMixedContentNotification);
         mDivider.setVisibility(View.VISIBLE);
     }
@@ -358,17 +358,17 @@ public class SiteIdentityPopup extends A
             config.setMessage(mContext.getString(R.string.blocked_tracking_content_message_top) + "\n\n" +
                       mContext.getString(R.string.blocked_tracking_content_message_bottom));
         } else {
             icon = R.drawable.shield_disabled_doorhanger;
             config.setMessage(mContext.getString(R.string.loaded_tracking_content_message_top) + "\n\n" +
                       mContext.getString(R.string.loaded_tracking_content_message_bottom));
         }
 
-        config.setLink(mContext.getString(R.string.learn_more), TRACKING_CONTENT_SUPPORT_URL, "\n\n");
+        config.setLink(mContext.getString(R.string.learn_more), TRACKING_CONTENT_SUPPORT_URL);
         addNotificationButtons(config, blocked);
 
         mTrackingContentNotification = DoorHanger.Get(mContext, config);
 
         mTrackingContentNotification.setIcon(icon);
 
 
         mContent.addView(mTrackingContentNotification);
--- a/mobile/android/base/widget/DefaultDoorHanger.java
+++ b/mobile/android/base/widget/DefaultDoorHanger.java
@@ -1,21 +1,17 @@
 /* -*- Mode: Java; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*-
  * This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 package org.mozilla.gecko.widget;
 
 import android.text.Html;
-import android.text.SpannableString;
 import android.text.Spanned;
-import android.text.method.LinkMovementMethod;
-import android.text.style.ForegroundColorSpan;
-import android.text.style.URLSpan;
 import android.util.Log;
 import android.widget.Button;
 import android.widget.TextView;
 import org.mozilla.gecko.R;
 import org.mozilla.gecko.Tabs;
 import org.mozilla.gecko.prompts.PromptInput;
 
 import org.json.JSONArray;
@@ -61,17 +57,17 @@ public class DefaultDoorHanger extends D
 
         final JSONObject options = config.getOptions();
         if (options != null) {
             setOptions(options);
         }
 
         final DoorhangerConfig.Link link = config.getLink();
         if (link != null) {
-            addLink(link.label, link.url, link.delimiter);
+            addLink(link.label, link.url);
         }
 
         addButtonsToLayout(config);
     }
 
     @Override
     protected int getContentResource() {
         return R.layout.default_doorhanger;
@@ -88,17 +84,17 @@ public class DefaultDoorHanger extends D
     @Override
     public void setOptions(final JSONObject options) {
         super.setOptions(options);
         final JSONObject link = options.optJSONObject("link");
         if (link != null) {
             try {
                 final String linkLabel = link.getString("label");
                 final String linkUrl = link.getString("url");
-                addLink(linkLabel, linkUrl, " ");
+                addLink(linkLabel, linkUrl);
             } catch (JSONException e) { }
         }
 
         final JSONArray inputs = options.optJSONArray("inputs");
         if (inputs != null) {
             mInputs = new ArrayList<PromptInput>();
 
             final ViewGroup group = (ViewGroup) findViewById(R.id.doorhanger_inputs);
@@ -170,33 +166,25 @@ public class DefaultDoorHanger extends D
         };
     }
 
     private void setMessage(String message) {
         Spanned markupMessage = Html.fromHtml(message);
         mMessage.setText(markupMessage);
     }
 
-    private void addLink(String label, String url, String delimiter) {
-        String title = mMessage.getText().toString();
-        SpannableString titleWithLink = new SpannableString(title + delimiter + label);
-        URLSpan linkSpan = new URLSpan(url) {
+    private void addLink(String label, final String url) {
+        mLink.setText(label);
+        mLink.setOnClickListener(new OnClickListener() {
             @Override
             public void onClick(View view) {
-                Tabs.getInstance().loadUrlInTab(getURL());
+                 Tabs.getInstance().loadUrlInTab(url);
             }
-        };
-
-        // Prevent text outside the link from flashing when clicked.
-        ForegroundColorSpan colorSpan = new ForegroundColorSpan(mMessage.getCurrentTextColor());
-        titleWithLink.setSpan(colorSpan, 0, title.length(), 0);
-
-        titleWithLink.setSpan(linkSpan, title.length() + 1, titleWithLink.length(), 0);
-        mMessage.setText(titleWithLink);
-        mMessage.setMovementMethod(LinkMovementMethod.getInstance());
+        });
+        mLink.setVisibility(VISIBLE);
     }
 
     private void styleInput(PromptInput input, View view) {
         if (input instanceof PromptInput.MenulistInput) {
             styleDropdownInputs(input, view);
         }
         view.setPadding(0, 0, 0, mResources.getDimensionPixelSize(R.dimen.doorhanger_subsection_padding));
     }
--- a/mobile/android/base/widget/DoorHanger.java
+++ b/mobile/android/base/widget/DoorHanger.java
@@ -54,16 +54,17 @@ public abstract class DoorHanger extends
     private final int mTabId;
 
     // DoorHanger identifier.
     private final String mIdentifier;
 
     protected final Type mType;
 
     protected final ImageView mIcon;
+    protected final TextView mLink;
     protected final TextView mDoorhangerTitle;
 
     protected final Context mContext;
     protected final Resources mResources;
 
     protected int mDividerColor;
 
     protected boolean mPersistWhileVisible;
@@ -79,16 +80,17 @@ public abstract class DoorHanger extends
         mIdentifier = config.getId();
         mType = type;
 
         LayoutInflater.from(context).inflate(R.layout.doorhanger, this);
         setOrientation(VERTICAL);
 
         mDivider = findViewById(R.id.divider_doorhanger);
         mIcon = (ImageView) findViewById(R.id.doorhanger_icon);
+        mLink = (TextView) findViewById(R.id.doorhanger_link);
         mDoorhangerTitle = (TextView) findViewById(R.id.doorhanger_title);
 
         mNegativeButton = (Button) findViewById(R.id.doorhanger_button_negative);
         mPositiveButton = (Button) findViewById(R.id.doorhanger_button_positive);
         mOnButtonClickListener = config.getButtonClickListener();
 
         mDividerColor = mResources.getColor(R.color.divider_light);
 
--- a/mobile/android/base/widget/DoorhangerConfig.java
+++ b/mobile/android/base/widget/DoorhangerConfig.java
@@ -9,22 +9,20 @@ import org.json.JSONObject;
 
 import org.mozilla.gecko.widget.DoorHanger.Type;
 
 public class DoorhangerConfig {
 
     public static class Link {
         public final String label;
         public final String url;
-        public final String delimiter;
 
-        private Link(String label, String url, String delimiter) {
+        private Link(String label, String url) {
             this.label = label;
             this.url = url;
-            this.delimiter = delimiter;
         }
     }
 
     public static class ButtonConfig {
         public final String label;
         public final int callback;
 
         public ButtonConfig(String label, int callback) {
@@ -102,16 +100,16 @@ public class DoorhangerConfig {
     public  ButtonConfig getNegativeButtonConfig() {
         return negativeButtonConfig;
     }
 
     public DoorHanger.OnButtonClickListener getButtonClickListener() {
         return this.buttonClickListener;
     }
 
-    public void setLink(String label, String url, String delimiter) {
-        this.link = new Link(label, url, delimiter);
+    public void setLink(String label, String url) {
+        this.link = new Link(label, url);
     }
 
     public Link getLink() {
         return link;
     }
 }
--- a/mobile/android/base/widget/LoginDoorHanger.java
+++ b/mobile/android/base/widget/LoginDoorHanger.java
@@ -31,24 +31,22 @@ import org.mozilla.gecko.R;
 import org.mozilla.gecko.favicons.Favicons;
 import org.mozilla.gecko.favicons.OnFaviconLoadedListener;
 
 public class LoginDoorHanger extends DoorHanger {
     private static final String LOGTAG = "LoginDoorHanger";
     private enum ActionType { EDIT, SELECT }
 
     private final TextView mMessage;
-    private final TextView mLink;
     private final DoorhangerConfig.ButtonConfig mButtonConfig;
 
     public LoginDoorHanger(Context context, DoorhangerConfig config) {
         super(context, config, Type.LOGIN);
 
         mMessage = (TextView) findViewById(R.id.doorhanger_message);
-        mLink = (TextView) findViewById(R.id.doorhanger_link);
         mIcon.setImageResource(R.drawable.icon_key);
         mIcon.setVisibility(View.VISIBLE);
 
         mButtonConfig = config.getPositiveButtonConfig();
 
         loadConfig(config);
     }