]> gitweb.stoutner.com Git - PrivacyBrowserAndroid.git/blob - app/src/main/java/com/stoutner/privacybrowser/activities/SettingsActivity.kt
Add a bottom app bar to Settings. https://redmine.stoutner.com/issues/716
[PrivacyBrowserAndroid.git] / app / src / main / java / com / stoutner / privacybrowser / activities / SettingsActivity.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.MenuItem
24 import android.view.WindowManager
25
26 import androidx.appcompat.app.AppCompatActivity
27 import androidx.appcompat.widget.Toolbar
28 import androidx.preference.PreferenceManager
29
30 import com.stoutner.privacybrowser.R
31 import com.stoutner.privacybrowser.fragments.SettingsFragment
32
33 class SettingsActivity : AppCompatActivity() {
34     override fun onCreate(savedInstanceState: Bundle?) {
35         // Get a handle for the shared preferences.
36         val sharedPreferences = PreferenceManager.getDefaultSharedPreferences(applicationContext)
37
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)
41
42         // Disable screenshots if not allowed.
43         if (!allowScreenshots) window.addFlags(WindowManager.LayoutParams.FLAG_SECURE)
44
45         // Run the default commands.
46         super.onCreate(savedInstanceState)
47
48         // Set the content view.
49         if (bottomAppBar) {
50             setContentView(R.layout.settings_bottom_appbar)
51         } else {
52             setContentView(R.layout.settings_top_appbar)
53         }
54
55         // Get a handle for the toolbar.
56         val toolbar = findViewById<Toolbar>(R.id.toolbar)
57
58         // Set the support action bar.
59         setSupportActionBar(toolbar)
60
61         // Get a handle for the action bar.
62         val actionBar = supportActionBar!!
63
64         // Display the home arrow on the action bar.
65         actionBar.setDisplayHomeAsUpEnabled(true)
66
67         // Display the settings fragment.
68         supportFragmentManager.beginTransaction().replace(R.id.preferences_framelayout, SettingsFragment()).commit()
69     }
70
71     override fun onOptionsItemSelected(item: MenuItem): Boolean {
72         // As the back arrow is the only option, finish the activity.
73         finish()
74
75         // Consume the event.
76         return true
77     }
78 }