Search in sources :

Example 11 with DownloadService

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;
    }
}
Also used : DownloadFile(org.moire.ultrasonic.service.DownloadFile) SongListAdapter(org.moire.ultrasonic.view.SongListAdapter) DragSortListView(com.mobeta.android.dslv.DragSortListView) DownloadService(org.moire.ultrasonic.service.DownloadService) Point(android.graphics.Point)

Example 12 with DownloadService

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;
}
Also used : DownloadFile(org.moire.ultrasonic.service.DownloadFile) Drawable(android.graphics.drawable.Drawable) MenuItem(android.view.MenuItem) DownloadService(org.moire.ultrasonic.service.DownloadService)

Example 13 with DownloadService

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();
}
Also used : DownloadService(org.moire.ultrasonic.service.DownloadService) Point(android.graphics.Point)

Example 14 with DownloadService

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);
    }
}
Also used : AudioManager(android.media.AudioManager) SharedPreferences(android.content.SharedPreferences) OnAudioFocusChangeListener(android.media.AudioManager.OnAudioFocusChangeListener) DownloadService(org.moire.ultrasonic.service.DownloadService)

Example 15 with DownloadService

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);
}
Also used : DownloadService(org.moire.ultrasonic.service.DownloadService) Paint(android.graphics.Paint)

Aggregations

DownloadService (org.moire.ultrasonic.service.DownloadService)21 Point (android.graphics.Point)6 Entry (org.moire.ultrasonic.domain.MusicDirectory.Entry)4 DownloadFile (org.moire.ultrasonic.service.DownloadFile)4 Intent (android.content.Intent)3 PlayerState (org.moire.ultrasonic.domain.PlayerState)3 View (android.view.View)2 TextView (android.widget.TextView)2 DragSortListView (com.mobeta.android.dslv.DragSortListView)2 ArrayList (java.util.ArrayList)2 MusicService (org.moire.ultrasonic.service.MusicService)2 SilentBackgroundTask (org.moire.ultrasonic.util.SilentBackgroundTask)2 SharedPreferences (android.content.SharedPreferences)1 Paint (android.graphics.Paint)1 Drawable (android.graphics.drawable.Drawable)1 AudioManager (android.media.AudioManager)1 OnAudioFocusChangeListener (android.media.AudioManager.OnAudioFocusChangeListener)1 Handler (android.os.Handler)1 Display (android.view.Display)1 GestureDetector (android.view.GestureDetector)1