Bug 735741: Factor out UI in about:home [r=mfinkle]

--HG--
rename : mobile/android/base/resources/layout/abouthome_content.xml => mobile/android/base/resources/layout/abouthome_content.xml.in
This commit is contained in:
Sriram Ramasubramanian 2012-03-19 16:15:05 -07:00
Родитель 3f47c98434
Коммит b3d3200781
6 изменённых файлов: 229 добавлений и 160 удалений

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

@ -85,7 +85,6 @@ import android.widget.ArrayAdapter;
import android.widget.FrameLayout;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.ScrollView;
@ -124,9 +123,9 @@ public class AboutHomeContent extends ScrollView
protected SimpleCursorAdapter mTopSitesAdapter;
protected GridView mTopSitesGrid;
protected LinearLayout mAddonsLayout;
protected LinearLayout mLastTabsLayout;
protected LinearLayout mRemoteTabsLayout;
protected AboutHomeSection mAddons;
protected AboutHomeSection mLastTabs;
protected AboutHomeSection mRemoteTabs;
private View.OnClickListener mRemoteTabClickListener;
@ -180,9 +179,9 @@ public class AboutHomeContent extends ScrollView
}
});
mAddonsLayout = (LinearLayout) findViewById(R.id.recommended_addons);
mLastTabsLayout = (LinearLayout) findViewById(R.id.last_tabs);
mRemoteTabsLayout = (LinearLayout) findViewById(R.id.remote_tabs);
mAddons = (AboutHomeSection) findViewById(R.id.recommended_addons);
mLastTabs = (AboutHomeSection) findViewById(R.id.last_tabs);
mRemoteTabs = (AboutHomeSection) findViewById(R.id.remote_tabs);
TextView allTopSitesText = (TextView) findViewById(R.id.all_top_sites_text);
allTopSitesText.setOnClickListener(new View.OnClickListener() {
@ -191,16 +190,14 @@ public class AboutHomeContent extends ScrollView
}
});
TextView allAddonsText = (TextView) findViewById(R.id.all_addons_text);
allAddonsText.setOnClickListener(new View.OnClickListener() {
mAddons.setOnMoreTextClickListener(new View.OnClickListener() {
public void onClick(View v) {
if (mUriLoadCallback != null)
mUriLoadCallback.callback("https://addons.mozilla.org/android");
}
});
TextView allRemoteTabsText = (TextView) findViewById(R.id.all_remote_tabs_text);
allRemoteTabsText.setOnClickListener(new View.OnClickListener() {
mRemoteTabs.setOnMoreTextClickListener(new View.OnClickListener() {
public void onClick(View v) {
Context context = v.getContext();
context.startActivity(new Intent(context, RemoteTabs.class));
@ -256,17 +253,10 @@ public class AboutHomeContent extends ScrollView
}
void setLastTabsVisibility(boolean visible) {
int visibility = visible ? View.VISIBLE : View.GONE;
findViewById(R.id.last_tabs_title).setVisibility(visibility);
findViewById(R.id.last_tabs).setVisibility(visibility);
findViewById(R.id.last_tabs_open_all).setVisibility(visibility);
}
private void setAddonsVisibility(boolean visible) {
int visibility = visible ? View.VISIBLE : View.GONE;
findViewById(R.id.recommended_addons_title).setVisibility(visibility);
findViewById(R.id.recommended_addons).setVisibility(visibility);
findViewById(R.id.all_addons_text).setVisibility(visibility);
if (visible)
mLastTabs.show();
else
mLastTabs.hide();
}
private void setTopSitesVisibility(boolean visible, boolean hasTopSites) {
@ -280,14 +270,6 @@ public class AboutHomeContent extends ScrollView
findViewById(R.id.no_top_sites_text).setVisibility(visibilityWithoutTopSites);
}
private void setRemoteTabsVisibility(boolean visible) {
int visibility = visible ? View.VISIBLE : View.GONE;
findViewById(R.id.remote_tabs_title).setVisibility(visibility);
findViewById(R.id.remote_tabs_client).setVisibility(visibility);
findViewById(R.id.remote_tabs).setVisibility(visibility);
findViewById(R.id.all_remote_tabs_text).setVisibility(visibility);
}
private void setSyncVisibility(boolean visible) {
int visibility = visible ? View.VISIBLE : View.GONE;
findViewById(R.id.sync_box_container).setVisibility(visibility);
@ -518,14 +500,14 @@ public class AboutHomeContent extends ScrollView
public void run() {
try {
if (array == null || array.length() == 0) {
setAddonsVisibility(false);
mAddons.hide();
return;
}
for (int i = 0; i < array.length(); i++) {
JSONObject jsonobj = array.getJSONObject(i);
final View row = mInflater.inflate(R.layout.abouthome_addon_row, mAddonsLayout, false);
final View row = mInflater.inflate(R.layout.abouthome_addon_row, mAddons.getItemsContainer(), false);
((TextView) row.findViewById(R.id.addon_title)).setText(jsonobj.getString("name"));
((TextView) row.findViewById(R.id.addon_version)).setText(jsonobj.getString("version"));
@ -551,10 +533,10 @@ public class AboutHomeContent extends ScrollView
}
});
mAddonsLayout.addView(row);
mAddons.addItem(row);
}
setAddonsVisibility(true);
mAddons.show();
} catch (JSONException e) {
Log.i(LOGTAG, "error reading json file", e);
}
@ -611,7 +593,7 @@ public class AboutHomeContent extends ScrollView
GeckoApp.mAppContext.mMainHandler.post(new Runnable() {
public void run() {
View container = mInflater.inflate(R.layout.abouthome_last_tabs_row, mLastTabsLayout, false);
View container = mInflater.inflate(R.layout.abouthome_last_tabs_row, mLastTabs.getItemsContainer(), false);
((TextView) container.findViewById(R.id.last_tab_title)).setText(title);
((TextView) container.findViewById(R.id.last_tab_url)).setText(url);
if (favicon != null)
@ -623,39 +605,38 @@ public class AboutHomeContent extends ScrollView
}
});
mLastTabsLayout.addView(container);
mLastTabs.addItem(container);
}
});
}
int numLastTabs = lastTabUrlsList.size();
if (numLastTabs > 0) {
GeckoApp.mAppContext.mMainHandler.post(new Runnable() {
public void run() {
findViewById(R.id.last_tabs_title).setVisibility(View.VISIBLE);
final int numLastTabs = lastTabUrlsList.size();
GeckoApp.mAppContext.mMainHandler.post(new Runnable() {
public void run() {
if (numLastTabs > 1) {
mLastTabs.showMoreText();
mLastTabs.setOnMoreTextClickListener(new View.OnClickListener() {
public void onClick(View v) {
for (String url : lastTabUrlsList)
GeckoApp.mAppContext.loadUrlInTab(url);
}
});
mLastTabs.show();
} else if (numLastTabs == 1) {
mLastTabs.hideMoreText();
mLastTabs.show();
}
});
if (numLastTabs > 1) {
GeckoApp.mAppContext.mMainHandler.post(new Runnable() {
public void run() {
LinkTextView openAll = (LinkTextView) findViewById(R.id.last_tabs_open_all);
openAll.setVisibility(View.VISIBLE);
openAll.setOnClickListener(new LinkTextView.OnClickListener() {
public void onClick(View v) {
for (String url : lastTabUrlsList)
GeckoApp.mAppContext.loadUrlInTab(url);
}
});
}
});
}
}
});
}
private void loadRemoteTabs(final Activity activity) {
if (!isSyncSetup()) {
setRemoteTabsVisibility(false);
GeckoApp.mAppContext.mMainHandler.post(new Runnable() {
public void run() {
mRemoteTabs.hide();
}
});
return;
}
@ -666,11 +647,11 @@ public class AboutHomeContent extends ScrollView
public void onQueryTabsComplete(List<TabsAccessor.RemoteTab> tabsList) {
ArrayList<TabsAccessor.RemoteTab> tabs = new ArrayList<TabsAccessor.RemoteTab> (tabsList);
if (tabs == null || tabs.size() == 0) {
setRemoteTabsVisibility(false);
mRemoteTabs.hide();
return;
}
mRemoteTabsLayout.removeAllViews();
mRemoteTabs.clear();
String client = null;
@ -680,15 +661,15 @@ public class AboutHomeContent extends ScrollView
else if (!TextUtils.equals(client, tab.name))
break;
final TextView row = (TextView) mInflater.inflate(R.layout.abouthome_remote_tab_row, mRemoteTabsLayout, false);
final TextView row = (TextView) mInflater.inflate(R.layout.abouthome_remote_tab_row, mRemoteTabs.getItemsContainer(), false);
row.setText(TextUtils.isEmpty(tab.title) ? tab.url : tab.title);
row.setTag(tab.url);
mRemoteTabsLayout.addView(row);
mRemoteTabs.addItem(row);
row.setOnClickListener(mRemoteTabClickListener);
}
((TextView) findViewById(R.id.remote_tabs_client)).setText(client);
setRemoteTabsVisibility(true);
mRemoteTabs.setSubtitle(client);
mRemoteTabs.show();
}
public static class TopSitesGridView extends GridView {

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

@ -0,0 +1,103 @@
/* 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;
import android.content.Context;
import android.content.res.TypedArray;
import android.util.AttributeSet;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.LinearLayout.LayoutParams;
import android.widget.TextView;
import android.text.TextUtils;
public class AboutHomeSection extends LinearLayout {
private static final String LOGTAG = "GeckoAboutHomeSection";
private TextView mTitle;
private TextView mSubtitle;
private LinearLayout mItemsContainer;
private LinkTextView mMoreText;
public AboutHomeSection(Context context, AttributeSet attrs) {
super(context, attrs);
setOrientation(VERTICAL);
LayoutInflater.from(context).inflate(R.layout.abouthome_section, this);
mTitle = (TextView) this.findViewById(R.id.title);
mSubtitle = (TextView) this.findViewById(R.id.subtitle);
mItemsContainer = (LinearLayout) this.findViewById(R.id.items_container);
mMoreText = (LinkTextView) this.findViewById(R.id.more_text);
TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.AboutHomeSection);
setTitle(a.getText(R.styleable.AboutHomeSection_title));
setSubtitle(a.getText(R.styleable.AboutHomeSection_subtitle));
setMoreText(a.getText(R.styleable.AboutHomeSection_more_text));
a.recycle();
}
public LinearLayout getItemsContainer() {
return mItemsContainer;
}
public void setTitle(CharSequence title) {
if (!TextUtils.isEmpty(title)) {
mTitle.setText(title);
mTitle.setVisibility(View.VISIBLE);
} else {
mTitle.setVisibility(View.GONE);
}
}
public void setSubtitle(CharSequence subtitle) {
if (!TextUtils.isEmpty(subtitle)) {
mSubtitle.setText(subtitle);
mSubtitle.setVisibility(View.VISIBLE);
} else {
mSubtitle.setVisibility(View.GONE);
}
}
public void setMoreText(CharSequence moreText) {
if (!TextUtils.isEmpty(moreText)) {
mMoreText.setText(moreText);
mMoreText.setVisibility(View.VISIBLE);
} else {
mMoreText.setVisibility(View.GONE);
}
}
public void setOnMoreTextClickListener(View.OnClickListener listener) {
mMoreText.setOnClickListener(listener);
}
public void addItem(View item) {
mItemsContainer.addView(item);
}
public void clear() {
mItemsContainer.removeAllViews();
}
public void show() {
setVisibility(View.VISIBLE);
}
public void hide() {
setVisibility(View.GONE);
}
public void showMoreText() {
mMoreText.setVisibility(View.VISIBLE);
}
public void hideMoreText() {
mMoreText.setVisibility(View.GONE);
}
}

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

@ -62,6 +62,7 @@ SYNC_PP_RES_XML=res/xml/sync_syncadapter.xml res/xml/sync_options.xml
FENNEC_JAVA_FILES = \
AboutHomeContent.java \
AboutHomeSection.java \
AlertNotification.java \
AwesomeBar.java \
AwesomeBarTabs.java \
@ -169,6 +170,10 @@ FENNEC_PP_JAVA_FILES = \
SmsManager.java \
$(NULL)
FENNEC_PP_XML_FILES = \
res/layout/abouthome_content.xml \
$(NULL)
ifneq (,$(findstring -march=armv7,$(OS_CFLAGS)))
MIN_CPU_VERSION=7
@ -203,6 +208,7 @@ GARBAGE += \
gecko.ap_ \
res/values/strings.xml \
R.java \
$(FENNEC_PP_XML_FILES) \
$(SYNC_PP_RES_XML) \
package-name.txt \
Manifest.java \
@ -263,11 +269,11 @@ RES_LAYOUT = \
res/layout/tabs_tray.xml \
res/layout/list_item_header.xml \
res/layout/select_dialog_list.xml \
res/layout/abouthome_content.xml \
res/layout/abouthome_topsite_item.xml \
res/layout/abouthome_addon_row.xml \
res/layout/abouthome_last_tabs_row.xml \
res/layout/abouthome_section.xml \
res/layout/abouthome_remote_tab_row.xml \
res/layout/abouthome_topsite_item.xml \
$(NULL)
RES_LAYOUT_V11 = \
@ -280,6 +286,7 @@ RES_LAYOUT_LAND_V14 = \
RES_VALUES = \
$(SYNC_RES_VALUES) \
res/values/attrs.xml \
res/values/arrays.xml \
res/values/colors.xml \
res/values/styles.xml \
@ -624,7 +631,10 @@ classes.dex: $(FENNEC_JAVA_FILES) $(FENNEC_PP_JAVA_FILES) $(SYNC_JAVA_FILES) $(S
$(JAVAC) $(JAVAC_FLAGS) -Xlint:all,-deprecation,-fallthrough -d classes -classpath classes $(addprefix $(srcdir)/,$(FENNEC_JAVA_FILES)) $(FENNEC_PP_JAVA_FILES) $(addprefix $(srcdir)/,$(SYNC_JAVA_FILES)) $(SYNC_PP_JAVA_FILES) R.java
$(DX) --dex --output=$@ classes
PP_RES_XML=$(SYNC_PP_RES_XML)
PP_RES_XML= \
$(SYNC_PP_RES_XML) \
$(FENNEC_PP_XML_FILES) \
$(NULL)
# This is kinda awful; if any of the source files change, we remake them all.
$(PP_RES_XML): $(patsubst res/%,$(srcdir)/resources/%.in,$(PP_RES_XML))

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

@ -1,5 +1,7 @@
#filter substitution
<?xml version="1.0" encoding="utf-8"?>
<merge xmlns:android="http://schemas.android.com/apk/res/android">
<merge xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:gecko="http://schemas.android.com/apk/res/@ANDROID_PACKAGE_NAME@">
<LinearLayout android:layout_width="fill_parent"
android:orientation="vertical"
@ -121,100 +123,26 @@
</RelativeLayout>
<TextView android:id="@+id/last_tabs_title"
android:layout_width="fill_parent"
android:layout_height="26dip"
android:paddingLeft="12dip"
android:background="@drawable/abouthome_separator"
android:textSize="12sp"
android:textColor="#000000"
android:textStyle="bold"
android:gravity="left|center_vertical"
android:visibility="gone"
android:text="@string/abouthome_last_tabs_title"/>
<org.mozilla.gecko.AboutHomeSection android:id="@+id/last_tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:visibility="gone"
gecko:title="@string/abouthome_last_tabs_title"
gecko:more_text="@string/abouthome_last_tabs_open"/>
<LinearLayout android:id="@+id/last_tabs"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
<org.mozilla.gecko.AboutHomeSection android:id="@+id/recommended_addons"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:visibility="gone"
gecko:title="@string/abouthome_addons_title"
gecko:more_text="@string/abouthome_addons_browse"/>
<org.mozilla.gecko.LinkTextView android:id="@+id/last_tabs_open_all"
android:layout_width="fill_parent"
android:layout_height="47dip"
android:background="@drawable/abouthome_separator"
android:textColor="#22629e"
android:textSize="12sp"
android:gravity="center"
android:visibility="gone"
android:text="@string/abouthome_last_tabs_open"/>
<TextView android:id="@+id/recommended_addons_title"
android:layout_width="fill_parent"
android:layout_height="26dip"
android:paddingLeft="12dip"
android:background="@drawable/abouthome_separator"
android:textSize="12sp"
android:textColor="#000000"
android:textStyle="bold"
android:gravity="left|center_vertical"
android:visibility="gone"
android:text="@string/abouthome_addons_title"/>
<LinearLayout android:id="@+id/recommended_addons"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:visibility="gone"
android:isScrollContainer="false"/>
<org.mozilla.gecko.LinkTextView android:id="@+id/all_addons_text"
android:layout_width="fill_parent"
android:layout_height="47dip"
android:background="@drawable/abouthome_separator"
android:textColor="#22629e"
android:textSize="12sp"
android:gravity="center"
android:visibility="gone"
android:text="@string/abouthome_addons_browse"/>
<TextView android:id="@+id/remote_tabs_title"
android:layout_width="fill_parent"
android:layout_height="26dip"
android:paddingLeft="12dip"
android:background="@drawable/abouthome_separator"
android:textSize="12sp"
android:textColor="#000000"
android:textStyle="bold"
android:gravity="left|center_vertical"
android:visibility="gone"
android:text="@string/remote_tabs"/>
<TextView android:id="@+id/remote_tabs_client"
android:layout_width="fill_parent"
android:layout_height="26dip"
android:paddingLeft="12dip"
android:background="@drawable/abouthome_separator"
android:textSize="12sp"
android:textColor="#666666"
android:gravity="left|center_vertical"
android:visibility="gone"/>
<LinearLayout android:id="@+id/remote_tabs"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:visibility="gone"
android:isScrollContainer="false"/>
<org.mozilla.gecko.LinkTextView android:id="@+id/all_remote_tabs_text"
android:layout_width="fill_parent"
android:layout_height="47dip"
android:background="@drawable/abouthome_separator"
android:textColor="#22629e"
android:textSize="12sp"
android:gravity="center"
android:visibility="gone"
android:text="@string/remote_tabs_show_all"/>
<org.mozilla.gecko.AboutHomeSection android:id="@+id/remote_tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:visibility="gone"
gecko:title="@string/remote_tabs"
gecko:more_text="@string/remote_tabs_show_all"/>
</LinearLayout>

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

@ -0,0 +1,37 @@
<?xml version="1.0" encoding="utf-8"?>
<merge xmlns:android="http://schemas.android.com/apk/res/android">
<TextView android:id="@+id/title"
android:layout_width="fill_parent"
android:layout_height="26dip"
android:paddingLeft="12dip"
android:background="@drawable/abouthome_separator"
android:textSize="12sp"
android:textColor="#000000"
android:textStyle="bold"
android:gravity="left|center_vertical"/>
<TextView android:id="@+id/subtitle"
android:layout_width="fill_parent"
android:layout_height="26dip"
android:paddingLeft="12dip"
android:background="@drawable/abouthome_separator"
android:textSize="12sp"
android:textColor="#666666"
android:gravity="left|center_vertical"/>
<LinearLayout android:id="@+id/items_container"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:isScrollContainer="false"/>
<org.mozilla.gecko.LinkTextView android:id="@+id/more_text"
android:layout_width="fill_parent"
android:layout_height="47dip"
android:background="@drawable/abouthome_separator"
android:textColor="#22629e"
android:textSize="12sp"
android:gravity="center"/>
</merge>

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

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<declare-styleable name="AboutHomeSection">
<attr name="title" format="string"/>
<attr name="subtitle" format="string"/>
<attr name="more_text" format="string"/>
</declare-styleable>
</resources>