From: Soren Stoutner Date: Wed, 14 Jun 2017 01:24:32 +0000 (-0700) Subject: Create a dark theme for `AboutActivity`. X-Git-Tag: v2.4~9 X-Git-Url: https://gitweb.stoutner.com/?a=commitdiff_plain;h=e3ed631a52f5e8eac2d5c938b2d475ed6c9362bb;p=PrivacyBrowserAndroid.git Create a dark theme for `AboutActivity`. --- diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 300e3045..cca1063f 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -162,7 +162,6 @@ = 21. Toolbar aboutAppBar = (Toolbar) findViewById(R.id.about_toolbar); diff --git a/app/src/main/java/com/stoutner/privacybrowser/activities/MainWebViewActivity.java b/app/src/main/java/com/stoutner/privacybrowser/activities/MainWebViewActivity.java index b8266726..e7286522 100644 --- a/app/src/main/java/com/stoutner/privacybrowser/activities/MainWebViewActivity.java +++ b/app/src/main/java/com/stoutner/privacybrowser/activities/MainWebViewActivity.java @@ -122,6 +122,9 @@ import java.util.Set; public class MainWebViewActivity extends AppCompatActivity implements NavigationView.OnNavigationItemSelectedListener, CreateHomeScreenShortcutDialog.CreateHomeScreenSchortcutListener, SslCertificateErrorDialog.SslCertificateErrorListener, DownloadFileDialog.DownloadFileListener, DownloadImageDialog.DownloadImageListener, UrlHistoryDialog.UrlHistoryListener { + // `darkTheme` is public static so it can be accessed from `AboutActivity`. It is also used in `onCreate()`, `applyAppSettings()`, and `applyDomainSettings()`. + public static boolean darkTheme; + // `favoriteIconBitmap` is public static so it can be accessed from `CreateHomeScreenShortcutDialog`, `BookmarksActivity`, `CreateBookmarkDialog`, `CreateBookmarkFolderDialog`, `EditBookmarkDialog`, `EditBookmarkFolderDialog`, `ViewSslCertificateDialog`. // It is also used in `onCreate()`, `onCreateHomeScreenShortcutCreate()`, and `applyDomainSettings`. public static Bitmap favoriteIconBitmap; @@ -292,9 +295,6 @@ public class MainWebViewActivity extends AppCompatActivity implements Navigation // `mainWebViewRelativeLayout` is used in `onCreate()` and `onNavigationItemSelected()`. private RelativeLayout mainWebViewRelativeLayout; - // `darkTheme` is used in `onCreate()`, `applyAppSettings()`, and `applyDomainSettings()`. - private boolean darkTheme; - @Override // Remove Android Studio's warning about the dangers of using SetJavaScriptEnabled. The whole premise of Privacy Browser is built around an understanding of these dangers. @SuppressLint("SetJavaScriptEnabled") @@ -317,7 +317,7 @@ public class MainWebViewActivity extends AppCompatActivity implements Navigation // Run the default commands. super.onCreate(savedInstanceState); - // Set the content view according to the theme.. + // Set the content view according to the theme. if (darkTheme) { setContentView(R.layout.main_drawerlayout_dark); } else { diff --git a/app/src/main/java/com/stoutner/privacybrowser/fragments/AboutTabFragment.java b/app/src/main/java/com/stoutner/privacybrowser/fragments/AboutTabFragment.java index 59891f00..ffac619f 100644 --- a/app/src/main/java/com/stoutner/privacybrowser/fragments/AboutTabFragment.java +++ b/app/src/main/java/com/stoutner/privacybrowser/fragments/AboutTabFragment.java @@ -22,6 +22,8 @@ package com.stoutner.privacybrowser.fragments; import android.annotation.SuppressLint; import android.content.pm.PackageManager; import android.content.pm.Signature; +import android.graphics.ColorMatrixColorFilter; +import android.graphics.Paint; import android.os.Build; import android.os.Bundle; import android.support.v4.app.Fragment; @@ -36,6 +38,7 @@ import android.widget.TextView; import com.stoutner.privacybrowser.BuildConfig; import com.stoutner.privacybrowser.R; +import com.stoutner.privacybrowser.activities.MainWebViewActivity; import java.io.ByteArrayInputStream; import java.io.InputStream; @@ -74,9 +77,12 @@ public class AboutTabFragment extends Fragment { // Load the tabs. Tab numbers start at 0. if (tabNumber == 0) { // Load the about tab. - // Setting false at the end of inflater.inflate does not attach the inflated layout as a child of container. - // The fragment will take care of attaching the root automatically. - tabLayout = inflater.inflate(R.layout.about_tab_version, container, false); + // Inflate the layout according to the theme. Setting false at the end of inflater.inflate does not attach the inflated layout as a child of container. The fragment will take care of attaching the root automatically. + if (MainWebViewActivity.darkTheme) { + tabLayout = inflater.inflate(R.layout.about_tab_version_dark, container, false); + } else { + tabLayout = inflater.inflate(R.layout.about_tab_version_light, container, false); + } // Get handles for the `TextViews`. TextView versionNumberTextView = (TextView) tabLayout.findViewById(R.id.about_version_number); @@ -158,8 +164,17 @@ public class AboutTabFragment extends Fragment { SpannableStringBuilder webKitStringBuilder = new SpannableStringBuilder(webKitLabel + webKit); SpannableStringBuilder chromeStringBuilder = new SpannableStringBuilder(chromeLabel + chrome); - // Create a blue `ForegroundColorSpan`. We have to use the deprecated `getColor()` until API >= 23. - @SuppressWarnings("deprecation") ForegroundColorSpan blueColorSpan = new ForegroundColorSpan(getResources().getColor(R.color.blue_700)); + // Create the `blueColorSpan` variable. + ForegroundColorSpan blueColorSpan; + + // Set `blueColorSpan` according to the theme. We have to use the deprecated `getColor()` until API >= 23. + if (MainWebViewActivity.darkTheme) { + //noinspection deprecation + blueColorSpan = new ForegroundColorSpan(getResources().getColor(R.color.blue_400)); + } else { + //noinspection deprecation + blueColorSpan = new ForegroundColorSpan(getResources().getColor(R.color.blue_700)); + } // Setup the spans to display the device information in blue. `SPAN_INCLUSIVE_INCLUSIVE` allows the span to grow in either direction. brandStringBuilder.setSpan(blueColorSpan, brandLabel.length(), brandStringBuilder.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE); @@ -273,11 +288,35 @@ public class AboutTabFragment extends Fragment { // Do nothing if `PackageManager` says Privacy Browser isn't installed. } } else { // load a WebView for all the other tabs. Tab numbers start at 0. - // Setting false at the end of inflater.inflate does not attach the inflated layout as a child of container. - // The fragment will take care of attaching the root automatically. + // Setting false at the end of inflater.inflate does not attach the inflated layout as a child of container. The fragment will take care of attaching the root automatically. tabLayout = inflater.inflate(R.layout.bare_webview, container, false); + + // Get a handle for `tabWebView`. WebView tabWebView = (WebView) tabLayout; + // Filter the colors if `darkTheme` is `true`. + if (MainWebViewActivity.darkTheme) { + // Initialize `darkPaint`. + Paint darkPaint = new Paint(); + + // Setup a float array that inverts and tempers the colors (no hard whites or blacks). + float[] darkFilterFloatArray = { + -.8f, 0, 0, 0, 255, // Red. + 0, -.8f, 0, 0, 255, // Green. + 0, 0, -.8f, 0, 255, // Blue. + 0, 0, 0, .8f, 0 // Alpha. + }; + + // Set `darkPaint` to use `darkFilterFloatArray`. + darkPaint.setColorFilter(new ColorMatrixColorFilter(darkFilterFloatArray)); + + // Apply `darkPaint` to `tabWebView`. + tabWebView.setLayerType(View.LAYER_TYPE_HARDWARE, darkPaint); + } else { + // Reset `tabWebView` to use the normal colors. + tabWebView.setLayerType(View.LAYER_TYPE_HARDWARE, null); + } + switch (tabNumber) { case 1: tabWebView.loadUrl("file:///android_asset/" + getString(R.string.android_asset_path) + "/about_permissions.html"); diff --git a/app/src/main/res/layout/about_coordinatorlayout.xml b/app/src/main/res/layout/about_coordinatorlayout.xml deleted file mode 100644 index b8ddd1d8..00000000 --- a/app/src/main/res/layout/about_coordinatorlayout.xml +++ /dev/null @@ -1,74 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/app/src/main/res/layout/about_coordinatorlayout_dark.xml b/app/src/main/res/layout/about_coordinatorlayout_dark.xml new file mode 100644 index 00000000..e07db78f --- /dev/null +++ b/app/src/main/res/layout/about_coordinatorlayout_dark.xml @@ -0,0 +1,70 @@ + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/about_coordinatorlayout_light.xml b/app/src/main/res/layout/about_coordinatorlayout_light.xml new file mode 100644 index 00000000..ce665c15 --- /dev/null +++ b/app/src/main/res/layout/about_coordinatorlayout_light.xml @@ -0,0 +1,70 @@ + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/about_tab_version.xml b/app/src/main/res/layout/about_tab_version.xml deleted file mode 100644 index b64e7640..00000000 --- a/app/src/main/res/layout/about_tab_version.xml +++ /dev/null @@ -1,203 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/app/src/main/res/layout/about_tab_version_dark.xml b/app/src/main/res/layout/about_tab_version_dark.xml new file mode 100644 index 00000000..f5e206aa --- /dev/null +++ b/app/src/main/res/layout/about_tab_version_dark.xml @@ -0,0 +1,203 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/about_tab_version_light.xml b/app/src/main/res/layout/about_tab_version_light.xml new file mode 100644 index 00000000..b64e7640 --- /dev/null +++ b/app/src/main/res/layout/about_tab_version_light.xml @@ -0,0 +1,203 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/bookmarks_coordinatorlayout.xml b/app/src/main/res/layout/bookmarks_coordinatorlayout.xml index ee1e2ebc..1185cd84 100644 --- a/app/src/main/res/layout/bookmarks_coordinatorlayout.xml +++ b/app/src/main/res/layout/bookmarks_coordinatorlayout.xml @@ -38,7 +38,7 @@ android:id="@+id/bookmarks_appbarlayout" android:layout_height="wrap_content" android:layout_width="match_parent" - android:theme="@style/PrivacyBrowserAppBarOverlayLight" > + android:theme="@style/PrivacyBrowserAppBarLight" > + android:theme="@style/PrivacyBrowserAppBarWhiteText" + app:popupTheme="@style/PrivacyBrowserPopupsLight" /> + android:theme="@style/PrivacyBrowserAppBarWhiteText" + app:popupTheme="@style/PrivacyBrowserPopupsLight" /> + android:theme="@style/PrivacyBrowserAppBarLight" > + android:theme="@style/PrivacyBrowserAppBarWhiteText" + app:popupTheme="@style/PrivacyBrowserPopupsLight" /> diff --git a/app/src/main/res/layout/guide_coordinatorlayout.xml b/app/src/main/res/layout/guide_coordinatorlayout.xml index 54f39617..233da963 100644 --- a/app/src/main/res/layout/guide_coordinatorlayout.xml +++ b/app/src/main/res/layout/guide_coordinatorlayout.xml @@ -41,7 +41,7 @@ android:layout_height="wrap_content" android:layout_width="match_parent" android:background="@color/blue_700" - android:theme="@style/PrivacyBrowserAppBarOverlayLight" > + android:theme="@style/PrivacyBrowserAppBarLight" > + android:theme="@style/PrivacyBrowserAppBarWhiteText" + app:popupTheme="@style/PrivacyBrowserPopupsLight" /> + android:theme="@style/PrivacyBrowserAppBarLight" > #FFF5F5F5 #FFE0E0E0 + #FFBDBDBD #FF9E9E9E #FF212121 diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml index 5395eee0..5e76c6e4 100644 --- a/app/src/main/res/values/styles.xml +++ b/app/src/main/res/values/styles.xml @@ -36,9 +36,7 @@ @color/blue_200 true @color/blue_700 - @style/PrivacyBrowserPopupOverlayLight - @style/spinnerItemStyle - @style/spinnerDropDownItemStyle + @style/PrivacyBrowserPopupsLight @@ -48,37 +46,19 @@ @color/blue_700 - - - - - - - - - - + + + +