Added numpad on outgoing call view if early media
This commit is contained in:
parent
94487278d6
commit
1d0cbbcc69
5 changed files with 92 additions and 21 deletions
|
@ -20,11 +20,16 @@
|
||||||
package org.linphone.activities.call
|
package org.linphone.activities.call
|
||||||
|
|
||||||
import android.Manifest
|
import android.Manifest
|
||||||
|
import android.animation.ValueAnimator
|
||||||
import android.annotation.TargetApi
|
import android.annotation.TargetApi
|
||||||
import android.content.pm.PackageManager
|
import android.content.pm.PackageManager
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
|
import android.util.DisplayMetrics
|
||||||
|
import android.view.Display
|
||||||
import androidx.databinding.DataBindingUtil
|
import androidx.databinding.DataBindingUtil
|
||||||
import androidx.lifecycle.ViewModelProvider
|
import androidx.lifecycle.ViewModelProvider
|
||||||
|
import com.google.android.flexbox.FlexboxLayout
|
||||||
|
import org.linphone.LinphoneApplication
|
||||||
import org.linphone.LinphoneApplication.Companion.coreContext
|
import org.linphone.LinphoneApplication.Companion.coreContext
|
||||||
import org.linphone.R
|
import org.linphone.R
|
||||||
import org.linphone.activities.call.viewmodels.CallViewModel
|
import org.linphone.activities.call.viewmodels.CallViewModel
|
||||||
|
@ -41,6 +46,9 @@ class OutgoingCallActivity : ProximitySensorActivity() {
|
||||||
private lateinit var viewModel: CallViewModel
|
private lateinit var viewModel: CallViewModel
|
||||||
private lateinit var controlsViewModel: ControlsViewModel
|
private lateinit var controlsViewModel: ControlsViewModel
|
||||||
|
|
||||||
|
// We have to use lateinit here because we need to compute the screen width first
|
||||||
|
private lateinit var numpadAnimator: ValueAnimator
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
|
|
||||||
|
@ -87,11 +95,29 @@ class OutgoingCallActivity : ProximitySensorActivity() {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
controlsViewModel.toggleNumpadEvent.observe(this, {
|
||||||
|
it.consume { open ->
|
||||||
|
if (this::numpadAnimator.isInitialized) {
|
||||||
|
if (open) {
|
||||||
|
numpadAnimator.start()
|
||||||
|
} else {
|
||||||
|
numpadAnimator.reverse()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
if (Version.sdkAboveOrEqual(Version.API23_MARSHMALLOW_60)) {
|
if (Version.sdkAboveOrEqual(Version.API23_MARSHMALLOW_60)) {
|
||||||
checkPermissions()
|
checkPermissions()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun onStart() {
|
||||||
|
super.onStart()
|
||||||
|
|
||||||
|
initNumpadLayout()
|
||||||
|
}
|
||||||
|
|
||||||
override fun onResume() {
|
override fun onResume() {
|
||||||
super.onResume()
|
super.onResume()
|
||||||
|
|
||||||
|
@ -151,4 +177,22 @@ class OutgoingCallActivity : ProximitySensorActivity() {
|
||||||
}
|
}
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun initNumpadLayout() {
|
||||||
|
val metrics = DisplayMetrics()
|
||||||
|
val display: Display = windowManager.defaultDisplay
|
||||||
|
display.getRealMetrics(metrics)
|
||||||
|
val screenWidth = metrics.widthPixels.toFloat()
|
||||||
|
numpadAnimator = ValueAnimator.ofFloat(screenWidth, 0f).apply {
|
||||||
|
addUpdateListener {
|
||||||
|
val value = it.animatedValue as Float
|
||||||
|
findViewById<FlexboxLayout>(R.id.numpad)?.translationX = -value
|
||||||
|
duration = if (LinphoneApplication.corePreferences.enableAnimations) 500 else 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Hide the numpad here as we can't set the translationX property on include tag in layout
|
||||||
|
if (controlsViewModel.numpadVisibility.value == false) {
|
||||||
|
findViewById<FlexboxLayout>(R.id.numpad)?.translationX = -screenWidth
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -176,21 +176,7 @@ class ControlsFragment : GenericFragment<CallControlsFragmentBinding>() {
|
||||||
override fun onStart() {
|
override fun onStart() {
|
||||||
super.onStart()
|
super.onStart()
|
||||||
|
|
||||||
val metrics = DisplayMetrics()
|
initNumpadLayout()
|
||||||
val display: Display = requireActivity().getWindowManager().getDefaultDisplay()
|
|
||||||
display.getRealMetrics(metrics)
|
|
||||||
val screenWidth = metrics.widthPixels.toFloat()
|
|
||||||
numpadAnimator = ValueAnimator.ofFloat(screenWidth, 0f).apply {
|
|
||||||
addUpdateListener {
|
|
||||||
val value = it.animatedValue as Float
|
|
||||||
view?.findViewById<FlexboxLayout>(R.id.numpad)?.translationX = -value
|
|
||||||
duration = if (corePreferences.enableAnimations) 500 else 0
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// Hide the numpad here as we can't set the translationX property on include tag in layout
|
|
||||||
if (controlsViewModel.numpadVisibility.value == false) {
|
|
||||||
view?.findViewById<FlexboxLayout>(R.id.numpad)?.translationX = -screenWidth
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onRequestPermissionsResult(
|
override fun onRequestPermissionsResult(
|
||||||
|
@ -254,4 +240,22 @@ class ControlsFragment : GenericFragment<CallControlsFragmentBinding>() {
|
||||||
|
|
||||||
dialog?.show()
|
dialog?.show()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun initNumpadLayout() {
|
||||||
|
val metrics = DisplayMetrics()
|
||||||
|
val display: Display = requireActivity().windowManager.defaultDisplay
|
||||||
|
display.getRealMetrics(metrics)
|
||||||
|
val screenWidth = metrics.widthPixels.toFloat()
|
||||||
|
numpadAnimator = ValueAnimator.ofFloat(screenWidth, 0f).apply {
|
||||||
|
addUpdateListener {
|
||||||
|
val value = it.animatedValue as Float
|
||||||
|
view?.findViewById<FlexboxLayout>(R.id.numpad)?.translationX = -value
|
||||||
|
duration = if (corePreferences.enableAnimations) 500 else 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Hide the numpad here as we can't set the translationX property on include tag in layout
|
||||||
|
if (controlsViewModel.numpadVisibility.value == false) {
|
||||||
|
view?.findViewById<FlexboxLayout>(R.id.numpad)?.translationX = -screenWidth
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -55,6 +55,8 @@ open class CallViewModel(val call: Call) : GenericContactViewModel(call.remoteAd
|
||||||
|
|
||||||
val isPaused = MutableLiveData<Boolean>()
|
val isPaused = MutableLiveData<Boolean>()
|
||||||
|
|
||||||
|
val isOutgoingEarlyMedia = MutableLiveData<Boolean>()
|
||||||
|
|
||||||
val callEndedEvent: MutableLiveData<Event<Boolean>> by lazy {
|
val callEndedEvent: MutableLiveData<Event<Boolean>> by lazy {
|
||||||
MutableLiveData<Event<Boolean>>()
|
MutableLiveData<Event<Boolean>>()
|
||||||
}
|
}
|
||||||
|
@ -70,6 +72,7 @@ open class CallViewModel(val call: Call) : GenericContactViewModel(call.remoteAd
|
||||||
if (call != this@CallViewModel.call) return
|
if (call != this@CallViewModel.call) return
|
||||||
|
|
||||||
isPaused.value = state == Call.State.Paused
|
isPaused.value = state == Call.State.Paused
|
||||||
|
isOutgoingEarlyMedia.value = state == Call.State.OutgoingEarlyMedia
|
||||||
|
|
||||||
if (state == Call.State.End || state == Call.State.Released || state == Call.State.Error) {
|
if (state == Call.State.End || state == Call.State.Released || state == Call.State.Error) {
|
||||||
timer?.cancel()
|
timer?.cancel()
|
||||||
|
|
|
@ -1,8 +1,7 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<layout xmlns:android="http://schemas.android.com/apk/res/android"
|
<layout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
xmlns:tools="http://schemas.android.com/tools"
|
xmlns:tools="http://schemas.android.com/tools">
|
||||||
xmlns:bind="http://schemas.android.com/tools">
|
|
||||||
|
|
||||||
<data>
|
<data>
|
||||||
<import type="android.view.View" />
|
<import type="android.view.View" />
|
||||||
|
@ -272,14 +271,14 @@
|
||||||
<include
|
<include
|
||||||
android:id="@+id/primary_buttons_row"
|
android:id="@+id/primary_buttons_row"
|
||||||
layout="@layout/call_primary_buttons"
|
layout="@layout/call_primary_buttons"
|
||||||
bind:viewModel="@{controlsViewModel}"
|
tools:viewModel="@{controlsViewModel}"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_alignParentBottom="true"/>
|
android:layout_alignParentBottom="true"/>
|
||||||
|
|
||||||
<include
|
<include
|
||||||
layout="@layout/numpad"
|
layout="@layout/numpad"
|
||||||
bind:keyListener="@{controlsViewModel.onKeyClick}"
|
tools:keyListener="@{controlsViewModel.onKeyClick}"
|
||||||
android:layout_above="@id/primary_buttons_row"
|
android:layout_above="@id/primary_buttons_row"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
|
@ -288,7 +287,7 @@
|
||||||
|
|
||||||
<include
|
<include
|
||||||
layout="@layout/call_secondary_buttons"
|
layout="@layout/call_secondary_buttons"
|
||||||
bind:viewModel="@{controlsViewModel}"
|
tools:viewModel="@{controlsViewModel}"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:layout_above="@id/primary_buttons_row" />
|
android:layout_above="@id/primary_buttons_row" />
|
||||||
|
|
|
@ -94,6 +94,18 @@
|
||||||
android:layout_alignParentBottom="true"
|
android:layout_alignParentBottom="true"
|
||||||
android:orientation="horizontal">
|
android:orientation="horizontal">
|
||||||
|
|
||||||
|
<ImageView
|
||||||
|
android:onClick="@{() -> controlsViewModel.toggleNumpadVisibility()}"
|
||||||
|
android:selected="@{controlsViewModel.numpadVisibility}"
|
||||||
|
android:visibility="@{viewModel.isOutgoingEarlyMedia() ? View.VISIBLE : View.GONE, default=gone}"
|
||||||
|
android:contentDescription="@string/content_description_show_numpad"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="@dimen/call_button_size"
|
||||||
|
android:layout_weight="1"
|
||||||
|
android:background="@drawable/button_background_dark"
|
||||||
|
android:padding="15dp"
|
||||||
|
android:src="@drawable/call_numpad" />
|
||||||
|
|
||||||
<ImageView
|
<ImageView
|
||||||
android:onClick="@{() -> controlsViewModel.toggleMuteMicrophone()}"
|
android:onClick="@{() -> controlsViewModel.toggleMuteMicrophone()}"
|
||||||
android:selected="@{controlsViewModel.isMicrophoneMuted}"
|
android:selected="@{controlsViewModel.isMicrophoneMuted}"
|
||||||
|
@ -121,13 +133,22 @@
|
||||||
android:contentDescription="@string/content_description_terminate_call"
|
android:contentDescription="@string/content_description_terminate_call"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_weight="0.7"
|
android:layout_weight="@{viewModel.isOutgoingEarlyMedia ? 1.0f : 0.7f,default=0.7}"
|
||||||
android:background="@drawable/call_hangup_background"
|
android:background="@drawable/call_hangup_background"
|
||||||
android:padding="12dp"
|
android:padding="12dp"
|
||||||
android:src="@drawable/call_hangup" />
|
android:src="@drawable/call_hangup" />
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
|
<include
|
||||||
|
layout="@layout/numpad"
|
||||||
|
tools:keyListener="@{controlsViewModel.onKeyClick}"
|
||||||
|
android:layout_above="@id/buttons"
|
||||||
|
android:layout_below="@id/top_bar"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:layout_centerInParent="true" />
|
||||||
|
|
||||||
</RelativeLayout>
|
</RelativeLayout>
|
||||||
|
|
||||||
</layout>
|
</layout>
|
Loading…
Reference in a new issue