[Android] Add OnTabChangedListener

Geoffrey Métais git at videolan.org
Wed Mar 4 17:20:49 CET 2015


vlc-ports/android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Wed Mar  4 17:20:25 2015 +0100| [3113316d845c37cb0aa5b26166aeec94d975c787] | committer: Geoffrey Métais

Add OnTabChangedListener

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

 vlc-android/src/com/android/widget/SlidingTabLayout.java |   13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/vlc-android/src/com/android/widget/SlidingTabLayout.java b/vlc-android/src/com/android/widget/SlidingTabLayout.java
index f56dbc5..47fcc3d 100644
--- a/vlc-android/src/com/android/widget/SlidingTabLayout.java
+++ b/vlc-android/src/com/android/widget/SlidingTabLayout.java
@@ -62,6 +62,11 @@ public class SlidingTabLayout extends HorizontalScrollView {
          */
         int getIndicatorColor(int position);
     }
+
+    public interface OnTabChangedListener {
+        public void tabChanged(int position);
+    }
+
     private static final int TITLE_OFFSET_DIPS = 24;
     private static final int TAB_VIEW_HORIZONTAL_PADDING_DIPS = 5;
     private static final int TAB_VIEW_VERTICAL_PADDING_DIPS = 10;
@@ -71,6 +76,7 @@ public class SlidingTabLayout extends HorizontalScrollView {
     private int mTabViewTextViewId;
     private boolean mDistributeEvenly;
     private ViewPager mViewPager;
+    private OnTabChangedListener tabChangedListener;
     private SparseArray<String> mContentDescriptions = new SparseArray<String>();
     private final SlidingTabStrip mTabStrip;
     public SlidingTabLayout(Context context) {
@@ -276,6 +282,11 @@ public class SlidingTabLayout extends HorizontalScrollView {
             }
         }
     }
+
+    public void setOnTabChangedListener(OnTabChangedListener listener) {
+        tabChangedListener = listener;
+    }
+
     private ViewPager.OnPageChangeListener mViewPagerPageChangeListener = new ViewPager.OnPageChangeListener() {
         @Override
         public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
@@ -284,6 +295,8 @@ public class SlidingTabLayout extends HorizontalScrollView {
 
         @Override
         public void onPageSelected(int position) {
+            if (tabChangedListener != null)
+                tabChangedListener.tabChanged(position);
             for (int i = 0; i < mTabStrip.getChildCount(); i++) {
                 if (mTabStrip.getChildAt(i) instanceof TextView) {
                     int color = (i == position)



More information about the Android mailing list