Android Open Source - audioplayer Prompt Covers






From Project

Back to project page audioplayer.

License

The source code is released under:

GNU General Public License

If you think the Android project audioplayer listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package fr.julien_dumortier.simplemusicplayer.coveralbumeditor;
/*from  www  . j a  va2s.  c o  m*/
import java.util.List;
import fr.julien_dumortier.simplemusicplayer.R;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.drawable.BitmapDrawable;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.ImageView;
import android.widget.Toast;
import android.widget.ViewFlipper;

public class PromptCovers extends AlertDialog {
  
  private Activity mContext; 
    private ViewFlipper viewFlipper;
    private float lastX;
    private List<String> mUrls;
    private IOnCoverSelectedListener mListener;
    
    public interface IOnCoverSelectedListener {
      public void onCoverSelected(Bitmap bmp);
    }

  public PromptCovers(Activity context, List<String> coverUrls, IOnCoverSelectedListener listener) {
    super(context);
    mListener = listener;
    mContext = context;
    mUrls = coverUrls;
    setTitle(context.getResources().getString(R.string.cover_choice));
    viewFlipper = new ViewFlipper(mContext);
    Toast.makeText(mContext, mContext.getResources().getString(R.string.swipe_to_choice), Toast.LENGTH_LONG).show();
    for(int i=0; i<mUrls.size(); i++) {
      View v = LayoutInflater.from(context).inflate(R.layout.prompt_covers, null);
      viewFlipper.addView(v, i);
    }

    startSetCoverInImageView();
    
    setView(viewFlipper);
    setButton(context.getResources().getText(R.string.ok), new OnClickListener() {
      public void onClick(DialogInterface dialog, int which) {
        if(viewFlipper!=null) {
          View v = viewFlipper.getCurrentView();
          if(v!=null) {
            ImageView iv = (ImageView) v.findViewById(R.id.cover_image);
            Bitmap bmp = null;
            if(iv.getDrawable()!=null)
              bmp = ((BitmapDrawable)iv.getDrawable()).getBitmap();
            
            if(bmp == null) {
              int realPos = 0;
              int size = viewFlipper.getChildCount();
              for(int pos = 0;pos<size;pos++) {
                if(v.equals(getChildPos(pos)))
                  realPos=pos;  
              }
              try {
                bmp = getBitmapFromUrl(mUrls.get(realPos));
              } catch (Exception e) {}
            }
            if(bmp!=null)
              mListener.onCoverSelected(bmp);
          }
        }
      }
    });
    setButton2(context.getResources().getText(R.string.cancel), new OnClickListener() {
      public void onClick(DialogInterface dialog, int which) {}});
    
  }
  
  public boolean onTouchEvent(MotionEvent touchevent) 
    {
             switch (touchevent.getAction())
             {
                    // when user first touches the screen to swap
                     case MotionEvent.ACTION_DOWN: 
                     {
                         lastX = touchevent.getX();
                         break;
                    }
                     case MotionEvent.ACTION_UP: 
                     {
                         float currentX = touchevent.getX();
                         
                         // if left to right swipe on screen
                         if (lastX < currentX-20) 
                         {
                              // If no more View/Child to flip
                             if (viewFlipper.getDisplayedChild() == 0)
                                 break;
                             
                             // set the required Animation type to ViewFlipper
                             // The Next screen will come in form Left and current Screen will go OUT from Right 
                             viewFlipper.setInAnimation(mContext, R.anim.in_from_left);
                             viewFlipper.setOutAnimation(mContext, R.anim.out_to_right);
                             // Show the next Screen
                             viewFlipper.showNext();
                         }
                         
                         // if right to left swipe on screen
                         if (lastX > currentX+20)
                         {
                             if (viewFlipper.getDisplayedChild() == 1)
                                 break;
                             // set the required Animation type to ViewFlipper
                             // The Next screen will come in form Right and current Screen will go OUT from Left 
                             viewFlipper.setInAnimation(mContext, R.anim.in_from_right);
                             viewFlipper.setOutAnimation(mContext, R.anim.out_to_left);
                             // Show The Previous Screen
                             viewFlipper.showPrevious();
                         }
                         break;
                     }
             }
             return false;
    }
  
  private int mCurrentPos;
  private Bitmap mTmpBitmap;
  private void startSetCoverInImageView() {
    new Thread("Thread get cover at pos"+mCurrentPos) {
      public void run() {
        int size = viewFlipper.getChildCount();
        for(int pos = 0; pos<size;pos++) {
          View v = getChildPos(pos);
          final ImageView coverImage = (ImageView)v.findViewById(R.id.cover_image);
          final ImageView loadImage = (ImageView) v.findViewById(R.id.load);
          
          mContext.runOnUiThread(new Runnable() {
            public void run() {
              loadImage.setVisibility(View.VISIBLE);
              final Animation rotateAnimation = AnimationUtils.loadAnimation(mContext, R.anim.rotate_animation);
              rotateAnimation.setRepeatCount(Animation.INFINITE);
              loadImage.startAnimation(rotateAnimation);
            }
          });
          try {
            mTmpBitmap = getBitmapFromUrl(mUrls.get(pos));
          } catch (Exception e) {
            mTmpBitmap = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.failed_job);
          }
          mContext.runOnUiThread(new Runnable() {
            public void run() {
              coverImage.setImageBitmap(mTmpBitmap);
              loadImage.setVisibility(View.INVISIBLE);
              loadImage.clearAnimation();
            }
          });
        }
      }
    }.start();
  }
  
  private View getChildPos(int pos) {
    if(pos==0)
      return viewFlipper.getChildAt(0);
    return viewFlipper.getChildAt(viewFlipper.getChildCount()-pos);
  }
  
  private static Bitmap getBitmapFromUrl(String url) throws Exception {
    byte [] data = CoverAlbumEditor.downloadUrlToByteArray(url);
    return BitmapFactory.decodeByteArray(data, 0, data.length);
  }
}




Java Source Code List

fr.julien_dumortier.simplemusicplayer.DevInfo.java
fr.julien_dumortier.simplemusicplayer.DrawerListAdapter.java
fr.julien_dumortier.simplemusicplayer.IMusicMediaControllerGetter.java
fr.julien_dumortier.simplemusicplayer.MainActivity.java
fr.julien_dumortier.simplemusicplayer.browsemanager.BrowseCover.java
fr.julien_dumortier.simplemusicplayer.browsemanager.BrowseManager.java
fr.julien_dumortier.simplemusicplayer.coveralbumeditor.CoverAlbumEditor.java
fr.julien_dumortier.simplemusicplayer.coveralbumeditor.CoverAlbumGetter.java
fr.julien_dumortier.simplemusicplayer.coveralbumeditor.PromptCovers.java
fr.julien_dumortier.simplemusicplayer.equalizer.EqualizerActivity.java
fr.julien_dumortier.simplemusicplayer.equalizer.EqualizerConfigurationDataBase.java
fr.julien_dumortier.simplemusicplayer.equalizer.VerticalSeekBar.java
fr.julien_dumortier.simplemusicplayer.equalizer.preset.Preset.java
fr.julien_dumortier.simplemusicplayer.item.Album.java
fr.julien_dumortier.simplemusicplayer.item.Artist.java
fr.julien_dumortier.simplemusicplayer.item.Genre.java
fr.julien_dumortier.simplemusicplayer.item.Item.java
fr.julien_dumortier.simplemusicplayer.item.Playlist.java
fr.julien_dumortier.simplemusicplayer.item.Track.java
fr.julien_dumortier.simplemusicplayer.item.itemadapter.AlbumAdapter.java
fr.julien_dumortier.simplemusicplayer.item.itemadapter.ArtistAdapter.java
fr.julien_dumortier.simplemusicplayer.item.itemadapter.CurrentPlayAnimationManager.java
fr.julien_dumortier.simplemusicplayer.item.itemadapter.GenreAdapter.java
fr.julien_dumortier.simplemusicplayer.item.itemadapter.ItemAdapter.java
fr.julien_dumortier.simplemusicplayer.item.itemadapter.ItemClicManager.java
fr.julien_dumortier.simplemusicplayer.item.itemadapter.OrganisableTrackAdapter.java
fr.julien_dumortier.simplemusicplayer.item.itemadapter.PlayListAdapter.java
fr.julien_dumortier.simplemusicplayer.item.itemadapter.TrackAdapter.java
fr.julien_dumortier.simplemusicplayer.notifynews.NotifyNews.java
fr.julien_dumortier.simplemusicplayer.playerview.FullScreenPlayerViewController.java
fr.julien_dumortier.simplemusicplayer.playerview.IPlayerViewController.java
fr.julien_dumortier.simplemusicplayer.playerview.MiniPlayerViewController.java
fr.julien_dumortier.simplemusicplayer.playerview.TimeFormater.java
fr.julien_dumortier.simplemusicplayer.playlistview.MultiSelectManager.java
fr.julien_dumortier.simplemusicplayer.playlistview.PlayListManagerActivity.java
fr.julien_dumortier.simplemusicplayer.playlistview.SaveManagerView.java
fr.julien_dumortier.simplemusicplayer.playlistview.SavedPlaylistManager.java
fr.julien_dumortier.simplemusicplayer.service.BackgroundBinder.java
fr.julien_dumortier.simplemusicplayer.service.MusicPlayerService.java
fr.julien_dumortier.simplemusicplayer.service.bluetoohactionmanager.BluetoothReceiver.java
fr.julien_dumortier.simplemusicplayer.service.notificationplayer.NotificationManagerService.java
fr.julien_dumortier.simplemusicplayer.service.notificationplayer.NotificationPlayer.java
fr.julien_dumortier.simplemusicplayer.service.phonestatemanager.PhoneCallStateManager.java
fr.julien_dumortier.simplemusicplayer.service.playlist.EndOfPlayListException.java
fr.julien_dumortier.simplemusicplayer.service.playlist.IMediaPlayerController.java
fr.julien_dumortier.simplemusicplayer.service.playlist.MusicMediaPlayer.java
fr.julien_dumortier.simplemusicplayer.service.playlist.PlayListManager.java
fr.julien_dumortier.simplemusicplayer.thememanager.ColorPreferences.java
fr.julien_dumortier.simplemusicplayer.thememanager.DisplayManager2.java
fr.julien_dumortier.simplemusicplayer.thememanager.ManageDisplayView.java
fr.julien_dumortier.simplemusicplayer.uiprompt.PromptActionByType.java
fr.julien_dumortier.simplemusicplayer.uiprompt.PromptActionPlaylist.java
fr.julien_dumortier.simplemusicplayer.uiprompt.PromptConfirmAddInNew.java
fr.julien_dumortier.simplemusicplayer.uiprompt.PromptConfirmDeletePlaylist.java
fr.julien_dumortier.simplemusicplayer.uiprompt.PromptConfirmExit.java
fr.julien_dumortier.simplemusicplayer.uiprompt.PromptConfirmReplacePlaylist.java
fr.julien_dumortier.simplemusicplayer.uiprompt.PromptDefineCoverAlbum.java
fr.julien_dumortier.simplemusicplayer.uiprompt.PromptGetTextName.java
fr.julien_dumortier.simplemusicplayer.uiprompt.PromptMoveTrack.java
fr.julien_dumortier.simplemusicplayer.uiprompt.PromptPlaylistName.java
fr.julien_dumortier.simplemusicplayer.uiprompt.PromptShowText.java
fr.julien_dumortier.simplemusicplayer.uiprompt.PromptSuppressConfirm.java
fr.julien_dumortier.simplemusicplayer.widget.AudioPlayerApplication.java
fr.julien_dumortier.simplemusicplayer.widget.AudioPlayerWidgetProvider.java
fr.julien_dumortier.simplemusicplayer.widget.AudioPlayerWidgetViewController.java
fr.julien_dumortier.simplemusicplayer.widget.WidgetView.java