mirror of
https://github.com/FossifyOrg/Gallery.git
synced 2024-11-22 20:48:00 +01:00
use bottom actions at Set Wallpaper intent too
This commit is contained in:
parent
ef40875d72
commit
f8cf95991f
4 changed files with 67 additions and 30 deletions
|
@ -16,7 +16,8 @@ import com.simplemobiletools.commons.helpers.isNougatPlus
|
|||
import com.simplemobiletools.commons.models.RadioItem
|
||||
import com.simplemobiletools.gallery.R
|
||||
import com.theartofdev.edmodo.cropper.CropImageView
|
||||
import kotlinx.android.synthetic.main.activity_edit.*
|
||||
import kotlinx.android.synthetic.main.activity_set_wallpaper.*
|
||||
import kotlinx.android.synthetic.main.bottom_set_wallpaper_actions.*
|
||||
|
||||
class SetWallpaperActivity : SimpleActivity(), CropImageView.OnCropImageCompleteListener {
|
||||
private val PICK_IMAGE = 1
|
||||
|
@ -39,6 +40,7 @@ class SetWallpaperActivity : SimpleActivity(), CropImageView.OnCropImageComplete
|
|||
}
|
||||
|
||||
handleImage(intent)
|
||||
setupBottomActions()
|
||||
}
|
||||
|
||||
private fun handleImage(intent: Intent) {
|
||||
|
@ -58,27 +60,30 @@ class SetWallpaperActivity : SimpleActivity(), CropImageView.OnCropImageComplete
|
|||
setupAspectRatio()
|
||||
}
|
||||
|
||||
private fun setupBottomActions() {
|
||||
bottom_set_wallpaper_aspect_ratio.setOnClickListener {
|
||||
changeAspectRatio(!isLandscapeRatio)
|
||||
}
|
||||
|
||||
bottom_set_wallpaper_rotate.setOnClickListener {
|
||||
crop_image_view.rotateImage(90)
|
||||
}
|
||||
}
|
||||
|
||||
private fun setupAspectRatio() {
|
||||
val wallpaperWidth = if (isLandscapeRatio) wallpaperManager.desiredMinimumWidth else wallpaperManager.desiredMinimumWidth / 2
|
||||
crop_image_view.setAspectRatio(wallpaperWidth, wallpaperManager.desiredMinimumHeight)
|
||||
bottom_set_wallpaper_aspect_ratio.setImageResource(if (isLandscapeRatio) R.drawable.ic_minimize else R.drawable.ic_maximize)
|
||||
}
|
||||
|
||||
override fun onCreateOptionsMenu(menu: Menu): Boolean {
|
||||
menuInflater.inflate(R.menu.menu_set_wallpaper, menu)
|
||||
|
||||
menu.apply {
|
||||
findItem(R.id.portrait_aspect_ratio).isVisible = isLandscapeRatio
|
||||
findItem(R.id.landscape_aspect_ratio).isVisible = !isLandscapeRatio
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
||||
when (item.itemId) {
|
||||
R.id.save -> confirmWallpaper()
|
||||
R.id.rotate -> crop_image_view.rotateImage(90)
|
||||
R.id.portrait_aspect_ratio -> changeAspectRatio(false)
|
||||
R.id.landscape_aspect_ratio -> changeAspectRatio(true)
|
||||
else -> return super.onOptionsItemSelected(item)
|
||||
}
|
||||
return true
|
||||
|
@ -87,7 +92,6 @@ class SetWallpaperActivity : SimpleActivity(), CropImageView.OnCropImageComplete
|
|||
private fun changeAspectRatio(isLandscape: Boolean) {
|
||||
isLandscapeRatio = isLandscape
|
||||
setupAspectRatio()
|
||||
invalidateOptionsMenu()
|
||||
}
|
||||
|
||||
@SuppressLint("InlinedApi")
|
||||
|
|
|
@ -1,9 +1,20 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<com.theartofdev.edmodo.cropper.CropImageView
|
||||
<RelativeLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:id="@+id/crop_image_view"
|
||||
android:id="@+id/activity_set_wallpaper_holder"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
app:cropBackgroundColor="@color/crop_image_view_background"
|
||||
app:cropInitialCropWindowPaddingRatio="0"/>
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<com.theartofdev.edmodo.cropper.CropImageView
|
||||
android:id="@+id/crop_image_view"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
app:cropBackgroundColor="@color/crop_image_view_background"
|
||||
app:cropInitialCropWindowPaddingRatio="0"/>
|
||||
|
||||
<include
|
||||
android:id="@+id/bottom_set_wallpaper_actions"
|
||||
layout="@layout/bottom_set_wallpaper_actions"/>
|
||||
|
||||
</RelativeLayout>
|
||||
|
|
37
app/src/main/res/layout/bottom_set_wallpaper_actions.xml
Normal file
37
app/src/main/res/layout/bottom_set_wallpaper_actions.xml
Normal 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_set_wallpaper_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_set_wallpaper_aspect_ratio"
|
||||
style="@style/MyBorderlessBackgroundStyle"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:padding="@dimen/normal_margin"
|
||||
android:src="@drawable/ic_minimize"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toStartOf="@+id/bottom_set_wallpaper_rotate"
|
||||
app:layout_constraintHorizontal_bias="0.5"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent"/>
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/bottom_set_wallpaper_rotate"
|
||||
style="@style/MyBorderlessBackgroundStyle"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:padding="@dimen/normal_margin"
|
||||
android:src="@drawable/ic_rotate_right"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintHorizontal_bias="0.5"
|
||||
app:layout_constraintStart_toEndOf="@+id/bottom_set_wallpaper_aspect_ratio"
|
||||
app:layout_constraintTop_toTopOf="parent"/>
|
||||
|
||||
</android.support.constraint.ConstraintLayout>
|
|
@ -6,19 +6,4 @@
|
|||
android:icon="@drawable/ic_check"
|
||||
android:title="@string/save"
|
||||
app:showAsAction="ifRoom"/>
|
||||
<item
|
||||
android:id="@+id/portrait_aspect_ratio"
|
||||
android:icon="@drawable/ic_minimize"
|
||||
android:title="@string/portrait_aspect_ratio"
|
||||
app:showAsAction="ifRoom"/>
|
||||
<item
|
||||
android:id="@+id/landscape_aspect_ratio"
|
||||
android:icon="@drawable/ic_maximize"
|
||||
android:title="@string/landscape_aspect_ratio"
|
||||
app:showAsAction="ifRoom"/>
|
||||
<item
|
||||
android:id="@+id/rotate"
|
||||
android:icon="@drawable/ic_rotate_right"
|
||||
android:title="@string/rotate"
|
||||
app:showAsAction="ifRoom"/>
|
||||
</menu>
|
||||
|
|
Loading…
Reference in a new issue