Get rid of CompatFroyo
This commit is contained in:
parent
c3cdcc50ec
commit
750fbb47b3
@ -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);
|
||||
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);
|
||||
ComponentName receiver = new ComponentName(context.getPackageName(), MediaButtonReceiver.class.getName());
|
||||
CompatFroyo.unregisterMediaButtonEventReceiver(audioManager, receiver);
|
||||
audioManager.unregisterMediaButtonEventReceiver(receiver);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -27,6 +27,7 @@ import android.app.Notification;
|
||||
import android.app.NotificationManager;
|
||||
import android.app.PendingIntent;
|
||||
import android.app.Service;
|
||||
import android.app.backup.BackupManager;
|
||||
import android.appwidget.AppWidgetManager;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.ComponentName;
|
||||
@ -79,6 +80,7 @@ public final class PlaybackService extends Service
|
||||
, SharedPreferences.OnSharedPreferenceChangeListener
|
||||
, SongTimeline.Callback
|
||||
, SensorEventListener
|
||||
, AudioManager.OnAudioFocusChangeListener
|
||||
{
|
||||
/**
|
||||
* Name of the state file.
|
||||
@ -404,8 +406,6 @@ public final class PlaybackService extends Service
|
||||
mNotificationManager = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);
|
||||
mAudioManager = (AudioManager)getSystemService(AUDIO_SERVICE);
|
||||
|
||||
CompatFroyo.createAudioFocus();
|
||||
|
||||
SharedPreferences settings = getSettings(this);
|
||||
settings.registerOnSharedPreferenceChangeListener(this);
|
||||
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)) {
|
||||
mReadaheadEnabled = settings.getBoolean(PrefKeys.ENABLE_READAHEAD, false);
|
||||
}
|
||||
|
||||
CompatFroyo.dataChanged(this);
|
||||
/* Tell androids cloud-backup manager that we just changed our preferences */
|
||||
(new BackupManager(this)).dataChanged();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -886,7 +886,7 @@ public final class PlaybackService extends Service
|
||||
if (mNotificationMode != NEVER)
|
||||
startForeground(NOTIFICATION_ID, createNotification(mCurrentSong, mState));
|
||||
|
||||
CompatFroyo.requestAudioFocus(mAudioManager);
|
||||
mAudioManager.requestAudioFocus(this, AudioManager.STREAM_MUSIC, AudioManager.AUDIOFOCUS_GAIN);
|
||||
|
||||
mHandler.removeMessages(RELEASE_WAKE_LOCK);
|
||||
try {
|
||||
|
Loading…
x
Reference in New Issue
Block a user