mirror of
https://gitlab.linphone.org/BC/public/linphone-android.git
synced 2026-01-17 11:28:06 +00:00
Added microphone volume vu meter
This commit is contained in:
parent
c64bd5bc1c
commit
5ef7eab0c5
6 changed files with 181 additions and 5 deletions
99
app/src/main/java/org/linphone/ui/call/view/VuMeterView.kt
Normal file
99
app/src/main/java/org/linphone/ui/call/view/VuMeterView.kt
Normal file
|
|
@ -0,0 +1,99 @@
|
|||
/*
|
||||
* Copyright (c) 2010-2025 Belledonne Communications SARL.
|
||||
*
|
||||
* This file is part of linphone-android
|
||||
* (see https://www.linphone.org).
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package org.linphone.ui.call.view
|
||||
|
||||
import android.content.Context
|
||||
import android.graphics.BitmapShader
|
||||
import android.graphics.Canvas
|
||||
import android.graphics.Matrix
|
||||
import android.graphics.Paint
|
||||
import android.graphics.Shader
|
||||
import android.util.AttributeSet
|
||||
import android.view.View
|
||||
import androidx.core.content.ContextCompat
|
||||
import androidx.core.graphics.createBitmap
|
||||
import org.linphone.R
|
||||
|
||||
class VuMeterView : View {
|
||||
companion object {
|
||||
private const val TAG = "[VuMeter View]"
|
||||
}
|
||||
|
||||
private lateinit var paint: Paint
|
||||
private lateinit var matrix: Matrix
|
||||
private lateinit var vuMeterPaint: Paint
|
||||
|
||||
private val color = ContextCompat.getColor(context, R.color.vu_meter)
|
||||
|
||||
private var vuMeterPercentage: Float = 0f
|
||||
|
||||
constructor(context: Context?) : super(context) {
|
||||
init()
|
||||
}
|
||||
|
||||
constructor(context: Context?, attrs: AttributeSet?) : super(context, attrs) {
|
||||
init()
|
||||
}
|
||||
|
||||
constructor(context: Context?, attrs: AttributeSet?, defStyle: Int) : super(
|
||||
context,
|
||||
attrs,
|
||||
defStyle
|
||||
) {
|
||||
init()
|
||||
}
|
||||
|
||||
private fun init() {
|
||||
paint = Paint()
|
||||
paint.isAntiAlias = true
|
||||
matrix = Matrix()
|
||||
|
||||
vuMeterPaint = Paint()
|
||||
vuMeterPaint.strokeWidth = 2f
|
||||
vuMeterPaint.isAntiAlias = true
|
||||
vuMeterPaint.setColor(color)
|
||||
}
|
||||
|
||||
fun setVuMeterPercentage(percentage: Float) {
|
||||
vuMeterPercentage = percentage
|
||||
invalidate()
|
||||
}
|
||||
|
||||
override fun onSizeChanged(w: Int, h: Int, oldw: Int, oldh: Int) {
|
||||
super.onSizeChanged(w, h, oldw, oldh)
|
||||
createShader()
|
||||
}
|
||||
|
||||
private fun createShader(): Shader {
|
||||
val level = (height - height * vuMeterPercentage).toFloat()
|
||||
|
||||
val bitmap = createBitmap(width, height)
|
||||
val canvas = Canvas(bitmap)
|
||||
canvas.drawRect(0f, height.toFloat(), width.toFloat(), level, vuMeterPaint)
|
||||
|
||||
val shader = BitmapShader(bitmap, Shader.TileMode.REPEAT, Shader.TileMode.CLAMP)
|
||||
return shader
|
||||
}
|
||||
|
||||
override fun onDraw(canvas: Canvas) {
|
||||
paint.setShader(createShader())
|
||||
canvas.drawCircle(width / 2f, height / 2f, width / 2f, paint)
|
||||
}
|
||||
}
|
||||
|
|
@ -29,6 +29,9 @@ import androidx.lifecycle.MutableLiveData
|
|||
import androidx.lifecycle.viewModelScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.delay
|
||||
import kotlinx.coroutines.flow.flow
|
||||
import kotlinx.coroutines.flow.launchIn
|
||||
import kotlinx.coroutines.flow.onEach
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.withContext
|
||||
import org.linphone.LinphoneApplication.Companion.coreContext
|
||||
|
|
@ -69,6 +72,8 @@ class CurrentCallViewModel
|
|||
constructor() : GenericViewModel() {
|
||||
companion object {
|
||||
private const val TAG = "[Current Call ViewModel]"
|
||||
private const val VU_METER_MIN = -20f
|
||||
private const val VU_METER_MAX = 4
|
||||
}
|
||||
|
||||
val contact = MutableLiveData<ContactAvatarModel>()
|
||||
|
|
@ -107,6 +112,8 @@ class CurrentCallViewModel
|
|||
|
||||
val isMicrophoneMuted = MutableLiveData<Boolean>()
|
||||
|
||||
val microphoneRecordingVolume = MutableLiveData<Float>()
|
||||
|
||||
val isSpeakerEnabled = MutableLiveData<Boolean>()
|
||||
|
||||
val isHeadsetEnabled = MutableLiveData<Boolean>()
|
||||
|
|
@ -541,6 +548,7 @@ class CurrentCallViewModel
|
|||
operationInProgress.value = false
|
||||
proximitySensorEnabled.value = false
|
||||
videoUpdateInProgress.value = false
|
||||
microphoneRecordingVolume.value = 0f
|
||||
|
||||
coreContext.postOnCoreThread { core ->
|
||||
hideSipAddresses.postValue(corePreferences.hideSipAddresses)
|
||||
|
|
@ -1247,6 +1255,13 @@ class CurrentCallViewModel
|
|||
} else {
|
||||
Log.i("$TAG Failed to find an existing 1-1 conversation for current call")
|
||||
}
|
||||
|
||||
microphoneVolumeVuMeterTickerFlow().onEach {
|
||||
coreContext.postOnCoreThread {
|
||||
val volumeDbm0 = currentCall.recordVolume
|
||||
microphoneRecordingVolume.postValue(computeVuMeterValue(volumeDbm0))
|
||||
}
|
||||
}.launchIn(viewModelScope)
|
||||
}
|
||||
|
||||
@WorkerThread
|
||||
|
|
@ -1519,4 +1534,17 @@ class CurrentCallViewModel
|
|||
private fun showRecordingToast() {
|
||||
showGreenToast(R.string.call_is_being_recorded, R.drawable.record_fill)
|
||||
}
|
||||
|
||||
private fun microphoneVolumeVuMeterTickerFlow() = flow {
|
||||
while (::currentCall.isInitialized) {
|
||||
emit(Unit)
|
||||
delay(50)
|
||||
}
|
||||
}
|
||||
|
||||
private fun computeVuMeterValue(volume: Float): Float {
|
||||
if (volume < VU_METER_MIN) return 0f
|
||||
if (volume > VU_METER_MAX) return 1f
|
||||
return (volume - VU_METER_MIN) / (VU_METER_MAX - VU_METER_MIN)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -69,6 +69,7 @@ import org.linphone.core.ConsolidatedPresence
|
|||
import org.linphone.core.tools.Log
|
||||
import org.linphone.ui.NotoSansFont
|
||||
import org.linphone.ui.call.conference.model.ConferenceParticipantDeviceModel
|
||||
import org.linphone.ui.call.view.VuMeterView
|
||||
import org.linphone.ui.call.view.RoundCornersTextureView
|
||||
|
||||
/**
|
||||
|
|
@ -501,6 +502,12 @@ fun setParticipantTextureView(
|
|||
model.setTextureView(textureView)
|
||||
}
|
||||
|
||||
@UiThread
|
||||
@BindingAdapter("vuMeterPercentage")
|
||||
fun setVuMeterPercentage(view: VuMeterView, percentage: Float) {
|
||||
view.setVuMeterPercentage(percentage)
|
||||
}
|
||||
|
||||
@UiThread
|
||||
@BindingAdapter("onValueChanged")
|
||||
fun AppCompatEditText.editTextSetting(lambda: () -> Unit) {
|
||||
|
|
|
|||
|
|
@ -77,6 +77,28 @@
|
|||
app:layout_constraintStart_toStartOf="@id/toggle_video"
|
||||
app:layout_constraintEnd_toEndOf="@id/toggle_video"/>
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/toggle_mute_mic_background"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="0dp"
|
||||
android:selected="@{viewModel.isMicrophoneMuted}"
|
||||
android:background="@drawable/in_call_button_background_red"
|
||||
android:contentDescription="@null"
|
||||
app:layout_constraintTop_toTopOf="@id/toggle_mute_mic"
|
||||
app:layout_constraintBottom_toBottomOf="@id/toggle_mute_mic"
|
||||
app:layout_constraintStart_toStartOf="@id/toggle_mute_mic"
|
||||
app:layout_constraintEnd_toEndOf="@id/toggle_mute_mic" />
|
||||
|
||||
<org.linphone.ui.call.view.VuMeterView
|
||||
android:id="@+id/record_volume_vu_meter"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="0dp"
|
||||
vuMeterPercentage="@{viewModel.microphoneRecordingVolume}"
|
||||
app:layout_constraintTop_toTopOf="@id/toggle_mute_mic_background"
|
||||
app:layout_constraintBottom_toBottomOf="@id/toggle_mute_mic_background"
|
||||
app:layout_constraintStart_toStartOf="@id/toggle_mute_mic_background"
|
||||
app:layout_constraintEnd_toEndOf="@id/toggle_mute_mic_background" />
|
||||
|
||||
<ImageView
|
||||
android:onClick="@{() -> viewModel.toggleMuteMicrophone()}"
|
||||
android:id="@+id/toggle_mute_mic"
|
||||
|
|
@ -84,9 +106,7 @@
|
|||
android:layout_height="@dimen/call_button_size"
|
||||
android:layout_marginEnd="16dp"
|
||||
android:padding="@dimen/call_button_icon_padding"
|
||||
android:selected="@{viewModel.isMicrophoneMuted}"
|
||||
android:src="@{viewModel.isMicrophoneMuted ? @drawable/microphone_slash : @drawable/microphone, default=@drawable/microphone}"
|
||||
android:background="@drawable/in_call_button_background_red"
|
||||
android:contentDescription="@string/content_description_toggle_microphone"
|
||||
app:tint="@color/in_call_button_tint_color"
|
||||
app:layout_constraintTop_toBottomOf="@id/call_actions_handle"
|
||||
|
|
|
|||
|
|
@ -65,6 +65,28 @@
|
|||
app:layout_constraintStart_toEndOf="@id/hang_up"
|
||||
app:layout_constraintEnd_toStartOf="@id/toggle_mute_mic" />
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/toggle_mute_mic_background"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="0dp"
|
||||
android:selected="@{viewModel.isMicrophoneMuted}"
|
||||
android:background="@drawable/in_call_button_background_red"
|
||||
android:contentDescription="@null"
|
||||
app:layout_constraintTop_toTopOf="@id/toggle_mute_mic"
|
||||
app:layout_constraintBottom_toBottomOf="@id/toggle_mute_mic"
|
||||
app:layout_constraintStart_toStartOf="@id/toggle_mute_mic"
|
||||
app:layout_constraintEnd_toEndOf="@id/toggle_mute_mic" />
|
||||
|
||||
<org.linphone.ui.call.view.VuMeterView
|
||||
android:id="@+id/record_volume_vu_meter"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="0dp"
|
||||
vuMeterPercentage="@{viewModel.microphoneRecordingVolume}"
|
||||
app:layout_constraintTop_toTopOf="@id/toggle_mute_mic_background"
|
||||
app:layout_constraintBottom_toBottomOf="@id/toggle_mute_mic_background"
|
||||
app:layout_constraintStart_toStartOf="@id/toggle_mute_mic_background"
|
||||
app:layout_constraintEnd_toEndOf="@id/toggle_mute_mic_background" />
|
||||
|
||||
<ImageView
|
||||
android:onClick="@{() -> viewModel.toggleMuteMicrophone()}"
|
||||
android:id="@+id/toggle_mute_mic"
|
||||
|
|
@ -72,12 +94,11 @@
|
|||
android:layout_height="@dimen/call_button_size"
|
||||
android:layout_marginEnd="16dp"
|
||||
android:padding="@dimen/call_button_icon_padding"
|
||||
android:contentDescription="@string/content_description_toggle_microphone"
|
||||
android:src="@{viewModel.isMicrophoneMuted ? @drawable/microphone_slash : @drawable/microphone, default=@drawable/microphone}"
|
||||
android:background="@drawable/in_call_button_background_red"
|
||||
android:contentDescription="@string/content_description_toggle_microphone"
|
||||
app:tint="@color/in_call_button_tint_color"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/call_actions_handle"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintStart_toEndOf="@id/toggle_video"
|
||||
app:layout_constraintEnd_toStartOf="@id/change_audio_output" />
|
||||
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@
|
|||
<color name="bc_white">#FFFFFF</color>
|
||||
<color name="dialog_background">#99000000</color><!-- 60% opacity -->
|
||||
<color name="shadow">#10000000</color>
|
||||
<color name="vu_meter">#3CFFFFFF</color>
|
||||
|
||||
<color name="background_color_dark_mode">#191919</color>
|
||||
<color name="background_color_alt_dark_mode">#303030</color>
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue