[Android] Custom tab view

Geoffrey Métais git at videolan.org
Thu Feb 26 11:23:34 CET 2015


vlc-ports/android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Thu Feb 26 11:22:59 2015 +0100| [8ae6f4b6c59fbb244a09804bd88e827f372dc116] | committer: Geoffrey Métais

Custom tab view

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

 vlc-android/res/layout/tab_layout.xml              |   30 +++++++++++---------
 vlc-android/res/values-sw480dp/dimens.xml          |    1 +
 vlc-android/res/values/dimens.xml                  |    1 +
 .../src/com/android/widget/SlidingTabLayout.java   |   10 ++++---
 .../src/com/android/widget/SlidingTabStrip.java    |    1 -
 .../src/org/videolan/vlc/gui/AboutFragment.java    |    1 +
 .../vlc/gui/audio/AudioAlbumsSongsFragment.java    |    1 +
 .../vlc/gui/audio/AudioBrowserFragment.java        |    3 +-
 8 files changed, 28 insertions(+), 20 deletions(-)

diff --git a/vlc-android/res/layout/tab_layout.xml b/vlc-android/res/layout/tab_layout.xml
index bc5b5d0..abeb893 100644
--- a/vlc-android/res/layout/tab_layout.xml
+++ b/vlc-android/res/layout/tab_layout.xml
@@ -1,14 +1,16 @@
-<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
-        android:layout_width="fill_parent"
-        android:layout_height="fill_parent"
-        android:background="@drawable/tab_indicator"
-        android:orientation="vertical" >
-
-    <TextView
-        android:id="@+id/textView"
-        android:layout_width="wrap_content"
-        android:layout_height="wrap_content"
-        android:layout_gravity="center_vertical|center_horizontal"
-        android:textAllCaps="true" />
-
-</LinearLayout>
+<TextView xmlns:android="http://schemas.android.com/apk/res/android"
+    android:id="@+id/tab_title"
+    android:layout_width="wrap_content"
+    android:layout_height="wrap_content"
+    android:paddingLeft="5dp"
+    android:paddingRight="5dp"
+    android:paddingBottom="10dp"
+    android:paddingTop="10dp"
+    android:gravity="center"
+    android:singleLine="true"
+    android:ellipsize="end"
+    android:typeface="normal"
+    android:textSize="12sp"
+    android:textStyle="bold"
+    android:textColor="@android:color/white"
+    android:textAllCaps="true" />
diff --git a/vlc-android/res/values-sw480dp/dimens.xml b/vlc-android/res/values-sw480dp/dimens.xml
index 4a2229d..93ce372 100644
--- a/vlc-android/res/values-sw480dp/dimens.xml
+++ b/vlc-android/res/values-sw480dp/dimens.xml
@@ -3,4 +3,5 @@
     <dimen name="media_ctrl_margin_top">30dp</dimen>
     <dimen name="images_margin_sides">60dp</dimen>
     <dimen name="overlay_margin">5dp</dimen>
+    <dimen name="tab_layout_horizontal_padding">20dp</dimen>
 </resources>
\ No newline at end of file
diff --git a/vlc-android/res/values/dimens.xml b/vlc-android/res/values/dimens.xml
index d696404..ef4f530 100644
--- a/vlc-android/res/values/dimens.xml
+++ b/vlc-android/res/values/dimens.xml
@@ -11,6 +11,7 @@
     <dimen name="grid_card_title_text_size">12sp</dimen>
     <dimen name="grid_card_subtitle_text_size">10sp</dimen>
     <dimen name="grid_card_vertical_spacing">0dp</dimen>
+    <dimen name="tab_layout_horizontal_padding">5dp</dimen>
 
     <!-- Video Player -->
     <dimen name="overlay_padding_bottom">15dip</dimen>
diff --git a/vlc-android/src/com/android/widget/SlidingTabLayout.java b/vlc-android/src/com/android/widget/SlidingTabLayout.java
index 244fe87..c6fb90e 100644
--- a/vlc-android/src/com/android/widget/SlidingTabLayout.java
+++ b/vlc-android/src/com/android/widget/SlidingTabLayout.java
@@ -31,6 +31,9 @@ import android.view.ViewGroup;
 import android.widget.HorizontalScrollView;
 import android.widget.LinearLayout;
 import android.widget.TextView;
+
+import org.videolan.vlc.R;
+
 /**
  * To be used with ViewPager to provide a tab indicator component which give constant feedback as to
  * the user's scroll progress.
@@ -80,6 +83,9 @@ public class SlidingTabLayout extends HorizontalScrollView {
         super(context, attrs, defStyle);
         // Disable the Scroll Bar
         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));
         // Make sure that the Tab Strips fills this View
         setFillViewport(true);
         mTitleOffset = (int) (TITLE_OFFSET_DIPS * getResources().getDisplayMetrics().density);
@@ -151,10 +157,6 @@ public class SlidingTabLayout extends HorizontalScrollView {
         textView.setTypeface(Typeface.DEFAULT_BOLD);
         textView.setLayoutParams(new LinearLayout.LayoutParams(
                 ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));
-        TypedValue outValue = new TypedValue();
-        getContext().getTheme().resolveAttribute(android.R.attr.selectableItemBackground,
-                outValue, true);
-        textView.setBackgroundResource(outValue.resourceId);
         textView.setTextColor(Color.WHITE);
         int hpadding = (int) (TAB_VIEW_HORIZONTAL_PADDING_DIPS * getResources().getDisplayMetrics().density);
         int vpadding = (int) (TAB_VIEW_VERTICAL_PADDING_DIPS * getResources().getDisplayMetrics().density);
diff --git a/vlc-android/src/com/android/widget/SlidingTabStrip.java b/vlc-android/src/com/android/widget/SlidingTabStrip.java
index f344655..a77cdb2 100644
--- a/vlc-android/src/com/android/widget/SlidingTabStrip.java
+++ b/vlc-android/src/com/android/widget/SlidingTabStrip.java
@@ -58,7 +58,6 @@ class SlidingTabStrip extends LinearLayout {
         mBottomBorderPaint.setColor(mDefaultBottomBorderColor);
         mSelectedIndicatorThickness = (int) (SELECTED_INDICATOR_THICKNESS_DIPS * density);
         mSelectedIndicatorPaint = new Paint();
-        setBackgroundColor(getResources().getColor(org.videolan.vlc.R.color.darkorange));
     }
     void setCustomTabColorizer(SlidingTabLayout.TabColorizer customTabColorizer) {
         mCustomTabColorizer = customTabColorizer;
diff --git a/vlc-android/src/org/videolan/vlc/gui/AboutFragment.java b/vlc-android/src/org/videolan/vlc/gui/AboutFragment.java
index 53400c6..2a584e5 100644
--- a/vlc-android/src/org/videolan/vlc/gui/AboutFragment.java
+++ b/vlc-android/src/org/videolan/vlc/gui/AboutFragment.java
@@ -101,6 +101,7 @@ public class AboutFragment extends Fragment {
         mViewPager.setAdapter(new AudioPagerAdapter(lists, titles));
 
         mSlidingTabLayout = (SlidingTabLayout) v.findViewById(R.id.sliding_tabs);
+        mSlidingTabLayout.setCustomTabView(R.layout.tab_layout, R.id.tab_title);
         mSlidingTabLayout.setDistributeEvenly(true);
         mSlidingTabLayout.setViewPager(mViewPager);
 
diff --git a/vlc-android/src/org/videolan/vlc/gui/audio/AudioAlbumsSongsFragment.java b/vlc-android/src/org/videolan/vlc/gui/audio/AudioAlbumsSongsFragment.java
index c55b18c..6312fd8 100644
--- a/vlc-android/src/org/videolan/vlc/gui/audio/AudioAlbumsSongsFragment.java
+++ b/vlc-android/src/org/videolan/vlc/gui/audio/AudioAlbumsSongsFragment.java
@@ -131,6 +131,7 @@ public class AudioAlbumsSongsFragment extends BrowserFragment implements SwipeRe
 
         mViewPager.setOnTouchListener(mSwipeFilter);
         mSlidingTabLayout = (SlidingTabLayout) v.findViewById(R.id.sliding_tabs);
+        mSlidingTabLayout.setCustomTabView(R.layout.tab_layout, R.id.tab_title);
         mSlidingTabLayout.setDistributeEvenly(true);
         mSlidingTabLayout.setViewPager(mViewPager);
 
diff --git a/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserFragment.java b/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserFragment.java
index b2ff49c..5bf715e 100644
--- a/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserFragment.java
+++ b/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserFragment.java
@@ -146,11 +146,12 @@ public class AudioBrowserFragment extends BrowserFragment implements SwipeRefres
         String[] titles = new String[] {getString(R.string.artists), getString(R.string.albums),
                 getString(R.string.songs), getString(R.string.genres)};
         mViewPager = (ViewPager) v.findViewById(R.id.pager);
-        mViewPager.setOffscreenPageLimit(MODE_TOTAL-1);
+        mViewPager.setOffscreenPageLimit(MODE_TOTAL - 1);
         mViewPager.setAdapter(new AudioPagerAdapter(mLists, titles));
 
         mViewPager.setOnTouchListener(mSwipeFilter);
         mSlidingTabLayout = (SlidingTabLayout) v.findViewById(R.id.sliding_tabs);
+        mSlidingTabLayout.setCustomTabView(R.layout.tab_layout, R.id.tab_title);
         mSlidingTabLayout.setDistributeEvenly(true);
         mSlidingTabLayout.setViewPager(mViewPager);
 



More information about the Android mailing list