diff options
author | daniel oeh <daniel.oeh@gmail.com> | 2014-10-17 22:07:03 +0200 |
---|---|---|
committer | daniel oeh <daniel.oeh@gmail.com> | 2014-10-17 22:07:03 +0200 |
commit | 3a1ced0301e5e9a3067967b0c83f49723d9d37b4 (patch) | |
tree | 04348304132a417b4be007733f402faed9dcac8d /core | |
parent | aa535ac240bc1dfae0db7e85f54747f3cabeb96d (diff) | |
download | AntennaPod-3a1ced0301e5e9a3067967b0c83f49723d9d37b4.zip |
Added more changes to support SP
Diffstat (limited to 'core')
16 files changed, 63 insertions, 41 deletions
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 @@ <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="de.danoeh.antennapod.core"> - <uses-permission android:name="android.permission.INTERNET"/> - <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/> - <uses-permission android:name="android.permission.WAKE_LOCK"/> - <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/> - <uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/> - <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/> + <uses-permission android:name="android.permission.INTERNET" /> + <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> + <uses-permission android:name="android.permission.WAKE_LOCK" /> + <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> + <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" /> + <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" /> - <application android:allowBackup="true" - android:label="@string/app_name" - android:icon="@drawable/ic_launcher"> + <application + android:allowBackup="true" + android:icon="@drawable/ic_launcher" + android:label="@string/app_name"> <service android:name=".service.download.DownloadService" - android:enabled="true"/> + android:enabled="true" /> <service android:name=".service.playback.PlaybackService" android:enabled="true" - android:exported="true"> - </service> + android:exported="true"/> <service android:name=".service.GpodnetSyncService" - android:enabled="true"> - </service> + android:enabled="true"/> <receiver android:name=".receiver.MediaButtonReceiver" android:exported="true"> <intent-filter> - <action android:name="android.intent.action.MEDIA_BUTTON"/> + <action android:name="android.intent.action.MEDIA_BUTTON" /> </intent-filter> <intent-filter> - <action android:name="de.danoeh.antennapod.NOTIFY_BUTTON_RECEIVER"/> + <action android:name="de.danoeh.antennapod.NOTIFY_BUTTON_RECEIVER" /> </intent-filter> </receiver> - <receiver android:name=".receiver.ConnectivityActionReceiver"> - <intent-filter> - <action android:name="android.net.conn.CONNECTIVITY_CHANGE"/> - </intent-filter> - </receiver> <receiver android:name=".receiver.AlarmUpdateReceiver"> <intent-filter> - <action android:name="android.intent.action.BOOT_COMPLETED"/> + <action android:name="android.intent.action.BOOT_COMPLETED" /> </intent-filter> <intent-filter> - <action android:name="android.intent.action.PACKAGE_REPLACED"/> + <action android:name="android.intent.action.PACKAGE_REPLACED" /> <data android:path="de.danoeh.antennapod" - android:scheme="package"/> + android:scheme="package" /> </intent-filter> </receiver> 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_default.png Binary files differindex 37d73c734..37d73c734 100644 --- a/core/src/main/res/drawable-hdpi-v11/ic_stat_antenna.png +++ b/core/src/main/res/drawable-hdpi-v11/ic_stat_antenna_default.png diff --git a/core/src/main/res/drawable-hdpi/ic_stat_antenna.png b/core/src/main/res/drawable-hdpi/ic_stat_antenna_default.png Binary files differindex 36d502492..36d502492 100644 --- a/core/src/main/res/drawable-hdpi/ic_stat_antenna.png +++ b/core/src/main/res/drawable-hdpi/ic_stat_antenna_default.png 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_default.png Binary files differindex e44f42510..e44f42510 100644 --- a/core/src/main/res/drawable-ldpi-v11/ic_stat_antenna.png +++ b/core/src/main/res/drawable-ldpi-v11/ic_stat_antenna_default.png diff --git a/core/src/main/res/drawable-ldpi/ic_stat_antenna.png b/core/src/main/res/drawable-ldpi/ic_stat_antenna_default.png Binary files differindex 63d72970d..63d72970d 100644 --- a/core/src/main/res/drawable-ldpi/ic_stat_antenna.png +++ b/core/src/main/res/drawable-ldpi/ic_stat_antenna_default.png 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_default.png Binary files differindex 8808dedc7..8808dedc7 100644 --- a/core/src/main/res/drawable-mdpi-v11/ic_stat_antenna.png +++ b/core/src/main/res/drawable-mdpi-v11/ic_stat_antenna_default.png diff --git a/core/src/main/res/drawable-mdpi/ic_stat_antenna.png b/core/src/main/res/drawable-mdpi/ic_stat_antenna_default.png Binary files differindex 8b1206b51..8b1206b51 100644 --- a/core/src/main/res/drawable-mdpi/ic_stat_antenna.png +++ b/core/src/main/res/drawable-mdpi/ic_stat_antenna_default.png 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_default.png Binary files differindex 59de64c87..59de64c87 100644 --- a/core/src/main/res/drawable-xhdpi-v11/ic_stat_antenna.png +++ b/core/src/main/res/drawable-xhdpi-v11/ic_stat_antenna_default.png diff --git a/core/src/main/res/drawable-xhdpi/ic_stat_antenna.png b/core/src/main/res/drawable-xhdpi/ic_stat_antenna_default.png Binary files differindex 50d73271d..50d73271d 100644 --- a/core/src/main/res/drawable-xhdpi/ic_stat_antenna.png +++ b/core/src/main/res/drawable-xhdpi/ic_stat_antenna_default.png |