mirror of
				https://github.com/SimpleMobileTools/Simple-Camera.git
				synced 2025-06-27 09:02:59 +02:00 
			
		
		
		
	improve preview alignment
- center the PreviewView between the top action icons and the bottom mode switcher view for 4:3, 3:2 (video mode - SD) and 1:1 resolutions, when not full screen
This commit is contained in:
		| @@ -11,6 +11,7 @@ import android.os.Bundle | |||||||
| 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.* | ||||||
| @@ -318,7 +319,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) | ||||||
| @@ -752,6 +755,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) | ||||||
|   | |||||||
| @@ -162,6 +162,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 | ||||||
|   | |||||||
| @@ -29,6 +29,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