add some more buttons at the bottom of the Editor

This commit is contained in:
tibbi 2018-07-19 20:12:03 +02:00
parent 8f8baecc5f
commit baec75dc62
8 changed files with 112 additions and 21 deletions

View file

@ -24,7 +24,8 @@ import com.simplemobiletools.gallery.extensions.openEditor
import com.theartofdev.edmodo.cropper.CropImageView import com.theartofdev.edmodo.cropper.CropImageView
import kotlinx.android.synthetic.main.activity_edit.* 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.* import kotlinx.android.synthetic.main.bottom_editor_crop_rotate_actions.*
import kotlinx.android.synthetic.main.bottom_editor_primary_actions.*
import java.io.* import java.io.*
class EditActivity : SimpleActivity(), CropImageView.OnCropImageCompleteListener { class EditActivity : SimpleActivity(), CropImageView.OnCropImageCompleteListener {
@ -38,17 +39,22 @@ class EditActivity : SimpleActivity(), CropImageView.OnCropImageCompleteListener
private val ASPECT_RATIO_SIXTEEN_NINE = 3 private val ASPECT_RATIO_SIXTEEN_NINE = 3
// constants for bottom primary action groups // constants for bottom primary action groups
private val PRIMARY_NONE = 0 private val PRIMARY_ACTION_NONE = 0
private val PRIMARY_ASPECT_RATIO = 1 private val PRIMARY_ACTION_FILTER = 1
private val PRIMARY_ACTION_CROP_ROTATE = 2
private val CROP_ROTATE_NONE = 0
private val CROP_ROTATE_ASPECT_RATIO = 1
private lateinit var uri: Uri private lateinit var uri: Uri
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 currPrimaryAction = PRIMARY_NONE private var currPrimaryAction = PRIMARY_ACTION_NONE
private var currCropRotateAction = CROP_ROTATE_NONE
private var currAspectRatio = ASPECT_RATIO_FREE
private var isCropIntent = false private var isCropIntent = false
private var isEditingWithThirdParty = false private var isEditingWithThirdParty = false
private var currentAspectRatio = ASPECT_RATIO_FREE
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
@ -104,14 +110,13 @@ class EditActivity : SimpleActivity(), CropImageView.OnCropImageCompleteListener
guidelines = CropImageView.Guidelines.ON guidelines = CropImageView.Guidelines.ON
if (isCropIntent && shouldCropSquare()) { if (isCropIntent && shouldCropSquare()) {
currentAspectRatio = ASPECT_RATIO_ONE_ONE currAspectRatio = ASPECT_RATIO_ONE_ONE
setFixedAspectRatio(true) setFixedAspectRatio(true)
bottom_aspect_ratio.beGone() bottom_aspect_ratio.beGone()
} }
} }
setupBottomActions() setupBottomActions()
bottom_aspect_ratio.performClick()
} }
override fun onResume() { override fun onResume() {
@ -142,10 +147,31 @@ class EditActivity : SimpleActivity(), CropImageView.OnCropImageCompleteListener
private fun setupBottomActions() { private fun setupBottomActions() {
setupPrimaryActionButtons() setupPrimaryActionButtons()
setupCropRotateActionButtons()
setupAspectRatioButtons() setupAspectRatioButtons()
} }
private fun setupPrimaryActionButtons() { private fun setupPrimaryActionButtons() {
bottom_primary_filter.setOnClickListener {
currPrimaryAction = if (currPrimaryAction == PRIMARY_ACTION_FILTER) {
PRIMARY_ACTION_NONE
} else {
PRIMARY_ACTION_FILTER
}
updatePrimaryActionButtons()
}
bottom_primary_crop_rotate.setOnClickListener {
currPrimaryAction = if (currPrimaryAction == PRIMARY_ACTION_CROP_ROTATE) {
PRIMARY_ACTION_NONE
} else {
PRIMARY_ACTION_CROP_ROTATE
}
updatePrimaryActionButtons()
}
}
private fun setupCropRotateActionButtons() {
bottom_rotate.setOnClickListener { bottom_rotate.setOnClickListener {
crop_image_view.rotateImage(90) crop_image_view.rotateImage(90)
} }
@ -164,16 +190,16 @@ class EditActivity : SimpleActivity(), CropImageView.OnCropImageCompleteListener
} }
bottom_aspect_ratio.setOnClickListener { bottom_aspect_ratio.setOnClickListener {
currPrimaryAction = if (currPrimaryAction == PRIMARY_ASPECT_RATIO) { currCropRotateAction = if (currCropRotateAction == CROP_ROTATE_ASPECT_RATIO) {
crop_image_view.guidelines = CropImageView.Guidelines.OFF crop_image_view.guidelines = CropImageView.Guidelines.OFF
bottom_aspect_ratios.beGone() bottom_aspect_ratios.beGone()
PRIMARY_NONE CROP_ROTATE_NONE
} else { } else {
crop_image_view.guidelines = CropImageView.Guidelines.ON crop_image_view.guidelines = CropImageView.Guidelines.ON
bottom_aspect_ratios.beVisible() bottom_aspect_ratios.beVisible()
PRIMARY_ASPECT_RATIO CROP_ROTATE_ASPECT_RATIO
} }
updatePrimaryActionButtons() updateCropRotateActionButtons()
} }
} }
@ -196,8 +222,29 @@ class EditActivity : SimpleActivity(), CropImageView.OnCropImageCompleteListener
updateAspectRatioButtons() updateAspectRatioButtons()
} }
private fun updatePrimaryActionButtons() {
arrayOf(bottom_primary_filter, bottom_primary_crop_rotate).forEach {
it.applyColorFilter(Color.WHITE)
}
val currentPrimaryActionButton = when (currPrimaryAction) {
PRIMARY_ACTION_FILTER -> bottom_primary_filter
PRIMARY_ACTION_CROP_ROTATE -> bottom_primary_crop_rotate
else -> null
}
currentPrimaryActionButton?.applyColorFilter(config.primaryColor)
if (currPrimaryAction == PRIMARY_ACTION_CROP_ROTATE) {
bottom_editor_edit_actions.beVisible()
} else {
bottom_aspect_ratios.beGone()
bottom_editor_edit_actions.beGone()
currCropRotateAction = CROP_ROTATE_NONE
}
}
private fun updateAspectRatio(aspectRatio: Int) { private fun updateAspectRatio(aspectRatio: Int) {
currentAspectRatio = aspectRatio currAspectRatio = aspectRatio
updateAspectRatioButtons() updateAspectRatioButtons()
crop_image_view.apply { crop_image_view.apply {
@ -220,7 +267,7 @@ class EditActivity : SimpleActivity(), CropImageView.OnCropImageCompleteListener
it.setTextColor(Color.WHITE) it.setTextColor(Color.WHITE)
} }
val currentAspectRatioButton = when (currentAspectRatio) { val currentAspectRatioButton = when (currAspectRatio) {
ASPECT_RATIO_FREE -> bottom_aspect_ratio_free ASPECT_RATIO_FREE -> bottom_aspect_ratio_free
ASPECT_RATIO_ONE_ONE -> bottom_aspect_ratio_one_one ASPECT_RATIO_ONE_ONE -> bottom_aspect_ratio_one_one
ASPECT_RATIO_FOUR_THREE -> bottom_aspect_ratio_four_three ASPECT_RATIO_FOUR_THREE -> bottom_aspect_ratio_four_three
@ -230,13 +277,13 @@ class EditActivity : SimpleActivity(), CropImageView.OnCropImageCompleteListener
currentAspectRatioButton.setTextColor(config.primaryColor) currentAspectRatioButton.setTextColor(config.primaryColor)
} }
private fun updatePrimaryActionButtons() { private fun updateCropRotateActionButtons() {
arrayOf(bottom_aspect_ratio).forEach { arrayOf(bottom_aspect_ratio).forEach {
it.applyColorFilter(Color.WHITE) it.applyColorFilter(Color.WHITE)
} }
val primaryActionView = when (currPrimaryAction) { val primaryActionView = when (currCropRotateAction) {
PRIMARY_ASPECT_RATIO -> bottom_aspect_ratio CROP_ROTATE_ASPECT_RATIO -> bottom_aspect_ratio
else -> null else -> null
} }

Binary file not shown.

After

Width:  |  Height:  |  Size: 292 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 324 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 473 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 585 B

View file

@ -19,11 +19,19 @@
layout="@layout/bottom_actions_aspect_ratio" layout="@layout/bottom_actions_aspect_ratio"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_above="@+id/bottom_editor_actions" android:layout_above="@+id/bottom_editor_edit_actions"
android:visibility="gone"/> android:visibility="gone"/>
<include <include
android:id="@+id/bottom_editor_actions" android:id="@+id/bottom_editor_edit_actions"
layout="@layout/bottom_editor_actions"/> layout="@layout/bottom_editor_crop_rotate_actions"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="@+id/bottom_editor_primary_actions"
android:visibility="gone"/>
<include
android:id="@+id/bottom_editor_primary_actions"
layout="@layout/bottom_editor_primary_actions"/>
</RelativeLayout> </RelativeLayout>

View file

@ -5,8 +5,7 @@
android:id="@+id/bottom_editor_actions_wrapper" android:id="@+id/bottom_editor_actions_wrapper"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="@dimen/bottom_actions_height" android:layout_height="@dimen/bottom_actions_height"
android:layout_alignParentBottom="true" android:layout_alignParentBottom="true">
android:background="@drawable/gradient_background_lighter">
<ImageView <ImageView
android:id="@+id/bottom_rotate" android:id="@+id/bottom_rotate"

View file

@ -0,0 +1,37 @@
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/bottom_editor_primary_actions_wrapper"
android:layout_width="match_parent"
android:layout_height="@dimen/bottom_actions_height"
android:layout_alignParentBottom="true"
android:background="@drawable/gradient_background_lighter">
<ImageView
android:id="@+id/bottom_primary_filter"
style="@style/MyBorderlessBackgroundStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="@dimen/normal_margin"
android:src="@drawable/ic_photo_filter"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/bottom_primary_crop_rotate"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"/>
<ImageView
android:id="@+id/bottom_primary_crop_rotate"
style="@style/MyBorderlessBackgroundStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="@dimen/normal_margin"
android:src="@drawable/ic_crop_rotate"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toEndOf="@+id/bottom_primary_filter"
app:layout_constraintTop_toTopOf="parent"/>
</android.support.constraint.ConstraintLayout>