Add option to toggle notification design in N+ (#106)
This commit is contained in:
parent
abb2c21add
commit
964de0e720
5 changed files with 80 additions and 17 deletions
|
|
@ -201,12 +201,7 @@ public class MusicService extends Service implements SharedPreferences.OnSharedP
|
|||
|
||||
registerReceiver(widgetIntentReceiver, new IntentFilter(APP_WIDGET_UPDATE));
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
|
||||
playingNotification = new PlayingNotificationImpl24();
|
||||
} else {
|
||||
playingNotification = new PlayingNotificationImpl();
|
||||
}
|
||||
playingNotification.init(this);
|
||||
initNotification();
|
||||
|
||||
mediaStoreObserver = new MediaStoreObserver(playerHandler);
|
||||
throttledSeekHandler = new ThrottledSeekHandler(playerHandler);
|
||||
|
|
@ -557,8 +552,17 @@ public class MusicService extends Service implements SharedPreferences.OnSharedP
|
|||
return (getAudioManager().requestAudioFocus(audioFocusListener, AudioManager.STREAM_MUSIC, AudioManager.AUDIOFOCUS_GAIN) == AudioManager.AUDIOFOCUS_REQUEST_GRANTED);
|
||||
}
|
||||
|
||||
private void updateNotification() {
|
||||
if (getCurrentSong().id != -1) {
|
||||
public void initNotification() {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N && !PreferenceUtil.getInstance(this).classicNotification()) {
|
||||
playingNotification = new PlayingNotificationImpl24();
|
||||
} else {
|
||||
playingNotification = new PlayingNotificationImpl();
|
||||
}
|
||||
playingNotification.init(this);
|
||||
}
|
||||
|
||||
public void updateNotification() {
|
||||
if (playingNotification != null && getCurrentSong().id != -1) {
|
||||
playingNotification.update();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -26,8 +26,10 @@ import com.kabouzeid.appthemehelper.common.prefs.supportv7.ATEPreferenceFragment
|
|||
import com.kabouzeid.appthemehelper.util.ColorUtil;
|
||||
import com.kabouzeid.gramophone.R;
|
||||
import com.kabouzeid.gramophone.appshortcuts.DynamicShortcutManager;
|
||||
import com.kabouzeid.gramophone.helper.MusicPlayerRemote;
|
||||
import com.kabouzeid.gramophone.preferences.NowPlayingScreenPreference;
|
||||
import com.kabouzeid.gramophone.preferences.NowPlayingScreenPreferenceDialog;
|
||||
import com.kabouzeid.gramophone.service.MusicService;
|
||||
import com.kabouzeid.gramophone.ui.activities.base.AbsBaseActivity;
|
||||
import com.kabouzeid.gramophone.util.NavigationUtil;
|
||||
import com.kabouzeid.gramophone.util.PreferenceUtil;
|
||||
|
|
@ -127,6 +129,7 @@ public class SettingsActivity extends AbsBaseActivity implements ColorChooserDia
|
|||
public void onCreatePreferences(Bundle bundle, String s) {
|
||||
addPreferencesFromResource(R.xml.pref_general);
|
||||
addPreferencesFromResource(R.xml.pref_colors);
|
||||
addPreferencesFromResource(R.xml.pref_notification);
|
||||
addPreferencesFromResource(R.xml.pref_now_playing_screen);
|
||||
addPreferencesFromResource(R.xml.pref_images);
|
||||
addPreferencesFromResource(R.xml.pref_lockscreen);
|
||||
|
|
@ -198,7 +201,7 @@ public class SettingsActivity extends AbsBaseActivity implements ColorChooserDia
|
|||
}
|
||||
});
|
||||
|
||||
ATEColorPreference primaryColorPref = (ATEColorPreference) findPreference("primary_color");
|
||||
final ATEColorPreference primaryColorPref = (ATEColorPreference) findPreference("primary_color");
|
||||
final int primaryColor = ThemeStore.primaryColor(getActivity());
|
||||
primaryColorPref.setColor(primaryColor, ColorUtil.darkenColor(primaryColor));
|
||||
primaryColorPref.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
|
||||
|
|
@ -214,7 +217,7 @@ public class SettingsActivity extends AbsBaseActivity implements ColorChooserDia
|
|||
}
|
||||
});
|
||||
|
||||
ATEColorPreference accentColorPref = (ATEColorPreference) findPreference("accent_color");
|
||||
final ATEColorPreference accentColorPref = (ATEColorPreference) findPreference("accent_color");
|
||||
final int accentColor = ThemeStore.accentColor(getActivity());
|
||||
accentColorPref.setColor(accentColor, ColorUtil.darkenColor(accentColor));
|
||||
accentColorPref.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
|
||||
|
|
@ -248,7 +251,30 @@ public class SettingsActivity extends AbsBaseActivity implements ColorChooserDia
|
|||
});
|
||||
}
|
||||
|
||||
TwoStatePreference colorAppShortcuts = (TwoStatePreference) findPreference("should_color_app_shortcuts");
|
||||
final TwoStatePreference classicNotification = (TwoStatePreference) findPreference("classic_notification");
|
||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N_MR1) {
|
||||
classicNotification.setEnabled(false);
|
||||
classicNotification.setSummary(R.string.pref_only_nougat);
|
||||
} else {
|
||||
classicNotification.setChecked(PreferenceUtil.getInstance(getActivity()).classicNotification());
|
||||
classicNotification.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
|
||||
@Override
|
||||
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
||||
//Save preference
|
||||
PreferenceUtil.getInstance(getActivity()).setClassicNotification((Boolean)newValue);
|
||||
|
||||
final MusicService service = MusicPlayerRemote.musicService;
|
||||
if (service != null) {
|
||||
service.initNotification();
|
||||
service.updateNotification();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
final TwoStatePreference colorAppShortcuts = (TwoStatePreference) findPreference("should_color_app_shortcuts");
|
||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N_MR1) {
|
||||
colorAppShortcuts.setEnabled(false);
|
||||
colorAppShortcuts.setSummary(R.string.pref_only_nougat_mr1);
|
||||
|
|
@ -261,16 +287,14 @@ public class SettingsActivity extends AbsBaseActivity implements ColorChooserDia
|
|||
PreferenceUtil.getInstance(getActivity()).setColoredAppShortcuts((Boolean)newValue);
|
||||
|
||||
//Update app shortcuts
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N_MR1) {
|
||||
new DynamicShortcutManager(getActivity()).updateDynamicShortcuts();
|
||||
}
|
||||
new DynamicShortcutManager(getActivity()).updateDynamicShortcuts();
|
||||
|
||||
return true;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Preference equalizer = findPreference("equalizer");
|
||||
final Preference equalizer = findPreference("equalizer");
|
||||
if (!hasEqualizer()) {
|
||||
equalizer.setEnabled(false);
|
||||
equalizer.setSummary(getResources().getString(R.string.no_equalizer));
|
||||
|
|
|
|||
|
|
@ -44,6 +44,8 @@ public final class PreferenceUtil {
|
|||
public static final String FORCE_SQUARE_ALBUM_COVER = "force_square_album_art";
|
||||
|
||||
public static final String COLORED_NOTIFICATION = "colored_notification";
|
||||
public static final String CLASSIC_NOTIFICATION = "classic_notification";
|
||||
|
||||
public static final String COLORED_APP_SHORTCUTS = "colored_app_shortcuts";
|
||||
|
||||
public static final String AUDIO_DUCKING = "audio_ducking";
|
||||
|
|
@ -149,6 +151,16 @@ public final class PreferenceUtil {
|
|||
return mPreferences.getBoolean(COLORED_NOTIFICATION, true);
|
||||
}
|
||||
|
||||
public final boolean classicNotification() {
|
||||
return mPreferences.getBoolean(CLASSIC_NOTIFICATION, true);
|
||||
}
|
||||
|
||||
public void setClassicNotification(final boolean value) {
|
||||
final SharedPreferences.Editor editor = mPreferences.edit();
|
||||
editor.putBoolean(CLASSIC_NOTIFICATION, value);
|
||||
editor.apply();
|
||||
}
|
||||
|
||||
public void setColoredAppShortcuts(final boolean value) {
|
||||
final SharedPreferences.Editor editor = mPreferences.edit();
|
||||
editor.putBoolean(COLORED_APP_SHORTCUTS, value);
|
||||
|
|
|
|||
|
|
@ -118,6 +118,7 @@
|
|||
<string name="pref_header_general">General</string>
|
||||
<string name="pref_header_images">Images</string>
|
||||
<string name="pref_header_lockscreen">Lockscreen</string>
|
||||
<string name="pref_header_notification">Notification</string>
|
||||
<string name="pref_title_navigation_bar">Colored navigation bar</string>
|
||||
<string name="pref_title_app_shortcuts">Colored app shortcuts</string>
|
||||
<string name="pref_title_set_default_start_page">Start page</string>
|
||||
|
|
@ -125,6 +126,7 @@
|
|||
<string name="pref_title_auto_download_artist_images">Auto download artist images</string>
|
||||
<string name="pref_title_blurred_album_art">Blur album cover</string>
|
||||
<string name="pref_title_colored_notification">Colored notification</string>
|
||||
<string name="pref_title_classic_notification">Classic notification design</string>
|
||||
<string name="pref_title_ignore_media_store_artwork">Ignore Media Store covers</string>
|
||||
<string name="pref_title_gapless_playback">Gapless playback</string>
|
||||
<string name="pref_title_force_square_album_art">Square album cover</string>
|
||||
|
|
@ -158,10 +160,12 @@
|
|||
<string name="empty">Empty</string>
|
||||
<string name="playlist_name_empty">Playlist name</string>
|
||||
<string name="song">Song</string>
|
||||
<string name="pref_only_lollipop">"Only available on Lollipop."</string>
|
||||
<string name="pref_only_nougat_mr1">"Only available on Nougat 7.1."</string>
|
||||
<string name="pref_only_lollipop">"Only available on Lollipop or above."</string>
|
||||
<string name="pref_only_nougat">"Only available on Nougat 7.0 or above."</string>
|
||||
<string name="pref_only_nougat_mr1">"Only available on Nougat 7.1 or above."</string>
|
||||
<string name="pref_summary_album_art_on_lockscreen">Uses the current songs album cover as lockscreen wallpaper.</string>
|
||||
<string name="pref_summary_blurred_album_art">Blurs the album cover on the lockscreen. Can cause problems with third party apps and widgets.</string>
|
||||
<string name="pref_summary_classic_notification">Use the classic notification design.</string>
|
||||
<string name="pref_summary_colored_notification">"Colors the notification in the album cover\u2019s vibrant color."</string>
|
||||
<string name="pref_summary_gapless_playback">"Can cause playback issues on some devices."</string>
|
||||
<string name="pref_summary_force_square_album_art">Album covers in the now playing view are always squared.</string>
|
||||
|
|
|
|||
19
app/src/main/res/xml/pref_notification.xml
Normal file
19
app/src/main/res/xml/pref_notification.xml
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
<android.support.v7.preference.PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
|
||||
<com.kabouzeid.appthemehelper.common.prefs.supportv7.ATEPreferenceCategory android:title="@string/pref_header_notification">
|
||||
|
||||
<com.kabouzeid.appthemehelper.common.prefs.supportv7.ATESwitchPreference
|
||||
android:defaultValue="true"
|
||||
android:key="colored_notification"
|
||||
android:summary="@string/pref_summary_colored_notification"
|
||||
android:title="@string/pref_title_colored_notification" />
|
||||
|
||||
<com.kabouzeid.appthemehelper.common.prefs.supportv7.ATESwitchPreference
|
||||
android:defaultValue="false"
|
||||
android:key="classic_notification"
|
||||
android:summary="@string/pref_summary_classic_notification"
|
||||
android:title="@string/pref_title_classic_notification" />
|
||||
|
||||
</com.kabouzeid.appthemehelper.common.prefs.supportv7.ATEPreferenceCategory>
|
||||
|
||||
</android.support.v7.preference.PreferenceScreen>
|
||||
Loading…
Add table
Add a link
Reference in a new issue