From b092a245491349021e1d79c9f884d92a92e5c2b9 Mon Sep 17 00:00:00 2001 From: Scott Jackson Date: Thu, 2 May 2013 07:44:14 -0700 Subject: Only use executeOnExecutor for ICS+ --- .../service/DownloadServiceLifecycleSupport.java | 94 +++++++++++++--------- 1 file changed, 56 insertions(+), 38 deletions(-) (limited to 'subsonic-android') diff --git a/subsonic-android/src/github/daneren2005/dsub/service/DownloadServiceLifecycleSupport.java b/subsonic-android/src/github/daneren2005/dsub/service/DownloadServiceLifecycleSupport.java index a8600252..68917d9e 100644 --- a/subsonic-android/src/github/daneren2005/dsub/service/DownloadServiceLifecycleSupport.java +++ b/subsonic-android/src/github/daneren2005/dsub/service/DownloadServiceLifecycleSupport.java @@ -31,6 +31,7 @@ import android.content.Intent; import android.content.IntentFilter; import android.media.RemoteControlClient; import android.os.AsyncTask; +import android.os.Build; import android.telephony.PhoneStateListener; import android.telephony.TelephonyManager; import android.util.Log; @@ -182,7 +183,11 @@ public class DownloadServiceLifecycleSupport { } public void serializeDownloadQueue() { - new SerializeTask().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { + new SerializeTask().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); + } else { + new SerializeTask().execute(); + } } public void serializeDownloadQueueNow() { @@ -199,7 +204,11 @@ public class DownloadServiceLifecycleSupport { } private void deserializeDownloadQueue() { - new DeserializeTask().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { + new DeserializeTask().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); + } else { + new DeserializeTask().execute(); + } } private void deserializeDownloadQueueNow() { State state = FileUtil.deserialize(downloadService, FILENAME_DOWNLOADS_SER); @@ -214,42 +223,51 @@ public class DownloadServiceLifecycleSupport { } private void handleKeyEvent(KeyEvent event) { - if (event.getAction() != KeyEvent.ACTION_DOWN || event.getRepeatCount() > 0) { - return; - } - - switch (event.getKeyCode()) { - case RemoteControlClient.FLAG_KEY_MEDIA_PLAY_PAUSE: - case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE: - case KeyEvent.KEYCODE_HEADSETHOOK: - downloadService.togglePlayPause(); - break; - case RemoteControlClient.FLAG_KEY_MEDIA_PREVIOUS: - case KeyEvent.KEYCODE_MEDIA_PREVIOUS: - downloadService.previous(); - break; - case RemoteControlClient.FLAG_KEY_MEDIA_NEXT: - case KeyEvent.KEYCODE_MEDIA_NEXT: - if (downloadService.getCurrentPlayingIndex() < downloadService.size() - 1) { - downloadService.next(); - } - break; - case RemoteControlClient.FLAG_KEY_MEDIA_STOP: - case KeyEvent.KEYCODE_MEDIA_STOP: - downloadService.stop(); - break; - case RemoteControlClient.FLAG_KEY_MEDIA_PLAY: - case KeyEvent.KEYCODE_MEDIA_PLAY: - if(downloadService.getPlayerState() != PlayerState.STARTED) { - downloadService.start(); - } - break; - case RemoteControlClient.FLAG_KEY_MEDIA_PAUSE: - case KeyEvent.KEYCODE_MEDIA_PAUSE: - downloadService.pause(); - default: - break; - } + if(event.getAction() == KeyEvent.ACTION_DOWN && event.getRepeatCount() > 0) { + switch (event.getKeyCode()) { + case RemoteControlClient.FLAG_KEY_MEDIA_PREVIOUS: + case KeyEvent.KEYCODE_MEDIA_PREVIOUS: + downloadService.seekTo(downloadService.getPlayerPosition() - 10000); + break; + case RemoteControlClient.FLAG_KEY_MEDIA_NEXT: + case KeyEvent.KEYCODE_MEDIA_NEXT: + downloadService.seekTo(downloadService.getPlayerPosition() + 10000); + break; + } + } else if(event.getAction() == KeyEvent.ACTION_UP) { + switch (event.getKeyCode()) { + case RemoteControlClient.FLAG_KEY_MEDIA_PLAY_PAUSE: + case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE: + case KeyEvent.KEYCODE_HEADSETHOOK: + downloadService.togglePlayPause(); + break; + case RemoteControlClient.FLAG_KEY_MEDIA_PREVIOUS: + case KeyEvent.KEYCODE_MEDIA_PREVIOUS: + downloadService.previous(); + break; + case RemoteControlClient.FLAG_KEY_MEDIA_NEXT: + case KeyEvent.KEYCODE_MEDIA_NEXT: + if (downloadService.getCurrentPlayingIndex() < downloadService.size() - 1) { + downloadService.next(); + } + break; + case RemoteControlClient.FLAG_KEY_MEDIA_STOP: + case KeyEvent.KEYCODE_MEDIA_STOP: + downloadService.stop(); + break; + case RemoteControlClient.FLAG_KEY_MEDIA_PLAY: + case KeyEvent.KEYCODE_MEDIA_PLAY: + if(downloadService.getPlayerState() != PlayerState.STARTED) { + downloadService.start(); + } + break; + case RemoteControlClient.FLAG_KEY_MEDIA_PAUSE: + case KeyEvent.KEYCODE_MEDIA_PAUSE: + downloadService.pause(); + default: + break; + } + } } /** -- cgit v1.2.3