Small fixes

This commit is contained in:
Karim Abou Zeid 2015-03-24 21:56:21 +01:00
commit d3d37ccab3
12 changed files with 26 additions and 17 deletions

View file

@ -83,7 +83,8 @@ public class SongAdapter extends RecyclerView.Adapter<SongAdapter.ViewHolder> {
holder.songTitle.setTextColor(accentColor);
holder.songInfo.setVisibility(View.GONE);
holder.overflowButton.setVisibility(View.GONE);
holder.albumArt.setPadding(48, 48, 48, 48);
final int padding = activity.getResources().getDimensionPixelSize(R.dimen.default_item_margin);
holder.albumArt.setPadding(padding, padding, padding, padding);
holder.albumArt.setColorFilter(accentColor);
holder.albumArt.setImageResource(R.drawable.ic_shuffle_white_48dp);
holder.separator.setVisibility(View.VISIBLE);

View file

@ -46,7 +46,7 @@ public class PlayingNotificationHelper {
R.layout.notification_playing_expanded);
notification = new NotificationCompat.Builder(service)
.setSmallIcon(R.drawable.notification_icon)
.setSmallIcon(R.drawable.ic_audiotrack_white_24dp)
.setContentIntent(getOpenMusicControllerPendingIntent())
.setCategory(NotificationCompat.CATEGORY_PROGRESS)
.setPriority(NotificationCompat.PRIORITY_MAX)

View file

@ -28,9 +28,11 @@ public class MediaButtonIntentReceiver extends BroadcastReceiver {
break;
case KeyEvent.KEYCODE_HEADSETHOOK:
case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
case KeyEvent.KEYCODE_MEDIA_PLAY:
command = MusicService.ACTION_TOGGLE_PLAYBACK;
break;
case KeyEvent.KEYCODE_MEDIA_PLAY:
command = MusicService.ACTION_RESUME;
break;
case KeyEvent.KEYCODE_MEDIA_NEXT:
command = MusicService.ACTION_SKIP;
break;

View file

@ -41,6 +41,7 @@ import java.util.List;
public class MusicService extends Service implements MediaPlayer.OnPreparedListener, MediaPlayer.OnErrorListener, MediaPlayer.OnCompletionListener, AudioManager.OnAudioFocusChangeListener {
public static final String ACTION_TOGGLE_PLAYBACK = "com.kabouzeid.gramophone.action.TOGGLE_PLAYBACK";
public static final String ACTION_PLAY = "com.kabouzeid.gramophone.action.PLAY";
public static final String ACTION_RESUME = "com.kabouzeid.gramophone.action.RESUME";
public static final String ACTION_PAUSE = "com.kabouzeid.gramophone.action.PAUSE";
public static final String ACTION_STOP = "com.kabouzeid.gramophone.action.STOP";
public static final String ACTION_SKIP = "com.kabouzeid.gramophone.action.SKIP";
@ -56,7 +57,7 @@ public class MusicService extends Service implements MediaPlayer.OnPreparedListe
private final BroadcastReceiver receiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
if (intent.getAction().equals(AudioManager.ACTION_AUDIO_BECOMING_NOISY)) {
if (intent.getAction().compareTo(AudioManager.ACTION_AUDIO_BECOMING_NOISY) == 0) {
pausePlaying();
}
}
@ -145,6 +146,9 @@ public class MusicService extends Service implements MediaPlayer.OnPreparedListe
case ACTION_PLAY:
playSong();
break;
case ACTION_RESUME:
resumePlaying();
break;
case ACTION_REWIND:
back();
break;
@ -594,17 +598,19 @@ public class MusicService extends Service implements MediaPlayer.OnPreparedListe
}
public void resumePlaying() {
if (requestFocus()) {
if (isPlayerPrepared) {
player.start();
playingNotificationHelper.updatePlayState(isPlaying());
remoteControlClient.setPlaybackState(RemoteControlClient.PLAYSTATE_PLAYING);
notifyOnMusicRemoteEventListeners(MusicRemoteEvent.RESUME);
if(!isPlaying()) {
if (requestFocus()) {
if (isPlayerPrepared) {
player.start();
playingNotificationHelper.updatePlayState(isPlaying());
remoteControlClient.setPlaybackState(RemoteControlClient.PLAYSTATE_PLAYING);
notifyOnMusicRemoteEventListeners(MusicRemoteEvent.RESUME);
} else {
playSong();
}
} else {
playSong();
Toast.makeText(this, getResources().getString(R.string.audio_focus_denied), Toast.LENGTH_SHORT).show();
}
} else {
Toast.makeText(this, getResources().getString(R.string.audio_focus_denied), Toast.LENGTH_SHORT).show();
}
}