[Android] VLCOptions: use a context instead of a shared preferences

Thomas Guillem git at videolan.org
Wed Jul 1 15:14:32 CEST 2015


vlc-ports/android | branch: master | Thomas Guillem <thomas at gllm.fr> | Wed Jul  1 09:45:18 2015 +0200| [c48376596d42274db0e0bd793c2c8521be75f7e7] | committer: Thomas Guillem

VLCOptions: use a context instead of a shared preferences

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

 .../src/org/videolan/vlc/gui/PreferencesActivity.java        |    2 +-
 .../src/org/videolan/vlc/gui/video/VideoPlayerActivity.java  |    2 +-
 vlc-android/src/org/videolan/vlc/util/VLCInstance.java       |   10 +++-------
 vlc-android/src/org/videolan/vlc/util/VLCOptions.java        |    4 +++-
 4 files changed, 8 insertions(+), 10 deletions(-)

diff --git a/vlc-android/src/org/videolan/vlc/gui/PreferencesActivity.java b/vlc-android/src/org/videolan/vlc/gui/PreferencesActivity.java
index 426c1a5..dec15d1 100644
--- a/vlc-android/src/org/videolan/vlc/gui/PreferencesActivity.java
+++ b/vlc-android/src/org/videolan/vlc/gui/PreferencesActivity.java
@@ -365,7 +365,7 @@ public class PreferencesActivity extends PreferenceActivity implements OnSharedP
                 || key.equalsIgnoreCase("enable_verbose_mode")
                 || key.equalsIgnoreCase("network_caching")
                 || key.equalsIgnoreCase("dev_hardware_decoder")) {
-            VLCInstance.restart(sharedPreferences);
+            VLCInstance.restart(this);
             if (mService != null)
                 mService.restartMediaPlayer();
         }
diff --git a/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.java b/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.java
index ac5de7b..3580898 100644
--- a/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.java
+++ b/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.java
@@ -2563,7 +2563,7 @@ public class VideoPlayerActivity extends AppCompatActivity implements IVLCVout.C
             mService.stop();
             if (VLCOptions.isAudioHdmiEnabled() != mHasHdmiAudio) {
                 VLCOptions.setAudioHdmiEnabled(mHasHdmiAudio);
-                VLCInstance.restart(PreferenceManager.getDefaultSharedPreferences(this));
+                VLCInstance.restart(this);
                 mService.restartMediaPlayer();
             }
             if (savedIndexPosition == -1 && mUri != null) {
diff --git a/vlc-android/src/org/videolan/vlc/util/VLCInstance.java b/vlc-android/src/org/videolan/vlc/util/VLCInstance.java
index d365dc7..41e194e 100644
--- a/vlc-android/src/org/videolan/vlc/util/VLCInstance.java
+++ b/vlc-android/src/org/videolan/vlc/util/VLCInstance.java
@@ -22,13 +22,10 @@ package org.videolan.vlc.util;
 
 import android.content.Context;
 import android.content.Intent;
-import android.content.SharedPreferences;
-import android.preference.PreferenceManager;
 import android.util.Log;
 
 import org.videolan.libvlc.LibVLC;
 import org.videolan.libvlc.util.VLCUtil;
-import org.videolan.libvlc.MediaPlayer;
 import org.videolan.vlc.VLCApplication;
 import org.videolan.vlc.VLCCrashHandler;
 import org.videolan.vlc.gui.CompatErrorActivity;
@@ -45,13 +42,12 @@ public class VLCInstance {
             Thread.setDefaultUncaughtExceptionHandler(new VLCCrashHandler());
 
             final Context context = VLCApplication.getAppContext();
-            final SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(context);
             if(!VLCUtil.hasCompatibleCPU(context)) {
                 Log.e(TAG, VLCUtil.getErrorMsg());
                 throw new IllegalStateException("LibVLC initialisation failed: " + VLCUtil.getErrorMsg());
             }
 
-            sLibVLC = new LibVLC(VLCOptions.getLibOptions(pref));
+            sLibVLC = new LibVLC(VLCOptions.getLibOptions(context));
             LibVLC.setOnNativeCrashListener(new LibVLC.OnNativeCrashListener() {
                 @Override
                 public void onNativeCrash() {
@@ -65,10 +61,10 @@ public class VLCInstance {
         return sLibVLC;
     }
 
-    public static synchronized void restart(SharedPreferences pref) throws IllegalStateException {
+    public static synchronized void restart(Context context) throws IllegalStateException {
         if (sLibVLC != null) {
             sLibVLC.release();
-            sLibVLC = new LibVLC(VLCOptions.getLibOptions(pref));
+            sLibVLC = new LibVLC(VLCOptions.getLibOptions(context));
         }
     }
 
diff --git a/vlc-android/src/org/videolan/vlc/util/VLCOptions.java b/vlc-android/src/org/videolan/vlc/util/VLCOptions.java
index c50db38..9016c9c 100644
--- a/vlc-android/src/org/videolan/vlc/util/VLCOptions.java
+++ b/vlc-android/src/org/videolan/vlc/util/VLCOptions.java
@@ -53,7 +53,9 @@ public class VLCOptions {
 
     private static boolean sHdmiAudioEnabled = false;
 
-    public static ArrayList<String> getLibOptions(SharedPreferences pref) {
+    public static ArrayList<String> getLibOptions(Context context) {
+        final SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(context);
+
         ArrayList<String> options = new ArrayList<String>(50);
 
         final boolean timeStrechingDefault = VLCApplication.getAppResources().getBoolean(R.bool.time_stretching_default);



More information about the Android mailing list