Skip to content

Commit

Permalink
Add following features
Browse files Browse the repository at this point in the history
- Accurate shades
- Override colors manually
  • Loading branch information
Mahmud0808 committed Dec 11, 2023
1 parent 5ab339e commit 120680e
Show file tree
Hide file tree
Showing 14 changed files with 239 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,5 @@ public class Const {
public static final String MONET_PITCH_BLACK_THEME = "monetPitchBlackTheme";
public static final String MONET_SEED_COLOR = "monetSeedColor";
public static final String MONET_SEED_COLOR_ENABLED = "monetSeedColorEnabled";
public static final String MANUAL_OVERRIDE_COLORS = "manualOverrideColors";
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.drdisagree.colorblendr.ui.fragments;

import static com.drdisagree.colorblendr.common.Const.MANUAL_OVERRIDE_COLORS;
import static com.drdisagree.colorblendr.common.Const.MONET_ACCENT_SATURATION;
import static com.drdisagree.colorblendr.common.Const.MONET_ACCURATE_SHADES;
import static com.drdisagree.colorblendr.common.Const.MONET_BACKGROUND_LIGHTNESS;
Expand All @@ -9,6 +10,9 @@
import static com.drdisagree.colorblendr.common.Const.MONET_SEED_COLOR_ENABLED;

import android.annotation.SuppressLint;
import android.content.ClipData;
import android.content.ClipboardManager;
import android.content.Context;
import android.os.Bundle;
import android.util.TypedValue;
import android.view.Gravity;
Expand All @@ -30,6 +34,7 @@
import com.drdisagree.colorblendr.utils.ColorUtil;
import com.drdisagree.colorblendr.xposed.modules.utils.ColorModifiers;
import com.google.android.material.slider.Slider;
import com.google.android.material.snackbar.Snackbar;

import java.util.ArrayList;
import java.util.Map;
Expand All @@ -46,7 +51,6 @@ public class StylingFragment extends Fragment {
private static final int[] colorCodes = {
0, 10, 50, 100, 200, 300, 400, 500, 600, 700, 800, 900, 1000
};
private static boolean accurateShades = RPrefs.getBoolean(MONET_ACCURATE_SHADES, true);
private final int[] monetAccentSaturation = new int[]{RPrefs.getInt(MONET_ACCENT_SATURATION, 100)};
private final int[] monetBackgroundSaturation = new int[]{RPrefs.getInt(MONET_BACKGROUND_SATURATION, 100)};
private final int[] monetBackgroundLightness = new int[]{RPrefs.getInt(MONET_BACKGROUND_LIGHTNESS, 100)};
Expand All @@ -70,6 +74,7 @@ public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container,
)};

assignStockColorsToPalette();
enablePaletteOnClickListener();

// Primary color
binding.seedColorPicker.setPreviewColor(RPrefs.getInt(
Expand Down Expand Up @@ -192,6 +197,10 @@ private void assignStockColorsToPalette() {
colorTableRows[i].getChildAt(j).getBackground().setTint(systemColors[i][j]);
colorTableRows[i].getChildAt(j).setTag(systemColors[i][j]);

if (RPrefs.getInt("monet_color_" + i + j, -1) != -1) {
colorTableRows[i].getChildAt(j).getBackground().setTint(RPrefs.getInt("monet_color_" + i + j, 0));
}

TextView textView = new TextView(requireContext());
textView.setText(String.valueOf(colorCodes[j]));
textView.setRotation(270);
Expand Down Expand Up @@ -224,7 +233,8 @@ private void assignCustomColorsToPalette() {
monetAccentSaturation[0],
monetBackgroundSaturation[0],
monetBackgroundLightness[0],
RPrefs.getBoolean(MONET_PITCH_BLACK_THEME, false)
RPrefs.getBoolean(MONET_PITCH_BLACK_THEME, false),
RPrefs.getBoolean(MONET_ACCURATE_SHADES, true)
);
for (int j = 1; j < palette.get(i).size(); j++) {
palette.get(i).set(j, modifiedShades.get(j - 1));
Expand All @@ -236,6 +246,87 @@ private void assignCustomColorsToPalette() {
for (int j = 0; j < colorTableRows[i].getChildCount(); j++) {
colorTableRows[i].getChildAt(j).getBackground().setTint(palette.get(i).get(j));
colorTableRows[i].getChildAt(j).setTag(palette.get(i).get(j));
((TextView) ((ViewGroup) colorTableRows[i].getChildAt(j))
.getChildAt(0))
.setTextColor(ColorUtil.calculateTextColor(palette.get(i).get(j)));
}
}
}

private void enablePaletteOnClickListener() {
int[][] systemColors = ColorUtil.getSystemColors(requireContext());

for (int i = 0; i < colorTableRows.length; i++) {
for (int j = 0; j < colorTableRows[i].getChildCount(); j++) {
int finalI = i;
int finalJ = j;

colorTableRows[i].getChildAt(j).setOnClickListener(v -> {
boolean manualOverride = RPrefs.getBoolean(MANUAL_OVERRIDE_COLORS, false);
String snackbarButton = manualOverride ? "Override" : "Copy";

Snackbar.make(
requireView(),
"Color code: " + ColorUtil.intToHexColor((Integer) v.getTag()),
Snackbar.LENGTH_INDEFINITE)
.setAction(snackbarButton, v1 -> {
if (!manualOverride) {
ClipboardManager clipboard = (ClipboardManager) requireContext().getSystemService(Context.CLIPBOARD_SERVICE);
ClipData clip = ClipData.newPlainText(ColorUtil.getColorNames()[finalI][finalJ], ColorUtil.intToHexColor((Integer) v.getTag()));
clipboard.setPrimaryClip(clip);
return;
}

if (finalJ == 0 || finalJ == 12) {
Snackbar.make(requireView(), "Cannot override this color", Snackbar.LENGTH_SHORT)
.setAction("Dismiss", v2 -> {
})
.show();
return;
}

new ColorPickerDialog()
.withCornerRadius(10)
.withColor((Integer) v.getTag())
.withAlphaEnabled(false)
.withPicker(ImagePickerView.class)
.withListener((pickerView, color) -> {
if ((Integer) v.getTag() != color) {
v.setTag(color);
v.getBackground().setTint(color);
((TextView) ((ViewGroup) v)
.getChildAt(0))
.setTextColor(ColorUtil.calculateTextColor(color));
RPrefs.putInt("monet_color_" + finalI + finalJ, color);
}
})
.show(getChildFragmentManager(), "overrideColorPicker" + finalI + finalJ);
})
.show();
});

colorTableRows[i].getChildAt(j).setOnLongClickListener(v -> {
if (finalJ == 0 || finalJ == 12) {
return true;
}

RPrefs.clearPref("monet_color_" + finalI + finalJ);
v.getBackground().setTint(systemColors[finalI][finalJ]);
v.setTag(systemColors[finalI][finalJ]);
((TextView) ((ViewGroup) v)
.getChildAt(0))
.setTextColor(ColorUtil.calculateTextColor(systemColors[finalI][finalJ]));
Snackbar.make(requireView(), "Custom color cleared", Snackbar.LENGTH_SHORT)
.setAction("Reset all", v2 -> {
for (int x = 0; x < colorTableRows.length; x++) {
for (int y = 0; y < colorTableRows[x].getChildCount(); y++) {
RPrefs.clearPref("monet_color_" + x + y);
}
}
})
.show();
return true;
});
}
}
}
Expand All @@ -244,13 +335,21 @@ private void assignCustomColorsToPalette() {
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);

sharedViewModel.getBooleanStates().observe(getViewLifecycleOwner(), this::updateBooleanStates);
sharedViewModel.getVisibilityStates().observe(getViewLifecycleOwner(), this::updateViewVisibility);
}

private void updateBooleanStates(Map<String, Boolean> stringBooleanMap) {
Boolean accurateShades = stringBooleanMap.get(MONET_ACCURATE_SHADES);
if (accurateShades != null) {
assignCustomColorsToPalette();
}
}

private void updateViewVisibility(Map<String, Integer> visibilityStates) {
Integer visibility = visibilityStates.get(MONET_SEED_COLOR_ENABLED);
if (visibility != null && binding.seedColorPicker.getVisibility() != visibility) {
binding.seedColorPicker.setVisibility(visibility);
Integer seedColorVisibility = visibilityStates.get(MONET_SEED_COLOR_ENABLED);
if (seedColorVisibility != null && binding.seedColorPicker.getVisibility() != seedColorVisibility) {
binding.seedColorPicker.setVisibility(seedColorVisibility);
monetSeedColor = new int[]{RPrefs.getInt(
MONET_SEED_COLOR,
getPrimaryColor()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.drdisagree.colorblendr.ui.fragments;

import static com.drdisagree.colorblendr.common.Const.MANUAL_OVERRIDE_COLORS;
import static com.drdisagree.colorblendr.common.Const.MONET_ACCURATE_SHADES;
import static com.drdisagree.colorblendr.common.Const.MONET_PITCH_BLACK_THEME;
import static com.drdisagree.colorblendr.common.Const.MONET_SEED_COLOR_ENABLED;

Expand All @@ -26,6 +28,12 @@ public class ToolsFragment extends Fragment {
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
binding = FragmentToolsBinding.inflate(inflater, container, false);

binding.accurateShades.setSwitchChecked(RPrefs.getBoolean(MONET_ACCURATE_SHADES, true));
binding.accurateShades.setSwitchChangeListener((buttonView, isChecked) -> {
RPrefs.putBoolean(MONET_ACCURATE_SHADES, isChecked);
sharedViewModel.setBooleanState(MONET_ACCURATE_SHADES, isChecked);
});

binding.pitchBlackTheme.setSwitchChecked(RPrefs.getBoolean(MONET_PITCH_BLACK_THEME, false));
binding.pitchBlackTheme.setSwitchChangeListener((buttonView, isChecked) -> RPrefs.putBoolean(MONET_PITCH_BLACK_THEME, isChecked));

Expand All @@ -35,6 +43,9 @@ public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container,
sharedViewModel.setVisibilityState(MONET_SEED_COLOR_ENABLED, isChecked ? View.VISIBLE : View.GONE);
});

binding.overrideColorsManually.setSwitchChecked(RPrefs.getBoolean(MANUAL_OVERRIDE_COLORS, false));
binding.overrideColorsManually.setSwitchChangeListener((buttonView, isChecked) -> RPrefs.putBoolean(MANUAL_OVERRIDE_COLORS, isChecked));

return binding.getRoot();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,21 @@

public class SharedViewModel extends ViewModel {

private final MutableLiveData<Map<String, Boolean>> booleanStates = new MutableLiveData<>();

public LiveData<Map<String, Boolean>> getBooleanStates() {
return booleanStates;
}

public void setBooleanState(String viewId, boolean state) {
Map<String, Boolean> currentStates = booleanStates.getValue();
if (currentStates == null) {
currentStates = new HashMap<>();
}
currentStates.put(viewId, state);
booleanStates.setValue(currentStates);
}

private final MutableLiveData<Map<String, Integer>> visibilityStates = new MutableLiveData<>();

public LiveData<Map<String, Integer>> getVisibilityStates() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ public static String[][] getColorNames() {
return colorNames;
}

public static String intToHexColor(int colorInt) {
return String.format("#%06X", (0xFFFFFF & colorInt));
}

public static int[][] getSystemColors(Context context) {
return new int[][]{
new int[]{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.drdisagree.colorblendr.xposed.modules;

import static com.drdisagree.colorblendr.common.Const.MONET_ACCENT_SATURATION;
import static com.drdisagree.colorblendr.common.Const.MONET_ACCURATE_SHADES;
import static com.drdisagree.colorblendr.common.Const.MONET_BACKGROUND_LIGHTNESS;
import static com.drdisagree.colorblendr.common.Const.MONET_BACKGROUND_SATURATION;
import static com.drdisagree.colorblendr.common.Const.MONET_PITCH_BLACK_THEME;
Expand Down Expand Up @@ -36,6 +37,7 @@ public class MonetColorsA12 extends ModPack implements IXposedHookLoadPackage {
private int monetBackgroundSaturation = 100;
private int monetBackgroundLightness = 100;
private boolean pitchBlackTheme = false;
private boolean accurateShades = true;
private AtomicInteger counter;
private Method reevaluateSystemTheme;
private XC_MethodHook.MethodHookParam ThemeOverlayControllerParam;
Expand All @@ -51,12 +53,14 @@ public void updatePrefs(String... Key) {
monetBackgroundSaturation = Xprefs.getInt(MONET_BACKGROUND_SATURATION, 100);
monetBackgroundLightness = Xprefs.getInt(MONET_BACKGROUND_LIGHTNESS, 100);
pitchBlackTheme = Xprefs.getBoolean(MONET_PITCH_BLACK_THEME, false);
accurateShades = Xprefs.getBoolean(MONET_ACCURATE_SHADES, true);
seedColor = Xprefs.getInt(MONET_SEED_COLOR, -1);

if (Key.length > 0 && (Key[0].equals(MONET_ACCENT_SATURATION) ||
Key[0].equals(MONET_BACKGROUND_SATURATION) ||
Key[0].equals(MONET_BACKGROUND_LIGHTNESS) ||
Key[0].equals(MONET_PITCH_BLACK_THEME) ||
Key[0].equals(MONET_ACCURATE_SHADES) ||
Key[0].equals(MONET_SEED_COLOR)
)) {
try {
Expand Down Expand Up @@ -113,7 +117,8 @@ protected void beforeHookedMethod(MethodHookParam param) {
monetAccentSaturation,
monetBackgroundSaturation,
monetBackgroundLightness,
pitchBlackTheme
pitchBlackTheme,
accurateShades
);

int[] shades = modifiedShades.stream()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.drdisagree.colorblendr.xposed.modules;

import static com.drdisagree.colorblendr.common.Const.MONET_ACCENT_SATURATION;
import static com.drdisagree.colorblendr.common.Const.MONET_ACCURATE_SHADES;
import static com.drdisagree.colorblendr.common.Const.MONET_BACKGROUND_LIGHTNESS;
import static com.drdisagree.colorblendr.common.Const.MONET_BACKGROUND_SATURATION;
import static com.drdisagree.colorblendr.common.Const.MONET_PITCH_BLACK_THEME;
Expand Down Expand Up @@ -37,6 +38,7 @@ public class MonetColorsA13 extends ModPack implements IXposedHookLoadPackage {
private int monetBackgroundSaturation = 100;
private int monetBackgroundLightness = 100;
private boolean pitchBlackTheme = false;
private boolean accurateShades = true;
private AtomicInteger counter;
private Method reevaluateSystemTheme;
private XC_MethodHook.MethodHookParam ThemeOverlayControllerParam;
Expand All @@ -55,12 +57,14 @@ public void updatePrefs(String... Key) {
monetBackgroundSaturation = Xprefs.getInt(MONET_BACKGROUND_SATURATION, 100);
monetBackgroundLightness = Xprefs.getInt(MONET_BACKGROUND_LIGHTNESS, 100);
pitchBlackTheme = Xprefs.getBoolean(MONET_PITCH_BLACK_THEME, false);
accurateShades = Xprefs.getBoolean(MONET_ACCURATE_SHADES, true);
seedColor = Xprefs.getInt(MONET_SEED_COLOR, -1);

if (Key.length > 0 && (Key[0].equals(MONET_ACCENT_SATURATION) ||
Key[0].equals(MONET_BACKGROUND_SATURATION) ||
Key[0].equals(MONET_BACKGROUND_LIGHTNESS) ||
Key[0].equals(MONET_PITCH_BLACK_THEME) ||
Key[0].equals(MONET_ACCURATE_SHADES) ||
Key[0].equals(MONET_SEED_COLOR)
)) {
try {
Expand Down Expand Up @@ -129,7 +133,8 @@ protected void beforeHookedMethod(MethodHookParam param) {
monetAccentSaturation,
monetBackgroundSaturation,
monetBackgroundLightness,
pitchBlackTheme
pitchBlackTheme,
accurateShades
);

param.setResult(modifiedShades);
Expand Down Expand Up @@ -171,7 +176,8 @@ protected void beforeHookedMethod(MethodHookParam param) {
monetAccentSaturation,
monetBackgroundSaturation,
monetBackgroundLightness,
pitchBlackTheme
pitchBlackTheme,
accurateShades
);

int[] shades = modifiedShades.stream()
Expand Down
Loading

0 comments on commit 120680e

Please sign in to comment.