]> gitweb.stoutner.com Git - PrivacyBrowserAndroid.git/blob - app/src/main/java/com/stoutner/privacybrowser/activities/GuideActivity.java
bd459471876c591dd4f634cae61ed350377848cd
[PrivacyBrowserAndroid.git] / app / src / main / java / com / stoutner / privacybrowser / activities / GuideActivity.java
1 /*
2  * Copyright © 2016-2019 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.content.SharedPreferences;
23 import android.os.Bundle;
24 import android.preference.PreferenceManager;
25 import android.view.WindowManager;
26
27 import androidx.appcompat.app.ActionBar;
28 import androidx.appcompat.app.AppCompatActivity;
29 import androidx.appcompat.widget.Toolbar;  // The AndroidX toolbar must be used until the minimum API is >= 21.
30 import androidx.fragment.app.Fragment;
31 import androidx.fragment.app.FragmentManager;
32 import androidx.fragment.app.FragmentPagerAdapter;
33 import androidx.viewpager.widget.ViewPager;
34
35 import com.google.android.material.tabs.TabLayout;
36
37 import com.stoutner.privacybrowser.fragments.GuideTabFragment;
38 import com.stoutner.privacybrowser.R;
39
40 public class GuideActivity extends AppCompatActivity {
41     @Override
42     protected void onCreate(Bundle savedInstanceState) {
43         // Get a handle for the shared preferences.
44         SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
45
46         // Get the theme and screenshot preferences.
47         boolean darkTheme = sharedPreferences.getBoolean("dark_theme", false);
48         boolean allowScreenshots = sharedPreferences.getBoolean("allow_screenshots", false);
49
50         // Disable screenshots if not allowed.
51         if (!allowScreenshots) {
52             getWindow().addFlags(WindowManager.LayoutParams.FLAG_SECURE);
53         }
54
55         // Set the theme.
56         if (darkTheme) {
57             setTheme(R.style.PrivacyBrowserDark_SecondaryActivity);
58         } else {
59             setTheme(R.style.PrivacyBrowserLight_SecondaryActivity);
60         }
61
62         // Run the default commands.
63         super.onCreate(savedInstanceState);
64
65         // Set the content view.
66         setContentView(R.layout.guide_coordinatorlayout);
67
68         // The AndroidX toolbar must be used until the minimum API is >= 21.
69         Toolbar toolbar = findViewById(R.id.guide_toolbar);
70         setSupportActionBar(toolbar);
71
72         // Get a handle for the action bar.
73         final ActionBar actionBar = getSupportActionBar();
74
75         // Remove the incorrect lint warning that the action bar might be null.
76         assert actionBar != null;
77
78         // Display the home arrow on the action bar.
79         actionBar.setDisplayHomeAsUpEnabled(true);
80
81         //  Setup the ViewPager.
82         ViewPager aboutViewPager = findViewById(R.id.guide_viewpager);
83         assert aboutViewPager != null; // This assert removes the incorrect warning in Android Studio on the following line that aboutViewPager might be null.
84         aboutViewPager.setAdapter(new guidePagerAdapter(getSupportFragmentManager()));
85
86         // Setup the TabLayout and connect it to the ViewPager.
87         TabLayout aboutTabLayout = findViewById(R.id.guide_tablayout);
88         assert aboutTabLayout != null; // This assert removes the incorrect warning in Android Studio on the following line that aboutTabLayout might be null.
89         aboutTabLayout.setupWithViewPager(aboutViewPager);
90     }
91
92     private class guidePagerAdapter extends FragmentPagerAdapter {
93         private guidePagerAdapter(FragmentManager fragmentManager) {
94             // Run the default commands.
95             super(fragmentManager);
96         }
97
98         @Override
99         // Get the count of the number of tabs.
100         public int getCount() {
101             return 10;
102         }
103
104         @Override
105         // Get the name of each tab.  Tab numbers start at 0.
106         public CharSequence getPageTitle(int tab) {
107             switch (tab) {
108                 case 0:
109                     return getString(R.string.overview);
110
111                 case 1:
112                     return getString(R.string.javascript);
113
114                 case 2:
115                     return getString(R.string.local_storage);
116
117                 case 3:
118                     return getString(R.string.user_agent);
119
120                 case 4:
121                     return getString(R.string.requests);
122
123                 case 5:
124                     return getString(R.string.domain_settings);
125
126                 case 6:
127                     return getString(R.string.ssl_certificates);
128
129                 case 7:
130                     return getString(R.string.tor);
131
132                 case 8:
133                     return getString(R.string.tracking_ids);
134
135                 case 9:
136                     return getString(R.string.bookmarks);
137
138                 default:
139                     return "";
140             }
141         }
142
143         @Override
144         // Setup each tab.
145         public Fragment getItem(int tab) {
146             return GuideTabFragment.createTab(tab);
147         }
148     }
149 }