Media Button fixes, moved search defaults to settings

This commit is contained in:
Joshua Bahnsen 2013-01-25 00:47:38 -07:00
parent 946b5572e5
commit c11711f950
16 changed files with 299 additions and 241 deletions

View File

@ -19,6 +19,8 @@ public final class R {
public static final int bufferLengthValues=0x7f060008;
public static final int cacheSizeNames=0x7f060005;
public static final int cacheSizeValues=0x7f060004;
public static final int defaultSearchNames=0x7f060013;
public static final int defaultSearchValues=0x7f060012;
public static final int maxAlbumsNames=0x7f06000d;
public static final int maxAlbumsValues=0x7f06000c;
public static final int maxArtistsNames=0x7f060011;
@ -347,12 +349,12 @@ public final class R {
public static final int select_album_n_songs_downloading=0x7f0a0001;
}
public static final class string {
public static final int background_task_loading=0x7f0900e7;
public static final int background_task_network_error=0x7f0900e9;
public static final int background_task_no_network=0x7f0900e8;
public static final int background_task_not_found=0x7f0900ea;
public static final int background_task_parse_error=0x7f0900eb;
public static final int background_task_wait=0x7f0900e6;
public static final int background_task_loading=0x7f0900e8;
public static final int background_task_network_error=0x7f0900ea;
public static final int background_task_no_network=0x7f0900e9;
public static final int background_task_not_found=0x7f0900eb;
public static final int background_task_parse_error=0x7f0900ec;
public static final int background_task_wait=0x7f0900e7;
public static final int button_bar_browse=0x7f09000b;
public static final int button_bar_home=0x7f09000a;
public static final int button_bar_now_playing=0x7f09000e;
@ -400,9 +402,9 @@ public final class R {
public static final int download_repeat_single=0x7f09005f;
public static final int download_visualizer_off=0x7f090061;
public static final int download_visualizer_on=0x7f090060;
public static final int equalizer_enabled=0x7f0900f8;
public static final int equalizer_label=0x7f0900f7;
public static final int equalizer_preset=0x7f0900f9;
public static final int equalizer_enabled=0x7f0900f9;
public static final int equalizer_label=0x7f0900f8;
public static final int equalizer_preset=0x7f0900fa;
public static final int error_label=0x7f09006b;
public static final int help_back=0x7f090027;
public static final int help_close=0x7f090028;
@ -437,14 +439,14 @@ public final class R {
/** <string name="settings.screen_lit_title">TODO: Keep screen on</string>
<string name="settings.screen_lit_summary">TODO: Keeping the screen on when downloading may improve download speed</string>
*/
public static final int music_service_retry=0x7f0900e5;
public static final int parser_artist_count=0x7f0900f3;
public static final int parser_not_authenticated=0x7f0900f1;
public static final int parser_not_authorized=0x7f0900f2;
public static final int parser_reading=0x7f0900ed;
public static final int parser_reading_done=0x7f0900ee;
public static final int parser_upgrade_client=0x7f0900ef;
public static final int parser_upgrade_server=0x7f0900f0;
public static final int music_service_retry=0x7f0900e6;
public static final int parser_artist_count=0x7f0900f4;
public static final int parser_not_authenticated=0x7f0900f2;
public static final int parser_not_authorized=0x7f0900f3;
public static final int parser_reading=0x7f0900ee;
public static final int parser_reading_done=0x7f0900ef;
public static final int parser_upgrade_client=0x7f0900f0;
public static final int parser_upgrade_server=0x7f0900f1;
public static final int play_video_loading=0x7f09002b;
public static final int play_video_noplugin=0x7f09002c;
/** <string name="menu.exit">TODO: Exit</string>
@ -479,11 +481,11 @@ public final class R {
public static final int select_album_play_all=0x7f09003f;
public static final int select_album_searching=0x7f09003e;
public static final int select_album_select=0x7f090039;
public static final int select_artist_all_folders=0x7f0900f6;
public static final int select_artist_folder=0x7f0900f5;
public static final int select_artist_refresh=0x7f0900f4;
public static final int select_artist_all_folders=0x7f0900f7;
public static final int select_artist_folder=0x7f0900f6;
public static final int select_artist_refresh=0x7f0900f5;
public static final int select_playlist_empty=0x7f090047;
public static final int service_connecting=0x7f0900ec;
public static final int service_connecting=0x7f0900ed;
public static final int settings_appearance_title=0x7f090080;
public static final int settings_buffer_length=0x7f0900b2;
public static final int settings_buffer_length_10=0x7f0900b7;
@ -509,6 +511,9 @@ public final class R {
public static final int settings_cache_title=0x7f090075;
public static final int settings_clear_search_history=0x7f0900a5;
public static final int settings_connection_failure=0x7f09007d;
public static final int settings_default_albums=0x7f0900e4;
public static final int settings_default_artists=0x7f0900e3;
public static final int settings_default_songs=0x7f0900e5;
public static final int settings_hide_media_summary=0x7f0900ac;
/** <string name="settings.scrobble_title">TODO: Scrobble to Last.fm</string>
<string name="settings.scrobble_summary">TODO: Remember to set up your Last.fm user and password on the Subsonic server</string>
@ -518,26 +523,25 @@ public final class R {
public static final int settings_invalid_url=0x7f09007e;
public static final int settings_invalid_username=0x7f09007f;
public static final int settings_max_albums=0x7f0900c6;
public static final int settings_max_albums_10=0x7f0900c9;
public static final int settings_max_albums_100=0x7f0900ce;
public static final int settings_max_albums_20=0x7f0900ca;
public static final int settings_max_albums_250=0x7f0900cf;
public static final int settings_max_albums_30=0x7f0900cb;
public static final int settings_max_albums_40=0x7f0900cc;
public static final int settings_max_albums_5=0x7f0900c8;
public static final int settings_max_albums_50=0x7f0900cd;
public static final int settings_max_albums_500=0x7f0900d0;
public static final int settings_max_albums_summary=0x7f0900c7;
public static final int settings_max_artists=0x7f0900db;
public static final int settings_max_artists_10=0x7f0900de;
public static final int settings_max_artists_100=0x7f0900e2;
public static final int settings_max_artists_200=0x7f0900e3;
public static final int settings_max_artists_25=0x7f0900df;
public static final int settings_max_artists_5=0x7f0900dd;
public static final int settings_max_artists_50=0x7f0900e0;
public static final int settings_max_artists_500=0x7f0900e4;
public static final int settings_max_artists_75=0x7f0900e1;
public static final int settings_max_artists_summary=0x7f0900dc;
public static final int settings_max_albums_10=0x7f0900c8;
public static final int settings_max_albums_100=0x7f0900cd;
public static final int settings_max_albums_20=0x7f0900c9;
public static final int settings_max_albums_250=0x7f0900ce;
public static final int settings_max_albums_30=0x7f0900ca;
public static final int settings_max_albums_40=0x7f0900cb;
public static final int settings_max_albums_5=0x7f0900c7;
public static final int settings_max_albums_50=0x7f0900cc;
public static final int settings_max_albums_500=0x7f0900cf;
public static final int settings_max_artists=0x7f0900d9;
public static final int settings_max_artists_10=0x7f0900dc;
public static final int settings_max_artists_100=0x7f0900e0;
public static final int settings_max_artists_200=0x7f0900e1;
public static final int settings_max_artists_25=0x7f0900dd;
public static final int settings_max_artists_3=0x7f0900da;
public static final int settings_max_artists_5=0x7f0900db;
public static final int settings_max_artists_50=0x7f0900de;
public static final int settings_max_artists_500=0x7f0900e2;
public static final int settings_max_artists_75=0x7f0900df;
public static final int settings_max_bitrate_112=0x7f09008d;
public static final int settings_max_bitrate_128=0x7f09008e;
public static final int settings_max_bitrate_160=0x7f09008f;
@ -551,16 +555,15 @@ public final class R {
public static final int settings_max_bitrate_mobile=0x7f090088;
public static final int settings_max_bitrate_unlimited=0x7f090093;
public static final int settings_max_bitrate_wifi=0x7f090087;
public static final int settings_max_songs=0x7f0900d1;
public static final int settings_max_songs_10=0x7f0900d4;
public static final int settings_max_songs_100=0x7f0900d8;
public static final int settings_max_songs_200=0x7f0900d9;
public static final int settings_max_songs_25=0x7f0900d5;
public static final int settings_max_songs_5=0x7f0900d3;
public static final int settings_max_songs_50=0x7f0900d6;
public static final int settings_max_songs_500=0x7f0900da;
public static final int settings_max_songs_75=0x7f0900d7;
public static final int settings_max_songs_summary=0x7f0900d2;
public static final int settings_max_songs=0x7f0900d0;
public static final int settings_max_songs_10=0x7f0900d2;
public static final int settings_max_songs_100=0x7f0900d6;
public static final int settings_max_songs_200=0x7f0900d7;
public static final int settings_max_songs_25=0x7f0900d3;
public static final int settings_max_songs_5=0x7f0900d1;
public static final int settings_max_songs_50=0x7f0900d4;
public static final int settings_max_songs_500=0x7f0900d8;
public static final int settings_max_songs_75=0x7f0900d5;
public static final int settings_media_button_summary=0x7f0900af;
public static final int settings_media_button_title=0x7f0900ae;
public static final int settings_network_timeout=0x7f0900b3;
@ -605,19 +608,19 @@ public final class R {
public static final int settings_theme_fullscreenlight=0x7f090083;
public static final int settings_theme_light=0x7f090084;
public static final int settings_theme_title=0x7f090081;
public static final int settings_theme_wheat=0x7f090101;
public static final int settings_theme_wheat=0x7f090102;
public static final int settings_title=0x7f09006c;
public static final int settings_wifi_required_summary=0x7f090095;
public static final int settings_wifi_required_title=0x7f090094;
public static final int song_details_all=0x7f090068;
public static final int song_details_kbps=0x7f090069;
public static final int util_bytes_format_byte=0x7f090100;
public static final int util_bytes_format_gigabyte=0x7f0900fd;
public static final int util_bytes_format_kilobyte=0x7f0900ff;
public static final int util_bytes_format_megabyte=0x7f0900fe;
public static final int widget_initial_text=0x7f0900fa;
public static final int widget_sdcard_busy=0x7f0900fb;
public static final int widget_sdcard_missing=0x7f0900fc;
public static final int util_bytes_format_byte=0x7f090101;
public static final int util_bytes_format_gigabyte=0x7f0900fe;
public static final int util_bytes_format_kilobyte=0x7f090100;
public static final int util_bytes_format_megabyte=0x7f0900ff;
public static final int widget_initial_text=0x7f0900fb;
public static final int widget_sdcard_busy=0x7f0900fc;
public static final int widget_sdcard_missing=0x7f0900fd;
}
public static final class style {
public static final int Dark=0x7f0b0000;

View File

@ -28,13 +28,12 @@
a:paddingRight="25dip"/>
</LinearLayout>
<WebView
a:id="@+id/help_contents"
a:layout_width="fill_parent"
a:layout_height="wrap_content"
a:layout_above="@id/help_buttons"
a:fadingEdge="vertical"
a:fadingEdgeLength="12dip"/>
a:id="@+id/help_contents"
a:layout_width="fill_parent"
a:layout_height="match_parent"
a:layout_above="@id/help_buttons"
a:fadingEdge="vertical"
a:fadingEdgeLength="12dip" />
</RelativeLayout>

View File

@ -196,5 +196,29 @@
<item>@string/settings.max_artists_200</item>
<item>@string/settings.max_artists_500</item>
</string-array>
<string-array name="defaultSearchValues">
<item>3</item>
<item>5</item>
<item>10</item>
<item>25</item>
<item>50</item>
<item>75</item>
<item>100</item>
<item>200</item>
<item>500</item>
</string-array>
<string-array name="defaultSearchNames">
<item>@string/settings.max_artists_3</item>
<item>@string/settings.max_artists_5</item>
<item>@string/settings.max_artists_10</item>
<item>@string/settings.max_artists_25</item>
<item>@string/settings.max_artists_50</item>
<item>@string/settings.max_artists_75</item>
<item>@string/settings.max_artists_100</item>
<item>@string/settings.max_artists_200</item>
<item>@string/settings.max_artists_500</item>
</string-array>
</resources>

View File

@ -218,7 +218,6 @@
<string name="settings.show_notification">Show Notification</string>
<string name="settings.show_notification_summary">Show now playing notification in the status bar</string>
<string name="settings.max_albums">Max Albums</string>
<string name="settings.max_albums_summary">Number of albums to return</string>
<string name="settings.max_albums_5">5</string>
<string name="settings.max_albums_10">10</string>
<string name="settings.max_albums_20">20</string>
@ -229,7 +228,6 @@
<string name="settings.max_albums_250">250</string>
<string name="settings.max_albums_500">500</string>
<string name="settings.max_songs">Max Songs</string>
<string name="settings.max_songs_summary">Number of songs to return</string>
<string name="settings.max_songs_5">5</string>
<string name="settings.max_songs_10">10</string>
<string name="settings.max_songs_25">25</string>
@ -239,7 +237,7 @@
<string name="settings.max_songs_200">200</string>
<string name="settings.max_songs_500">500</string>
<string name="settings.max_artists">Max Artists</string>
<string name="settings.max_artists_summary">Number of artists to return</string>
<string name="settings.max_artists_3">3</string>
<string name="settings.max_artists_5">5</string>
<string name="settings.max_artists_10">10</string>
<string name="settings.max_artists_25">25</string>
@ -248,6 +246,9 @@
<string name="settings.max_artists_100">100</string>
<string name="settings.max_artists_200">200</string>
<string name="settings.max_artists_500">500</string>
<string name="settings.default_artists">Default Artists</string>
<string name="settings.default_albums">Default Albums</string>
<string name="settings.default_songs">Default Songs</string>
<string name="music_service.retry">A network error occurred. Retrying %1$d of %2$d.</string>

View File

@ -180,25 +180,43 @@
<PreferenceCategory
a:title="@string/settings.search_title">
<ListPreference
a:title="@string/settings.default_artists"
a:key="defaultArtists"
a:defaultValue="3"
a:entryValues="@array/defaultSearchValues"
a:entries="@array/defaultSearchNames"/>
<ListPreference
a:title="@string/settings.max_artists"
a:summary="@string/settings.max_artists_summary"
a:key="maxArtists"
a:defaultValue="10"
a:entryValues="@array/maxArtistsValues"
a:entries="@array/maxArtistsNames"/>
<ListPreference
a:title="@string/settings.default_albums"
a:key="defaultAlbums"
a:defaultValue="5"
a:entryValues="@array/defaultSearchValues"
a:entries="@array/defaultSearchNames"/>
<ListPreference
a:title="@string/settings.max_albums"
a:summary="@string/settings.max_albums_summary"
a:key="maxAlbums"
a:defaultValue="20"
a:entryValues="@array/maxAlbumsValues"
a:entries="@array/maxAlbumsNames"/>
<ListPreference
a:title="@string/settings.default_songs"
a:key="defaultSongs"
a:defaultValue="10"
a:entryValues="@array/defaultSearchValues"
a:entries="@array/defaultSearchNames"/>
<ListPreference
a:title="@string/settings.max_songs"
a:summary="@string/settings.max_songs_summary"
a:key="maxSongs"
a:defaultValue="25"
a:entryValues="@array/maxSongsValues"

View File

@ -344,27 +344,6 @@ public class DownloadActivity extends SubsonicTabActivity implements OnGestureLi
if (visualizerView != null) {
visualizerView.setActive(downloadService != null && downloadService.getShowVisualization());
}
//updateButtons();
}
private void updateButtons() {
boolean eqEnabled = getDownloadService() != null && getDownloadService().getEqualizerController() != null && getDownloadService().getEqualizerController().isEnabled();
if (equalizerMenuItem != null) {
equalizerMenuItem.setEnabled(eqEnabled);
}
if (visualizerView != null) {
if (visualizerMenuItem != null) {
visualizerMenuItem.setEnabled(visualizerView.isActive());
}
}
boolean jukeboxEnabled = getDownloadService() != null && getDownloadService().isJukeboxEnabled();
if (jukeboxMenuItem != null) {
jukeboxMenuItem.setEnabled(jukeboxEnabled);
}
}
// Scroll to current playing/downloading.

View File

@ -15,24 +15,19 @@
along with Subsonic. If not, see <http://www.gnu.org/licenses/>.
Copyright 2009 (C) Sindre Mehus
*/
*/
package net.sourceforge.subsonic.androidapp.activity;
import java.util.Arrays;
import net.sourceforge.subsonic.androidapp.R;
import net.sourceforge.subsonic.androidapp.service.DownloadFile;
import net.sourceforge.subsonic.androidapp.service.DownloadService;
import net.sourceforge.subsonic.androidapp.service.DownloadServiceImpl;
import net.sourceforge.subsonic.androidapp.service.MusicService;
import net.sourceforge.subsonic.androidapp.service.MusicServiceFactory;
import net.sourceforge.subsonic.androidapp.util.Constants;
import net.sourceforge.subsonic.androidapp.util.MergeAdapter;
import net.sourceforge.subsonic.androidapp.util.Util;
import net.sourceforge.subsonic.androidapp.util.FileUtil;
import android.app.ActionBar;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
@ -43,8 +38,6 @@ import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.TextView;
@ -69,6 +62,7 @@ public class MainActivity extends SubsonicTabActivity {
super.onCreate(savedInstanceState);
if (getIntent().hasExtra(Constants.INTENT_EXTRA_NAME_EXIT)) {
exit();
return;
}
setContentView(R.layout.main);
@ -277,6 +271,7 @@ public class MainActivity extends SubsonicTabActivity {
private void exit() {
stopService(new Intent(this, DownloadServiceImpl.class));
Util.unregisterMediaButtonEventReceiver(this);
finish();
}

View File

@ -60,9 +60,9 @@ import net.sourceforge.subsonic.androidapp.util.Util;
*/
public class SearchActivity extends SubsonicTabActivity {
private static final int DEFAULT_ARTISTS = 3;
private static final int DEFAULT_ALBUMS = 5;
private static final int DEFAULT_SONGS = 10;
private static int DEFAULT_ARTISTS;
private static int DEFAULT_ALBUMS;
private static int DEFAULT_SONGS;
private ListView list;
@ -89,6 +89,10 @@ public class SearchActivity extends SubsonicTabActivity {
setTitle(R.string.search_title);
DEFAULT_ARTISTS = Util.getDefaultArtists(this);
DEFAULT_ALBUMS = Util.getDefaultAlbums(this);
DEFAULT_SONGS = Util.getDefaultSongs(this);
View buttons = LayoutInflater.from(this).inflate(R.layout.search_buttons, null);
artistsHeading = buttons.findViewById(R.id.search_artists);

View File

@ -61,7 +61,6 @@ public class SelectAlbumActivity extends SubsonicTabActivity {
private Button unpinButton;
private Button deleteButton;
private Button moreButton;
//private ImageView coverArtView;
private boolean licenseValid;
private boolean playAllButtonVisible;
private MenuItem playAllButton;
@ -98,7 +97,6 @@ public class SelectAlbumActivity extends SubsonicTabActivity {
});
entryList.setOnTouchListener(gestureListener);
//coverArtView = (ImageView) findViewById(R.id.actionbar_home_icon);
selectButton = (Button) findViewById(R.id.select_album_select);
playNowButton = (Button) findViewById(R.id.select_album_play_now);
playLastButton = (Button) findViewById(R.id.select_album_play_last);
@ -608,7 +606,6 @@ public class SelectAlbumActivity extends SubsonicTabActivity {
}
if (songCount > 0) {
//getImageLoader().loadImage(coverArtView, entries.get(0), false, true);
entryList.addFooterView(footer);
selectButton.setVisibility(View.VISIBLE);
playNowButton.setVisibility(View.VISIBLE);

View File

@ -60,6 +60,10 @@ public class SettingsActivity extends PreferenceActivity implements SharedPrefer
private ListPreference maxAlbums;
private ListPreference maxSongs;
private ListPreference maxArtists;
private ListPreference defaultAlbums;
private ListPreference defaultSongs;
private ListPreference defaultArtists;
@Override
public void onCreate(Bundle savedInstanceState) {
@ -77,6 +81,9 @@ public class SettingsActivity extends PreferenceActivity implements SharedPrefer
maxAlbums = (ListPreference) findPreference(Constants.PREFERENCES_KEY_MAX_ALBUMS);
maxSongs = (ListPreference) findPreference(Constants.PREFERENCES_KEY_MAX_SONGS);
maxArtists = (ListPreference) findPreference(Constants.PREFERENCES_KEY_MAX_ARTISTS);
defaultArtists = (ListPreference) findPreference(Constants.PREFERENCES_KEY_DEFAULT_ARTISTS);
defaultSongs = (ListPreference) findPreference(Constants.PREFERENCES_KEY_DEFAULT_SONGS);
defaultAlbums = (ListPreference) findPreference(Constants.PREFERENCES_KEY_DEFAULT_ALBUMS);
findPreference("testConnection1").setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
@Override
@ -163,6 +170,9 @@ public class SettingsActivity extends PreferenceActivity implements SharedPrefer
maxAlbums.setSummary(maxAlbums.getEntry());
maxArtists.setSummary(maxArtists.getEntry());
maxSongs.setSummary(maxSongs.getEntry());
defaultAlbums.setSummary(defaultAlbums.getEntry());
defaultArtists.setSummary(defaultArtists.getEntry());
defaultSongs.setSummary(defaultSongs.getEntry());
for (ServerSettings ss : serverSettings.values()) {
ss.update();

View File

@ -206,6 +206,7 @@ public class SubsonicTabActivity extends Activity implements OnClickListener{
@Override
protected void onDestroy() {
Util.unregisterMediaButtonEventReceiver(this);
super.onDestroy();
destroyed = true;
getImageLoader().clear();

View File

@ -1,50 +1,55 @@
/*
This file is part of Subsonic.
Subsonic is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Subsonic is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Subsonic. If not, see <http://www.gnu.org/licenses/>.
Copyright 2010 (C) Sindre Mehus
*/
package net.sourceforge.subsonic.androidapp.receiver;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;
import android.view.KeyEvent;
import net.sourceforge.subsonic.androidapp.service.DownloadServiceImpl;
/**
* @author Sindre Mehus
*/
public class MediaButtonIntentReceiver extends BroadcastReceiver {
private static final String TAG = MediaButtonIntentReceiver.class.getSimpleName();
@Override
public void onReceive(Context context, Intent intent) {
KeyEvent event = (KeyEvent) intent.getExtras().get(Intent.EXTRA_KEY_EVENT);
Log.i(TAG, "Got MEDIA_BUTTON key event: " + event);
Intent serviceIntent = new Intent(context, DownloadServiceImpl.class);
serviceIntent.putExtra(Intent.EXTRA_KEY_EVENT, event);
context.startService(serviceIntent);
try {
abortBroadcast();
} catch (Exception x) {
// Ignored.
}
}
}
/*
This file is part of Subsonic.
Subsonic is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Subsonic is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Subsonic. If not, see <http://www.gnu.org/licenses/>.
Copyright 2010 (C) Sindre Mehus
*/
package net.sourceforge.subsonic.androidapp.receiver;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;
import android.view.KeyEvent;
import net.sourceforge.subsonic.androidapp.service.DownloadServiceImpl;
import net.sourceforge.subsonic.androidapp.util.Util;
/**
* @author Sindre Mehus
*/
public class MediaButtonIntentReceiver extends BroadcastReceiver {
private static final String TAG = MediaButtonIntentReceiver.class.getSimpleName();
@Override
public void onReceive(Context context, Intent intent) {
if (Util.getMediaButtonsPreference(context)) {
KeyEvent event = (KeyEvent) intent.getExtras().get(Intent.EXTRA_KEY_EVENT);
Log.i(TAG, "Got MEDIA_BUTTON key event: " + event);
Intent serviceIntent = new Intent(context, DownloadServiceImpl.class);
serviceIntent.putExtra(Intent.EXTRA_KEY_EVENT, event);
context.startService(serviceIntent);
try {
if (isOrderedBroadcast()) {
abortBroadcast();
}
} catch (Exception x) {
// Ignored.
}
}
}
}

View File

@ -61,7 +61,7 @@ import java.util.List;
import static net.sourceforge.subsonic.androidapp.domain.PlayerState.*;
/**
* @author Sindre Mehus
* @author Sindre Mehus, Joshua Bahnsen
* @version $Id$
*/
public class DownloadServiceImpl extends Service implements DownloadService {
@ -86,7 +86,7 @@ public class DownloadServiceImpl extends Service implements DownloadService {
private final List<DownloadFile> cleanupCandidates = new ArrayList<DownloadFile>();
private final Scrobbler scrobbler = new Scrobbler();
private final JukeboxService jukeboxService = new JukeboxService(this);
private final Notification notification = new Notification(R.drawable.ic_stat_subsonic, null, System.currentTimeMillis());
private Notification notification = new Notification(R.drawable.ic_stat_subsonic, null, System.currentTimeMillis());
private DownloadFile currentPlaying;
private DownloadFile currentDownloading;
@ -107,8 +107,6 @@ public class DownloadServiceImpl extends Service implements DownloadService {
private boolean jukeboxEnabled;
RemoteControlClientCompat remoteControlClientCompat;
AudioManager audioManager;
ComponentName mediaButtonReceiverComponent;
static {
try {
@ -173,9 +171,6 @@ public class DownloadServiceImpl extends Service implements DownloadService {
}
}
audioManager = (AudioManager) getSystemService(AUDIO_SERVICE);
mediaButtonReceiverComponent = new ComponentName(this, MediaButtonIntentReceiver.class);
PowerManager pm = (PowerManager)getSystemService(Context.POWER_SERVICE);
wakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, this.getClass().getName());
wakeLock.setReferenceCounted(false);
@ -183,7 +178,7 @@ public class DownloadServiceImpl extends Service implements DownloadService {
instance = this;
lifecycleSupport.onCreate();
}
@Override
public void onStart(Intent intent, int startId) {
super.onStart(intent, startId);
@ -202,7 +197,10 @@ public class DownloadServiceImpl extends Service implements DownloadService {
if (visualizerController != null) {
visualizerController.release();
}
AudioManager audioManager = (AudioManager) this.getSystemService(Context.AUDIO_SERVICE);
RemoteControlHelper.unregisterRemoteControlClient(audioManager, remoteControlClientCompat);
notification = null;
instance = null;
}
@ -431,6 +429,8 @@ public class DownloadServiceImpl extends Service implements DownloadService {
} else {
Util.broadcastNewTrackInfo(this, null);
}
setRemoteControl();
if (Util.isNotificationEnabled(this) && currentPlaying != null && showNotification) {
Util.showPlayingNotification(this, this, handler, currentPlaying.getSong(), this.notification, this.playerState);
@ -578,8 +578,8 @@ public class DownloadServiceImpl extends Service implements DownloadService {
@Override
public synchronized void stop() {
AudioManager am = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
am.abandonAudioFocus(_afChangeListener);
AudioManager audioManager = (AudioManager) this.getSystemService(Context.AUDIO_SERVICE);
audioManager.abandonAudioFocus(_afChangeListener);
try {
if (playerState == STARTED) {
@ -599,16 +599,6 @@ public class DownloadServiceImpl extends Service implements DownloadService {
@Override
public synchronized void start() {
AudioManager am = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
int result = am.requestAudioFocus(_afChangeListener, AudioManager.STREAM_MUSIC, AudioManager.AUDIOFOCUS_GAIN);
if (result == AudioManager.AUDIOFOCUS_REQUEST_FAILED)
stop();
// grab the media button when we have audio focus
AudioManager audioManager = (AudioManager)getSystemService(Context.AUDIO_SERVICE);
audioManager.registerMediaButtonEventReceiver(new ComponentName(this, MediaButtonIntentReceiver.class));
try {
if (jukeboxEnabled) {
jukeboxService.start();
@ -687,59 +677,7 @@ public class DownloadServiceImpl extends Service implements DownloadService {
this.playerState = playerState;
if (remoteControlClientCompat == null) {
Intent intent = new Intent(Intent.ACTION_MEDIA_BUTTON);
intent.setComponent(mediaButtonReceiverComponent);
remoteControlClientCompat = new RemoteControlClientCompat(PendingIntent.getBroadcast(this, 0, intent, 0));
RemoteControlHelper.registerRemoteControlClient(audioManager, remoteControlClientCompat);
}
switch (playerState)
{
case STARTED:
remoteControlClientCompat.setPlaybackState(RemoteControlClient.PLAYSTATE_PLAYING);
break;
case PAUSED:
remoteControlClientCompat.setPlaybackState(RemoteControlClient.PLAYSTATE_PAUSED);
break;
case IDLE:
case STOPPED:
remoteControlClientCompat.setPlaybackState(RemoteControlClient.PLAYSTATE_STOPPED);
break;
}
remoteControlClientCompat.setTransportControlFlags(
RemoteControlClient.FLAG_KEY_MEDIA_PLAY |
RemoteControlClient.FLAG_KEY_MEDIA_PAUSE |
RemoteControlClient.FLAG_KEY_MEDIA_NEXT |
RemoteControlClient.FLAG_KEY_MEDIA_PREVIOUS |
RemoteControlClient.FLAG_KEY_MEDIA_STOP);
try {
//String artist = currentPlaying.getSong().getArtist();
//String album = currentPlaying.getSong().getAlbum();
String album = currentPlaying.getSong().getAlbum();
String title = currentPlaying.getSong().getArtist() + " - " + currentPlaying.getSong().getTitle();
Integer duration = currentPlaying.getSong().getDuration();
MusicService musicService = MusicServiceFactory.getMusicService(this);
DisplayMetrics metrics = this.getResources().getDisplayMetrics();
int size = Math.min(metrics.widthPixels, metrics.heightPixels);
Bitmap bitmap = musicService.getCoverArt(this, currentPlaying.getSong(), size, true, null);
// Update the remote controls
remoteControlClientCompat.editMetadata(true)
//.putString(MediaMetadataRetriever.METADATA_KEY_ARTIST, artist)
.putString(MediaMetadataRetriever.METADATA_KEY_TITLE, title)
.putString(MediaMetadataRetriever.METADATA_KEY_ALBUM, album)
.putLong(MediaMetadataRetriever.METADATA_KEY_DURATION, duration)
.putBitmap(RemoteControlClientCompat.MetadataEditorCompat.METADATA_KEY_ARTWORK, bitmap)
.apply();
}
catch (Exception e) {
//
}
setRemoteControl();
if (Util.isNotificationEnabled(this)) {
if (show) {
@ -802,6 +740,68 @@ public class DownloadServiceImpl extends Service implements DownloadService {
jukeboxService.adjustVolume(up);
}
private void setRemoteControl() {
if (Util.getMediaButtonsPreference(this)) {
AudioManager audioManager = (AudioManager) this.getSystemService(Context.AUDIO_SERVICE);
audioManager.requestAudioFocus(_afChangeListener, AudioManager.STREAM_MUSIC, AudioManager.AUDIOFOCUS_GAIN);
if (remoteControlClientCompat == null) {
audioManager = (AudioManager) this.getSystemService(Context.AUDIO_SERVICE);
Intent intent = new Intent(Intent.ACTION_MEDIA_BUTTON);
intent.setComponent(new ComponentName(this.getPackageName(), MediaButtonIntentReceiver.class.getName()));
remoteControlClientCompat = new RemoteControlClientCompat(PendingIntent.getBroadcast(this, 0, intent, 0));
RemoteControlHelper.registerRemoteControlClient(audioManager, remoteControlClientCompat);
}
switch (playerState)
{
case STARTED:
remoteControlClientCompat.setPlaybackState(RemoteControlClient.PLAYSTATE_PLAYING);
break;
case PAUSED:
remoteControlClientCompat.setPlaybackState(RemoteControlClient.PLAYSTATE_PAUSED);
break;
case IDLE:
case STOPPED:
remoteControlClientCompat.setPlaybackState(RemoteControlClient.PLAYSTATE_STOPPED);
break;
}
remoteControlClientCompat.setTransportControlFlags(
RemoteControlClient.FLAG_KEY_MEDIA_PLAY |
RemoteControlClient.FLAG_KEY_MEDIA_PAUSE |
RemoteControlClient.FLAG_KEY_MEDIA_NEXT |
RemoteControlClient.FLAG_KEY_MEDIA_PREVIOUS |
RemoteControlClient.FLAG_KEY_MEDIA_STOP);
try {
//String artist = currentPlaying.getSong().getArtist();
//String album = currentPlaying.getSong().getAlbum();
String album = currentPlaying.getSong().getAlbum();
String title = currentPlaying.getSong().getArtist() + " - " + currentPlaying.getSong().getTitle();
Integer duration = currentPlaying.getSong().getDuration();
MusicService musicService = MusicServiceFactory.getMusicService(this);
DisplayMetrics metrics = this.getResources().getDisplayMetrics();
int size = Math.min(metrics.widthPixels, metrics.heightPixels);
Bitmap bitmap = musicService.getCoverArt(this, currentPlaying.getSong(), size, true, null);
// Update the remote controls
remoteControlClientCompat.editMetadata(true)
//.putString(MediaMetadataRetriever.METADATA_KEY_ARTIST, artist)
.putString(MediaMetadataRetriever.METADATA_KEY_TITLE, title)
.putString(MediaMetadataRetriever.METADATA_KEY_ALBUM, album)
.putLong(MediaMetadataRetriever.METADATA_KEY_DURATION, duration)
.putBitmap(RemoteControlClientCompat.MetadataEditorCompat.METADATA_KEY_ARTWORK, bitmap)
.apply();
}
catch (Exception e) {
//
}
}
}
private synchronized void bufferAndPlay() {
reset();

View File

@ -168,6 +168,7 @@ public class DownloadServiceLifecycleSupport {
downloadService.unregisterReceiver(ejectEventReceiver);
downloadService.unregisterReceiver(headsetEventReceiver);
downloadService.unregisterReceiver(intentReceiver);
Util.unregisterMediaButtonEventReceiver(downloadService);
TelephonyManager telephonyManager = (TelephonyManager) downloadService.getSystemService(Context.TELEPHONY_SERVICE);
telephonyManager.listen(phoneStateListener, PhoneStateListener.LISTEN_NONE);

View File

@ -81,6 +81,10 @@ public final class Constants {
public static final String PREFERENCES_KEY_MAX_ALBUMS = "maxAlbums";
public static final String PREFERENCES_KEY_MAX_SONGS = "maxSongs";
public static final String PREFERENCES_KEY_MAX_ARTISTS = "maxArtists";
public static final String PREFERENCES_KEY_DEFAULT_ALBUMS = "defaultAlbums";
public static final String PREFERENCES_KEY_DEFAULT_SONGS = "defaultSongs";
public static final String PREFERENCES_KEY_DEFAULT_ARTISTS = "defaultArtists";
// Name of the preferences file.
public static final String PREFERENCES_FILE_NAME = "net.sourceforge.subsonic.androidapp_preferences";

View File

@ -600,10 +600,12 @@ public class Util extends DownloadActivity {
notification.contentView.setTextViewText(R.id.artist, text);
notification.contentView.setTextViewText(R.id.album, album);
if (playerState == PlayerState.PAUSED)
if (playerState == PlayerState.PAUSED) {
notification.contentView.setImageViewResource(R.id.control_play, R.drawable.ic_appwidget_music_play);
else if (playerState == PlayerState.STARTED)
}
else if (playerState == PlayerState.STARTED) {
notification.contentView.setImageViewResource(R.id.control_play, R.drawable.ic_appwidget_music_pause);
}
// Send the notification and put the service in the foreground.
handler.post(new Runnable() {
@ -612,7 +614,7 @@ public class Util extends DownloadActivity {
startForeground(downloadService, Constants.NOTIFICATION_ID_PLAYING, notification);
}
});
// Update widget
SubsonicAppWidgetProvider4x1.getInstance().notifyChange(context, downloadService, true);
}
@ -673,12 +675,7 @@ public class Util extends DownloadActivity {
public static void registerMediaButtonEventReceiver(Context context) {
// Only do it if enabled in the settings.
SharedPreferences prefs = getPreferences(context);
boolean enabled = prefs.getBoolean(Constants.PREFERENCES_KEY_MEDIA_BUTTONS, true);
if (enabled) {
if (getMediaButtonsPreference(context)) {
// AudioManager.registerMediaButtonEventReceiver() was introduced in Android 2.2.
// Use reflection to maintain compatibility with 1.5.
try {
@ -830,10 +827,20 @@ public class Util extends DownloadActivity {
return Integer.parseInt(prefs.getString(Constants.PREFERENCES_KEY_NETWORK_TIMEOUT, "15000"));
}
public static int getDefaultAlbums(Context context) {
SharedPreferences prefs = getPreferences(context);
return Integer.parseInt(prefs.getString(Constants.PREFERENCES_KEY_DEFAULT_ALBUMS, "5"));
}
public static int getMaxAlbums(Context context) {
SharedPreferences prefs = getPreferences(context);
return Integer.parseInt(prefs.getString(Constants.PREFERENCES_KEY_MAX_ALBUMS, "20"));
}
public static int getDefaultSongs(Context context) {
SharedPreferences prefs = getPreferences(context);
return Integer.parseInt(prefs.getString(Constants.PREFERENCES_KEY_DEFAULT_SONGS, "10"));
}
public static int getMaxSongs(Context context) {
SharedPreferences prefs = getPreferences(context);
@ -845,8 +852,18 @@ public class Util extends DownloadActivity {
return Integer.parseInt(prefs.getString(Constants.PREFERENCES_KEY_MAX_ARTISTS, "10"));
}
public static int getDefaultArtists(Context context) {
SharedPreferences prefs = getPreferences(context);
return Integer.parseInt(prefs.getString(Constants.PREFERENCES_KEY_DEFAULT_ARTISTS, "3"));
}
public static int getBufferLength(Context context) {
SharedPreferences prefs = getPreferences(context);
return Integer.parseInt(prefs.getString(Constants.PREFERENCES_KEY_BUFFER_LENGTH, "5"));
}
public static boolean getMediaButtonsPreference(Context context) {
SharedPreferences prefs = getPreferences(context);
return prefs.getBoolean(Constants.PREFERENCES_KEY_MEDIA_BUTTONS, true);
}
}