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.MenuItem
24 import android.view.WindowManager
26 import androidx.appcompat.app.AppCompatActivity
27 import androidx.appcompat.widget.Toolbar
28 import androidx.preference.PreferenceManager
30 import com.stoutner.privacybrowser.R
31 import com.stoutner.privacybrowser.fragments.SettingsFragment
33 class SettingsActivity : AppCompatActivity() {
34 override fun onCreate(savedInstanceState: Bundle?) {
35 // Get a handle for the shared preferences.
36 val sharedPreferences = PreferenceManager.getDefaultSharedPreferences(applicationContext)
38 // Get the preference.
39 val allowScreenshots = sharedPreferences.getBoolean(getString(R.string.allow_screenshots_key), false)
40 val bottomAppBar = sharedPreferences.getBoolean(getString(R.string.bottom_app_bar_key), false)
42 // Disable screenshots if not allowed.
43 if (!allowScreenshots) window.addFlags(WindowManager.LayoutParams.FLAG_SECURE)
45 // Run the default commands.
46 super.onCreate(savedInstanceState)
48 // Set the content view.
50 setContentView(R.layout.settings_bottom_appbar)
52 setContentView(R.layout.settings_top_appbar)
55 // Get a handle for the toolbar.
56 val toolbar = findViewById<Toolbar>(R.id.toolbar)
58 // Set the support action bar.
59 setSupportActionBar(toolbar)
61 // Get a handle for the action bar.
62 val actionBar = supportActionBar!!
64 // Display the home arrow on the action bar.
65 actionBar.setDisplayHomeAsUpEnabled(true)
67 // Display the settings fragment.
68 supportFragmentManager.beginTransaction().replace(R.id.preferences_framelayout, SettingsFragment()).commit()
71 override fun onOptionsItemSelected(item: MenuItem): Boolean {
72 // As the back arrow is the only option, finish the activity.