Skip to content

Commit

Permalink
Add some basic colors
Browse files Browse the repository at this point in the history
  • Loading branch information
Mahmud0808 committed Jan 11, 2024
1 parent bb168c9 commit 785402a
Show file tree
Hide file tree
Showing 8 changed files with 167 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.graphics.Color;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
Expand Down Expand Up @@ -51,7 +52,10 @@
import com.google.gson.reflect.TypeToken;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import me.jfenn.colorpickerdialog.dialogs.ColorPickerDialog;
import me.jfenn.colorpickerdialog.views.picker.ImagePickerView;
Expand All @@ -71,7 +75,9 @@ public class ColorsFragment extends Fragment {
private final BroadcastReceiver wallpaperChangedReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, android.content.Intent intent) {
addWallpaperColorItems();
if (binding.colorsToggleGroup.getCheckedButtonId() == R.id.wallpaper_colors_button) {
addWallpaperColorItems();
}
}
};

Expand Down Expand Up @@ -111,6 +117,28 @@ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceStat
sharedViewModel.getBooleanStates().observe(getViewLifecycleOwner(), this::updateBooleanStates);
sharedViewModel.getVisibilityStates().observe(getViewLifecycleOwner(), this::updateViewVisibility);

// Color codes
binding.colorsToggleGroup.check(
RPrefs.getBoolean(MONET_SEED_COLOR_ENABLED, false) ?
R.id.basic_colors_button :
R.id.wallpaper_colors_button
);
binding.colorsToggleGroup.addOnButtonCheckedListener((group, checkedId, isChecked) -> {
if (isChecked) {
if (checkedId == R.id.wallpaper_colors_button) {
addWallpaperColorItems();
} else {
addBasicColorItems();
}
}
});
if (RPrefs.getBoolean(MONET_SEED_COLOR_ENABLED, false)) {
addBasicColorItems();
} else {
addWallpaperColorItems();
}

// Color table preview
initColorTablePreview(colorTableRows);

// Primary color
Expand Down Expand Up @@ -151,8 +179,6 @@ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceStat

// Force per app theme
binding.perAppTheme.setOnClickListener(v -> HomeFragment.replaceFragment(new PerAppThemeFragment()));

addWallpaperColorItems();
}

private void updateBooleanStates(Map<String, Boolean> stringBooleanMap) {
Expand Down Expand Up @@ -354,52 +380,59 @@ private void enablePaletteOnClickListener(LinearLayout[] colorTableRows, int[][]

private void addWallpaperColorItems() {
String wallpaperColors = RPrefs.getString(WALLPAPER_COLOR_LIST, null);
if (wallpaperColors == null) {
binding.wallpaperColorsCard.setVisibility(View.GONE);
return;
ArrayList<Integer> wallpaperColorList;

if (wallpaperColors != null) {
wallpaperColorList = Const.GSON.fromJson(
wallpaperColors,
new TypeToken<ArrayList<Integer>>() {
}.getType()
);
} else {
binding.wallpaperColorsCard.setVisibility(View.VISIBLE);
wallpaperColorList = ColorUtil.getMonetAccentColors();
}

ArrayList<Integer> wallpaperColorList = Const.GSON.fromJson(
wallpaperColors,
new TypeToken<ArrayList<Integer>>() {
}.getType()
);
addColorsToContainer(wallpaperColorList, true);
}

if (wallpaperColorList == null || wallpaperColorList.size() <= 1) {
binding.wallpaperColorsCard.setVisibility(View.GONE);
return;
} else {
binding.wallpaperColorsCard.setVisibility(View.VISIBLE);
}
private void addBasicColorItems() {
String[] basicColors = getResources().getStringArray(R.array.basic_color_codes);
List<Integer> basicColorList = Arrays.stream(basicColors)
.map(Color::parseColor)
.collect(Collectors.toList());

addColorsToContainer(new ArrayList<>(basicColorList), false);
}

binding.wallpaperColorsContainer.removeAllViews();
private void addColorsToContainer(ArrayList<Integer> colorList, boolean isWallpaperColors) {
binding.colorsContainer.removeAllViews();

for (int i = 0; i < wallpaperColorList.size(); i++) {
for (int i = 0; i < colorList.size(); i++) {
int size = (int) (48 * getResources().getDisplayMetrics().density);
int margin = (int) (12 * getResources().getDisplayMetrics().density);

WallColorPreview colorPreview = new WallColorPreview(requireContext());
LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(size, size);
layoutParams.setMargins(margin, margin, margin, margin);
colorPreview.setLayoutParams(layoutParams);
colorPreview.setMainColor(wallpaperColorList.get(i));
colorPreview.setTag(wallpaperColorList.get(i));
colorPreview.setSelected(wallpaperColorList.get(i) == RPrefs.getInt(MONET_SEED_COLOR, Integer.MIN_VALUE));
colorPreview.setMainColor(colorList.get(i));
colorPreview.setTag(colorList.get(i));
colorPreview.setSelected(colorList.get(i) == RPrefs.getInt(MONET_SEED_COLOR, Integer.MIN_VALUE));

colorPreview.setOnClickListener(v -> {
RPrefs.putInt(MONET_SEED_COLOR, (Integer) colorPreview.getTag());
RPrefs.putBoolean(MONET_SEED_COLOR_ENABLED, !isWallpaperColors);
ArrayList<ArrayList<Integer>> modifiedColors = generateModifiedColors();
updatePreviewColors(
colorTableRows,
modifiedColors
);
binding.seedColorPicker.setPreviewColor((Integer) colorPreview.getTag());
RPrefs.putLong(MONET_LAST_UPDATED, System.currentTimeMillis());
OverlayManager.applyFabricatedColors(requireContext());
});

binding.wallpaperColorsContainer.addView(colorPreview);
binding.colorsContainer.addView(colorPreview);
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package com.drdisagree.colorblendr.ui.views;

import android.content.Context;
import android.util.AttributeSet;
import android.view.View;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.google.android.material.button.MaterialButton;
import com.google.android.material.button.MaterialButtonToggleGroup;
import com.google.android.material.shape.ShapeAppearanceModel;

public class MyMaterialButtonToggleGroup extends MaterialButtonToggleGroup {
public MyMaterialButtonToggleGroup(@NonNull Context context) {
super(context);
}

public MyMaterialButtonToggleGroup(@NonNull Context context, @Nullable AttributeSet attrs) {
super(context, attrs);
}

public MyMaterialButtonToggleGroup(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}

@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);

for (int i = 0; i < getChildCount(); i++) {
View childView = getChildAt(i);
if (childView instanceof MaterialButton button) {
if (button.getVisibility() == View.GONE) {
continue;
}

ShapeAppearanceModel.Builder builder = button.getShapeAppearanceModel().toBuilder();
float radius = 120 * getResources().getDisplayMetrics().density;
button.setShapeAppearanceModel(
builder
.setTopLeftCornerSize(radius)
.setBottomLeftCornerSize(radius)
.setTopRightCornerSize(radius)
.setBottomRightCornerSize(radius).build()
);
}
}
}
}
6 changes: 6 additions & 0 deletions app/src/main/res/drawable/divider_toggle_button.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<size
android:width="8dp"
android:height="16dp" />
</shape>
47 changes: 37 additions & 10 deletions app/src/main/res/layout/fragment_colors.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
android:paddingTop="12dp">

<com.google.android.material.card.MaterialCardView
android:id="@+id/wallpaper_colors_card"
style="@style/Widget.Material3.CardView.Outlined"
android:layout_width="match_parent"
android:layout_height="wrap_content"
Expand All @@ -34,22 +33,50 @@
android:layout_height="wrap_content"
android:orientation="vertical">

<com.google.android.material.textview.MaterialTextView
style="?attr/textAppearanceTitleSmall"
android:layout_width="wrap_content"
<com.drdisagree.colorblendr.ui.views.MyMaterialButtonToggleGroup
android:id="@+id/colors_toggle_group"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="start|center"
android:layout_marginHorizontal="22dp"
android:layout_marginTop="16dp"
android:text="@string/wallpaper_colors"
android:textColor="?attr/colorOnSurface" />
android:divider="@drawable/divider_toggle_button"
android:dividerPadding="8dp"
android:gravity="center"
android:showDividers="middle"
app:checkedButton="@id/wallpaper_colors_button"
app:selectionRequired="true"
app:singleSelection="true">

<com.google.android.material.button.MaterialButton
android:id="@+id/wallpaper_colors_button"
style="@style/Widget.Material3.Button.TextButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:minHeight="0dp"
android:paddingVertical="8dp"
android:text="@string/wallpaper_colors"
android:textSize="13sp" />

<com.google.android.material.button.MaterialButton
android:id="@+id/basic_colors_button"
style="@style/Widget.Material3.Button.TextButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:minHeight="0dp"
android:paddingVertical="8dp"
android:text="@string/basic_colors"
android:textSize="13sp" />

</com.drdisagree.colorblendr.ui.views.MyMaterialButtonToggleGroup>

<com.google.android.flexbox.FlexboxLayout
android:id="@+id/wallpaper_colors_container"
android:id="@+id/colors_container"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_margin="24dp"
android:layout_marginHorizontal="24dp"
android:layout_marginTop="18dp"
android:layout_marginBottom="24dp"
app:alignContent="center"
app:alignItems="center"
app:flexDirection="row"
Expand All @@ -71,7 +98,7 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:icon="@drawable/ic_paint"
app:previewColor="@android:color/black"
app:previewColor="@android:color/system_accent1_400"
app:summaryText="@string/seed_color_picker_desc"
app:titleText="@string/seed_color_picker_title" />

Expand Down
4 changes: 2 additions & 2 deletions app/src/main/res/layout/view_backup_restore.xml
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
android:layout_marginEnd="6dp"
android:layout_weight="1"
android:text="@string/backup"
app:cornerRadius="12dp"
app:cornerRadius="@dimen/default_corner_radius"
app:icon="@drawable/ic_backup"
app:iconGravity="textStart" />

Expand All @@ -87,7 +87,7 @@
android:layout_marginStart="6dp"
android:layout_weight="1"
android:text="@string/restore"
app:cornerRadius="12dp"
app:cornerRadius="@dimen/default_corner_radius"
app:icon="@drawable/ic_restore"
app:iconGravity="textStart" />

Expand Down
13 changes: 13 additions & 0 deletions app/src/main/res/values/arrays.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,17 @@
<item>@string/monet_content</item>
<item>@string/monet_fruitsalad</item>
</string-array>

<string-array name="basic_color_codes" translatable="false">
<item>#f9d99a</item>
<item>#fa5f49</item>
<item>#c5c6c8</item>
<item>#d8af97</item>
<item>#d8f79a</item>
<item>#95b8f6</item>
<item>#7ff9c7</item>
<item>#f15fff</item>
<item>#f7cae4</item>
<item>#b186f1</item>
</string-array>
</resources>
1 change: 1 addition & 0 deletions app/src/main/res/values/dimens.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
<resources>
<dimen name="reset_icon_size">22dp</dimen>
<dimen name="about_button_icon_size">22dp</dimen>
<dimen name="default_corner_radius">12dp</dimen>
</resources>
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@
<string name="styles">Styles</string>
<string name="theme">Theme</string>
<string name="wallpaper_colors">Wallpaper colors</string>
<string name="basic_colors">Basic colors</string>
<string name="force_per_app_theme_title">Force per app theme</string>
<string name="force_per_app_theme_desc">Apply custom colors to specific apps which do not follow system monet</string>
<string name="back">Back</string>
Expand Down

0 comments on commit 785402a

Please sign in to comment.