Bug 959777 - Create generic parent class TwoLineRow for TwoRowPageRow (r=margaret)

--HG--
rename : mobile/android/base/resources/layout/two_line_page_row.xml => mobile/android/base/resources/layout/two_line_row.xml
This commit is contained in:
Lucas Rocha 2014-01-27 13:29:54 -08:00
Родитель dd7690ccc3
Коммит b7c0353d45
7 изменённых файлов: 108 добавлений и 75 удалений

Просмотреть файл

@ -21,23 +21,14 @@ 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;
@ -79,16 +70,9 @@ public class TwoLinePageRow extends LinearLayout
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);
}
@ -120,36 +104,6 @@ public class TwoLinePageRow extends LinearLayout
}
}
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.
@ -168,11 +122,11 @@ public class TwoLinePageRow extends LinearLayout
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);
}
}
@ -180,6 +134,7 @@ public class TwoLinePageRow extends LinearLayout
mShowIcons = showIcons;
}
@Override
public void updateFromCursor(Cursor cursor) {
if (cursor == null) {
return;
@ -207,20 +162,20 @@ public class TwoLinePageRow extends LinearLayout
// 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)) {

Просмотреть файл

@ -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);
}

Просмотреть файл

@ -242,6 +242,7 @@ gbjar.sources += [
'home/TopSitesPanel.java',
'home/TopSitesThumbnailView.java',
'home/TwoLinePageRow.java',
'home/TwoLineRow.java',
'InputMethods.java',
'JavaAddonManager.java',
'LightweightTheme.java',

Просмотреть файл

@ -6,7 +6,7 @@
<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"
@ -18,14 +18,14 @@
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"

Просмотреть файл

@ -9,13 +9,13 @@
<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>

Просмотреть файл

@ -9,7 +9,7 @@
<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>

Просмотреть файл

@ -109,22 +109,22 @@
<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>
@ -143,7 +143,7 @@
<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"/>
@ -317,11 +317,11 @@
<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>