Added option to disable album art on lockscreen.
This commit is contained in:
parent
456fc40cd7
commit
5a1503ed7b
5 changed files with 81 additions and 30 deletions
|
|
@ -68,7 +68,8 @@ public class MusicService extends Service {
|
|||
public static final String SHUFFLE_MODE_CHANGED = "com.kabouzeid.gramophone.shufflemodechanged";
|
||||
|
||||
public static final String SETTING_GAPLESS_PLAYBACK_CHANGED = "com.kabouzeid.gramophone.SETTING_GAPLESS_PLAYBACK_CHANGED";
|
||||
public static final String SETTING_GAPLESS_PLAYBACK_CHANGED_VALUE_EXTRA = "com.kabouzeid.gramophone.SETTING_GAPLESS_PLAYBACK_CHANGED_VALUE_EXTRA";
|
||||
public static final String SETTING_ALBUM_ART_ON_LOCKSCREEN_CHANGED = "com.kabouzeid.gramophone.SETTING_ALBUM_ART_ON_LOCKSCREEN_CHANGED";
|
||||
public static final String SETTING_BOOLEAN_EXTRA = "com.kabouzeid.gramophone.SETTING_BOOLEAN_EXTRA";
|
||||
|
||||
public static final String SAVED_POSITION = "POSITION";
|
||||
public static final String SAVED_POSITION_IN_TRACK = "POSITION_IN_TRACK";
|
||||
|
|
@ -108,7 +109,6 @@ public class MusicService extends Service {
|
|||
@SuppressWarnings("deprecation")
|
||||
private RemoteControlClient remoteControlClient;
|
||||
private PowerManager.WakeLock wakeLock;
|
||||
private String currentAlbumArtUri;
|
||||
private MusicPlayerHandler playerHandler;
|
||||
private QueueSaveHandler queueSaveHandler;
|
||||
private boolean isFadingDown = false;
|
||||
|
|
@ -128,11 +128,16 @@ public class MusicService extends Service {
|
|||
}
|
||||
};
|
||||
|
||||
private final BroadcastReceiver gaplessPlaybackSettingChangedReceiver = new BroadcastReceiver() {
|
||||
private final BroadcastReceiver preferencesChangedReceiver = new BroadcastReceiver() {
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
if (intent.getAction().equals(SETTING_GAPLESS_PLAYBACK_CHANGED)) {
|
||||
setGaplessPlaybackEnabled(intent.getBooleanExtra(SETTING_GAPLESS_PLAYBACK_CHANGED_VALUE_EXTRA, true));
|
||||
switch (intent.getAction()) {
|
||||
case SETTING_GAPLESS_PLAYBACK_CHANGED:
|
||||
setGaplessPlaybackEnabled(intent.getBooleanExtra(SETTING_BOOLEAN_EXTRA, true));
|
||||
break;
|
||||
case SETTING_ALBUM_ART_ON_LOCKSCREEN_CHANGED:
|
||||
updateRemoteControlClientImpl(intent.getBooleanExtra(SETTING_BOOLEAN_EXTRA, true));
|
||||
break;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
@ -183,7 +188,12 @@ public class MusicService extends Service {
|
|||
private void registerReceiversAndRemoteControlClient() {
|
||||
if (!receiversAndRemoteControlClientRegistered) {
|
||||
registerReceiver(becomingNoisyReceiver, new IntentFilter(AudioManager.ACTION_AUDIO_BECOMING_NOISY));
|
||||
registerReceiver(gaplessPlaybackSettingChangedReceiver, new IntentFilter(SETTING_GAPLESS_PLAYBACK_CHANGED));
|
||||
|
||||
IntentFilter preferenceIntentFilter = new IntentFilter();
|
||||
preferenceIntentFilter.addAction(SETTING_GAPLESS_PLAYBACK_CHANGED);
|
||||
preferenceIntentFilter.addAction(SETTING_ALBUM_ART_ON_LOCKSCREEN_CHANGED);
|
||||
registerReceiver(preferencesChangedReceiver, preferenceIntentFilter);
|
||||
|
||||
//noinspection deprecation
|
||||
getAudioManager().registerMediaButtonEventReceiver(new ComponentName(getApplicationContext(), MediaButtonIntentReceiver.class));
|
||||
initRemoteControlClient();
|
||||
|
|
@ -267,7 +277,7 @@ public class MusicService extends Service {
|
|||
private void unregisterReceiversAndRemoteControlClient() {
|
||||
if (receiversAndRemoteControlClientRegistered) {
|
||||
unregisterReceiver(becomingNoisyReceiver);
|
||||
unregisterReceiver(gaplessPlaybackSettingChangedReceiver);
|
||||
unregisterReceiver(preferencesChangedReceiver);
|
||||
//noinspection deprecation
|
||||
getAudioManager().unregisterRemoteControlClient(remoteControlClient);
|
||||
//noinspection deprecation
|
||||
|
|
@ -394,38 +404,46 @@ public class MusicService extends Service {
|
|||
}
|
||||
|
||||
private void updateRemoteControlClient() {
|
||||
updateRemoteControlClientImpl(PreferenceUtils.getInstance(this).albumArtOnLockscrenn());
|
||||
}
|
||||
|
||||
private void updateRemoteControlClientImpl(boolean showAlbumArt) {
|
||||
final Song song = getCurrentSong();
|
||||
remoteControlClient
|
||||
.editMetadata(false)
|
||||
.editMetadata(!showAlbumArt)
|
||||
.putString(MediaMetadataRetriever.METADATA_KEY_ARTIST, song.artistName)
|
||||
.putString(MediaMetadataRetriever.METADATA_KEY_TITLE, song.title)
|
||||
.putLong(MediaMetadataRetriever.METADATA_KEY_DURATION, song.duration)
|
||||
.apply();
|
||||
currentAlbumArtUri = MusicUtil.getAlbumArtUri(song.albumId).toString();
|
||||
ImageLoader.getInstance().displayImage(currentAlbumArtUri, new NonViewAware(new ImageSize(-1, -1), ViewScaleType.CROP), new SimpleImageLoadingListener() {
|
||||
@Override
|
||||
public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
|
||||
if (currentAlbumArtUri.equals(imageUri)) {
|
||||
Bitmap albumArt = loadedImage;
|
||||
if (albumArt != null) {
|
||||
// RemoteControlClient wants to recycle the bitmaps thrown at it, so we need
|
||||
// to make sure not to hand out our cache copy
|
||||
Bitmap.Config config = albumArt.getConfig();
|
||||
if (config == null) {
|
||||
config = Bitmap.Config.ARGB_8888;
|
||||
if (showAlbumArt) {
|
||||
final String currentAlbumArtUri = MusicUtil.getAlbumArtUri(song.albumId).toString();
|
||||
ImageLoader.getInstance().displayImage(currentAlbumArtUri, new NonViewAware(new ImageSize(-1, -1), ViewScaleType.CROP), new SimpleImageLoadingListener() {
|
||||
@Override
|
||||
public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
|
||||
if (currentAlbumArtUri.equals(imageUri)) {
|
||||
Bitmap albumArt = loadedImage;
|
||||
if (albumArt != null) {
|
||||
// RemoteControlClient wants to recycle the bitmaps thrown at it, so we need
|
||||
// to make sure not to hand out our cache copy
|
||||
Bitmap.Config config = albumArt.getConfig();
|
||||
if (config == null) {
|
||||
config = Bitmap.Config.ARGB_8888;
|
||||
}
|
||||
albumArt = albumArt.copy(config, false);
|
||||
updateRemoteControlClientBitmap(albumArt.copy(albumArt.getConfig(), true));
|
||||
}
|
||||
albumArt = albumArt.copy(config, false);
|
||||
updateRemoteControlClientBitmap(albumArt.copy(albumArt.getConfig(), true));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLoadingFailed(String imageUri, View view, FailReason failReason) {
|
||||
if (currentAlbumArtUri.equals(imageUri))
|
||||
updateRemoteControlClientBitmap(null);
|
||||
}
|
||||
});
|
||||
@Override
|
||||
public void onLoadingFailed(String imageUri, View view, FailReason failReason) {
|
||||
if (currentAlbumArtUri.equals(imageUri))
|
||||
updateRemoteControlClientBitmap(null);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
updateRemoteControlClientBitmap(null);
|
||||
}
|
||||
}
|
||||
|
||||
private void updateRemoteControlClientBitmap(final Bitmap albumArt) {
|
||||
|
|
|
|||
|
|
@ -69,6 +69,7 @@ public class SettingsActivity extends AbsBaseActivity implements ColorChooserDia
|
|||
addPreferencesFromResource(R.xml.pref_general);
|
||||
addPreferencesFromResource(R.xml.pref_colors);
|
||||
addPreferencesFromResource(R.xml.pref_now_playing_screen);
|
||||
addPreferencesFromResource(R.xml.pref_lockscreen);
|
||||
addPreferencesFromResource(R.xml.pref_audio);
|
||||
|
||||
final Preference defaultStartPage = findPreference("default_start_page");
|
||||
|
|
@ -147,11 +148,20 @@ public class SettingsActivity extends AbsBaseActivity implements ColorChooserDia
|
|||
}
|
||||
});
|
||||
|
||||
Preference albumArtOnLockscreen = findPreference("album_art_on_lockscreen");
|
||||
albumArtOnLockscreen.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
|
||||
@Override
|
||||
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
||||
getActivity().sendBroadcast(new Intent(MusicService.SETTING_ALBUM_ART_ON_LOCKSCREEN_CHANGED).putExtra(MusicService.SETTING_BOOLEAN_EXTRA, (boolean) newValue));
|
||||
return true;
|
||||
}
|
||||
});
|
||||
|
||||
Preference gaplessPlayback = findPreference("gapless_playback");
|
||||
gaplessPlayback.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
|
||||
@Override
|
||||
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
||||
getActivity().sendBroadcast(new Intent(MusicService.SETTING_GAPLESS_PLAYBACK_CHANGED).putExtra(MusicService.SETTING_GAPLESS_PLAYBACK_CHANGED_VALUE_EXTRA, (boolean) newValue));
|
||||
getActivity().sendBroadcast(new Intent(MusicService.SETTING_GAPLESS_PLAYBACK_CHANGED).putExtra(MusicService.SETTING_BOOLEAN_EXTRA, (boolean) newValue));
|
||||
return true;
|
||||
}
|
||||
});
|
||||
|
|
|
|||
|
|
@ -44,6 +44,7 @@ public final class PreferenceUtils {
|
|||
public static final String COLORED_NOTIFICATION = "colored_notification";
|
||||
public static final String GAPLESS_PLAYBACK = "gapless_playback";
|
||||
public static final String LAST_ADDED_CUTOFF_TIMESTAMP = "last_added_cutoff_timestamp";
|
||||
public static final String ALBUM_ART_ON_LOCKSCREEN = "album_art_on_lockscreen";
|
||||
|
||||
private static PreferenceUtils sInstance;
|
||||
|
||||
|
|
@ -203,6 +204,10 @@ public final class PreferenceUtils {
|
|||
return mPreferences.getBoolean(GAPLESS_PLAYBACK, true);
|
||||
}
|
||||
|
||||
public final boolean albumArtOnLockscrenn() {
|
||||
return mPreferences.getBoolean(ALBUM_ART_ON_LOCKSCREEN, true);
|
||||
}
|
||||
|
||||
// public final boolean downloadMissingArtistImages() {
|
||||
// return mPreferences.getBoolean(DOWNLOAD_MISSING_ARTIST_IMAGES, true);
|
||||
// }
|
||||
|
|
|
|||
|
|
@ -102,6 +102,7 @@
|
|||
<string name="pref_title_general_theme">General Theme</string>
|
||||
<string name="pref_header_audio">Audio</string>
|
||||
<string name="pref_header_general">General</string>
|
||||
<string name="pref_header_lockscreen">Lockscreen</string>
|
||||
<string name="pref_summary_colored_navigation_bar">In which views the navigation bar should be colored.</string>
|
||||
<string name="pref_title_navigation_bar">Colored Navigation Bar</string>
|
||||
<string name="pref_title_set_default_start_page">Start Page</string>
|
||||
|
|
@ -112,6 +113,7 @@
|
|||
<string name="pref_title_colored_navigation_bar_tag_editor">Tag Editor</string>
|
||||
<string name="pref_title_colored_navigation_bar_other_screens">Everywhere Else</string>
|
||||
<string name="pref_title_colored_album_footers">Colored Album Footers</string>
|
||||
<string name="pref_title_album_art_on_lockscreen">Album Art on Lockscreen</string>
|
||||
<string name="pref_title_colored_notification">Colored Notification</string>
|
||||
<string name="pref_title_fade_play_pause">Fade Play/Pause</string>
|
||||
<string name="pref_title_gapless_playback">Gapless Playback</string>
|
||||
|
|
@ -148,6 +150,7 @@
|
|||
<string name="song">Song</string>
|
||||
<string name="pref_only_lollipop">"Only available on Lollipop."</string>
|
||||
<string name="pref_summary_colored_album_footers">"Album footers in the grid are colored with the album cover\'s vibrant color."</string>
|
||||
<string name="pref_summary_album_art_on_lockscreen">The album art is shown on the lockscreen. You might have to restart Phonograph in order for changes to take affect.</string>
|
||||
<string name="pref_summary_colored_notification">"The notification is colored with the album cover\'s vibrant color."</string>
|
||||
<string name="pref_summary_fade_play_pause">"Fades the song in/out on play/pause."</string>
|
||||
<string name="pref_summary_gapless_playback">"Eliminates the gap between two songs. Disabling this might fix playback issues."</string>
|
||||
|
|
|
|||
15
app/src/main/res/xml/pref_lockscreen.xml
Normal file
15
app/src/main/res/xml/pref_lockscreen.xml
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
|
||||
<com.kabouzeid.gramophone.prefs.DynamicPreferenceCategory android:title="@string/pref_header_lockscreen">
|
||||
|
||||
<CheckBoxPreference
|
||||
android:layout="@layout/preference_custom"
|
||||
android:defaultValue="true"
|
||||
android:key="album_art_on_lockscreen"
|
||||
android:title="@string/pref_title_album_art_on_lockscreen"
|
||||
android:summary="@string/pref_summary_album_art_on_lockscreen"
|
||||
android:widgetLayout="@layout/preference_dynamic_checkbox" />
|
||||
|
||||
</com.kabouzeid.gramophone.prefs.DynamicPreferenceCategory>
|
||||
|
||||
</PreferenceScreen>
|
||||
Loading…
Add table
Add a link
Reference in a new issue