From 750fbb47b317c0d62cec8343e0d227c6b0b65adf Mon Sep 17 00:00:00 2001 From: Adrian Ulrich Date: Sun, 1 Sep 2013 10:21:21 +0200 Subject: [PATCH] Get rid of CompatFroyo --- .../android/vanilla/CompatFroyo.java | 91 ------------------- .../android/vanilla/MediaButtonReceiver.java | 4 +- .../android/vanilla/PlaybackService.java | 10 +- 3 files changed, 7 insertions(+), 98 deletions(-) delete mode 100644 src/ch/blinkenlights/android/vanilla/CompatFroyo.java diff --git a/src/ch/blinkenlights/android/vanilla/CompatFroyo.java b/src/ch/blinkenlights/android/vanilla/CompatFroyo.java deleted file mode 100644 index 24ede9d1..00000000 --- a/src/ch/blinkenlights/android/vanilla/CompatFroyo.java +++ /dev/null @@ -1,91 +0,0 @@ -/* - * Copyright (C) 2011 Christopher Eby - * - * 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); - } - } -} diff --git a/src/ch/blinkenlights/android/vanilla/MediaButtonReceiver.java b/src/ch/blinkenlights/android/vanilla/MediaButtonReceiver.java index dea34e13..9daa7a11 100644 --- a/src/ch/blinkenlights/android/vanilla/MediaButtonReceiver.java +++ b/src/ch/blinkenlights/android/vanilla/MediaButtonReceiver.java @@ -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 diff --git a/src/ch/blinkenlights/android/vanilla/PlaybackService.java b/src/ch/blinkenlights/android/vanilla/PlaybackService.java index 093891f8..aa04677b 100644 --- a/src/ch/blinkenlights/android/vanilla/PlaybackService.java +++ b/src/ch/blinkenlights/android/vanilla/PlaybackService.java @@ -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 {