[Android] PlaybackService: use an ArrayList for callbacks
Thomas Guillem
git at videolan.org
Wed Jul 1 15:14:33 CEST 2015
vlc-ports/android | branch: master | Thomas Guillem <thomas at gllm.fr> | Wed Jul 1 10:29:05 2015 +0200| [dc5ae243aa9d3219fb37a208ad4bb9e7cc0b7d15] | committer: Thomas Guillem
PlaybackService: use an ArrayList for callbacks
> http://git.videolan.org/gitweb.cgi/vlc-ports/android.git/?a=commit;h=dc5ae243aa9d3219fb37a208ad4bb9e7cc0b7d15
---
.../src/org/videolan/vlc/PlaybackService.java | 32 ++++++++------------
1 file changed, 12 insertions(+), 20 deletions(-)
diff --git a/vlc-android/src/org/videolan/vlc/PlaybackService.java b/vlc-android/src/org/videolan/vlc/PlaybackService.java
index fcafc30..90f3d89 100644
--- a/vlc-android/src/org/videolan/vlc/PlaybackService.java
+++ b/vlc-android/src/org/videolan/vlc/PlaybackService.java
@@ -130,7 +130,7 @@ public class PlaybackService extends Service {
private MediaWrapperList mMediaList = new MediaWrapperList();
private MediaPlayer mMediaPlayer;
- private HashMap<Callback, Integer> mCallback;
+ final private ArrayList<Callback> mCallbacks = new ArrayList<Callback>();
private boolean mDetectHeadset = true;
private boolean mPebbleEnabled;
private PowerManager.WakeLock mWakeLock;
@@ -202,7 +202,6 @@ public class PlaybackService extends Service {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
mDetectHeadset = prefs.getBoolean("enable_headset_detection", true);
- mCallback = new HashMap<Callback, Integer>();
mCurrentIndex = -1;
mPrevIndex = -1;
mNextIndex = -1;
@@ -547,7 +546,7 @@ public class PlaybackService extends Service {
case Media.Event.MetaChanged:
break;
}
- for (Callback callback : mCallback.keySet())
+ for (Callback callback : mCallbacks)
callback.onMediaEvent(event);
}
};
@@ -636,7 +635,7 @@ public class PlaybackService extends Service {
case MediaPlayer.Event.ESDeleted:
break;
}
- for (Callback callback : mCallback.keySet())
+ for (Callback callback : mCallbacks)
callback.onMediaPlayerEvent(event);
}
};
@@ -727,7 +726,7 @@ public class PlaybackService extends Service {
}
private void executeUpdate(Boolean updateWidget) {
- for (Callback callback : mCallback.keySet()) {
+ for (Callback callback : mCallbacks) {
callback.update();
}
if (updateWidget)
@@ -735,14 +734,14 @@ public class PlaybackService extends Service {
}
private void executeUpdateProgress() {
- for (Callback callback : mCallback.keySet()) {
+ for (Callback callback : mCallbacks) {
callback.updateProgress();
}
}
private void executeOnMediaPlayedAdded() {
final MediaWrapper media = getCurrentMedia();
- for (Callback callback : mCallback.keySet()) {
+ for (Callback callback : mCallbacks) {
callback.onMediaPlayedAdded(media, 0);
}
}
@@ -780,7 +779,7 @@ public class PlaybackService extends Service {
switch (msg.what) {
case SHOW_PROGRESS:
- if (service.mCallback.size() > 0) {
+ if (service.mCallbacks.size() > 0) {
removeMessages(SHOW_PROGRESS);
service.executeUpdateProgress();
sendEmptyMessageDelayed(SHOW_PROGRESS, 1000);
@@ -1382,23 +1381,16 @@ public class PlaybackService extends Service {
@MainThread
public synchronized void addCallback(Callback cb) {
- Integer count = mCallback.get(cb);
- if (count == null)
- count = 0;
- mCallback.put(cb, count + 1);
- if (hasCurrentMedia())
+ if (!mCallbacks.contains(cb)) {
+ mCallbacks.add(cb);
+ if (hasCurrentMedia())
mHandler.sendEmptyMessage(SHOW_PROGRESS);
+ }
}
@MainThread
public synchronized void removeCallback(Callback cb) {
- Integer count = mCallback.get(cb);
- if (count == null)
- count = 0;
- if (count > 1)
- mCallback.put(cb, count - 1);
- else
- mCallback.remove(cb);
+ mCallbacks.remove(cb);
}
@MainThread
More information about the Android
mailing list