]> gitweb.stoutner.com Git - PrivacyBrowserAndroid.git/blob - app/src/main/java/com/stoutner/privacybrowser/activities/AboutActivity.java
Create a dark theme for `AboutActivity`.
[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 according to the theme.
49         if (MainWebViewActivity.darkTheme) {
50             setContentView(R.layout.about_coordinatorlayout_dark);
51         } else {
52             setContentView(R.layout.about_coordinatorlayout_light);
53         }
54
55         // We need to use the SupportActionBar from android.support.v7.app.ActionBar until the minimum API is >= 21.
56         Toolbar aboutAppBar = (Toolbar) findViewById(R.id.about_toolbar);
57         setSupportActionBar(aboutAppBar);
58
59         // Display the home arrow on supportAppBar.
60         final ActionBar appBar = getSupportActionBar();
61         assert appBar != null;// This assert removes the incorrect warning in Android Studio on the following line that appBar might be null.
62         appBar.setDisplayHomeAsUpEnabled(true);
63
64         //  Setup the ViewPager.
65         ViewPager aboutViewPager = (ViewPager) findViewById(R.id.about_viewpager);
66         aboutViewPager.setAdapter(new aboutPagerAdapter(getSupportFragmentManager()));
67
68         // Setup the TabLayout and connect it to the ViewPager.
69         TabLayout aboutTabLayout = (TabLayout) findViewById(R.id.about_tablayout);
70         aboutTabLayout.setupWithViewPager(aboutViewPager);
71     }
72
73     private class aboutPagerAdapter extends FragmentPagerAdapter {
74         private aboutPagerAdapter(FragmentManager fm) {
75             super(fm);
76         }
77
78         @Override
79         // Get the count of the number of tabs.
80         public int getCount() {
81             return 7;
82         }
83
84         @Override
85         // Get the name of each tab.  Tab numbers start at 0.
86         public CharSequence getPageTitle(int tab) {
87             switch (tab) {
88                 case 0:
89                     return getString(R.string.version);
90
91                 case 1:
92                     return getString(R.string.permissions);
93
94                 case 2:
95                     return getString(R.string.privacy_policy);
96
97                 case 3:
98                     return getString(R.string.changelog);
99
100                 case 4:
101                     return getString(R.string.licenses);
102
103                 case 5:
104                     return getString(R.string.contributors);
105
106                 case 6:
107                     return getString(R.string.links);
108
109                 default:
110                     return "";
111             }
112         }
113
114         @Override
115         // Setup each tab.
116         public Fragment getItem(int tab) {
117             return AboutTabFragment.createTab(tab);
118         }
119     }
120 }