Added "Colored App Shortcuts" as an option in settings

This commit is contained in:
Adrian Campos 2017-03-18 20:17:08 -07:00 committed by Karim Abou Zeid
commit 4170e00cfd
10 changed files with 67 additions and 5 deletions

View file

@ -12,6 +12,7 @@ import android.util.TypedValue;
import com.kabouzeid.appthemehelper.ThemeStore; import com.kabouzeid.appthemehelper.ThemeStore;
import com.kabouzeid.gramophone.R; import com.kabouzeid.gramophone.R;
import com.kabouzeid.gramophone.util.PreferenceUtil;
import com.kabouzeid.gramophone.util.Util; import com.kabouzeid.gramophone.util.Util;
/** /**
@ -21,6 +22,22 @@ import com.kabouzeid.gramophone.util.Util;
@RequiresApi(Build.VERSION_CODES.N_MR1) @RequiresApi(Build.VERSION_CODES.N_MR1)
public final class AppShortcutIconGenerator { public final class AppShortcutIconGenerator {
public static Icon generateThemedIcon(Context context, int iconId) { public static Icon generateThemedIcon(Context context, int iconId) {
if (PreferenceUtil.getInstance(context).coloredAppShortcuts()){
return generateUserThemedIcon(context, iconId);
} else {
return generateDefaultThemedIcon(context, iconId);
}
}
private static Icon generateDefaultThemedIcon(Context context, int iconId) {
//Return an Icon of iconId with default colors
return generateThemedIcon(context, iconId,
context.getColor(R.color.app_shortcut_default_foreground),
context.getColor(R.color.app_shortcut_default_background)
);
}
private static Icon generateUserThemedIcon(Context context, int iconId) {
//Get background color from context's theme //Get background color from context's theme
final TypedValue typedColorBackground = new TypedValue(); final TypedValue typedColorBackground = new TypedValue();
context.getTheme().resolveAttribute(android.R.attr.colorBackground, typedColorBackground, true); context.getTheme().resolveAttribute(android.R.attr.colorBackground, typedColorBackground, true);
@ -32,7 +49,7 @@ public final class AppShortcutIconGenerator {
); );
} }
public static Icon generateThemedIcon(Context context, int iconId, int foregroundColor, int backgroundColor) { private static Icon generateThemedIcon(Context context, int iconId, int foregroundColor, int backgroundColor) {
//Get and tint foreground and background drawables //Get and tint foreground and background drawables
Drawable vectorDrawable = Util.getTintedVectorDrawable(context, iconId, foregroundColor); Drawable vectorDrawable = Util.getTintedVectorDrawable(context, iconId, foregroundColor);
Drawable backgroundDrawable = Util.getTintedVectorDrawable(context, R.drawable.ic_app_shortcut_background, backgroundColor); Drawable backgroundDrawable = Util.getTintedVectorDrawable(context, R.drawable.ic_app_shortcut_background, backgroundColor);

View file

@ -248,6 +248,28 @@ public class SettingsActivity extends AbsBaseActivity implements ColorChooserDia
}); });
} }
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);
} else {
colorAppShortcuts.setChecked(PreferenceUtil.getInstance(getActivity()).coloredAppShortcuts());
colorAppShortcuts.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
//Save preference
PreferenceUtil.getInstance(getActivity()).setColoredAppShortcuts((Boolean)newValue);
//Update app shortcuts
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N_MR1) {
new DynamicShortcutManager(getActivity()).updateDynamicShortcuts();
}
return true;
}
});
}
Preference equalizer = findPreference("equalizer"); Preference equalizer = findPreference("equalizer");
if (!hasEqualizer()) { if (!hasEqualizer()) {
equalizer.setEnabled(false); equalizer.setEnabled(false);

View file

@ -44,6 +44,7 @@ public final class PreferenceUtil {
public static final String FORCE_SQUARE_ALBUM_COVER = "force_square_album_art"; public static final String FORCE_SQUARE_ALBUM_COVER = "force_square_album_art";
public static final String COLORED_NOTIFICATION = "colored_notification"; public static final String COLORED_NOTIFICATION = "colored_notification";
public static final String COLORED_APP_SHORTCUTS = "colored_app_shortcuts";
public static final String AUDIO_DUCKING = "audio_ducking"; public static final String AUDIO_DUCKING = "audio_ducking";
public static final String GAPLESS_PLAYBACK = "gapless_playback"; public static final String GAPLESS_PLAYBACK = "gapless_playback";
@ -148,6 +149,16 @@ public final class PreferenceUtil {
return mPreferences.getBoolean(COLORED_NOTIFICATION, true); return mPreferences.getBoolean(COLORED_NOTIFICATION, true);
} }
public void setColoredAppShortcuts(final boolean value) {
final SharedPreferences.Editor editor = mPreferences.edit();
editor.putBoolean(COLORED_APP_SHORTCUTS, value);
editor.apply();
}
public final boolean coloredAppShortcuts() {
return mPreferences.getBoolean(COLORED_APP_SHORTCUTS, true);
}
public final boolean gaplessPlayback() { public final boolean gaplessPlayback() {
return mPreferences.getBoolean(GAPLESS_PLAYBACK, false); return mPreferences.getBoolean(GAPLESS_PLAYBACK, false);
} }

View file

@ -12,7 +12,7 @@
android:scaleY="0.916"> android:scaleY="0.916">
<path <path
android:name="ic_app_shortcut_background" android:name="ic_app_shortcut_background"
android:fillColor="#f5f5f5" android:fillColor="#000"
android:pathData="M 88 0 C 136.601057985 0 176 39.3989420149 176 88 C 176 136.601057985 136.601057985 176 88 176 C 39.3989420149 176 0 136.601057985 0 88 C 0 39.3989420149 39.3989420149 0 88 0 Z" /> android:pathData="M 88 0 C 136.601057985 0 176 39.3989420149 176 88 C 176 136.601057985 136.601057985 176 88 176 C 39.3989420149 176 0 136.601057985 0 88 C 0 39.3989420149 39.3989420149 0 88 0 Z" />
</group> </group>
</vector> </vector>

View file

@ -14,7 +14,7 @@
android:translateY="-8"> android:translateY="-8">
<path <path
android:name="ic_app_shortcut_last_added_ic" android:name="ic_app_shortcut_last_added_ic"
android:fillColor="#607d8b" android:fillColor="#000"
android:pathData="M124.35,92h-16.2v16.2h-8.1V92H83.85v-8.1h16.2V67.65h8.1v16.2h16.2M128.4,55.5H79.8a8.1,8.1,0,0,0-8.1,8.1v48.6a8.1,8.1,0,0,0,8.1,8.1h48.6a8.1,8.1,0,0,0,8.1-8.1V63.6a8.1,8.1,0,0,0-8.1-8.1M63.6,71.7H55.5v56.7a8.1,8.1,0,0,0,8.1,8.1h56.7v-8.1H63.6Z" /> android:pathData="M124.35,92h-16.2v16.2h-8.1V92H83.85v-8.1h16.2V67.65h8.1v16.2h16.2M128.4,55.5H79.8a8.1,8.1,0,0,0-8.1,8.1v48.6a8.1,8.1,0,0,0,8.1,8.1h48.6a8.1,8.1,0,0,0,8.1-8.1V63.6a8.1,8.1,0,0,0-8.1-8.1M63.6,71.7H55.5v56.7a8.1,8.1,0,0,0,8.1,8.1h56.7v-8.1H63.6Z" />
</group> </group>
</vector> </vector>

View file

@ -14,7 +14,7 @@
android:translateY="-8"> android:translateY="-8">
<path <path
android:name="ic_app_shortcut_shuffle_ic" android:name="ic_app_shortcut_shuffle_ic"
android:fillColor="#607d8b" android:fillColor="#000"
android:pathData="M110.15,103l-7,7,15.65,15.65L108.5,136H136V108.5l-10.2,10.2L110.15,103M108.5,56l10.2,10.2L56,128.95l7,7L125.8,73.3,136,83.5V56M89,81.85,63.05,56l-7,7L81.85,88.9Z" /> android:pathData="M110.15,103l-7,7,15.65,15.65L108.5,136H136V108.5l-10.2,10.2L110.15,103M108.5,56l10.2,10.2L56,128.95l7,7L125.8,73.3,136,83.5V56M89,81.85,63.05,56l-7,7L81.85,88.9Z" />
</group> </group>
</vector> </vector>

View file

@ -14,7 +14,7 @@
android:translateY="-8"> android:translateY="-8">
<path <path
android:name="ic_app_shortcut_top_tracks_ic" android:name="ic_app_shortcut_top_tracks_ic"
android:fillColor="#607d8b" android:fillColor="#000"
android:pathData="M113.7,69.45l10.13,10.13-21.59,21.59-17.7-17.7L51.75,116.31,58,122.55,84.54,96l17.7,17.7,27.88-27.83L140.25,96V69.45Z" /> android:pathData="M113.7,69.45l10.13,10.13-21.59,21.59-17.7-17.7L51.75,116.31,58,122.55,84.54,96l17.7,17.7,27.88-27.83L140.25,96V69.45Z" />
</group> </group>
</vector> </vector>

View file

@ -1,4 +1,7 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<resources> <resources>
<color name="twenty_percent_black_overlay">#34000000</color> <color name="twenty_percent_black_overlay">#34000000</color>
<color name="app_shortcut_default_foreground">#607d8b</color>
<color name="app_shortcut_default_background">#f5f5f5</color>
</resources> </resources>

View file

@ -119,6 +119,7 @@
<string name="pref_header_images">Images</string> <string name="pref_header_images">Images</string>
<string name="pref_header_lockscreen">Lockscreen</string> <string name="pref_header_lockscreen">Lockscreen</string>
<string name="pref_title_navigation_bar">Colored navigation bar</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> <string name="pref_title_set_default_start_page">Start page</string>
<string name="pref_title_album_art_on_lockscreen">Show album cover</string> <string name="pref_title_album_art_on_lockscreen">Show album cover</string>
<string name="pref_title_auto_download_artist_images">Auto download artist images</string> <string name="pref_title_auto_download_artist_images">Auto download artist images</string>
@ -158,6 +159,7 @@
<string name="playlist_name_empty">Playlist name</string> <string name="playlist_name_empty">Playlist name</string>
<string name="song">Song</string> <string name="song">Song</string>
<string name="pref_only_lollipop">"Only available on Lollipop."</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_summary_album_art_on_lockscreen">Uses the current songs album cover as lockscreen wallpaper.</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_blurred_album_art">Blurs the album cover on the lockscreen. Can cause problems with third party apps and widgets.</string>
<string name="pref_summary_colored_notification">"Colors the notification in the album cover\u2019s vibrant color."</string> <string name="pref_summary_colored_notification">"Colors the notification in the album cover\u2019s vibrant color."</string>
@ -171,6 +173,7 @@
<string name="pref_summary_ignore_media_store_artwork">Can increase the album cover quality but causes slower image loading times. Only enable this if you have problems with low resolution artworks.</string> <string name="pref_summary_ignore_media_store_artwork">Can increase the album cover quality but causes slower image loading times. Only enable this if you have problems with low resolution artworks.</string>
<string name="pref_summary_colored_playback_controls_now_playing">Colors play/pause, shuffle and repeat as well as the progress slider in the album cover\u2019s vibrant color.</string> <string name="pref_summary_colored_playback_controls_now_playing">Colors play/pause, shuffle and repeat as well as the progress slider in the album cover\u2019s vibrant color.</string>
<string name="pref_summary_colored_navigation_bar">Colors the navigation bar in the primary color.</string> <string name="pref_summary_colored_navigation_bar">Colors the navigation bar in the primary color.</string>
<string name="pref_summary_colored_app_shortcuts">Colors the app shortcuts in the primary color.</string>
<string name="pref_summary_audio_ducking">Notifications, navigation etc.</string> <string name="pref_summary_audio_ducking">Notifications, navigation etc.</string>
<string name="could_not_download_album_cover">"Couldn\u2019t download a matching album cover."</string> <string name="could_not_download_album_cover">"Couldn\u2019t download a matching album cover."</string>
<string name="search_hint">Search your library…</string> <string name="search_hint">Search your library…</string>

View file

@ -27,6 +27,12 @@
android:summary="@string/pref_summary_colored_navigation_bar" android:summary="@string/pref_summary_colored_navigation_bar"
android:title="@string/pref_title_navigation_bar" /> android:title="@string/pref_title_navigation_bar" />
<com.kabouzeid.appthemehelper.common.prefs.supportv7.ATESwitchPreference
android:defaultValue="true"
android:key="should_color_app_shortcuts"
android:summary="@string/pref_summary_colored_app_shortcuts"
android:title="@string/pref_title_app_shortcuts" />
</com.kabouzeid.appthemehelper.common.prefs.supportv7.ATEPreferenceCategory> </com.kabouzeid.appthemehelper.common.prefs.supportv7.ATEPreferenceCategory>
</android.support.v7.preference.PreferenceScreen> </android.support.v7.preference.PreferenceScreen>