Show popup on switching to/from speakerphone.

This commit is contained in:
Nicholas
2023-08-01 15:51:31 -04:00
committed by Greyson Parrelli
parent 8ca49c1e18
commit 7ff4a82755
7 changed files with 58 additions and 7 deletions
@@ -61,6 +61,7 @@ import org.thoughtcrime.securesms.components.webrtc.CallParticipantsState;
import org.thoughtcrime.securesms.components.webrtc.CallStateUpdatePopupWindow;
import org.thoughtcrime.securesms.components.webrtc.CallToastPopupWindow;
import org.thoughtcrime.securesms.components.webrtc.GroupCallSafetyNumberChangeNotificationUtil;
import org.thoughtcrime.securesms.components.webrtc.WebRtcAudioDevice;
import org.thoughtcrime.securesms.components.webrtc.WebRtcAudioOutput;
import org.thoughtcrime.securesms.components.webrtc.WebRtcCallView;
import org.thoughtcrime.securesms.components.webrtc.WebRtcCallViewModel;
@@ -833,6 +834,7 @@ public class WebRtcCallActivity extends BaseActivity implements SafetyNumberChan
@Override
public void onAudioOutputChanged(@NonNull WebRtcAudioOutput audioOutput) {
maybeDisplaySpeakerphonePopup(audioOutput);
switch (audioOutput) {
case HANDSET:
handleSetAudioHandset();
@@ -853,8 +855,9 @@ public class WebRtcCallActivity extends BaseActivity implements SafetyNumberChan
@RequiresApi(31)
@Override
public void onAudioOutputChanged31(@NonNull Integer audioDeviceInfo) {
ApplicationDependencies.getSignalCallManager().selectAudioDevice(new SignalAudioManager.ChosenAudioDeviceIdentifier(audioDeviceInfo));
public void onAudioOutputChanged31(@NonNull WebRtcAudioDevice audioOutput) {
maybeDisplaySpeakerphonePopup(audioOutput.getWebRtcAudioOutput());
ApplicationDependencies.getSignalCallManager().selectAudioDevice(new SignalAudioManager.ChosenAudioDeviceIdentifier(audioOutput.getDeviceId()));
}
@Override
@@ -937,6 +940,15 @@ public class WebRtcCallActivity extends BaseActivity implements SafetyNumberChan
}
}
private void maybeDisplaySpeakerphonePopup(WebRtcAudioOutput nextOutput) {
final WebRtcAudioOutput currentOutput = viewModel.getCurrentAudioOutput();
if (currentOutput == WebRtcAudioOutput.SPEAKER && nextOutput != WebRtcAudioOutput.SPEAKER) {
callStateUpdatePopupWindow.onCallStateUpdate(CallStateUpdatePopupWindow.CallStateUpdate.SPEAKER_OFF);
} else if (currentOutput != WebRtcAudioOutput.SPEAKER && nextOutput == WebRtcAudioOutput.SPEAKER) {
callStateUpdatePopupWindow.onCallStateUpdate(CallStateUpdatePopupWindow.CallStateUpdate.SPEAKER_ON);
}
}
private class WindowLayoutInfoConsumer implements Consumer<WindowLayoutInfo> {
@Override
@@ -114,6 +114,8 @@ class CallStateUpdatePopupWindow(private val parent: ViewGroup) : PopupWindow(
RINGING_OFF(R.drawable.symbol_bell_slash_compact_16, R.string.CallStateUpdatePopupWindow__ringing_off),
RINGING_DISABLED(null, R.string.CallStateUpdatePopupWindow__group_is_too_large),
MIC_ON(R.drawable.symbol_mic_compact_16, R.string.CallStateUpdatePopupWindow__mic_on),
MIC_OFF(R.drawable.symbol_mic_slash_compact_16, R.string.CallStateUpdatePopupWindow__mic_off)
MIC_OFF(R.drawable.symbol_mic_slash_compact_16, R.string.CallStateUpdatePopupWindow__mic_off),
SPEAKER_ON(R.drawable.symbol_speaker_24, R.string.CallStateUpdatePopupWindow__speaker_on),
SPEAKER_OFF(R.drawable.symbol_speaker_slash_24, R.string.CallStateUpdatePopupWindow__speaker_off)
}
}
@@ -248,9 +248,8 @@ public class WebRtcCallView extends ConstraintLayout {
runIfNonNull(controlsListener, listener ->
{
if (Build.VERSION.SDK_INT >= 31) {
final Integer deviceId = webRtcAudioDevice.getDeviceId();
if (deviceId != null) {
listener.onAudioOutputChanged31(deviceId);
if (webRtcAudioDevice.getDeviceId() != null) {
listener.onAudioOutputChanged31(webRtcAudioDevice);
} else {
Log.e(TAG, "Attempted to change audio output to null device ID.");
}
@@ -1102,7 +1101,7 @@ public class WebRtcCallView extends ConstraintLayout {
void hideSystemUI();
void onAudioOutputChanged(@NonNull WebRtcAudioOutput audioOutput);
@RequiresApi(31)
void onAudioOutputChanged31(@NonNull Integer audioOutputAddress);
void onAudioOutputChanged31(@NonNull WebRtcAudioDevice audioOutput);
void onVideoChanged(boolean isVideoEnabled);
void onMicChanged(boolean isMicEnabled);
void onCameraDirectionChanged();
@@ -163,6 +163,10 @@ public class WebRtcCallViewModel extends ViewModel {
return shouldShowSpeakerHint;
}
public WebRtcAudioOutput getCurrentAudioOutput() {
return getWebRtcControls().getValue().getAudioOutput();
}
public LiveData<WebRtcEphemeralState> getEphemeralState() {
return ephemeralState;
}
@@ -0,0 +1,15 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="@color/signal_light_colorOnSecondaryContainer"
android:pathData="M10.6 3.66c1.02-1.02 2.78-0.3 2.78 1.15V19.2c0 1.45-1.76 2.17-2.78 1.15l-3.46-3.46H4c-1.59 0-2.88-1.3-2.88-2.88v-4c0-1.59 1.3-2.87 2.88-2.87h3.14l3.46-3.47Zm1.03 1.45l-3.51 3.5C7.95 8.79 7.73 8.89 7.5 8.89H4c-0.62 0-1.13 0.5-1.13 1.12v4c0 0.62 0.5 1.13 1.13 1.13h3.5c0.23 0 0.45 0.09 0.62 0.25l3.5 3.5V5.12Z" />
<path
android:fillColor="@color/signal_light_colorOnSecondaryContainer"
android:pathData="M16.23 6.57c0.41-0.25 0.95-0.12 1.2 0.29 0.92 1.5 1.44 3.26 1.44 5.14s-0.52 3.64-1.44 5.14c-0.25 0.41-0.79 0.54-1.2 0.3-0.41-0.26-0.54-0.8-0.3-1.21 0.76-1.23 1.2-2.68 1.2-4.23 0-1.55-0.44-3-1.2-4.23-0.24-0.41-0.11-0.95 0.3-1.2Z" />
<path
android:fillColor="@color/signal_light_colorOnSecondaryContainer"
android:pathData="M20.28 3.92c-0.28-0.4-0.83-0.48-1.22-0.2-0.4 0.28-0.48 0.83-0.2 1.22 1.43 1.99 2.26 4.42 2.26 7.06 0 2.64-0.83 5.07-2.26 7.06-0.28 0.4-0.2 0.94 0.2 1.22s0.94 0.2 1.22-0.2c1.63-2.28 2.6-5.07 2.6-8.08s-0.97-5.8-2.6-8.08Z" />
</vector>
@@ -0,0 +1,15 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="@color/signal_light_colorOnSecondaryContainer"
android:pathData="M5.12 3.38c-0.34-0.34-0.9-0.34-1.24 0-0.34 0.34-0.34 0.9 0 1.24l16 16c0.34 0.34 0.9 0.34 1.24 0 0.34-0.34 0.34-0.9 0-1.24l-16-16Z" />
<path
android:fillColor="@color/signal_light_colorOnSecondaryContainer"
android:pathData="M4.63 10c0-0.7 0.25-1.35 0.67-1.85L6.55 9.4C6.44 9.58 6.38 9.78 6.38 10v4c0 0.62 0.5 1.13 1.12 1.13h3.86l3.77 3.76v-0.9l1.68 1.68c-0.33 1.11-1.8 1.57-2.7 0.67l-3.47-3.46H7.5c-1.59 0-2.88-1.3-2.88-2.88v-4Z" />
<path
android:fillColor="@color/signal_light_colorOnSecondaryContainer"
android:pathData="M12.05 8.19l3.07-3.08v6.16l1.76 1.75v-8.2c0-1.46-1.76-2.18-2.78-1.16l-3.29 3.3 1.24 1.23Z" />
</vector>
+4
View File
@@ -6086,6 +6086,10 @@
<string name="CallStateUpdatePopupWindow__mic_on">Mic on</string>
<!-- Displayed when the user turns off their mic -->
<string name="CallStateUpdatePopupWindow__mic_off">Mic off</string>
<!-- Displayed when the user turns on their speakerphone -->
<string name="CallStateUpdatePopupWindow__speaker_on">Speaker on</string>
<!-- Displayed when the user turns off their speakerphone -->
<string name="CallStateUpdatePopupWindow__speaker_off">Speaker off</string>
<!-- Accessibility label describing the capture button on the camera screen -->
<string name="CameraControls_capture_button_accessibility_label">Capture Button</string>