From 74857298f431569df1849e8ef91387cb25274095 Mon Sep 17 00:00:00 2001 From: Soren Stoutner Date: Thu, 15 Jun 2017 17:01:07 -0700 Subject: [PATCH] Refactor style code to use attrs.xml. Create a dark theme for Find on Page. --- .../activities/AboutActivity.java | 8 +- .../activities/GuideActivity.java | 8 +- .../activities/MainWebViewActivity.java | 10 +- .../fragments/AboutTabFragment.java | 8 +- .../fragments/SettingsFragment.java | 13 ++ ...t_dark.xml => about_coordinatorlayout.xml} | 8 +- .../layout/about_coordinatorlayout_light.xml | 70 ------ ...ersion_light.xml => about_tab_version.xml} | 16 +- .../res/layout/about_tab_version_dark.xml | 203 ------------------ .../main/res/layout/find_on_page_app_bar.xml | 7 +- ...t_dark.xml => guide_coordinatorlayout.xml} | 8 +- .../layout/guide_coordinatorlayout_light.xml | 70 ------ ...layout_light.xml => main_drawerlayout.xml} | 14 +- .../res/layout/main_drawerlayout_dark.xml | 102 --------- ..._header_dark.xml => navigation_header.xml} | 4 +- .../res/layout/navigation_header_light.xml | 34 --- .../attrs.xml} | 22 +- app/src/main/res/values/strings.xml | 2 +- app/src/main/res/values/styles.xml | 30 ++- 19 files changed, 92 insertions(+), 545 deletions(-) rename app/src/main/res/layout/{about_coordinatorlayout_dark.xml => about_coordinatorlayout.xml} (91%) delete mode 100644 app/src/main/res/layout/about_coordinatorlayout_light.xml rename app/src/main/res/layout/{about_tab_version_light.xml => about_tab_version.xml} (92%) delete mode 100644 app/src/main/res/layout/about_tab_version_dark.xml rename app/src/main/res/layout/{guide_coordinatorlayout_dark.xml => guide_coordinatorlayout.xml} (91%) delete mode 100644 app/src/main/res/layout/guide_coordinatorlayout_light.xml rename app/src/main/res/layout/{main_drawerlayout_light.xml => main_drawerlayout.xml} (87%) delete mode 100644 app/src/main/res/layout/main_drawerlayout_dark.xml rename app/src/main/res/layout/{navigation_header_dark.xml => navigation_header.xml} (91%) delete mode 100644 app/src/main/res/layout/navigation_header_light.xml rename app/src/main/res/{drawable/url_bar_background_transparent.xml => values/attrs.xml} (58%) 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/layout/about_coordinatorlayout_dark.xml b/app/src/main/res/layout/about_coordinatorlayout.xml similarity index 91% rename from app/src/main/res/layout/about_coordinatorlayout_dark.xml rename to app/src/main/res/layout/about_coordinatorlayout.xml index 2034eaa2..9e43e766 100644 --- a/app/src/main/res/layout/about_coordinatorlayout_dark.xml +++ b/app/src/main/res/layout/about_coordinatorlayout.xml @@ -34,20 +34,20 @@ android:layout_width="match_parent" android:orientation="vertical" > - + - + + android:theme="?attr/appBarTextTheme" /> + android:theme="?attr/tabLayoutTheme" /> 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_light.xml b/app/src/main/res/layout/about_tab_version.xml similarity index 92% rename from app/src/main/res/layout/about_tab_version_light.xml rename to app/src/main/res/layout/about_tab_version.xml index b64e7640..19922b2c 100644 --- a/app/src/main/res/layout/about_tab_version_light.xml +++ b/app/src/main/res/layout/about_tab_version.xml @@ -36,8 +36,8 @@ android:layout_width="match_parent" android:layout_height="wrap_content" > - + + Although we don't need it, we have to include `android:paddingEnd` to make lint happy. --> + android:textColor="?attr/aboutTitle" /> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ 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_dark.xml b/app/src/main/res/layout/guide_coordinatorlayout.xml similarity index 91% rename from app/src/main/res/layout/guide_coordinatorlayout_dark.xml rename to app/src/main/res/layout/guide_coordinatorlayout.xml index 2bb50ad4..885ec2e3 100644 --- a/app/src/main/res/layout/guide_coordinatorlayout_dark.xml +++ b/app/src/main/res/layout/guide_coordinatorlayout.xml @@ -34,20 +34,20 @@ android:layout_width="match_parent" android:orientation="vertical" > - + - + + android:theme="?attr/appBarTextTheme" /> + android:theme="?attr/tabLayoutTheme" /> 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_light.xml b/app/src/main/res/layout/main_drawerlayout.xml similarity index 87% rename from app/src/main/res/layout/main_drawerlayout_light.xml rename to app/src/main/res/layout/main_drawerlayout.xml index 5d483496..c138a3bf 100644 --- a/app/src/main/res/layout/main_drawerlayout_light.xml +++ b/app/src/main/res/layout/main_drawerlayout.xml @@ -25,9 +25,9 @@ android:layout_height="match_parent" android:layout_width="match_parent" > - + - + @@ -98,7 +98,7 @@ android:layout_height="match_parent" android:layout_width="wrap_content" android:layout_gravity="start" - app:headerLayout="@layout/navigation_header_light" + app:headerLayout="@layout/navigation_header" app:menu="@menu/webview_navigation_menu" - app:itemIconTint="@color/blue_800" /> + app:itemIconTint="?attr/navigationIconTintColor" /> \ 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/navigation_header_dark.xml b/app/src/main/res/layout/navigation_header.xml similarity index 91% rename from app/src/main/res/layout/navigation_header_dark.xml rename to app/src/main/res/layout/navigation_header.xml index ef7de3c5..b1229d8b 100644 --- a/app/src/main/res/layout/navigation_header_dark.xml +++ b/app/src/main/res/layout/navigation_header.xml @@ -30,5 +30,5 @@ android:paddingEnd="15dp" android:textStyle="bold" android:textSize="20sp" - android:background="@color/blue_900" - android:textColor="@color/gray_300" /> \ No newline at end of file + android:background="?attr/navigationHeaderBackground" + android:textColor="?attr/navigationHeaderTextColor" /> \ 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/drawable/url_bar_background_transparent.xml b/app/src/main/res/values/attrs.xml similarity index 58% rename from app/src/main/res/drawable/url_bar_background_transparent.xml rename to app/src/main/res/values/attrs.xml index ad27b437..0529ec55 100644 --- a/app/src/main/res/drawable/url_bar_background_transparent.xml +++ b/app/src/main/res/values/attrs.xml @@ -18,13 +18,19 @@ You should have received a copy of the GNU General Public License along with Privacy Browser. If not, see . --> - + + + + - + + - - \ No newline at end of file + + + + + + + + \ 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"`. --> -- 2.45.2