use of org.moire.ultrasonic.view.AutoRepeatButton in project ultrasonic by ultrasonic.
the class DownloadActivity method onCreate.
/**
* Called when the activity is first created.
*/
@Override
public void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.download);
final WindowManager windowManager = getWindowManager();
final Display display = windowManager.getDefaultDisplay();
Point size = new Point();
display.getSize(size);
int width = size.x;
int height = size.y;
swipeDistance = (width + height) * PERCENTAGE_OF_SCREEN_FOR_SWIPE / 100;
swipeVelocity = swipeDistance;
gestureScanner = new GestureDetector(this, this);
playlistFlipper = (ViewFlipper) findViewById(R.id.download_playlist_flipper);
emptyTextView = (TextView) findViewById(R.id.download_empty);
songTitleTextView = (TextView) findViewById(R.id.download_song_title);
albumTextView = (TextView) findViewById(R.id.download_album);
artistTextView = (TextView) findViewById(R.id.download_artist);
albumArtImageView = (ImageView) findViewById(R.id.download_album_art_image);
positionTextView = (TextView) findViewById(R.id.download_position);
downloadTrackTextView = (TextView) findViewById(R.id.download_track);
downloadTotalDurationTextView = (TextView) findViewById(R.id.download_total_duration);
durationTextView = (TextView) findViewById(R.id.download_duration);
progressBar = (SeekBar) findViewById(R.id.download_progress_bar);
playlistView = (DragSortListView) findViewById(R.id.download_list);
final AutoRepeatButton previousButton = (AutoRepeatButton) findViewById(R.id.download_previous);
final AutoRepeatButton nextButton = (AutoRepeatButton) findViewById(R.id.download_next);
pauseButton = findViewById(R.id.download_pause);
stopButton = findViewById(R.id.download_stop);
startButton = findViewById(R.id.download_start);
final View shuffleButton = findViewById(R.id.download_shuffle);
repeatButton = (ImageView) findViewById(R.id.download_repeat);
visualizerViewLayout = (LinearLayout) findViewById(R.id.download_visualizer_view_layout);
View.OnTouchListener touchListener = new View.OnTouchListener() {
@Override
public boolean onTouch(View view, MotionEvent me) {
return gestureScanner.onTouchEvent(me);
}
};
albumArtImageView.setOnTouchListener(touchListener);
albumArtImageView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(final View view) {
toggleFullScreenAlbumArt();
}
});
previousButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(final View view) {
warnIfNetworkOrStorageUnavailable();
new SilentBackgroundTask<Void>(DownloadActivity.this) {
@Override
protected Void doInBackground() throws Throwable {
getDownloadService().previous();
return null;
}
@Override
protected void done(final Void result) {
onCurrentChanged();
onSliderProgressChanged();
}
}.execute();
}
});
previousButton.setOnRepeatListener(new Runnable() {
@Override
public void run() {
int incrementTime = Util.getIncrementTime(DownloadActivity.this);
changeProgress(-incrementTime);
}
});
nextButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(final View view) {
warnIfNetworkOrStorageUnavailable();
new SilentBackgroundTask<Boolean>(DownloadActivity.this) {
@Override
protected Boolean doInBackground() throws Throwable {
if (getDownloadService().getCurrentPlayingIndex() < getDownloadService().size() - 1) {
getDownloadService().next();
return true;
} else {
return false;
}
}
@Override
protected void done(final Boolean result) {
if (result) {
onCurrentChanged();
onSliderProgressChanged();
}
}
}.execute();
}
});
nextButton.setOnRepeatListener(new Runnable() {
@Override
public void run() {
int incrementTime = Util.getIncrementTime(DownloadActivity.this);
changeProgress(incrementTime);
}
});
pauseButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(final View view) {
new SilentBackgroundTask<Void>(DownloadActivity.this) {
@Override
protected Void doInBackground() throws Throwable {
getDownloadService().pause();
return null;
}
@Override
protected void done(final Void result) {
onCurrentChanged();
onSliderProgressChanged();
}
}.execute();
}
});
stopButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(final View view) {
new SilentBackgroundTask<Void>(DownloadActivity.this) {
@Override
protected Void doInBackground() throws Throwable {
getDownloadService().reset();
return null;
}
@Override
protected void done(final Void result) {
onCurrentChanged();
onSliderProgressChanged();
}
}.execute();
}
});
startButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(final View view) {
warnIfNetworkOrStorageUnavailable();
new SilentBackgroundTask<Void>(DownloadActivity.this) {
@Override
protected Void doInBackground() throws Throwable {
start();
return null;
}
@Override
protected void done(final Void result) {
onCurrentChanged();
onSliderProgressChanged();
}
}.execute();
}
});
shuffleButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(final View view) {
getDownloadService().shuffle();
Util.toast(DownloadActivity.this, R.string.download_menu_shuffle_notification);
}
});
repeatButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(final View view) {
final RepeatMode repeatMode = getDownloadService().getRepeatMode().next();
getDownloadService().setRepeatMode(repeatMode);
onDownloadListChanged();
switch(repeatMode) {
case OFF:
Util.toast(DownloadActivity.this, R.string.download_repeat_off);
break;
case ALL:
Util.toast(DownloadActivity.this, R.string.download_repeat_all);
break;
case SINGLE:
Util.toast(DownloadActivity.this, R.string.download_repeat_single);
break;
default:
break;
}
}
});
progressBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
@Override
public void onStopTrackingTouch(final SeekBar seekBar) {
new SilentBackgroundTask<Void>(DownloadActivity.this) {
@Override
protected Void doInBackground() throws Throwable {
getDownloadService().seekTo(getProgressBar().getProgress());
return null;
}
@Override
protected void done(final Void result) {
onSliderProgressChanged();
}
}.execute();
}
@Override
public void onStartTrackingTouch(final SeekBar seekBar) {
}
@Override
public void onProgressChanged(final SeekBar seekBar, final int progress, final boolean fromUser) {
}
});
playlistView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(final AdapterView<?> parent, final View view, final int position, final long id) {
warnIfNetworkOrStorageUnavailable();
new SilentBackgroundTask<Void>(DownloadActivity.this) {
@Override
protected Void doInBackground() throws Throwable {
getDownloadService().play(position);
return null;
}
@Override
protected void done(final Void result) {
onCurrentChanged();
onSliderProgressChanged();
}
}.execute();
}
});
registerForContextMenu(playlistView);
final DownloadService downloadService = getDownloadService();
if (downloadService != null && getIntent().getBooleanExtra(Constants.INTENT_EXTRA_NAME_SHUFFLE, false)) {
warnIfNetworkOrStorageUnavailable();
downloadService.setShufflePlayEnabled(true);
}
visualizerAvailable = (downloadService != null) && (downloadService.getVisualizerController() != null);
equalizerAvailable = (downloadService != null) && (downloadService.getEqualizerController() != null);
new Thread(new Runnable() {
@Override
public void run() {
try {
DownloadService downloadService = getDownloadService();
jukeboxAvailable = (downloadService != null) && (downloadService.isJukeboxAvailable());
} catch (Exception e) {
Log.e(TAG, e.getMessage(), e);
}
}
}).start();
final View nowPlayingMenuItem = findViewById(R.id.menu_now_playing);
menuDrawer.setActiveView(nowPlayingMenuItem);
if (visualizerAvailable) {
visualizerView = new VisualizerView(this);
visualizerViewLayout.addView(visualizerView, new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT));
if (!visualizerView.isActive()) {
visualizerViewLayout.setVisibility(View.GONE);
} else {
visualizerViewLayout.setVisibility(View.VISIBLE);
}
visualizerView.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(final View view, final MotionEvent motionEvent) {
visualizerView.setActive(!visualizerView.isActive());
getDownloadService().setShowVisualization(visualizerView.isActive());
return true;
}
});
} else {
visualizerViewLayout.setVisibility(View.GONE);
}
}
Aggregations