[Android] android: apply theme to preference activty

Tse, Kit Yam git at videolan.org
Fri Mar 6 15:15:44 CET 2015


vlc-ports/android | branch: master | Tse, Kit Yam <me at kytse.com> | Fri Mar  6 18:03:43 2015 +0800| [fe83a14e9374f29876150a7b9cc709ca40bbf8ef] | committer: Geoffrey Métais

android: apply theme to preference activty

This patch fix one of the problems mentioned in #12828, the theme won't be
applied on preference activity.

Signed-off-by: Geoffrey Métais <geoffrey.metais at gmail.com>

> http://git.videolan.org/gitweb.cgi/vlc-ports/android.git/?a=commit;h=fe83a14e9374f29876150a7b9cc709ca40bbf8ef
---

 .../org/videolan/vlc/gui/PreferencesActivity.java  |   20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

diff --git a/vlc-android/src/org/videolan/vlc/gui/PreferencesActivity.java b/vlc-android/src/org/videolan/vlc/gui/PreferencesActivity.java
index 91d078b..ae713f2 100644
--- a/vlc-android/src/org/videolan/vlc/gui/PreferencesActivity.java
+++ b/vlc-android/src/org/videolan/vlc/gui/PreferencesActivity.java
@@ -34,6 +34,7 @@ import org.videolan.vlc.util.Logcat;
 import org.videolan.vlc.util.Util;
 import org.videolan.vlc.util.VLCInstance;
 
+import android.annotation.TargetApi;
 import android.app.AlertDialog;
 import android.app.Dialog;
 import android.content.Context;
@@ -81,6 +82,9 @@ public class PreferencesActivity extends PreferenceActivity implements OnSharedP
 
     @Override
     protected void onCreate(Bundle savedInstanceState) {
+        /* Theme must be applied before super.onCreate */
+        applyTheme();
+
         super.onCreate(savedInstanceState);
         addPreferencesFromResource(R.xml.preferences);
 
@@ -146,6 +150,9 @@ public class PreferencesActivity extends PreferenceActivity implements OnSharedP
                     @Override
                     public boolean onPreferenceClick(Preference preference) {
                         setResult(RESULT_RESTART);
+                        Intent intent = getIntent();
+                        finish();
+                        startActivity(intent);
                         return true;
                     }
                 });
@@ -276,6 +283,19 @@ public class PreferencesActivity extends PreferenceActivity implements OnSharedP
         sharedPrefs.registerOnSharedPreferenceChangeListener(this);
     }
 
+    @TargetApi(Build.VERSION_CODES.LOLLIPOP)
+    private void applyTheme() {
+        SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(this);
+        boolean enableBlackTheme = pref.getBoolean("enable_black_theme", false);
+        if (enableBlackTheme) {
+            setTheme(R.style.Theme_VLC_Black);
+            //We need to manually change statusbar color, otherwise, it remains orange.
+            if (LibVlcUtil.isLolliPopOrLater()) {
+                getWindow().setStatusBarColor(Color.DKGRAY);
+            }
+        }
+    }
+
     @Override
     protected void onPostCreate(Bundle savedInstanceState) {
         super.onPostCreate(savedInstanceState);



More information about the Android mailing list