From 92b2c31da3f34e9272a662bae41ecc698b70a40e Mon Sep 17 00:00:00 2001 From: Lucas Rocha Date: Fri, 7 Feb 2014 13:29:40 +0000 Subject: [PATCH] Bug 964508 - Rename TwoLineRow members and move icon code to TwoLinePageRow (r=margaret) --- mobile/android/base/home/PanelListRow.java | 4 +- mobile/android/base/home/TwoLinePageRow.java | 47 +++++++++++++++---- mobile/android/base/home/TwoLineRow.java | 46 ++++-------------- .../base/resources/layout/two_line_row.xml | 8 ++-- .../values-large-land-v11/styles.xml | 2 +- .../base/resources/values-v16/styles.xml | 2 +- .../android/base/resources/values/styles.xml | 14 +++--- 7 files changed, 63 insertions(+), 60 deletions(-) diff --git a/mobile/android/base/home/PanelListRow.java b/mobile/android/base/home/PanelListRow.java index 0b14bf6fc85..6725e144b7b 100644 --- a/mobile/android/base/home/PanelListRow.java +++ b/mobile/android/base/home/PanelListRow.java @@ -41,11 +41,11 @@ public class PanelListRow extends TwoLineRow { int titleIndex = cursor.getColumnIndexOrThrow(HomeItems.TITLE); final String title = cursor.getString(titleIndex); - setPrimaryText(title); + setTitle(title); int urlIndex = cursor.getColumnIndexOrThrow(HomeItems.URL); final String url = cursor.getString(urlIndex); - setSecondaryText(url); + setDescription(url); int imageIndex = cursor.getColumnIndexOrThrow(HomeItems.IMAGE_URL); final String imageUrl = cursor.getString(imageIndex); diff --git a/mobile/android/base/home/TwoLinePageRow.java b/mobile/android/base/home/TwoLinePageRow.java index 9bfa0839023..7488018f1f4 100644 --- a/mobile/android/base/home/TwoLinePageRow.java +++ b/mobile/android/base/home/TwoLinePageRow.java @@ -21,12 +21,19 @@ import android.database.Cursor; import android.graphics.Bitmap; import android.text.TextUtils; import android.util.AttributeSet; +import android.widget.TextView; import java.lang.ref.WeakReference; public class TwoLinePageRow extends TwoLineRow implements Tabs.OnTabsChangedListener { + private static final int NO_ICON = 0; + + private final TextView mDescription; + private int mSwitchToTabIconId; + private int mPageTypeIconId; + private final FaviconView mFavicon; private boolean mShowIcons; @@ -72,6 +79,10 @@ public class TwoLinePageRow extends TwoLineRow mShowIcons = true; + mDescription = (TextView) findViewById(R.id.description); + mSwitchToTabIconId = NO_ICON; + mPageTypeIconId = NO_ICON; + mFavicon = (FaviconView) findViewById(R.id.icon); mFaviconListener = new UpdateViewFaviconLoadedListener(mFavicon); } @@ -104,6 +115,24 @@ public class TwoLinePageRow extends TwoLineRow } } + private void setSwitchToTabIcon(int iconId) { + if (mSwitchToTabIconId == iconId) { + return; + } + + mSwitchToTabIconId = iconId; + mDescription.setCompoundDrawablesWithIntrinsicBounds(mSwitchToTabIconId, 0, mPageTypeIconId, 0); + } + + private void setPageTypeIcon(int iconId) { + if (mPageTypeIconId == iconId) { + return; + } + + mPageTypeIconId = iconId; + mDescription.setCompoundDrawablesWithIntrinsicBounds(mSwitchToTabIconId, 0, mPageTypeIconId, 0); + } + /** * Stores the page URL, so that we can use it to replace "Switch to tab" if the open * tab changes or is closed. @@ -122,11 +151,11 @@ public class TwoLinePageRow extends TwoLineRow boolean isPrivate = Tabs.getInstance().getSelectedTab().isPrivate(); Tab tab = Tabs.getInstance().getFirstTabForUrl(mPageUrl, isPrivate); if (!mShowIcons || tab == null) { - setSecondaryText(mPageUrl); - setSecondaryIcon(NO_ICON); + setDescription(mPageUrl); + setSwitchToTabIcon(NO_ICON); } else { - setSecondaryText(R.string.switch_to_tab); - setSecondaryIcon(R.drawable.ic_url_bar_tab); + setDescription(R.string.switch_to_tab); + setSwitchToTabIcon(R.drawable.ic_url_bar_tab); } } @@ -162,20 +191,20 @@ public class TwoLinePageRow extends TwoLineRow // The bookmark id will be 0 (null in database) when the url // is not a bookmark. if (bookmarkId == 0) { - setPrimaryIcon(NO_ICON); + setPageTypeIcon(NO_ICON); } else if (display == Combined.DISPLAY_READER) { - setPrimaryIcon(R.drawable.ic_url_bar_reader); + setPageTypeIcon(R.drawable.ic_url_bar_reader); } else { - setPrimaryIcon(R.drawable.ic_url_bar_star); + setPageTypeIcon(R.drawable.ic_url_bar_star); } } else { - setPrimaryIcon(NO_ICON); + setPageTypeIcon(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 - setPrimaryText(TextUtils.isEmpty(title) ? url : title); + setTitle(TextUtils.isEmpty(title) ? url : title); // No point updating the below things if URL has not changed. Prevents evil Favicon flicker. if (url.equals(mPageUrl)) { diff --git a/mobile/android/base/home/TwoLineRow.java b/mobile/android/base/home/TwoLineRow.java index 85c579f4fa6..ddc62d9c27c 100644 --- a/mobile/android/base/home/TwoLineRow.java +++ b/mobile/android/base/home/TwoLineRow.java @@ -18,13 +18,8 @@ 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; + private final TextView mTitle; + private final TextView mDescription; public TwoLineRow(Context context) { this(context, null); @@ -35,42 +30,21 @@ public abstract class TwoLineRow extends LinearLayout { 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); + mTitle = (TextView) findViewById(R.id.title); + mDescription = (TextView) findViewById(R.id.description); } - protected void setPrimaryText(String text) { - mPrimaryText.setText(text); + protected void setTitle(String text) { + mTitle.setText(text); } - protected void setSecondaryText(String text) { - mSecondaryText.setText(text); + protected void setDescription(String text) { + mDescription.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); + protected void setDescription(int stringId) { + mDescription.setText(stringId); } public abstract void updateFromCursor(Cursor cursor); diff --git a/mobile/android/base/resources/layout/two_line_row.xml b/mobile/android/base/resources/layout/two_line_row.xml index 6571982c9f4..9cb136a1304 100644 --- a/mobile/android/base/resources/layout/two_line_row.xml +++ b/mobile/android/base/resources/layout/two_line_row.xml @@ -18,14 +18,14 @@ android:orientation="vertical"> - vertical - - diff --git a/mobile/android/base/resources/values/styles.xml b/mobile/android/base/resources/values/styles.xml index b6797ce74ba..31ebe20bb7e 100644 --- a/mobile/android/base/resources/values/styles.xml +++ b/mobile/android/base/resources/values/styles.xml @@ -111,20 +111,20 @@ - -