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.content.Intent
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.os.SystemClock
|
import android.os.SystemClock
|
||||||
|
import android.view.MotionEvent
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.widget.Chronometer
|
import android.widget.Chronometer
|
||||||
import androidx.databinding.DataBindingUtil
|
import androidx.databinding.DataBindingUtil
|
||||||
|
@ -52,6 +53,39 @@ class SingleCallFragment : GenericFragment<VoipSingleCallFragmentBinding>() {
|
||||||
|
|
||||||
private var dialog: Dialog? = null
|
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 getLayoutId(): Int = R.layout.voip_single_call_fragment
|
||||||
|
|
||||||
override fun onStart() {
|
override fun onStart() {
|
||||||
|
@ -67,6 +101,8 @@ class SingleCallFragment : GenericFragment<VoipSingleCallFragmentBinding>() {
|
||||||
|
|
||||||
binding.lifecycleOwner = viewLifecycleOwner
|
binding.lifecycleOwner = viewLifecycleOwner
|
||||||
|
|
||||||
|
binding.previewTouchListener = previewTouchListener
|
||||||
|
|
||||||
binding.controlsViewModel = controlsViewModel
|
binding.controlsViewModel = controlsViewModel
|
||||||
|
|
||||||
binding.callsViewModel = callsViewModel
|
binding.callsViewModel = callsViewModel
|
||||||
|
|
|
@ -21,8 +21,6 @@ package org.linphone.activities.voip.viewmodels
|
||||||
|
|
||||||
import android.Manifest
|
import android.Manifest
|
||||||
import android.animation.ValueAnimator
|
import android.animation.ValueAnimator
|
||||||
import android.view.MotionEvent
|
|
||||||
import android.view.View
|
|
||||||
import android.view.animation.LinearInterpolator
|
import android.view.animation.LinearInterpolator
|
||||||
import androidx.lifecycle.MediatorLiveData
|
import androidx.lifecycle.MediatorLiveData
|
||||||
import androidx.lifecycle.MutableLiveData
|
import androidx.lifecycle.MutableLiveData
|
||||||
|
@ -107,30 +105,6 @@ class ControlsViewModel : ViewModel() {
|
||||||
|
|
||||||
private val nonEarpieceOutputAudioDevice = MutableLiveData<Boolean>()
|
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() {
|
private val listener: CoreListenerStub = object : CoreListenerStub() {
|
||||||
override fun onCallStateChanged(
|
override fun onCallStateChanged(
|
||||||
core: Core,
|
core: Core,
|
||||||
|
|
|
@ -9,6 +9,10 @@
|
||||||
|
|
||||||
<import type="com.google.android.flexbox.FlexDirection" />
|
<import type="com.google.android.flexbox.FlexDirection" />
|
||||||
|
|
||||||
|
<variable
|
||||||
|
name="previewTouchListener"
|
||||||
|
type="android.view.View.OnTouchListener" />
|
||||||
|
|
||||||
<variable
|
<variable
|
||||||
name="controlsViewModel"
|
name="controlsViewModel"
|
||||||
type="org.linphone.activities.voip.viewmodels.ControlsViewModel" />
|
type="org.linphone.activities.voip.viewmodels.ControlsViewModel" />
|
||||||
|
@ -166,27 +170,29 @@
|
||||||
app:layout_constraintEnd_toEndOf="@id/background"
|
app:layout_constraintEnd_toEndOf="@id/background"
|
||||||
app:layout_constraintTop_toTopOf="@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_width="wrap_content"
|
||||||
android:layout_height="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}"
|
android:visibility="@{controlsViewModel.isVideoEnabled && !callsViewModel.currentCallData.isRemotelyPaused ? View.VISIBLE : View.GONE}"
|
||||||
app:layout_constraintBottom_toTopOf="@id/primary_buttons"
|
app:constraint_referenced_ids="local_preview_video_surface,switch_camera" />
|
||||||
app:layout_constraintEnd_toEndOf="@id/background">
|
|
||||||
|
|
||||||
<org.linphone.activities.voip.views.RoundCornersTextureView
|
<org.linphone.activities.voip.views.RoundCornersTextureView
|
||||||
android:id="@+id/local_preview_video_surface"
|
android:id="@+id/local_preview_video_surface"
|
||||||
android:layout_width="0dp"
|
android:layout_width="0dp"
|
||||||
android:layout_height="0dp"
|
android:layout_height="0dp"
|
||||||
android:layout_size="@{controlsViewModel.pipMode ? @dimen/video_preview_pip_max_size : @dimen/video_preview_max_size}"
|
android:layout_size="@{controlsViewModel.pipMode ? @dimen/video_preview_pip_max_size : @dimen/video_preview_max_size}"
|
||||||
|
android:onTouch="@{previewTouchListener}"
|
||||||
app:alignTopRight="true"
|
app:alignTopRight="true"
|
||||||
app:displayMode="black_bars"
|
app:displayMode="black_bars"
|
||||||
|
app:layout_constraintBottom_toTopOf="@id/primary_buttons"
|
||||||
|
app:layout_constraintEnd_toEndOf="@id/background"
|
||||||
app:layout_constraintHeight_max="200dp"
|
app:layout_constraintHeight_max="200dp"
|
||||||
app:layout_constraintWidth_max="200dp"
|
app:layout_constraintWidth_max="200dp"
|
||||||
bind:ignore="MissingConstraints" />
|
bind:ignore="MissingConstraints" />
|
||||||
|
|
||||||
<ImageView
|
<ImageView
|
||||||
|
android:id="@+id/switch_camera"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_margin="5dp"
|
android:layout_margin="5dp"
|
||||||
|
@ -195,10 +201,8 @@
|
||||||
android:padding="10dp"
|
android:padding="10dp"
|
||||||
android:src="@drawable/icon_call_camera_switch"
|
android:src="@drawable/icon_call_camera_switch"
|
||||||
android:visibility="@{controlsViewModel.isSwitchCameraAvailable && !controlsViewModel.pipMode ? View.VISIBLE : View.GONE, default=gone}"
|
android:visibility="@{controlsViewModel.isSwitchCameraAvailable && !controlsViewModel.pipMode ? View.VISIBLE : View.GONE, default=gone}"
|
||||||
app:layout_constraintEnd_toEndOf="parent"
|
app:layout_constraintEnd_toEndOf="@id/local_preview_video_surface"
|
||||||
app:layout_constraintTop_toTopOf="parent" />
|
app:layout_constraintTop_toTopOf="@id/local_preview_video_surface" />
|
||||||
|
|
||||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
|
||||||
|
|
||||||
<ViewStub
|
<ViewStub
|
||||||
android:id="@+id/stubbed_audio_routes"
|
android:id="@+id/stubbed_audio_routes"
|
||||||
|
|
Loading…
Reference in a new issue