@Override
  protected void onSongChange(Song song) {
    super.onSongChange(song);

    setDuration(song == null ? 0 : song.duration);

    if (mTitle != null) {
      if (song == null) {
        mTitle.setText(null);
        mAlbum.setText(null);
        mArtist.setText(null);
      } else {
        mTitle.setText(song.title);
        mAlbum.setText(song.album);
        mArtist.setText(song.artist);
      }
      updateQueuePosition();
    }

    mCurrentSong = song;
    updateElapsedTime();

    if (mExtraInfoVisible) {
      mHandler.sendEmptyMessage(MSG_LOAD_EXTRA_INFO);
    }
  }
 @Override
 public void onClick(View view) {
   if (view == mOverlayText && (mState & PlaybackService.FLAG_EMPTY_QUEUE) != 0) {
     setState(PlaybackService.get(this).setFinishAction(SongTimeline.FINISH_RANDOM));
   } else if (view == mCoverView) {
     performAction(mCoverPressAction);
   } else if (view.getId() == R.id.info_table) {
     openLibrary(mCurrentSong);
   } else {
     super.onClick(view);
   }
 }
  @Override
  public void onStart() {
    super.onStart();

    SharedPreferences settings = PlaybackService.getSettings(this);
    if (mDisplayMode != Integer.parseInt(settings.getString(PrefKeys.DISPLAY_MODE, "2"))) {
      finish();
      startActivity(new Intent(this, FullPlaybackActivity.class));
    }

    mCoverPressAction =
        Action.getAction(settings, PrefKeys.COVER_PRESS_ACTION, Action.ToggleControls);
    mCoverLongPressAction =
        Action.getAction(settings, PrefKeys.COVER_LONGPRESS_ACTION, Action.PlayPause);
  }
 @Override
 public boolean onCreateOptionsMenu(Menu menu) {
   if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
     menu.add(0, MENU_LIBRARY, 0, R.string.library).setIcon(R.drawable.ic_menu_music_library);
   }
   super.onCreateOptionsMenu(menu);
   menu.add(0, MENU_CLEAR_QUEUE, 0, R.string.clear_queue)
       .setIcon(R.drawable.ic_menu_close_clear_cancel);
   menu.add(0, MENU_ENQUEUE_ALBUM, 0, R.string.enqueue_current_album)
       .setIcon(R.drawable.ic_menu_add);
   menu.add(0, MENU_ENQUEUE_ARTIST, 0, R.string.enqueue_current_artist)
       .setIcon(R.drawable.ic_menu_add);
   menu.add(0, MENU_ENQUEUE_GENRE, 0, R.string.enqueue_current_genre)
       .setIcon(R.drawable.ic_menu_add);
   menu.add(0, MENU_TOGGLE_CONTROLS, 0, R.string.toggle_controls);
   return true;
 }
  @Override
  protected void onStateChange(int state, int toggled) {
    super.onStateChange(state, toggled);

    if ((toggled & (PlaybackService.FLAG_NO_MEDIA | PlaybackService.FLAG_EMPTY_QUEUE)) != 0) {
      if ((state & PlaybackService.FLAG_NO_MEDIA) != 0) {
        showOverlayMessage(R.string.no_songs);
      } else if ((state & PlaybackService.FLAG_EMPTY_QUEUE) != 0) {
        showOverlayMessage(R.string.empty_queue);
      } else {
        hideMessageOverlay();
      }
    }

    if ((state & PlaybackService.FLAG_PLAYING) != 0) updateElapsedTime();

    if (mQueuePosView != null) updateQueuePosition();
  }
  @Override
  public void onCreate(Bundle icicle) {
    super.onCreate(icicle);

    setTitle(R.string.playback_view);

    SharedPreferences settings = PlaybackService.getSettings(this);
    int displayMode = Integer.parseInt(settings.getString(PrefKeys.DISPLAY_MODE, "2"));
    mDisplayMode = displayMode;

    int layout = R.layout.full_playback;
    int coverStyle;

    switch (displayMode) {
      default:
        Log.w("VanillaMusic", "Invalid display mode given. Defaulting to widget mode.");
        // fall through
      case DISPLAY_INFO_WIDGETS:
        coverStyle = CoverBitmap.STYLE_NO_INFO;
        layout = R.layout.full_playback_alt;
        break;
      case DISPLAY_INFO_OVERLAP:
        coverStyle = CoverBitmap.STYLE_OVERLAPPING_BOX;
        break;
      case DISPLAY_INFO_BELOW:
        coverStyle = CoverBitmap.STYLE_INFO_BELOW;
        break;
    }

    setContentView(layout);

    CoverView coverView = (CoverView) findViewById(R.id.cover_view);
    coverView.setup(mLooper, this, coverStyle);
    coverView.setOnClickListener(this);
    coverView.setOnLongClickListener(this);
    mCoverView = coverView;

    mControlsBottom = findViewById(R.id.controls_bottom);
    View previousButton = findViewById(R.id.previous);
    previousButton.setOnClickListener(this);
    mPlayPauseButton = (ImageButton) findViewById(R.id.play_pause);
    mPlayPauseButton.setOnClickListener(this);
    View nextButton = findViewById(R.id.next);
    nextButton.setOnClickListener(this);

    TableLayout table = (TableLayout) findViewById(R.id.info_table);
    if (table != null) {
      table.setOnClickListener(this);
      table.setOnLongClickListener(this);
      mInfoTable = table;
    }

    mTitle = (TextView) findViewById(R.id.title);
    mAlbum = (TextView) findViewById(R.id.album);
    mArtist = (TextView) findViewById(R.id.artist);

    mControlsTop = findViewById(R.id.controls_top);
    mElapsedView = (TextView) findViewById(R.id.elapsed);
    mDurationView = (TextView) findViewById(R.id.duration);
    mSeekBar = (SeekBar) findViewById(R.id.seek_bar);
    mSeekBar.setMax(1000);
    mSeekBar.setOnSeekBarChangeListener(this);
    mQueuePosView = (TextView) findViewById(R.id.queue_pos);

    mGenreView = (TextView) findViewById(R.id.genre);
    mTrackView = (TextView) findViewById(R.id.track);
    mYearView = (TextView) findViewById(R.id.year);
    mComposerView = (TextView) findViewById(R.id.composer);
    mFormatView = (TextView) findViewById(R.id.format);

    mShuffleButton = (ImageButton) findViewById(R.id.shuffle);
    mShuffleButton.setOnClickListener(this);
    registerForContextMenu(mShuffleButton);
    mEndButton = (ImageButton) findViewById(R.id.end_action);
    mEndButton.setOnClickListener(this);
    registerForContextMenu(mEndButton);

    setControlsVisible(settings.getBoolean(PrefKeys.VISIBLE_CONTROLS, true));
    setExtraInfoVisible(settings.getBoolean(PrefKeys.VISIBLE_EXTRA_INFO, false));
    setDuration(0);
  }
 @Override
 public void onPause() {
   super.onPause();
   mPaused = true;
 }
 @Override
 public void onResume() {
   super.onResume();
   mPaused = false;
   updateElapsedTime();
 }