Get rid of CompatFroyo
This commit is contained in:
parent
c3cdcc50ec
commit
750fbb47b3
src/ch/blinkenlights/android/vanilla
@ -1,91 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2011 Christopher Eby <kreed@kreed.org>
|
|
||||||
*
|
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
|
||||||
* in the Software without restriction, including without limitation the rights
|
|
||||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
* copies of the Software, and to permit persons to whom the Software is
|
|
||||||
* furnished to do so, subject to the following conditions:
|
|
||||||
*
|
|
||||||
* The above copyright notice and this permission notice shall be included in
|
|
||||||
* all copies or substantial portions of the Software.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
||||||
* THE SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package ch.blinkenlights.android.vanilla;
|
|
||||||
|
|
||||||
import android.annotation.TargetApi;
|
|
||||||
import android.app.backup.BackupManager;
|
|
||||||
import android.content.ComponentName;
|
|
||||||
import android.content.Context;
|
|
||||||
import android.media.AudioManager;
|
|
||||||
import android.view.VelocityTracker;
|
|
||||||
import android.view.ViewConfiguration;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Framework methods only in Froyo or above go here.
|
|
||||||
*/
|
|
||||||
@TargetApi(8)
|
|
||||||
public class CompatFroyo implements AudioManager.OnAudioFocusChangeListener {
|
|
||||||
/**
|
|
||||||
* Instance of the audio focus listener created by {@link #createAudioFocus()}.
|
|
||||||
*/
|
|
||||||
private static CompatFroyo sAudioFocus;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Calls {@link AudioManager#registerMediaButtonEventReceiver(ComponentName)}.
|
|
||||||
*/
|
|
||||||
public static void registerMediaButtonEventReceiver(AudioManager manager, ComponentName receiver)
|
|
||||||
{
|
|
||||||
manager.registerMediaButtonEventReceiver(receiver);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Calls {@link AudioManager#unregisterMediaButtonEventReceiver(ComponentName)}.
|
|
||||||
*/
|
|
||||||
public static void unregisterMediaButtonEventReceiver(AudioManager manager, ComponentName receiver)
|
|
||||||
{
|
|
||||||
manager.unregisterMediaButtonEventReceiver(receiver);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Calls {@link BackupManager#dataChanged()}.
|
|
||||||
*/
|
|
||||||
public static void dataChanged(Context context)
|
|
||||||
{
|
|
||||||
new BackupManager(context).dataChanged();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates an audio focus listener that calls back to {@link PlaybackService#onAudioFocusChange(int)}.
|
|
||||||
*/
|
|
||||||
public static void createAudioFocus()
|
|
||||||
{
|
|
||||||
sAudioFocus = new CompatFroyo();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Calls {@link AudioManager#requestAudioFocus(AudioManager.OnAudioFocusChangeListener, int, int)}
|
|
||||||
*/
|
|
||||||
public static void requestAudioFocus(AudioManager manager)
|
|
||||||
{
|
|
||||||
manager.requestAudioFocus(sAudioFocus, AudioManager.STREAM_MUSIC, AudioManager.AUDIOFOCUS_GAIN);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onAudioFocusChange(int type)
|
|
||||||
{
|
|
||||||
PlaybackService service = PlaybackService.sInstance;
|
|
||||||
if (service != null) {
|
|
||||||
service.onAudioFocusChange(type);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -224,7 +224,7 @@ public class MediaButtonReceiver extends BroadcastReceiver {
|
|||||||
|
|
||||||
AudioManager audioManager = (AudioManager)context.getSystemService(Context.AUDIO_SERVICE);
|
AudioManager audioManager = (AudioManager)context.getSystemService(Context.AUDIO_SERVICE);
|
||||||
ComponentName receiver = new ComponentName(context.getPackageName(), MediaButtonReceiver.class.getName());
|
ComponentName receiver = new ComponentName(context.getPackageName(), MediaButtonReceiver.class.getName());
|
||||||
CompatFroyo.registerMediaButtonEventReceiver(audioManager, receiver);
|
audioManager.registerMediaButtonEventReceiver(receiver);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -236,7 +236,7 @@ public class MediaButtonReceiver extends BroadcastReceiver {
|
|||||||
{
|
{
|
||||||
AudioManager audioManager = (AudioManager)context.getSystemService(Context.AUDIO_SERVICE);
|
AudioManager audioManager = (AudioManager)context.getSystemService(Context.AUDIO_SERVICE);
|
||||||
ComponentName receiver = new ComponentName(context.getPackageName(), MediaButtonReceiver.class.getName());
|
ComponentName receiver = new ComponentName(context.getPackageName(), MediaButtonReceiver.class.getName());
|
||||||
CompatFroyo.unregisterMediaButtonEventReceiver(audioManager, receiver);
|
audioManager.unregisterMediaButtonEventReceiver(receiver);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -27,6 +27,7 @@ import android.app.Notification;
|
|||||||
import android.app.NotificationManager;
|
import android.app.NotificationManager;
|
||||||
import android.app.PendingIntent;
|
import android.app.PendingIntent;
|
||||||
import android.app.Service;
|
import android.app.Service;
|
||||||
|
import android.app.backup.BackupManager;
|
||||||
import android.appwidget.AppWidgetManager;
|
import android.appwidget.AppWidgetManager;
|
||||||
import android.content.BroadcastReceiver;
|
import android.content.BroadcastReceiver;
|
||||||
import android.content.ComponentName;
|
import android.content.ComponentName;
|
||||||
@ -79,6 +80,7 @@ public final class PlaybackService extends Service
|
|||||||
, SharedPreferences.OnSharedPreferenceChangeListener
|
, SharedPreferences.OnSharedPreferenceChangeListener
|
||||||
, SongTimeline.Callback
|
, SongTimeline.Callback
|
||||||
, SensorEventListener
|
, SensorEventListener
|
||||||
|
, AudioManager.OnAudioFocusChangeListener
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Name of the state file.
|
* Name of the state file.
|
||||||
@ -404,8 +406,6 @@ public final class PlaybackService extends Service
|
|||||||
mNotificationManager = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);
|
mNotificationManager = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);
|
||||||
mAudioManager = (AudioManager)getSystemService(AUDIO_SERVICE);
|
mAudioManager = (AudioManager)getSystemService(AUDIO_SERVICE);
|
||||||
|
|
||||||
CompatFroyo.createAudioFocus();
|
|
||||||
|
|
||||||
SharedPreferences settings = getSettings(this);
|
SharedPreferences settings = getSettings(this);
|
||||||
settings.registerOnSharedPreferenceChangeListener(this);
|
settings.registerOnSharedPreferenceChangeListener(this);
|
||||||
mNotificationMode = Integer.parseInt(settings.getString(PrefKeys.NOTIFICATION_MODE, "1"));
|
mNotificationMode = Integer.parseInt(settings.getString(PrefKeys.NOTIFICATION_MODE, "1"));
|
||||||
@ -805,8 +805,8 @@ public final class PlaybackService extends Service
|
|||||||
} else if (PrefKeys.ENABLE_READAHEAD.equals(key)) {
|
} else if (PrefKeys.ENABLE_READAHEAD.equals(key)) {
|
||||||
mReadaheadEnabled = settings.getBoolean(PrefKeys.ENABLE_READAHEAD, false);
|
mReadaheadEnabled = settings.getBoolean(PrefKeys.ENABLE_READAHEAD, false);
|
||||||
}
|
}
|
||||||
|
/* Tell androids cloud-backup manager that we just changed our preferences */
|
||||||
CompatFroyo.dataChanged(this);
|
(new BackupManager(this)).dataChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -886,7 +886,7 @@ public final class PlaybackService extends Service
|
|||||||
if (mNotificationMode != NEVER)
|
if (mNotificationMode != NEVER)
|
||||||
startForeground(NOTIFICATION_ID, createNotification(mCurrentSong, mState));
|
startForeground(NOTIFICATION_ID, createNotification(mCurrentSong, mState));
|
||||||
|
|
||||||
CompatFroyo.requestAudioFocus(mAudioManager);
|
mAudioManager.requestAudioFocus(this, AudioManager.STREAM_MUSIC, AudioManager.AUDIOFOCUS_GAIN);
|
||||||
|
|
||||||
mHandler.removeMessages(RELEASE_WAKE_LOCK);
|
mHandler.removeMessages(RELEASE_WAKE_LOCK);
|
||||||
try {
|
try {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user