Added more changes to support SP

This commit is contained in:
daniel oeh 2014-10-17 22:07:03 +02:00
parent aa535ac240
commit 3a1ced0301
16 changed files with 63 additions and 41 deletions

View File

@ -8,9 +8,10 @@
<uses-permission android:name="android.permission.ACCESS_WIFI_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.RECEIVE_BOOT_COMPLETED" />
<application android:allowBackup="true" <application
android:label="@string/app_name" android:allowBackup="true"
android:icon="@drawable/ic_launcher"> android:icon="@drawable/ic_launcher"
android:label="@string/app_name">
<service <service
android:name=".service.download.DownloadService" android:name=".service.download.DownloadService"
@ -18,12 +19,10 @@
<service <service
android:name=".service.playback.PlaybackService" android:name=".service.playback.PlaybackService"
android:enabled="true" android:enabled="true"
android:exported="true"> android:exported="true"/>
</service>
<service <service
android:name=".service.GpodnetSyncService" android:name=".service.GpodnetSyncService"
android:enabled="true"> android:enabled="true"/>
</service>
<receiver <receiver
android:name=".receiver.MediaButtonReceiver" android:name=".receiver.MediaButtonReceiver"
@ -36,11 +35,6 @@
</intent-filter> </intent-filter>
</receiver> </receiver>
<receiver android:name=".receiver.ConnectivityActionReceiver">
<intent-filter>
<action android:name="android.net.conn.CONNECTIVITY_CHANGE"/>
</intent-filter>
</receiver>
<receiver android:name=".receiver.AlarmUpdateReceiver"> <receiver android:name=".receiver.AlarmUpdateReceiver">
<intent-filter> <intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" /> <action android:name="android.intent.action.BOOT_COMPLETED" />

View File

@ -19,4 +19,6 @@ public interface ApplicationCallbacks {
* activity. * activity.
*/ */
public Intent getStorageErrorActivity(Context context); public Intent getStorageErrorActivity(Context context);
public void setUpateInterval(long upateInterval);
} }

View File

@ -23,6 +23,11 @@ public interface PlaybackServiceCallbacks {
* Returns true if the PlaybackService should load new episodes from the queue when playback ends * 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 * and false if the PlaybackService should ignore the queue and load no more episodes when playback
* finishes. * finishes.
* */ */
public boolean useQueue(); public boolean useQueue();
/**
* Returns a drawable resource that is used for the notification of the playback service.
*/
public int getNotificationIconResource(Context context);
} }

View File

@ -20,6 +20,7 @@ import java.util.List;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import de.danoeh.antennapod.core.BuildConfig; import de.danoeh.antennapod.core.BuildConfig;
import de.danoeh.antennapod.core.ClientConfig;
import de.danoeh.antennapod.core.R; import de.danoeh.antennapod.core.R;
import de.danoeh.antennapod.core.receiver.FeedUpdateReceiver; import de.danoeh.antennapod.core.receiver.FeedUpdateReceiver;
@ -329,7 +330,7 @@ public class UserPreferences implements
} else if (key.equals(PREF_UPDATE_INTERVAL)) { } else if (key.equals(PREF_UPDATE_INTERVAL)) {
updateInterval = readUpdateInterval(sp.getString( updateInterval = readUpdateInterval(sp.getString(
PREF_UPDATE_INTERVAL, "0")); PREF_UPDATE_INTERVAL, "0"));
restartUpdateAlarm(updateInterval); ClientConfig.applicationCallbacks.setUpateInterval(updateInterval);
} else if (key.equals(PREF_AUTO_DELETE)) { } else if (key.equals(PREF_AUTO_DELETE)) {
autoDelete = sp.getBoolean(PREF_AUTO_DELETE, false); 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. * 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(); instanceAvailable();
if (BuildConfig.DEBUG) if (BuildConfig.DEBUG)
Log.d(TAG, "Restarting update alarm. New value: " + millis); Log.d(TAG, "Restarting update alarm.");
AlarmManager alarmManager = (AlarmManager) instance.context AlarmManager alarmManager = (AlarmManager) instance.context
.getSystemService(Context.ALARM_SERVICE); .getSystemService(Context.ALARM_SERVICE);
PendingIntent updateIntent = PendingIntent.getBroadcast( PendingIntent updateIntent = PendingIntent.getBroadcast(
instance.context, 0, new Intent( instance.context, 0, new Intent(
FeedUpdateReceiver.ACTION_REFRESH_FEEDS), 0 FeedUpdateReceiver.ACTION_REFRESH_FEEDS), 0);
);
alarmManager.cancel(updateIntent); alarmManager.cancel(updateIntent);
if (millis != 0) { if (intervalMillis != 0) {
alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, millis, millis, alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, triggerAtMillis, intervalMillis,
updateIntent); updateIntent);
if (BuildConfig.DEBUG) if (BuildConfig.DEBUG)
Log.d(TAG, "Changed alarm to new interval"); 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. * Reads episode cache size as it is saved in the episode_cache_size_values array.
*/ */

View File

@ -8,6 +8,7 @@ import android.util.Log;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import de.danoeh.antennapod.core.BuildConfig; import de.danoeh.antennapod.core.BuildConfig;
import de.danoeh.antennapod.core.ClientConfig;
import de.danoeh.antennapod.core.preferences.UserPreferences; import de.danoeh.antennapod.core.preferences.UserPreferences;
/** Listens for events that make it necessary to reset the update alarm. */ /** 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"); Log.d(TAG, "Resetting update alarm after app upgrade");
} }
UserPreferences.restartUpdateAlarm(UserPreferences.getUpdateInterval()); ClientConfig.applicationCallbacks.setUpateInterval(UserPreferences.getUpdateInterval());
} }

View File

@ -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 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 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_PLAYER_STATUS_CHANGED = "com.android.music.playstatechanged";
private static final String AVRCP_ACTION_META_CHANGED = "com.android.music.metachanged"; 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)); sendBroadcast(new Intent(ACTION_PLAYER_STATUS_CHANGED));
updateWidget(); updateWidget();
refreshRemoteControlClientState(newInfo); refreshRemoteControlClientState(newInfo);
@ -694,8 +698,8 @@ public class PlaybackService extends Service {
} }
if (icon == null) { if (icon == null) {
icon = BitmapFactory.decodeResource(getResources(), icon = BitmapFactory.decodeResource(getApplicationContext().getResources(),
R.drawable.ic_stat_antenna); ClientConfig.playbackServiceCallbacks.getNotificationIconResource(getApplicationContext()));
} }
return null; return null;
@ -708,6 +712,8 @@ public class PlaybackService extends Service {
return; return;
} }
PlaybackServiceMediaPlayer.PSMPInfo newInfo = mediaPlayer.getPSMPInfo(); PlaybackServiceMediaPlayer.PSMPInfo newInfo = mediaPlayer.getPSMPInfo();
final int smallIcon = ClientConfig.playbackServiceCallbacks.getNotificationIconResource(getApplicationContext());
if (!isCancelled() && info.playerStatus == PlayerStatus.PLAYING if (!isCancelled() && info.playerStatus == PlayerStatus.PLAYING
&& info.playable != null) { && info.playable != null) {
String contentText = info.playable.getFeedTitle(); String contentText = info.playable.getFeedTitle();
@ -730,7 +736,7 @@ public class PlaybackService extends Service {
.setOngoing(true) .setOngoing(true)
.setContentIntent(pIntent) .setContentIntent(pIntent)
.setLargeIcon(icon) .setLargeIcon(icon)
.setSmallIcon(R.drawable.ic_stat_antenna) .setSmallIcon(smallIcon)
.addAction(android.R.drawable.ic_media_pause, .addAction(android.R.drawable.ic_media_pause,
getString(R.string.pause_label), getString(R.string.pause_label),
pauseButtonPendingIntent); pauseButtonPendingIntent);
@ -741,7 +747,7 @@ public class PlaybackService extends Service {
.setContentTitle(contentTitle) .setContentTitle(contentTitle)
.setContentText(contentText).setOngoing(true) .setContentText(contentText).setOngoing(true)
.setContentIntent(pIntent).setLargeIcon(icon) .setContentIntent(pIntent).setLargeIcon(icon)
.setSmallIcon(R.drawable.ic_stat_antenna); .setSmallIcon(smallIcon);
notification = notificationBuilder.getNotification(); notification = notificationBuilder.getNotification();
} }
if (newInfo.playerStatus == PlayerStatus.PLAYING) { if (newInfo.playerStatus == PlayerStatus.PLAYING) {

View File

@ -10,5 +10,15 @@ public enum PlayerStatus {
PREPARED, PREPARED,
SEEKING, SEEKING,
INITIALIZING, // playback service is loading the Playable's metadata 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];
}
} }

View File

@ -394,6 +394,12 @@ public abstract class PlaybackController {
public abstract void onPlaybackEnd(); public abstract void onPlaybackEnd();
public void repeatHandleStatus() {
if (status != null && playbackService != null) {
handleStatus();
}
}
/** /**
* Is called whenever the PlaybackService changes it's status. This method * Is called whenever the PlaybackService changes it's status. This method
* should be used to update the GUI or start/cancel background threads. * should be used to update the GUI or start/cancel background threads.

View File

Before

Width:  |  Height:  |  Size: 678 B

After

Width:  |  Height:  |  Size: 678 B

View File

Before

Width:  |  Height:  |  Size: 649 B

After

Width:  |  Height:  |  Size: 649 B

View File

Before

Width:  |  Height:  |  Size: 307 B

After

Width:  |  Height:  |  Size: 307 B

View File

Before

Width:  |  Height:  |  Size: 271 B

After

Width:  |  Height:  |  Size: 271 B

View File

Before

Width:  |  Height:  |  Size: 414 B

After

Width:  |  Height:  |  Size: 414 B

View File

Before

Width:  |  Height:  |  Size: 412 B

After

Width:  |  Height:  |  Size: 412 B

View File

Before

Width:  |  Height:  |  Size: 1005 B

After

Width:  |  Height:  |  Size: 1005 B

View File

Before

Width:  |  Height:  |  Size: 942 B

After

Width:  |  Height:  |  Size: 942 B