]> gitweb.stoutner.com Git - PrivacyBrowserAndroid.git/blob - app/src/main/java/com/stoutner/privacybrowser/activities/AboutActivity.java
0f6df3dfad5b166ab4b2eddf699664039b0a964e
[PrivacyBrowserAndroid.git] / app / src / main / java / com / stoutner / privacybrowser / activities / AboutActivity.java
1 /*
2  * Copyright © 2016-2017 Soren Stoutner <soren@stoutner.com>.
3  *
4  * This file is part of Privacy Browser <https://www.stoutner.com/privacy-browser>.
5  *
6  * Privacy Browser is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * Privacy Browser is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with Privacy Browser.  If not, see <http://www.gnu.org/licenses/>.
18  */
19
20 package com.stoutner.privacybrowser.activities;
21
22 import android.os.Bundle;
23 import android.support.design.widget.TabLayout;
24 import android.support.v4.app.Fragment;
25 import android.support.v4.app.FragmentManager;
26 import android.support.v4.app.FragmentPagerAdapter;
27 import android.support.v4.view.ViewPager;
28 import android.support.v7.app.ActionBar;
29 import android.support.v7.app.AppCompatActivity;
30 import android.support.v7.widget.Toolbar;
31
32 import com.stoutner.privacybrowser.fragments.AboutTabFragment;
33 import com.stoutner.privacybrowser.R;
34
35 public class AboutActivity extends AppCompatActivity {
36     @Override
37     protected void onCreate(Bundle savedInstanceState) {
38         // Set the theme.
39         if (MainWebViewActivity.darkTheme) {
40             setTheme(R.style.PrivacyBrowserDark_SecondaryActivity);
41         } else {
42             setTheme(R.style.PrivacyBrowserLight_SecondaryActivity);
43         }
44
45         // Run the default commands.
46         super.onCreate(savedInstanceState);
47
48         // Set the content view.
49         setContentView(R.layout.about_coordinatorlayout);
50
51         // `SupportActionBar` from `android.support.v7.app.ActionBar` must be used until the minimum API is >= 21.
52         Toolbar aboutAppBar = findViewById(R.id.about_toolbar);
53         setSupportActionBar(aboutAppBar);
54
55         // Display the home arrow on `supportAppBar`.
56         final ActionBar appBar = getSupportActionBar();
57         assert appBar != null;  // This assert removes the incorrect warning in Android Studio on the following line that appBar might be null.
58         appBar.setDisplayHomeAsUpEnabled(true);
59
60         //  Setup the ViewPager.
61         ViewPager aboutViewPager = findViewById(R.id.about_viewpager);
62         aboutViewPager.setAdapter(new aboutPagerAdapter(getSupportFragmentManager()));
63
64         // Setup the TabLayout and connect it to the ViewPager.
65         TabLayout aboutTabLayout = findViewById(R.id.about_tablayout);
66         aboutTabLayout.setupWithViewPager(aboutViewPager);
67     }
68
69     private class aboutPagerAdapter extends FragmentPagerAdapter {
70         private aboutPagerAdapter(FragmentManager fm) {
71             super(fm);
72         }
73
74         @Override
75         // Get the count of the number of tabs.
76         public int getCount() {
77             return 7;
78         }
79
80         @Override
81         // Get the name of each tab.  Tab numbers start at 0.
82         public CharSequence getPageTitle(int tab) {
83             switch (tab) {
84                 case 0:
85                     return getString(R.string.version);
86
87                 case 1:
88                     return getString(R.string.permissions);
89
90                 case 2:
91                     return getString(R.string.privacy_policy);
92
93                 case 3:
94                     return getString(R.string.changelog);
95
96                 case 4:
97                     return getString(R.string.licenses);
98
99                 case 5:
100                     return getString(R.string.contributors);
101
102                 case 6:
103                     return getString(R.string.links);
104
105                 default:
106                     return "";
107             }
108         }
109
110         @Override
111         // Setup each tab.
112         public Fragment getItem(int tab) {
113             return AboutTabFragment.createTab(tab);
114         }
115     }
116 }