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