Эх сурвалжийг харах

highlight active audio output

use layout weight

Signed-off-by: Marcel Hibbe <dev@mhibbe.de>
Marcel Hibbe 3 жил өмнө
parent
commit
ffb223a66f

+ 35 - 28
app/src/main/java/com/nextcloud/talk/activities/CallActivity.java

@@ -173,6 +173,8 @@ public class CallActivity extends CallBaseActivity {
 
     public static final String TAG = "CallActivity";
 
+    public MagicAudioManager audioManager;
+
     private static final String[] PERMISSIONS_CALL = {
         android.Manifest.permission.CAMERA,
         android.Manifest.permission.RECORD_AUDIO,
@@ -198,7 +200,6 @@ public class CallActivity extends CallBaseActivity {
     private MediaConstraints videoConstraints;
     private MediaConstraints sdpConstraints;
     private MediaConstraints sdpConstraintsForMCU;
-    private MagicAudioManager audioManager;
     private VideoSource videoSource;
     private VideoTrack localVideoTrack;
     private AudioSource audioSource;
@@ -369,33 +370,6 @@ public class CallActivity extends CallBaseActivity {
         });
     }
 
-    public void setAudioOutputChannel(MagicAudioManager.AudioDevice audioDevice) {
-        if (audioManager == null) {
-            return;
-        }
-
-        audioManager.selectAudioDevice(audioDevice);
-
-        switch (audioManager.getResultingAudioDevice()) {
-            case BLUETOOTH:
-                binding.audioOutputButton.getHierarchy().setPlaceholderImage(
-                    AppCompatResources.getDrawable(context, R.drawable.ic_baseline_bluetooth_audio_24));
-                break;
-            case SPEAKER_PHONE:
-                binding.audioOutputButton.getHierarchy().setPlaceholderImage(
-                    AppCompatResources.getDrawable(context, R.drawable.ic_volume_up_white_24dp));
-                break;
-            case EARPIECE:
-                binding.audioOutputButton.getHierarchy().setPlaceholderImage(
-                    AppCompatResources.getDrawable(context, R.drawable.ic_baseline_phone_in_talk_24));
-                break;
-            default:
-                Log.e(TAG, "Invalid audio device selection");
-                break;
-        }
-        DrawableCompat.setTint(binding.audioOutputButton.getDrawable(), Color.WHITE);
-    }
-
     private void createCameraEnumerator() {
         boolean camera2EnumeratorIsSupported = false;
         try {
@@ -441,6 +415,12 @@ public class CallActivity extends CallBaseActivity {
         Log.d(TAG, "Starting the audio manager...");
         audioManager.start(this::onAudioManagerDevicesChanged);
 
+        if (isVoiceOnlyCall) {
+            setAudioOutputChannel(MagicAudioManager.AudioDevice.EARPIECE);
+        } else {
+            setAudioOutputChannel(MagicAudioManager.AudioDevice.SPEAKER_PHONE);
+        }
+
         iceServers = new ArrayList<>();
 
         //create sdpConstraints
@@ -471,6 +451,33 @@ public class CallActivity extends CallBaseActivity {
         microphoneInitialization();
     }
 
+    public void setAudioOutputChannel(MagicAudioManager.AudioDevice selectedAudioDevice) {
+        if (audioManager == null) {
+            return;
+        }
+
+        audioManager.selectAudioDevice(selectedAudioDevice);
+
+        switch (audioManager.getResultingAudioDevice()) {
+            case BLUETOOTH:
+                binding.audioOutputButton.getHierarchy().setPlaceholderImage(
+                    AppCompatResources.getDrawable(context, R.drawable.ic_baseline_bluetooth_audio_24));
+                break;
+            case SPEAKER_PHONE:
+                binding.audioOutputButton.getHierarchy().setPlaceholderImage(
+                    AppCompatResources.getDrawable(context, R.drawable.ic_volume_up_white_24dp));
+                break;
+            case EARPIECE:
+                binding.audioOutputButton.getHierarchy().setPlaceholderImage(
+                    AppCompatResources.getDrawable(context, R.drawable.ic_baseline_phone_in_talk_24));
+                break;
+            default:
+                Log.e(TAG, "Icon for audio output not available");
+                break;
+        }
+        DrawableCompat.setTint(binding.audioOutputButton.getDrawable(), Color.WHITE);
+    }
+
     private void handleFromNotification() {
         int apiVersion = ApiUtils.getConversationApiVersion(conversationUser, new int[]{ApiUtils.APIv4, 1});
 

+ 48 - 3
app/src/main/java/com/nextcloud/talk/ui/dialog/AudioOutputDialog.kt

@@ -2,9 +2,7 @@
  * Nextcloud Talk application
  *
  * @author Marcel Hibbe
- * @author Andy Scherzinger
- * Copyright (C) 2021 Marcel Hibbe <dev@mhibbe.de>
- * Copyright (C) 2021 Andy Scherzinger <info@andy-scherzinger.de>
+ * Copyright (C) 2022 Marcel Hibbe <dev@mhibbe.de>
  *
  * 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
@@ -23,8 +21,10 @@
 package com.nextcloud.talk.ui.dialog
 
 import android.os.Bundle
+import android.util.Log
 import android.view.View
 import android.view.ViewGroup
+import androidx.core.content.ContextCompat
 import com.google.android.material.bottomsheet.BottomSheetBehavior
 import com.google.android.material.bottomsheet.BottomSheetDialog
 import com.nextcloud.talk.R
@@ -42,7 +42,52 @@ class AudioOutputDialog(val callActivity: CallActivity) : BottomSheetDialog(call
         setContentView(dialogAudioOutputBinding.root)
         window?.setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)
 
+        highlightActiveOutputChannel()
+        initClickListeners()
+    }
+
+    private fun highlightActiveOutputChannel() {
+        when (callActivity.audioManager?.resultingAudioDevice) {
+            MagicAudioManager.AudioDevice.BLUETOOTH -> {
+                dialogAudioOutputBinding.audioOutputBluetoothIcon.setColorFilter(
+                    ContextCompat.getColor(
+                        context, R.color
+                            .colorPrimary
+                    ), android.graphics.PorterDuff.Mode.SRC_IN
+                )
+                dialogAudioOutputBinding.audioOutputBluetoothText.setTextColor(
+                    callActivity.resources.getColor(
+                        R.color
+                            .colorPrimary
+                    )
+                )
+            }
+
+            MagicAudioManager.AudioDevice.SPEAKER_PHONE -> {
+                dialogAudioOutputBinding.audioOutputSpeakerIcon.setColorFilter(
+                    ContextCompat.getColor(
+                        context,
+                        R.color.colorPrimary
+                    ), android.graphics.PorterDuff.Mode.SRC_IN
+                )
+                dialogAudioOutputBinding.audioOutputSpeakerText.setTextColor(callActivity.resources.getColor(R.color.colorPrimary))
+            }
+
+            MagicAudioManager.AudioDevice.EARPIECE -> {
+                dialogAudioOutputBinding.audioOutputEarspeakerIcon.setColorFilter(
+                    ContextCompat.getColor(
+                        context,
+                        R.color.colorPrimary
+                    ), android.graphics.PorterDuff.Mode.SRC_IN
+                )
+                dialogAudioOutputBinding.audioOutputEarspeakerText.setTextColor(callActivity.resources.getColor(R.color.colorPrimary))
+            }
+
+            else -> Log.d(TAG, "AudioOutputDialog doesn't know this AudioDevice")
+        }
+    }
 
+    private fun initClickListeners() {
         dialogAudioOutputBinding.audioOutputBluetooth.setOnClickListener {
             callActivity.setAudioOutputChannel(MagicAudioManager.AudioDevice.BLUETOOTH)
             dismiss()

+ 3 - 3
app/src/main/res/layout/dialog_audio_output.xml

@@ -57,7 +57,7 @@
             android:layout_height="wrap_content"
             android:contentDescription="@null"
             android:src="@drawable/ic_baseline_bluetooth_audio_24"
-            app:tint="@color/colorPrimary" />
+            app:tint="#99ffffff" />
 
         <androidx.appcompat.widget.AppCompatTextView
             android:id="@+id/audio_output_bluetooth_text"
@@ -90,7 +90,7 @@
             android:layout_height="wrap_content"
             android:contentDescription="@null"
             android:src="@drawable/ic_volume_up_white_24dp"
-            app:tint="@color/colorPrimary" />
+            app:tint="#99ffffff" />
 
         <androidx.appcompat.widget.AppCompatTextView
             android:id="@+id/audio_output_speaker_text"
@@ -123,7 +123,7 @@
             android:layout_height="wrap_content"
             android:contentDescription="@null"
             android:src="@drawable/ic_baseline_phone_in_talk_24"
-            app:tint="@color/colorPrimary" />
+            app:tint="#99ffffff" />
 
         <androidx.appcompat.widget.AppCompatTextView
             android:id="@+id/audio_output_earspeaker_text"