disable flinging on preview view
- only change camera mode when fling happens on the bottom tab - so zoom gestures do not interfere with the fling
This commit is contained in:
parent
122841b641
commit
a20c7137bb
|
@ -1,5 +1,6 @@
|
||||||
package com.simplemobiletools.camera.activities
|
package com.simplemobiletools.camera.activities
|
||||||
|
|
||||||
|
import android.annotation.SuppressLint
|
||||||
import android.app.Activity
|
import android.app.Activity
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.content.res.ColorStateList
|
import android.content.res.ColorStateList
|
||||||
|
@ -39,16 +40,24 @@ import com.simplemobiletools.camera.views.FocusCircleView
|
||||||
import com.simplemobiletools.commons.extensions.*
|
import com.simplemobiletools.commons.extensions.*
|
||||||
import com.simplemobiletools.commons.helpers.*
|
import com.simplemobiletools.commons.helpers.*
|
||||||
import com.simplemobiletools.commons.models.Release
|
import com.simplemobiletools.commons.models.Release
|
||||||
import kotlinx.android.synthetic.main.activity_main.*
|
|
||||||
import kotlinx.android.synthetic.main.layout_flash.*
|
|
||||||
import kotlinx.android.synthetic.main.layout_top.*
|
|
||||||
import java.util.concurrent.TimeUnit
|
import java.util.concurrent.TimeUnit
|
||||||
|
import kotlin.math.abs
|
||||||
|
import kotlinx.android.synthetic.main.activity_main.*
|
||||||
|
import kotlinx.android.synthetic.main.layout_flash.flash_auto
|
||||||
|
import kotlinx.android.synthetic.main.layout_flash.flash_off
|
||||||
|
import kotlinx.android.synthetic.main.layout_flash.flash_on
|
||||||
|
import kotlinx.android.synthetic.main.layout_flash.flash_toggle_group
|
||||||
|
import kotlinx.android.synthetic.main.layout_top.change_resolution
|
||||||
|
import kotlinx.android.synthetic.main.layout_top.default_icons
|
||||||
|
import kotlinx.android.synthetic.main.layout_top.settings
|
||||||
|
import kotlinx.android.synthetic.main.layout_top.toggle_flash
|
||||||
|
|
||||||
class MainActivity : SimpleActivity(), PhotoProcessor.MediaSavedListener, CameraXPreviewListener {
|
class MainActivity : SimpleActivity(), PhotoProcessor.MediaSavedListener, CameraXPreviewListener {
|
||||||
private companion object {
|
private companion object {
|
||||||
const val CAPTURE_ANIMATION_DURATION = 500L
|
const val CAPTURE_ANIMATION_DURATION = 500L
|
||||||
const val PHOTO_MODE_INDEX = 1
|
const val PHOTO_MODE_INDEX = 1
|
||||||
const val VIDEO_MODE_INDEX = 0
|
const val VIDEO_MODE_INDEX = 0
|
||||||
|
private const val MIN_SWIPE_DISTANCE_X = 100
|
||||||
}
|
}
|
||||||
|
|
||||||
lateinit var mTimerHandler: Handler
|
lateinit var mTimerHandler: Handler
|
||||||
|
@ -288,6 +297,7 @@ class MainActivity : SimpleActivity(), PhotoProcessor.MediaSavedListener, Camera
|
||||||
private fun initializeCamera() {
|
private fun initializeCamera() {
|
||||||
setContentView(R.layout.activity_main)
|
setContentView(R.layout.activity_main)
|
||||||
initButtons()
|
initButtons()
|
||||||
|
initModeSwitcher()
|
||||||
defaultScene = Scene(top_options, default_icons)
|
defaultScene = Scene(top_options, default_icons)
|
||||||
flashModeScene = Scene(top_options, flash_toggle_group)
|
flashModeScene = Scene(top_options, flash_toggle_group)
|
||||||
|
|
||||||
|
@ -376,6 +386,43 @@ class MainActivity : SimpleActivity(), PhotoProcessor.MediaSavedListener, Camera
|
||||||
flash_auto.setOnClickListener { selectFlashMode(FLASH_AUTO) }
|
flash_auto.setOnClickListener { selectFlashMode(FLASH_AUTO) }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressLint("ClickableViewAccessibility")
|
||||||
|
private fun initModeSwitcher(){
|
||||||
|
val gestureDetector = GestureDetector(this, object : GestureDetector.SimpleOnGestureListener() {
|
||||||
|
override fun onFling(event1: MotionEvent, event2: MotionEvent, velocityX: Float, velocityY: Float): Boolean {
|
||||||
|
val deltaX = event1.x - event2.x
|
||||||
|
val deltaXAbs = abs(deltaX)
|
||||||
|
|
||||||
|
if (deltaXAbs >= MIN_SWIPE_DISTANCE_X) {
|
||||||
|
if (deltaX > 0) {
|
||||||
|
onSwipeLeft()
|
||||||
|
} else {
|
||||||
|
onSwipeRight()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
camera_mode_tab.setOnTouchListener { _, event ->
|
||||||
|
gestureDetector.onTouchEvent(event)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun onSwipeLeft() {
|
||||||
|
if (!is3rdPartyIntent() && camera_mode_tab.isVisible()) {
|
||||||
|
selectPhotoTab(triggerListener = true)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun onSwipeRight() {
|
||||||
|
if (!is3rdPartyIntent() && camera_mode_tab.isVisible()) {
|
||||||
|
selectVideoTab(triggerListener = true)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
private fun selectFlashMode(flashMode: Int) {
|
private fun selectFlashMode(flashMode: Int) {
|
||||||
closeOptions()
|
closeOptions()
|
||||||
mPreview?.setFlashlightState(flashMode)
|
mPreview?.setFlashlightState(flashMode)
|
||||||
|
@ -715,18 +762,6 @@ class MainActivity : SimpleActivity(), PhotoProcessor.MediaSavedListener, Camera
|
||||||
mFocusCircleView.drawFocusCircle(xPos, yPos)
|
mFocusCircleView.drawFocusCircle(xPos, yPos)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onSwipeLeft() {
|
|
||||||
if (!is3rdPartyIntent() && camera_mode_tab.isVisible()) {
|
|
||||||
selectPhotoTab(triggerListener = true)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onSwipeRight() {
|
|
||||||
if (!is3rdPartyIntent() && camera_mode_tab.isVisible()) {
|
|
||||||
selectVideoTab(triggerListener = true)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onTouchPreview() {
|
override fun onTouchPreview() {
|
||||||
closeOptions()
|
closeOptions()
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,7 +31,6 @@ import com.simplemobiletools.camera.models.MySize
|
||||||
import com.simplemobiletools.camera.models.ResolutionOption
|
import com.simplemobiletools.camera.models.ResolutionOption
|
||||||
import com.simplemobiletools.commons.extensions.toast
|
import com.simplemobiletools.commons.extensions.toast
|
||||||
import com.simplemobiletools.commons.helpers.ensureBackgroundThread
|
import com.simplemobiletools.commons.helpers.ensureBackgroundThread
|
||||||
import kotlin.math.abs
|
|
||||||
|
|
||||||
class CameraXPreview(
|
class CameraXPreview(
|
||||||
private val activity: AppCompatActivity,
|
private val activity: AppCompatActivity,
|
||||||
|
@ -46,7 +45,6 @@ class CameraXPreview(
|
||||||
// Auto focus is 1/6 of the area.
|
// Auto focus is 1/6 of the area.
|
||||||
private const val AF_SIZE = 1.0f / 6.0f
|
private const val AF_SIZE = 1.0f / 6.0f
|
||||||
private const val AE_SIZE = AF_SIZE * 1.5f
|
private const val AE_SIZE = AF_SIZE * 1.5f
|
||||||
private const val MIN_SWIPE_DISTANCE_X = 100
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private val config = activity.config
|
private val config = activity.config
|
||||||
|
@ -293,21 +291,6 @@ class CameraXPreview(
|
||||||
true
|
true
|
||||||
} ?: false
|
} ?: false
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onFling(event1: MotionEvent, event2: MotionEvent, velocityX: Float, velocityY: Float): Boolean {
|
|
||||||
val deltaX = event1.x - event2.x
|
|
||||||
val deltaXAbs = abs(deltaX)
|
|
||||||
|
|
||||||
if (deltaXAbs >= MIN_SWIPE_DISTANCE_X) {
|
|
||||||
if (deltaX > 0) {
|
|
||||||
listener.onSwipeLeft()
|
|
||||||
} else {
|
|
||||||
listener.onSwipeRight()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
previewView.setOnTouchListener { _, event ->
|
previewView.setOnTouchListener { _, event ->
|
||||||
val handledGesture = gestureDetector.onTouchEvent(event)
|
val handledGesture = gestureDetector.onTouchEvent(event)
|
||||||
|
|
|
@ -18,8 +18,6 @@ interface CameraXPreviewListener {
|
||||||
fun onVideoRecordingStopped()
|
fun onVideoRecordingStopped()
|
||||||
fun onVideoDurationChanged(durationNanos: Long)
|
fun onVideoDurationChanged(durationNanos: Long)
|
||||||
fun onFocusCamera(xPos: Float, yPos: Float)
|
fun onFocusCamera(xPos: Float, yPos: Float)
|
||||||
fun onSwipeLeft()
|
|
||||||
fun onSwipeRight()
|
|
||||||
fun onTouchPreview()
|
fun onTouchPreview()
|
||||||
fun displaySelectedResolution(resolutionOption: ResolutionOption)
|
fun displaySelectedResolution(resolutionOption: ResolutionOption)
|
||||||
fun showImageSizes(
|
fun showImageSizes(
|
||||||
|
|
Loading…
Reference in New Issue