Backed out changeset f279d53c2d4d (bug 942231) for Android Bustage on a CLOSED TREE

This commit is contained in:
Carsten "Tomcat" Book 2013-12-12 12:44:48 +01:00
parent 17610f17b4
commit 3c90185a80
2 changed files with 37 additions and 37 deletions

View File

@ -21,22 +21,22 @@ import java.util.EnumMap;
class HomeAdapter extends FragmentStatePagerAdapter {
private final Context mContext;
private final ArrayList<PageInfo> mPageInfos;
private final ArrayList<TabInfo> mTabs;
private final EnumMap<Page, Fragment> mPages;
private OnAddPageListener mAddPageListener;
private OnAddTabListener mAddTabListener;
interface OnAddPageListener {
public void onAddPage(String title);
interface OnAddTabListener {
public void onAddTab(String title);
}
final class PageInfo {
final class TabInfo {
private final Page page;
private final Class<?> clss;
private final Bundle args;
private final String title;
PageInfo(Page page, Class<?> clss, Bundle args, String title) {
TabInfo(Page page, Class<?> clss, Bundle args, String title) {
this.page = page;
this.clss = clss;
this.args = args;
@ -49,31 +49,31 @@ class HomeAdapter extends FragmentStatePagerAdapter {
mContext = context;
mPageInfos = new ArrayList<PageInfo>();
mTabs = new ArrayList<TabInfo>();
mPages = new EnumMap<Page, Fragment>(Page.class);
}
@Override
public int getCount() {
return mPageInfos.size();
return mTabs.size();
}
@Override
public Fragment getItem(int position) {
PageInfo info = mPageInfos.get(position);
TabInfo info = mTabs.get(position);
return Fragment.instantiate(mContext, info.clss.getName(), info.args);
}
@Override
public CharSequence getPageTitle(int position) {
PageInfo info = mPageInfos.get(position);
TabInfo info = mTabs.get(position);
return info.title.toUpperCase();
}
@Override
public Object instantiateItem(ViewGroup container, int position) {
Fragment fragment = (Fragment) super.instantiateItem(container, position);
mPages.put(mPageInfos.get(position).page, fragment);
mPages.put(mTabs.get(position).page, fragment);
return fragment;
}
@ -81,36 +81,36 @@ class HomeAdapter extends FragmentStatePagerAdapter {
@Override
public void destroyItem(ViewGroup container, int position, Object object) {
super.destroyItem(container, position, object);
mPages.remove(mPageInfos.get(position).page);
mPages.remove(mTabs.get(position).page);
}
public void setOnAddPageListener(OnAddPageListener listener) {
mAddPageListener = listener;
public void setOnAddTabListener(OnAddTabListener listener) {
mAddTabListener = listener;
}
public void addPage(Page page, Class<?> clss, Bundle args, String title) {
addPage(-1, page, clss, args, title);
public void addTab(Page page, Class<?> clss, Bundle args, String title) {
addTab(-1, page, clss, args, title);
}
public void addPage(int index, Page page, Class<?> clss, Bundle args, String title) {
PageInfo info = new PageInfo(page, clss, args, title);
public void addTab(int index, Page page, Class<?> clss, Bundle args, String title) {
TabInfo info = new TabInfo(page, clss, args, title);
if (index >= 0) {
mPageInfos.add(index, info);
mTabs.add(index, info);
} else {
mPageInfos.add(info);
mTabs.add(info);
}
notifyDataSetChanged();
if (mAddPageListener != null) {
mAddPageListener.onAddPage(title);
if (mAddTabListener != null) {
mAddTabListener.onAddTab(title);
}
}
public int getItemPosition(Page page) {
for (int i = 0; i < mPageInfos.size(); i++) {
PageInfo info = mPageInfos.get(i);
for (int i = 0; i < mTabs.size(); i++) {
TabInfo info = mTabs.get(i);
if (info.page == page) {
return i;
}
@ -120,13 +120,13 @@ class HomeAdapter extends FragmentStatePagerAdapter {
}
public Page getPageAtPosition(int position) {
PageInfo info = mPageInfos.get(position);
TabInfo info = mTabs.get(position);
return info.page;
}
public void setCanLoadHint(boolean canLoadHint) {
// Update fragment arguments for future instances
for (PageInfo info : mPageInfos) {
for (TabInfo info : mTabs) {
info.args.putBoolean(HomePager.CAN_LOAD_ARG, canLoadHint);
}

View File

@ -8,7 +8,7 @@ package org.mozilla.gecko.home;
import org.mozilla.gecko.R;
import org.mozilla.gecko.animation.PropertyAnimator;
import org.mozilla.gecko.animation.ViewHelper;
import org.mozilla.gecko.home.HomeAdapter.OnAddPageListener;
import org.mozilla.gecko.home.HomeAdapter.OnAddTabListener;
import org.mozilla.gecko.mozglue.RobocopTarget;
import org.mozilla.gecko.util.HardwareUtils;
@ -32,7 +32,7 @@ public class HomePager extends ViewPager {
private volatile boolean mLoaded;
private Decor mDecor;
private final OnAddPageListener mAddPageListener;
private final OnAddTabListener mAddTabListener;
// List of pages in order.
@RobocopTarget
@ -90,9 +90,9 @@ public class HomePager extends ViewPager {
super(context, attrs);
mContext = context;
mAddPageListener = new OnAddPageListener() {
mAddTabListener = new OnAddTabListener() {
@Override
public void onAddPage(String title) {
public void onAddTab(String title) {
if (mDecor != null) {
mDecor.onAddPagerView(title);
}
@ -163,26 +163,26 @@ public class HomePager extends ViewPager {
}
final HomeAdapter adapter = new HomeAdapter(mContext, fm);
adapter.setOnAddPageListener(mAddPageListener);
adapter.setOnAddTabListener(mAddTabListener);
// Only animate on post-HC devices, when a non-null animator is given
final boolean shouldAnimate = (animator != null && Build.VERSION.SDK_INT >= 11);
adapter.addPage(Page.TOP_SITES, TopSitesPage.class, new Bundle(),
adapter.addTab(Page.TOP_SITES, TopSitesPage.class, new Bundle(),
getContext().getString(R.string.home_top_sites_title));
adapter.addPage(Page.BOOKMARKS, BookmarksPage.class, new Bundle(),
adapter.addTab(Page.BOOKMARKS, BookmarksPage.class, new Bundle(),
getContext().getString(R.string.bookmarks_title));
// We disable reader mode support on low memory devices. Hence the
// reading list page should not show up on such devices.
if (!HardwareUtils.isLowMemoryPlatform()) {
adapter.addPage(Page.READING_LIST, ReadingListPage.class, new Bundle(),
adapter.addTab(Page.READING_LIST, ReadingListPage.class, new Bundle(),
getContext().getString(R.string.reading_list_title));
}
// On phones, the history page is the first one. On tablets, the
// history page is the last.
adapter.addPage(HardwareUtils.isTablet() ? -1 : 0,
// On phones, the history tab is the first tab. On tablets, the
// history tab is the last tab.
adapter.addTab(HardwareUtils.isTablet() ? -1 : 0,
Page.HISTORY, HistoryPage.class, new Bundle(),
getContext().getString(R.string.home_history_title));