Skip to content

Commit

Permalink
sNotzColor: Use own color picker
Browse files Browse the repository at this point in the history
Which is a modernized, simplified version of colorpicker library by @QuadFlask (ref: https://github.com/QuadFlask/colorpicker/). Due credits to the original author.

Signed-off-by: sunilpaulmathew <[email protected]>
sunilpaulmathew committed Jan 10, 2025

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent 5039cb0 commit 49364a7
Showing 25 changed files with 1,251 additions and 34 deletions.
1 change: 0 additions & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
@@ -85,7 +85,6 @@ dependencies {
implementation "com.github.sunilpaulmathew.sCommon:themeutils:${sCommon_Version}"
implementation "com.github.sunilpaulmathew.sCommon:translatorutils:${sCommon_Version}"

implementation 'com.github.QuadFlask:colorpicker:0.0.15'
implementation "com.google.android.material:material:1.12.0"
implementation "com.google.code.gson:gson:2.10.1"
implementation 'me.dm7.barcodescanner:zxing:1.9.8'
Original file line number Diff line number Diff line change
@@ -9,12 +9,11 @@
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.flask.colorpicker.ColorPickerView;
import com.flask.colorpicker.builder.ColorPickerDialogBuilder;
import com.google.android.material.button.MaterialButton;
import com.google.android.material.textview.MaterialTextView;
import com.sunilpaulmathew.snotz.R;
import com.sunilpaulmathew.snotz.adapters.ColorCustomizationsAdapter;
import com.sunilpaulmathew.snotz.colorpicker.ColorPickerDialog;
import com.sunilpaulmathew.snotz.utils.Security;
import com.sunilpaulmathew.snotz.utils.sNotzColor;
import com.sunilpaulmathew.snotz.utils.serializableItems.CheckListItems;
@@ -44,11 +43,10 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {

mStartButton.setOnClickListener(v -> Security.launchMainActivity(this));

mRecycleViewAdapter.setOnItemClickListener((position, v) -> ColorPickerDialogBuilder
mRecycleViewAdapter.setOnItemClickListener((position, v) -> ColorPickerDialog
.with(this)
.setTitle(R.string.choose_color)
.initialColor(sNotzColor.getDefaultColor(position, this))
.wheelType(ColorPickerView.WHEEL_TYPE.FLOWER)
.density(12)
.setOnColorSelectedListener(selectedColor -> {
})
Original file line number Diff line number Diff line change
@@ -22,12 +22,11 @@
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.flask.colorpicker.ColorPickerView;
import com.flask.colorpicker.builder.ColorPickerDialogBuilder;
import com.google.android.material.card.MaterialCardView;
import com.google.android.material.textview.MaterialTextView;
import com.sunilpaulmathew.snotz.R;
import com.sunilpaulmathew.snotz.adapters.CheckListAdapter;
import com.sunilpaulmathew.snotz.colorpicker.ColorPickerDialog;
import com.sunilpaulmathew.snotz.utils.AppSettings;
import com.sunilpaulmathew.snotz.utils.CheckLists;
import com.sunilpaulmathew.snotz.utils.Utils;
@@ -94,11 +93,10 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
mRecyclerViewCheckList.addItemDecoration(new DividerItemDecoration(this, DividerItemDecoration.VERTICAL));
mRecyclerViewCheckList.setAdapter(new CheckListAdapter(mData));

mColorBackground.setOnClickListener(v -> ColorPickerDialogBuilder
mColorBackground.setOnClickListener(v -> ColorPickerDialog
.with(this)
.setTitle(R.string.choose_color)
.initialColor(mSelectedColorBg)
.wheelType(ColorPickerView.WHEEL_TYPE.FLOWER)
.density(12)
.setOnColorSelectedListener(selectedColor -> {
})
@@ -110,11 +108,10 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
.setNegativeButton(R.string.cancel, (dialog, which) -> {
}).build().show());

mColorText.setOnClickListener(v -> ColorPickerDialogBuilder
mColorText.setOnClickListener(v -> ColorPickerDialog
.with(this)
.setTitle(R.string.choose_color)
.initialColor(mSelectedColorTxt)
.wheelType(ColorPickerView.WHEEL_TYPE.FLOWER)
.density(12)
.setOnColorSelectedListener(selectedColor -> {
})
Original file line number Diff line number Diff line change
@@ -27,8 +27,6 @@
import androidx.recyclerview.widget.ItemTouchHelper;
import androidx.recyclerview.widget.RecyclerView;

import com.flask.colorpicker.ColorPickerView;
import com.flask.colorpicker.builder.ColorPickerDialogBuilder;
import com.google.android.material.card.MaterialCardView;
import com.google.android.material.checkbox.MaterialCheckBox;
import com.google.android.material.dialog.MaterialAlertDialogBuilder;
@@ -37,6 +35,7 @@
import com.google.gson.JsonObject;
import com.sunilpaulmathew.snotz.R;
import com.sunilpaulmathew.snotz.adapters.CheckListAdapter;
import com.sunilpaulmathew.snotz.colorpicker.ColorPickerDialog;
import com.sunilpaulmathew.snotz.utils.AppSettings;
import com.sunilpaulmathew.snotz.utils.CheckLists;
import com.sunilpaulmathew.snotz.utils.Utils;
@@ -150,7 +149,9 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
isNoteModified = true;
}
mContents.setText(mNote);
} else {
}

if (mNote == null || isChecklist) {
mReadingMode.setVisibility(View.GONE);
}

@@ -238,11 +239,10 @@ public void onSwiped(@NonNull RecyclerView.ViewHolder viewHolder, int direction)
}
});

mColorBackground.setOnClickListener(v -> ColorPickerDialogBuilder
mColorBackground.setOnClickListener(v -> ColorPickerDialog
.with(this)
.setTitle(R.string.choose_color)
.initialColor(mSelectedColorBg)
.wheelType(ColorPickerView.WHEEL_TYPE.FLOWER)
.density(12)
.setOnColorSelectedListener(selectedColor -> {
})
@@ -256,11 +256,10 @@ public void onSwiped(@NonNull RecyclerView.ViewHolder viewHolder, int direction)
}).build().show()
);

mColorText.setOnClickListener(v -> ColorPickerDialogBuilder
mColorText.setOnClickListener(v -> ColorPickerDialog
.with(this)
.setTitle(R.string.choose_color)
.initialColor(mSelectedColorTxt)
.wheelType(ColorPickerView.WHEEL_TYPE.FLOWER)
.density(12)
.setOnColorSelectedListener(selectedColor -> {
})
Original file line number Diff line number Diff line change
@@ -17,13 +17,12 @@
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.flask.colorpicker.ColorPickerView;
import com.flask.colorpicker.builder.ColorPickerDialogBuilder;
import com.google.android.material.dialog.MaterialAlertDialogBuilder;
import com.google.android.material.textview.MaterialTextView;
import com.sunilpaulmathew.snotz.BuildConfig;
import com.sunilpaulmathew.snotz.R;
import com.sunilpaulmathew.snotz.adapters.SettingsAdapter;
import com.sunilpaulmathew.snotz.colorpicker.ColorPickerDialog;
import com.sunilpaulmathew.snotz.utils.AppSettings;
import com.sunilpaulmathew.snotz.utils.Billing;
import com.sunilpaulmathew.snotz.utils.CheckLists;
@@ -85,11 +84,10 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
} else if (position == 1) {
sThemeUtils.setAppTheme(this);
} else if (position == 2) {
ColorPickerDialogBuilder
ColorPickerDialog
.with(this)
.setTitle(R.string.choose_color)
.initialColor(sNotzColor.getAppAccentColor(this))
.wheelType(ColorPickerView.WHEEL_TYPE.FLOWER)
.density(12)
.setOnColorSelectedListener(selectedColor -> {
})
@@ -125,11 +123,10 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
sCommonUtils.toast(getString(R.string.note_color_random_message), this).show();
return;
}
ColorPickerDialogBuilder
ColorPickerDialog
.with(this)
.setTitle(R.string.choose_color)
.initialColor(sCommonUtils.getInt("accent_color", sNotzColor.getAccentColor(this), this))
.wheelType(ColorPickerView.WHEEL_TYPE.FLOWER)
.density(12)
.setOnColorSelectedListener(selectedColor -> {
})
@@ -145,11 +142,10 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
sCommonUtils.toast(getString(R.string.note_color_random_message), this).show();
return;
}
ColorPickerDialogBuilder
ColorPickerDialog
.with(this)
.setTitle(R.string.choose_color)
.initialColor(sCommonUtils.getInt("text_color", sNotzColor.getTextColor(this), this))
.wheelType(ColorPickerView.WHEEL_TYPE.FLOWER)
.density(12)
.setOnColorSelectedListener(selectedColor -> {
})
@@ -172,12 +168,11 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
sCommonUtils.saveBoolean("auto_save", !sCommonUtils.getBoolean("auto_save", false, this), this);
mRecycleViewAdapter.notifyItemChanged(position);
} else if (position == 11) {
ColorPickerDialogBuilder
ColorPickerDialog
.with(this)
.setTitle(R.string.choose_color)
.initialColor(sCommonUtils.getInt("checklist_color", sNotzColor.getMaterial3Colors(
0, sCommonUtils.getColor(R.color.color_teal, this), this), this))
.wheelType(ColorPickerView.WHEEL_TYPE.FLOWER)
.density(12)
.setOnColorSelectedListener(selectedColor -> {
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
package com.sunilpaulmathew.snotz.colorpicker;

import android.content.Context;
import android.content.DialogInterface;
import android.graphics.Color;
import android.view.Gravity;
import android.view.ViewGroup;

import androidx.appcompat.widget.LinearLayoutCompat;

import com.google.android.material.dialog.MaterialAlertDialogBuilder;
import com.sunilpaulmathew.snotz.R;
import com.sunilpaulmathew.snotz.colorpicker.interfaces.ColorPickerClickListener;
import com.sunilpaulmathew.snotz.colorpicker.interfaces.OnColorSelectedListener;
import com.sunilpaulmathew.snotz.colorpicker.views.AlphaSlider;
import com.sunilpaulmathew.snotz.colorpicker.views.ColorPickerView;
import com.sunilpaulmathew.snotz.colorpicker.views.LightnessSlider;

public class ColorPickerDialog {

private final ColorPickerView colorPickerView;
private final LinearLayoutCompat pickerContainer;
private final MaterialAlertDialogBuilder builder;

private final Integer[] initialColor = new Integer[] {
null, null, null, null, null
};

private ColorPickerDialog(Context context) {
this(context, 0);
}

private ColorPickerDialog(Context context, int theme) {
int defaultMargin = getDimensionAsPx(context, R.dimen.default_slider_margin);
int defaultMarginTop = getDimensionAsPx(context, R.dimen.default_margin_top);

builder = new MaterialAlertDialogBuilder(context, theme);
pickerContainer = new LinearLayoutCompat(context);
pickerContainer.setOrientation(LinearLayoutCompat.VERTICAL);
pickerContainer.setGravity(Gravity.CENTER_HORIZONTAL);
pickerContainer.setPadding(defaultMargin, defaultMarginTop, defaultMargin, 0);

LinearLayoutCompat.LayoutParams layoutParamsForColorPickerView = new LinearLayoutCompat.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 0);
layoutParamsForColorPickerView.weight = 1;
colorPickerView = new ColorPickerView(context);

pickerContainer.addView(colorPickerView, layoutParamsForColorPickerView);

builder.setView(pickerContainer);
}

public static ColorPickerDialog with(Context context) {
return new ColorPickerDialog(context);
}

public static ColorPickerDialog with(Context context, int theme) {
return new ColorPickerDialog(context, theme);
}

public ColorPickerDialog setTitle(String title) {
builder.setTitle(title);
return this;
}

public ColorPickerDialog setTitle(int titleId) {
builder.setTitle(titleId);
return this;
}

public ColorPickerDialog initialColor(int initialColor) {
this.initialColor[0] = initialColor;
return this;
}

public ColorPickerDialog density(int density) {
colorPickerView.setDensity(density);
return this;
}

public ColorPickerDialog setOnColorSelectedListener(OnColorSelectedListener onColorSelectedListener) {
colorPickerView.addOnColorSelectedListener(onColorSelectedListener);
return this;
}

public ColorPickerDialog setPositiveButton(CharSequence text, final ColorPickerClickListener onClickListener) {
builder.setPositiveButton(text, (dialog, which) -> positiveButtonOnClick(dialog, onClickListener));
return this;
}

public ColorPickerDialog setPositiveButton(int textId, final ColorPickerClickListener onClickListener) {
builder.setPositiveButton(textId, (dialog, which) -> positiveButtonOnClick(dialog, onClickListener));
return this;
}

public ColorPickerDialog setNegativeButton(CharSequence text, DialogInterface.OnClickListener onClickListener) {
builder.setNegativeButton(text, onClickListener);
return this;
}

public ColorPickerDialog setNegativeButton(int textId, DialogInterface.OnClickListener onClickListener) {
builder.setNegativeButton(textId, onClickListener);
return this;
}

public MaterialAlertDialogBuilder build() {
Context context = builder.getContext();
colorPickerView.setInitialColors(initialColor, getStartOffset(initialColor));
boolean isBorderEnabled = true;
colorPickerView.setShowBorder(isBorderEnabled);

LinearLayoutCompat.LayoutParams layoutParamsForLightnessBar = new LinearLayoutCompat.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, getDimensionAsPx(context, R.dimen.default_slider_height));
LightnessSlider lightnessSlider = new LightnessSlider(context);
lightnessSlider.setLayoutParams(layoutParamsForLightnessBar);
pickerContainer.addView(lightnessSlider);
colorPickerView.setLightnessSlider(lightnessSlider);
lightnessSlider.setColor(getStartColor(initialColor));
lightnessSlider.setShowBorder(isBorderEnabled);

LinearLayoutCompat.LayoutParams layoutParamsForAlphaBar = new LinearLayoutCompat.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, getDimensionAsPx(context, R.dimen.default_slider_height));
AlphaSlider alphaSlider = new AlphaSlider(context);
alphaSlider.setLayoutParams(layoutParamsForAlphaBar);
pickerContainer.addView(alphaSlider);
colorPickerView.setAlphaSlider(alphaSlider);
alphaSlider.setColor(getStartColor(initialColor));
alphaSlider.setShowBorder(isBorderEnabled);

return builder;
}

private Integer getStartOffset(Integer[] colors) {
int start = 0;
for (int i = 0; i < colors.length; i++) {
if (colors[i] == null) {
return start;
}
start = (i + 1) / 2;
}
return start;
}

private int getStartColor(Integer[] colors) {
Integer startColor = getStartOffset(colors);
return startColor == null ? Color.WHITE : colors[startColor];
}

private static int getDimensionAsPx(Context context, int rid) {
return (int) (context.getResources().getDimension(rid) + .5f);
}

private void positiveButtonOnClick(DialogInterface dialog, ColorPickerClickListener onClickListener) {
int selectedColor = colorPickerView.getSelectedColor();
Integer[] allColors = colorPickerView.getAllColors();
onClickListener.onClick(dialog, selectedColor, allColors);
}

}
18 changes: 18 additions & 0 deletions app/src/main/java/com/sunilpaulmathew/snotz/colorpicker/License.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
## License

```
Copyright (C) 2014-2017 QuadFlask
Copyright (C) 2025-2026 sunilpaulmathew <[email protected]>
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.sunilpaulmathew.snotz.colorpicker.interfaces;

import android.content.DialogInterface;

public interface ColorPickerClickListener {
void onClick(DialogInterface d, int lastSelectedColor, Integer[] allColors);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.sunilpaulmathew.snotz.colorpicker.interfaces;

import android.graphics.Canvas;

import com.sunilpaulmathew.snotz.colorpicker.utils.ColorCircle;

import java.util.List;

public interface ColorWheelRenderer {
float GAP_PERCENTAGE = 0.025f;

void draw(int density, float maxRadius, float lightness, float alpha, float strokeWidth, float cSize, Canvas targetCanvas);

List<ColorCircle> getColorCircleList();
}
Loading

0 comments on commit 49364a7

Please sign in to comment.