2 * Copyright 2016-2022 Soren Stoutner <soren@stoutner.com>.
4 * This file is part of Privacy Browser Android <https://www.stoutner.com/privacy-browser-android>.
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.
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.
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/>.
20 package com.stoutner.privacybrowser.activities
22 import android.os.Bundle
23 import android.view.WindowManager
25 import androidx.appcompat.app.AppCompatActivity
26 import androidx.appcompat.widget.Toolbar
27 import androidx.preference.PreferenceManager
28 import androidx.viewpager.widget.ViewPager
30 import com.google.android.material.tabs.TabLayout
32 import com.stoutner.privacybrowser.R
33 import com.stoutner.privacybrowser.adapters.GuidePagerAdapter
35 class GuideActivity : AppCompatActivity() {
36 override fun onCreate(savedInstanceState: Bundle?) {
37 // Get a handle for the shared preferences.
38 val sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this)
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)
44 // Disable screenshots if not allowed.
45 if (!allowScreenshots) {
46 window.addFlags(WindowManager.LayoutParams.FLAG_SECURE)
49 // Run the default commands.
50 super.onCreate(savedInstanceState)
52 // Set the content view.
54 setContentView(R.layout.guide_bottom_appbar)
56 setContentView(R.layout.guide_top_appbar)
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)
64 // Set the support action bar.
65 setSupportActionBar(toolbar)
67 // Get a handle for the action bar.
68 val actionBar = supportActionBar!!
70 // Display the home arrow on the action bar.
71 actionBar.setDisplayHomeAsUpEnabled(true)
73 // Initialize the guide pager adapter.
74 val guidePagerAdapter = GuidePagerAdapter(supportFragmentManager, applicationContext)
76 // Set the view pager adapter.
77 guideViewPager.adapter = guidePagerAdapter
79 // Keep all the tabs in memory. This prevents the memory usage adapter from running multiple times.
80 guideViewPager.offscreenPageLimit = 10
82 // Link the tab layout to the view pager.
83 guideTabLayout.setupWithViewPager(guideViewPager)