Remove RemoteControlClientCompat, fix Remote Control, add alwaysShowNotification option

This commit is contained in:
Joshua Bahnsen 2013-02-22 18:23:41 -07:00
parent edd5fdb5a5
commit 4c7c0ebf90
8 changed files with 106 additions and 531 deletions

View File

@ -349,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=0x7f0900ec;
public static final int background_task_network_error=0x7f0900ee;
public static final int background_task_no_network=0x7f0900ed;
public static final int background_task_not_found=0x7f0900ef;
public static final int background_task_parse_error=0x7f0900f0;
public static final int background_task_wait=0x7f0900eb;
public static final int background_task_loading=0x7f0900ee;
public static final int background_task_network_error=0x7f0900f0;
public static final int background_task_no_network=0x7f0900ef;
public static final int background_task_not_found=0x7f0900f1;
public static final int background_task_parse_error=0x7f0900f2;
public static final int background_task_wait=0x7f0900ed;
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;
@ -402,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=0x7f0900fd;
public static final int equalizer_label=0x7f0900fc;
public static final int equalizer_preset=0x7f0900fe;
public static final int equalizer_enabled=0x7f0900ff;
public static final int equalizer_label=0x7f0900fe;
public static final int equalizer_preset=0x7f090100;
public static final int error_label=0x7f09006b;
public static final int help_back=0x7f090027;
public static final int help_close=0x7f090028;
@ -439,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=0x7f0900ea;
public static final int parser_artist_count=0x7f0900f8;
public static final int parser_not_authenticated=0x7f0900f6;
public static final int parser_not_authorized=0x7f0900f7;
public static final int parser_reading=0x7f0900f2;
public static final int parser_reading_done=0x7f0900f3;
public static final int parser_upgrade_client=0x7f0900f4;
public static final int parser_upgrade_server=0x7f0900f5;
public static final int music_service_retry=0x7f0900ec;
public static final int parser_artist_count=0x7f0900fa;
public static final int parser_not_authenticated=0x7f0900f8;
public static final int parser_not_authorized=0x7f0900f9;
public static final int parser_reading=0x7f0900f4;
public static final int parser_reading_done=0x7f0900f5;
public static final int parser_upgrade_client=0x7f0900f6;
public static final int parser_upgrade_server=0x7f0900f7;
public static final int play_video_loading=0x7f09002b;
public static final int play_video_noplugin=0x7f09002c;
/** <string name="menu.exit">TODO: Exit</string>
@ -481,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=0x7f0900fb;
public static final int select_artist_folder=0x7f0900fa;
public static final int select_artist_refresh=0x7f0900f9;
public static final int select_artist_all_folders=0x7f0900fd;
public static final int select_artist_folder=0x7f0900fc;
public static final int select_artist_refresh=0x7f0900fb;
public static final int select_playlist_empty=0x7f090047;
public static final int service_connecting=0x7f0900f1;
public static final int service_connecting=0x7f0900f3;
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;
@ -511,9 +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=0x7f0900e8;
public static final int settings_default_artists=0x7f0900e7;
public static final int settings_default_songs=0x7f0900e9;
public static final int settings_default_albums=0x7f0900ea;
public static final int settings_default_artists=0x7f0900e9;
public static final int settings_default_songs=0x7f0900eb;
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>
@ -522,26 +522,26 @@ public final class R {
public static final int settings_hide_media_toast=0x7f0900ad;
public static final int settings_invalid_url=0x7f09007e;
public static final int settings_invalid_username=0x7f09007f;
public static final int settings_max_albums=0x7f0900ca;
public static final int settings_max_albums_10=0x7f0900cc;
public static final int settings_max_albums_100=0x7f0900d1;
public static final int settings_max_albums_20=0x7f0900cd;
public static final int settings_max_albums_250=0x7f0900d2;
public static final int settings_max_albums_30=0x7f0900ce;
public static final int settings_max_albums_40=0x7f0900cf;
public static final int settings_max_albums_5=0x7f0900cb;
public static final int settings_max_albums_50=0x7f0900d0;
public static final int settings_max_albums_500=0x7f0900d3;
public static final int settings_max_artists=0x7f0900dd;
public static final int settings_max_artists_10=0x7f0900e0;
public static final int settings_max_artists_100=0x7f0900e4;
public static final int settings_max_artists_200=0x7f0900e5;
public static final int settings_max_artists_25=0x7f0900e1;
public static final int settings_max_artists_3=0x7f0900de;
public static final int settings_max_artists_5=0x7f0900df;
public static final int settings_max_artists_50=0x7f0900e2;
public static final int settings_max_artists_500=0x7f0900e6;
public static final int settings_max_artists_75=0x7f0900e3;
public static final int settings_max_albums=0x7f0900cc;
public static final int settings_max_albums_10=0x7f0900ce;
public static final int settings_max_albums_100=0x7f0900d3;
public static final int settings_max_albums_20=0x7f0900cf;
public static final int settings_max_albums_250=0x7f0900d4;
public static final int settings_max_albums_30=0x7f0900d0;
public static final int settings_max_albums_40=0x7f0900d1;
public static final int settings_max_albums_5=0x7f0900cd;
public static final int settings_max_albums_50=0x7f0900d2;
public static final int settings_max_albums_500=0x7f0900d5;
public static final int settings_max_artists=0x7f0900df;
public static final int settings_max_artists_10=0x7f0900e2;
public static final int settings_max_artists_100=0x7f0900e6;
public static final int settings_max_artists_200=0x7f0900e7;
public static final int settings_max_artists_25=0x7f0900e3;
public static final int settings_max_artists_3=0x7f0900e0;
public static final int settings_max_artists_5=0x7f0900e1;
public static final int settings_max_artists_50=0x7f0900e4;
public static final int settings_max_artists_500=0x7f0900e8;
public static final int settings_max_artists_75=0x7f0900e5;
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;
@ -555,15 +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=0x7f0900d4;
public static final int settings_max_songs_10=0x7f0900d6;
public static final int settings_max_songs_100=0x7f0900da;
public static final int settings_max_songs_200=0x7f0900db;
public static final int settings_max_songs_25=0x7f0900d7;
public static final int settings_max_songs_5=0x7f0900d5;
public static final int settings_max_songs_50=0x7f0900d8;
public static final int settings_max_songs_500=0x7f0900dc;
public static final int settings_max_songs_75=0x7f0900d9;
public static final int settings_max_songs=0x7f0900d6;
public static final int settings_max_songs_10=0x7f0900d8;
public static final int settings_max_songs_100=0x7f0900dc;
public static final int settings_max_songs_200=0x7f0900dd;
public static final int settings_max_songs_25=0x7f0900d9;
public static final int settings_max_songs_5=0x7f0900d7;
public static final int settings_max_songs_50=0x7f0900da;
public static final int settings_max_songs_500=0x7f0900de;
public static final int settings_max_songs_75=0x7f0900db;
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;
@ -597,9 +597,11 @@ public final class R {
public static final int settings_server_unused2=0x7f090070;
public static final int settings_server_username=0x7f090073;
public static final int settings_servers_title=0x7f09006e;
public static final int settings_show_lockscreen_controls=0x7f0900c6;
public static final int settings_show_lockscreen_controls_summary=0x7f0900c7;
public static final int settings_show_lockscreen_controls=0x7f0900c8;
public static final int settings_show_lockscreen_controls_summary=0x7f0900c9;
public static final int settings_show_notification=0x7f0900c4;
public static final int settings_show_notification_always=0x7f0900c6;
public static final int settings_show_notification_always_summary=0x7f0900c7;
public static final int settings_show_notification_summary=0x7f0900c5;
public static final int settings_test_connection_title=0x7f09006d;
public static final int settings_testing_connection=0x7f09007a;
@ -610,21 +612,21 @@ 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=0x7f090106;
public static final int settings_theme_wheat=0x7f090108;
public static final int settings_title=0x7f09006c;
public static final int settings_use_stream_proxy=0x7f0900c8;
public static final int settings_use_stream_proxy_summary=0x7f0900c9;
public static final int settings_use_stream_proxy=0x7f0900ca;
public static final int settings_use_stream_proxy_summary=0x7f0900cb;
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=0x7f090105;
public static final int util_bytes_format_gigabyte=0x7f090102;
public static final int util_bytes_format_kilobyte=0x7f090104;
public static final int util_bytes_format_megabyte=0x7f090103;
public static final int widget_initial_text=0x7f0900ff;
public static final int widget_sdcard_busy=0x7f090100;
public static final int widget_sdcard_missing=0x7f090101;
public static final int util_bytes_format_byte=0x7f090107;
public static final int util_bytes_format_gigabyte=0x7f090104;
public static final int util_bytes_format_kilobyte=0x7f090106;
public static final int util_bytes_format_megabyte=0x7f090105;
public static final int widget_initial_text=0x7f090101;
public static final int widget_sdcard_busy=0x7f090102;
public static final int widget_sdcard_missing=0x7f090103;
}
public static final class style {
public static final int Dark=0x7f0b0000;

View File

@ -217,6 +217,8 @@
<string name="settings.network_timeout_120000">120 seconds</string>
<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.show_notification_always">Always Show Notification</string>
<string name="settings.show_notification_always_summary">Always show now playing notification when playlist is populated</string>
<string name="settings.show_lockscreen_controls">Show Lock Screen Controls</string>
<string name="settings.show_lockscreen_controls_summary">Show playback controls on the lock screen</string>
<string name="settings.use_stream_proxy">Use Stream Proxy</string>

View File

@ -262,6 +262,12 @@
a:key="showNotification"
a:defaultValue="true"/>
<CheckBoxPreference
a:title="@string/settings.show_notification_always"
a:summary="@string/settings.show_notification_always_summary"
a:key="alwaysShowNotification"
a:defaultValue="true"/>
<CheckBoxPreference
a:title="@string/settings.show_lockscreen_controls"
a:summary="@string/settings.show_lockscreen_controls_summary"

View File

@ -51,9 +51,6 @@ import net.sourceforge.subsonic.androidapp.util.ShufflePlayBuffer;
import net.sourceforge.subsonic.androidapp.util.SimpleServiceBinder;
import net.sourceforge.subsonic.androidapp.util.StreamProxy;
import net.sourceforge.subsonic.androidapp.util.Util;
import net.sourceforge.subsonic.androidapp.util.RemoteControlHelper;
import net.sourceforge.subsonic.androidapp.util.RemoteControlClientCompat;
import java.io.File;
import java.util.ArrayList;
import java.util.Collections;
@ -107,10 +104,8 @@ public class DownloadServiceImpl extends Service implements DownloadService {
private boolean showVisualization;
private boolean jukeboxEnabled;
private StreamProxy proxy;
private static MusicDirectory.Entry currentSong;
RemoteControlClientCompat remoteControlClientCompat;
private RemoteControlClient remoteControlClient;
static {
try {
@ -207,7 +202,7 @@ public class DownloadServiceImpl extends Service implements DownloadService {
}
AudioManager audioManager = (AudioManager) this.getSystemService(Context.AUDIO_SERVICE);
RemoteControlHelper.unregisterRemoteControlClient(audioManager, remoteControlClientCompat);
audioManager.unregisterRemoteControlClient(remoteControlClient);
notification = null;
instance = null;
}
@ -679,8 +674,10 @@ public class DownloadServiceImpl extends Service implements DownloadService {
lifecycleSupport.serializeDownloadQueue();
}
boolean show = playerState == PlayerState.STARTED || playerState == PlayerState.PAUSED;
boolean hide = playerState == PlayerState.IDLE || playerState == PlayerState.STOPPED;
boolean showWhenPaused = (playerState == PlayerState.PAUSED && Util.isNotificationAlwaysEnabled(this));
boolean show = playerState == PlayerState.STARTED || showWhenPaused;
boolean hide = playerState == PlayerState.IDLE || playerState == PlayerState.STOPPED || !showWhenPaused;
Util.broadcastPlaybackStatusChange(this, playerState);
this.playerState = playerState;
@ -753,42 +750,43 @@ public class DownloadServiceImpl extends Service implements DownloadService {
AudioManager audioManager = (AudioManager) this.getSystemService(Context.AUDIO_SERVICE);
audioManager.requestAudioFocus(_afChangeListener, AudioManager.STREAM_MUSIC, AudioManager.AUDIOFOCUS_GAIN);
if (remoteControlClientCompat == null) {
if (remoteControlClient == null) {
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);
}
remoteControlClient = new RemoteControlClient(PendingIntent.getBroadcast(this, 0, intent, 0));
audioManager.registerRemoteControlClient(remoteControlClient);
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.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_PLAY_PAUSE |
RemoteControlClient.FLAG_KEY_MEDIA_STOP);
}
switch (playerState)
{
case STARTED:
remoteControlClient.setPlaybackState(RemoteControlClient.PLAYSTATE_PLAYING);
break;
case PAUSED:
remoteControlClient.setPlaybackState(RemoteControlClient.PLAYSTATE_PAUSED);
break;
case IDLE:
case STOPPED:
remoteControlClient.setPlaybackState(RemoteControlClient.PLAYSTATE_STOPPED);
break;
}
try {
if (currentPlaying != null) {
if (currentSong != currentPlaying.getSong()) {
currentSong = currentPlaying.getSong();
String artist = currentSong.getArtist();
String album = currentSong.getAlbum();
String title = currentSong.getArtist() + " - " + currentSong.getTitle();
String title = artist + " - " + currentSong.getTitle();
Integer duration = currentSong.getDuration();
MusicService musicService = MusicServiceFactory.getMusicService(this);
@ -797,13 +795,13 @@ public class DownloadServiceImpl extends Service implements DownloadService {
Bitmap bitmap = musicService.getCoverArt(this, currentSong, size, true, null);
// Update the remote controls
remoteControlClientCompat
remoteControlClient
.editMetadata(true)
.putString(MediaMetadataRetriever.METADATA_KEY_TITLE, title)
.putString(MediaMetadataRetriever.METADATA_KEY_ARTIST, currentSong.getArtist())
.putString(MediaMetadataRetriever.METADATA_KEY_ARTIST, artist)
.putString(MediaMetadataRetriever.METADATA_KEY_ALBUM, album)
.putLong(MediaMetadataRetriever.METADATA_KEY_DURATION, duration)
.putBitmap(RemoteControlClientCompat.MetadataEditorCompat.METADATA_KEY_ARTWORK, bitmap)
.putBitmap(RemoteControlClient.MetadataEditor.BITMAP_KEY_ARTWORK, bitmap)
.apply();
}
}

View File

@ -78,6 +78,7 @@ public final class Constants {
public static final String PREFERENCES_KEY_BUFFER_LENGTH = "bufferLength";
public static final String PREFERENCES_KEY_NETWORK_TIMEOUT = "networkTimeout";
public static final String PREFERENCES_KEY_SHOW_NOTIFICATION = "showNotification";
public static final String PREFERENCES_KEY_ALWAYS_SHOW_NOTIFICATION = "alwaysShowNotification";
public static final String PREFERENCES_KEY_SHOW_LOCK_SCREEN_CONTROLS = "showLockScreen";
public static final String PREFERENCES_KEY_MAX_ALBUMS = "maxAlbums";
public static final String PREFERENCES_KEY_MAX_SONGS = "maxSongs";

View File

@ -1,353 +0,0 @@
/*
* Copyright (C) 2011 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.sourceforge.subsonic.androidapp.util;
import android.app.PendingIntent;
import android.graphics.Bitmap;
import android.os.Looper;
import android.util.Log;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
/**
* RemoteControlClient enables exposing information meant to be consumed by remote controls capable
* of displaying metadata, artwork and media transport control buttons. A remote control client
* object is associated with a media button event receiver. This event receiver must have been
* previously registered with
* {@link android.media.AudioManager#registerMediaButtonEventReceiver(android.content.ComponentName)}
* before the RemoteControlClient can be registered through
* {@link android.media.AudioManager#registerRemoteControlClient(android.media.RemoteControlClient)}.
*/
@SuppressWarnings({"rawtypes", "unchecked"})
public class RemoteControlClientCompat {
private static final String TAG = "RemoteControlCompat";
private static Class sRemoteControlClientClass;
// RCC short for RemoteControlClient
private static Method sRCCEditMetadataMethod;
private static Method sRCCSetPlayStateMethod;
private static Method sRCCSetTransportControlFlags;
private static boolean sHasRemoteControlAPIs = false;
static {
try {
ClassLoader classLoader = RemoteControlClientCompat.class.getClassLoader();
sRemoteControlClientClass = getActualRemoteControlClientClass(classLoader);
// dynamically populate the playstate and flag values in case they change
// in future versions.
for (Field field : RemoteControlClientCompat.class.getFields()) {
try {
Field realField = sRemoteControlClientClass.getField(field.getName());
Object realValue = realField.get(null);
field.set(null, realValue);
} catch (NoSuchFieldException e) {
Log.w(TAG, "Could not get real field: " + field.getName());
} catch (IllegalArgumentException e) {
Log.w(TAG, "Error trying to pull field value for: " + field.getName()
+ " " + e.getMessage());
} catch (IllegalAccessException e) {
Log.w(TAG, "Error trying to pull field value for: " + field.getName()
+ " " + e.getMessage());
}
}
// get the required public methods on RemoteControlClient
sRCCEditMetadataMethod = sRemoteControlClientClass.getMethod("editMetadata",
boolean.class);
sRCCSetPlayStateMethod = sRemoteControlClientClass.getMethod("setPlaybackState",
int.class);
sRCCSetTransportControlFlags = sRemoteControlClientClass.getMethod(
"setTransportControlFlags", int.class);
sHasRemoteControlAPIs = true;
} catch (ClassNotFoundException e) {
// Silently fail when running on an OS before ICS.
} catch (NoSuchMethodException e) {
// Silently fail when running on an OS before ICS.
} catch (IllegalArgumentException e) {
// Silently fail when running on an OS before ICS.
} catch (SecurityException e) {
// Silently fail when running on an OS before ICS.
}
}
public static Class getActualRemoteControlClientClass(ClassLoader classLoader)
throws ClassNotFoundException {
return classLoader.loadClass("android.media.RemoteControlClient");
}
private Object mActualRemoteControlClient;
public RemoteControlClientCompat(PendingIntent pendingIntent) {
if (!sHasRemoteControlAPIs) {
return;
}
try {
mActualRemoteControlClient =
sRemoteControlClientClass.getConstructor(PendingIntent.class)
.newInstance(pendingIntent);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
public RemoteControlClientCompat(PendingIntent pendingIntent, Looper looper) {
if (!sHasRemoteControlAPIs) {
return;
}
try {
mActualRemoteControlClient =
sRemoteControlClientClass.getConstructor(PendingIntent.class, Looper.class)
.newInstance(pendingIntent, looper);
} catch (Exception e) {
Log.e(TAG, "Error creating new instance of " + sRemoteControlClientClass.getName(), e);
}
}
/**
* Class used to modify metadata in a {@link android.media.RemoteControlClient} object. Use
* {@link android.media.RemoteControlClient#editMetadata(boolean)} to create an instance of an
* editor, on which you set the metadata for the RemoteControlClient instance. Once all the
* information has been set, use {@link #apply()} to make it the new metadata that should be
* displayed for the associated client. Once the metadata has been "applied", you cannot reuse
* this instance of the MetadataEditor.
*/
public class MetadataEditorCompat {
private Method mPutStringMethod;
private Method mPutBitmapMethod;
private Method mPutLongMethod;
private Method mClearMethod;
private Method mApplyMethod;
private Object mActualMetadataEditor;
/**
* The metadata key for the content artwork / album art.
*/
public final static int METADATA_KEY_ARTWORK = 100;
private MetadataEditorCompat(Object actualMetadataEditor) {
if (sHasRemoteControlAPIs && actualMetadataEditor == null) {
throw new IllegalArgumentException("Remote Control API's exist, " +
"should not be given a null MetadataEditor");
}
if (sHasRemoteControlAPIs) {
Class metadataEditorClass = actualMetadataEditor.getClass();
try {
mPutStringMethod = metadataEditorClass.getMethod("putString",
int.class, String.class);
mPutBitmapMethod = metadataEditorClass.getMethod("putBitmap",
int.class, Bitmap.class);
mPutLongMethod = metadataEditorClass.getMethod("putLong",
int.class, long.class);
mClearMethod = metadataEditorClass.getMethod("clear", new Class[]{});
mApplyMethod = metadataEditorClass.getMethod("apply", new Class[]{});
} catch (Exception e) {
throw new RuntimeException(e.getMessage(), e);
}
}
mActualMetadataEditor = actualMetadataEditor;
}
/**
* Adds textual information to be displayed.
* Note that none of the information added after {@link #apply()} has been called,
* will be displayed.
* @param key The identifier of a the metadata field to set. Valid values are
* {@link android.media.MediaMetadataRetriever#METADATA_KEY_ALBUM},
* {@link android.media.MediaMetadataRetriever#METADATA_KEY_ALBUMARTIST},
* {@link android.media.MediaMetadataRetriever#METADATA_KEY_TITLE},
* {@link android.media.MediaMetadataRetriever#METADATA_KEY_ARTIST},
* {@link android.media.MediaMetadataRetriever#METADATA_KEY_AUTHOR},
* {@link android.media.MediaMetadataRetriever#METADATA_KEY_COMPILATION},
* {@link android.media.MediaMetadataRetriever#METADATA_KEY_COMPOSER},
* {@link android.media.MediaMetadataRetriever#METADATA_KEY_DATE},
* {@link android.media.MediaMetadataRetriever#METADATA_KEY_GENRE},
* {@link android.media.MediaMetadataRetriever#METADATA_KEY_TITLE},
* {@link android.media.MediaMetadataRetriever#METADATA_KEY_WRITER}.
* @param value The text for the given key, or {@code null} to signify there is no valid
* information for the field.
* @return Returns a reference to the same MetadataEditor object, so you can chain put
* calls together.
*/
public MetadataEditorCompat putString(int key, String value) {
if (sHasRemoteControlAPIs) {
try {
mPutStringMethod.invoke(mActualMetadataEditor, key, value);
} catch (Exception e) {
throw new RuntimeException(e.getMessage(), e);
}
}
return this;
}
/**
* Sets the album / artwork picture to be displayed on the remote control.
* @param key the identifier of the bitmap to set. The only valid value is
* {@link #METADATA_KEY_ARTWORK}
* @param bitmap The bitmap for the artwork, or null if there isn't any.
* @return Returns a reference to the same MetadataEditor object, so you can chain put
* calls together.
* @throws IllegalArgumentException
* @see android.graphics.Bitmap
*/
public MetadataEditorCompat putBitmap(int key, Bitmap bitmap) {
if (sHasRemoteControlAPIs) {
try {
mPutBitmapMethod.invoke(mActualMetadataEditor, key, bitmap);
} catch (Exception e) {
throw new RuntimeException(e.getMessage(), e);
}
}
return this;
}
/**
* Adds numerical information to be displayed.
* Note that none of the information added after {@link #apply()} has been called,
* will be displayed.
* @param key the identifier of a the metadata field to set. Valid values are
* {@link android.media.MediaMetadataRetriever#METADATA_KEY_CD_TRACK_NUMBER},
* {@link android.media.MediaMetadataRetriever#METADATA_KEY_DISC_NUMBER},
* {@link android.media.MediaMetadataRetriever#METADATA_KEY_DURATION} (with a value
* expressed in milliseconds),
* {@link android.media.MediaMetadataRetriever#METADATA_KEY_YEAR}.
* @param value The long value for the given key
* @return Returns a reference to the same MetadataEditor object, so you can chain put
* calls together.
* @throws IllegalArgumentException
*/
public MetadataEditorCompat putLong(int key, long value) {
if (sHasRemoteControlAPIs) {
try {
mPutLongMethod.invoke(mActualMetadataEditor, key, value);
} catch (Exception e) {
throw new RuntimeException(e.getMessage(), e);
}
}
return this;
}
/**
* Clears all the metadata that has been set since the MetadataEditor instance was
* created with {@link android.media.RemoteControlClient#editMetadata(boolean)}.
*/
public void clear() {
if (sHasRemoteControlAPIs) {
try {
mClearMethod.invoke(mActualMetadataEditor, (Object[]) null);
} catch (Exception e) {
throw new RuntimeException(e.getMessage(), e);
}
}
}
/**
* Associates all the metadata that has been set since the MetadataEditor instance was
* created with {@link android.media.RemoteControlClient#editMetadata(boolean)}, or since
* {@link #clear()} was called, with the RemoteControlClient. Once "applied", this
* MetadataEditor cannot be reused to edit the RemoteControlClient's metadata.
*/
public void apply() {
if (sHasRemoteControlAPIs) {
try {
mApplyMethod.invoke(mActualMetadataEditor, (Object[]) null);
} catch (Exception e) {
throw new RuntimeException(e.getMessage(), e);
}
}
}
}
/**
* Creates a {@link android.media.RemoteControlClient.MetadataEditor}.
* @param startEmpty Set to false if you want the MetadataEditor to contain the metadata that
* was previously applied to the RemoteControlClient, or true if it is to be created empty.
* @return a new MetadataEditor instance.
*/
public MetadataEditorCompat editMetadata(boolean startEmpty) {
Object metadataEditor;
if (sHasRemoteControlAPIs) {
try {
metadataEditor = sRCCEditMetadataMethod.invoke(mActualRemoteControlClient,
startEmpty);
} catch (Exception e) {
throw new RuntimeException(e);
}
} else {
metadataEditor = null;
}
return new MetadataEditorCompat(metadataEditor);
}
/**
* Sets the current playback state.
* @param state The current playback state, one of the following values:
* {@link android.media.RemoteControlClient#PLAYSTATE_STOPPED},
* {@link android.media.RemoteControlClient#PLAYSTATE_PAUSED},
* {@link android.media.RemoteControlClient#PLAYSTATE_PLAYING},
* {@link android.media.RemoteControlClient#PLAYSTATE_FAST_FORWARDING},
* {@link android.media.RemoteControlClient#PLAYSTATE_REWINDING},
* {@link android.media.RemoteControlClient#PLAYSTATE_SKIPPING_FORWARDS},
* {@link android.media.RemoteControlClient#PLAYSTATE_SKIPPING_BACKWARDS},
* {@link android.media.RemoteControlClient#PLAYSTATE_BUFFERING},
* {@link android.media.RemoteControlClient#PLAYSTATE_ERROR}.
*/
public void setPlaybackState(int state) {
if (sHasRemoteControlAPIs) {
try {
sRCCSetPlayStateMethod.invoke(mActualRemoteControlClient, state);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
}
/**
* Sets the flags for the media transport control buttons that this client supports.
* @param transportControlFlags A combination of the following flags:
* {@link android.media.RemoteControlClient#FLAG_KEY_MEDIA_PREVIOUS},
* {@link android.media.RemoteControlClient#FLAG_KEY_MEDIA_REWIND},
* {@link android.media.RemoteControlClient#FLAG_KEY_MEDIA_PLAY},
* {@link android.media.RemoteControlClient#FLAG_KEY_MEDIA_PLAY_PAUSE},
* {@link android.media.RemoteControlClient#FLAG_KEY_MEDIA_PAUSE},
* {@link android.media.RemoteControlClient#FLAG_KEY_MEDIA_STOP},
* {@link android.media.RemoteControlClient#FLAG_KEY_MEDIA_FAST_FORWARD},
* {@link android.media.RemoteControlClient#FLAG_KEY_MEDIA_NEXT}
*/
public void setTransportControlFlags(int transportControlFlags) {
if (sHasRemoteControlAPIs) {
try {
sRCCSetTransportControlFlags.invoke(mActualRemoteControlClient,
transportControlFlags);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
}
public final Object getActualRemoteControlClientObject() {
return mActualRemoteControlClient;
}
}

View File

@ -1,86 +0,0 @@
/*
* Copyright (C) 2011 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.sourceforge.subsonic.androidapp.util;
import android.media.AudioManager;
import android.util.Log;
import java.lang.reflect.Method;
/**
* Contains methods to handle registering/unregistering remote control clients. These methods only
* run on ICS devices. On previous devices, all methods are no-ops.
*/
@SuppressWarnings({"unchecked", "rawtypes"})
public class RemoteControlHelper {
private static final String TAG = "RemoteControlHelper";
private static boolean sHasRemoteControlAPIs = false;
private static Method sRegisterRemoteControlClientMethod;
private static Method sUnregisterRemoteControlClientMethod;
static {
try {
ClassLoader classLoader = RemoteControlHelper.class.getClassLoader();
Class sRemoteControlClientClass =
RemoteControlClientCompat.getActualRemoteControlClientClass(classLoader);
sRegisterRemoteControlClientMethod = AudioManager.class.getMethod(
"registerRemoteControlClient", new Class[]{sRemoteControlClientClass});
sUnregisterRemoteControlClientMethod = AudioManager.class.getMethod(
"unregisterRemoteControlClient", new Class[]{sRemoteControlClientClass});
sHasRemoteControlAPIs = true;
} catch (ClassNotFoundException e) {
// Silently fail when running on an OS before ICS.
} catch (NoSuchMethodException e) {
// Silently fail when running on an OS before ICS.
} catch (IllegalArgumentException e) {
// Silently fail when running on an OS before ICS.
} catch (SecurityException e) {
// Silently fail when running on an OS before ICS.
}
}
public static void registerRemoteControlClient(AudioManager audioManager,
RemoteControlClientCompat remoteControlClient) {
if (!sHasRemoteControlAPIs) {
return;
}
try {
sRegisterRemoteControlClientMethod.invoke(audioManager,
remoteControlClient.getActualRemoteControlClientObject());
} catch (Exception e) {
Log.e(TAG, e.getMessage(), e);
}
}
public static void unregisterRemoteControlClient(AudioManager audioManager,
RemoteControlClientCompat remoteControlClient) {
if (!sHasRemoteControlAPIs) {
return;
}
try {
sUnregisterRemoteControlClientMethod.invoke(audioManager,
remoteControlClient.getActualRemoteControlClientObject());
} catch (Exception e) {
Log.e(TAG, e.getMessage(), e);
}
}
}

View File

@ -142,6 +142,11 @@ public class Util extends DownloadActivity {
return prefs.getBoolean(Constants.PREFERENCES_KEY_SHOW_NOTIFICATION, false);
}
public static boolean isNotificationAlwaysEnabled(Context context) {
SharedPreferences prefs = getPreferences(context);
return prefs.getBoolean(Constants.PREFERENCES_KEY_ALWAYS_SHOW_NOTIFICATION, false);
}
public static boolean isLockScreenEnabled(Context context) {
SharedPreferences prefs = getPreferences(context);
return prefs.getBoolean(Constants.PREFERENCES_KEY_SHOW_LOCK_SCREEN_CONTROLS, false);