OSDN Git Service

Add ability to seek through track with circular motion
[android-x86/packages-apps-Eleven.git] / src / com / cyanogenmod / eleven / utils / MusicUtils.java
index 252f869..38e9ac0 100644 (file)
@@ -87,7 +87,8 @@ public final class MusicUtils {
     public static final String MUSIC_ONLY_SELECTION = MediaStore.Audio.AudioColumns.IS_MUSIC + "=1"
                     + " AND " + MediaStore.Audio.AudioColumns.TITLE + " != ''"; //$NON-NLS-2$
 
-    private static boolean sShakeToPlayEnabled;
+    public static final long UPDATE_FREQUENCY_MS = 500;
+    public static final long UPDATE_FREQUENCY_FAST_MS = 30;
 
     static {
         mConnectionMap = new WeakHashMap<Context, ServiceBinder>();
@@ -109,10 +110,10 @@ public final class MusicUtils {
         if (realActivity == null) {
             realActivity = (Activity)context;
         }
-        sShakeToPlayEnabled = PreferenceUtils.getInstance(context).getShakeToPlay();
         final ContextWrapper contextWrapper = new ContextWrapper(realActivity);
         contextWrapper.startService(new Intent(contextWrapper, MusicPlaybackService.class));
-        final ServiceBinder binder = new ServiceBinder(callback);
+        final ServiceBinder binder = new ServiceBinder(callback,
+                contextWrapper.getApplicationContext());
         if (contextWrapper.bindService(
                 new Intent().setClass(contextWrapper, MusicPlaybackService.class), binder, 0)) {
             mConnectionMap.put(contextWrapper, binder);
@@ -141,14 +142,16 @@ public final class MusicUtils {
 
     public static final class ServiceBinder implements ServiceConnection {
         private final ServiceConnection mCallback;
+        private final Context mContext;
 
         /**
          * Constructor of <code>ServiceBinder</code>
          *
          * @param context The {@link ServiceConnection} to use
          */
-        public ServiceBinder(final ServiceConnection callback) {
+        public ServiceBinder(final ServiceConnection callback, final Context context) {
             mCallback = callback;
+            mContext = context;
         }
 
         @Override
@@ -157,7 +160,7 @@ public final class MusicUtils {
             if (mCallback != null) {
                 mCallback.onServiceConnected(className, service);
             }
-            MusicUtils.setShakeToPlayEnabled(sShakeToPlayEnabled);
+            MusicUtils.initPlaybackServiceWithSettings(mContext);
         }
 
         @Override
@@ -275,9 +278,19 @@ public final class MusicUtils {
     }
 
     /**
+     * Initialize playback service with values from Settings
+     */
+    public static void initPlaybackServiceWithSettings(final Context context) {
+        MusicUtils.setShakeToPlayEnabled(
+                PreferenceUtils.getInstance(context).getShakeToPlay());
+        MusicUtils.setShowAlbumArtOnLockscreen(
+                PreferenceUtils.getInstance(context).getShowAlbumArtOnLockscreen());
+    }
+
+    /**
      * Set shake to play status
      */
-    public static void setShakeToPlayEnabled(boolean enabled) {
+    public static void setShakeToPlayEnabled(final boolean enabled) {
         try {
             if (mService != null) {
                 mService.setShakeToPlayEnabled(enabled);
@@ -287,6 +300,18 @@ public final class MusicUtils {
     }
 
     /**
+     * Set show album art on lockscreen
+     */
+    public static void setShowAlbumArtOnLockscreen(final boolean enabled) {
+        try {
+            if (mService != null) {
+                mService.setLockscreenAlbumArt(enabled);
+            }
+        } catch (final RemoteException ignored) {
+        }
+    }
+
+    /**
      * Changes to the next track asynchronously
      */
     public static void asyncNext(final Context context) {
@@ -849,15 +874,6 @@ public final class MusicUtils {
             if (forceShuffle) {
                 mService.setShuffleMode(MusicPlaybackService.SHUFFLE_NORMAL);
             }
-            final long currentId = mService.getAudioId();
-            final int currentQueuePosition = getQueuePosition();
-            if (position != -1 && currentQueuePosition == position && currentId == list[position]) {
-                final long[] playlist = getQueue();
-                if (Arrays.equals(list, playlist)) {
-                    mService.play();
-                    return;
-                }
-            }
             if (position < 0) {
                 position = 0;
             }