]> gitweb.stoutner.com Git - PrivacyBrowserAndroid.git/blobdiff - app/src/main/java/com/stoutner/privacybrowser/activities/ViewSourceActivity.java
Switch to the new Day/Night theme. https://redmine.stoutner.com/issues/522
[PrivacyBrowserAndroid.git] / app / src / main / java / com / stoutner / privacybrowser / activities / ViewSourceActivity.java
index 229bcf28ade37a7c7e51beb1ae1d1e7774003a7c..51036fbc38bc82cf46b6d87fd97c070b275a6d90 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright © 2017-2019 Soren Stoutner <soren@stoutner.com>.
+ * Copyright © 2017-2020 Soren Stoutner <soren@stoutner.com>.
  *
  * This file is part of Privacy Browser <https://www.stoutner.com/privacy-browser>.
  *
@@ -23,10 +23,12 @@ import android.app.Activity;
 import android.content.Context;
 import android.content.Intent;
 import android.content.SharedPreferences;
+import android.content.res.Configuration;
 import android.os.Bundle;
 import android.preference.PreferenceManager;
 import android.text.Spanned;
 import android.text.style.ForegroundColorSpan;
+import android.util.TypedValue;
 import android.view.KeyEvent;
 import android.view.Menu;
 import android.view.MenuItem;
@@ -61,9 +63,8 @@ public class ViewSourceActivity extends AppCompatActivity {
         // Get a handle for the shared preferences.
         SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
 
-        // Get the screenshot and theme preferences.
+        // Get the screenshot preference.
         boolean allowScreenshots = sharedPreferences.getBoolean("allow_screenshots", false);
-        boolean darkTheme = sharedPreferences.getBoolean("dark_theme", false);
 
         // Disable screenshots if not allowed.
         if (!allowScreenshots) {
@@ -71,11 +72,7 @@ public class ViewSourceActivity extends AppCompatActivity {
         }
 
         // Set the theme.
-        if (darkTheme) {
-            setTheme(R.style.PrivacyBrowserDark);
-        } else {
-            setTheme(R.style.PrivacyBrowserLight);
-        }
+        setTheme(R.style.PrivacyBrowser);
 
         // Run the default commands.
         super.onCreate(savedInstanceState);
@@ -161,7 +158,7 @@ public class ViewSourceActivity extends AppCompatActivity {
 
                 // Get new source data for the current URL if it beings with `http`.
                 if (url.startsWith("http")) {
-                    new GetSource(this, userAgent).execute(url);
+                    new GetSource(this, this, userAgent).execute(url);
                 }
 
                 // Consume the key press.
@@ -182,24 +179,38 @@ public class ViewSourceActivity extends AppCompatActivity {
 
             // Get new source data for the URL if it begins with `http`.
             if (url.startsWith("http")) {
-                new GetSource(this, userAgent).execute(url);
+                new GetSource(this, this, userAgent).execute(url);
             } else {
                 // Stop the refresh animation.
                 swipeRefreshLayout.setRefreshing(false);
             }
         });
 
-        // Set the swipe to refresh color according to the theme.
-        if (darkTheme) {
-            swipeRefreshLayout.setColorSchemeResources(R.color.blue_600);
-            swipeRefreshLayout.setProgressBackgroundColorSchemeResource(R.color.gray_800);
+        // Get the current theme status.
+        int currentThemeStatus = getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK;
+
+        // Set the refresh color scheme according to the theme.
+        if (currentThemeStatus == Configuration.UI_MODE_NIGHT_YES) {
+            swipeRefreshLayout.setColorSchemeResources(R.color.blue_500);
         } else {
             swipeRefreshLayout.setColorSchemeResources(R.color.blue_700);
         }
 
+        // Initialize a color background typed value.
+        TypedValue colorBackgroundTypedValue = new TypedValue();
+
+        // Get the color background from the theme.
+        getTheme().resolveAttribute(android.R.attr.colorBackground, colorBackgroundTypedValue, true);
+
+        // Get the color background int from the typed value.
+        int colorBackgroundInt = colorBackgroundTypedValue.data;
+
+        // Set the swipe refresh background color.
+        swipeRefreshLayout.setProgressBackgroundColorSchemeColor(colorBackgroundInt);
+
         // Get the source using an AsyncTask if the URL begins with `http`.
         if ((currentUrl != null) && currentUrl.startsWith("http")) {
-            new GetSource(this, userAgent).execute(currentUrl);
+            new GetSource(this, this, userAgent).execute(currentUrl);
         }
     }