From 899c42debcb5bfc00f03e304bdbb59b2818181f9 Mon Sep 17 00:00:00 2001 From: Sriram Ramasubramanian Date: Thu, 24 Jan 2013 17:08:08 -0800 Subject: [PATCH] Bug 834525: New tab thumbnail styling for tabs-ui. [r=mfinkle] --HG-- extra : rebase_source : a774fdea385a9f3e9997adebf730cdb40e9e8a92 --- mobile/android/base/GeckoViewsFactory.java | 7 +- mobile/android/base/Makefile.in | 5 +- mobile/android/base/TabsTray.java | 27 +----- .../tab_title.xml} | 7 +- .../base/resources/drawable/tab_thumbnail.xml | 39 +++++++++ .../drawable/tabs_tray_default_selector.xml | 11 --- .../layout-xlarge-v11/remote_tabs_child.xml | 6 +- .../layout-xlarge-v11/remote_tabs_group.xml | 2 +- .../layout-xlarge-v11/tabs_panel.xml.in | 2 + .../resources/layout-xlarge-v11/tabs_row.xml | 86 +++++++------------ .../resources/layout/remote_tabs_child.xml | 6 +- .../resources/layout/remote_tabs_group.xml | 2 +- .../base/resources/layout/tabs_panel.xml.in | 1 + .../base/resources/layout/tabs_row.xml | 65 ++++++-------- .../resources/values-xlarge-v11/dimens.xml | 2 +- .../android/base/resources/values/dimens.xml | 5 +- .../android/base/resources/values/styles.xml | 15 +--- mobile/android/base/widget/TabRow.java | 60 +++++++++++++ 18 files changed, 186 insertions(+), 162 deletions(-) rename mobile/android/base/resources/{drawable/tabs_tray_active_selector.xml => color/tab_title.xml} (68%) create mode 100644 mobile/android/base/resources/drawable/tab_thumbnail.xml delete mode 100644 mobile/android/base/resources/drawable/tabs_tray_default_selector.xml create mode 100644 mobile/android/base/widget/TabRow.java diff --git a/mobile/android/base/GeckoViewsFactory.java b/mobile/android/base/GeckoViewsFactory.java index 9c90fd03145..4e45b5ecf60 100644 --- a/mobile/android/base/GeckoViewsFactory.java +++ b/mobile/android/base/GeckoViewsFactory.java @@ -5,6 +5,7 @@ package org.mozilla.gecko; import org.mozilla.gecko.gfx.LayerView; +import org.mozilla.gecko.widget.TabRow; import org.mozilla.gecko.widget.ThumbnailView; import android.content.Context; @@ -83,12 +84,16 @@ public final class GeckoViewsFactory implements LayoutInflater.Factory { return new MenuButton(context, attrs); else if (TextUtils.equals(viewName, "RemoteTabs")) return new RemoteTabs(context, attrs); + else if (TextUtils.equals(viewName, "TabRow")) + return new TabRow(context, attrs); else if (TextUtils.equals(viewName, "TabsButton")) return new TabsButton(context, attrs); else if (TextUtils.equals(viewName, "TabsPanel")) return new TabsPanel(context, attrs); else if (TextUtils.equals(viewName, "TabsTray")) return new TabsTray(context, attrs); + else if (TextUtils.equals(viewName, "ThumbnailView")) + return new ThumbnailView(context, attrs); else if (TextUtils.equals(viewName, "TextSelectionHandle")) return new TextSelectionHandle(context, attrs); else if (TextUtils.equals(viewName, "gfx.LayerView")) @@ -113,8 +118,6 @@ public final class GeckoViewsFactory implements LayoutInflater.Factory { return new GeckoTextSwitcher(context, attrs); else if (TextUtils.equals(viewName, "TextView")) return new GeckoTextView(context, attrs); - else if (TextUtils.equals(viewName, "widget.ThumbnailView")) - return new ThumbnailView(context, attrs); else Log.d(LOGTAG, "Warning: unknown custom view: " + viewName); } diff --git a/mobile/android/base/Makefile.in b/mobile/android/base/Makefile.in index a6d1760c235..3796e9eebcb 100644 --- a/mobile/android/base/Makefile.in +++ b/mobile/android/base/Makefile.in @@ -183,6 +183,7 @@ FENNEC_JAVA_FILES = \ ui/SimpleScaleGestureDetector.java \ ui/SubdocumentScrollHelper.java \ widget/DateTimePicker.java \ + widget/TabRow.java \ widget/ThumbnailView.java \ GeckoNetworkManager.java \ GeckoScreenOrientationListener.java \ @@ -1032,6 +1033,7 @@ RES_DRAWABLE_XLARGE_XHDPI_V11 = \ RES_COLOR = \ res/color/menu_item_title.xml \ res/color/select_item_multichoice.xml \ + res/color/tab_title.xml \ res/color/tabs_counter_color.xml \ $(NULL) @@ -1092,12 +1094,11 @@ MOZ_ANDROID_DRAWABLES += \ mobile/android/base/resources/drawable/spinner.xml \ mobile/android/base/resources/drawable/suggestion_selector.xml \ mobile/android/base/resources/drawable/tab_new_level.xml \ + mobile/android/base/resources/drawable/tab_thumbnail.xml \ mobile/android/base/resources/drawable/tabs_button.xml \ mobile/android/base/resources/drawable/tabs_level.xml \ mobile/android/base/resources/drawable/tabs_tray_bg_repeat.xml \ mobile/android/base/resources/drawable/tabs_tray_selected_bg_repeat.xml \ - mobile/android/base/resources/drawable/tabs_tray_active_selector.xml \ - mobile/android/base/resources/drawable/tabs_tray_default_selector.xml \ mobile/android/base/resources/drawable/shadow.png \ mobile/android/base/resources/drawable/marketplace.png \ mobile/android/base/resources/drawable/webapp_titlebar_bg.xml \ diff --git a/mobile/android/base/TabsTray.java b/mobile/android/base/TabsTray.java index 0dfa23062b0..8e9f5b5ae08 100644 --- a/mobile/android/base/TabsTray.java +++ b/mobile/android/base/TabsTray.java @@ -115,14 +115,12 @@ public class TabsTray extends ListView int id; TextView title; ImageView thumbnail; - ImageButton close; LinearLayout info; public TabRow(View view) { info = (LinearLayout) view; title = (TextView) view.findViewById(R.id.title); thumbnail = (ImageView) view.findViewById(R.id.thumbnail); - close = (ImageButton) view.findViewById(R.id.close); } } @@ -196,7 +194,7 @@ public class TabsTray extends ListView if (selected == -1) return; - TabsTray.this.setSelection(selected); + TabsTray.this.setItemChecked(selected, true); } public void clear() { @@ -227,6 +225,7 @@ public class TabsTray extends ListView if (tab.isPrivate() == mIsPrivate && mTabs != null) { mTabs.remove(tab); notifyDataSetChanged(); // Be sure to call this whenever mTabs changes. + updateSelectedPosition(); } } @@ -245,13 +244,11 @@ public class TabsTray extends ListView row.thumbnail.setImageResource(R.drawable.tab_thumbnail_default); if (Tabs.getInstance().isSelectedTab(tab)) - row.info.setBackgroundResource(R.drawable.tabs_tray_active_selector); + row.thumbnail.setAlpha(255); else - row.info.setBackgroundResource(R.drawable.tabs_tray_default_selector); + row.thumbnail.setAlpha(179); row.title.setText(tab.getDisplayTitle()); - - row.close.setTag(row); } public View getView(int position, View convertView, ViewGroup parent) { @@ -259,14 +256,10 @@ public class TabsTray extends ListView if (convertView == null) { convertView = mInflater.inflate(R.layout.tabs_row, null); - row = new TabRow(convertView); - row.close.setOnClickListener(mOnCloseClickListener); - convertView.setTag(row); } else { row = (TabRow) convertView.getTag(); - row.close.setVisibility(View.VISIBLE); } Tab tab = mTabs.get(position); @@ -336,15 +329,6 @@ public class TabsTray extends ListView PropertyAnimator animator = new PropertyAnimator(ANIMATION_DURATION); animator.attach(view, Property.ALPHA, 1); animator.attach(view, Property.TRANSLATION_X, 0); - - animator.setPropertyAnimationListener(new PropertyAnimator.PropertyAnimationListener() { - public void onPropertyAnimationStart() { } - public void onPropertyAnimationEnd() { - TabRow tab = (TabRow) view.getTag(); - tab.close.setVisibility(View.VISIBLE); - } - }); - animator.start(); } @@ -494,9 +478,6 @@ public class TabsTray extends ListView mSwiping = true; TabsTray.this.requestDisallowInterceptTouchEvent(true); - TabRow tab = (TabRow) mSwipeView.getTag(); - tab.close.setVisibility(View.INVISIBLE); - // Stops listview from highlighting the touched item // in the list when swiping. MotionEvent cancelEvent = MotionEvent.obtain(e); diff --git a/mobile/android/base/resources/drawable/tabs_tray_active_selector.xml b/mobile/android/base/resources/color/tab_title.xml similarity index 68% rename from mobile/android/base/resources/drawable/tabs_tray_active_selector.xml rename to mobile/android/base/resources/color/tab_title.xml index 984a4ba1118..81344cbefda 100644 --- a/mobile/android/base/resources/drawable/tabs_tray_active_selector.xml +++ b/mobile/android/base/resources/color/tab_title.xml @@ -5,7 +5,10 @@ - - + + + diff --git a/mobile/android/base/resources/drawable/tab_thumbnail.xml b/mobile/android/base/resources/drawable/tab_thumbnail.xml new file mode 100644 index 00000000000..f229f1792c6 --- /dev/null +++ b/mobile/android/base/resources/drawable/tab_thumbnail.xml @@ -0,0 +1,39 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/mobile/android/base/resources/drawable/tabs_tray_default_selector.xml b/mobile/android/base/resources/drawable/tabs_tray_default_selector.xml deleted file mode 100644 index c2eca9bd086..00000000000 --- a/mobile/android/base/resources/drawable/tabs_tray_default_selector.xml +++ /dev/null @@ -1,11 +0,0 @@ - - - - - - - - - diff --git a/mobile/android/base/resources/layout-xlarge-v11/remote_tabs_child.xml b/mobile/android/base/resources/layout-xlarge-v11/remote_tabs_child.xml index 35df9110190..a958ded596c 100644 --- a/mobile/android/base/resources/layout-xlarge-v11/remote_tabs_child.xml +++ b/mobile/android/base/resources/layout-xlarge-v11/remote_tabs_child.xml @@ -8,20 +8,20 @@ android:layout_height="@dimen/remote_tab_child_row_height" android:gravity="center_vertical" android:orientation="vertical" - android:background="@drawable/tabs_tray_default_selector" + android:background="@drawable/action_bar_button" android:paddingLeft="2dp" android:paddingRight="2dp"> diff --git a/mobile/android/base/resources/layout-xlarge-v11/remote_tabs_group.xml b/mobile/android/base/resources/layout-xlarge-v11/remote_tabs_group.xml index 0ba18e6bdbd..ff4a1602a67 100644 --- a/mobile/android/base/resources/layout-xlarge-v11/remote_tabs_group.xml +++ b/mobile/android/base/resources/layout-xlarge-v11/remote_tabs_group.xml @@ -7,7 +7,7 @@ android:id="@+id/client" android:layout_width="fill_parent" android:layout_height="@dimen/remote_tab_group_row_height" - style="@style/RemoteTabRowTextAppearance.Url" + style="@style/TabRowTextAppearance.Url" android:background="@android:color/transparent" android:paddingLeft="2dip" android:paddingRight="2dip" diff --git a/mobile/android/base/resources/layout-xlarge-v11/tabs_panel.xml.in b/mobile/android/base/resources/layout-xlarge-v11/tabs_panel.xml.in index 02b2e17aa3e..129848b83af 100644 --- a/mobile/android/base/resources/layout-xlarge-v11/tabs_panel.xml.in +++ b/mobile/android/base/resources/layout-xlarge-v11/tabs_panel.xml.in @@ -37,6 +37,7 @@ style="@style/TabsList" android:layout_width="fill_parent" android:layout_height="fill_parent" + android:choiceMode="singleChoice" android:visibility="gone" gecko:tabs="tabs_normal"/> @@ -44,6 +45,7 @@ style="@style/TabsList" android:layout_width="fill_parent" android:layout_height="fill_parent" + android:choiceMode="singleChoice" android:visibility="gone" gecko:tabs="tabs_private"/> diff --git a/mobile/android/base/resources/layout-xlarge-v11/tabs_row.xml b/mobile/android/base/resources/layout-xlarge-v11/tabs_row.xml index d433d715ada..4061e8e579e 100644 --- a/mobile/android/base/resources/layout-xlarge-v11/tabs_row.xml +++ b/mobile/android/base/resources/layout-xlarge-v11/tabs_row.xml @@ -3,64 +3,38 @@ - 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/. --> - - - - - - - - - - - - - - - - - + android:padding="6dip" + android:gravity="center"> - + + + + + + + + + diff --git a/mobile/android/base/resources/layout/remote_tabs_child.xml b/mobile/android/base/resources/layout/remote_tabs_child.xml index 5f4ce532474..52691eaee9a 100644 --- a/mobile/android/base/resources/layout/remote_tabs_child.xml +++ b/mobile/android/base/resources/layout/remote_tabs_child.xml @@ -8,20 +8,20 @@ android:layout_height="@dimen/remote_tab_child_row_height" android:gravity="center_vertical" android:orientation="vertical" - android:background="@drawable/tabs_tray_default_selector" + android:background="@drawable/action_bar_button" android:paddingLeft="4dp" android:paddingRight="4dp"> diff --git a/mobile/android/base/resources/layout/remote_tabs_group.xml b/mobile/android/base/resources/layout/remote_tabs_group.xml index 29a62485e65..45f040094a7 100644 --- a/mobile/android/base/resources/layout/remote_tabs_group.xml +++ b/mobile/android/base/resources/layout/remote_tabs_group.xml @@ -7,7 +7,7 @@ android:id="@+id/client" android:layout_width="fill_parent" android:layout_height="@dimen/remote_tab_group_row_height" - style="@style/RemoteTabRowTextAppearance.Url" + style="@style/TabRowTextAppearance.Url" android:background="@android:color/transparent" android:paddingLeft="4dp" android:paddingRight="4dp" diff --git a/mobile/android/base/resources/layout/tabs_panel.xml.in b/mobile/android/base/resources/layout/tabs_panel.xml.in index 689b4c3a6bc..60d88108dce 100644 --- a/mobile/android/base/resources/layout/tabs_panel.xml.in +++ b/mobile/android/base/resources/layout/tabs_panel.xml.in @@ -35,6 +35,7 @@ style="@style/TabsList" android:layout_width="fill_parent" android:layout_height="fill_parent" + android:choiceMode="singleChoice" android:visibility="gone" gecko:tabs="tabs_normal"/> diff --git a/mobile/android/base/resources/layout/tabs_row.xml b/mobile/android/base/resources/layout/tabs_row.xml index 8885e2d6067..df0cd43e99f 100644 --- a/mobile/android/base/resources/layout/tabs_row.xml +++ b/mobile/android/base/resources/layout/tabs_row.xml @@ -3,58 +3,41 @@ - 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/. --> - + android:layout_height="wrap_content" + android:paddingLeft="12dip" + android:paddingRight="12dip" + android:paddingTop="6dip" + android:paddingBottom="6dip"> - + - + - - - + + android:maxLines="4" + android:duplicateParentState="true"/> - - - + diff --git a/mobile/android/base/resources/values-xlarge-v11/dimens.xml b/mobile/android/base/resources/values-xlarge-v11/dimens.xml index 914a59791f0..b9a1fbca5ac 100644 --- a/mobile/android/base/resources/values-xlarge-v11/dimens.xml +++ b/mobile/android/base/resources/values-xlarge-v11/dimens.xml @@ -12,9 +12,9 @@ 66dp 46dp 56dp - 150dp 56dp 34dp + 114dp 26sp 8dip 84dip diff --git a/mobile/android/base/resources/values/dimens.xml b/mobile/android/base/resources/values/dimens.xml index 89e9fb382f0..94c859348e1 100644 --- a/mobile/android/base/resources/values/dimens.xml +++ b/mobile/android/base/resources/values/dimens.xml @@ -29,7 +29,6 @@ 29.33dip 44dp 6dp - 108dp 44dp 240dp 5dip @@ -46,8 +45,8 @@ 64dp 26dp 400dp - 78dp - 136dp + 90dp + 160dp 22sp 16dip 2dp diff --git a/mobile/android/base/resources/values/styles.xml b/mobile/android/base/resources/values/styles.xml index 52f47c58686..5c101195c6a 100644 --- a/mobile/android/base/resources/values/styles.xml +++ b/mobile/android/base/resources/values/styles.xml @@ -154,23 +154,12 @@ - - - - - diff --git a/mobile/android/base/widget/TabRow.java b/mobile/android/base/widget/TabRow.java new file mode 100644 index 00000000000..84590fbe4f5 --- /dev/null +++ b/mobile/android/base/widget/TabRow.java @@ -0,0 +1,60 @@ +/* -*- 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.widget; + +import android.content.Context; +import android.util.AttributeSet; +import android.view.View; +import android.widget.Checkable; +import android.widget.LinearLayout; + +public class TabRow extends LinearLayout + implements Checkable { + private static final String LOGTAG = "GeckoTabRow"; + private static final int[] STATE_CHECKED = { android.R.attr.state_checked }; + private boolean mChecked; + + public TabRow(Context context, AttributeSet attrs) { + super(context, attrs); + mChecked = false; + } + + @Override + public int[] onCreateDrawableState(int extraSpace) { + final int[] drawableState = super.onCreateDrawableState(extraSpace + 1); + + if (mChecked) + mergeDrawableStates(drawableState, STATE_CHECKED); + + return drawableState; + } + + @Override + public boolean isChecked() { + return mChecked; + } + + @Override + public void setChecked(boolean checked) { + android.util.Log.i("Sriram", "setting the state to: " + checked); + if (mChecked != checked) { + mChecked = checked; + refreshDrawableState(); + + int count = getChildCount(); + for (int i=0; i < count; i++) { + final View child = getChildAt(i); + if (child instanceof Checkable) + ((Checkable) child).setChecked(checked); + } + } + } + + @Override + public void toggle() { + mChecked = !mChecked; + } +}