From 3a1ced0301e5e9a3067967b0c83f49723d9d37b4 Mon Sep 17 00:00:00 2001 From: daniel oeh Date: Fri, 17 Oct 2014 22:07:03 +0200 Subject: Added more changes to support SP --- core/src/main/AndroidManifest.xml | 42 +++++++++------------ .../antennapod/core/ApplicationCallbacks.java | 2 + .../antennapod/core/PlaybackServiceCallbacks.java | 7 +++- .../core/preferences/UserPreferences.java | 18 ++++----- .../core/receiver/AlarmUpdateReceiver.java | 3 +- .../core/service/playback/PlaybackService.java | 14 +++++-- .../core/service/playback/PlayerStatus.java | 12 +++++- .../core/util/playback/PlaybackController.java | 6 +++ .../main/res/drawable-hdpi-v11/ic_stat_antenna.png | Bin 678 -> 0 bytes .../drawable-hdpi-v11/ic_stat_antenna_default.png | Bin 0 -> 678 bytes .../src/main/res/drawable-hdpi/ic_stat_antenna.png | Bin 649 -> 0 bytes .../res/drawable-hdpi/ic_stat_antenna_default.png | Bin 0 -> 649 bytes .../main/res/drawable-ldpi-v11/ic_stat_antenna.png | Bin 307 -> 0 bytes .../drawable-ldpi-v11/ic_stat_antenna_default.png | Bin 0 -> 307 bytes .../src/main/res/drawable-ldpi/ic_stat_antenna.png | Bin 271 -> 0 bytes .../res/drawable-ldpi/ic_stat_antenna_default.png | Bin 0 -> 271 bytes .../main/res/drawable-mdpi-v11/ic_stat_antenna.png | Bin 414 -> 0 bytes .../drawable-mdpi-v11/ic_stat_antenna_default.png | Bin 0 -> 414 bytes .../src/main/res/drawable-mdpi/ic_stat_antenna.png | Bin 412 -> 0 bytes .../res/drawable-mdpi/ic_stat_antenna_default.png | Bin 0 -> 412 bytes .../res/drawable-xhdpi-v11/ic_stat_antenna.png | Bin 1005 -> 0 bytes .../drawable-xhdpi-v11/ic_stat_antenna_default.png | Bin 0 -> 1005 bytes .../main/res/drawable-xhdpi/ic_stat_antenna.png | Bin 942 -> 0 bytes .../res/drawable-xhdpi/ic_stat_antenna_default.png | Bin 0 -> 942 bytes 24 files changed, 63 insertions(+), 41 deletions(-) delete mode 100644 core/src/main/res/drawable-hdpi-v11/ic_stat_antenna.png create mode 100644 core/src/main/res/drawable-hdpi-v11/ic_stat_antenna_default.png delete mode 100644 core/src/main/res/drawable-hdpi/ic_stat_antenna.png create mode 100644 core/src/main/res/drawable-hdpi/ic_stat_antenna_default.png delete mode 100644 core/src/main/res/drawable-ldpi-v11/ic_stat_antenna.png create mode 100644 core/src/main/res/drawable-ldpi-v11/ic_stat_antenna_default.png delete mode 100644 core/src/main/res/drawable-ldpi/ic_stat_antenna.png create mode 100644 core/src/main/res/drawable-ldpi/ic_stat_antenna_default.png delete mode 100644 core/src/main/res/drawable-mdpi-v11/ic_stat_antenna.png create mode 100644 core/src/main/res/drawable-mdpi-v11/ic_stat_antenna_default.png delete mode 100644 core/src/main/res/drawable-mdpi/ic_stat_antenna.png create mode 100644 core/src/main/res/drawable-mdpi/ic_stat_antenna_default.png delete mode 100644 core/src/main/res/drawable-xhdpi-v11/ic_stat_antenna.png create mode 100644 core/src/main/res/drawable-xhdpi-v11/ic_stat_antenna_default.png delete mode 100644 core/src/main/res/drawable-xhdpi/ic_stat_antenna.png create mode 100644 core/src/main/res/drawable-xhdpi/ic_stat_antenna_default.png (limited to 'core') diff --git a/core/src/main/AndroidManifest.xml b/core/src/main/AndroidManifest.xml index 006b3f123..c660cd805 100644 --- a/core/src/main/AndroidManifest.xml +++ b/core/src/main/AndroidManifest.xml @@ -1,55 +1,49 @@ - - - - - - + + + + + + - + + android:enabled="true" /> - + android:exported="true"/> - + android:enabled="true"/> - + - + - - - - - - + - + + android:scheme="package" /> diff --git a/core/src/main/java/de/danoeh/antennapod/core/ApplicationCallbacks.java b/core/src/main/java/de/danoeh/antennapod/core/ApplicationCallbacks.java index 69a959ba8..d88e8fbb1 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/ApplicationCallbacks.java +++ b/core/src/main/java/de/danoeh/antennapod/core/ApplicationCallbacks.java @@ -19,4 +19,6 @@ public interface ApplicationCallbacks { * activity. */ public Intent getStorageErrorActivity(Context context); + + public void setUpateInterval(long upateInterval); } diff --git a/core/src/main/java/de/danoeh/antennapod/core/PlaybackServiceCallbacks.java b/core/src/main/java/de/danoeh/antennapod/core/PlaybackServiceCallbacks.java index 7aa99dcef..fb01fa703 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/PlaybackServiceCallbacks.java +++ b/core/src/main/java/de/danoeh/antennapod/core/PlaybackServiceCallbacks.java @@ -23,6 +23,11 @@ public interface PlaybackServiceCallbacks { * Returns true if the PlaybackService should load new episodes from the queue when playback ends * and false if the PlaybackService should ignore the queue and load no more episodes when playback * finishes. - * */ + */ public boolean useQueue(); + + /** + * Returns a drawable resource that is used for the notification of the playback service. + */ + public int getNotificationIconResource(Context context); } diff --git a/core/src/main/java/de/danoeh/antennapod/core/preferences/UserPreferences.java b/core/src/main/java/de/danoeh/antennapod/core/preferences/UserPreferences.java index 5cac4837d..93fff71ba 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/preferences/UserPreferences.java +++ b/core/src/main/java/de/danoeh/antennapod/core/preferences/UserPreferences.java @@ -20,6 +20,7 @@ import java.util.List; import java.util.concurrent.TimeUnit; import de.danoeh.antennapod.core.BuildConfig; +import de.danoeh.antennapod.core.ClientConfig; import de.danoeh.antennapod.core.R; import de.danoeh.antennapod.core.receiver.FeedUpdateReceiver; @@ -329,7 +330,7 @@ public class UserPreferences implements } else if (key.equals(PREF_UPDATE_INTERVAL)) { updateInterval = readUpdateInterval(sp.getString( PREF_UPDATE_INTERVAL, "0")); - restartUpdateAlarm(updateInterval); + ClientConfig.applicationCallbacks.setUpateInterval(updateInterval); } else if (key.equals(PREF_AUTO_DELETE)) { autoDelete = sp.getBoolean(PREF_AUTO_DELETE, false); @@ -541,23 +542,19 @@ public class UserPreferences implements /** * Updates alarm registered with the AlarmManager service or deactivates it. - * - * @param millis new value to register with AlarmManager. If millis is 0, the - * alarm is deactivated. */ - public static void restartUpdateAlarm(long millis) { + public static void restartUpdateAlarm(long triggerAtMillis, long intervalMillis) { instanceAvailable(); if (BuildConfig.DEBUG) - Log.d(TAG, "Restarting update alarm. New value: " + millis); + Log.d(TAG, "Restarting update alarm."); AlarmManager alarmManager = (AlarmManager) instance.context .getSystemService(Context.ALARM_SERVICE); PendingIntent updateIntent = PendingIntent.getBroadcast( instance.context, 0, new Intent( - FeedUpdateReceiver.ACTION_REFRESH_FEEDS), 0 - ); + FeedUpdateReceiver.ACTION_REFRESH_FEEDS), 0); alarmManager.cancel(updateIntent); - if (millis != 0) { - alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, millis, millis, + if (intervalMillis != 0) { + alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, triggerAtMillis, intervalMillis, updateIntent); if (BuildConfig.DEBUG) Log.d(TAG, "Changed alarm to new interval"); @@ -567,6 +564,7 @@ public class UserPreferences implements } } + /** * Reads episode cache size as it is saved in the episode_cache_size_values array. */ diff --git a/core/src/main/java/de/danoeh/antennapod/core/receiver/AlarmUpdateReceiver.java b/core/src/main/java/de/danoeh/antennapod/core/receiver/AlarmUpdateReceiver.java index 0777a7a2e..0a002825a 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/receiver/AlarmUpdateReceiver.java +++ b/core/src/main/java/de/danoeh/antennapod/core/receiver/AlarmUpdateReceiver.java @@ -8,6 +8,7 @@ import android.util.Log; import org.apache.commons.lang3.StringUtils; import de.danoeh.antennapod.core.BuildConfig; +import de.danoeh.antennapod.core.ClientConfig; import de.danoeh.antennapod.core.preferences.UserPreferences; /** Listens for events that make it necessary to reset the update alarm. */ @@ -26,7 +27,7 @@ public class AlarmUpdateReceiver extends BroadcastReceiver { Log.d(TAG, "Resetting update alarm after app upgrade"); } - UserPreferences.restartUpdateAlarm(UserPreferences.getUpdateInterval()); + ClientConfig.applicationCallbacks.setUpateInterval(UserPreferences.getUpdateInterval()); } diff --git a/core/src/main/java/de/danoeh/antennapod/core/service/playback/PlaybackService.java b/core/src/main/java/de/danoeh/antennapod/core/service/playback/PlaybackService.java index bbf0bfb38..6c1b9491b 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/service/playback/PlaybackService.java +++ b/core/src/main/java/de/danoeh/antennapod/core/service/playback/PlaybackService.java @@ -79,6 +79,7 @@ public class PlaybackService extends Service { public static final String EXTRA_PREPARE_IMMEDIATELY = "extra.de.danoeh.antennapod.core.service.prepareImmediately"; public static final String ACTION_PLAYER_STATUS_CHANGED = "action.de.danoeh.antennapod.core.service.playerStatusChanged"; + public static final String EXTRA_NEW_PLAYER_STATUS = "extra.de.danoeh.antennapod.service.playerStatusChanged.newStatus"; private static final String AVRCP_ACTION_PLAYER_STATUS_CHANGED = "com.android.music.playstatechanged"; private static final String AVRCP_ACTION_META_CHANGED = "com.android.music.metachanged"; @@ -417,6 +418,9 @@ public class PlaybackService extends Service { } + Intent statusUpdate = new Intent(ACTION_PLAYER_STATUS_CHANGED); + statusUpdate.putExtra(EXTRA_NEW_PLAYER_STATUS, newInfo.playerStatus.ordinal()); + sendBroadcast(statusUpdate); sendBroadcast(new Intent(ACTION_PLAYER_STATUS_CHANGED)); updateWidget(); refreshRemoteControlClientState(newInfo); @@ -694,8 +698,8 @@ public class PlaybackService extends Service { } if (icon == null) { - icon = BitmapFactory.decodeResource(getResources(), - R.drawable.ic_stat_antenna); + icon = BitmapFactory.decodeResource(getApplicationContext().getResources(), + ClientConfig.playbackServiceCallbacks.getNotificationIconResource(getApplicationContext())); } return null; @@ -708,6 +712,8 @@ public class PlaybackService extends Service { return; } PlaybackServiceMediaPlayer.PSMPInfo newInfo = mediaPlayer.getPSMPInfo(); + final int smallIcon = ClientConfig.playbackServiceCallbacks.getNotificationIconResource(getApplicationContext()); + if (!isCancelled() && info.playerStatus == PlayerStatus.PLAYING && info.playable != null) { String contentText = info.playable.getFeedTitle(); @@ -730,7 +736,7 @@ public class PlaybackService extends Service { .setOngoing(true) .setContentIntent(pIntent) .setLargeIcon(icon) - .setSmallIcon(R.drawable.ic_stat_antenna) + .setSmallIcon(smallIcon) .addAction(android.R.drawable.ic_media_pause, getString(R.string.pause_label), pauseButtonPendingIntent); @@ -741,7 +747,7 @@ public class PlaybackService extends Service { .setContentTitle(contentTitle) .setContentText(contentText).setOngoing(true) .setContentIntent(pIntent).setLargeIcon(icon) - .setSmallIcon(R.drawable.ic_stat_antenna); + .setSmallIcon(smallIcon); notification = notificationBuilder.getNotification(); } if (newInfo.playerStatus == PlayerStatus.PLAYING) { diff --git a/core/src/main/java/de/danoeh/antennapod/core/service/playback/PlayerStatus.java b/core/src/main/java/de/danoeh/antennapod/core/service/playback/PlayerStatus.java index 1ad0c25d9..7c666abd5 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/service/playback/PlayerStatus.java +++ b/core/src/main/java/de/danoeh/antennapod/core/service/playback/PlayerStatus.java @@ -10,5 +10,15 @@ public enum PlayerStatus { PREPARED, SEEKING, INITIALIZING, // playback service is loading the Playable's metadata - INITIALIZED // playback service was started, data source of media player was set. + INITIALIZED; // playback service was started, data source of media player was set. + + private static final PlayerStatus[] fromOrdinalLookup; + + static { + fromOrdinalLookup = PlayerStatus.values(); + } + + public static PlayerStatus fromOrdinal(int o) { + return fromOrdinalLookup[o]; + } } diff --git a/core/src/main/java/de/danoeh/antennapod/core/util/playback/PlaybackController.java b/core/src/main/java/de/danoeh/antennapod/core/util/playback/PlaybackController.java index 5118d92ae..6b843e040 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/util/playback/PlaybackController.java +++ b/core/src/main/java/de/danoeh/antennapod/core/util/playback/PlaybackController.java @@ -394,6 +394,12 @@ public abstract class PlaybackController { public abstract void onPlaybackEnd(); + public void repeatHandleStatus() { + if (status != null && playbackService != null) { + handleStatus(); + } + } + /** * Is called whenever the PlaybackService changes it's status. This method * should be used to update the GUI or start/cancel background threads. diff --git a/core/src/main/res/drawable-hdpi-v11/ic_stat_antenna.png b/core/src/main/res/drawable-hdpi-v11/ic_stat_antenna.png deleted file mode 100644 index 37d73c734..000000000 Binary files a/core/src/main/res/drawable-hdpi-v11/ic_stat_antenna.png and /dev/null differ diff --git a/core/src/main/res/drawable-hdpi-v11/ic_stat_antenna_default.png b/core/src/main/res/drawable-hdpi-v11/ic_stat_antenna_default.png new file mode 100644 index 000000000..37d73c734 Binary files /dev/null and b/core/src/main/res/drawable-hdpi-v11/ic_stat_antenna_default.png differ diff --git a/core/src/main/res/drawable-hdpi/ic_stat_antenna.png b/core/src/main/res/drawable-hdpi/ic_stat_antenna.png deleted file mode 100644 index 36d502492..000000000 Binary files a/core/src/main/res/drawable-hdpi/ic_stat_antenna.png and /dev/null differ diff --git a/core/src/main/res/drawable-hdpi/ic_stat_antenna_default.png b/core/src/main/res/drawable-hdpi/ic_stat_antenna_default.png new file mode 100644 index 000000000..36d502492 Binary files /dev/null and b/core/src/main/res/drawable-hdpi/ic_stat_antenna_default.png differ diff --git a/core/src/main/res/drawable-ldpi-v11/ic_stat_antenna.png b/core/src/main/res/drawable-ldpi-v11/ic_stat_antenna.png deleted file mode 100644 index e44f42510..000000000 Binary files a/core/src/main/res/drawable-ldpi-v11/ic_stat_antenna.png and /dev/null differ diff --git a/core/src/main/res/drawable-ldpi-v11/ic_stat_antenna_default.png b/core/src/main/res/drawable-ldpi-v11/ic_stat_antenna_default.png new file mode 100644 index 000000000..e44f42510 Binary files /dev/null and b/core/src/main/res/drawable-ldpi-v11/ic_stat_antenna_default.png differ diff --git a/core/src/main/res/drawable-ldpi/ic_stat_antenna.png b/core/src/main/res/drawable-ldpi/ic_stat_antenna.png deleted file mode 100644 index 63d72970d..000000000 Binary files a/core/src/main/res/drawable-ldpi/ic_stat_antenna.png and /dev/null differ diff --git a/core/src/main/res/drawable-ldpi/ic_stat_antenna_default.png b/core/src/main/res/drawable-ldpi/ic_stat_antenna_default.png new file mode 100644 index 000000000..63d72970d Binary files /dev/null and b/core/src/main/res/drawable-ldpi/ic_stat_antenna_default.png differ diff --git a/core/src/main/res/drawable-mdpi-v11/ic_stat_antenna.png b/core/src/main/res/drawable-mdpi-v11/ic_stat_antenna.png deleted file mode 100644 index 8808dedc7..000000000 Binary files a/core/src/main/res/drawable-mdpi-v11/ic_stat_antenna.png and /dev/null differ diff --git a/core/src/main/res/drawable-mdpi-v11/ic_stat_antenna_default.png b/core/src/main/res/drawable-mdpi-v11/ic_stat_antenna_default.png new file mode 100644 index 000000000..8808dedc7 Binary files /dev/null and b/core/src/main/res/drawable-mdpi-v11/ic_stat_antenna_default.png differ diff --git a/core/src/main/res/drawable-mdpi/ic_stat_antenna.png b/core/src/main/res/drawable-mdpi/ic_stat_antenna.png deleted file mode 100644 index 8b1206b51..000000000 Binary files a/core/src/main/res/drawable-mdpi/ic_stat_antenna.png and /dev/null differ diff --git a/core/src/main/res/drawable-mdpi/ic_stat_antenna_default.png b/core/src/main/res/drawable-mdpi/ic_stat_antenna_default.png new file mode 100644 index 000000000..8b1206b51 Binary files /dev/null and b/core/src/main/res/drawable-mdpi/ic_stat_antenna_default.png differ diff --git a/core/src/main/res/drawable-xhdpi-v11/ic_stat_antenna.png b/core/src/main/res/drawable-xhdpi-v11/ic_stat_antenna.png deleted file mode 100644 index 59de64c87..000000000 Binary files a/core/src/main/res/drawable-xhdpi-v11/ic_stat_antenna.png and /dev/null differ diff --git a/core/src/main/res/drawable-xhdpi-v11/ic_stat_antenna_default.png b/core/src/main/res/drawable-xhdpi-v11/ic_stat_antenna_default.png new file mode 100644 index 000000000..59de64c87 Binary files /dev/null and b/core/src/main/res/drawable-xhdpi-v11/ic_stat_antenna_default.png differ diff --git a/core/src/main/res/drawable-xhdpi/ic_stat_antenna.png b/core/src/main/res/drawable-xhdpi/ic_stat_antenna.png deleted file mode 100644 index 50d73271d..000000000 Binary files a/core/src/main/res/drawable-xhdpi/ic_stat_antenna.png and /dev/null differ diff --git a/core/src/main/res/drawable-xhdpi/ic_stat_antenna_default.png b/core/src/main/res/drawable-xhdpi/ic_stat_antenna_default.png new file mode 100644 index 000000000..50d73271d Binary files /dev/null and b/core/src/main/res/drawable-xhdpi/ic_stat_antenna_default.png differ -- cgit v1.2.3