[Android] DayNight mode

Geoffrey Métais git at videolan.org
Thu Oct 27 14:47:41 CEST 2016


vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Thu Oct 27 14:47:28 2016 +0200| [369ad9dc0e5847ac34ba6120d72b8e93a7942283] | committer: Geoffrey Métais

DayNight mode

> https://code.videolan.org/videolan/vlc-android/commit/369ad9dc0e5847ac34ba6120d72b8e93a7942283
---

 vlc-android/res/values-night/styles.xml                        |  5 +++++
 vlc-android/res/values/strings.xml                             |  2 ++
 vlc-android/res/xml/preferences_ui.xml                         | 10 +++++++++-
 .../src/org/videolan/vlc/gui/AudioPlayerContainerActivity.java |  6 +++++-
 .../src/org/videolan/vlc/gui/preferences/PreferencesUi.java    |  6 ++++++
 5 files changed, 27 insertions(+), 2 deletions(-)

diff --git a/vlc-android/res/values-night/styles.xml b/vlc-android/res/values-night/styles.xml
new file mode 100644
index 0000000..2c9bf45
--- /dev/null
+++ b/vlc-android/res/values-night/styles.xml
@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="utf-8"?>
+<resources>
+    <style name="Theme.VLC"
+        parent="Theme.VLC.Black" />
+</resources>
\ No newline at end of file
diff --git a/vlc-android/res/values/strings.xml b/vlc-android/res/values/strings.xml
index 6067484..9eb4977 100644
--- a/vlc-android/res/values/strings.xml
+++ b/vlc-android/res/values/strings.xml
@@ -264,6 +264,8 @@
     <string name="enable_black_theme">Enable the black theme</string>
     <string name="enable_black_theme_summary">Change the interface colours for better comfort in low light environments.</string>
     <string name="subtitle_text_encoding">Subtitle text encoding</string>
+    <string name="daynight_title">DayNight mode</string>
+    <string name="daynight_summary">Automatically switch to night mode at appropriate time</string>
 
     <string name="extra_prefs_category">Extra settings</string>
 
diff --git a/vlc-android/res/xml/preferences_ui.xml b/vlc-android/res/xml/preferences_ui.xml
index 0a65eaa..c4847e0 100644
--- a/vlc-android/res/xml/preferences_ui.xml
+++ b/vlc-android/res/xml/preferences_ui.xml
@@ -8,7 +8,15 @@
         android:defaultValue="false"
         android:key="enable_black_theme"
         android:summary="@string/enable_black_theme_summary"
-        android:title="@string/enable_black_theme" />
+        android:title="@string/enable_black_theme"
+        android:disableDependentsState="true" />
+
+    <android.support.v7.preference.SwitchPreferenceCompat
+        android:defaultValue="false"
+        android:key="daynight"
+        android:dependency="enable_black_theme"
+        android:summary="@string/daynight_summary"
+        android:title="@string/daynight_title" />
 
     <CheckBoxPreference
         android:key="tv_ui"
diff --git a/vlc-android/src/org/videolan/vlc/gui/AudioPlayerContainerActivity.java b/vlc-android/src/org/videolan/vlc/gui/AudioPlayerContainerActivity.java
index c5e2102..4b8526f 100644
--- a/vlc-android/src/org/videolan/vlc/gui/AudioPlayerContainerActivity.java
+++ b/vlc-android/src/org/videolan/vlc/gui/AudioPlayerContainerActivity.java
@@ -36,6 +36,7 @@ import android.support.v4.app.Fragment;
 import android.support.v4.app.FragmentManager;
 import android.support.v7.app.ActionBar;
 import android.support.v7.app.AppCompatActivity;
+import android.support.v7.app.AppCompatDelegate;
 import android.support.v7.widget.Toolbar;
 import android.view.LayoutInflater;
 import android.view.View;
@@ -55,7 +56,6 @@ import org.videolan.vlc.interfaces.IRefreshable;
 import org.videolan.vlc.media.MediaLibrary;
 import org.videolan.vlc.media.MediaUtils;
 import org.videolan.vlc.util.Strings;
-import org.videolan.vlc.util.Util;
 import org.videolan.vlc.util.WeakHandler;
 
 public class AudioPlayerContainerActivity extends AppCompatActivity implements PlaybackService.Client.Callback  {
@@ -63,6 +63,10 @@ public class AudioPlayerContainerActivity extends AppCompatActivity implements P
     public static final String TAG = "VLC/AudioPlayerContainerActivity";
     public static final String ACTION_SHOW_PLAYER = Strings.buildPkgString("gui.ShowPlayer");
 
+    static {
+        AppCompatDelegate.setDefaultNightMode(PreferenceManager.getDefaultSharedPreferences(VLCApplication.getAppContext()).getBoolean("daynight", false) ? AppCompatDelegate.MODE_NIGHT_AUTO : AppCompatDelegate.MODE_NIGHT_NO);
+    }
+
     protected static final String ID_VIDEO = "video";
     protected static final String ID_AUDIO = "audio";
     protected static final String ID_NETWORK = "network";
diff --git a/vlc-android/src/org/videolan/vlc/gui/preferences/PreferencesUi.java b/vlc-android/src/org/videolan/vlc/gui/preferences/PreferencesUi.java
index ab67472..cce5256 100644
--- a/vlc-android/src/org/videolan/vlc/gui/preferences/PreferencesUi.java
+++ b/vlc-android/src/org/videolan/vlc/gui/preferences/PreferencesUi.java
@@ -25,10 +25,13 @@ package org.videolan.vlc.gui.preferences;
 
 import android.content.SharedPreferences;
 import android.os.Bundle;
+import android.support.v7.app.AppCompatDelegate;
 import android.support.v7.preference.Preference;
+import android.support.v7.preference.SwitchPreferenceCompat;
 
 import org.videolan.libvlc.util.AndroidUtil;
 import org.videolan.vlc.R;
+import org.videolan.vlc.VLCApplication;
 import org.videolan.vlc.gui.helpers.UiTools;
 
 public class PreferencesUi extends BasePreferenceFragment implements SharedPreferences.OnSharedPreferenceChangeListener {
@@ -73,6 +76,9 @@ public class PreferencesUi extends BasePreferenceFragment implements SharedPrefe
             case "enable_black_theme":
                 ((PreferencesActivity) getActivity()).exitAndRescan();
                 return true;
+            case "daynight":
+                AppCompatDelegate.setDefaultNightMode(((SwitchPreferenceCompat)preference).isChecked() ? AppCompatDelegate.MODE_NIGHT_AUTO : AppCompatDelegate.MODE_NIGHT_NO);
+                return true;
         }
         return super.onPreferenceTreeClick(preference);
     }



More information about the Android mailing list