Bug 959777 - Create generic parent class TwoLineRow for TwoRowPageRow (r=margaret)
authorLucas Rocha <lucasr@mozilla.com>
Mon, 27 Jan 2014 13:29:54 -0800
changeset 181475 53f58523637d9d500b999136d5a0dc53142577e2
parent 181474 313023e201fed6c309dfa0da2d9639b1f0125598
child 181476 2f7bda3e92f7b8e22993b13e72d706d4027f9140
push id3343
push userffxbld
push dateMon, 17 Mar 2014 21:55:32 +0000
treeherdermozilla-beta@2f7d3415f79f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmargaret
bugs959777
milestone29.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 959777 - Create generic parent class TwoLineRow for TwoRowPageRow (r=margaret)
mobile/android/base/home/TwoLinePageRow.java
mobile/android/base/home/TwoLineRow.java
mobile/android/base/moz.build
mobile/android/base/resources/layout/two_line_page_row.xml
mobile/android/base/resources/layout/two_line_row.xml
mobile/android/base/resources/values-large-land-v11/styles.xml
mobile/android/base/resources/values-v16/styles.xml
mobile/android/base/resources/values/styles.xml
--- a/mobile/android/base/home/TwoLinePageRow.java
+++ b/mobile/android/base/home/TwoLinePageRow.java
@@ -16,33 +16,24 @@ import org.mozilla.gecko.favicons.OnFavi
 import org.mozilla.gecko.util.ThreadUtils;
 import org.mozilla.gecko.widget.FaviconView;
 
 import android.content.Context;
 import android.database.Cursor;
 import android.graphics.Bitmap;
 import android.text.TextUtils;
 import android.util.AttributeSet;
-import android.view.Gravity;
-import android.view.LayoutInflater;
-import android.widget.LinearLayout;
-import android.widget.TextView;
 
 import java.lang.ref.WeakReference;
 
-public class TwoLinePageRow extends LinearLayout
+public class TwoLinePageRow extends TwoLineRow
                             implements Tabs.OnTabsChangedListener {
-    private static final int NO_ICON = 0;
 
-    private final TextView mTitle;
-    private final TextView mUrl;
     private final FaviconView mFavicon;
 
-    private int mUrlIconId;
-    private int mBookmarkIconId;
     private boolean mShowIcons;
     private int mLoadFaviconJobId = Favicons.NOT_LOADING;
 
     // Only holds a reference to the FaviconView itself, so if the row gets
     // discarded while a task is outstanding, we'll leak less memory.
     private static class UpdateViewFaviconLoadedListener implements OnFaviconLoadedListener {
         private final WeakReference<FaviconView> view;
         public UpdateViewFaviconLoadedListener(FaviconView view) {
@@ -74,26 +65,19 @@ public class TwoLinePageRow extends Line
 
     public TwoLinePageRow(Context context) {
         this(context, null);
     }
 
     public TwoLinePageRow(Context context, AttributeSet attrs) {
         super(context, attrs);
 
-        setGravity(Gravity.CENTER_VERTICAL);
-
-        mUrlIconId = NO_ICON;
-        mBookmarkIconId = NO_ICON;
         mShowIcons = true;
 
-        LayoutInflater.from(context).inflate(R.layout.two_line_page_row, this);
-        mTitle = (TextView) findViewById(R.id.title);
-        mUrl = (TextView) findViewById(R.id.url);
-        mFavicon = (FaviconView) findViewById(R.id.favicon);
+        mFavicon = (FaviconView) findViewById(R.id.icon);
         mFaviconListener = new UpdateViewFaviconLoadedListener(mFavicon);
     }
 
     @Override
     protected void onAttachedToWindow() {
         Tabs.registerOnTabsChangedListener(this);
     }
 
@@ -115,46 +99,16 @@ public class TwoLinePageRow extends Line
             case ADDED:
             case CLOSED:
             case LOCATION_CHANGE:
                 updateDisplayedUrl();
                 break;
         }
     }
 
-    private void setTitle(String title) {
-        mTitle.setText(title);
-    }
-
-    private void setUrl(String url) {
-        mUrl.setText(url);
-    }
-
-    private void setUrl(int stringId) {
-        mUrl.setText(stringId);
-    }
-
-    private void setUrlIcon(int urlIconId) {
-        if (mUrlIconId == urlIconId) {
-            return;
-        }
-
-        mUrlIconId = urlIconId;
-        mUrl.setCompoundDrawablesWithIntrinsicBounds(mUrlIconId, 0, mBookmarkIconId, 0);
-    }
-
-    private void setBookmarkIcon(int bookmarkIconId) {
-        if (mBookmarkIconId == bookmarkIconId) {
-            return;
-        }
-
-        mBookmarkIconId = bookmarkIconId;
-        mUrl.setCompoundDrawablesWithIntrinsicBounds(mUrlIconId, 0, mBookmarkIconId, 0);
-    }
-
     /**
      * Stores the page URL, so that we can use it to replace "Switch to tab" if the open
      * tab changes or is closed.
      */
     private void updateDisplayedUrl(String url) {
         mPageUrl = url;
         updateDisplayedUrl();
     }
@@ -163,28 +117,29 @@ public class TwoLinePageRow extends Line
      * Replaces the page URL with "Switch to tab" if there is already a tab open with that URL.
      * Only looks for tabs that are either private or non-private, depending on the current 
      * selected tab.
      */
     private void updateDisplayedUrl() {
         boolean isPrivate = Tabs.getInstance().getSelectedTab().isPrivate();
         int tabId = Tabs.getInstance().getTabIdForUrl(mPageUrl, isPrivate);
         if (!mShowIcons || tabId < 0) {
-            setUrl(mPageUrl);
-            setUrlIcon(NO_ICON);
+            setSecondaryText(mPageUrl);
+            setSecondaryIcon(NO_ICON);
         } else {
-            setUrl(R.string.switch_to_tab);
-            setUrlIcon(R.drawable.ic_url_bar_tab);
+            setSecondaryText(R.string.switch_to_tab);
+            setSecondaryIcon(R.drawable.ic_url_bar_tab);
         }
     }
 
     public void setShowIcons(boolean showIcons) {
         mShowIcons = showIcons;
     }
 
+    @Override
     public void updateFromCursor(Cursor cursor) {
         if (cursor == null) {
             return;
         }
 
         int titleIndex = cursor.getColumnIndexOrThrow(URLColumns.TITLE);
         final String title = cursor.getString(titleIndex);
 
@@ -202,30 +157,30 @@ public class TwoLinePageRow extends Line
                     display = cursor.getInt(displayIndex);
                 } else {
                     display = Combined.DISPLAY_NORMAL;
                 }
 
                 // The bookmark id will be 0 (null in database) when the url
                 // is not a bookmark.
                 if (bookmarkId == 0) {
-                    setBookmarkIcon(NO_ICON);
+                    setPrimaryIcon(NO_ICON);
                 } else if (display == Combined.DISPLAY_READER) {
-                    setBookmarkIcon(R.drawable.ic_url_bar_reader);
+                    setPrimaryIcon(R.drawable.ic_url_bar_reader);
                 } else {
-                    setBookmarkIcon(R.drawable.ic_url_bar_star);
+                    setPrimaryIcon(R.drawable.ic_url_bar_star);
                 }
             } else {
-                setBookmarkIcon(NO_ICON);
+                setPrimaryIcon(NO_ICON);
             }
         }
 
         // Use the URL instead of an empty title for consistency with the normal URL
         // bar view - this is the equivalent of getDisplayTitle() in Tab.java
-        setTitle(TextUtils.isEmpty(title) ? url : title);
+        setPrimaryText(TextUtils.isEmpty(title) ? url : title);
 
         // No point updating the below things if URL has not changed. Prevents evil Favicon flicker.
         if (url.equals(mPageUrl)) {
             return;
         }
 
         // Blank the Favicon, so we don't show the wrong Favicon if we scroll and miss DB.
         mFavicon.clearImage();
new file mode 100644
--- /dev/null
+++ b/mobile/android/base/home/TwoLineRow.java
@@ -0,0 +1,77 @@
+/* -*- 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.home;
+
+import org.mozilla.gecko.R;
+
+import android.content.Context;
+import android.database.Cursor;
+import android.util.AttributeSet;
+import android.view.Gravity;
+import android.view.LayoutInflater;
+import android.widget.LinearLayout;
+import android.widget.TextView;
+
+import java.lang.ref.WeakReference;
+
+public abstract class TwoLineRow extends LinearLayout {
+    protected static final int NO_ICON = 0;
+
+    private final TextView mPrimaryText;
+    private int mPrimaryIconId;
+
+    private final TextView mSecondaryText;
+    private int mSecondaryIconId;
+
+    public TwoLineRow(Context context) {
+        this(context, null);
+    }
+
+    public TwoLineRow(Context context, AttributeSet attrs) {
+        super(context, attrs);
+
+        setGravity(Gravity.CENTER_VERTICAL);
+
+        mSecondaryIconId = NO_ICON;
+        mPrimaryIconId = NO_ICON;
+
+        LayoutInflater.from(context).inflate(R.layout.two_line_row, this);
+        mPrimaryText = (TextView) findViewById(R.id.primary_text);
+        mSecondaryText = (TextView) findViewById(R.id.secondary_text);
+    }
+
+    protected void setPrimaryText(String text) {
+        mPrimaryText.setText(text);
+    }
+
+    protected void setSecondaryText(String text) {
+        mSecondaryText.setText(text);
+    }
+
+    protected void setSecondaryText(int stringId) {
+        mSecondaryText.setText(stringId);
+    }
+
+    protected void setPrimaryIcon(int iconId) {
+        if (mPrimaryIconId == iconId) {
+            return;
+        }
+
+        mPrimaryIconId = iconId;
+        mSecondaryText.setCompoundDrawablesWithIntrinsicBounds(mSecondaryIconId, 0, mPrimaryIconId, 0);
+    }
+
+    protected void setSecondaryIcon(int iconId) {
+        if (mSecondaryIconId == iconId) {
+            return;
+        }
+
+        mSecondaryIconId = iconId;
+        mSecondaryText.setCompoundDrawablesWithIntrinsicBounds(mSecondaryIconId, 0, mPrimaryIconId, 0);
+    }
+
+    public abstract void updateFromCursor(Cursor cursor);
+}
--- a/mobile/android/base/moz.build
+++ b/mobile/android/base/moz.build
@@ -237,16 +237,17 @@ gbjar.sources += [
     'home/SimpleCursorLoader.java',
     'home/SuggestClient.java',
     'home/TabMenuStrip.java',
     'home/TopSitesGridItemView.java',
     'home/TopSitesGridView.java',
     'home/TopSitesPanel.java',
     'home/TopSitesThumbnailView.java',
     'home/TwoLinePageRow.java',
+    'home/TwoLineRow.java',
     'InputMethods.java',
     'JavaAddonManager.java',
     'LightweightTheme.java',
     'LightweightThemeDrawable.java',
     'LocaleManager.java',
     'MediaCastingBar.java',
     'MemoryMonitor.java',
     'menu/GeckoMenu.java',
rename from mobile/android/base/resources/layout/two_line_page_row.xml
rename to mobile/android/base/resources/layout/two_line_row.xml
--- a/mobile/android/base/resources/layout/two_line_page_row.xml
+++ b/mobile/android/base/resources/layout/two_line_row.xml
@@ -1,36 +1,36 @@
 <?xml version="1.0" encoding="utf-8"?>
 <!-- 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/. -->
 
 <merge xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:gecko="http://schemas.android.com/apk/res-auto">
 
-    <org.mozilla.gecko.widget.FaviconView android:id="@+id/favicon"
+    <org.mozilla.gecko.widget.FaviconView android:id="@+id/icon"
                                           android:layout_width="@dimen/favicon_bg"
                                           android:layout_height="@dimen/favicon_bg"
                                           android:layout_marginLeft="10dip"
                                           android:layout_marginRight="10dip"/>
 
     <LinearLayout android:layout_width="fill_parent"
                   android:layout_height="wrap_content"
                   android:layout_marginRight="10dip"
                   android:orientation="vertical">
 
         <org.mozilla.gecko.home.FadedTextView
-                android:id="@+id/title"
-                style="@style/Widget.TwoLinePageRow.Title"
+                android:id="@+id/primary_text"
+                style="@style/Widget.TwoLineRow.PrimaryText"
                 android:layout_width="fill_parent"
                 android:layout_height="wrap_content"
                 gecko:fadeWidth="30dp"/>
 
-        <TextView android:id="@+id/url"
-                  style="@style/Widget.TwoLinePageRow.Url"
+        <TextView android:id="@+id/secondary_text"
+                  style="@style/Widget.TwoLineRow.SecondaryText"
                   android:layout_width="fill_parent"
                   android:layout_height="wrap_content"
                   android:drawablePadding="5dp"
                   android:maxLength="1024"/>
 
     </LinearLayout>
 
 </merge>
--- a/mobile/android/base/resources/values-large-land-v11/styles.xml
+++ b/mobile/android/base/resources/values-large-land-v11/styles.xml
@@ -4,23 +4,23 @@
    - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
 
 <resources>
 
     <style name="TabsList" parent="TabsListBase">
          <item name="android:orientation">vertical</item>
     </style>
 
-    <style name="Widget.BookmarkFolderView" parent="Widget.TwoLinePageRow.Title">
+    <style name="Widget.BookmarkFolderView" parent="Widget.TwoLineRow.PrimaryText">
         <item name="android:paddingLeft">60dip</item>
         <item name="android:drawablePadding">10dip</item>
         <item name="android:drawableLeft">@drawable/bookmark_folder</item>
     </style>
 
-    <style name="Widget.BookmarkItemView" parent="Widget.TwoLinePageRow">
+    <style name="Widget.BookmarkItemView" parent="Widget.TwoLineRow">
         <item name="android:paddingLeft">50dp</item>
         <item name="android:paddingRight">50dp</item>
     </style>
 
     <style name="Widget.BookmarksListView" parent="Widget.HomeListView">
         <item name="android:paddingTop">30dp</item>
         <item name="android:paddingLeft">120dp</item>
         <item name="android:paddingRight">120dp</item>
--- a/mobile/android/base/resources/values-v16/styles.xml
+++ b/mobile/android/base/resources/values-v16/styles.xml
@@ -4,17 +4,17 @@
    - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
 
 <resources xmlns:android="http://schemas.android.com/apk/res/android">
 
     <style name="TextAppearance.EmptyMessage" parent="TextAppearance.Large">
         <item name="android:fontFamily">sans-serif-light</item>
     </style>
 
-    <style name="TextAppearance.Widget.TwoLinePageRow.Title" parent="TextAppearance.Medium">
+    <style name="TextAppearance.Widget.TwoLineRow.PrimaryText" parent="TextAppearance.Medium">
         <item name="android:fontFamily">sans-serif-light</item>
     </style>
 
     <style name="TextAppearance.Widget.Home.PageTitle" parent="TextAppearance.Medium">
         <item name="android:fontFamily">sans-serif-light</item>
     </style>
 
 </resources>
--- a/mobile/android/base/resources/values/styles.xml
+++ b/mobile/android/base/resources/values/styles.xml
@@ -104,32 +104,32 @@
         <item name="android:paddingRight">10dip</item>
         <item name="android:drawablePadding">6dip</item>
         <item name="android:gravity">center_vertical</item>
         <item name="android:textAppearance">@style/TextAppearance</item>
         <item name="android:singleLine">true</item>
         <item name="android:ellipsize">middle</item>
     </style>
 
-    <style name="Widget.TwoLinePageRow" />
+    <style name="Widget.TwoLineRow" />
 
-    <style name="Widget.TwoLinePageRow.Title">
-        <item name="android:textAppearance">@style/TextAppearance.Widget.TwoLinePageRow.Title</item>
+    <style name="Widget.TwoLineRow.PrimaryText">
+        <item name="android:textAppearance">@style/TextAppearance.Widget.TwoLineRow.PrimaryText</item>
         <item name="android:singleLine">true</item>
         <item name="android:ellipsize">none</item>
     </style>
 
-    <style name="Widget.TwoLinePageRow.Url">
-        <item name="android:textAppearance">@style/TextAppearance.Widget.TwoLinePageRow.Url</item>
+    <style name="Widget.TwoLineRow.SecondaryText">
+        <item name="android:textAppearance">@style/TextAppearance.Widget.TwoLineRow.SecondaryText</item>
         <item name="android:includeFontPadding">false</item>
         <item name="android:singleLine">true</item>
         <item name="android:ellipsize">middle</item>
     </style>
 
-    <style name="Widget.BookmarkFolderView" parent="Widget.TwoLinePageRow.Title">
+    <style name="Widget.BookmarkFolderView" parent="Widget.TwoLineRow.PrimaryText">
         <item name="android:paddingLeft">10dip</item>
         <item name="android:drawablePadding">10dip</item>
         <item name="android:drawableLeft">@drawable/bookmark_folder</item>
     </style>
 
     <style name="Widget.TopSitesGridView" parent="Widget.GridView">
         <item name="android:padding">7dp</item>
         <item name="android:horizontalSpacing">0dp</item>
@@ -138,17 +138,17 @@
 
     <style name="Widget.TopSitesGridItemView">
       <item name="android:layout_width">fill_parent</item>
       <item name="android:layout_height">fill_parent</item>
       <item name="android:padding">5dip</item>
       <item name="android:orientation">vertical</item>
     </style>
 
-    <style name="Widget.BookmarkItemView" parent="Widget.TwoLinePageRow"/>
+    <style name="Widget.BookmarkItemView" parent="Widget.TwoLineRow"/>
 
     <style name="Widget.BookmarksListView" parent="Widget.HomeListView"/>
 
     <style name="Widget.TopSitesThumbnailView">
       <item name="android:padding">0dip</item>
       <item name="android:scaleType">centerCrop</item>
     </style>
 
@@ -312,21 +312,21 @@
         <item name="android:textColor">?android:attr/textColorHint</item>
     </style>
 
     <style name="TextAppearance.Widget.HomePagerTabMenuStrip" parent="TextAppearance.Small">
         <item name="android:textColor">?android:attr/textColorHint</item>
         <item name="android:textSize">14sp</item>
     </style>
 
-    <style name="TextAppearance.Widget.TwoLinePageRow" />
+    <style name="TextAppearance.Widget.TwoLineRow" />
 
-    <style name="TextAppearance.Widget.TwoLinePageRow.Title" parent="TextAppearance.Medium"/>
+    <style name="TextAppearance.Widget.TwoLineRow.PrimaryText" parent="TextAppearance.Medium"/>
 
-    <style name="TextAppearance.Widget.TwoLinePageRow.Url" parent="TextAppearance.Micro">
+    <style name="TextAppearance.Widget.TwoLineRow.SecondaryText" parent="TextAppearance.Micro">
         <item name="android:textColor">?android:attr/textColorSecondary</item>
     </style>
 
     <style name="TextAppearance.Widget.SuggestionsPrompt" parent="TextAppearance.Small">
         <item name="android:textColor">@color/url_bar_title</item>
     </style>
 
     <style name="TextAppearance.Widget.Home" />