public void onTrackChanged(ICurrentlyPlaying newSong) { final SongAdapter adapter = mSongAdapter; if (adapter != null) { final int currentPos = mCurrentPosition; final int newPos = newSong.getPlaylistPosition(); // clear previous song's icon OneLabelItemView view = adapter.getViewAtPosition(currentPos); if (currentPos >= 0 && view != null) { view.setCover( BitmapFactory.decodeResource(mActivity.getResources(), R.drawable.icon_song_light)); Log.i(TAG, "Resetting previous icon at position " + currentPos + " (" + view.title + ")"); } else { Log.i(TAG, "NOT resetting previous icon at position " + currentPos); } // set new song's play icon view = adapter.getViewAtPosition(newPos); mCurrentPosition = newPos; if (view != null) { view.setCover(BitmapFactory.decodeResource(mActivity.getResources(), R.drawable.icon_play)); } else { mList.setSelection(newPos); } } }
/** * This is called from the thread with a message containing updated info of what's currently * playing. * * @param msg Message object containing currently playing info */ public synchronized boolean handleMessage(Message msg) { final Bundle data = msg.getData(); final ICurrentlyPlaying currentlyPlaying = (ICurrentlyPlaying) data.getSerializable(NowPlayingPollerThread.BUNDLE_CURRENTLY_PLAYING); switch (msg.what) { case NowPlayingPollerThread.MESSAGE_PROGRESS_CHANGED: mPlayStatus = currentlyPlaying.getPlayStatus(); if (currentlyPlaying.isPlaying()) { mPlaylistActivity.setTime(Song.getDuration(currentlyPlaying.getTime() + 1)); } else { mPlaylistActivity.clear(); } return true; case NowPlayingPollerThread.MESSAGE_PLAYLIST_ITEM_CHANGED: mLastPosition = data.getInt(NowPlayingPollerThread.BUNDLE_LAST_PLAYPOSITION); onTrackChanged(currentlyPlaying); return true; case NowPlayingPollerThread.MESSAGE_PLAYSTATE_CHANGED: mPlayListId = data.getInt(NowPlayingPollerThread.BUNDLE_LAST_PLAYLIST); return true; case MESSAGE_PLAYLIST_SIZE: final int size = msg.getData().getInt(BUNDLE_PLAYLIST_SIZE); mPlaylistActivity.setNumItems(size == 0 ? "empty" : size + " tracks"); return true; case NowPlayingPollerThread.MESSAGE_CONNECTION_ERROR: case NowPlayingPollerThread.MESSAGE_RECONFIGURE: mPlayStatus = PlayStatus.UNKNOWN; return true; default: return false; } }