remove media button preferences and enable them always
This commit is contained in:
parent
0f5a229df3
commit
800ecc6edb
@ -26,9 +26,6 @@ package ch.blinkenlights.android.vanilla;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.media.AsyncPlayer;
|
||||
import android.media.AudioManager;
|
||||
import android.net.Uri;
|
||||
import android.os.Build;
|
||||
import android.os.SystemClock;
|
||||
@ -49,74 +46,10 @@ public class MediaButtonReceiver extends BroadcastReceiver {
|
||||
*/
|
||||
private static final int DOUBLE_CLICK_DELAY = 600;
|
||||
|
||||
/**
|
||||
* Whether the headset controls should be used. 1 for yes, 0 for no, -1 for
|
||||
* uninitialized.
|
||||
*/
|
||||
private static int sUseControls = -1;
|
||||
/**
|
||||
* Time of the last play/pause click. Used to detect double-clicks.
|
||||
*/
|
||||
private static long sLastClickTime = 0;
|
||||
/**
|
||||
* Whether a beep should be played in response to double clicks be used.
|
||||
* 1 for yes, 0 for no, -1 for uninitialized.
|
||||
*/
|
||||
private static int sBeep = -1;
|
||||
/**
|
||||
* Lazy-loaded AsyncPlayer for beep sounds.
|
||||
*/
|
||||
private static AsyncPlayer sBeepPlayer;
|
||||
/**
|
||||
* Lazy-loaded URI of the beep resource.
|
||||
*/
|
||||
private static Uri sBeepSound;
|
||||
|
||||
/**
|
||||
* Play a beep sound.
|
||||
*/
|
||||
private static void beep(Context context)
|
||||
{
|
||||
if (sBeep == -1) {
|
||||
SharedPreferences settings = SharedPrefHelper.getSettings(context);
|
||||
sBeep = settings.getBoolean(PrefKeys.MEDIA_BUTTON_BEEP, PrefDefaults.MEDIA_BUTTON_BEEP) ? 1 : 0;
|
||||
}
|
||||
|
||||
if (sBeep == 1) {
|
||||
if (sBeepPlayer == null) {
|
||||
sBeepPlayer = new AsyncPlayer("BeepPlayer");
|
||||
sBeepSound = Uri.parse("android.resource://ch.blinkenlights.android.vanilla/raw/beep");
|
||||
}
|
||||
sBeepPlayer.play(context, sBeepSound, false, AudioManager.STREAM_MUSIC);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reload the preferences and enable/disable buttons as appropriate.
|
||||
*
|
||||
* @param context A context to use.
|
||||
*/
|
||||
public static void reloadPreference(Context context)
|
||||
{
|
||||
sUseControls = -1;
|
||||
sBeep = -1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return whether headset controls should be used, loading the preference
|
||||
* if necessary.
|
||||
*
|
||||
* @param context A context to use.
|
||||
*/
|
||||
public static boolean useHeadsetControls(Context context)
|
||||
{
|
||||
if (sUseControls == -1) {
|
||||
SharedPreferences settings = SharedPrefHelper.getSettings(context);
|
||||
sUseControls = settings.getBoolean(PrefKeys.MEDIA_BUTTON, PrefDefaults.MEDIA_BUTTON) ? 1 : 0;
|
||||
}
|
||||
|
||||
return sUseControls == 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Process a media button key press.
|
||||
@ -128,7 +61,7 @@ public class MediaButtonReceiver extends BroadcastReceiver {
|
||||
*/
|
||||
public static boolean processKey(Context context, KeyEvent event)
|
||||
{
|
||||
if (event == null || !useHeadsetControls(context))
|
||||
if (event == null)
|
||||
return false;
|
||||
|
||||
int action = event.getAction();
|
||||
@ -143,7 +76,6 @@ public class MediaButtonReceiver extends BroadcastReceiver {
|
||||
if (action == KeyEvent.ACTION_DOWN) {
|
||||
long time = SystemClock.uptimeMillis();
|
||||
if (time - sLastClickTime < DOUBLE_CLICK_DELAY) {
|
||||
beep(context);
|
||||
Handler handler = new Handler();
|
||||
DelayedClickCounter dcc = new DelayedClickCounter(context, time);
|
||||
handler.postDelayed(dcc, DOUBLE_CLICK_DELAY);
|
||||
|
@ -888,9 +888,6 @@ public final class PlaybackService extends Service
|
||||
updateNotification();
|
||||
} else if (PrefKeys.SCROBBLE.equals(key)) {
|
||||
mScrobble = settings.getBoolean(PrefKeys.SCROBBLE, PrefDefaults.SCROBBLE);
|
||||
} else if (PrefKeys.MEDIA_BUTTON.equals(key) || PrefKeys.MEDIA_BUTTON_BEEP.equals(key)) {
|
||||
MediaButtonReceiver.reloadPreference(this);
|
||||
mRemoteControlClient.initializeRemote();
|
||||
} else if (PrefKeys.COVER_ON_LOCKSCREEN.equals(key)) {
|
||||
mRemoteControlClient.reloadPreference();
|
||||
} else if (PrefKeys.USE_IDLE_TIMEOUT.equals(key) || PrefKeys.IDLE_TIMEOUT.equals(key)) {
|
||||
|
@ -50,8 +50,6 @@ public class PrefDefaults {
|
||||
public static final boolean HEADSET_PAUSE = true;
|
||||
public static final int IDLE_TIMEOUT = 3600;
|
||||
public static final int LIBRARY_PAGE = 0;
|
||||
public static final boolean MEDIA_BUTTON = true;
|
||||
public static final boolean MEDIA_BUTTON_BEEP = true;
|
||||
public static final String NOTIFICATION_ACTION = "0";
|
||||
public static final String NOTIFICATION_VISIBILITY = "0";
|
||||
public static final boolean NOTIFICATION_NAG = false;
|
||||
|
@ -48,8 +48,6 @@ public class PrefKeys {
|
||||
public static final String HEADSET_PAUSE = "headset_pause";
|
||||
public static final String IDLE_TIMEOUT = "idle_timeout";
|
||||
public static final String LIBRARY_PAGE = "library_page";
|
||||
public static final String MEDIA_BUTTON = "media_button";
|
||||
public static final String MEDIA_BUTTON_BEEP = "media_button_beep";
|
||||
public static final String NOTIFICATION_ACTION = "notification_action";
|
||||
public static final String NOTIFICATION_VISIBILITY = "notification_visibility";
|
||||
public static final String PLAYBACK_ON_STARTUP = "playback_on_startup";
|
||||
|
@ -63,8 +63,6 @@ public class RemoteControlImplICS implements RemoteControl.Client {
|
||||
public void initializeRemote() {
|
||||
// make sure there is only one registered remote
|
||||
unregisterRemote();
|
||||
if (MediaButtonReceiver.useHeadsetControls(mContext) == false)
|
||||
return;
|
||||
|
||||
// Receive 'background' play button events
|
||||
AudioManager audioManager = (AudioManager)mContext.getSystemService(Context.AUDIO_SERVICE);
|
||||
|
Binary file not shown.
@ -185,8 +185,6 @@ THE SOFTWARE.
|
||||
<string name="ignore_audiofocus_loss_summary">Keep playing on permanent audio focus loss</string>
|
||||
<string name="media_button_title">Headset/Bluetooth controls</string>
|
||||
<string name="media_button_summary">This is also required for ICS lockscreen controls.</string>
|
||||
<string name="media_button_beep_title">Headset control beep</string>
|
||||
<string name="media_button_beep_summary">Beep after skipping a track with a headset control double click.</string>
|
||||
<string name="headset_only_title">External output only</string>
|
||||
<string name="headset_only_summary">Prevents music from being played through the internal speakers.</string>
|
||||
<string name="headset_pause_title">Pause when unplugged</string>
|
||||
|
@ -43,16 +43,6 @@ THE SOFTWARE.
|
||||
vanilla:sbpCheckBoxKey="ignore_audiofocus_loss"
|
||||
vanilla:sbpCheckBoxText="@string/ignore_audiofocus_loss_summary"
|
||||
/>
|
||||
<CheckBoxPreference
|
||||
android:key="media_button"
|
||||
android:title="@string/media_button_title"
|
||||
android:summary="@string/media_button_summary"
|
||||
android:defaultValue="true" />
|
||||
<CheckBoxPreference
|
||||
android:key="media_button_beep"
|
||||
android:title="@string/media_button_beep_title"
|
||||
android:summary="@string/media_button_beep_summary"
|
||||
android:defaultValue="true" />
|
||||
<CheckBoxPreference
|
||||
android:key="headset_only"
|
||||
android:title="@string/headset_only_title"
|
||||
|
Loading…
x
Reference in New Issue
Block a user