Search in sources :

Example 1 with DownloadService

use of org.moire.ultrasonic.service.DownloadService in project ultrasonic by ultrasonic.

the class SettingsFragment method setCacheLocation.

private void setCacheLocation(String path) {
    File dir = new File(path);
    if (!FileUtil.ensureDirectoryExistsAndIsReadWritable(dir)) {
        Util.toast(getActivity(), R.string.settings_cache_location_error, false);
        // Reset it to the default.
        String defaultPath = FileUtil.getDefaultMusicDirectory().getPath();
        if (!defaultPath.equals(path)) {
            Util.getPreferences(getActivity()).edit().putString(Constants.PREFERENCES_KEY_CACHE_LOCATION, defaultPath).apply();
            cacheLocation.setSummary(defaultPath);
            cacheLocation.setText(defaultPath);
        }
        // Clear download queue.
        DownloadService downloadService = DownloadServiceImpl.getInstance();
        downloadService.clear();
    }
}
Also used : File(java.io.File) DownloadService(org.moire.ultrasonic.service.DownloadService)

Example 2 with DownloadService

use of org.moire.ultrasonic.service.DownloadService in project ultrasonic by ultrasonic.

the class EqualizerActivity method setup.

private void setup() {
    DownloadService instance = DownloadServiceImpl.getInstance();
    if (instance == null) {
        return;
    }
    equalizerController = instance.getEqualizerController();
    equalizer = equalizerController.getEqualizer();
    initEqualizer();
    final View presetButton = findViewById(R.id.equalizer_preset);
    registerForContextMenu(presetButton);
    presetButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            presetButton.showContextMenu();
        }
    });
    CheckBox enabledCheckBox = (CheckBox) findViewById(R.id.equalizer_enabled);
    enabledCheckBox.setChecked(equalizer.getEnabled());
    enabledCheckBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
            setEqualizerEnabled(b);
        }
    });
}
Also used : CheckBox(android.widget.CheckBox) TextView(android.widget.TextView) View(android.view.View) DownloadService(org.moire.ultrasonic.service.DownloadService) CompoundButton(android.widget.CompoundButton)

Example 3 with DownloadService

use of org.moire.ultrasonic.service.DownloadService in project ultrasonic by ultrasonic.

the class MainActivity method setActiveServer.

private void setActiveServer(final int instance) {
    final DownloadService service = getDownloadService();
    if (Util.getActiveServer(this) != instance) {
        if (service != null) {
            service.clearIncomplete();
        }
    }
    Util.setActiveServer(this, instance);
    if (service != null) {
        service.setJukeboxEnabled(Util.getJukeboxEnabled(this, instance));
    }
}
Also used : DownloadService(org.moire.ultrasonic.service.DownloadService)

Example 4 with DownloadService

use of org.moire.ultrasonic.service.DownloadService in project ultrasonic by ultrasonic.

the class SubsonicTabActivity method showNowPlaying.

public void showNowPlaying() {
    this.runOnUiThread(new Runnable() {

        @Override
        public void run() {
            new SilentBackgroundTask<Void>(SubsonicTabActivity.this) {

                @Override
                protected Void doInBackground() throws Throwable {
                    if (!Util.getShowNowPlayingPreference(SubsonicTabActivity.this)) {
                        hideNowPlaying();
                        return null;
                    }
                    nowPlayingView = findViewById(R.id.now_playing);
                    if (nowPlayingView != null) {
                        final DownloadService downloadService = DownloadServiceImpl.getInstance();
                        if (downloadService != null) {
                            PlayerState playerState = downloadService.getPlayerState();
                            if (playerState.equals(PlayerState.PAUSED) || playerState.equals(PlayerState.STARTED)) {
                                DownloadFile file = downloadService.getCurrentPlaying();
                                if (file != null) {
                                    final Entry song = file.getSong();
                                    showNowPlaying(SubsonicTabActivity.this, downloadService, song, playerState);
                                }
                            } else {
                                hideNowPlaying();
                            }
                        }
                    }
                    return null;
                }

                @Override
                protected void done(Void result) {
                }
            }.execute();
        }
    });
}
Also used : Entry(org.moire.ultrasonic.domain.MusicDirectory.Entry) DownloadFile(org.moire.ultrasonic.service.DownloadFile) PlayerState(org.moire.ultrasonic.domain.PlayerState) SilentBackgroundTask(org.moire.ultrasonic.util.SilentBackgroundTask) DownloadService(org.moire.ultrasonic.service.DownloadService)

Example 5 with DownloadService

use of org.moire.ultrasonic.service.DownloadService in project ultrasonic by ultrasonic.

the class SubsonicTabActivity method getDownloadService.

public DownloadService getDownloadService() {
    // If service is not available, request it to start and wait for it.
    for (int i = 0; i < 5; i++) {
        DownloadService downloadService = DownloadServiceImpl.getInstance();
        if (downloadService != null) {
            return downloadService;
        }
        Log.w(TAG, "DownloadService not running. Attempting to start it.");
        startService(new Intent(this, DownloadServiceImpl.class));
        Util.sleepQuietly(50L);
    }
    return DownloadServiceImpl.getInstance();
}
Also used : DownloadServiceImpl(org.moire.ultrasonic.service.DownloadServiceImpl) Intent(android.content.Intent) DownloadService(org.moire.ultrasonic.service.DownloadService)

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