Skip to content

Commit f8cb9fe

Browse files
committed
replace color picker from another library
Fixes: #19237
1 parent c04dede commit f8cb9fe

File tree

6 files changed

+90
-49
lines changed

6 files changed

+90
-49
lines changed

AnkiDroid/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,7 @@ dependencies {
424424
implementation libs.java.semver // For AnkiDroid JS API Versioning
425425
implementation libs.drakeet.drawer
426426
implementation libs.tapTargetPrompt
427-
implementation libs.colorpicker
427+
implementation libs.skydoves.colorpickerview
428428
implementation libs.kotlin.reflect
429429
implementation libs.kotlin.test
430430
implementation libs.search.preference

AnkiDroid/src/main/java/com/ichi2/anki/Whiteboard.kt

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,10 @@ import com.ichi2.anki.common.time.Time
4545
import com.ichi2.anki.common.time.getTimestamp
4646
import com.ichi2.anki.dialogs.WhiteBoardWidthDialog
4747
import com.ichi2.anki.preferences.sharedPrefs
48+
import com.ichi2.anki.ui.windows.reviewer.whiteboard.createColorPickerDialog
4849
import com.ichi2.compat.CompatHelper
4950
import com.ichi2.themes.Themes.currentTheme
5051
import com.ichi2.utils.DisplayUtils.getDisplayDimensions
51-
import com.mrudultora.colorpicker.ColorPickerPopUp
5252
import timber.log.Timber
5353
import java.io.FileNotFoundException
5454
import kotlin.math.abs
@@ -395,22 +395,11 @@ class Whiteboard(
395395
penColor = yellowPenColor
396396
}
397397
R.id.pen_color_custom -> {
398-
ColorPickerPopUp(context).run {
399-
setShowAlpha(true)
400-
setDefaultColor(penColor)
401-
setOnPickColorListener(
402-
object : ColorPickerPopUp.OnPickColorListener {
403-
override fun onColorPicked(color: Int) {
404-
penColor = color
405-
}
406-
407-
override fun onCancel() {
408-
// unused
409-
}
410-
},
411-
)
412-
show()
413-
}
398+
createColorPickerDialog(
399+
context = context,
400+
initialColor = penColor,
401+
onColorSelected = { penColor = it },
402+
).show()
414403
}
415404
R.id.stroke_width -> {
416405
handleWidthChangeDialog()
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/*
2+
* Copyright (c) 2025 Divyansh Kushwaha <[email protected]>
3+
*
4+
* This program is free software; you can redistribute it and/or modify it under
5+
* the terms of the GNU General Public License as published by the Free Software
6+
* Foundation; either version 3 of the License, or (at your option) any later
7+
* version.
8+
*
9+
* This program is distributed in the hope that it will be useful, but WITHOUT ANY
10+
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
11+
* PARTICULAR PURPOSE. See the GNU General Public License for more details.
12+
*
13+
* You should have received a copy of the GNU General Public License along with
14+
* this program. If not, see <http://www.gnu.org/licenses/>.
15+
*/
16+
17+
package com.ichi2.anki.ui.windows.reviewer.whiteboard
18+
19+
import android.content.Context
20+
import com.ichi2.anki.R
21+
import com.skydoves.colorpickerview.ColorEnvelope
22+
import com.skydoves.colorpickerview.ColorPickerDialog
23+
import com.skydoves.colorpickerview.listeners.ColorEnvelopeListener
24+
25+
/**
26+
* Creates a customizable color picker dialog with optional alpha and brightness controls.
27+
*
28+
* @param context The Android context used to create the dialog.
29+
* @param initialColor The initial color to display in the picker as an `AARRGGBB` integer.
30+
* @param showAlpha Whether to show the alpha (transparency) slider. Defaults to `true`.
31+
* @param showBrightnessSlider Whether to show the brightness adjustment slider. Defaults to `true`.
32+
* @param onColorSelected Callback invoked when the user confirms their color selection.
33+
* Receives the selected color as an `AARRGGBB` integer.
34+
*
35+
* @return A [ColorPickerDialog.Builder] instance that can be further customized or shown using `.show()`.
36+
*/
37+
fun createColorPickerDialog(
38+
context: Context,
39+
initialColor: Int,
40+
showAlpha: Boolean = true,
41+
showBrightnessSlider: Boolean = true,
42+
onColorSelected: (Int) -> Unit,
43+
): ColorPickerDialog.Builder =
44+
ColorPickerDialog.Builder(context).apply {
45+
attachAlphaSlideBar(showAlpha)
46+
colorPickerView.setInitialColor(initialColor)
47+
setPositiveButton(
48+
R.string.dialog_ok,
49+
object : ColorEnvelopeListener {
50+
override fun onColorSelected(
51+
envelope: ColorEnvelope?,
52+
fromUser: Boolean,
53+
) {
54+
envelope?.color?.let(onColorSelected)
55+
}
56+
},
57+
)
58+
setTitle(R.string.choose_color)
59+
setNegativeButton(R.string.dialog_cancel, null)
60+
attachBrightnessSlideBar(showBrightnessSlider)
61+
setBottomSpace(12) // 12Dp
62+
}

AnkiDroid/src/main/java/com/ichi2/anki/ui/windows/reviewer/whiteboard/WhiteboardFragment.kt

Lines changed: 16 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ import com.ichi2.compat.setTooltipTextCompat
4949
import com.ichi2.themes.Themes
5050
import com.ichi2.utils.dp
5151
import com.ichi2.utils.increaseHorizontalPaddingOfMenuIcons
52-
import com.mrudultora.colorpicker.ColorPickerPopUp
5352
import kotlinx.coroutines.flow.combine
5453
import kotlinx.coroutines.flow.launchIn
5554
import kotlinx.coroutines.flow.onEach
@@ -274,21 +273,14 @@ class WhiteboardFragment :
274273
* Shows a popup for adding a new brush color.
275274
*/
276275
private fun showAddColorDialog() {
277-
ColorPickerPopUp(context).run {
278-
setShowAlpha(true)
279-
setDefaultColor(viewModel.brushColor.value)
280-
setOnPickColorListener(
281-
object : ColorPickerPopUp.OnPickColorListener {
282-
override fun onColorPicked(color: Int) {
283-
Timber.i("Added brush with color %d", color)
284-
viewModel.addBrush(color)
285-
}
286-
287-
override fun onCancel() {}
288-
},
289-
)
290-
show()
291-
}
276+
createColorPickerDialog(
277+
context = requireContext(),
278+
initialColor = viewModel.brushColor.value,
279+
onColorSelected = { color ->
280+
Timber.i("Added brush with color %d", color)
281+
viewModel.addBrush(color)
282+
},
283+
).show()
292284
}
293285

294286
/**
@@ -367,19 +359,14 @@ class WhiteboardFragment :
367359
* Shows a color picker popup to change the active brush's color.
368360
*/
369361
private fun showChangeColorDialog() {
370-
ColorPickerPopUp(requireContext())
371-
.setShowAlpha(true)
372-
.setDefaultColor(viewModel.brushColor.value)
373-
.setOnPickColorListener(
374-
object : ColorPickerPopUp.OnPickColorListener {
375-
override fun onColorPicked(color: Int) {
376-
viewModel.updateBrushColor(color)
377-
strokeWidthPopup?.dismiss()
378-
}
379-
380-
override fun onCancel() {}
381-
},
382-
).show()
362+
createColorPickerDialog(
363+
context = requireContext(),
364+
initialColor = viewModel.brushColor.value,
365+
onColorSelected = { color ->
366+
viewModel.updateBrushColor(color)
367+
strokeWidthPopup?.dismiss()
368+
},
369+
).show()
383370
}
384371

385372
/**

AnkiDroid/src/main/res/values/03-dialogs.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,4 +268,7 @@ also changes the interval of the card"
268268
<string name="tts_error_dialog_reason_text">The text to speech engine <b>%1$s</b> does not support the following language: <b>%2$s</b></string>
269269
<string name="tts_error_dialog_change_button_text">Change engine</string>
270270
<string name="tts_error_dialog_supported_voices_button_text">Voice options</string>
271+
272+
<!-- Whiteboard -->
273+
<string name="choose_color">Choose Color</string>
271274
</resources>

gradle/libs.versions.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ androidxWork = "2.10.5"
6262
ankiBackend = '0.1.62-anki25.09.2'
6363
autoService = "1.1.1"
6464
autoServiceAnnotations = "1.1.1"
65-
colorpicker = "1.2.0"
65+
colorPickerView= "2.3.0"
6666
# https://commons.apache.org/proper/commons-collections/changes.html
6767
commonsCollections4 = "4.5.0"
6868
# https://commons.apache.org/proper/commons-compress/changes-report.html
@@ -143,7 +143,7 @@ androidx-recyclerview = { module = "androidx.recyclerview:recyclerview", version
143143
auto-service = { module = "com.google.auto.service:auto-service", version.ref = "autoService" }
144144
auto-service-annotations = { module = "com.google.auto.service:auto-service-annotations", version.ref = "autoServiceAnnotations" }
145145
jetbrains-annotations = { module = "org.jetbrains:annotations", version.ref = "jetbrainsAnnotations" }
146-
colorpicker = { module = "com.github.mrudultora:Colorpicker", version.ref = "colorpicker" }
146+
skydoves-colorpickerview = {module = "com.github.skydoves:colorpickerview", version.ref = "colorPickerView"}
147147
commons-io = { module = "commons-io:commons-io", version.ref = "commonsIo" }
148148
commons-collections4 = { module = "org.apache.commons:commons-collections4", version.ref = "commonsCollections4" }
149149
commons-compress = { module = "org.apache.commons:commons-compress", version.ref = "commonsCompress" }

0 commit comments

Comments
 (0)