change lock orientation into forcing different orientation types

This commit is contained in:
tibbi 2018-07-01 14:14:53 +02:00
parent b0653ae2cc
commit 712e4c02db
6 changed files with 43 additions and 20 deletions

View File

@ -47,7 +47,7 @@ ext {
} }
dependencies { 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.theartofdev.edmodo:android-image-cropper:2.7.0'
implementation 'com.android.support:multidex:1.0.3' implementation 'com.android.support:multidex:1.0.3'
implementation 'it.sephiroth.android.exif:library:1.0.1' implementation 'it.sephiroth.android.exif:library:1.0.1'

View File

@ -13,6 +13,7 @@ import android.graphics.BitmapFactory
import android.graphics.Color import android.graphics.Color
import android.graphics.Matrix import android.graphics.Matrix
import android.graphics.drawable.ColorDrawable import android.graphics.drawable.ColorDrawable
import android.graphics.drawable.Drawable
import android.media.ExifInterface import android.media.ExifInterface
import android.net.Uri import android.net.Uri
import android.os.Build 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_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_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_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_change_orientation).isVisible = mRotationDegrees == 0 && visibleBottomActions and BOTTOM_ACTION_CHANGE_ORIENTATION == 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).icon = getChangeOrientationIcon()
findItem(R.id.menu_rotate).setShowAsAction( findItem(R.id.menu_rotate).setShowAsAction(
if (mRotationDegrees != 0) { if (mRotationDegrees != 0) {
MenuItem.SHOW_AS_ACTION_ALWAYS 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_add_to_favorites -> toggleFavorite()
R.id.menu_remove_from_favorites -> toggleFavorite() R.id.menu_remove_from_favorites -> toggleFavorite()
R.id.menu_restore_file -> restoreFile() 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_save_as -> saveImageAs()
R.id.menu_settings -> launchSettings() R.id.menu_settings -> launchSettings()
else -> return super.onOptionsItemSelected(item) else -> return super.onOptionsItemSelected(item)
@ -544,16 +547,23 @@ class ViewPagerActivity : SimpleActivity(), ViewPager.OnPageChangeListener, View
supportInvalidateOptionsMenu() supportInvalidateOptionsMenu()
} }
private fun toggleLockOrientation() { private fun toggleOrientation(orientation: Int) {
mIsOrientationLocked = !mIsOrientationLocked requestedOrientation = orientation
if (mIsOrientationLocked) { mIsOrientationLocked = orientation == ActivityInfo.SCREEN_ORIENTATION_PORTRAIT || orientation == ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) { invalidateOptionsMenu()
requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_LOCKED }
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 { } else {
setupRotation() R.drawable.ic_orientation_auto
} }
invalidateOptionsMenu() return resources.getDrawable(drawable)
} }
private fun saveImageAs() { 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 { bottom_lock_orientation.setOnClickListener {
if (bottom_actions.alpha == 1f) { if (bottom_actions.alpha == 1f) {

View File

@ -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_delete.isChecked = actions and BOTTOM_ACTION_DELETE != 0
manage_bottom_actions_rotate.isChecked = actions and BOTTOM_ACTION_ROTATE != 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_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_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_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 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 result += BOTTOM_ACTION_ROTATE
if (manage_bottom_actions_properties.isChecked) if (manage_bottom_actions_properties.isChecked)
result += BOTTOM_ACTION_PROPERTIES result += BOTTOM_ACTION_PROPERTIES
if (manage_bottom_actions_lock_orientation.isChecked) if (manage_bottom_actions_change_orientation.isChecked)
result += BOTTOM_ACTION_LOCK_ORIENTATION result += BOTTOM_ACTION_CHANGE_ORIENTATION
if (manage_bottom_actions_slideshow.isChecked) if (manage_bottom_actions_slideshow.isChecked)
result += BOTTOM_ACTION_SLIDESHOW result += BOTTOM_ACTION_SLIDESHOW
if (manage_bottom_actions_show_on_map.isChecked) if (manage_bottom_actions_show_on_map.isChecked)

View File

@ -138,7 +138,7 @@ const val BOTTOM_ACTION_SHARE = 4
const val BOTTOM_ACTION_DELETE = 8 const val BOTTOM_ACTION_DELETE = 8
const val BOTTOM_ACTION_ROTATE = 16 const val BOTTOM_ACTION_ROTATE = 16
const val BOTTOM_ACTION_PROPERTIES = 32 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_SLIDESHOW = 128
const val BOTTOM_ACTION_SHOW_ON_MAP = 256 const val BOTTOM_ACTION_SHOW_ON_MAP = 256
const val BOTTOM_ACTION_TOGGLE_VISIBILITY = 512 const val BOTTOM_ACTION_TOGGLE_VISIBILITY = 512

View File

@ -63,7 +63,7 @@
android:text="@string/properties"/> android:text="@string/properties"/>
<com.simplemobiletools.commons.views.MyAppCompatCheckbox <com.simplemobiletools.commons.views.MyAppCompatCheckbox
android:id="@+id/manage_bottom_actions_lock_orientation" android:id="@+id/manage_bottom_actions_change_orientation"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:paddingBottom="@dimen/activity_margin" android:paddingBottom="@dimen/activity_margin"

View File

@ -49,9 +49,22 @@
android:title="@string/restore_this_file" android:title="@string/restore_this_file"
app:showAsAction="never"/> app:showAsAction="never"/>
<item <item
android:id="@+id/menu_lock_orientation" android:id="@+id/menu_change_orientation"
android:title="@string/lock_orientation" android:icon="@drawable/ic_orientation_auto"
app:showAsAction="never"/> android:title="@string/change_orientation"
app:showAsAction="ifRoom">
<menu>
<item
android:id="@+id/menu_force_portrait"
android:title="@string/force_portrait"/>
<item
android:id="@+id/menu_force_landscape"
android:title="@string/force_landscape"/>
<item
android:id="@+id/menu_default_orientation"
android:title="@string/use_default_orientation"/>
</menu>
</item>
<item <item
android:id="@+id/menu_copy_to" android:id="@+id/menu_copy_to"
android:title="@string/copy_to" android:title="@string/copy_to"