package com.teleca.jamendo.activity;
import java.util.List;
import org.json.JSONException;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.gesture.GestureOverlayView;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.preference.PreferenceManager;
import android.text.TextUtils.TruncateAt;
import android.util.Log;
import android.view.KeyEvent;
import android.view.View;
import android.view.Window;
import android.view.View.OnClickListener;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.view.animation.Animation.AnimationListener;
import android.widget.ImageButton;
import android.widget.ProgressBar;
import android.widget.RatingBar;
import android.widget.SlidingDrawer;
import android.widget.TextView;
import android.widget.Toast;
import com.teleca.jamendo.JamendoApplication;
import com.teleca.jamendo.R;
import com.teleca.jamendo.api.Album;
import com.teleca.jamendo.api.JamendoGet2Api;
import com.teleca.jamendo.api.License;
import com.teleca.jamendo.api.Playlist;
import com.teleca.jamendo.api.PlaylistEntry;
import com.teleca.jamendo.api.PlaylistRemote;
import com.teleca.jamendo.api.Track;
import com.teleca.jamendo.api.WSError;
import com.teleca.jamendo.api.Playlist.PlaylistPlaybackMode;
import com.teleca.jamendo.api.impl.JamendoGet2ApiImpl;
import com.teleca.jamendo.dialog.AddToPlaylistDialog;
import com.teleca.jamendo.dialog.LoadingDialog;
import com.teleca.jamendo.dialog.LyricsDialog;
import com.teleca.jamendo.dialog.PlayerAlbumLoadingDialog;
import com.teleca.jamendo.dialog.PlaylistRemoteLoadingDialog;
import com.teleca.jamendo.media.PlayerEngine;
import com.teleca.jamendo.media.PlayerEngineListener;
import com.teleca.jamendo.util.Helper;
import com.teleca.jamendo.util.OnSeekToListenerImp;
import com.teleca.jamendo.util.SeekToMode;
import com.teleca.jamendo.widget.ReflectableLayout;
import com.teleca.jamendo.widget.ReflectiveSurface;
import com.teleca.jamendo.widget.RemoteImageView;
/**
* Central part of the UI. Touching cover fades in 4-way media buttons. 4-way
* media buttons fade out after certain amount of time. Other parts of layout
* are progress bar, total play time, played time, song title, artist name and
* jamendo slider.<br>
* <br>
*
* License information is implemented overlaying CreativeCommons logo over the
* album picture. Information about type of license is retrieved concurrently to
* track bufferring. 中央部分的UI。 4路多媒体按键触摸盖变淡。 4路媒体按钮淡出后一定的时间。
* 其他部分的布局,进度条,总播放时间,播放时间,歌曲标题, 艺术家姓名和实施jamendo
* slider.License信息叠加在专辑图片CreativeCommons标志。 有关许可证类型的信息检索的同时跟踪bufferring。
*
* @author Lukasz Wisniewski
*/
//播放界面
public class PlayerActivity extends Activity
{
private PlayerEngine getPlayerEngine()
{
return JamendoApplication.getInstance().getPlayerEngineInterface();
};
//播放列表
private Playlist mPlaylist;
//相册
private Album mCurrentAlbum;
// XML layout
private TextView mArtistTextView;
private TextView mSongTextView;
private TextView mCurrentTimeTextView;
private TextView mTotalTimeTextView;
private RatingBar mRatingBar;
private ProgressBar mProgressBar;
private ImageButton mPlayImageButton;
private ImageButton mNextImageButton;
private ImageButton mPrevImageButton;
private ImageButton mStopImageButton;
private ImageButton mShuffleImageButton;
private ImageButton mRepeatImageButton;
private RemoteImageView mCoverImageView;
private RemoteImageView mLicenseImageView;
private GestureOverlayView mGesturesOverlayView;
private Animation mFadeInAnimation;
private Animation mFadeOutAnimation;
private ReflectableLayout mReflectableLayout;
private ReflectiveSurface mReflectiveSurface;
private String mBetterRes;
private SlidingDrawer mSlidingDrawer;
private LoadingDialog mUriLoadingDialog;
SeekToMode seekToMode;
Handler mHandlerOfFadeOutAnimation;
Runnable mRunnableOfFadeOutAnimation;
/**
* Launch this Activity from the outside, with defined playlist
* 从外部启动这项活动,定义播放列表
* @param c
* context from which Activity should be started
* @param a
* playlist to be played
*/
public static void launch(Context c, Playlist playlist)
{
Intent intent = new Intent(c, PlayerActivity.class);
intent.putExtra("playlist", playlist);
/*
* For example, consider a task consisting of the activities: A, B, C,
* D. If D calls startActivity() with an Intent that resolves to the
* component of activity B, then C and D will be finished and B receive
* the given Intent, resulting in the stack now being: A, B.
* 例如,如果考虑一个任务活动组成,A,B,C,Dð调用startActivity(活动B的组成部分,
* 解决一个Intent),然后将完成C和D和B收到给出的意向,导致堆栈现在是:A,B
*/
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
c.startActivity(intent);
}
/**
* Launch this Activity from the outside, with defined playlist on a remote
* server
* 推出这项活动从外面定义播放列表,在远程服务器上
* @param c
* @param playlistRemote
*/
public static void launch(Activity c, PlaylistRemote playlistRemote)
{
Intent intent = new Intent(c, PlayerActivity.class);
new PlaylistRemoteLoadingDialog(c, R.string.loading_playlist, R.string.loading_playlist_fail, intent).execute(playlistRemote);
}
/**
* Launch this Activity from the outside with the given album
* 推出这项活动,从外面给定的专辑
* @param c
* Activity from which PlayerActivity should be started
* @param album
* an album to be played
*/
public static void launch(Activity c, Album album)
{
new PlayerAlbumLoadingDialog(c, R.string.album_loading, R.string.album_fail).execute(album);
}
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
Log.i(JamendoApplication.TAG, "PlayerActivity.onCreate");
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.player);
// XML binding
mBetterRes = getResources().getString(R.string.better_res);
mArtistTextView = (TextView) findViewById(R.id.ArtistTextView);
mSongTextView = (TextView) findViewById(R.id.SongTextView);
// AutoScrolling of long song titles
mSongTextView.setEllipsize(TruncateAt.MARQUEE);
mSongTextView.setHorizontallyScrolling(true);
mSongTextView.setSelected(true);
mCurrentTimeTextView = (TextView) findViewById(R.id.CurrentTimeTextView);
mTotalTimeTextView = (TextView) findViewById(R.id.TotalTimeTextView);
mRatingBar = (RatingBar) findViewById(R.id.TrackRowRatingBar);
mCoverImageView = (RemoteImageView) findViewById(R.id.CoverImageView);
mCoverImageView.setOnClickListener(mCoverOnClickListener);
mCoverImageView.setDefaultImage(R.drawable.no_cd_300);
mProgressBar = (ProgressBar) findViewById(R.id.ProgressBar);
mReflectableLayout = (ReflectableLayout) findViewById(R.id.ReflectableLayout);
mReflectiveSurface = (ReflectiveSurface) findViewById(R.id.ReflectiveSurface);
if (mReflectableLayout != null && mReflectiveSurface != null)
{
mReflectableLayout.setReflectiveSurface(mReflectiveSurface);
mReflectiveSurface.setReflectableLayout(mReflectableLayout);
}
handleIntent();
// used for Fade Out Animation handle control
//用于出�