From: Soren Stoutner Date: Fri, 16 Jun 2017 00:01:07 +0000 (-0700) Subject: Refactor style code to use attrs.xml. Create a dark theme for Find on Page. X-Git-Tag: v2.4~7 X-Git-Url: https://gitweb.stoutner.com/?p=PrivacyBrowserAndroid.git;a=commitdiff_plain;h=74857298f431569df1849e8ef91387cb25274095 Refactor style code to use attrs.xml. Create a dark theme for Find on Page. --- 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 8244774e..c2045215 100644 --- a/app/src/main/java/com/stoutner/privacybrowser/activities/AboutActivity.java +++ b/app/src/main/java/com/stoutner/privacybrowser/activities/AboutActivity.java @@ -45,12 +45,8 @@ public class AboutActivity extends AppCompatActivity { // Run the default commands. super.onCreate(savedInstanceState); - // Set the content view according to the theme. - if (MainWebViewActivity.darkTheme) { - setContentView(R.layout.about_coordinatorlayout_dark); - } else { - setContentView(R.layout.about_coordinatorlayout_light); - } + // Set the content view. + setContentView(R.layout.about_coordinatorlayout); // 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); diff --git a/app/src/main/java/com/stoutner/privacybrowser/activities/GuideActivity.java b/app/src/main/java/com/stoutner/privacybrowser/activities/GuideActivity.java index a8728fe6..3bde5a16 100644 --- a/app/src/main/java/com/stoutner/privacybrowser/activities/GuideActivity.java +++ b/app/src/main/java/com/stoutner/privacybrowser/activities/GuideActivity.java @@ -45,12 +45,8 @@ public class GuideActivity extends AppCompatActivity { // Run the default commands. super.onCreate(savedInstanceState); - // Set the content view according to the theme. - if (MainWebViewActivity.darkTheme) { - setContentView(R.layout.guide_coordinatorlayout_dark); - } else { - setContentView(R.layout.guide_coordinatorlayout_light); - } + // Set the content view. + setContentView(R.layout.guide_coordinatorlayout); // We need to use `SupportActionBar` from `android.support.v7.app.ActionBar` until the minimum API is >= 21. Toolbar guideAppBar = (Toolbar) findViewById(R.id.guide_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 0012898e..02f3742f 100644 --- a/app/src/main/java/com/stoutner/privacybrowser/activities/MainWebViewActivity.java +++ b/app/src/main/java/com/stoutner/privacybrowser/activities/MainWebViewActivity.java @@ -317,12 +317,8 @@ public class MainWebViewActivity extends AppCompatActivity implements Navigation // Run the default commands. super.onCreate(savedInstanceState); - // Set the content view according to the theme. - if (darkTheme) { - setContentView(R.layout.main_drawerlayout_dark); - } else { - setContentView(R.layout.main_drawerlayout_light); - } + // Set the content view. + setContentView(R.layout.main_drawerlayout); // Get a handle for `inputMethodManager`. inputMethodManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); @@ -2525,7 +2521,7 @@ public class MainWebViewActivity extends AppCompatActivity implements Navigation } // Set a transparent background on `urlTextBox`. We have to use the deprecated `.getDrawable()` until the minimum API >= 21. - urlAppBarRelativeLayout.setBackgroundDrawable(getResources().getDrawable(R.drawable.url_bar_background_transparent)); + urlAppBarRelativeLayout.setBackgroundDrawable(getResources().getDrawable(R.color.transparent)); } // Close `domainsDatabaseHelper`. 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 ffac619f..c7d045e7 100644 --- a/app/src/main/java/com/stoutner/privacybrowser/fragments/AboutTabFragment.java +++ b/app/src/main/java/com/stoutner/privacybrowser/fragments/AboutTabFragment.java @@ -77,12 +77,8 @@ public class AboutTabFragment extends Fragment { // Load the tabs. Tab numbers start at 0. if (tabNumber == 0) { // Load the about tab. - // 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); - } + // 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); // Get handles for the `TextViews`. TextView versionNumberTextView = (TextView) tabLayout.findViewById(R.id.about_version_number); diff --git a/app/src/main/java/com/stoutner/privacybrowser/fragments/SettingsFragment.java b/app/src/main/java/com/stoutner/privacybrowser/fragments/SettingsFragment.java index 14d39bd9..340e4552 100644 --- a/app/src/main/java/com/stoutner/privacybrowser/fragments/SettingsFragment.java +++ b/app/src/main/java/com/stoutner/privacybrowser/fragments/SettingsFragment.java @@ -20,6 +20,7 @@ package com.stoutner.privacybrowser.fragments; import android.annotation.SuppressLint; +import android.content.Intent; import android.content.SharedPreferences; import android.os.Build; import android.os.Bundle; @@ -792,6 +793,18 @@ public class SettingsFragment extends PreferenceFragment { } else { darkThemePreference.setIcon(R.drawable.theme_light); } + + // Create an `Intent` to restart Privacy Browser. + Intent intent = getActivity().getParentActivityIntent(); + + // Assert that `intent` is not `null` to remove the lint error below. + assert intent != null; + + // `Intent.FLAG_ACTIVITY_CLEAR_TASK` removes all activities from the stack. It requires `Intent.FLAG_ACTIVITY_NEW_TASK`. + intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK); + + // Make it so. + startActivity(intent); break; case "display_webpage_images": diff --git a/app/src/main/res/drawable/url_bar_background_transparent.xml b/app/src/main/res/drawable/url_bar_background_transparent.xml deleted file mode 100644 index ad27b437..00000000 --- a/app/src/main/res/drawable/url_bar_background_transparent.xml +++ /dev/null @@ -1,30 +0,0 @@ - - - - - - - - - - \ No newline at end of file diff --git a/app/src/main/res/layout/about_coordinatorlayout.xml b/app/src/main/res/layout/about_coordinatorlayout.xml new file mode 100644 index 00000000..9e43e766 --- /dev/null +++ b/app/src/main/res/layout/about_coordinatorlayout.xml @@ -0,0 +1,70 @@ + + + + + + + + + + + + + + + + + + + + + + + + \ 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 deleted file mode 100644 index 2034eaa2..00000000 --- a/app/src/main/res/layout/about_coordinatorlayout_dark.xml +++ /dev/null @@ -1,70 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - \ 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 deleted file mode 100644 index 0038ed16..00000000 --- a/app/src/main/res/layout/about_coordinatorlayout_light.xml +++ /dev/null @@ -1,70 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - \ 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 new file mode 100644 index 00000000..19922b2c --- /dev/null +++ b/app/src/main/res/layout/about_tab_version.xml @@ -0,0 +1,203 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ 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 deleted file mode 100644 index f5e206aa..00000000 --- a/app/src/main/res/layout/about_tab_version_dark.xml +++ /dev/null @@ -1,203 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ 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 deleted file mode 100644 index b64e7640..00000000 --- a/app/src/main/res/layout/about_tab_version_light.xml +++ /dev/null @@ -1,203 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/app/src/main/res/layout/find_on_page_app_bar.xml b/app/src/main/res/layout/find_on_page_app_bar.xml index 30b5ae0a..d657edcb 100644 --- a/app/src/main/res/layout/find_on_page_app_bar.xml +++ b/app/src/main/res/layout/find_on_page_app_bar.xml @@ -57,8 +57,9 @@ android:layout_marginStart="4dp" android:layout_marginEnd="4dp" android:layout_gravity="center_vertical" + android:tint="?attr/findOnPageIconTintColor" android:contentDescription="@string/previous" - android:onClick="findPreviousOnPage"/> + android:onClick="findPreviousOnPage" /> + android:onClick="findNextOnPage" /> \ No newline at end of file diff --git a/app/src/main/res/layout/guide_coordinatorlayout.xml b/app/src/main/res/layout/guide_coordinatorlayout.xml new file mode 100644 index 00000000..885ec2e3 --- /dev/null +++ b/app/src/main/res/layout/guide_coordinatorlayout.xml @@ -0,0 +1,70 @@ + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/guide_coordinatorlayout_dark.xml b/app/src/main/res/layout/guide_coordinatorlayout_dark.xml deleted file mode 100644 index 2bb50ad4..00000000 --- a/app/src/main/res/layout/guide_coordinatorlayout_dark.xml +++ /dev/null @@ -1,70 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/app/src/main/res/layout/guide_coordinatorlayout_light.xml b/app/src/main/res/layout/guide_coordinatorlayout_light.xml deleted file mode 100644 index 506985db..00000000 --- a/app/src/main/res/layout/guide_coordinatorlayout_light.xml +++ /dev/null @@ -1,70 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/app/src/main/res/layout/main_drawerlayout.xml b/app/src/main/res/layout/main_drawerlayout.xml new file mode 100644 index 00000000..c138a3bf --- /dev/null +++ b/app/src/main/res/layout/main_drawerlayout.xml @@ -0,0 +1,104 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/main_drawerlayout_dark.xml b/app/src/main/res/layout/main_drawerlayout_dark.xml deleted file mode 100644 index 54e8bf63..00000000 --- a/app/src/main/res/layout/main_drawerlayout_dark.xml +++ /dev/null @@ -1,102 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/app/src/main/res/layout/main_drawerlayout_light.xml b/app/src/main/res/layout/main_drawerlayout_light.xml deleted file mode 100644 index 5d483496..00000000 --- a/app/src/main/res/layout/main_drawerlayout_light.xml +++ /dev/null @@ -1,104 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/app/src/main/res/layout/navigation_header.xml b/app/src/main/res/layout/navigation_header.xml new file mode 100644 index 00000000..b1229d8b --- /dev/null +++ b/app/src/main/res/layout/navigation_header.xml @@ -0,0 +1,34 @@ + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/navigation_header_dark.xml b/app/src/main/res/layout/navigation_header_dark.xml deleted file mode 100644 index ef7de3c5..00000000 --- a/app/src/main/res/layout/navigation_header_dark.xml +++ /dev/null @@ -1,34 +0,0 @@ - - - - - \ No newline at end of file diff --git a/app/src/main/res/layout/navigation_header_light.xml b/app/src/main/res/layout/navigation_header_light.xml deleted file mode 100644 index 38751010..00000000 --- a/app/src/main/res/layout/navigation_header_light.xml +++ /dev/null @@ -1,34 +0,0 @@ - - - - - \ No newline at end of file diff --git a/app/src/main/res/values/attrs.xml b/app/src/main/res/values/attrs.xml new file mode 100644 index 00000000..0529ec55 --- /dev/null +++ b/app/src/main/res/values/attrs.xml @@ -0,0 +1,36 @@ + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 6b38aed8..1c6e1eea 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -348,7 +348,7 @@ Display additional app bar icons Display icons for toggling cookies, DOM storage, and form data in the app bar if there is room. Dark theme - Privacy Browser must be restarted for the new theme to take effect. + Changing the theme will restart Privacy Browser. Display webpage images Disable to conserve bandwidth. diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml index b9706c69..8832ee83 100644 --- a/app/src/main/res/values/styles.xml +++ b/app/src/main/res/values/styles.xml @@ -22,21 +22,31 @@ + When it is specified the root layout should include `android:fitsSystemWindows="true"`. --> - + @@ -69,16 +79,26 @@ + When it is specified the root layout should include `android:fitsSystemWindows="true"`. -->