adding a Use Default button to the color picker

This commit is contained in:
tibbi 2019-07-22 21:39:12 +02:00
parent ff63136f5f
commit 7764ea2d7c
2 changed files with 20 additions and 9 deletions

View file

@ -12,11 +12,12 @@ import android.widget.ImageView
import androidx.appcompat.app.AlertDialog import androidx.appcompat.app.AlertDialog
import com.simplemobiletools.commons.R import com.simplemobiletools.commons.R
import com.simplemobiletools.commons.extensions.* import com.simplemobiletools.commons.extensions.*
import com.simplemobiletools.commons.helpers.DEFAULT_NAVIGATION_BAR_COLOR
import com.simplemobiletools.commons.views.ColorPickerSquare import com.simplemobiletools.commons.views.ColorPickerSquare
import kotlinx.android.synthetic.main.dialog_color_picker.view.* import kotlinx.android.synthetic.main.dialog_color_picker.view.*
// forked from https://github.com/yukuku/ambilwarna // forked from https://github.com/yukuku/ambilwarna
class ColorPickerDialog(val activity: Activity, color: Int, val removeDimmedBackground: Boolean = false, class ColorPickerDialog(val activity: Activity, color: Int, val removeDimmedBackground: Boolean = false, val showUseDefaultButton: Boolean = false,
val currentColorCallback: ((color: Int) -> Unit)? = null, val callback: (wasPositivePressed: Boolean, color: Int) -> Unit) { val currentColorCallback: ((color: Int) -> Unit)? = null, val callback: (wasPositivePressed: Boolean, color: Int) -> Unit) {
lateinit var viewHue: View lateinit var viewHue: View
lateinit var viewSatVal: ColorPickerSquare lateinit var viewSatVal: ColorPickerSquare
@ -120,17 +121,22 @@ class ColorPickerDialog(val activity: Activity, color: Int, val removeDimmedBack
} }
val textColor = activity.baseConfig.textColor val textColor = activity.baseConfig.textColor
dialog = AlertDialog.Builder(activity) val builder = AlertDialog.Builder(activity)
.setPositiveButton(R.string.ok) { dialog, which -> confirmNewColor() } .setPositiveButton(R.string.ok) { dialog, which -> confirmNewColor() }
.setNegativeButton(R.string.cancel) { dialog, which -> dialogDismissed() } .setNegativeButton(R.string.cancel) { dialog, which -> dialogDismissed() }
.setOnCancelListener { dialogDismissed() } .setOnCancelListener { dialogDismissed() }
.create().apply {
activity.setupDialogStuff(view, this) { if (showUseDefaultButton) {
view.color_picker_arrow.applyColorFilter(textColor) builder.setNeutralButton(R.string.use_default) { dialog, which -> useDefault() }
view.color_picker_hex_arrow.applyColorFilter(textColor) }
viewCursor.applyColorFilter(textColor)
} dialog = builder.create().apply {
} activity.setupDialogStuff(view, this) {
view.color_picker_arrow.applyColorFilter(textColor)
view.color_picker_hex_arrow.applyColorFilter(textColor)
viewCursor.applyColorFilter(textColor)
}
}
view.onGlobalLayout { view.onGlobalLayout {
moveHuePicker() moveHuePicker()
@ -151,6 +157,10 @@ class ColorPickerDialog(val activity: Activity, color: Int, val removeDimmedBack
} }
} }
private fun useDefault() {
callback(true, DEFAULT_NAVIGATION_BAR_COLOR)
}
private fun getHexCode(color: Int) = color.toHex().substring(1) private fun getHexCode(color: Int) = color.toHex().substring(1)
private fun updateHue() { private fun updateHue() {

View file

@ -21,6 +21,7 @@ const val ALARM_SOUND_TYPE_ALARM = 1
const val ALARM_SOUND_TYPE_NOTIFICATION = 2 const val ALARM_SOUND_TYPE_NOTIFICATION = 2
const val YOUR_ALARM_SOUNDS_MIN_ID = 1000 const val YOUR_ALARM_SOUNDS_MIN_ID = 1000
const val SHOW_FAQ_BEFORE_MAIL = "show_faq_before_mail" const val SHOW_FAQ_BEFORE_MAIL = "show_faq_before_mail"
const val DEFAULT_NAVIGATION_BAR_COLOR = -2
val DEFAULT_WIDGET_BG_COLOR = Color.parseColor("#33000000") val DEFAULT_WIDGET_BG_COLOR = Color.parseColor("#33000000")
const val HOUR_MINUTES = 60 const val HOUR_MINUTES = 60