Merge pull request #351 from KryptKode/fix/camera-ui

FIX: UI issues
This commit is contained in:
Tibor Kaputa 2022-10-10 08:41:34 +02:00 committed by GitHub
commit 45e2ba1908
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 43 additions and 58 deletions

View File

@ -27,6 +27,8 @@ import com.google.android.material.tabs.TabLayout
import com.simplemobiletools.camera.BuildConfig
import com.simplemobiletools.camera.R
import com.simplemobiletools.camera.extensions.config
import com.simplemobiletools.camera.extensions.fadeIn
import com.simplemobiletools.camera.extensions.fadeOut
import com.simplemobiletools.camera.extensions.toFlashModeId
import com.simplemobiletools.camera.helpers.*
import com.simplemobiletools.camera.implementations.CameraXInitializer
@ -37,10 +39,16 @@ import com.simplemobiletools.camera.views.FocusCircleView
import com.simplemobiletools.commons.extensions.*
import com.simplemobiletools.commons.helpers.*
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 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 {
private companion object {
@ -74,7 +82,6 @@ class MainActivity : SimpleActivity(), PhotoProcessor.MediaSavedListener, Camera
super.onCreate(savedInstanceState)
appLaunched(BuildConfig.APPLICATION_ID)
requestWindowFeature(Window.FEATURE_NO_TITLE)
WindowCompat.setDecorFitsSystemWindows(window, false)
initVariables()
tryInitCamera()
@ -243,9 +250,9 @@ class MainActivity : SimpleActivity(), PhotoProcessor.MediaSavedListener, Camera
if (isTiramisuPlus()) {
handlePermission(PERMISSION_READ_MEDIA_IMAGES) { grantedReadImages ->
if (grantedReadImages) {
handlePermission(PERMISSION_READ_MEDIA_VIDEO) { grantedReadVideos ->
callback.invoke(grantedReadVideos)
}
handlePermission(PERMISSION_READ_MEDIA_VIDEO, callback)
} else {
callback.invoke(false)
}
}
} else {
@ -290,6 +297,7 @@ class MainActivity : SimpleActivity(), PhotoProcessor.MediaSavedListener, Camera
defaultScene = Scene(top_options, default_icons)
flashModeScene = Scene(top_options, flash_toggle_group)
WindowCompat.setDecorFitsSystemWindows(window, false)
ViewCompat.setOnApplyWindowInsetsListener(view_holder) { _, windowInsets ->
val safeInsetBottom = windowInsets.displayCutout?.safeInsetBottom ?: 0
val safeInsetTop = windowInsets.displayCutout?.safeInsetTop ?: 0
@ -524,11 +532,6 @@ class MainActivity : SimpleActivity(), PhotoProcessor.MediaSavedListener, Camera
}
}
private fun showTimer() {
video_rec_curr_timer.beVisible()
setupTimer()
}
private fun hideTimer() {
video_rec_curr_timer.text = 0.getFormattedDuration()
video_rec_curr_timer.beGone()
@ -536,15 +539,6 @@ class MainActivity : SimpleActivity(), PhotoProcessor.MediaSavedListener, Camera
mTimerHandler.removeCallbacksAndMessages(null)
}
private fun setupTimer() {
runOnUiThread(object : Runnable {
override fun run() {
video_rec_curr_timer.text = mCurrVideoRecTimer++.getFormattedDuration()
mTimerHandler.postDelayed(this, 1000L)
}
})
}
private fun resumeCameraItems() {
if (!mIsInPhotoMode) {
initVideoButtons()
@ -557,7 +551,7 @@ class MainActivity : SimpleActivity(), PhotoProcessor.MediaSavedListener, Camera
private fun hasPhotoModePermissions(): Boolean {
return if (isTiramisuPlus()) {
hasPermission(PERMISSION_READ_MEDIA_IMAGES) && hasPermission(PERMISSION_CAMERA)
hasPermission(PERMISSION_READ_MEDIA_IMAGES) && hasPermission(PERMISSION_READ_MEDIA_VIDEO) && hasPermission(PERMISSION_CAMERA)
} else {
hasPermission(PERMISSION_WRITE_STORAGE) && hasPermission(PERMISSION_CAMERA)
}
@ -681,21 +675,28 @@ class MainActivity : SimpleActivity(), PhotoProcessor.MediaSavedListener, Camera
override fun onVideoRecordingStarted() {
camera_mode_tab.beInvisible()
shutter.isSelected = true
toggle_camera.beInvisible()
video_rec_curr_timer.beVisible()
toggle_camera.fadeOut()
last_photo_video_preview.fadeOut()
change_resolution.isEnabled = false
settings.isEnabled = false
video_rec_curr_timer.beVisible()
shutter.isSelected = true
}
override fun onVideoRecordingStopped() {
camera_mode_tab.beVisible()
shutter.isSelected = false
toggle_camera.fadeIn()
last_photo_video_preview.fadeIn()
video_rec_curr_timer.text = 0.getFormattedDuration()
video_rec_curr_timer.beGone()
shutter.isSelected = false
change_resolution.isEnabled = true
settings.isEnabled = true
toggle_camera.beVisible()
}
override fun onVideoDurationChanged(durationNanos: Long) {
@ -820,33 +821,6 @@ class MainActivity : SimpleActivity(), PhotoProcessor.MediaSavedListener, Camera
button.iconTint = ColorStateList(states, iconColors)
}
fun setRecordingState(isRecording: Boolean) {
runOnUiThread {
if (isRecording) {
shutter.isSelected = true
toggle_camera.beInvisible()
showTimer()
} else {
shutter.isSelected = false
hideTimer()
}
}
}
fun videoSaved(uri: Uri) {
setupPreviewImage(false)
if (isVideoCaptureIntent()) {
Intent().apply {
data = uri
flags = Intent.FLAG_GRANT_READ_URI_PERMISSION
setResult(Activity.RESULT_OK, this)
}
finish()
}
}
fun drawFocusCircle(x: Float, y: Float) = mFocusCircleView.drawFocusCircle(x, y)
override fun mediaSaved(path: String) {
rescanPaths(arrayListOf(path)) {
setupPreviewImage(true)

View File

@ -0,0 +1,12 @@
package com.simplemobiletools.camera.extensions
import android.view.View
import com.simplemobiletools.commons.helpers.SHORT_ANIMATION_DURATION
fun View.fadeIn() {
animate().alpha(1f).setDuration(SHORT_ANIMATION_DURATION).withStartAction { isClickable = true }.start()
}
fun View.fadeOut() {
animate().alpha(0f).setDuration(SHORT_ANIMATION_DURATION).withEndAction { isClickable = false }.start()
}

View File

@ -6,8 +6,7 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
android:animateLayoutChanges="true"
android:background="@android:color/black"
android:fitsSystemWindows="true">
android:background="@android:color/black">
<androidx.camera.view.PreviewView
android:id="@+id/preview_view"
@ -111,8 +110,8 @@
android:contentDescription="@string/shutter"
android:src="@drawable/ic_shutter_animated"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@id/last_photo_video_preview"
app:layout_constraintStart_toEndOf="@id/toggle_camera"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintVertical_bias="1" />
<ImageView