Skip to content

Commit

Permalink
Improve more color previews to match the theme
Browse files Browse the repository at this point in the history
  • Loading branch information
Mahmud0808 committed Jan 11, 2024
1 parent 6c4ef38 commit 6fa297b
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 60 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -190,27 +190,51 @@ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceStat
}

private void updatePreviewColors() {
ArrayList<ArrayList<Integer>> colors = generateModifiedColors(
ArrayList<ArrayList<Integer>> colorPalette = generateModifiedColors(
monetAccentSaturation[0],
monetBackgroundSaturation[0],
monetBackgroundLightness[0],
RPrefs.getBoolean(MONET_PITCH_BLACK_THEME, false),
RPrefs.getBoolean(MONET_ACCURATE_SHADES, true)
);

if (colors != null) {
boolean isDark = SystemUtil.isDarkMode();

binding.colorAccent1.colorPreviewBg.getBackground().setTint(colors.get(0).get(isDark ? 4 : 8));
binding.colorAccent1.colorPreviewFg.getBackground().setTint(colors.get(0).get(isDark ? 4 : 8));
binding.colorAccent2.colorPreviewBg.getBackground().setTint(colors.get(1).get(isDark ? 4 : 8));
binding.colorAccent2.colorPreviewFg.getBackground().setTint(colors.get(1).get(isDark ? 4 : 8));
binding.colorAccent3.colorPreviewBg.getBackground().setTint(colors.get(2).get(isDark ? 4 : 8));
binding.colorAccent3.colorPreviewFg.getBackground().setTint(colors.get(2).get(isDark ? 4 : 8));
binding.colorNeutral1.colorPreviewBg.getBackground().setTint(colors.get(3).get(isDark ? 9 : 3));
binding.colorNeutral1.colorPreviewFg.getBackground().setTint(colors.get(3).get(isDark ? 9 : 3));
binding.colorNeutral2.colorPreviewBg.getBackground().setTint(colors.get(4).get(isDark ? 9 : 3));
binding.colorNeutral2.colorPreviewFg.getBackground().setTint(colors.get(4).get(isDark ? 9 : 3));
if (colorPalette != null) {
boolean isDarkMode = SystemUtil.isDarkMode();

binding.colorAccent1.colorContainer.setHalfCircleColor(colorPalette.get(0).get(4));
binding.colorAccent1.colorContainer.setFirstQuarterCircleColor(colorPalette.get(0).get(5));
binding.colorAccent1.colorContainer.setSecondQuarterCircleColor(colorPalette.get(0).get(6));
binding.colorAccent1.colorContainer.setSquareColor(colorPalette.get(0).get(!isDarkMode ? 3 : 9));
binding.colorAccent1.colorContainer.setPadding(8);
binding.colorAccent1.colorContainer.invalidateColors();

binding.colorAccent2.colorContainer.setHalfCircleColor(colorPalette.get(1).get(4));
binding.colorAccent2.colorContainer.setFirstQuarterCircleColor(colorPalette.get(1).get(5));
binding.colorAccent2.colorContainer.setSecondQuarterCircleColor(colorPalette.get(1).get(6));
binding.colorAccent2.colorContainer.setSquareColor(colorPalette.get(1).get(!isDarkMode ? 3 : 9));
binding.colorAccent2.colorContainer.setPadding(8);
binding.colorAccent2.colorContainer.invalidateColors();

binding.colorAccent3.colorContainer.setHalfCircleColor(colorPalette.get(2).get(4));
binding.colorAccent3.colorContainer.setFirstQuarterCircleColor(colorPalette.get(2).get(5));
binding.colorAccent3.colorContainer.setSecondQuarterCircleColor(colorPalette.get(2).get(6));
binding.colorAccent3.colorContainer.setSquareColor(colorPalette.get(2).get(!isDarkMode ? 3 : 9));
binding.colorAccent3.colorContainer.setPadding(8);
binding.colorAccent3.colorContainer.invalidateColors();

binding.colorNeutral1.colorContainer.setHalfCircleColor(colorPalette.get(3).get(4));
binding.colorNeutral1.colorContainer.setFirstQuarterCircleColor(colorPalette.get(3).get(5));
binding.colorNeutral1.colorContainer.setSecondQuarterCircleColor(colorPalette.get(3).get(6));
binding.colorNeutral1.colorContainer.setSquareColor(colorPalette.get(3).get(!isDarkMode ? 3 : 9));
binding.colorNeutral1.colorContainer.setPadding(8);
binding.colorNeutral1.colorContainer.invalidateColors();

binding.colorNeutral2.colorContainer.setHalfCircleColor(colorPalette.get(4).get(4));
binding.colorNeutral2.colorContainer.setFirstQuarterCircleColor(colorPalette.get(4).get(5));
binding.colorNeutral2.colorContainer.setSecondQuarterCircleColor(colorPalette.get(4).get(6));
binding.colorNeutral2.colorContainer.setSquareColor(colorPalette.get(4).get(!isDarkMode ? 3 : 9));
binding.colorNeutral2.colorContainer.setPadding(8);
binding.colorNeutral2.colorContainer.invalidateColors();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public class ColorPreview extends View {

private Paint squarePaint, secondQuarterCirclePaint, firstQuarterCirclePaint, halfCirclePaint;
private RectF squareRect, circleRect;
private float padding;

public ColorPreview(Context context) {
super(context);
Expand All @@ -35,6 +36,8 @@ public ColorPreview(Context context, AttributeSet attrs, int defStyleAttr) {
private void init(Context context) {
boolean isDarkMode = (context.getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_YES) == Configuration.UI_MODE_NIGHT_YES;

padding = 10 * getResources().getDisplayMetrics().density;

squareRect = new RectF();
circleRect = new RectF();

Expand Down Expand Up @@ -70,7 +73,6 @@ protected void onDraw(@NonNull Canvas canvas) {
squareRect.set(0, 0, width, height);
canvas.drawRoundRect(squareRect, cornerRadius, cornerRadius, squarePaint);

float padding = 10 * getResources().getDisplayMetrics().density;
float margin = 0 * getResources().getDisplayMetrics().density;

circleRect.set(padding, padding, width - padding, height - padding - margin);
Expand Down Expand Up @@ -102,4 +104,8 @@ public void setHalfCircleColor(@ColorInt int color) {
public void invalidateColors() {
invalidate();
}

public void setPadding(float padding) {
this.padding = padding * getResources().getDisplayMetrics().density;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ public void setMainColor(@ColorInt int color) {
setHalfCircleColor(colorPalette.get(0).get(4));
setFirstQuarterCircleColor(colorPalette.get(2).get(5));
setSecondQuarterCircleColor(colorPalette.get(1).get(6));
setSquareColor(colorPalette.get(4).get(!isDarkMode ? 2 : 9));
setSquareColor(colorPalette.get(4).get(!isDarkMode ? 3 : 9));
setCenterCircleColor(color);
invalidateColors();
} catch (Exception ignored) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ public boolean isSelected() {
public void setSelected(boolean isSelected) {
this.isSelected = isSelected;
container.setCardBackgroundColor(getCardBackgroundColor());
container.setStrokeWidth(isSelected ? 2 : 0);
titleTextView.setTextColor(getTextColor(isSelected));
descriptionTextView.setTextColor(getTextColor(isSelected));
}
Expand Down
10 changes: 0 additions & 10 deletions app/src/main/res/drawable/wallpaper_color_preview_bg.xml

This file was deleted.

9 changes: 0 additions & 9 deletions app/src/main/res/drawable/wallpaper_color_preview_fg.xml

This file was deleted.

28 changes: 3 additions & 25 deletions app/src/main/res/layout/view_wallpaper_color.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,33 +7,11 @@
android:gravity="center"
android:orientation="vertical">

<FrameLayout
<com.drdisagree.colorblendr.ui.views.ColorPreview
android:id="@+id/color_container"
android:layout_width="48dp"
android:layout_height="48dp"
android:layout_gravity="center"
android:clickable="false"
android:focusable="false">

<View
android:id="@+id/color_preview_bg"
android:layout_width="48dp"
android:layout_height="48dp"
android:layout_gravity="center"
android:alpha="0.4"
android:background="@drawable/wallpaper_color_preview_bg"
android:clickable="false"
android:focusable="false" />

<View
android:id="@+id/color_preview_fg"
android:layout_width="34dp"
android:layout_height="34dp"
android:layout_gravity="center"
android:background="@drawable/wallpaper_color_preview_fg"
android:clickable="false"
android:focusable="false" />

</FrameLayout>
android:layout_gravity="center" />

<com.google.android.material.textview.MaterialTextView
android:id="@+id/title"
Expand Down

0 comments on commit 6fa297b

Please sign in to comment.