use of org.moire.ultrasonic.service.DownloadService in project ultrasonic by ultrasonic.
the class DownloadActivity method onDownloadListChanged.
private void onDownloadListChanged() {
final DownloadService downloadService = getDownloadService();
if (downloadService == null) {
return;
}
final List<DownloadFile> list = downloadService.getSongs();
emptyTextView.setText(R.string.download_empty);
final SongListAdapter adapter = new SongListAdapter(this, list);
playlistView.setAdapter(adapter);
playlistView.setDragSortListener(new DragSortListView.DragSortListener() {
@Override
public void drop(int from, int to) {
if (from != to) {
DownloadFile item = adapter.getItem(from);
adapter.remove(item);
adapter.notifyDataSetChanged();
adapter.insert(item, to);
adapter.notifyDataSetChanged();
}
}
@Override
public void drag(int from, int to) {
}
@Override
public void remove(int which) {
DownloadFile item = adapter.getItem(which);
DownloadService downloadService = getDownloadService();
if (item == null || downloadService == null) {
return;
}
DownloadFile currentPlaying = downloadService.getCurrentPlaying();
if (currentPlaying == item) {
getDownloadService().next();
}
adapter.remove(item);
adapter.notifyDataSetChanged();
String songRemoved = String.format(getResources().getString(R.string.download_song_removed), item.getSong().getTitle());
Util.toast(DownloadActivity.this, songRemoved);
onDownloadListChanged();
onCurrentChanged();
}
});
emptyTextView.setVisibility(list.isEmpty() ? View.VISIBLE : View.GONE);
currentRevision = downloadService.getDownloadListUpdateRevision();
switch(downloadService.getRepeatMode()) {
case OFF:
repeatButton.setImageDrawable(Util.getDrawableFromAttribute(this, R.attr.media_repeat_off));
break;
case ALL:
repeatButton.setImageDrawable(Util.getDrawableFromAttribute(this, R.attr.media_repeat_all));
break;
case SINGLE:
repeatButton.setImageDrawable(Util.getDrawableFromAttribute(this, R.attr.media_repeat_single));
break;
default:
break;
}
}
use of org.moire.ultrasonic.service.DownloadService in project ultrasonic by ultrasonic.
the class DownloadActivity method onPrepareOptionsMenu.
@Override
public boolean onPrepareOptionsMenu(final Menu menu) {
super.onPrepareOptionsMenu(menu);
final MenuItem screenOption = menu.findItem(R.id.menu_item_screen_on_off);
final MenuItem jukeboxOption = menu.findItem(R.id.menu_item_jukebox);
final MenuItem equalizerMenuItem = menu.findItem(R.id.menu_item_equalizer);
final MenuItem visualizerMenuItem = menu.findItem(R.id.menu_item_visualizer);
final MenuItem shareMenuItem = menu.findItem(R.id.menu_item_share);
starMenuItem = menu.findItem(R.id.menu_item_star);
MenuItem bookmarkMenuItem = menu.findItem(R.id.menu_item_bookmark_set);
MenuItem bookmarkRemoveMenuItem = menu.findItem(R.id.menu_item_bookmark_delete);
if (Util.isOffline(this)) {
if (shareMenuItem != null) {
shareMenuItem.setVisible(false);
}
if (starMenuItem != null) {
starMenuItem.setVisible(false);
}
if (bookmarkMenuItem != null) {
bookmarkMenuItem.setVisible(false);
}
if (bookmarkRemoveMenuItem != null) {
bookmarkRemoveMenuItem.setVisible(false);
}
}
if (equalizerMenuItem != null) {
equalizerMenuItem.setEnabled(equalizerAvailable);
equalizerMenuItem.setVisible(equalizerAvailable);
}
if (visualizerMenuItem != null) {
visualizerMenuItem.setEnabled(visualizerAvailable);
visualizerMenuItem.setVisible(visualizerAvailable);
}
final DownloadService downloadService = getDownloadService();
if (downloadService != null) {
DownloadFile downloadFile = downloadService.getCurrentPlaying();
if (downloadFile != null) {
currentSong = downloadFile.getSong();
}
if (currentSong != null) {
final Drawable starDrawable = currentSong.getStarred() ? Util.getDrawableFromAttribute(SubsonicTabActivity.getInstance(), R.attr.star_full) : Util.getDrawableFromAttribute(SubsonicTabActivity.getInstance(), R.attr.star_hollow);
if (starMenuItem != null) {
starMenuItem.setIcon(starDrawable);
}
} else {
final Drawable starDrawable = Util.getDrawableFromAttribute(SubsonicTabActivity.getInstance(), R.attr.star_hollow);
if (starMenuItem != null) {
starMenuItem.setIcon(starDrawable);
}
}
if (downloadService.getKeepScreenOn()) {
if (screenOption != null) {
screenOption.setTitle(R.string.download_menu_screen_off);
}
} else {
if (screenOption != null) {
screenOption.setTitle(R.string.download_menu_screen_on);
}
}
if (jukeboxOption != null) {
jukeboxOption.setEnabled(jukeboxAvailable);
jukeboxOption.setVisible(jukeboxAvailable);
if (downloadService.isJukeboxEnabled()) {
jukeboxOption.setTitle(R.string.download_menu_jukebox_off);
} else {
jukeboxOption.setTitle(R.string.download_menu_jukebox_on);
}
}
}
return true;
}
use of org.moire.ultrasonic.service.DownloadService in project ultrasonic by ultrasonic.
the class DownloadActivity method changeProgress.
private void changeProgress(final int ms) {
final DownloadService downloadService = getDownloadService();
if (downloadService == null) {
return;
}
new SilentBackgroundTask<Void>(this) {
int msPlayed;
Integer duration;
int seekTo;
@Override
protected Void doInBackground() throws Throwable {
msPlayed = Math.max(0, downloadService.getPlayerPosition());
duration = downloadService.getPlayerDuration();
final int msTotal = duration;
seekTo = msPlayed + ms > msTotal ? msTotal : msPlayed + ms;
downloadService.seekTo(seekTo);
return null;
}
@Override
protected void done(final Void result) {
progressBar.setProgress(seekTo);
}
}.execute();
}
use of org.moire.ultrasonic.service.DownloadService in project ultrasonic by ultrasonic.
the class Util method requestAudioFocus.
public static void requestAudioFocus(final Context context) {
if (!hasFocus) {
final AudioManager audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
hasFocus = true;
audioManager.requestAudioFocus(new OnAudioFocusChangeListener() {
@Override
public void onAudioFocusChange(int focusChange) {
DownloadService downloadService = (DownloadService) context;
if ((focusChange == AudioManager.AUDIOFOCUS_LOSS_TRANSIENT || focusChange == AudioManager.AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK) && !downloadService.isJukeboxEnabled()) {
if (downloadService.getPlayerState() == PlayerState.STARTED) {
SharedPreferences preferences = getPreferences(context);
int lossPref = Integer.parseInt(preferences.getString(Constants.PREFERENCES_KEY_TEMP_LOSS, "1"));
if (lossPref == 2 || (lossPref == 1 && focusChange == AudioManager.AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK)) {
lowerFocus = true;
downloadService.setVolume(0.1f);
} else if (lossPref == 0 || (lossPref == 1)) {
pauseFocus = true;
downloadService.pause();
}
}
} else if (focusChange == AudioManager.AUDIOFOCUS_GAIN) {
if (pauseFocus) {
pauseFocus = false;
downloadService.start();
} else if (lowerFocus) {
lowerFocus = false;
downloadService.setVolume(1.0f);
}
} else if (focusChange == AudioManager.AUDIOFOCUS_LOSS && !downloadService.isJukeboxEnabled()) {
hasFocus = false;
downloadService.pause();
audioManager.abandonAudioFocus(this);
}
}
}, AudioManager.STREAM_MUSIC, AudioManager.AUDIOFOCUS_GAIN);
}
}
use of org.moire.ultrasonic.service.DownloadService in project ultrasonic by ultrasonic.
the class VisualizerView method onDraw.
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
if (!active) {
return;
}
DownloadService downloadService = DownloadServiceImpl.getInstance();
if (downloadService != null && downloadService.getPlayerState() != PlayerState.STARTED) {
return;
}
if (data == null) {
return;
}
if (points == null || points.length < data.length * 4) {
points = new float[data.length * 4];
}
int w = getWidth();
int h = getHeight();
for (int i = 0; i < data.length - 1; i++) {
points[i * 4] = w * i / (data.length - 1);
points[i * 4 + 1] = h / 2 + ((byte) (data[i] + 128)) * (h / 2) / 128;
points[i * 4 + 2] = w * (i + 1) / (data.length - 1);
points[i * 4 + 3] = h / 2 + ((byte) (data[i + 1] + 128)) * (h / 2) / 128;
}
canvas.drawLines(points, paint);
}
Aggregations