mirror of
https://github.com/SimpleMobileTools/Simple-Camera.git
synced 2025-06-27 09:02:59 +02:00
Merge pull request #380 from KryptKode/feat/preview-aligment-improvements
Preview alignment improvements
This commit is contained in:
@ -12,6 +12,7 @@ import android.os.CountDownTimer
|
|||||||
import android.provider.MediaStore
|
import android.provider.MediaStore
|
||||||
import android.view.*
|
import android.view.*
|
||||||
import android.widget.LinearLayout
|
import android.widget.LinearLayout
|
||||||
|
import androidx.constraintlayout.widget.ConstraintSet
|
||||||
import androidx.core.content.ContextCompat
|
import androidx.core.content.ContextCompat
|
||||||
import androidx.core.view.*
|
import androidx.core.view.*
|
||||||
import androidx.transition.*
|
import androidx.transition.*
|
||||||
@ -325,7 +326,9 @@ class MainActivity : SimpleActivity(), PhotoProcessor.MediaSavedListener, Camera
|
|||||||
initInPhotoMode = isInPhotoMode,
|
initInPhotoMode = isInPhotoMode,
|
||||||
)
|
)
|
||||||
|
|
||||||
mFocusCircleView = FocusCircleView(this)
|
mFocusCircleView = FocusCircleView(this).apply {
|
||||||
|
id = View.generateViewId()
|
||||||
|
}
|
||||||
view_holder.addView(mFocusCircleView)
|
view_holder.addView(mFocusCircleView)
|
||||||
|
|
||||||
setupPreviewImage(true)
|
setupPreviewImage(true)
|
||||||
@ -411,20 +414,15 @@ class MainActivity : SimpleActivity(), PhotoProcessor.MediaSavedListener, Camera
|
|||||||
|
|
||||||
@SuppressLint("ClickableViewAccessibility")
|
@SuppressLint("ClickableViewAccessibility")
|
||||||
private fun initModeSwitcher() {
|
private fun initModeSwitcher() {
|
||||||
val gestureDetector = GestureDetectorCompat(this, object : GestureDetector.SimpleOnGestureListener() {
|
val gestureDetector = GestureDetectorCompat(this, object : GestureDetectorListener() {
|
||||||
override fun onDown(e: MotionEvent): Boolean {
|
override fun onDown(e: MotionEvent): Boolean {
|
||||||
// we have to return true here so ACTION_UP
|
// we have to return true here so ACTION_UP
|
||||||
// (and onFling) can be dispatched
|
// (and onFling) can be dispatched
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onFling(event1: MotionEvent, event2: MotionEvent, velocityX: Float, velocityY: Float): Boolean {
|
override fun onFling(event1: MotionEvent?, event2: MotionEvent?, velocityX: Float, velocityY: Float): Boolean {
|
||||||
// these can be null even if the docs say they cannot, getting event1.x in itself can cause crashes
|
if (event1 == null || event2 == null) {
|
||||||
try {
|
|
||||||
if (event1 == null || event2 == null || event1.x == null || event2.x == null) {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
} catch (e: NullPointerException) {
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -824,6 +822,19 @@ class MainActivity : SimpleActivity(), PhotoProcessor.MediaSavedListener, Camera
|
|||||||
button.iconTint = ColorStateList(states, iconColors)
|
button.iconTint = ColorStateList(states, iconColors)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun adjustPreviewView(requiresCentering: Boolean) {
|
||||||
|
val constraintSet = ConstraintSet()
|
||||||
|
constraintSet.clone(view_holder)
|
||||||
|
if (requiresCentering) {
|
||||||
|
constraintSet.connect(preview_view.id, ConstraintSet.TOP, top_options.id, ConstraintSet.BOTTOM)
|
||||||
|
constraintSet.connect(preview_view.id, ConstraintSet.BOTTOM, camera_mode_tab.id, ConstraintSet.TOP)
|
||||||
|
} else {
|
||||||
|
constraintSet.connect(preview_view.id, ConstraintSet.TOP, ConstraintSet.PARENT_ID, ConstraintSet.TOP)
|
||||||
|
constraintSet.connect(preview_view.id, ConstraintSet.BOTTOM, ConstraintSet.PARENT_ID, ConstraintSet.BOTTOM)
|
||||||
|
}
|
||||||
|
constraintSet.applyTo(view_holder)
|
||||||
|
}
|
||||||
|
|
||||||
override fun mediaSaved(path: String) {
|
override fun mediaSaved(path: String) {
|
||||||
rescanPaths(arrayListOf(path)) {
|
rescanPaths(arrayListOf(path)) {
|
||||||
setupPreviewImage(true)
|
setupPreviewImage(true)
|
||||||
|
@ -0,0 +1,13 @@
|
|||||||
|
package com.simplemobiletools.camera.helpers;
|
||||||
|
|
||||||
|
import android.view.GestureDetector;
|
||||||
|
import android.view.MotionEvent;
|
||||||
|
|
||||||
|
import androidx.annotation.Nullable;
|
||||||
|
|
||||||
|
public class GestureDetectorListener extends GestureDetector.SimpleOnGestureListener {
|
||||||
|
@Override
|
||||||
|
public boolean onFling(@Nullable MotionEvent e1, @Nullable MotionEvent e2, float velocityX, float velocityY) {
|
||||||
|
return super.onFling(e1, e2, velocityX, velocityY);
|
||||||
|
}
|
||||||
|
}
|
@ -161,6 +161,8 @@ class CameraXPreview(
|
|||||||
MySize(selectedQuality.width, selectedQuality.height)
|
MySize(selectedQuality.width, selectedQuality.height)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
listener.adjustPreviewView(resolution.requiresCentering())
|
||||||
|
|
||||||
val isFullSize = resolution.isFullScreen
|
val isFullSize = resolution.isFullScreen
|
||||||
previewView.scaleType = if (isFullSize) ScaleType.FILL_CENTER else ScaleType.FIT_CENTER
|
previewView.scaleType = if (isFullSize) ScaleType.FILL_CENTER else ScaleType.FIT_CENTER
|
||||||
val rotation = previewView.display.rotation
|
val rotation = previewView.display.rotation
|
||||||
|
@ -30,6 +30,6 @@ interface CameraXPreviewListener {
|
|||||||
isFrontCamera: Boolean,
|
isFrontCamera: Boolean,
|
||||||
onSelect: (index: Int, changed: Boolean) -> Unit,
|
onSelect: (index: Int, changed: Boolean) -> Unit,
|
||||||
)
|
)
|
||||||
|
|
||||||
fun showFlashOptions(photoCapture: Boolean)
|
fun showFlashOptions(photoCapture: Boolean)
|
||||||
|
fun adjustPreviewView(requiresCentering: Boolean)
|
||||||
}
|
}
|
||||||
|
@ -17,6 +17,10 @@ data class MySize(val width: Int, val height: Int, val isFullScreen: Boolean = f
|
|||||||
|
|
||||||
val megaPixels: String = String.format("%.1f", (width * height.toFloat()) / ONE_MEGA_PIXEL)
|
val megaPixels: String = String.format("%.1f", (width * height.toFloat()) / ONE_MEGA_PIXEL)
|
||||||
|
|
||||||
|
fun requiresCentering(): Boolean {
|
||||||
|
return !isFullScreen && (isFourToThree() || isThreeToTwo() || isSquare())
|
||||||
|
}
|
||||||
|
|
||||||
fun isSixteenToNine() = ratio == 16 / 9f
|
fun isSixteenToNine() = ratio == 16 / 9f
|
||||||
|
|
||||||
private fun isFiveToThree() = ratio == 5 / 3f
|
private fun isFiveToThree() = ratio == 5 / 3f
|
||||||
|
@ -11,7 +11,9 @@
|
|||||||
<androidx.camera.view.PreviewView
|
<androidx.camera.view.PreviewView
|
||||||
android:id="@+id/preview_view"
|
android:id="@+id/preview_view"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent" />
|
android:layout_height="0dp"
|
||||||
|
app:layout_constraintBottom_toBottomOf="parent"
|
||||||
|
app:layout_constraintTop_toTopOf="parent" />
|
||||||
|
|
||||||
<View
|
<View
|
||||||
android:id="@+id/shutter_animation"
|
android:id="@+id/shutter_animation"
|
||||||
|
Reference in New Issue
Block a user