Use background color as state instead of using on/off drawables
This commit is contained in:
parent
853eecf876
commit
02693b33bf
|
@ -137,6 +137,7 @@ class MainActivity : SimpleActivity(), CanvasListener {
|
||||||
|
|
||||||
requestedOrientation = if (config.forcePortraitMode) ActivityInfo.SCREEN_ORIENTATION_PORTRAIT else ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED
|
requestedOrientation = if (config.forcePortraitMode) ActivityInfo.SCREEN_ORIENTATION_PORTRAIT else ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED
|
||||||
refreshMenuItems()
|
refreshMenuItems()
|
||||||
|
updateButtonStates()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onPause() {
|
override fun onPause() {
|
||||||
|
@ -348,6 +349,8 @@ class MainActivity : SimpleActivity(), CanvasListener {
|
||||||
private fun eraserClicked() {
|
private fun eraserClicked() {
|
||||||
if (isEyeDropperOn) {
|
if (isEyeDropperOn) {
|
||||||
eyeDropperClicked()
|
eyeDropperClicked()
|
||||||
|
} else if (isBucketFillOn) {
|
||||||
|
bucketFillClicked()
|
||||||
}
|
}
|
||||||
|
|
||||||
isEraserOn = !isEraserOn
|
isEraserOn = !isEraserOn
|
||||||
|
@ -355,13 +358,7 @@ class MainActivity : SimpleActivity(), CanvasListener {
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun updateEraserState() {
|
private fun updateEraserState() {
|
||||||
val iconId = if (isEraserOn) {
|
updateButtonStates()
|
||||||
R.drawable.ic_eraser_off_vector
|
|
||||||
} else {
|
|
||||||
R.drawable.ic_eraser_on_vector
|
|
||||||
}
|
|
||||||
|
|
||||||
eraser.setImageResource(iconId)
|
|
||||||
my_canvas.toggleEraser(isEraserOn)
|
my_canvas.toggleEraser(isEraserOn)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -382,6 +379,8 @@ class MainActivity : SimpleActivity(), CanvasListener {
|
||||||
private fun eyeDropperClicked() {
|
private fun eyeDropperClicked() {
|
||||||
if (isEraserOn) {
|
if (isEraserOn) {
|
||||||
eraserClicked()
|
eraserClicked()
|
||||||
|
} else if (isBucketFillOn) {
|
||||||
|
bucketFillClicked()
|
||||||
}
|
}
|
||||||
|
|
||||||
isEyeDropperOn = !isEyeDropperOn
|
isEyeDropperOn = !isEyeDropperOn
|
||||||
|
@ -391,28 +390,44 @@ class MainActivity : SimpleActivity(), CanvasListener {
|
||||||
eyeDropper.stop()
|
eyeDropper.stop()
|
||||||
}
|
}
|
||||||
|
|
||||||
val iconId = if (isEyeDropperOn) {
|
updateButtonStates()
|
||||||
R.drawable.ic_colorize_off_vector
|
|
||||||
} else {
|
|
||||||
R.drawable.ic_colorize_on_vector
|
|
||||||
}
|
|
||||||
|
|
||||||
eye_dropper.setImageResource(iconId)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun bucketFillClicked() {
|
private fun bucketFillClicked() {
|
||||||
isBucketFillOn = !isBucketFillOn
|
if (isEraserOn) {
|
||||||
|
eraserClicked()
|
||||||
val iconId = if (isBucketFillOn) {
|
} else if (isEyeDropperOn) {
|
||||||
R.drawable.ic_bucket_fill_off_vector
|
eyeDropperClicked()
|
||||||
} else {
|
|
||||||
R.drawable.ic_bucket_fill_on_vector
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bucket_fill.setImageResource(iconId)
|
isBucketFillOn = !isBucketFillOn
|
||||||
|
|
||||||
|
updateButtonStates()
|
||||||
my_canvas.toggleBucketFill(isBucketFillOn)
|
my_canvas.toggleBucketFill(isBucketFillOn)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun updateButtonStates() {
|
||||||
|
arrayOf(
|
||||||
|
eraser to isEraserOn,
|
||||||
|
eye_dropper to isEyeDropperOn,
|
||||||
|
bucket_fill to isBucketFillOn
|
||||||
|
).forEach {
|
||||||
|
val view = it.first
|
||||||
|
val enabled = it.second
|
||||||
|
|
||||||
|
view.apply {
|
||||||
|
if (enabled) {
|
||||||
|
val primaryColor = getProperPrimaryColor()
|
||||||
|
background = ColorDrawable(primaryColor).apply { alpha = 220 }
|
||||||
|
applyColorFilter(primaryColor.getContrastColor())
|
||||||
|
} else {
|
||||||
|
background = null
|
||||||
|
applyColorFilter(config.canvasBackgroundColor.getContrastColor())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private fun confirmImage() {
|
private fun confirmImage() {
|
||||||
when {
|
when {
|
||||||
isEditIntent -> {
|
isEditIntent -> {
|
||||||
|
|
Loading…
Reference in New Issue