allow customizing the editor drawing color

This commit is contained in:
tibbi 2019-01-12 22:48:15 +01:00
parent 9da4b800ac
commit 90f2d5e5df
7 changed files with 63 additions and 0 deletions

View File

@ -24,6 +24,7 @@ import com.bumptech.glide.load.engine.GlideException
import com.bumptech.glide.request.RequestListener import com.bumptech.glide.request.RequestListener
import com.bumptech.glide.request.RequestOptions import com.bumptech.glide.request.RequestOptions
import com.bumptech.glide.request.target.Target import com.bumptech.glide.request.target.Target
import com.simplemobiletools.commons.dialogs.ColorPickerDialog
import com.simplemobiletools.commons.extensions.* import com.simplemobiletools.commons.extensions.*
import com.simplemobiletools.commons.helpers.OTG_PATH import com.simplemobiletools.commons.helpers.OTG_PATH
import com.simplemobiletools.commons.helpers.PERMISSION_WRITE_STORAGE import com.simplemobiletools.commons.helpers.PERMISSION_WRITE_STORAGE
@ -46,6 +47,7 @@ import kotlinx.android.synthetic.main.activity_edit.*
import kotlinx.android.synthetic.main.bottom_actions_aspect_ratio.* import kotlinx.android.synthetic.main.bottom_actions_aspect_ratio.*
import kotlinx.android.synthetic.main.bottom_editor_actions_filter.* import kotlinx.android.synthetic.main.bottom_editor_actions_filter.*
import kotlinx.android.synthetic.main.bottom_editor_crop_rotate_actions.* import kotlinx.android.synthetic.main.bottom_editor_crop_rotate_actions.*
import kotlinx.android.synthetic.main.bottom_editor_draw_actions.*
import kotlinx.android.synthetic.main.bottom_editor_primary_actions.* import kotlinx.android.synthetic.main.bottom_editor_primary_actions.*
import java.io.* import java.io.*
@ -73,6 +75,7 @@ class EditActivity : SimpleActivity(), CropImageView.OnCropImageCompleteListener
private lateinit var saveUri: Uri private lateinit var saveUri: Uri
private var resizeWidth = 0 private var resizeWidth = 0
private var resizeHeight = 0 private var resizeHeight = 0
private var drawColor = 0
private var lastOtherAspectRatio: Pair<Int, Int>? = null private var lastOtherAspectRatio: Pair<Int, Int>? = null
private var currPrimaryAction = PRIMARY_ACTION_NONE private var currPrimaryAction = PRIMARY_ACTION_NONE
private var currCropRotateAction = CROP_ROTATE_NONE private var currCropRotateAction = CROP_ROTATE_NONE
@ -312,6 +315,7 @@ class EditActivity : SimpleActivity(), CropImageView.OnCropImageCompleteListener
setupPrimaryActionButtons() setupPrimaryActionButtons()
setupCropRotateActionButtons() setupCropRotateActionButtons()
setupAspectRatioButtons() setupAspectRatioButtons()
setupDrawButtons()
} }
private fun setupPrimaryActionButtons() { private fun setupPrimaryActionButtons() {
@ -416,6 +420,17 @@ class EditActivity : SimpleActivity(), CropImageView.OnCropImageCompleteListener
updateAspectRatioButtons() updateAspectRatioButtons()
} }
private fun setupDrawButtons() {
updateDrawColor(config.lastEditorDrawColor)
bottom_draw_color.setOnClickListener {
ColorPickerDialog(this, drawColor) { wasPositivePressed, color ->
if (wasPositivePressed) {
updateDrawColor(color)
}
}
}
}
private fun updatePrimaryActionButtons() { private fun updatePrimaryActionButtons() {
if (crop_image_view.isGone() && currPrimaryAction == PRIMARY_ACTION_CROP_ROTATE) { if (crop_image_view.isGone() && currPrimaryAction == PRIMARY_ACTION_CROP_ROTATE) {
loadCropImageView() loadCropImageView()
@ -439,6 +454,7 @@ class EditActivity : SimpleActivity(), CropImageView.OnCropImageCompleteListener
currentPrimaryActionButton?.applyColorFilter(config.primaryColor) currentPrimaryActionButton?.applyColorFilter(config.primaryColor)
bottom_editor_filter_actions.beVisibleIf(currPrimaryAction == PRIMARY_ACTION_FILTER) bottom_editor_filter_actions.beVisibleIf(currPrimaryAction == PRIMARY_ACTION_FILTER)
bottom_editor_crop_rotate_actions.beVisibleIf(currPrimaryAction == PRIMARY_ACTION_CROP_ROTATE) bottom_editor_crop_rotate_actions.beVisibleIf(currPrimaryAction == PRIMARY_ACTION_CROP_ROTATE)
bottom_editor_draw_actions.beVisibleIf(currPrimaryAction == PRIMARY_ACTION_DRAW)
if (currPrimaryAction == PRIMARY_ACTION_FILTER && bottom_actions_filter_list.adapter == null) { if (currPrimaryAction == PRIMARY_ACTION_FILTER && bottom_actions_filter_list.adapter == null) {
Thread { Thread {
@ -541,6 +557,13 @@ class EditActivity : SimpleActivity(), CropImageView.OnCropImageCompleteListener
primaryActionView?.applyColorFilter(config.primaryColor) primaryActionView?.applyColorFilter(config.primaryColor)
} }
private fun updateDrawColor(color: Int) {
drawColor = color
bottom_draw_color.applyColorFilter(color)
config.lastEditorDrawColor = color
editor_draw_canvas.updateColor(color)
}
private fun resizeImage() { private fun resizeImage() {
val point = getAreaSize() val point = getAreaSize()
if (point == null) { if (point == null) {

View File

@ -453,4 +453,8 @@ class Config(context: Context) : BaseConfig(context) {
var allowOneToOneZoom: Boolean var allowOneToOneZoom: Boolean
get() = prefs.getBoolean(ALLOW_ONE_TO_ONE_ZOOM, false) get() = prefs.getBoolean(ALLOW_ONE_TO_ONE_ZOOM, false)
set(allowOneToOneZoom) = prefs.edit().putBoolean(ALLOW_ONE_TO_ONE_ZOOM, allowOneToOneZoom).apply() set(allowOneToOneZoom) = prefs.edit().putBoolean(ALLOW_ONE_TO_ONE_ZOOM, allowOneToOneZoom).apply()
var lastEditorDrawColor: Int
get() = prefs.getInt(LAST_EDITOR_DRAW_COLOR, primaryColor)
set(lastEditorDrawColor) = prefs.edit().putInt(LAST_EDITOR_DRAW_COLOR, lastEditorDrawColor).apply()
} }

View File

@ -76,6 +76,7 @@ const val LAST_EDITOR_CROP_OTHER_ASPECT_RATIO_Y = "last_editor_crop_other_aspect
const val GROUP_DIRECT_SUBFOLDERS = "group_direct_subfolders" const val GROUP_DIRECT_SUBFOLDERS = "group_direct_subfolders"
const val SHOW_WIDGET_FOLDER_NAME = "show_widget_folder_name" const val SHOW_WIDGET_FOLDER_NAME = "show_widget_folder_name"
const val ALLOW_ONE_TO_ONE_ZOOM = "allow_one_to_one_zoom" const val ALLOW_ONE_TO_ONE_ZOOM = "allow_one_to_one_zoom"
const val LAST_EDITOR_DRAW_COLOR = "last_editor_draw_color"
// slideshow // slideshow
const val SLIDESHOW_INTERVAL = "slideshow_interval" const val SLIDESHOW_INTERVAL = "slideshow_interval"

View File

@ -119,6 +119,10 @@ class EditorDrawCanvas(context: Context, attrs: AttributeSet) : View(context, at
mPaint.strokeWidth = paintOptions.strokeWidth mPaint.strokeWidth = paintOptions.strokeWidth
} }
fun updateColor(newColor: Int) {
mPaintOptions.color = newColor
}
fun updateBackgroundBitmap(bitmap: Bitmap) { fun updateBackgroundBitmap(bitmap: Bitmap) {
backgroundBitmap = bitmap backgroundBitmap = bitmap
invalidate() invalidate()

View File

@ -63,6 +63,14 @@
android:layout_above="@+id/bottom_editor_primary_actions" android:layout_above="@+id/bottom_editor_primary_actions"
android:visibility="gone"/> android:visibility="gone"/>
<include
android:id="@+id/bottom_editor_draw_actions"
layout="@layout/bottom_editor_draw_actions"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="@+id/bottom_editor_primary_actions"
android:visibility="gone"/>
<include <include
android:id="@+id/bottom_editor_primary_actions" android:id="@+id/bottom_editor_primary_actions"
layout="@layout/bottom_editor_primary_actions"/> layout="@layout/bottom_editor_primary_actions"/>

View File

@ -0,0 +1,22 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/bottom_editor_draw_actions_wrapper"
android:layout_width="match_parent"
android:layout_height="@dimen/bottom_actions_height"
android:layout_alignParentBottom="true">
<ImageView
android:id="@+id/bottom_draw_color"
android:layout_width="@dimen/bottom_editor_color_picker_size"
android:layout_height="@dimen/bottom_editor_color_picker_size"
android:layout_marginEnd="@dimen/activity_margin"
android:background="?attr/selectableItemBackgroundBorderless"
android:padding="@dimen/small_margin"
android:src="@drawable/circle_background"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"/>
</androidx.constraintlayout.widget.ConstraintLayout>

View File

@ -12,6 +12,7 @@
<dimen name="instant_change_bar_width">50dp</dimen> <dimen name="instant_change_bar_width">50dp</dimen>
<dimen name="list_view_folder_thumbnail_size">72dp</dimen> <dimen name="list_view_folder_thumbnail_size">72dp</dimen>
<dimen name="bottom_actions_height">64dp</dimen> <dimen name="bottom_actions_height">64dp</dimen>
<dimen name="bottom_editor_color_picker_size">48dp</dimen>
<dimen name="bottom_filters_thumbnail_size">76dp</dimen> <dimen name="bottom_filters_thumbnail_size">76dp</dimen>
<dimen name="bottom_filters_height">90dp</dimen> <dimen name="bottom_filters_height">90dp</dimen>
<dimen name="bottom_editor_actions_shadow_height">180dp</dimen> <dimen name="bottom_editor_actions_shadow_height">180dp</dimen>