]> gitweb.stoutner.com Git - PrivacyBrowserAndroid.git/blob - app/src/main/java/com/stoutner/privacybrowser/activities/GuideActivity.java
856aa5d57163802fdd4c92e6d1dea72e787e48ff
[PrivacyBrowserAndroid.git] / app / src / main / java / com / stoutner / privacybrowser / activities / GuideActivity.java
1 /*
2  * Copyright © 2016-2018 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 import android.view.WindowManager;
32
33 import com.stoutner.privacybrowser.fragments.GuideTabFragment;
34 import com.stoutner.privacybrowser.R;
35
36 public class GuideActivity extends AppCompatActivity {
37     @Override
38     protected void onCreate(Bundle savedInstanceState) {
39         // Disable screenshots if not allowed.
40         if (!MainWebViewActivity.allowScreenshots) {
41             getWindow().addFlags(WindowManager.LayoutParams.FLAG_SECURE);
42         }
43
44         // Set the theme.
45         if (MainWebViewActivity.darkTheme) {
46             setTheme(R.style.PrivacyBrowserDark_SecondaryActivity);
47         } else {
48             setTheme(R.style.PrivacyBrowserLight_SecondaryActivity);
49         }
50
51         // Run the default commands.
52         super.onCreate(savedInstanceState);
53
54         // Set the content view.
55         setContentView(R.layout.guide_coordinatorlayout);
56
57         // We need to use `SupportActionBar` from `android.support.v7.app.ActionBar` until the minimum API is >= 21.
58         Toolbar guideAppBar = findViewById(R.id.guide_toolbar);
59         setSupportActionBar(guideAppBar);
60
61         // Display the home arrow on `ppBar`.
62         final ActionBar appBar = getSupportActionBar();
63         assert appBar != null;  // This assert removes the incorrect lint warning in Android Studio on the following line that `appBar` might be `null`.
64         appBar.setDisplayHomeAsUpEnabled(true);
65
66         //  Setup the ViewPager.
67         ViewPager aboutViewPager = findViewById(R.id.guide_viewpager);
68         assert aboutViewPager != null; // This assert removes the incorrect warning in Android Studio on the following line that aboutViewPager might be null.
69         aboutViewPager.setAdapter(new guidePagerAdapter(getSupportFragmentManager()));
70
71         // Setup the TabLayout and connect it to the ViewPager.
72         TabLayout aboutTabLayout = findViewById(R.id.guide_tablayout);
73         assert aboutTabLayout != null; // This assert removes the incorrect warning in Android Studio on the following line that aboutTabLayout might be null.
74         aboutTabLayout.setupWithViewPager(aboutViewPager);
75     }
76
77     private class guidePagerAdapter extends FragmentPagerAdapter {
78         private guidePagerAdapter(FragmentManager fm) {
79             super(fm);
80         }
81
82         @Override
83         // Get the count of the number of tabs.
84         public int getCount() {
85             return 9;
86         }
87
88         @Override
89         // Get the name of each tab.  Tab numbers start at 0.
90         public CharSequence getPageTitle(int tab) {
91             switch (tab) {
92                 case 0:
93                     return getString(R.string.overview);
94
95                 case 1:
96                     return getString(R.string.javascript);
97
98                 case 2:
99                     return getString(R.string.local_storage);
100
101                 case 3:
102                     return getString(R.string.user_agent);
103
104                 case 4:
105                     return getString(R.string.domain_settings);
106
107                 case 5:
108                     return getString(R.string.ssl_certificates);
109
110                 case 6:
111                     return getString(R.string.tor);
112
113                 case 7:
114                     return getString(R.string.tracking_ids);
115
116                 case 8:
117                     return getString(R.string.bookmarks);
118
119                 default:
120                     return "";
121             }
122         }
123
124         @Override
125         // Setup each tab.
126         public Fragment getItem(int tab) {
127             return GuideTabFragment.createTab(tab);
128         }
129     }
130 }