]> gitweb.stoutner.com Git - PrivacyBrowserAndroid.git/blob - app/src/main/java/com/stoutner/privacybrowser/activities/GuideActivity.kt
e73608a56902f53e9f6fc67414814e9302e0f6f4
[PrivacyBrowserAndroid.git] / app / src / main / java / com / stoutner / privacybrowser / activities / GuideActivity.kt
1 /*
2  * Copyright © 2016-2022 Soren Stoutner <soren@stoutner.com>.
3  *
4  * This file is part of Privacy Browser Android <https://www.stoutner.com/privacy-browser-android>.
5  *
6  * Privacy Browser Android 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 Android 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 Android.  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.AppCompatActivity
26 import androidx.appcompat.widget.Toolbar
27 import androidx.preference.PreferenceManager
28 import androidx.viewpager.widget.ViewPager
29
30 import com.google.android.material.tabs.TabLayout
31
32 import com.stoutner.privacybrowser.R
33 import com.stoutner.privacybrowser.adapters.GuidePagerAdapter
34
35 class GuideActivity : AppCompatActivity() {
36     override fun onCreate(savedInstanceState: Bundle?) {
37         // Get a handle for the shared preferences.
38         val sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this)
39
40         // Get the preferences.
41         val allowScreenshots = sharedPreferences.getBoolean(getString(R.string.allow_screenshots_key), false)
42         val bottomAppBar = sharedPreferences.getBoolean(getString(R.string.bottom_app_bar_key), false)
43
44         // Disable screenshots if not allowed.
45         if (!allowScreenshots) {
46             window.addFlags(WindowManager.LayoutParams.FLAG_SECURE)
47         }
48
49         // Run the default commands.
50         super.onCreate(savedInstanceState)
51
52         // Set the content view.
53         if (bottomAppBar) {
54             setContentView(R.layout.guide_bottom_appbar)
55         } else {
56             setContentView(R.layout.guide_top_appbar)
57         }
58
59         // Get handles for the views.
60         val toolbar = findViewById<Toolbar>(R.id.guide_toolbar)
61         val guideViewPager = findViewById<ViewPager>(R.id.guide_viewpager)
62         val guideTabLayout = findViewById<TabLayout>(R.id.guide_tablayout)
63
64         // Set the support action bar.
65         setSupportActionBar(toolbar)
66
67         // Get a handle for the action bar.
68         val actionBar = supportActionBar!!
69
70         // Display the home arrow on the action bar.
71         actionBar.setDisplayHomeAsUpEnabled(true)
72
73         // Initialize the guide pager adapter.
74         val guidePagerAdapter = GuidePagerAdapter(supportFragmentManager, applicationContext)
75
76         // Set the view pager adapter.
77         guideViewPager.adapter = guidePagerAdapter
78
79         // Keep all the tabs in memory.  This prevents the memory usage adapter from running multiple times.
80         guideViewPager.offscreenPageLimit = 10
81
82         // Link the tab layout to the view pager.
83         guideTabLayout.setupWithViewPager(guideViewPager)
84     }
85 }