From 90f2d5e5df22fc9abeeaa6bac464de7382572423 Mon Sep 17 00:00:00 2001 From: tibbi Date: Sat, 12 Jan 2019 22:48:15 +0100 Subject: [PATCH] allow customizing the editor drawing color --- .../gallery/pro/activities/EditActivity.kt | 23 +++++++++++++++++++ .../gallery/pro/helpers/Config.kt | 4 ++++ .../gallery/pro/helpers/Constants.kt | 1 + .../gallery/pro/views/EditorDrawCanvas.kt | 4 ++++ app/src/main/res/layout/activity_edit.xml | 8 +++++++ .../res/layout/bottom_editor_draw_actions.xml | 22 ++++++++++++++++++ app/src/main/res/values/dimens.xml | 1 + 7 files changed, 63 insertions(+) create mode 100644 app/src/main/res/layout/bottom_editor_draw_actions.xml diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/EditActivity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/EditActivity.kt index 09f43c482..ae3747789 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/EditActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/activities/EditActivity.kt @@ -24,6 +24,7 @@ import com.bumptech.glide.load.engine.GlideException import com.bumptech.glide.request.RequestListener import com.bumptech.glide.request.RequestOptions import com.bumptech.glide.request.target.Target +import com.simplemobiletools.commons.dialogs.ColorPickerDialog import com.simplemobiletools.commons.extensions.* import com.simplemobiletools.commons.helpers.OTG_PATH 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_editor_actions_filter.* 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 java.io.* @@ -73,6 +75,7 @@ class EditActivity : SimpleActivity(), CropImageView.OnCropImageCompleteListener private lateinit var saveUri: Uri private var resizeWidth = 0 private var resizeHeight = 0 + private var drawColor = 0 private var lastOtherAspectRatio: Pair? = null private var currPrimaryAction = PRIMARY_ACTION_NONE private var currCropRotateAction = CROP_ROTATE_NONE @@ -312,6 +315,7 @@ class EditActivity : SimpleActivity(), CropImageView.OnCropImageCompleteListener setupPrimaryActionButtons() setupCropRotateActionButtons() setupAspectRatioButtons() + setupDrawButtons() } private fun setupPrimaryActionButtons() { @@ -416,6 +420,17 @@ class EditActivity : SimpleActivity(), CropImageView.OnCropImageCompleteListener updateAspectRatioButtons() } + private fun setupDrawButtons() { + updateDrawColor(config.lastEditorDrawColor) + bottom_draw_color.setOnClickListener { + ColorPickerDialog(this, drawColor) { wasPositivePressed, color -> + if (wasPositivePressed) { + updateDrawColor(color) + } + } + } + } + private fun updatePrimaryActionButtons() { if (crop_image_view.isGone() && currPrimaryAction == PRIMARY_ACTION_CROP_ROTATE) { loadCropImageView() @@ -439,6 +454,7 @@ class EditActivity : SimpleActivity(), CropImageView.OnCropImageCompleteListener currentPrimaryActionButton?.applyColorFilter(config.primaryColor) bottom_editor_filter_actions.beVisibleIf(currPrimaryAction == PRIMARY_ACTION_FILTER) 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) { Thread { @@ -541,6 +557,13 @@ class EditActivity : SimpleActivity(), CropImageView.OnCropImageCompleteListener 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() { val point = getAreaSize() if (point == null) { diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/helpers/Config.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/helpers/Config.kt index 32467ca4b..ef2b092e7 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/helpers/Config.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/helpers/Config.kt @@ -453,4 +453,8 @@ class Config(context: Context) : BaseConfig(context) { var allowOneToOneZoom: Boolean get() = prefs.getBoolean(ALLOW_ONE_TO_ONE_ZOOM, false) 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() } diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/helpers/Constants.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/helpers/Constants.kt index d96736b78..f84ae3b88 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/helpers/Constants.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/helpers/Constants.kt @@ -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 SHOW_WIDGET_FOLDER_NAME = "show_widget_folder_name" const val ALLOW_ONE_TO_ONE_ZOOM = "allow_one_to_one_zoom" +const val LAST_EDITOR_DRAW_COLOR = "last_editor_draw_color" // slideshow const val SLIDESHOW_INTERVAL = "slideshow_interval" diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/views/EditorDrawCanvas.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/views/EditorDrawCanvas.kt index 0451f0667..2db8dcbaa 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/pro/views/EditorDrawCanvas.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/pro/views/EditorDrawCanvas.kt @@ -119,6 +119,10 @@ class EditorDrawCanvas(context: Context, attrs: AttributeSet) : View(context, at mPaint.strokeWidth = paintOptions.strokeWidth } + fun updateColor(newColor: Int) { + mPaintOptions.color = newColor + } + fun updateBackgroundBitmap(bitmap: Bitmap) { backgroundBitmap = bitmap invalidate() diff --git a/app/src/main/res/layout/activity_edit.xml b/app/src/main/res/layout/activity_edit.xml index 6a675d81c..bef9caf69 100644 --- a/app/src/main/res/layout/activity_edit.xml +++ b/app/src/main/res/layout/activity_edit.xml @@ -63,6 +63,14 @@ android:layout_above="@+id/bottom_editor_primary_actions" android:visibility="gone"/> + + diff --git a/app/src/main/res/layout/bottom_editor_draw_actions.xml b/app/src/main/res/layout/bottom_editor_draw_actions.xml new file mode 100644 index 000000000..4f2a55fbf --- /dev/null +++ b/app/src/main/res/layout/bottom_editor_draw_actions.xml @@ -0,0 +1,22 @@ + + + + + + diff --git a/app/src/main/res/values/dimens.xml b/app/src/main/res/values/dimens.xml index b2135537c..9185f05bb 100644 --- a/app/src/main/res/values/dimens.xml +++ b/app/src/main/res/values/dimens.xml @@ -12,6 +12,7 @@ 50dp 72dp 64dp + 48dp 76dp 90dp 180dp