Example usage for android.graphics.drawable TransitionDrawable invalidateSelf

List of usage examples for android.graphics.drawable TransitionDrawable invalidateSelf

Introduction

In this page you can find the example usage for android.graphics.drawable TransitionDrawable invalidateSelf.

Prototype

public void invalidateSelf() 

Source Link

Document

Use the current Callback implementation to have this Drawable redrawn.

Usage

From source file:com.xmobileapp.rockplayer.RockPlayer.java

/*************************************
 * //from ww  w . jav  a2 s.  co m
 * playPauseClickListenerHelper
 * 
 *************************************/
public void playPauseClickListenerHelper() {
    try {
        // TODO: UI related updates----
        //   these are just mockups
        if (playerServiceIface.isPlaying()) {
            playerServiceIface.pause();
            //            AlphaAnimation albumPlayingFadeOut = new AlphaAnimation((float)1.0, (float)0.66);
            //            albumPlayingFadeOut.setFillAfter(true);
            //            albumPlayingFadeOut.setDuration(200);
            //            currentAlbumPlayingLayout.startAnimation(albumPlayingFadeOut);
            //playPauseImage.setImageResource(android.R.drawable.ic_media_play);
            TransitionDrawable playPauseTDrawable = (TransitionDrawable) playPauseImage.getDrawable();
            playPauseTDrawable.setCrossFadeEnabled(true);
            playPauseTDrawable.reverseTransition(300);
            playPauseTDrawable.invalidateSelf();
            invalidateCurrentSongLayout.sendEmptyMessageDelayed(0, 50);
            invalidateCurrentSongLayout.sendEmptyMessageDelayed(0, 100);
            invalidateCurrentSongLayout.sendEmptyMessageDelayed(0, 150);
            invalidateCurrentSongLayout.sendEmptyMessageDelayed(0, 200);
            invalidateCurrentSongLayout.sendEmptyMessageDelayed(0, 250);
            //            TransitionDrawable playPauseBgTDrawable = (TransitionDrawable) playPauseImage.getBackground();
            //            playPauseBgTDrawable.startTransition(500);
            //            playPauseBgTDrawable.invalidateSelf();
            //            playPauseOverlayHandler.sendEmptyMessageDelayed(0, 500);
            //            currentAlbumPlayingLayout.invalidate();
            //TODO: reverse transition with an handler
            //            
            //            playPauseImageOverlay.setVisibility(View.VISIBLE);
            //            AlphaAnimation playPauseImageOverlayFadeIn = new AlphaAnimation(0.0f, 1.0f);
            //            playPauseImageOverlayFadeIn.setFillAfter(true);
            //            playPauseImageOverlayFadeIn.setDuration(200);
            //            playPauseImageOverlayFadeIn.setAnimationListener(playPauseOverlayFadeInAnimationListener);
            //            playPauseImageOverlay.startAnimation(playPauseImageOverlayFadeIn);
            //currentAlbumPlayingLayout.setBackgroundColor(Color.argb(128, 255, 255, 255));
            if (songProgressTimer != null)
                songProgressTimer.cancel();
        } else {
            //playerServiceIface.resume(); - use a delayed timer to not interfere with the button animations
            Message msg = new Message();
            msg.what = 0;
            playerServiceResumeHandler.sendMessageDelayed(new Message(), 900);
            //            AlphaAnimation albumPlayingFadeIn = new AlphaAnimation((float)0.66, (float)1.0);
            //            albumPlayingFadeIn.setFillAfter(true);
            //            albumPlayingFadeIn.setDuration(200);
            //            currentAlbumPlayingLayout.startAnimation(albumPlayingFadeIn);
            //playPauseImage.setImageResource(android.R.drawable.ic_media_pause);
            TransitionDrawable playPauseTDrawable = (TransitionDrawable) playPauseImage.getDrawable();
            playPauseTDrawable.setCrossFadeEnabled(true);
            playPauseTDrawable.startTransition(500);
            playPauseTDrawable.invalidateSelf();
            invalidateCurrentSongLayout.sendEmptyMessageDelayed(0, 150);
            invalidateCurrentSongLayout.sendEmptyMessageDelayed(0, 300);
            invalidateCurrentSongLayout.sendEmptyMessageDelayed(0, 450);
            invalidateCurrentSongLayout.sendEmptyMessageDelayed(0, 600);
            invalidateCurrentSongLayout.sendEmptyMessageDelayed(0, 750);
            //            TransitionDrawable playPauseBgTDrawable = (TransitionDrawable) playPauseImage.getBackground();
            //            playPauseBgTDrawable.startTransition(500);
            //            playPauseBgTDrawable.invalidateSelf();
            //            playPauseOverlayHandler.sendEmptyMessageDelayed(0, 500);
            //            currentAlbumPlayingLayout.invalidate();
            //TODO: reverse transition with an handler
            //            
            //            playPauseImageOverlay.setVisibility(View.VISIBLE);
            //            AlphaAnimation playPauseImageOverlayFadeIn = new AlphaAnimation(0.0f, 1.0f);
            //            playPauseImageOverlayFadeIn.setFillAfter(true);
            //            playPauseImageOverlayFadeIn.setDuration(250);
            //            playPauseImageOverlayFadeIn.setAnimationListener(playPauseOverlayFadeInAnimationListener);
            //            playPauseImageOverlay.startAnimation(playPauseImageOverlayFadeIn);
            //currentAlbumPlayingLayout.setBackgroundColor(Color.argb(0, 255, 255, 255));
            //Log.i("RES", "1");
            //            songProgressTimer = new Timer();
            //            Log.i("RES", "7");
            //            songProgressTimer.scheduleAtFixedRate(new SongProgressTimerTask(), 100, 1000);
            //            Log.i("RES", "8");
            updateSongTextUI(); // starts the progress timer
            //triggerSongProgress();
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:com.xmobileapp.rockplayer.RockPlayer.java

/*********************************************
 * //from  w  w w .  j av a2s .c  o m
 * getCurrentPlaying
 *    get what the player service is currently
 *    playing and update UI
 *
 *********************************************/
public void getCurrentPlaying() {
    //if(true) return;

    /*
     * ask the player service if/what he is playing
     */
    int albumCursorPosition = 0;
    int songCursorPosition = 0;
    try {
        albumCursorPosition = this.playerServiceIface.getAlbumCursorPosition();
        songCursorPosition = this.playerServiceIface.getSongCursorPosition();
    } catch (RemoteException e) {
        e.printStackTrace();
    }
    if (albumCursorPosition == -1 || songCursorPosition == -1) {
        //         Log.i("GETCURPLAY", "BOTH CURSORS ARE -1");
        //         try{
        //            Random rand = new Random();
        //            if(albumCursor != null && rand != null)
        //               albumCursorPosition = rand.nextInt(albumCursor.getCount()-1);
        //            else
        //               albumCursorPosition = 1;
        //            albumCursorPositionPlaying = albumCursorPosition;
        //            songCursorPosition = 0;
        //         } catch (Exception e) {
        //            try{
        //               if(albumCursor != null)
        //                  Log.i("EXCP", ""+albumCursor.getCount());
        //            } catch (Exception ee){
        //               ee.printStackTrace();
        //            }
        //            e.printStackTrace();
        //            albumCursorPosition = 0;
        //            albumCursorPositionPlaying = albumCursorPosition;
        //            songCursorPosition = 0;
        //         }
        //         try {
        //            playerServiceIface.setAlbumCursorPosition(albumCursorPosition);
        //            playerServiceIface.setSongCursorPosition(songCursorPosition);
        //            playerServiceIface.play(albumCursorPosition, songCursorPosition);
        //            playerServiceIface.pause();
        //            // HACKzzzzzzzzz we need a paused event from the service
        //            this.stopSongProgress();
        //         } catch (RemoteException e) {
        //            e.printStackTrace();
        //         }
    } else {
        try {
            if (playerServiceIface.isPlaying()) {
                TransitionDrawable playPauseTDrawable = (TransitionDrawable) playPauseImage.getDrawable();
                playPauseTDrawable.setCrossFadeEnabled(true);
                playPauseTDrawable.startTransition(1);
                playPauseTDrawable.invalidateSelf();
                //                this.playPauseImage.setImageResource(android.R.drawable.ic_media_pause);          }
            } else {
                albumCursorPosition = playerServiceIface.getAlbumCursorPosition();
                songCursorPosition = playerServiceIface.getSongCursorPosition();
                albumCursorPositionPlaying = albumCursorPosition;

                //               Log.i("INIT", albumCursorPosition+" "+songCursorPosition);
                //               playerServiceIface.play(albumCursorPositionPlaying,
                //                                 songCursorPosition);
                //               playerServiceIface.pause();
                this.stopSongProgress();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    // TODO: ask if he is playing
    /*
     * If media Library is empty just show a popup
     */
    if (albumCursor.getCount() == 0) {
        Dialog noMediaDialog = new Dialog(this);
        noMediaDialog.setTitle("No Media Available");
        //TextView noMediaText = new TextView(this);
        //noMediaText.setText("Please add some Music to your SD Card");
        //noMediaDialog.setContentView(noMediaText);
        noMediaDialog.show();
        return;
    }

    /*
     * Go to the current playing Media
     */
    Log.i("GETCURPLAY", "MOVING CURSORS");

    try {
        albumCursor.moveToPosition(albumCursorPosition);
        albumCursorPositionPlaying = albumCursorPosition;
        songCursor = initializeSongCursor(
                albumCursor.getString(albumCursor.getColumnIndexOrThrow(MediaStore.Audio.Albums.ALBUM)));
        songCursor.moveToPosition(songCursorPosition);
    } catch (Exception e) {
        e.printStackTrace();
    }

    Log.i("GETCURPLAY", "GET ALBUM ART");

    try {
        //         /*
        //          * get albumArt
        //          */
        //         String albumCoverPath = albumCursor.getString(
        //                              albumCursor.getColumnIndexOrThrow(
        //                                 MediaStore.Audio.Albums.ALBUM_ART));
        //          // if it does not exist in database look for our dir
        //          if(albumCoverPath == null){
        //             String artistName = albumCursor.getString(
        //                              albumCursor.getColumnIndexOrThrow(
        //                                    MediaStore.Audio.Albums.ARTIST));
        //             String albumName = albumCursor.getString(
        //                              albumCursor.getColumnIndexOrThrow(
        //                                    MediaStore.Audio.Albums.ALBUM));
        //             String path = this.FILEX_ALBUM_ART_PATH+
        //                         validateFileName(artistName)+
        //                        " - "+
        //                        validateFileName(albumName)+
        //                        FILEX_FILENAME_EXTENSION;
        //             File albumCoverFilePath = new File(path);
        //            if(albumCoverFilePath.exists() && albumCoverFilePath.length() > 0){
        //               albumCoverPath = path;
        //            }
        //          }
        //          
        //          Log.i("GETCURPLAY", "UPDATING UI COMPONENT");
        //
        //           /*
        //           * Update currentPlaying albumArt UI component
        //           */
        //         if(albumCoverPath != null){
        //            // TODO:
        //            // adjust sample size
        //            Options opts = new Options();
        //            opts.inSampleSize = 1;
        //            Bitmap albumCoverBitmap = BitmapFactory.decodeFile(albumCoverPath, opts);
        //            this.currentAlbumPlayingImageView.setImageBitmap(albumCoverBitmap);
        //         } else {
        //            // TODO:
        //            // adjust sample size dynamically
        //            Options opts = new Options();
        //            opts.inSampleSize = 1;
        //            Bitmap albumCoverBitmap = BitmapFactory.decodeResource(this.context.getResources(),
        //                                                R.drawable.albumart_mp_unknown, opts);
        //            if(albumCoverBitmap != null)
        //               this.currentAlbumPlayingImageView.setImageBitmap(albumCoverBitmap);
        //         }

        if (VIEW_STATE == FULLSCREEN_VIEW)
            this.currentAlbumPlayingImageView.setImageBitmap(
                    albumAdapter.getAlbumBitmap(albumCursor.getPosition(), BITMAP_SIZE_FULLSCREEN));
        else
            this.currentAlbumPlayingImageView
                    .setImageBitmap(albumAdapter.getAlbumBitmap(albumCursor.getPosition(), BITMAP_SIZE_NORMAL));

        if (showFrame)
            this.currentAlbumPlayingOverlayImageView.setVisibility(View.VISIBLE);
        else
            this.currentAlbumPlayingOverlayImageView.setVisibility(View.GONE);

        Log.i("GETCURPLAY", "UPDATING REST OF UI");

        /*
         * Update currentPlaying artist UI component
         */
        this.updateArtistTextUI();
        /*
         * Update currentPlaying song UI component
         */
        this.updateSongTextUI();
        /*
         * Update Song Progress
         */
        this.updateSongProgress();

        Log.i("GETCURPLAY", "CENTER ALBUMLIST");

        /*
         * Center Album List
         */
        albumNavigatorList.setSelectionFromTop(albumCursorPositionPlaying,
                (int) Math.round((display.getHeight() - 20) / 2.0
                        - (display.getWidth() * (1 - CURRENT_PLAY_SCREEN_FRACTION_LANDSCAPE))));
        this.albumNavigatorScrollListener.onScrollStateChanged(this.albumNavigatorList,
                OnScrollListener.SCROLL_STATE_IDLE);

    } catch (Exception e) {
        e.printStackTrace();
    }
}