Skip to content

Commit 4baf533

Browse files
Fix #85 About: Make tabs swipeable
Uses #109 from fxedel
1 parent 8395c42 commit 4baf533

File tree

3 files changed

+79
-42
lines changed

3 files changed

+79
-42
lines changed

app/app.iml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<module external.linked.project.id=":app" external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$/.." external.system.id="GRADLE" external.system.module.group="OwnCloudNotes" external.system.module.version="unspecified" type="JAVA_MODULE" version="4">
2+
<module external.linked.project.id=":app" external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$/.." external.system.id="GRADLE" external.system.module.group="OwnCloud-Notes" external.system.module.version="unspecified" type="JAVA_MODULE" version="4">
33
<component name="FacetManager">
44
<facet type="android-gradle" name="Android-Gradle">
55
<configuration>
@@ -77,6 +77,7 @@
7777
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/incremental" />
7878
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/manifests" />
7979
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/pre-dexed" />
80+
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/release" />
8081
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/res" />
8182
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/rs" />
8283
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/symbols" />
Lines changed: 65 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
package it.niedermann.owncloud.notes.android.activity;
22

33
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;
59
import android.support.v7.app.AppCompatActivity;
610

711
import it.niedermann.owncloud.notes.R;
@@ -11,20 +15,70 @@
1115

1216
public class AboutActivity extends AppCompatActivity {
1317

14-
private FragmentTabHost mTabHost;
1518
@Override
1619
protected void onCreate(Bundle savedInstanceState) {
1720
super.onCreate(savedInstanceState);
1821

1922
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+
}
2983
}
3084
}
Lines changed: 12 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,17 @@
11
<?xml version="1.0" encoding="utf-8"?>
2+
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
3+
android:layout_width="match_parent"
4+
android:layout_height="match_parent"
5+
android:orientation="vertical">
26

3-
<android.support.v4.app.FragmentTabHost
4-
android:id="@android:id/tabhost"
5-
xmlns:android="http://schemas.android.com/apk/res/android"
6-
android:layout_width="match_parent"
7-
android:layout_height="match_parent"
8-
>
9-
10-
<LinearLayout
7+
<android.support.design.widget.TabLayout
8+
android:id="@+id/tabs"
119
android:layout_width="match_parent"
12-
android:layout_height="match_parent"
13-
android:orientation="vertical">
14-
15-
<TabWidget
16-
android:id="@android:id/tabs"
17-
android:layout_width="match_parent"
18-
android:layout_height="wrap_content"
19-
android:layout_weight="0"
20-
android:orientation="horizontal"/>
10+
android:layout_height="wrap_content"/>
2111

22-
<FrameLayout
23-
android:id="@android:id/tabcontent"
24-
android:layout_width="0dp"
25-
android:layout_height="0dp"
26-
android:layout_weight="0"/>
27-
28-
<FrameLayout
29-
android:id="@+id/realtabcontent"
30-
android:layout_width="match_parent"
31-
android:layout_height="0dp"
32-
android:layout_weight="1"/>
12+
<android.support.v4.view.ViewPager
13+
android:id="@+id/pager"
14+
android:layout_width="match_parent"
15+
android:layout_height="wrap_content"/>
3316

34-
</LinearLayout>
35-
</android.support.v4.app.FragmentTabHost>
17+
</LinearLayout>

0 commit comments

Comments
 (0)