[Android] Create BaseActivity for theme management

Geoffrey Métais git at videolan.org
Tue Mar 14 18:33:59 CET 2017


vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Tue Mar 14 10:44:19 2017 +0100| [59c18fe9b0c60562c8b1589991ea24469e4f872a] | committer: Geoffrey Métais

Create BaseActivity for theme management

> https://code.videolan.org/videolan/vlc-android/commit/59c18fe9b0c60562c8b1589991ea24469e4f872a
---

 .../vlc/gui/AudioPlayerContainerActivity.java      | 18 +----------
 .../src/org/videolan/vlc/gui/BaseActivity.java     | 37 ++++++++++++++++++++++
 .../src/org/videolan/vlc/gui/DialogActivity.java   | 15 +--------
 3 files changed, 39 insertions(+), 31 deletions(-)

diff --git a/vlc-android/src/org/videolan/vlc/gui/AudioPlayerContainerActivity.java b/vlc-android/src/org/videolan/vlc/gui/AudioPlayerContainerActivity.java
index 58a323f..f676b7c 100644
--- a/vlc-android/src/org/videolan/vlc/gui/AudioPlayerContainerActivity.java
+++ b/vlc-android/src/org/videolan/vlc/gui/AudioPlayerContainerActivity.java
@@ -64,15 +64,11 @@ import org.videolan.vlc.media.MediaUtils;
 import org.videolan.vlc.util.Strings;
 import org.videolan.vlc.util.WeakHandler;
 
-public class AudioPlayerContainerActivity extends AppCompatActivity implements PlaybackService.Client.Callback, PlaybackService.Callback {
+public class AudioPlayerContainerActivity extends BaseActivity implements PlaybackService.Client.Callback, PlaybackService.Callback {
 
     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";
@@ -86,7 +82,6 @@ public class AudioPlayerContainerActivity extends AppCompatActivity implements P
     protected Toolbar mToolbar;
     protected AudioPlayer mAudioPlayer;
     private FrameLayout mAudioPlayerContainer;
-    protected SharedPreferences mSettings;
     private final PlaybackServiceActivity.Helper mHelper = new PlaybackServiceActivity.Helper(this, this);
     protected PlaybackService mService;
     protected BottomSheetBehavior mBottomSheetBehavior;
@@ -96,10 +91,6 @@ public class AudioPlayerContainerActivity extends AppCompatActivity implements P
 
     @Override
     protected void onCreate(Bundle savedInstanceState) {
-        /* Get settings */
-        mSettings = PreferenceManager.getDefaultSharedPreferences(this);
-        /* Theme must be applied before super.onCreate */
-        applyTheme();
 
         MediaUtils.updateSubsDownloaderActivity(this);
 
@@ -178,13 +169,6 @@ public class AudioPlayerContainerActivity extends AppCompatActivity implements P
         super.onBackPressed();
     }
 
-    private void applyTheme() {
-        boolean enableBlackTheme = mSettings.getBoolean("enable_black_theme", false);
-        if (VLCApplication.showTvUi() || enableBlackTheme) {
-            setTheme(R.style.Theme_VLC_Black);
-        }
-    }
-
     public void updateLib() {
         if (mPreventRescan) {
             mPreventRescan = false;
diff --git a/vlc-android/src/org/videolan/vlc/gui/BaseActivity.java b/vlc-android/src/org/videolan/vlc/gui/BaseActivity.java
new file mode 100644
index 0000000..a73e12a
--- /dev/null
+++ b/vlc-android/src/org/videolan/vlc/gui/BaseActivity.java
@@ -0,0 +1,37 @@
+package org.videolan.vlc.gui;
+
+import android.content.SharedPreferences;
+import android.os.Bundle;
+import android.preference.PreferenceManager;
+import android.support.annotation.Nullable;
+import android.support.v7.app.AppCompatActivity;
+import android.support.v7.app.AppCompatDelegate;
+
+import org.videolan.vlc.R;
+import org.videolan.vlc.VLCApplication;
+
+
+public class BaseActivity extends AppCompatActivity {
+
+    static {
+        AppCompatDelegate.setDefaultNightMode(PreferenceManager.getDefaultSharedPreferences(VLCApplication.getAppContext()).getBoolean("daynight", false) ? AppCompatDelegate.MODE_NIGHT_AUTO : AppCompatDelegate.MODE_NIGHT_NO);
+    }
+
+    protected SharedPreferences mSettings;
+
+    @Override
+    protected void onCreate(@Nullable Bundle savedInstanceState) {
+        /* Get settings */
+        mSettings = PreferenceManager.getDefaultSharedPreferences(this);
+        /* Theme must be applied before super.onCreate */
+        applyTheme();
+        super.onCreate(savedInstanceState);
+    }
+
+    private void applyTheme() {
+        boolean enableBlackTheme = mSettings.getBoolean("enable_black_theme", false);
+        if (VLCApplication.showTvUi() || enableBlackTheme) {
+            setTheme(R.style.Theme_VLC_Black);
+        }
+    }
+}
diff --git a/vlc-android/src/org/videolan/vlc/gui/DialogActivity.java b/vlc-android/src/org/videolan/vlc/gui/DialogActivity.java
index e9ac628..5cb5e29 100644
--- a/vlc-android/src/org/videolan/vlc/gui/DialogActivity.java
+++ b/vlc-android/src/org/videolan/vlc/gui/DialogActivity.java
@@ -24,24 +24,15 @@
 package org.videolan.vlc.gui;
 
 import android.os.Bundle;
-import android.preference.PreferenceManager;
 import android.support.v4.app.FragmentManager;
-import android.support.v7.app.AppCompatActivity;
-import android.support.v7.app.AppCompatDelegate;
 
-import org.videolan.vlc.R;
-import org.videolan.vlc.VLCApplication;
 import org.videolan.vlc.gui.dialogs.VlcDialog;
 import org.videolan.vlc.gui.dialogs.VlcLoginDialog;
 import org.videolan.vlc.gui.dialogs.VlcProgressDialog;
 import org.videolan.vlc.gui.dialogs.VlcQuestionDialog;
 import org.videolan.vlc.gui.network.MRLPanelFragment;
 
-public class DialogActivity extends AppCompatActivity {
-
-    static {
-        AppCompatDelegate.setDefaultNightMode(PreferenceManager.getDefaultSharedPreferences(VLCApplication.getAppContext()).getBoolean("daynight", false) ? AppCompatDelegate.MODE_NIGHT_AUTO : AppCompatDelegate.MODE_NIGHT_NO);
-    }
+public class DialogActivity extends BaseActivity {
 
     public static final String KEY_LOGIN = "LoginDialog";
     public static final String KEY_QUESTION = "QuestionDialog";
@@ -51,10 +42,6 @@ public class DialogActivity extends AppCompatActivity {
     @Override
     protected void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
-        boolean enableBlackTheme = PreferenceManager.getDefaultSharedPreferences(this).getBoolean("enable_black_theme", false);
-        if (VLCApplication.showTvUi() || enableBlackTheme) {
-            setTheme(R.style.Theme_VLC_Black);
-        }
         String key = getIntent().getAction();
         switch (key) {
             case KEY_LOGIN:



More information about the Android mailing list