1
1
package it .niedermann .owncloud .notes .android .activity ;
2
2
3
3
import android .os .Bundle ;
4
- import android .support .v4 .app .FragmentTabHost ;
4
+ import android .support .design .widget .TabLayout ;
5
+ import android .support .v4 .app .Fragment ;
6
+ import android .support .v4 .app .FragmentManager ;
7
+ import android .support .v4 .app .FragmentPagerAdapter ;
8
+ import android .support .v4 .view .ViewPager ;
5
9
import android .support .v7 .app .AppCompatActivity ;
6
10
7
11
import it .niedermann .owncloud .notes .R ;
11
15
12
16
public class AboutActivity extends AppCompatActivity {
13
17
14
- private FragmentTabHost mTabHost ;
15
18
@ Override
16
19
protected void onCreate (Bundle savedInstanceState ) {
17
20
super .onCreate (savedInstanceState );
18
21
19
22
setContentView (R .layout .activity_about );
20
- mTabHost = (FragmentTabHost ) findViewById (android .R .id .tabhost );
21
- mTabHost .setup (this , getSupportFragmentManager (), R .id .realtabcontent );
22
-
23
- mTabHost .addTab (mTabHost .newTabSpec (getString (R .string .about_credits_tab_title )).setIndicator (getString (R .string .about_credits_tab_title )),
24
- AboutFragmentCreditsTab .class , null );
25
- mTabHost .addTab (mTabHost .newTabSpec (getString (R .string .about_contribution_tab_title )).setIndicator (getString (R .string .about_contribution_tab_title )),
26
- AboutFragmentContributingTab .class , null );
27
- mTabHost .addTab (mTabHost .newTabSpec (getString (R .string .about_license_tab_title )).setIndicator (getString (R .string .about_license_tab_title )),
28
- AboutFragmentLicenseTab .class , null );
23
+
24
+ ViewPager mViewPager = (ViewPager ) findViewById (R .id .pager );
25
+ TabLayout mTabLayout = (TabLayout ) findViewById (R .id .tabs );
26
+
27
+ mViewPager .setAdapter (new TabsPagerAdapter (getSupportFragmentManager ()));
28
+ mTabLayout .setupWithViewPager (mViewPager );
29
+
30
+ }
31
+
32
+ private class TabsPagerAdapter extends FragmentPagerAdapter {
33
+ private final int PAGE_COUNT = 3 ;
34
+
35
+ public TabsPagerAdapter (FragmentManager fragmentManager ) {
36
+ super (fragmentManager );
37
+ }
38
+
39
+ @ Override
40
+ public int getCount () {
41
+ return PAGE_COUNT ;
42
+ }
43
+
44
+ /**
45
+ * return the right fragment for the given position
46
+ */
47
+ @ Override
48
+ public Fragment getItem (int position ) {
49
+ switch (position ) {
50
+ case 0 :
51
+ return new AboutFragmentCreditsTab ();
52
+
53
+ case 1 :
54
+ return new AboutFragmentContributingTab ();
55
+
56
+ case 2 :
57
+ return new AboutFragmentLicenseTab ();
58
+
59
+ default :
60
+ return null ;
61
+ }
62
+ }
63
+
64
+ /**
65
+ * generate title based on given position
66
+ */
67
+ @ Override
68
+ public CharSequence getPageTitle (int position ) {
69
+ switch (position ) {
70
+ case 0 :
71
+ return getString (R .string .about_credits_tab_title );
72
+
73
+ case 1 :
74
+ return getString (R .string .about_contribution_tab_title );
75
+
76
+ case 2 :
77
+ return getString (R .string .about_license_tab_title );
78
+
79
+ default :
80
+ return null ;
81
+ }
82
+ }
29
83
}
30
84
}
0 commit comments