[Android] Util method to async prefs saving when possible

Geoffrey Métais git at videolan.org
Mon Jan 5 17:39:30 CET 2015


vlc-ports/android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Mon Jan  5 17:35:25 2015 +0100| [72681fa7f5f189a5a9070e81f203470097a9e125] | committer: Geoffrey Métais

Util method to async prefs saving when possible

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

 vlc-android/src/org/videolan/vlc/util/Util.java |   11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/vlc-android/src/org/videolan/vlc/util/Util.java b/vlc-android/src/org/videolan/vlc/util/Util.java
index 3fd63e1..8989519 100644
--- a/vlc-android/src/org/videolan/vlc/util/Util.java
+++ b/vlc-android/src/org/videolan/vlc/util/Util.java
@@ -27,6 +27,7 @@ import java.io.InputStreamReader;
 import java.util.concurrent.atomic.AtomicInteger;
 
 import org.videolan.libvlc.LibVLC;
+import org.videolan.libvlc.LibVlcUtil;
 import org.videolan.libvlc.Media;
 import org.videolan.vlc.MediaLibrary;
 import org.videolan.vlc.R;
@@ -34,8 +35,10 @@ import org.videolan.vlc.VLCApplication;
 import org.videolan.vlc.VLCCallbackTask;
 import org.videolan.vlc.audio.AudioServiceController;
 
+import android.annotation.TargetApi;
 import android.content.Context;
 import android.content.Intent;
+import android.content.SharedPreferences;
 import android.content.res.TypedArray;
 import android.text.TextUtils.TruncateAt;
 import android.util.DisplayMetrics;
@@ -237,4 +240,12 @@ public class Util {
                         ? media.getNowPlaying()
                         : getMediaArtist(ctx, media) + " - " + getMediaAlbum(ctx, media);
     }
+
+    @TargetApi(android.os.Build.VERSION_CODES.GINGERBREAD)
+    public static void commitPreferences(SharedPreferences.Editor editor){
+        if (LibVlcUtil.isGingerbreadOrLater())
+            editor.apply();
+        else
+            editor.commit();
+    }
 }



More information about the Android mailing list