Skip to content

Commit

Permalink
update variable names: scrim -> bgGradient
Browse files Browse the repository at this point in the history
  • Loading branch information
peterfajdiga committed Mar 3, 2023
1 parent 8179391 commit b470512
Show file tree
Hide file tree
Showing 10 changed files with 66 additions and 66 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ protected void onCreate(Bundle savedInstanceState) {
contentView.post(() -> {
if (contentView.isAttachedToWindow()) {
setupSystemBarsPadding(contentView);
setupSystemBarsScrim(contentView);
setupSystemBarsBgGradient(contentView);
}
});
contentView.setOnApplyWindowInsetsListener((v, insets) -> {
Expand All @@ -156,7 +156,7 @@ protected void onCreate(Bundle savedInstanceState) {
contentView.post(() -> {
if (contentView.isAttachedToWindow()) {
setupSystemBarsPadding(contentView);
setupSystemBarsScrim(contentView);
setupSystemBarsBgGradient(contentView);
}
});
return insets;
Expand Down Expand Up @@ -360,40 +360,40 @@ private void setupSystemBarsPadding(final View contentView) {
}

@ColorInt
private int applyScrimOpacity(@ColorInt final int color) {
return color & ((Preferences.scrimOpacity << 24) | 0xffffff);
private int applyBgGradientOpacity(@ColorInt final int color) {
return color & ((Preferences.bgGradientOpacity << 24) | 0xffffff);
}

private void setupSystemBarsScrim(final View contentView) {
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O_MR1 && Preferences.scrimColorFromWallpaper) {
private void setupSystemBarsBgGradient(final View contentView) {
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O_MR1 && Preferences.bgGradientColorFromWallpaper) {
final WallpaperManager wallpaperManager = (WallpaperManager)getSystemService(WALLPAPER_SERVICE);
final WallpaperColors wallpaperColors = wallpaperManager.getWallpaperColors(WallpaperManager.FLAG_SYSTEM);
updateSystemBarsScrimColor(contentView, applyScrimOpacity(WallpaperColorUtils.getDarkColor(wallpaperColors)));
updateSystemBarsBgGradientColor(contentView, applyBgGradientOpacity(WallpaperColorUtils.getDarkColor(wallpaperColors)));
} else {
updateSystemBarsScrimColor(contentView, applyScrimOpacity(getScrimColor()));
updateSystemBarsBgGradientColor(contentView, applyBgGradientOpacity(getBgGradientColor()));
}
}

@ColorInt
private int getScrimColor() {
return MaterialColors.getColor(this, R.attr.scrimColor, Color.GRAY);
private int getBgGradientColor() {
return MaterialColors.getColor(this, R.attr.bgGradientColor, Color.GRAY);
}

private void updateSystemBarsScrimColor(final View contentView, @ColorInt final int color) {
private void updateSystemBarsBgGradientColor(final View contentView, @ColorInt final int color) {
final Resources res = getResources();
final int scrimHeight = Math.round(res.getDimension(R.dimen.system_bar_scrim_height));
final int bgGradientHeight = Math.round(res.getDimension(R.dimen.system_bar_bg_gradient_height));

final boolean hasNavigationBar = Build.VERSION.SDK_INT < Build.VERSION_CODES.Q || hasNavigationBar();
final int scrimHeightBottom = hasNavigationBar ? (
Preferences.headerOnBottom ? Math.round(res.getDimension(R.dimen.system_bar_scrim_height_large)) : scrimHeight
final int bgGradientHeightBottom = hasNavigationBar ? (
Preferences.headerOnBottom ? Math.round(res.getDimension(R.dimen.system_bar_bg_gradient_height_large)) : bgGradientHeight
) : (
Preferences.headerOnBottom ? scrimHeight : 0
Preferences.headerOnBottom ? bgGradientHeight : 0
);

contentView.setBackground(Drawables.createScrimBackground(
contentView.setBackground(Drawables.createBgGradientDrawable(
color,
scrimHeight,
scrimHeightBottom
bgGradientHeight,
bgGradientHeightBottom
));
}

Expand All @@ -411,7 +411,7 @@ public void onAttachedToWindow() {
super.onAttachedToWindow();
final View contentView = findViewById(android.R.id.content);
setupSystemBarsPadding(contentView);
setupSystemBarsScrim(contentView);
setupSystemBarsBgGradient(contentView);
}

@Override
Expand Down Expand Up @@ -507,42 +507,42 @@ private void setupHeaderBackground(@NonNull final View header) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O_MR1) {
final WallpaperManager wallpaperManager = (WallpaperManager)getSystemService(WALLPAPER_SERVICE);
final WallpaperColors wallpaperColors = wallpaperManager.getWallpaperColors(WallpaperManager.FLAG_SYSTEM);
@ColorInt final int scrimColor = applyScrimOpacity(
Preferences.scrimColorFromWallpaper ?
@ColorInt final int bgGradientColor = applyBgGradientOpacity(
Preferences.bgGradientColorFromWallpaper ?
WallpaperColorUtils.getDarkColor(wallpaperColors) :
getScrimColor()
getBgGradientColor()
);
@ColorInt final int expandedHeaderColor = WallpaperColorUtils.getDarkAccentColor(wallpaperColors);
updateHeaderColor(header, scrimColor, expandedHeaderColor);
updateHeaderColor(header, bgGradientColor, expandedHeaderColor);
setupWallpaperColorListener(header, wallpaperManager);
} else {
@ColorInt final int scrimColor = getScrimColor();
updateHeaderColor(header, scrimColor, scrimColor); // TODO: constant
@ColorInt final int bgGradientColor = getBgGradientColor();
updateHeaderColor(header, bgGradientColor, bgGradientColor);
}
}

@RequiresApi(api = Build.VERSION_CODES.O_MR1)
private void setupWallpaperColorListener(@NonNull final View header, @NonNull final WallpaperManager wallpaperManager) {
wallpaperManager.addOnColorsChangedListener((colors, which) -> {
if ((which & WallpaperManager.FLAG_SYSTEM) != 0) {
@ColorInt final int scrimColor = applyScrimOpacity(
Preferences.scrimColorFromWallpaper ?
@ColorInt final int bgGradientColor = applyBgGradientOpacity(
Preferences.bgGradientColorFromWallpaper ?
WallpaperColorUtils.getDarkColor(colors) :
getScrimColor()
getBgGradientColor()
);
@ColorInt final int expandedHeaderColor = WallpaperColorUtils.getDarkAccentColor(colors);
updateHeaderColor(header, scrimColor, expandedHeaderColor);
updateHeaderColor(header, bgGradientColor, expandedHeaderColor);
if (header.isAttachedToWindow()) {
updateSystemBarsScrimColor(findViewById(android.R.id.content), scrimColor);
updateSystemBarsBgGradientColor(findViewById(android.R.id.content), bgGradientColor);
}
}
}, null);
}

private void updateHeaderColor(@NonNull final View header, @ColorInt final int scrimColor, @ColorInt final int expandedColor) {
private void updateHeaderColor(@NonNull final View header, @ColorInt final int bgGradientColor, @ColorInt final int expandedColor) {
header.setBackground(Drawables.createHeaderBackground(
getResources(),
scrimColor,
bgGradientColor,
expandedColor,
!Preferences.headerOnBottom,
Preferences.headerSeparator
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@

import java.util.List;

import peterfajdiga.fastdraw.prefs.PrefMap;
import peterfajdiga.fastdraw.R;
import peterfajdiga.fastdraw.categoryorder.CategoryOrderAdapter;
import peterfajdiga.fastdraw.categoryorder.ReorderHelperCallback;
import peterfajdiga.fastdraw.prefs.PrefMap;

/**
* A {@link PreferenceActivity} that presents a set of application settings. On
Expand Down Expand Up @@ -183,7 +183,7 @@ public void onCreate(Bundle savedInstanceState) {

private void removeUnsupportedPreferences() {
if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.O_MR1) {
findPreference("scrimColorFromWallpaper").setEnabled(false);
findPreference("bgGradientColorFromWallpaper").setEnabled(false);
}
}
}
Expand Down
22 changes: 11 additions & 11 deletions app/src/main/java/peterfajdiga/fastdraw/prefs/Preferences.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ public final class Preferences {

public static boolean wallpaperParallax;
public static boolean headerSeparator;
public static boolean scrimColorFromWallpaper;
public static int scrimOpacity;
public static boolean bgGradientColorFromWallpaper;
public static int bgGradientOpacity;

public static void loadPreferences(final Context context) {
final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
Expand All @@ -29,14 +29,14 @@ public static void loadPreferences(final Context context) {
case "0": appsLinearList = false; break;
case "1": appsLinearList = true; break;
}
allowOrientation = prefs.getBoolean("allowOrientation", res.getBoolean(R.bool.default_allowOrientation));
widgetHeight = prefs.getInt("widgetHeight", res.getInteger(R.integer.default_widgetHeight));
headerOnBottom = prefs.getBoolean("headerbtm", res.getBoolean(R.bool.default_headerbtm));
scrollableTabs = prefs.getBoolean("scrollableTabs", res.getBoolean(R.bool.default_scrollableTabs));
hideHidden = prefs.getBoolean("hideHidden", res.getBoolean(R.bool.default_hideHidden));
wallpaperParallax = prefs.getBoolean("wallpaperParallax", res.getBoolean(R.bool.default_wallpaperParallax));
headerSeparator = prefs.getBoolean("headerSeparator", res.getBoolean(R.bool.default_headerSeparator));
scrimColorFromWallpaper = prefs.getBoolean("scrimColorFromWallpaper", res.getBoolean(R.bool.default_scrimColorFromWallpaper));
scrimOpacity = prefs.getInt("scrimOpacity", res.getInteger(R.integer.default_scrimOpacity));
allowOrientation = prefs.getBoolean("allowOrientation", res.getBoolean(R.bool.default_allowOrientation));
widgetHeight = prefs.getInt("widgetHeight", res.getInteger(R.integer.default_widgetHeight));
headerOnBottom = prefs.getBoolean("headerbtm", res.getBoolean(R.bool.default_headerbtm));
scrollableTabs = prefs.getBoolean("scrollableTabs", res.getBoolean(R.bool.default_scrollableTabs));
hideHidden = prefs.getBoolean("hideHidden", res.getBoolean(R.bool.default_hideHidden));
wallpaperParallax = prefs.getBoolean("wallpaperParallax", res.getBoolean(R.bool.default_wallpaperParallax));
headerSeparator = prefs.getBoolean("headerSeparator", res.getBoolean(R.bool.default_headerSeparator));
bgGradientColorFromWallpaper = prefs.getBoolean("bgGradientColorFromWallpaper", res.getBoolean(R.bool.default_bgGradientColorFromWallpaper));
bgGradientOpacity = prefs.getInt("bgGradientOpacity", res.getInteger(R.integer.default_bgGradientOpacity));
}
}
10 changes: 5 additions & 5 deletions app/src/main/java/peterfajdiga/fastdraw/views/Drawables.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ public static Drawable createHeaderBackground(
@NonNull final Resources res,
@ColorInt final int collapsedColor,
@ColorInt final int expandedColor,
final boolean scrim,
final boolean bgGradient,
final boolean separators
) {
final TransitionDrawable transitionDrawable = new TransitionDrawable(new Drawable[]{
createHeaderBackgroundCollapsed(res, collapsedColor, scrim),
createHeaderBackgroundCollapsed(res, collapsedColor, bgGradient),
createHeaderBackgroundExpanded(res, expandedColor, separators),
});
transitionDrawable.setCrossFadeEnabled(true);
Expand All @@ -34,9 +34,9 @@ public static Drawable createHeaderBackground(
public static Drawable createHeaderBackgroundCollapsed(
@NonNull final Resources res,
@ColorInt final int color,
final boolean scrim
final boolean bgGradient
) {
if (scrim) {
if (bgGradient) {
return new GradientDrawable(GradientDrawable.Orientation.TOP_BOTTOM, new int[]{
Color.TRANSPARENT,
color,
Expand Down Expand Up @@ -68,7 +68,7 @@ public static Drawable createHeaderBackgroundExpanded(
}
}

public static Drawable createScrimBackground(
public static Drawable createBgGradientDrawable(
@ColorInt final int color,
final int heightTop,
final int heightBottom
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/values/attrs.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<attr name="textColorPrimaryInactive" format="color" />
<attr name="scrimColor" format="color" />
<attr name="bgGradientColor" format="color" />
<attr name="softShadowColor" format="color" />
<attr name="hardShadowColor" format="color" />
</resources>
4 changes: 2 additions & 2 deletions app/src/main/res/values/defaults.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<bool name="default_hideHidden">true</bool>
<bool name="default_wallpaperParallax">true</bool>
<bool name="default_headerSeparator">true</bool>
<bool name="default_scrimColorFromWallpaper">false</bool>
<integer name="default_scrimOpacity">96</integer>
<bool name="default_bgGradientColorFromWallpaper">false</bool>
<integer name="default_bgGradientOpacity">96</integer>
<integer name="default_widgetHeight">260</integer>
</resources>
4 changes: 2 additions & 2 deletions app/src/main/res/values/dimens.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
<dimen name="pager_header_extra_height">72dp</dimen>
<dimen name="pager_header_expanded_elevation">24dp</dimen>

<dimen name="system_bar_scrim_height">56dp</dimen>
<dimen name="system_bar_scrim_height_large">128dp</dimen>
<dimen name="system_bar_bg_gradient_height">56dp</dimen>
<dimen name="system_bar_bg_gradient_height_large">128dp</dimen>

<dimen name="app_item_grid_padding_vertical">16dp</dimen>
<dimen name="app_item_grid_padding_below_label">3dp</dimen><!--app_item_padding_vertical - app_label_text_size-->
Expand Down
6 changes: 3 additions & 3 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@
<string name="pref_description_wallpaperParallax">Move wallpaper when switching categories</string>
<string name="pref_title_headerSeparator">Show tabs separator</string>
<string name="pref_description_headerSeparator">Display a white line between the tabs and the apps</string>
<string name="pref_title_scrimColorFromWallpaper">Background shadow color from wallpaper</string>
<string name="pref_description_scrimColorFromWallpaper">Color the background shadow based on the color of your wallpaper (requires Android Oreo or newer)</string>
<string name="pref_title_scrimOpacity">Background shadow opacity</string>
<string name="pref_title_bgGradientColorFromWallpaper">Background shadow color from wallpaper</string>
<string name="pref_description_bgGradientColorFromWallpaper">Color the background shadow based on the color of your wallpaper (requires Android Oreo or newer)</string>
<string name="pref_title_bgGradientOpacity">Background shadow opacity</string>

<string name="pref_header_categoryorder">Order of categories</string>
<string name="pref_title_orderreset">Order alphabetically</string>
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/values/styles.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<item name="android:colorEdgeEffect">@android:color/white</item>
<item name="android:textColorPrimary">@android:color/white</item>
<item name="textColorPrimaryInactive">#80FFFFFF</item>
<item name="scrimColor">@android:color/black</item>
<item name="bgGradientColor">@android:color/black</item>
<item name="softShadowColor">@android:color/black</item>
<item name="hardShadowColor">#80000000</item>
</style>
Expand Down
14 changes: 7 additions & 7 deletions app/src/main/res/xml/pref_appearance.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,17 @@
android:summary="@string/pref_description_headerSeparator" />

<SwitchPreference
android:defaultValue="@bool/default_scrimColorFromWallpaper"
android:key="scrimColorFromWallpaper"
android:defaultValue="@bool/default_bgGradientColorFromWallpaper"
android:key="bgGradientColorFromWallpaper"
android:disableDependentsState="true"
android:title="@string/pref_title_scrimColorFromWallpaper"
android:summary="@string/pref_description_scrimColorFromWallpaper" />
android:title="@string/pref_title_bgGradientColorFromWallpaper"
android:summary="@string/pref_description_bgGradientColorFromWallpaper" />

<SeekBarPreference
android:defaultValue="@integer/default_scrimOpacity"
android:defaultValue="@integer/default_bgGradientOpacity"
app:min="0"
android:max="255"
android:key="scrimOpacity"
android:title="@string/pref_title_scrimOpacity" />
android:key="bgGradientOpacity"
android:title="@string/pref_title_bgGradientOpacity" />

</PreferenceScreen>

0 comments on commit b470512

Please sign in to comment.