Bug 964508 - Rename TwoLineRow members and move icon code to TwoLinePageRow (r=margaret)

This commit is contained in:
Lucas Rocha 2014-02-07 13:29:40 +00:00
parent a171ee0bfa
commit 92b2c31da3
7 changed files with 63 additions and 60 deletions

View File

@ -41,11 +41,11 @@ public class PanelListRow extends TwoLineRow {
int titleIndex = cursor.getColumnIndexOrThrow(HomeItems.TITLE); int titleIndex = cursor.getColumnIndexOrThrow(HomeItems.TITLE);
final String title = cursor.getString(titleIndex); final String title = cursor.getString(titleIndex);
setPrimaryText(title); setTitle(title);
int urlIndex = cursor.getColumnIndexOrThrow(HomeItems.URL); int urlIndex = cursor.getColumnIndexOrThrow(HomeItems.URL);
final String url = cursor.getString(urlIndex); final String url = cursor.getString(urlIndex);
setSecondaryText(url); setDescription(url);
int imageIndex = cursor.getColumnIndexOrThrow(HomeItems.IMAGE_URL); int imageIndex = cursor.getColumnIndexOrThrow(HomeItems.IMAGE_URL);
final String imageUrl = cursor.getString(imageIndex); final String imageUrl = cursor.getString(imageIndex);

View File

@ -21,12 +21,19 @@ import android.database.Cursor;
import android.graphics.Bitmap; import android.graphics.Bitmap;
import android.text.TextUtils; import android.text.TextUtils;
import android.util.AttributeSet; import android.util.AttributeSet;
import android.widget.TextView;
import java.lang.ref.WeakReference; import java.lang.ref.WeakReference;
public class TwoLinePageRow extends TwoLineRow public class TwoLinePageRow extends TwoLineRow
implements Tabs.OnTabsChangedListener { 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 final FaviconView mFavicon;
private boolean mShowIcons; private boolean mShowIcons;
@ -72,6 +79,10 @@ public class TwoLinePageRow extends TwoLineRow
mShowIcons = true; mShowIcons = true;
mDescription = (TextView) findViewById(R.id.description);
mSwitchToTabIconId = NO_ICON;
mPageTypeIconId = NO_ICON;
mFavicon = (FaviconView) findViewById(R.id.icon); mFavicon = (FaviconView) findViewById(R.id.icon);
mFaviconListener = new UpdateViewFaviconLoadedListener(mFavicon); 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 * Stores the page URL, so that we can use it to replace "Switch to tab" if the open
* tab changes or is closed. * tab changes or is closed.
@ -122,11 +151,11 @@ public class TwoLinePageRow extends TwoLineRow
boolean isPrivate = Tabs.getInstance().getSelectedTab().isPrivate(); boolean isPrivate = Tabs.getInstance().getSelectedTab().isPrivate();
Tab tab = Tabs.getInstance().getFirstTabForUrl(mPageUrl, isPrivate); Tab tab = Tabs.getInstance().getFirstTabForUrl(mPageUrl, isPrivate);
if (!mShowIcons || tab == null) { if (!mShowIcons || tab == null) {
setSecondaryText(mPageUrl); setDescription(mPageUrl);
setSecondaryIcon(NO_ICON); setSwitchToTabIcon(NO_ICON);
} else { } else {
setSecondaryText(R.string.switch_to_tab); setDescription(R.string.switch_to_tab);
setSecondaryIcon(R.drawable.ic_url_bar_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 // The bookmark id will be 0 (null in database) when the url
// is not a bookmark. // is not a bookmark.
if (bookmarkId == 0) { if (bookmarkId == 0) {
setPrimaryIcon(NO_ICON); setPageTypeIcon(NO_ICON);
} else if (display == Combined.DISPLAY_READER) { } else if (display == Combined.DISPLAY_READER) {
setPrimaryIcon(R.drawable.ic_url_bar_reader); setPageTypeIcon(R.drawable.ic_url_bar_reader);
} else { } else {
setPrimaryIcon(R.drawable.ic_url_bar_star); setPageTypeIcon(R.drawable.ic_url_bar_star);
} }
} else { } else {
setPrimaryIcon(NO_ICON); setPageTypeIcon(NO_ICON);
} }
} }
// Use the URL instead of an empty title for consistency with the normal URL // 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 // 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. // No point updating the below things if URL has not changed. Prevents evil Favicon flicker.
if (url.equals(mPageUrl)) { if (url.equals(mPageUrl)) {

View File

@ -18,13 +18,8 @@ import android.widget.TextView;
import java.lang.ref.WeakReference; import java.lang.ref.WeakReference;
public abstract class TwoLineRow extends LinearLayout { public abstract class TwoLineRow extends LinearLayout {
protected static final int NO_ICON = 0; private final TextView mTitle;
private final TextView mDescription;
private final TextView mPrimaryText;
private int mPrimaryIconId;
private final TextView mSecondaryText;
private int mSecondaryIconId;
public TwoLineRow(Context context) { public TwoLineRow(Context context) {
this(context, null); this(context, null);
@ -35,42 +30,21 @@ public abstract class TwoLineRow extends LinearLayout {
setGravity(Gravity.CENTER_VERTICAL); setGravity(Gravity.CENTER_VERTICAL);
mSecondaryIconId = NO_ICON;
mPrimaryIconId = NO_ICON;
LayoutInflater.from(context).inflate(R.layout.two_line_row, this); LayoutInflater.from(context).inflate(R.layout.two_line_row, this);
mPrimaryText = (TextView) findViewById(R.id.primary_text); mTitle = (TextView) findViewById(R.id.title);
mSecondaryText = (TextView) findViewById(R.id.secondary_text); mDescription = (TextView) findViewById(R.id.description);
} }
protected void setPrimaryText(String text) { protected void setTitle(String text) {
mPrimaryText.setText(text); mTitle.setText(text);
} }
protected void setSecondaryText(String text) { protected void setDescription(String text) {
mSecondaryText.setText(text); mDescription.setText(text);
} }
protected void setSecondaryText(int stringId) { protected void setDescription(int stringId) {
mSecondaryText.setText(stringId); mDescription.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); public abstract void updateFromCursor(Cursor cursor);

View File

@ -18,14 +18,14 @@
android:orientation="vertical"> android:orientation="vertical">
<org.mozilla.gecko.home.FadedTextView <org.mozilla.gecko.home.FadedTextView
android:id="@+id/primary_text" android:id="@+id/title"
style="@style/Widget.TwoLineRow.PrimaryText" style="@style/Widget.TwoLineRow.Title"
android:layout_width="fill_parent" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
gecko:fadeWidth="30dp"/> gecko:fadeWidth="30dp"/>
<TextView android:id="@+id/secondary_text" <TextView android:id="@+id/description"
style="@style/Widget.TwoLineRow.SecondaryText" style="@style/Widget.TwoLineRow.Description"
android:layout_width="fill_parent" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:drawablePadding="5dp" android:drawablePadding="5dp"

View File

@ -9,7 +9,7 @@
<item name="android:orientation">vertical</item> <item name="android:orientation">vertical</item>
</style> </style>
<style name="Widget.BookmarkFolderView" parent="Widget.TwoLineRow.PrimaryText"> <style name="Widget.BookmarkFolderView" parent="Widget.TwoLineRow.Title">
<item name="android:paddingLeft">60dip</item> <item name="android:paddingLeft">60dip</item>
<item name="android:drawablePadding">10dip</item> <item name="android:drawablePadding">10dip</item>
<item name="android:drawableLeft">@drawable/bookmark_folder</item> <item name="android:drawableLeft">@drawable/bookmark_folder</item>

View File

@ -9,7 +9,7 @@
<item name="android:fontFamily">sans-serif-light</item> <item name="android:fontFamily">sans-serif-light</item>
</style> </style>
<style name="TextAppearance.Widget.TwoLineRow.PrimaryText" parent="TextAppearance.Medium"> <style name="TextAppearance.Widget.TwoLineRow.Title" parent="TextAppearance.Medium">
<item name="android:fontFamily">sans-serif-light</item> <item name="android:fontFamily">sans-serif-light</item>
</style> </style>

View File

@ -111,20 +111,20 @@
<style name="Widget.TwoLineRow" /> <style name="Widget.TwoLineRow" />
<style name="Widget.TwoLineRow.PrimaryText"> <style name="Widget.TwoLineRow.Title">
<item name="android:textAppearance">@style/TextAppearance.Widget.TwoLineRow.PrimaryText</item> <item name="android:textAppearance">@style/TextAppearance.Widget.TwoLineRow.Title</item>
<item name="android:singleLine">true</item> <item name="android:singleLine">true</item>
<item name="android:ellipsize">none</item> <item name="android:ellipsize">none</item>
</style> </style>
<style name="Widget.TwoLineRow.SecondaryText"> <style name="Widget.TwoLineRow.Description">
<item name="android:textAppearance">@style/TextAppearance.Widget.TwoLineRow.SecondaryText</item> <item name="android:textAppearance">@style/TextAppearance.Widget.TwoLineRow.Description</item>
<item name="android:includeFontPadding">false</item> <item name="android:includeFontPadding">false</item>
<item name="android:singleLine">true</item> <item name="android:singleLine">true</item>
<item name="android:ellipsize">middle</item> <item name="android:ellipsize">middle</item>
</style> </style>
<style name="Widget.BookmarkFolderView" parent="Widget.TwoLineRow.PrimaryText"> <style name="Widget.BookmarkFolderView" parent="Widget.TwoLineRow.Title">
<item name="android:paddingLeft">10dip</item> <item name="android:paddingLeft">10dip</item>
<item name="android:drawablePadding">10dip</item> <item name="android:drawablePadding">10dip</item>
<item name="android:drawableLeft">@drawable/bookmark_folder</item> <item name="android:drawableLeft">@drawable/bookmark_folder</item>
@ -344,9 +344,9 @@
<style name="TextAppearance.Widget.TwoLineRow" /> <style name="TextAppearance.Widget.TwoLineRow" />
<style name="TextAppearance.Widget.TwoLineRow.PrimaryText" parent="TextAppearance.Medium"/> <style name="TextAppearance.Widget.TwoLineRow.Title" parent="TextAppearance.Medium"/>
<style name="TextAppearance.Widget.TwoLineRow.SecondaryText" parent="TextAppearance.Micro"> <style name="TextAppearance.Widget.TwoLineRow.Description" parent="TextAppearance.Micro">
<item name="android:textColor">?android:attr/textColorSecondary</item> <item name="android:textColor">?android:attr/textColorSecondary</item>
</style> </style>