diff options
author | daniel oeh <daniel.oeh@gmail.com> | 2012-09-23 13:00:02 +0200 |
---|---|---|
committer | daniel oeh <daniel.oeh@gmail.com> | 2012-09-23 13:00:02 +0200 |
commit | 4a472ff3bbc7a79d42577be55e6c3336c32bf3dc (patch) | |
tree | 249ff13ec5935b57492d281e484300db6cf3169b /src | |
parent | 7a0297f937218f95922443134fc823c56cf4f424 (diff) | |
download | AntennaPod-4a472ff3bbc7a79d42577be55e6c3336c32bf3dc.zip |
Moved WidgetUpdater to background thread
Diffstat (limited to 'src')
-rw-r--r-- | src/de/danoeh/antennapod/service/PlayerWidgetService.java | 36 |
1 files changed, 30 insertions, 6 deletions
diff --git a/src/de/danoeh/antennapod/service/PlayerWidgetService.java b/src/de/danoeh/antennapod/service/PlayerWidgetService.java index 2d638823d..74fda6de9 100644 --- a/src/de/danoeh/antennapod/service/PlayerWidgetService.java +++ b/src/de/danoeh/antennapod/service/PlayerWidgetService.java @@ -25,7 +25,7 @@ public class PlayerWidgetService extends Service { private PlaybackService playbackService; /** True while service is updating the widget */ - private boolean isUpdating; + private volatile boolean isUpdating; public PlayerWidgetService() { } @@ -58,13 +58,11 @@ public class PlayerWidgetService extends Service { @Override public int onStartCommand(Intent intent, int flags, int startId) { if (!isUpdating) { - isUpdating = true; if (playbackService == null && PlaybackService.isRunning) { bindService(new Intent(this, PlaybackService.class), mConnection, 0); } else { - updateViews(); - isUpdating = false; + startViewUpdaterIfNotRunning(); } } else { if (AppConfig.DEBUG) @@ -75,6 +73,7 @@ public class PlayerWidgetService extends Service { } private void updateViews() { + isUpdating = true; if (AppConfig.DEBUG) Log.d(TAG, "Updating widget views"); ComponentName playerWidget = new ComponentName(this, PlayerWidget.class); @@ -112,6 +111,7 @@ public class PlayerWidgetService extends Service { } manager.updateAppWidget(playerWidget, views); + isUpdating = false; } /** Creates an intent which fakes a mediabutton press */ @@ -137,8 +137,7 @@ public class PlayerWidgetService extends Service { Log.d(TAG, "Connection to service established"); playbackService = ((PlaybackService.LocalBinder) service) .getService(); - updateViews(); - isUpdating = false; + startViewUpdaterIfNotRunning(); } @Override @@ -149,5 +148,30 @@ public class PlayerWidgetService extends Service { } }; + + private void startViewUpdaterIfNotRunning() { + if (!isUpdating) { + ViewUpdater updateThread = new ViewUpdater(this); + updateThread.start(); + } + } + + static class ViewUpdater extends Thread { + private static final String THREAD_NAME = "ViewUpdater"; + private PlayerWidgetService service; + + public ViewUpdater(PlayerWidgetService service) { + super(); + setName(THREAD_NAME); + this.service = service; + + } + + @Override + public void run() { + service.updateViews(); + } + + } } |