[Android] UI : Apply material theme to new SlidingTabLayout

Alexandre Perraud git at videolan.org
Thu Feb 26 17:30:50 CET 2015


vlc-ports/android | branch: master | Alexandre Perraud <4leyx4ndre at gmail.com> | Thu Feb 26 17:23:21 2015 +0100| [d9cff163432d87d3723fa706a0c7d6e8dc94348f] | committer: Alexandre Perraud

UI : Apply material theme to new SlidingTabLayout

> http://git.videolan.org/gitweb.cgi/vlc-ports/android.git/?a=commit;h=d9cff163432d87d3723fa706a0c7d6e8dc94348f
---

 vlc-android/res/layout/tab_layout.xml              |    3 +-
 vlc-android/res/values/attrs.xml                   |    3 ++
 vlc-android/res/values/styles.xml                  |    6 ++++
 .../src/com/android/widget/SlidingTabLayout.java   |   30 ++++++++++++++++++--
 .../src/com/android/widget/SlidingTabStrip.java    |    5 +++-
 .../src/org/videolan/vlc/gui/MainActivity.java     |    2 +-
 6 files changed, 43 insertions(+), 6 deletions(-)

diff --git a/vlc-android/res/layout/tab_layout.xml b/vlc-android/res/layout/tab_layout.xml
index abeb893..d3ae3c4 100644
--- a/vlc-android/res/layout/tab_layout.xml
+++ b/vlc-android/res/layout/tab_layout.xml
@@ -12,5 +12,4 @@
     android:typeface="normal"
     android:textSize="12sp"
     android:textStyle="bold"
-    android:textColor="@android:color/white"
-    android:textAllCaps="true" />
+    android:textColor="?attr/font_actionbar" />
diff --git a/vlc-android/res/values/attrs.xml b/vlc-android/res/values/attrs.xml
index f2fb8a9..b9f5c55 100644
--- a/vlc-android/res/values/attrs.xml
+++ b/vlc-android/res/values/attrs.xml
@@ -7,6 +7,7 @@
     <attr name="playlist_item_footer" format="reference|color" />
     <attr name="background_default" format="reference|color" />
     <attr name="background_default_darker" format="reference|color" />
+    <attr name="background_actionbar" format="reference|color" />
     <attr name="background_menu_divider" format="reference|color" />
     <attr name="background_menu" format="reference|color" />
     <attr name="background_header" format="reference|color" />
@@ -14,6 +15,8 @@
     <attr name="background_playlist" format="reference|color" />
     <attr name="font_default" format="reference|color" />
     <attr name="font_light" format="reference|color" />
+    <attr name="font_actionbar" format="reference|color" />
+    <attr name="font_actionbar_selected" format="reference|color" />
     <attr name="video_player_overlay" format="reference|color" />
     <attr name="status_bar_overlay" format="reference|color" />
     <attr name="advanced_options_divider" format="reference|color" />
diff --git a/vlc-android/res/values/styles.xml b/vlc-android/res/values/styles.xml
index 3f5576c..13f4677 100644
--- a/vlc-android/res/values/styles.xml
+++ b/vlc-android/res/values/styles.xml
@@ -30,6 +30,7 @@
         <item name="playlist_item_footer">@color/grey2</item>
         <item name="background_default">@color/grey50</item>
         <item name="background_default_darker">@color/grey100</item>
+        <item name="background_actionbar">@color/darkorange</item>
         <item name="background_menu_divider">@color/background_menu_divider</item>
         <item name="background_menu">@color/background_menu</item>
         <item name="background_player">@color/grey100</item>
@@ -40,6 +41,8 @@
         <item name="audio_player_header_time">@color/darkorange</item>
         <item name="font_default">@color/font_default</item>
         <item name="font_light">@color/font_light</item>
+        <item name="font_actionbar">@color/orange200</item>
+        <item name="font_actionbar_selected">@color/grey50</item>
         <item name="list_menu">@color/font_light</item>
         <item name="list_subtitle">@color/list_subtitle</item>
         <item name="list_title_last">@color/list_title_last</item>
@@ -100,6 +103,7 @@
         <item name="playlist_item_footer">@color/grey1</item>
         <item name="background_default">@color/grey850</item>
         <item name="background_default_darker">@color/grey875</item>
+        <item name="background_actionbar">@color/grey875</item>
         <item name="background_menu_divider">@color/grey1</item>
         <item name="background_menu">@color/grey850</item>
         <item name="background_player">@color/grey850</item>
@@ -110,6 +114,8 @@
         <item name="audio_player_header_time">@color/darkorange</item>
         <item name="font_default">@color/grey50</item>
         <item name="font_light">@color/font_light</item>
+        <item name="font_actionbar">@color/grey600</item>
+        <item name="font_actionbar_selected">@color/grey200</item>
         <item name="list_menu">@color/grey50</item>
         <item name="list_subtitle">@color/grey400</item>
         <item name="list_title_last">@color/list_title_last</item>
diff --git a/vlc-android/src/com/android/widget/SlidingTabLayout.java b/vlc-android/src/com/android/widget/SlidingTabLayout.java
index c6fb90e..f56dbc5 100644
--- a/vlc-android/src/com/android/widget/SlidingTabLayout.java
+++ b/vlc-android/src/com/android/widget/SlidingTabLayout.java
@@ -33,6 +33,7 @@ import android.widget.LinearLayout;
 import android.widget.TextView;
 
 import org.videolan.vlc.R;
+import org.videolan.vlc.util.Util;
 
 /**
  * To be used with ViewPager to provide a tab indicator component which give constant feedback as to
@@ -71,7 +72,6 @@ public class SlidingTabLayout extends HorizontalScrollView {
     private boolean mDistributeEvenly;
     private ViewPager mViewPager;
     private SparseArray<String> mContentDescriptions = new SparseArray<String>();
-    private ViewPager.OnPageChangeListener mViewPagerPageChangeListener;
     private final SlidingTabStrip mTabStrip;
     public SlidingTabLayout(Context context) {
         this(context, null);
@@ -85,7 +85,7 @@ public class SlidingTabLayout extends HorizontalScrollView {
         setHorizontalScrollBarEnabled(false);
         int hpadding = getResources().getDimensionPixelSize(R.dimen.tab_layout_horizontal_padding);
         setPadding(hpadding, 0, hpadding, 0);
-        setBackgroundColor(getResources().getColor(org.videolan.vlc.R.color.darkorange));
+        setBackgroundColor(getResources().getColor(Util.getResourceFromAttribute(context, org.videolan.vlc.R.attr.background_actionbar)));
         // Make sure that the Tab Strips fills this View
         setFillViewport(true);
         mTitleOffset = (int) (TITLE_OFFSET_DIPS * getResources().getDisplayMetrics().density);
@@ -187,6 +187,7 @@ public class SlidingTabLayout extends HorizontalScrollView {
                 lp.weight = 1;
             }
             tabTitleView.setText(adapter.getPageTitle(i).toString().toUpperCase());
+            tabTitleView.setTypeface(Typeface.DEFAULT_BOLD);
             tabView.setOnClickListener(tabClickListener);
             String desc = mContentDescriptions.get(i, null);
             if (desc != null) {
@@ -195,6 +196,7 @@ public class SlidingTabLayout extends HorizontalScrollView {
             mTabStrip.addView(tabView);
             if (i == mViewPager.getCurrentItem()) {
                 tabView.setSelected(true);
+                tabTitleView.setTextColor(getResources().getColor(Util.getResourceFromAttribute(getContext(), R.attr.font_actionbar_selected)));
             }
         }
     }
@@ -274,4 +276,28 @@ public class SlidingTabLayout extends HorizontalScrollView {
             }
         }
     }
+    private ViewPager.OnPageChangeListener mViewPagerPageChangeListener = new ViewPager.OnPageChangeListener() {
+        @Override
+        public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
+
+        }
+
+        @Override
+        public void onPageSelected(int position) {
+            for (int i = 0; i < mTabStrip.getChildCount(); i++) {
+                if (mTabStrip.getChildAt(i) instanceof TextView) {
+                    int color = (i == position)
+                            ? getResources().getColor(Util.getResourceFromAttribute(getContext(), R.attr.font_actionbar_selected))
+                            : getResources().getColor(Util.getResourceFromAttribute(getContext(), R.attr.font_actionbar));
+                    ((TextView) mTabStrip.getChildAt(i)).setTextColor(color);
+                }
+            }
+        }
+
+        @Override
+        public void onPageScrollStateChanged(int state) {
+
+        }
+    };
+
 }
\ No newline at end of file
diff --git a/vlc-android/src/com/android/widget/SlidingTabStrip.java b/vlc-android/src/com/android/widget/SlidingTabStrip.java
index a77cdb2..28779ef 100644
--- a/vlc-android/src/com/android/widget/SlidingTabStrip.java
+++ b/vlc-android/src/com/android/widget/SlidingTabStrip.java
@@ -24,6 +24,9 @@ import android.util.AttributeSet;
 import android.util.TypedValue;
 import android.view.View;
 import android.widget.LinearLayout;
+
+import org.videolan.vlc.util.Util;
+
 class SlidingTabStrip extends LinearLayout {
     private static final int DEFAULT_BOTTOM_BORDER_THICKNESS_DIPS = 0;
     private static final byte DEFAULT_BOTTOM_BORDER_COLOR_ALPHA = 0x26;
@@ -51,7 +54,7 @@ class SlidingTabStrip extends LinearLayout {
         mDefaultBottomBorderColor = setColorAlpha(themeForegroundColor,
                 DEFAULT_BOTTOM_BORDER_COLOR_ALPHA);
         mDefaultTabColorizer = new SimpleTabColorizer();
-        mDefaultTabColorizer.setIndicatorColors(Color.WHITE);
+        mDefaultTabColorizer.setIndicatorColors(getResources().getColor(Util.getResourceFromAttribute(context, org.videolan.vlc.R.attr.font_actionbar_selected)));
 //        mDefaultTabColorizer.setIndicatorColors(DEFAULT_SELECTED_INDICATOR_COLOR);
         mBottomBorderThickness = (int) (DEFAULT_BOTTOM_BORDER_THICKNESS_DIPS * density);
         mBottomBorderPaint = new Paint();
diff --git a/vlc-android/src/org/videolan/vlc/gui/MainActivity.java b/vlc-android/src/org/videolan/vlc/gui/MainActivity.java
index 9276f84..c6fd16d 100644
--- a/vlc-android/src/org/videolan/vlc/gui/MainActivity.java
+++ b/vlc-android/src/org/videolan/vlc/gui/MainActivity.java
@@ -188,7 +188,7 @@ public class MainActivity extends ActionBarActivity implements OnItemClickListen
         setContentView(R.layout.main);
 
         Toolbar toolbar = (Toolbar) findViewById(R.id.main_toolbar);
-        toolbar.setTitleTextColor(Color.WHITE);
+        toolbar.setTitleTextColor(getResources().getColor(Util.getResourceFromAttribute(mContext, R.attr.font_actionbar_selected)));
         setSupportActionBar(toolbar);
 
         mSlidingPane = (SlidingPaneLayout) findViewById(R.id.pane);



More information about the Android mailing list