diff --git a/app/build.gradle b/app/build.gradle index 218b725d2..f92e53fef 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -47,7 +47,7 @@ ext { } dependencies { - implementation 'com.simplemobiletools:commons:4.3.13' + implementation 'com.simplemobiletools:commons:4.3.15' implementation 'com.theartofdev.edmodo:android-image-cropper:2.7.0' implementation 'com.android.support:multidex:1.0.3' implementation 'it.sephiroth.android.exif:library:1.0.1' diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/ViewPagerActivity.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/ViewPagerActivity.kt index 7794a1c91..36a35fe4f 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/activities/ViewPagerActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/activities/ViewPagerActivity.kt @@ -13,6 +13,7 @@ import android.graphics.BitmapFactory import android.graphics.Color import android.graphics.Matrix import android.graphics.drawable.ColorDrawable +import android.graphics.drawable.Drawable import android.media.ExifInterface import android.net.Uri import android.os.Build @@ -299,8 +300,8 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View findItem(R.id.menu_add_to_favorites).isVisible = !currentMedium.isFavorite && visibleBottomActions and BOTTOM_ACTION_TOGGLE_FAVORITE == 0 findItem(R.id.menu_remove_from_favorites).isVisible = currentMedium.isFavorite && visibleBottomActions and BOTTOM_ACTION_TOGGLE_FAVORITE == 0 findItem(R.id.menu_restore_file).isVisible = currentMedium.path.startsWith(filesDir.toString()) - findItem(R.id.menu_lock_orientation).isVisible = mRotationDegrees == 0 && visibleBottomActions and BOTTOM_ACTION_ROTATE == 0 - findItem(R.id.menu_lock_orientation).title = getString(if (mIsOrientationLocked) R.string.unlock_orientation else R.string.lock_orientation) + findItem(R.id.menu_change_orientation).isVisible = mRotationDegrees == 0 && visibleBottomActions and BOTTOM_ACTION_CHANGE_ORIENTATION == 0 + findItem(R.id.menu_change_orientation).icon = getChangeOrientationIcon() findItem(R.id.menu_rotate).setShowAsAction( if (mRotationDegrees != 0) { MenuItem.SHOW_AS_ACTION_ALWAYS @@ -339,7 +340,9 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View R.id.menu_add_to_favorites -> toggleFavorite() R.id.menu_remove_from_favorites -> toggleFavorite() R.id.menu_restore_file -> restoreFile() - R.id.menu_lock_orientation -> toggleLockOrientation() + R.id.menu_force_portrait -> toggleOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT) + R.id.menu_force_landscape -> toggleOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE) + R.id.menu_default_orientation -> toggleOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) R.id.menu_save_as -> saveImageAs() R.id.menu_settings -> launchSettings() else -> return super.onOptionsItemSelected(item) @@ -544,16 +547,23 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View supportInvalidateOptionsMenu() } - private fun toggleLockOrientation() { - mIsOrientationLocked = !mIsOrientationLocked - if (mIsOrientationLocked) { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) { - requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_LOCKED + private fun toggleOrientation(orientation: Int) { + requestedOrientation = orientation + mIsOrientationLocked = orientation == ActivityInfo.SCREEN_ORIENTATION_PORTRAIT || orientation == ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE + invalidateOptionsMenu() + } + + private fun getChangeOrientationIcon(): Drawable { + val drawable = if (mIsOrientationLocked) { + if (requestedOrientation == ActivityInfo.SCREEN_ORIENTATION_PORTRAIT) { + R.drawable.ic_orientation_portrait + } else { + R.drawable.ic_orientation_landscape } } else { - setupRotation() + R.drawable.ic_orientation_auto } - invalidateOptionsMenu() + return resources.getDrawable(drawable) } private fun saveImageAs() { @@ -809,7 +819,7 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View } } - bottom_lock_orientation.beVisibleIf(visibleBottomActions and BOTTOM_ACTION_LOCK_ORIENTATION != 0) + bottom_lock_orientation.beVisibleIf(visibleBottomActions and BOTTOM_ACTION_CHANGE_ORIENTATION != 0) bottom_lock_orientation.setOnClickListener { if (bottom_actions.alpha == 1f) { diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/dialogs/ManageBottomActionsDialog.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/dialogs/ManageBottomActionsDialog.kt index 3236ad750..a9ef79936 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/dialogs/ManageBottomActionsDialog.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/dialogs/ManageBottomActionsDialog.kt @@ -20,7 +20,7 @@ class ManageBottomActionsDialog(val activity: BaseSimpleActivity, val callback: manage_bottom_actions_delete.isChecked = actions and BOTTOM_ACTION_DELETE != 0 manage_bottom_actions_rotate.isChecked = actions and BOTTOM_ACTION_ROTATE != 0 manage_bottom_actions_properties.isChecked = actions and BOTTOM_ACTION_PROPERTIES != 0 - manage_bottom_actions_lock_orientation.isChecked = actions and BOTTOM_ACTION_LOCK_ORIENTATION != 0 + manage_bottom_actions_change_orientation.isChecked = actions and BOTTOM_ACTION_CHANGE_ORIENTATION != 0 manage_bottom_actions_slideshow.isChecked = actions and BOTTOM_ACTION_PROPERTIES != 0 manage_bottom_actions_show_on_map.isChecked = actions and BOTTOM_ACTION_SHOW_ON_MAP != 0 manage_bottom_actions_toggle_visibility.isChecked = actions and BOTTOM_ACTION_TOGGLE_VISIBILITY != 0 @@ -50,8 +50,8 @@ class ManageBottomActionsDialog(val activity: BaseSimpleActivity, val callback: result += BOTTOM_ACTION_ROTATE if (manage_bottom_actions_properties.isChecked) result += BOTTOM_ACTION_PROPERTIES - if (manage_bottom_actions_lock_orientation.isChecked) - result += BOTTOM_ACTION_LOCK_ORIENTATION + if (manage_bottom_actions_change_orientation.isChecked) + result += BOTTOM_ACTION_CHANGE_ORIENTATION if (manage_bottom_actions_slideshow.isChecked) result += BOTTOM_ACTION_SLIDESHOW if (manage_bottom_actions_show_on_map.isChecked) diff --git a/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/Constants.kt b/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/Constants.kt index 43db43df9..fdde91fc2 100644 --- a/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/Constants.kt +++ b/app/src/main/kotlin/com/simplemobiletools/gallery/helpers/Constants.kt @@ -138,7 +138,7 @@ const val BOTTOM_ACTION_SHARE = 4 const val BOTTOM_ACTION_DELETE = 8 const val BOTTOM_ACTION_ROTATE = 16 const val BOTTOM_ACTION_PROPERTIES = 32 -const val BOTTOM_ACTION_LOCK_ORIENTATION = 64 +const val BOTTOM_ACTION_CHANGE_ORIENTATION = 64 const val BOTTOM_ACTION_SLIDESHOW = 128 const val BOTTOM_ACTION_SHOW_ON_MAP = 256 const val BOTTOM_ACTION_TOGGLE_VISIBILITY = 512 diff --git a/app/src/main/res/layout/dialog_manage_bottom_actions.xml b/app/src/main/res/layout/dialog_manage_bottom_actions.xml index 41af0399c..0e4bd1dcf 100644 --- a/app/src/main/res/layout/dialog_manage_bottom_actions.xml +++ b/app/src/main/res/layout/dialog_manage_bottom_actions.xml @@ -63,7 +63,7 @@ android:text="@string/properties"/> + android:id="@+id/menu_change_orientation" + android:icon="@drawable/ic_orientation_auto" + android:title="@string/change_orientation" + app:showAsAction="ifRoom"> + + + + + +