[Android] SlidingTabLayout for AboutFragment

Geoffrey Métais git at videolan.org
Wed Feb 25 18:31:59 CET 2015


vlc-ports/android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Wed Feb 25 18:29:50 2015 +0100| [4a365ef32b631d140cc2f25407755ba6c2687d1b] | committer: Geoffrey Métais

SlidingTabLayout for AboutFragment

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

 vlc-android/res/layout/about.xml                   |   66 ++++++++------------
 vlc-android/res/layout/about_main.xml              |    1 +
 .../src/org/videolan/vlc/gui/AboutFragment.java    |   64 +++++++------------
 .../vlc/gui/audio/AudioAlbumsSongsFragment.java    |    2 +-
 .../vlc/gui/audio/AudioBrowserFragment.java        |    2 +-
 .../videolan/vlc/gui/audio/AudioPagerAdapter.java  |    4 +-
 6 files changed, 53 insertions(+), 86 deletions(-)

diff --git a/vlc-android/res/layout/about.xml b/vlc-android/res/layout/about.xml
index f2579b0..672d0ba 100644
--- a/vlc-android/res/layout/about.xml
+++ b/vlc-android/res/layout/about.xml
@@ -1,43 +1,27 @@
 <?xml version="1.0" encoding="utf-8"?>
-<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    android:id="@android:id/tabcontent"
     android:layout_width="fill_parent"
-    android:layout_height="fill_parent"
-    android:gravity="center|fill_vertical"
-    android:orientation="vertical"
-    android:weightSum="1" >
-
-    <TabHost
-        android:id="@android:id/tabhost"
-        android:layout_width="fill_parent"
-        android:layout_height="fill_parent" >
-
-        <LinearLayout
-            android:layout_width="fill_parent"
-            android:layout_height="fill_parent"
-            android:orientation="vertical" >
-
-            <TabWidget
-                android:id="@android:id/tabs"
-                android:layout_width="fill_parent"
-                android:layout_height="wrap_content"
-                android:background="?attr/background_header" />
-
-            <FrameLayout
-                android:id="@android:id/tabcontent"
-                android:layout_width="fill_parent"
-                android:layout_height="fill_parent" >
-
-                <org.videolan.vlc.widget.FlingViewGroup
-                    android:id="@+id/fling_view_group"
-                    android:layout_width="match_parent"
-                    android:layout_height="match_parent" >
-
-                    <include layout="@layout/about_main" />
-
-                    <include layout="@layout/about_licence" />
-                </org.videolan.vlc.widget.FlingViewGroup>
-            </FrameLayout>
-        </LinearLayout>
-    </TabHost>
-
-</LinearLayout>
+    android:layout_height="fill_parent" >
+
+    <com.android.widget.SlidingTabLayout
+        android:id="@+id/sliding_tabs"
+        android:layout_width="match_parent"
+        android:layout_height="wrap_content"/>
+
+        <android.support.v4.view.ViewPager
+            android:id="@+id/pager"
+            android:layout_width="match_parent"
+            android:layout_height="match_parent"
+            android:layout_below="@+id/sliding_tabs">
+
+            <include layout="@layout/about_main" />
+            <include layout="@layout/about_licence" />
+        </android.support.v4.view.ViewPager>
+
+    <View
+        android:layout_width="match_parent"
+        android:layout_height="9dp"
+        android:layout_below="@+id/sliding_tabs"
+        android:background="@drawable/bottom_shadow" />
+</RelativeLayout>
diff --git a/vlc-android/res/layout/about_main.xml b/vlc-android/res/layout/about_main.xml
index c423910..b897736 100644
--- a/vlc-android/res/layout/about_main.xml
+++ b/vlc-android/res/layout/about_main.xml
@@ -1,5 +1,6 @@
 <?xml version="1.0" encoding="utf-8"?>
 <ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
+    android:id="@+id/about_main"
     android:layout_width="match_parent"
     android:layout_height="match_parent">
 
diff --git a/vlc-android/src/org/videolan/vlc/gui/AboutFragment.java b/vlc-android/src/org/videolan/vlc/gui/AboutFragment.java
index 026df2c..de6f6db 100644
--- a/vlc-android/src/org/videolan/vlc/gui/AboutFragment.java
+++ b/vlc-android/src/org/videolan/vlc/gui/AboutFragment.java
@@ -24,6 +24,7 @@ import android.annotation.SuppressLint;
 import android.content.Context;
 import android.os.Bundle;
 import android.support.v4.app.Fragment;
+import android.support.v4.view.ViewPager;
 import android.support.v7.app.ActionBarActivity;
 import android.text.Html;
 import android.view.LayoutInflater;
@@ -40,18 +41,25 @@ import android.widget.TabHost;
 import android.widget.TabHost.TabSpec;
 import android.widget.TextView;
 
+import com.android.widget.SlidingTabLayout;
+
 import org.videolan.vlc.BuildConfig;
 import org.videolan.vlc.R;
+import org.videolan.vlc.gui.audio.AudioPagerAdapter;
 import org.videolan.vlc.util.Util;
 import org.videolan.vlc.widget.FlingViewGroup;
 
+import java.util.ArrayList;
+
 public class AboutFragment extends Fragment {
     public final static String TAG = "VLC/AboutActivity";
 
-    private TabHost mTabHost;
-    FlingViewGroup mFlingViewGroup;
-    private int mCurrentTab = 0;
+    public final static int MODE_ABOUT = 0;
+    public final static int MODE_LICENCE = 1;
+    public final static int MODE_TOTAL = 2; // Number of audio browser modes
 
+    private ViewPager mViewPager;
+    private SlidingTabLayout mSlidingTabLayout;
 
     @Override
     public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
@@ -59,9 +67,7 @@ public class AboutFragment extends Fragment {
 
         View v = inflater.inflate(R.layout.about, container, false);
 
-        mTabHost = (TabHost) v.findViewById(android.R.id.tabhost);
-        mFlingViewGroup = (FlingViewGroup) v.findViewById(R.id.fling_view_group);
-
+        View aboutMain = v.findViewById(R.id.about_main);
         WebView t = (WebView)v.findViewById(R.id.webview);
         String revision = getString(R.string.build_revision);
         t.loadData(Util.readAsset("licence.htm", "").replace("!COMMITID!",revision), "text/html", "UTF8");
@@ -90,41 +96,17 @@ public class AboutFragment extends Fragment {
             }
         });
 
-        mTabHost.setup();
-
-        addNewTab(mTabHost, "about", getResources().getString(R.string.about));
-        addNewTab(mTabHost, "licence", getResources().getString(R.string.licence));
-
-        mTabHost.setCurrentTab(mCurrentTab);
-        mFlingViewGroup.snapToScreen(mCurrentTab);
-
-        mTabHost.setOnTabChangedListener(new TabHost.OnTabChangeListener() {
-            @Override
-            public void onTabChanged(String tabId) {
-                mCurrentTab = mTabHost.getCurrentTab();
-                mFlingViewGroup.smoothScrollTo(mCurrentTab);
-            }
-        });
-
-        mFlingViewGroup.setOnViewSwitchedListener(new FlingViewGroup.ViewSwitchListener() {
-            @Override
-            public void onSwitching(float progress) { }
-            @Override
-            public void onSwitched(int position) {
-                mTabHost.setCurrentTab(position);
-            }
-            @Override
-            public void onTouchDown() {}
-            @Override
-            public void onTouchUp() {}
-            @Override
-            public void onTouchClick() {}
-            @Override
-            public void onBackSwitched() {
-                MainActivity activity = (MainActivity)getActivity();
-                activity.popSecondaryFragment();
-            }
-        });
+        ArrayList<View> lists = new ArrayList<>();
+        lists.add(aboutMain);
+        lists.add(t);
+        String[] titles = new String[] {getString(R.string.about), getString(R.string.licence)};
+        mViewPager = (ViewPager) v.findViewById(R.id.pager);
+        mViewPager.setOffscreenPageLimit(MODE_TOTAL-1);
+        mViewPager.setAdapter(new AudioPagerAdapter(lists, titles));
+
+        mSlidingTabLayout = (SlidingTabLayout) v.findViewById(R.id.sliding_tabs);
+        mSlidingTabLayout.setDistributeEvenly(true);
+        mSlidingTabLayout.setViewPager(mViewPager);
 
         return v;
     }
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 16212d6..0e0b353 100644
--- a/vlc-android/src/org/videolan/vlc/gui/audio/AudioAlbumsSongsFragment.java
+++ b/vlc-android/src/org/videolan/vlc/gui/audio/AudioAlbumsSongsFragment.java
@@ -130,7 +130,7 @@ public class AudioAlbumsSongsFragment extends BrowserFragment implements SwipeRe
         ListView albumsList = (ListView) v.findViewById(R.id.albums);
         ListView songsList = (ListView) v.findViewById(R.id.songs);
 
-        ArrayList<ListView> lists = new ArrayList<>();
+        ArrayList<View> lists = new ArrayList<>();
         lists.add(albumsList);
         lists.add(songsList);
         String[] titles = new String[] {getString(R.string.albums), getString(R.string.songs)};
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 a132cf7..7239f62 100644
--- a/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserFragment.java
+++ b/vlc-android/src/org/videolan/vlc/gui/audio/AudioBrowserFragment.java
@@ -136,7 +136,7 @@ public class AudioBrowserFragment extends BrowserFragment implements SwipeRefres
         genreList.setAdapter(mGenresAdapter);
 
 
-        ArrayList<ListView> lists = new ArrayList<>();
+        ArrayList<View> lists = new ArrayList<>();
         lists.add(artistList);
         lists.add(albumList);
         lists.add(songsList);
diff --git a/vlc-android/src/org/videolan/vlc/gui/audio/AudioPagerAdapter.java b/vlc-android/src/org/videolan/vlc/gui/audio/AudioPagerAdapter.java
index 15e0dc5..5828a2d 100644
--- a/vlc-android/src/org/videolan/vlc/gui/audio/AudioPagerAdapter.java
+++ b/vlc-android/src/org/videolan/vlc/gui/audio/AudioPagerAdapter.java
@@ -34,10 +34,10 @@ import java.util.ArrayList;
 
 public class AudioPagerAdapter extends PagerAdapter {
 
-    private ArrayList<ListView> mLists;
+    private ArrayList<View> mLists;
     private String[] mTitles;
 
-    public AudioPagerAdapter(ArrayList<ListView> lists, String[] titles){
+    public AudioPagerAdapter(ArrayList<View> lists, String[] titles){
         mLists = lists;
         mTitles = titles;
     }



More information about the Android mailing list