Bug 1193745 - Implement the tablet tabs tray grid view on mobile r=mcomella

--HG--
extra : commitid : 54i2vPlOpHz
This commit is contained in:
Martyn Haigh 2015-08-27 13:09:28 +01:00
Родитель b722efa658
Коммит 6d01612636
13 изменённых файлов: 59 добавлений и 92 удалений

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

@ -446,8 +446,6 @@ public class BrowserApp extends GeckoApp
final View view;
if (BrowserToolbar.class.getName().equals(name)) {
view = BrowserToolbar.create(context, attrs);
} else if (TabsPanel.TabsLayout.class.getName().equals(name)) {
view = TabsPanel.createTabsLayout(context, attrs);
} else {
view = super.onCreateView(name, context, attrs);
}

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

@ -468,7 +468,6 @@ gbjar.sources += [
'tabs/TabsGridLayout.java',
'tabs/TabsLayoutAdapter.java',
'tabs/TabsLayoutItemView.java',
'tabs/TabsListLayout.java',
'tabs/TabsPanel.java',
'tabs/TabsPanelThumbnailView.java',
'Telemetry.java',

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

@ -14,7 +14,7 @@
<!-- Note: for an unknown reason, scrolling in the TabsLayout
does not work unless it is laid out after the empty view. -->
<view class="org.mozilla.gecko.tabs.TabsPanel$TabsLayout"
<org.mozilla.gecko.tabs.TabsGridLayout
android:id="@+id/private_tabs_layout"
style="@style/TabsLayout"
android:layout_width="match_parent"

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

@ -16,9 +16,9 @@
android:layout_height="wrap_content"
android:orientation="horizontal"
android:duplicateParentState="true"
android:paddingLeft="@dimen/tablet_tab_highlight_stroke_width"
android:paddingRight="@dimen/tablet_tab_highlight_stroke_width"
android:paddingBottom="@dimen/tablet_tab_highlight_stroke_width">
android:paddingLeft="@dimen/tab_highlight_stroke_width"
android:paddingRight="@dimen/tab_highlight_stroke_width"
android:paddingBottom="@dimen/tab_highlight_stroke_width">
<org.mozilla.gecko.widget.FadedSingleColorTextView
android:id="@+id/title"
@ -62,13 +62,13 @@
android:id="@+id/wrapper"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="@dimen/tablet_tab_highlight_stroke_width"
android:padding="@dimen/tab_highlight_stroke_width"
android:background="@drawable/tab_thumbnail"
android:duplicateParentState="true">
<org.mozilla.gecko.tabs.TabsPanelThumbnailView android:id="@+id/thumbnail"
android:layout_width="@dimen/tablet_tab_thumbnail_width"
android:layout_height="@dimen/tablet_tab_thumbnail_height"
android:layout_width="@dimen/tab_thumbnail_width"
android:layout_height="@dimen/tab_thumbnail_height"
/>
</org.mozilla.gecko.widget.TabThumbnailWrapper>

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

@ -66,7 +66,7 @@
android:layout_width="match_parent"
android:layout_height="match_parent">
<view class="org.mozilla.gecko.tabs.TabsPanel$TabsLayout"
<org.mozilla.gecko.tabs.TabsGridLayout
android:id="@+id/normal_tabs"
style="@style/TabsLayout"
android:layout_width="match_parent"

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

@ -9,5 +9,5 @@
<dimen name="home_remote_tabs_top_padding">16dp</dimen>
<dimen name="page_group_height">64dp</dimen>
<dimen name="tablet_tab_panel_grid_padding">48dp</dimen>
<dimen name="tab_panel_grid_padding">48dp</dimen>
</resources>

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

@ -5,6 +5,6 @@
<resources>
<dimen name="tablet_tab_panel_grid_padding">64dp</dimen>
<dimen name="tab_panel_grid_padding">64dp</dimen>
</resources>

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

@ -6,6 +6,6 @@
<resources>
<dimen name="panel_grid_view_column_width">250dp</dimen>
<dimen name="tablet_tab_panel_grid_padding">48dp</dimen>
<dimen name="tab_panel_grid_padding">48dp</dimen>
</resources>

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

@ -130,8 +130,6 @@
<dimen name="prompt_service_inputs_padding">16dp</dimen>
<dimen name="prompt_service_left_right_text_with_icon_padding">10dp</dimen>
<dimen name="prompt_service_top_bottom_text_with_icon_padding">8dp</dimen>
<dimen name="tab_thumbnail_height">90dp</dimen>
<dimen name="tab_thumbnail_width">160dp</dimen>
<dimen name="tabs_panel_indicator_width">60dp</dimen>
<dimen name="tabs_panel_button_width">48dp</dimen>
<dimen name="tabs_strip_height">48dp</dimen>
@ -145,14 +143,14 @@
<dimen name="validation_message_height">50dp</dimen>
<dimen name="validation_message_margin_top">6dp</dimen>
<dimen name="tablet_tab_thumbnail_width">168dp</dimen>
<dimen name="tablet_tab_thumbnail_height">140dp</dimen>
<dimen name="tablet_tab_panel_column_width">178dp</dimen>
<dimen name="tablet_tab_panel_grid_padding">19dp</dimen>
<dimen name="tablet_tab_panel_grid_vspacing">21dp</dimen>
<dimen name="tablet_tab_panel_grid_padding_top">24dp</dimen>
<dimen name="tab_thumbnail_width">121dp</dimen>
<dimen name="tab_thumbnail_height">90dp</dimen>
<dimen name="tab_panel_column_width">129dp</dimen>
<dimen name="tab_panel_grid_padding">20dp</dimen>
<dimen name="tab_panel_grid_vspacing">20dp</dimen>
<dimen name="tab_panel_grid_padding_top">19dp</dimen>
<dimen name="tablet_tab_highlight_stroke_width">5dp</dimen>
<dimen name="tab_highlight_stroke_width">4dp</dimen>
<!-- PageActionButtons dimensions -->
<dimen name="page_action_button_width">32dp</dimen>

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

@ -208,9 +208,9 @@
<item name="android:scrollbarStyle">outsideOverlay</item>
<item name="android:gravity">center</item>
<item name="android:numColumns">auto_fit</item>
<item name="android:columnWidth">@dimen/tablet_tab_panel_column_width</item>
<item name="android:columnWidth">@dimen/tab_panel_column_width</item>
<item name="android:horizontalSpacing">2dp</item>
<item name="android:verticalSpacing">@dimen/tablet_tab_panel_grid_vspacing</item>
<item name="android:verticalSpacing">@dimen/tab_panel_grid_vspacing</item>
<item name="android:drawSelectorOnTop">true</item>
<item name="android:clipToPadding">false</item>
</style>

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

@ -13,9 +13,7 @@ import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.LinearLayout;
/**
* A container that wraps the private tabs {@link android.widget.AdapterView} and empty
@ -26,7 +24,7 @@ import android.widget.LinearLayout;
class PrivateTabsPanel extends FrameLayout implements CloseAllPanelView {
private final TabsLayout tabsLayout;
public PrivateTabsPanel(Context context, AttributeSet attrs) {
public PrivateTabsPanel(final Context context, final AttributeSet attrs) {
super(context, attrs);
LayoutInflater.from(context).inflate(R.layout.private_tabs_panel, this);
@ -37,7 +35,7 @@ class PrivateTabsPanel extends FrameLayout implements CloseAllPanelView {
}
@Override
public void setTabsPanel(TabsPanel panel) {
public void setTabsPanel(final TabsPanel panel) {
tabsLayout.setTabsPanel(panel);
}
@ -53,11 +51,6 @@ class PrivateTabsPanel extends FrameLayout implements CloseAllPanelView {
tabsLayout.hide();
}
@Override
public boolean shouldExpand() {
return tabsLayout.shouldExpand();
}
@Override
public void closeAll() {
tabsLayout.closeAll();

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

@ -43,8 +43,7 @@ import java.util.ArrayList;
import java.util.List;
/**
* A tabs layout implementation for the tablet redesign (bug 1014156).
* Expected to replace TabsListLayout once complete.
* A tabs layout implementation for the tablet redesign (bug 1014156) and later ported to mobile (bug 1193745).
*/
class TabsGridLayout extends GridView
@ -56,24 +55,22 @@ class TabsGridLayout extends GridView
private static final int ANIM_TIME_MS = 200;
private static final DecelerateInterpolator ANIM_INTERPOLATOR = new DecelerateInterpolator();
private final Context mContext;
private final SparseArray<PointF> mTabLocations = new SparseArray<PointF>();
private final boolean mIsPrivate;
private final TabsLayoutAdapter mTabsAdapter;
private final int mColumnWidth;
private TabsPanel mTabsPanel;
private final SparseArray<PointF> tabLocations = new SparseArray<PointF>();
private final boolean isPrivate;
private final TabsLayoutAdapter tabsAdapter;
private final int columnWidth;
private TabsPanel tabsPanel;
private int lastSelectedTabId;
public TabsGridLayout(Context context, AttributeSet attrs) {
public TabsGridLayout(final Context context, final AttributeSet attrs) {
super(context, attrs, R.attr.tabGridLayoutViewStyle);
mContext = context;
TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.TabsLayout);
mIsPrivate = (a.getInt(R.styleable.TabsLayout_tabs, 0x0) == 1);
isPrivate = (a.getInt(R.styleable.TabsLayout_tabs, 0x0) == 1);
a.recycle();
mTabsAdapter = new TabsGridLayoutAdapter(mContext);
setAdapter(mTabsAdapter);
tabsAdapter = new TabsGridLayoutAdapter(context);
setAdapter(tabsAdapter);
setRecyclerListener(new RecyclerListener() {
@Override
@ -88,10 +85,10 @@ class TabsGridLayout extends GridView
setClipToPadding(false);
final Resources resources = getResources();
mColumnWidth = resources.getDimensionPixelSize(R.dimen.tablet_tab_panel_column_width);
columnWidth = resources.getDimensionPixelSize(R.dimen.tab_panel_column_width);
final int padding = resources.getDimensionPixelSize(R.dimen.tablet_tab_panel_grid_padding);
final int paddingTop = resources.getDimensionPixelSize(R.dimen.tablet_tab_panel_grid_padding_top);
final int padding = resources.getDimensionPixelSize(R.dimen.tab_panel_grid_padding);
final int paddingTop = resources.getDimensionPixelSize(R.dimen.tab_panel_grid_padding_top);
// Lets set double the top padding on the bottom so that the last row shows up properly!
// Your demise, GridView, cannot come fast enough.
@ -114,13 +111,13 @@ class TabsGridLayout extends GridView
}
private void populateTabLocations(final Tab removedTab) {
mTabLocations.clear();
tabLocations.clear();
final int firstPosition = getFirstVisiblePosition();
final int lastPosition = getLastVisiblePosition();
final int numberOfColumns = getNumColumns();
final int childCount = getChildCount();
final int removedPosition = mTabsAdapter.getPositionForTab(removedTab);
final int removedPosition = tabsAdapter.getPositionForTab(removedTab);
for (int x = 1, i = (removedPosition - firstPosition) + 1; i < childCount; i++, x++) {
final View child = getChildAt(i);
@ -128,7 +125,7 @@ class TabsGridLayout extends GridView
// Reset the transformations here in case the user is swiping tabs away fast and they swipe a tab
// before the last animation has finished (bug 1179195).
resetTransforms(child);
mTabLocations.append(x, new PointF(child.getX(), child.getY()));
tabLocations.append(x, new PointF(child.getX(), child.getY()));
}
}
@ -142,7 +139,7 @@ class TabsGridLayout extends GridView
final int removedHeight = getChildAt(0).getMeasuredHeight();
final int verticalSpacing =
getResources().getDimensionPixelOffset(R.dimen.tablet_tab_panel_grid_vspacing);
getResources().getDimensionPixelOffset(R.dimen.tab_panel_grid_vspacing);
ValueAnimator paddingAnimator = ValueAnimator.ofInt(getPaddingBottom() + removedHeight + verticalSpacing, getPaddingBottom());
paddingAnimator.setDuration(ANIM_TIME_MS * 2);
@ -160,7 +157,7 @@ class TabsGridLayout extends GridView
@Override
public void setTabsPanel(TabsPanel panel) {
mTabsPanel = panel;
tabsPanel = panel;
}
@Override
@ -172,7 +169,7 @@ class TabsGridLayout extends GridView
Tab currentlySelectedTab = Tabs.getInstance().getSelectedTab();
if (lastSelectedTabId != currentlySelectedTab.getId()) {
smoothScrollToPosition(mTabsAdapter.getPositionForTab(currentlySelectedTab));
smoothScrollToPosition(tabsAdapter.getPositionForTab(currentlySelectedTab));
}
}
@ -182,16 +179,11 @@ class TabsGridLayout extends GridView
setVisibility(View.GONE);
Tabs.unregisterOnTabsChangedListener(this);
GeckoAppShell.sendEventToGecko(GeckoEvent.createBroadcastEvent("Tab:Screenshot:Cancel", ""));
mTabsAdapter.clear();
}
@Override
public boolean shouldExpand() {
return true;
tabsAdapter.clear();
}
private void autoHidePanel() {
mTabsPanel.autoHidePanel();
tabsPanel.autoHidePanel();
}
@Override
@ -203,15 +195,15 @@ class TabsGridLayout extends GridView
break;
case CLOSED:
if (mTabsAdapter.getCount() > 0) {
if (tabsAdapter.getCount() > 0) {
animateRemoveTab(tab);
}
final Tabs tabsInstance = Tabs.getInstance();
if (mTabsAdapter.removeTab(tab)) {
if (tab.isPrivate() == mIsPrivate && mTabsAdapter.getCount() > 0) {
int selected = mTabsAdapter.getPositionForTab(tabsInstance.getSelectedTab());
if (tabsAdapter.removeTab(tab)) {
if (tab.isPrivate() == isPrivate && tabsAdapter.getCount() > 0) {
int selected = tabsAdapter.getPositionForTab(tabsInstance.getSelectedTab());
updateSelectedStyle(selected);
}
if (!tab.isPrivate()) {
@ -240,7 +232,7 @@ class TabsGridLayout extends GridView
case TITLE:
case RECORDING_CHANGE:
case AUDIO_PLAYING_CHANGE:
View view = getChildAt(mTabsAdapter.getPositionForTab(tab) - getFirstVisiblePosition());
View view = getChildAt(tabsAdapter.getPositionForTab(tab) - getFirstVisiblePosition());
if (view == null)
return;
@ -251,7 +243,7 @@ class TabsGridLayout extends GridView
// Updates the selected position in the list so that it will be scrolled to the right place.
private void updateSelectedPosition() {
int selected = mTabsAdapter.getPositionForTab(Tabs.getInstance().getSelectedTab());
int selected = tabsAdapter.getPositionForTab(Tabs.getInstance().getSelectedTab());
updateSelectedStyle(selected);
if (selected != -1) {
@ -265,7 +257,7 @@ class TabsGridLayout extends GridView
* @param selected position of the selected tab
*/
private void updateSelectedStyle(int selected) {
for (int i = 0; i < mTabsAdapter.getCount(); i++) {
for (int i = 0; i < tabsAdapter.getCount(); i++) {
setItemChecked(i, (i == selected));
}
}
@ -277,11 +269,11 @@ class TabsGridLayout extends GridView
Iterable<Tab> allTabs = Tabs.getInstance().getTabsInOrder();
for (Tab tab : allTabs) {
if (tab.isPrivate() == mIsPrivate)
if (tab.isPrivate() == isPrivate)
tabData.add(tab);
}
mTabsAdapter.setTabs(tabData);
tabsAdapter.setTabs(tabData);
updateSelectedPosition();
}
@ -306,14 +298,14 @@ class TabsGridLayout extends GridView
for (Tab tab : tabs) {
// In the normal panel we want to close all tabs (both private and normal),
// but in the private panel we only want to close private tabs.
if (!mIsPrivate || tab.isPrivate()) {
if (!isPrivate || tab.isPrivate()) {
Tabs.getInstance().closeTab(tab, false);
}
}
}
private View getViewForTab(Tab tab) {
final int position = mTabsAdapter.getPositionForTab(tab);
final int position = tabsAdapter.getPositionForTab(tab);
return getChildAt(position - getFirstVisiblePosition());
}
@ -325,7 +317,7 @@ class TabsGridLayout extends GridView
}
private void animateRemoveTab(final Tab removedTab) {
final int removedPosition = mTabsAdapter.getPositionForTab(removedTab);
final int removedPosition = tabsAdapter.getPositionForTab(removedTab);
final View removedView = getViewForTab(removedTab);
@ -358,12 +350,12 @@ class TabsGridLayout extends GridView
if (i % numberOfColumns == numberOfColumns - 1) {
// Animate X & Y
translateX = PropertyValuesHolder.ofFloat("translationX", -(mColumnWidth * numberOfColumns), 0);
translateX = PropertyValuesHolder.ofFloat("translationX", -(columnWidth * numberOfColumns), 0);
translateY = PropertyValuesHolder.ofFloat("translationY", removedHeight, 0);
animator = ObjectAnimator.ofPropertyValuesHolder(child, translateX, translateY);
} else {
// Just animate X
translateX = PropertyValuesHolder.ofFloat("translationX", mColumnWidth, 0);
translateX = PropertyValuesHolder.ofFloat("translationX", columnWidth, 0);
animator = ObjectAnimator.ofPropertyValuesHolder(child, translateX);
}
animator.setStartDelay(x * ANIM_DELAY_MULTIPLE_MS);
@ -382,7 +374,7 @@ class TabsGridLayout extends GridView
for (int x = 1, i = (removedPosition - firstPosition) + 1; i < childCount; i++, x++) {
final View child = getChildAt(i);
final PointF targetLocation = mTabLocations.get(x + 1);
final PointF targetLocation = tabLocations.get(x + 1);
if (targetLocation == null) {
continue;
}
@ -436,7 +428,7 @@ class TabsGridLayout extends GridView
final TabsLayoutItemView item = super.newView(position, parent);
item.setCloseOnClickListener(mCloseClickListener);
((ThemedRelativeLayout) item.findViewById(R.id.wrapper)).setPrivateMode(mIsPrivate);
((ThemedRelativeLayout) item.findViewById(R.id.wrapper)).setPrivateMode(isPrivate);
return item;
}

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

@ -56,7 +56,6 @@ public class TabsPanel extends LinearLayout
void setTabsPanel(TabsPanel panel);
void show();
void hide();
boolean shouldExpand();
}
public interface CloseAllPanelView extends PanelView {
@ -67,14 +66,6 @@ public class TabsPanel extends LinearLayout
void setEmptyView(View view);
}
public static View createTabsLayout(final Context context, final AttributeSet attrs) {
if (HardwareUtils.isTablet()) {
return new TabsGridLayout(context, attrs);
} else {
return new TabsListLayout(context, attrs);
}
}
public interface TabsLayoutChangeListener {
void onTabsLayoutChange(int width, int height);
}
@ -433,10 +424,6 @@ public class TabsPanel extends LinearLayout
return mVisible;
}
public Panel getCurrentPanel() {
return mCurrentPanel;
}
public void setHWLayerEnabled(boolean enabled) {
if (Versions.preHC) {
return;