X-Git-Url: https://gitweb.stoutner.com/?p=PrivacyBrowserAndroid.git;a=blobdiff_plain;f=app%2Fsrc%2Fmain%2Fjava%2Fcom%2Fstoutner%2Fprivacybrowser%2Factivities%2FAboutActivity.java;h=6ce5b431fa641b21d494a3b0238079bc9ad13235;hp=2251736b0ea7e95e720b9fd4ae0d5c9008e52d32;hb=1aa252f44922127b9053655a43b0df4e479438ed;hpb=f82135d919d64d4909c37c79a18e14ceba802579 diff --git a/app/src/main/java/com/stoutner/privacybrowser/activities/AboutActivity.java b/app/src/main/java/com/stoutner/privacybrowser/activities/AboutActivity.java index 2251736b..6ce5b431 100644 --- a/app/src/main/java/com/stoutner/privacybrowser/activities/AboutActivity.java +++ b/app/src/main/java/com/stoutner/privacybrowser/activities/AboutActivity.java @@ -1,5 +1,5 @@ /* - * Copyright © 2016-2017 Soren Stoutner . + * Copyright © 2016-2019 Soren Stoutner . * * This file is part of Privacy Browser . * @@ -19,88 +19,77 @@ package com.stoutner.privacybrowser.activities; +import android.content.Intent; +import android.content.SharedPreferences; import android.os.Bundle; -import android.support.design.widget.TabLayout; -import android.support.v4.app.Fragment; -import android.support.v4.app.FragmentManager; -import android.support.v4.app.FragmentPagerAdapter; -import android.support.v4.view.ViewPager; -import android.support.v7.app.ActionBar; -import android.support.v7.app.AppCompatActivity; -import android.support.v7.widget.Toolbar; - -import com.stoutner.privacybrowser.fragments.AboutTabFragment; +import android.preference.PreferenceManager; +import android.view.WindowManager; + +import androidx.appcompat.app.ActionBar; +import androidx.appcompat.app.AppCompatActivity; +import androidx.appcompat.widget.Toolbar; +import androidx.viewpager.widget.ViewPager; + +import com.google.android.material.tabs.TabLayout; + +import com.stoutner.privacybrowser.adapters.AboutPagerAdapter; import com.stoutner.privacybrowser.R; public class AboutActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.about_coordinatorlayout); + // Get a handle for the shared preferences. + SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this); - // We need to use the SupportActionBar from android.support.v7.app.ActionBar until the minimum API is >= 21. - Toolbar aboutAppBar = (Toolbar) findViewById(R.id.about_toolbar); - setSupportActionBar(aboutAppBar); + // Get the theme and screenshot preferences. + boolean darkTheme = sharedPreferences.getBoolean("dark_theme", false); + boolean allowScreenshots = sharedPreferences.getBoolean("allow_screenshots", false); - // Display the home arrow on supportAppBar. - final ActionBar appBar = getSupportActionBar(); - assert appBar != null;// This assert removes the incorrect warning in Android Studio on the following line that appBar might be null. - appBar.setDisplayHomeAsUpEnabled(true); - - // Setup the ViewPager. - ViewPager aboutViewPager = (ViewPager) findViewById(R.id.about_viewpager); - aboutViewPager.setAdapter(new aboutPagerAdapter(getSupportFragmentManager())); - - // Setup the TabLayout and connect it to the ViewPager. - TabLayout aboutTabLayout = (TabLayout) findViewById(R.id.about_tablayout); - aboutTabLayout.setupWithViewPager(aboutViewPager); - } - - private class aboutPagerAdapter extends FragmentPagerAdapter { - private aboutPagerAdapter(FragmentManager fm) { - super(fm); + // Disable screenshots if not allowed. + if (!allowScreenshots) { + getWindow().addFlags(WindowManager.LayoutParams.FLAG_SECURE); } - @Override - // Get the count of the number of tabs. - public int getCount() { - return 7; + // Set the theme. + if (darkTheme) { + setTheme(R.style.PrivacyBrowserDark_SecondaryActivity); + } else { + setTheme(R.style.PrivacyBrowserLight_SecondaryActivity); } - @Override - // Get the name of each tab. Tab numbers start at 0. - public CharSequence getPageTitle(int tab) { - switch (tab) { - case 0: - return getString(R.string.version); + // Run the default commands. + super.onCreate(savedInstanceState); - case 1: - return getString(R.string.permissions); + // Get the intent that launched the activity. + Intent launchingIntent = getIntent(); - case 2: - return getString(R.string.privacy_policy); + // Store the blocklist versions. + String[] blocklistVersions = launchingIntent.getStringArrayExtra("blocklist_versions"); - case 3: - return getString(R.string.changelog); + // Set the content view. + setContentView(R.layout.about_coordinatorlayout); - case 4: - return getString(R.string.licenses); + // Get handles for the views. + Toolbar toolbar = findViewById(R.id.about_toolbar); + TabLayout aboutTabLayout = findViewById(R.id.about_tablayout); + ViewPager aboutViewPager = findViewById(R.id.about_viewpager); - case 5: - return getString(R.string.contributors); + // Set the action bar. `SupportActionBar` must be used until the minimum API is >= 21. + setSupportActionBar(toolbar); - case 6: - return getString(R.string.links); + // Get a handle for the action bar. + final ActionBar actionBar = getSupportActionBar(); - default: - return ""; - } - } + // Remove the incorrect lint warning that the action bar might be null. + assert actionBar != null; // - @Override - // Setup each tab. - public Fragment getItem(int tab) { - return AboutTabFragment.createTab(tab); - } + // Display the home arrow on action bar. + actionBar.setDisplayHomeAsUpEnabled(true); + + // Setup the ViewPager. + aboutViewPager.setAdapter(new AboutPagerAdapter(getSupportFragmentManager(), getApplicationContext(), blocklistVersions)); + + // Connect the tab layout to the view pager. + aboutTabLayout.setupWithViewPager(aboutViewPager); } -} +} \ No newline at end of file