From 730844b3cc343a6d7407ba06280b18f987eda3f6 Mon Sep 17 00:00:00 2001 From: M66B Date: Sat, 2 Jan 2016 16:38:24 +0100 Subject: [PATCH] Added theme selection --- app/src/main/AndroidManifest.xml | 2 +- .../eu/faircode/netguard/ActivityMain.java | 8 ++-- .../eu/faircode/netguard/ActivityPro.java | 4 +- .../faircode/netguard/ActivitySettings.java | 32 +++++++++----- .../java/eu/faircode/netguard/Receiver.java | 2 +- .../eu/faircode/netguard/SinkholeService.java | 27 +++++++++--- .../main/java/eu/faircode/netguard/Util.java | 10 +++++ app/src/main/res/values/colors.xml | 20 ++++++--- app/src/main/res/values/strings.xml | 11 +++++ app/src/main/res/values/styles.xml | 44 ++++++++++++++----- app/src/main/res/xml/preferences.xml | 5 +++ 11 files changed, 121 insertions(+), 44 deletions(-) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 9251a1c7..0e6fb40b 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -26,7 +26,7 @@ android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:supportsRtl="true" - android:theme="@style/AppTheme"> + android:theme="@style/AppThemeTeal"> ssid = prefs.getStringSet(name, new HashSet()); if (ssid.size() > 0) @@ -725,7 +735,7 @@ public class ActivitySettings extends AppCompatActivity implements SharedPrefere else { // Pro features if (current == application) { - if ("dark_theme".equals(key)) { + if ("theme".equals(key)) { if (!IAB.isPurchased(ActivityPro.SKU_THEME, context)) return; } else if ("show_stats".equals(key)) { diff --git a/app/src/main/java/eu/faircode/netguard/Receiver.java b/app/src/main/java/eu/faircode/netguard/Receiver.java index 0125f4b3..2ec489b8 100644 --- a/app/src/main/java/eu/faircode/netguard/Receiver.java +++ b/app/src/main/java/eu/faircode/netguard/Receiver.java @@ -116,8 +116,8 @@ public class Receiver extends BroadcastReceiver { main.putExtra(ActivityMain.EXTRA_SEARCH, name); PendingIntent pi = PendingIntent.getActivity(context, 999, main, PendingIntent.FLAG_UPDATE_CURRENT); + Util.setTheme(context); TypedValue tv = new TypedValue(); - context.setTheme(prefs.getBoolean("dark_theme", false) ? R.style.AppThemeDark : R.style.AppTheme); context.getTheme().resolveAttribute(R.attr.colorPrimary, tv, true); NotificationCompat.Builder notification = new NotificationCompat.Builder(context) .setSmallIcon(R.drawable.ic_security_white_24dp) diff --git a/app/src/main/java/eu/faircode/netguard/SinkholeService.java b/app/src/main/java/eu/faircode/netguard/SinkholeService.java index df3f2f90..f4ac8bfe 100644 --- a/app/src/main/java/eu/faircode/netguard/SinkholeService.java +++ b/app/src/main/java/eu/faircode/netguard/SinkholeService.java @@ -105,7 +105,7 @@ public class SinkholeService extends VpnService { private static final int MSG_STATS_STOP = 2; private static final int MSG_STATS_UPDATE = 3; - public enum Command {start, reload, stop, stats, set} + public enum Command {start, reload, stop, stats, set, theme} private static volatile PowerManager.WakeLock wlInstance = null; @@ -245,6 +245,10 @@ public class SinkholeService extends VpnService { case set: set(intent); break; + + case theme: + setTheme(intent); + break; } // Update main view @@ -500,6 +504,12 @@ public class SinkholeService extends VpnService { } } + private void setTheme(Intent intent) { + Util.setTheme(this); + stopForeground(true); + startForeground(NOTIFY_FOREGROUND, getForegroundNotification(0, 0)); + } + private ParcelFileDescriptor startVPN() { SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); @@ -800,11 +810,9 @@ public class SinkholeService extends VpnService { @Override public void onCreate() { - super.onCreate(); Log.i(TAG, "Create"); - - SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); - setTheme(prefs.getBoolean("dark_theme", false) ? R.style.AppThemeDark : R.style.AppTheme); + Util.setTheme(this); + super.onCreate(); HandlerThread thread = new HandlerThread(getString(R.string.app_name) + " handler"); thread.start(); @@ -1003,6 +1011,15 @@ public class SinkholeService extends VpnService { context.startService(intent); } + public static void setTheme(Context context) { + SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); + if (prefs.getBoolean("enabled", false)) { + Intent intent = new Intent(context, SinkholeService.class); + intent.putExtra(EXTRA_COMMAND, Command.theme); + context.startService(intent); + } + } + public static void reloadStats(String reason, Context context) { Intent intent = new Intent(context, SinkholeService.class); intent.putExtra(EXTRA_COMMAND, Command.stats); diff --git a/app/src/main/java/eu/faircode/netguard/Util.java b/app/src/main/java/eu/faircode/netguard/Util.java index 42375592..733bd6cd 100644 --- a/app/src/main/java/eu/faircode/netguard/Util.java +++ b/app/src/main/java/eu/faircode/netguard/Util.java @@ -311,6 +311,16 @@ public class Util { } } + public static void setTheme(Context context) { + SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); + boolean dark = prefs.getBoolean("dark_theme", false); + String theme = prefs.getString("theme", "teal"); + if (theme.equals("teal")) + context.setTheme(dark ? R.style.AppThemeTealDark : R.style.AppThemeTeal); + else if (theme.equals("blue")) + context.setTheme(dark ? R.style.AppThemeBlueDark : R.style.AppThemeBlue); + } + public static int dips2pixels(int dips, Context context) { return Math.round(dips * context.getResources().getDisplayMetrics().density + 0.5f); } diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml index 59131c68..f98a8682 100644 --- a/app/src/main/res/values/colors.xml +++ b/app/src/main/res/values/colors.xml @@ -1,15 +1,21 @@ - #009688 + #009688 - #00796B + #00796B - #FF5722 + #FF5722 - #009688 - #FF5722 + #009688 + #FF5722 - #FF5722 - #009688 + #0066CC + #003366 + #FF3333 + #0066CC + #FF3333 + + #FF0000 + #0000FF diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 4bfdd09f..23e91658 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -34,6 +34,7 @@ These issues are caused by bugs in Android, or in the software provided by the m Manage system applications Auto enable after %1$s minutes Delay screen off %1$s minutes + Theme: %1$s Use dark theme Wi-Fi home networks: %1$s Handle metered Wi-Fi networks @@ -107,5 +108,15 @@ Since NetGuard has no internet permission, you know your internet traffic is not Challenge Response + + Teal/Orange + Blue/Red + + + + teal + blue + + ef46f813d2c8a064d72c936b9b96d1cccc989378 diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml index 4135f759..795cd3cf 100644 --- a/app/src/main/res/values/styles.xml +++ b/app/src/main/res/values/styles.xml @@ -3,22 +3,42 @@ - - + + + + diff --git a/app/src/main/res/xml/preferences.xml b/app/src/main/res/xml/preferences.xml index 675a067d..be8303bd 100644 --- a/app/src/main/res/xml/preferences.xml +++ b/app/src/main/res/xml/preferences.xml @@ -42,6 +42,11 @@ android:inputType="number" android:key="screen_delay" android:summary="@string/summary_delay" /> +