Reworked how video preview is moving
This commit is contained in:
parent
2835f80ee5
commit
5c3b79abee
3 changed files with 68 additions and 54 deletions
|
@ -23,6 +23,7 @@ import android.app.Dialog
|
|||
import android.content.Intent
|
||||
import android.os.Bundle
|
||||
import android.os.SystemClock
|
||||
import android.view.MotionEvent
|
||||
import android.view.View
|
||||
import android.widget.Chronometer
|
||||
import androidx.databinding.DataBindingUtil
|
||||
|
@ -52,6 +53,39 @@ class SingleCallFragment : GenericFragment<VoipSingleCallFragmentBinding>() {
|
|||
|
||||
private var dialog: Dialog? = null
|
||||
|
||||
private var previewX: Float = 0f
|
||||
private var previewY: Float = 0f
|
||||
private var switchX: Float = 0f
|
||||
private var switchY: Float = 0f
|
||||
private val previewTouchListener = View.OnTouchListener { view, event ->
|
||||
when (event.action) {
|
||||
MotionEvent.ACTION_DOWN -> {
|
||||
previewX = view.x - event.rawX
|
||||
previewY = view.y - event.rawY
|
||||
switchX = binding.switchCamera.x - event.rawX
|
||||
switchY = binding.switchCamera.y - event.rawY
|
||||
true
|
||||
}
|
||||
MotionEvent.ACTION_MOVE -> {
|
||||
view.animate()
|
||||
.x(event.rawX + previewX)
|
||||
.y(event.rawY + previewY)
|
||||
.setDuration(0)
|
||||
.start()
|
||||
binding.switchCamera.animate()
|
||||
.x(event.rawX + switchX)
|
||||
.y(event.rawY + switchY)
|
||||
.setDuration(0)
|
||||
.start()
|
||||
true
|
||||
}
|
||||
else -> {
|
||||
view.performClick()
|
||||
false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun getLayoutId(): Int = R.layout.voip_single_call_fragment
|
||||
|
||||
override fun onStart() {
|
||||
|
@ -67,6 +101,8 @@ class SingleCallFragment : GenericFragment<VoipSingleCallFragmentBinding>() {
|
|||
|
||||
binding.lifecycleOwner = viewLifecycleOwner
|
||||
|
||||
binding.previewTouchListener = previewTouchListener
|
||||
|
||||
binding.controlsViewModel = controlsViewModel
|
||||
|
||||
binding.callsViewModel = callsViewModel
|
||||
|
|
|
@ -21,8 +21,6 @@ package org.linphone.activities.voip.viewmodels
|
|||
|
||||
import android.Manifest
|
||||
import android.animation.ValueAnimator
|
||||
import android.view.MotionEvent
|
||||
import android.view.View
|
||||
import android.view.animation.LinearInterpolator
|
||||
import androidx.lifecycle.MediatorLiveData
|
||||
import androidx.lifecycle.MutableLiveData
|
||||
|
@ -107,30 +105,6 @@ class ControlsViewModel : ViewModel() {
|
|||
|
||||
private val nonEarpieceOutputAudioDevice = MutableLiveData<Boolean>()
|
||||
|
||||
private var previewX: Float = 0f
|
||||
private var previewY: Float = 0f
|
||||
val previewTouchListener = View.OnTouchListener { view, event ->
|
||||
when (event.action) {
|
||||
MotionEvent.ACTION_DOWN -> {
|
||||
previewX = view.x - event.rawX
|
||||
previewY = view.y - event.rawY
|
||||
true
|
||||
}
|
||||
MotionEvent.ACTION_MOVE -> {
|
||||
view.animate()
|
||||
.x(event.rawX + previewX)
|
||||
.y(event.rawY + previewY)
|
||||
.setDuration(0)
|
||||
.start()
|
||||
true
|
||||
}
|
||||
else -> {
|
||||
view.performClick()
|
||||
false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private val listener: CoreListenerStub = object : CoreListenerStub() {
|
||||
override fun onCallStateChanged(
|
||||
core: Core,
|
||||
|
|
|
@ -9,6 +9,10 @@
|
|||
|
||||
<import type="com.google.android.flexbox.FlexDirection" />
|
||||
|
||||
<variable
|
||||
name="previewTouchListener"
|
||||
type="android.view.View.OnTouchListener" />
|
||||
|
||||
<variable
|
||||
name="controlsViewModel"
|
||||
type="org.linphone.activities.voip.viewmodels.ControlsViewModel" />
|
||||
|
@ -166,39 +170,39 @@
|
|||
app:layout_constraintEnd_toEndOf="@id/background"
|
||||
app:layout_constraintTop_toTopOf="@id/background" />
|
||||
|
||||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
<androidx.constraintlayout.widget.Group
|
||||
android:id="@+id/video_preview_group"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_margin="25dp"
|
||||
android:onTouch="@{controlsViewModel.previewTouchListener}"
|
||||
android:visibility="@{controlsViewModel.isVideoEnabled && !callsViewModel.currentCallData.isRemotelyPaused ? View.VISIBLE : View.GONE}"
|
||||
app:constraint_referenced_ids="local_preview_video_surface,switch_camera" />
|
||||
|
||||
<org.linphone.activities.voip.views.RoundCornersTextureView
|
||||
android:id="@+id/local_preview_video_surface"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="0dp"
|
||||
android:layout_size="@{controlsViewModel.pipMode ? @dimen/video_preview_pip_max_size : @dimen/video_preview_max_size}"
|
||||
android:onTouch="@{previewTouchListener}"
|
||||
app:alignTopRight="true"
|
||||
app:displayMode="black_bars"
|
||||
app:layout_constraintBottom_toTopOf="@id/primary_buttons"
|
||||
app:layout_constraintEnd_toEndOf="@id/background">
|
||||
app:layout_constraintEnd_toEndOf="@id/background"
|
||||
app:layout_constraintHeight_max="200dp"
|
||||
app:layout_constraintWidth_max="200dp"
|
||||
bind:ignore="MissingConstraints" />
|
||||
|
||||
<org.linphone.activities.voip.views.RoundCornersTextureView
|
||||
android:id="@+id/local_preview_video_surface"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="0dp"
|
||||
android:layout_size="@{controlsViewModel.pipMode ? @dimen/video_preview_pip_max_size : @dimen/video_preview_max_size}"
|
||||
app:alignTopRight="true"
|
||||
app:displayMode="black_bars"
|
||||
app:layout_constraintHeight_max="200dp"
|
||||
app:layout_constraintWidth_max="200dp"
|
||||
bind:ignore="MissingConstraints" />
|
||||
|
||||
<ImageView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_margin="5dp"
|
||||
android:contentDescription="@string/content_description_switch_camera"
|
||||
android:onClick="@{() -> controlsViewModel.switchCamera()}"
|
||||
android:padding="10dp"
|
||||
android:src="@drawable/icon_call_camera_switch"
|
||||
android:visibility="@{controlsViewModel.isSwitchCameraAvailable && !controlsViewModel.pipMode ? View.VISIBLE : View.GONE, default=gone}"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
<ImageView
|
||||
android:id="@+id/switch_camera"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_margin="5dp"
|
||||
android:contentDescription="@string/content_description_switch_camera"
|
||||
android:onClick="@{() -> controlsViewModel.switchCamera()}"
|
||||
android:padding="10dp"
|
||||
android:src="@drawable/icon_call_camera_switch"
|
||||
android:visibility="@{controlsViewModel.isSwitchCameraAvailable && !controlsViewModel.pipMode ? View.VISIBLE : View.GONE, default=gone}"
|
||||
app:layout_constraintEnd_toEndOf="@id/local_preview_video_surface"
|
||||
app:layout_constraintTop_toTopOf="@id/local_preview_video_surface" />
|
||||
|
||||
<ViewStub
|
||||
android:id="@+id/stubbed_audio_routes"
|
||||
|
|
Loading…
Reference in a new issue