浏览代码

format code + fix klint/findbugs warnings

remove hardcodings

Signed-off-by: Marcel Hibbe <dev@mhibbe.de>

remove hardcodings

Signed-off-by: Marcel Hibbe <dev@mhibbe.de>
Marcel Hibbe 3 年之前
父节点
当前提交
7f0980e6d2

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

@@ -377,8 +377,8 @@ public class CallActivity extends CallBaseActivity {
         boolean camera2EnumeratorIsSupported = false;
         try {
             camera2EnumeratorIsSupported = Camera2Enumerator.isSupported(this);
-        } catch (final Throwable throwable) {
-            Log.w(TAG, "Camera2Enumerator threw an error");
+        } catch (final Throwable t) {
+            Log.w(TAG, "Camera2Enumerator threw an error", t);
         }
 
         if (camera2EnumeratorIsSupported) {

+ 24 - 15
app/src/main/java/com/nextcloud/talk/ui/dialog/AudioOutputDialog.kt

@@ -65,7 +65,10 @@ class AudioOutputDialog(val callActivity: CallActivity) : BottomSheetDialog(call
             dialogAudioOutputBinding.audioOutputSpeaker.visibility = View.VISIBLE
         }
 
-        if (callActivity.audioManager?.currentAudioDevice?.equals(MagicAudioManager.AudioDevice.WIRED_HEADSET) == true) {
+        if (callActivity.audioManager?.currentAudioDevice?.equals(
+                MagicAudioManager.AudioDevice.WIRED_HEADSET
+            ) == true
+        ) {
             dialogAudioOutputBinding.audioOutputEarspeaker.visibility = View.GONE
             dialogAudioOutputBinding.audioOutputSpeaker.visibility = View.GONE
             dialogAudioOutputBinding.audioOutputWiredHeadset.visibility = View.VISIBLE
@@ -81,15 +84,13 @@ class AudioOutputDialog(val callActivity: CallActivity) : BottomSheetDialog(call
             MagicAudioManager.AudioDevice.BLUETOOTH -> {
                 dialogAudioOutputBinding.audioOutputBluetoothIcon.setColorFilter(
                     ContextCompat.getColor(
-                        context, R.color
-                            .colorPrimary
-                    ), android.graphics.PorterDuff.Mode.SRC_IN
+                        context,
+                        R.color.colorPrimary
+                    ),
+                    android.graphics.PorterDuff.Mode.SRC_IN
                 )
                 dialogAudioOutputBinding.audioOutputBluetoothText.setTextColor(
-                    callActivity.resources.getColor(
-                        R.color
-                            .colorPrimary
-                    )
+                    callActivity.resources.getColor(R.color.colorPrimary)
                 )
             }
 
@@ -98,9 +99,12 @@ class AudioOutputDialog(val callActivity: CallActivity) : BottomSheetDialog(call
                     ContextCompat.getColor(
                         context,
                         R.color.colorPrimary
-                    ), android.graphics.PorterDuff.Mode.SRC_IN
+                    ),
+                    android.graphics.PorterDuff.Mode.SRC_IN
+                )
+                dialogAudioOutputBinding.audioOutputSpeakerText.setTextColor(
+                    callActivity.resources.getColor(R.color.colorPrimary)
                 )
-                dialogAudioOutputBinding.audioOutputSpeakerText.setTextColor(callActivity.resources.getColor(R.color.colorPrimary))
             }
 
             MagicAudioManager.AudioDevice.EARPIECE -> {
@@ -108,9 +112,12 @@ class AudioOutputDialog(val callActivity: CallActivity) : BottomSheetDialog(call
                     ContextCompat.getColor(
                         context,
                         R.color.colorPrimary
-                    ), android.graphics.PorterDuff.Mode.SRC_IN
+                    ),
+                    android.graphics.PorterDuff.Mode.SRC_IN
+                )
+                dialogAudioOutputBinding.audioOutputEarspeakerText.setTextColor(
+                    callActivity.resources.getColor(R.color.colorPrimary)
                 )
-                dialogAudioOutputBinding.audioOutputEarspeakerText.setTextColor(callActivity.resources.getColor(R.color.colorPrimary))
             }
 
             MagicAudioManager.AudioDevice.WIRED_HEADSET -> {
@@ -118,10 +125,12 @@ class AudioOutputDialog(val callActivity: CallActivity) : BottomSheetDialog(call
                     ContextCompat.getColor(
                         context,
                         R.color.colorPrimary
-                    ), android.graphics.PorterDuff.Mode.SRC_IN
+                    ),
+                    android.graphics.PorterDuff.Mode.SRC_IN
+                )
+                dialogAudioOutputBinding.audioOutputWiredHeadsetText.setTextColor(
+                    callActivity.resources.getColor(R.color.colorPrimary)
                 )
-                dialogAudioOutputBinding.audioOutputWiredHeadsetText.setTextColor(callActivity.resources.getColor(R.color
-                    .colorPrimary))
             }
 
             else -> Log.d(TAG, "AudioOutputDialog doesn't know this AudioDevice")

+ 38 - 50
app/src/main/java/com/nextcloud/talk/webrtc/MagicAudioManager.java

@@ -41,8 +41,10 @@ import android.media.AudioDeviceInfo;
 import android.media.AudioManager;
 import android.os.Build;
 import android.util.Log;
+
 import com.nextcloud.talk.events.PeerConnectionEvent;
 import com.nextcloud.talk.utils.power.PowerManagerUtils;
+
 import org.greenrobot.eventbus.EventBus;
 import org.webrtc.ThreadUtils;
 
@@ -114,8 +116,8 @@ public class MagicAudioManager {
     }
 
     /**
-     * This method is called when the proximity sensor reports a state change,
-     * e.g. from "NEAR to FAR" or from "FAR to NEAR".
+     * This method is called when the proximity sensor reports a state change, e.g. from "NEAR to FAR" or from "FAR to
+     * NEAR".
      */
     private void onProximitySensorChangedState() {
         if (!useProximitySensor) {
@@ -128,17 +130,17 @@ public class MagicAudioManager {
 
             if (proximitySensor.sensorReportsNearState()) {
                 setAudioDeviceInternal(AudioDevice.EARPIECE);
-                Log.d(TAG,"switched to EARPIECE because userSelectedAudioDevice was SPEAKER_PHONE and proximity=near");
+                Log.d(TAG, "switched to EARPIECE because userSelectedAudioDevice was SPEAKER_PHONE and proximity=near");
 
                 EventBus.getDefault().post(new PeerConnectionEvent(PeerConnectionEvent.PeerConnectionEventType
-                        .SENSOR_NEAR, null, null, null, null));
+                                                                       .SENSOR_NEAR, null, null, null, null));
 
             } else {
                 setAudioDeviceInternal(MagicAudioManager.AudioDevice.SPEAKER_PHONE);
-                Log.d(TAG,"switched to SPEAKER_PHONE because userSelectedAudioDevice was SPEAKER_PHONE and proximity=far");
+                Log.d(TAG, "switched to SPEAKER_PHONE because userSelectedAudioDevice was SPEAKER_PHONE and proximity=far");
 
                 EventBus.getDefault().post(new PeerConnectionEvent(PeerConnectionEvent.PeerConnectionEventType
-                        .SENSOR_FAR, null, null, null, null));
+                                                                       .SENSOR_FAR, null, null, null, null));
             }
         }
     }
@@ -206,7 +208,7 @@ public class MagicAudioManager {
 
         // Request audio playout focus (without ducking) and install listener for changes in focus.
         int result = audioManager.requestAudioFocus(audioFocusChangeListener,
-                AudioManager.STREAM_VOICE_CALL, AudioManager.AUDIOFOCUS_GAIN_TRANSIENT);
+                                                    AudioManager.STREAM_VOICE_CALL, AudioManager.AUDIOFOCUS_GAIN_TRANSIENT);
         if (result == AudioManager.AUDIOFOCUS_REQUEST_GRANTED) {
             Log.d(TAG, "Audio focus request granted for VOICE_CALL streams");
         } else {
@@ -311,15 +313,7 @@ public class MagicAudioManager {
         if (!audioDevices.contains(device)) {
             Log.e(TAG, "Can not select " + device + " from available " + audioDevices);
         }
-
         userSelectedAudioDevice = device;
-
-//        if (device == AudioDevice.SPEAKER_PHONE) {
-//            controlSpeakerByProximitySensor = true;
-//        } else {
-//            controlSpeakerByProximitySensor = false;
-//        }
-
         updateAudioDeviceState();
     }
 
@@ -383,11 +377,9 @@ public class MagicAudioManager {
     }
 
     /**
-     * Checks whether a wired headset is connected or not.
-     * This is not a valid indication that audio playback is actually over
-     * the wired headset as audio routing depends on other conditions. We
-     * only use it as an early indicator (during initialization) of an attached
-     * wired headset.
+     * Checks whether a wired headset is connected or not. This is not a valid indication that audio playback is
+     * actually over the wired headset as audio routing depends on other conditions. We only use it as an early
+     * indicator (during initialization) of an attached wired headset.
      */
     @Deprecated
     private boolean hasWiredHeadset() {
@@ -412,24 +404,24 @@ public class MagicAudioManager {
     public void updateAudioDeviceState() {
         ThreadUtils.checkIsOnMainThread();
         Log.d(TAG, "--- updateAudioDeviceState: "
-                + "wired headset=" + hasWiredHeadset + ", "
-                + "BT state=" + bluetoothManager.getState());
+            + "wired headset=" + hasWiredHeadset + ", "
+            + "BT state=" + bluetoothManager.getState());
         Log.d(TAG, "Device status: "
-                + "available=" + audioDevices + ", "
-                + "current=" + currentAudioDevice + ", "
-                + "user selected=" + userSelectedAudioDevice);
+            + "available=" + audioDevices + ", "
+            + "current=" + currentAudioDevice + ", "
+            + "user selected=" + userSelectedAudioDevice);
 
         if (bluetoothManager.getState() == MagicBluetoothManager.State.HEADSET_AVAILABLE
-                || bluetoothManager.getState() == MagicBluetoothManager.State.HEADSET_UNAVAILABLE
-                || bluetoothManager.getState() == MagicBluetoothManager.State.SCO_DISCONNECTING) {
+            || bluetoothManager.getState() == MagicBluetoothManager.State.HEADSET_UNAVAILABLE
+            || bluetoothManager.getState() == MagicBluetoothManager.State.SCO_DISCONNECTING) {
             bluetoothManager.updateDevice();
         }
 
         Set<AudioDevice> newAudioDevices = new HashSet<>();
 
         if (bluetoothManager.getState() == MagicBluetoothManager.State.SCO_CONNECTED
-                || bluetoothManager.getState() == MagicBluetoothManager.State.SCO_CONNECTING
-                || bluetoothManager.getState() == MagicBluetoothManager.State.HEADSET_AVAILABLE) {
+            || bluetoothManager.getState() == MagicBluetoothManager.State.SCO_CONNECTING
+            || bluetoothManager.getState() == MagicBluetoothManager.State.HEADSET_AVAILABLE) {
             newAudioDevices.add(AudioDevice.BLUETOOTH);
         }
 
@@ -447,7 +439,6 @@ public class MagicAudioManager {
         audioDevices = newAudioDevices;
 
 
-
         // Correct user selected audio devices if needed.
         if (userSelectedAudioDevice == AudioDevice.BLUETOOTH
             && bluetoothManager.getState() == MagicBluetoothManager.State.HEADSET_UNAVAILABLE) {
@@ -461,29 +452,27 @@ public class MagicAudioManager {
         }
 
 
-
-
         // Need to start Bluetooth if it is available and user either selected it explicitly or
         // user did not select any output device.
         boolean needBluetoothAudioStart =
-                bluetoothManager.getState() == MagicBluetoothManager.State.HEADSET_AVAILABLE
-                        && (userSelectedAudioDevice == AudioDevice.NONE
-                        || userSelectedAudioDevice == AudioDevice.BLUETOOTH);
+            bluetoothManager.getState() == MagicBluetoothManager.State.HEADSET_AVAILABLE
+                && (userSelectedAudioDevice == AudioDevice.NONE
+                || userSelectedAudioDevice == AudioDevice.BLUETOOTH);
 
         // Need to stop Bluetooth audio if user selected different device and
         // Bluetooth SCO connection is established or in the process.
         boolean needBluetoothAudioStop =
-                (bluetoothManager.getState() == MagicBluetoothManager.State.SCO_CONNECTED
-                        || bluetoothManager.getState() == MagicBluetoothManager.State.SCO_CONNECTING)
-                        && (userSelectedAudioDevice != AudioDevice.NONE
-                        && userSelectedAudioDevice != AudioDevice.BLUETOOTH);
+            (bluetoothManager.getState() == MagicBluetoothManager.State.SCO_CONNECTED
+                || bluetoothManager.getState() == MagicBluetoothManager.State.SCO_CONNECTING)
+                && (userSelectedAudioDevice != AudioDevice.NONE
+                && userSelectedAudioDevice != AudioDevice.BLUETOOTH);
 
         if (bluetoothManager.getState() == MagicBluetoothManager.State.HEADSET_AVAILABLE
-                || bluetoothManager.getState() == MagicBluetoothManager.State.SCO_CONNECTING
-                || bluetoothManager.getState() == MagicBluetoothManager.State.SCO_CONNECTED) {
+            || bluetoothManager.getState() == MagicBluetoothManager.State.SCO_CONNECTING
+            || bluetoothManager.getState() == MagicBluetoothManager.State.SCO_CONNECTED) {
             Log.d(TAG, "Need BT audio: start=" + needBluetoothAudioStart + ", "
-                    + "stop=" + needBluetoothAudioStop + ", "
-                    + "BT state=" + bluetoothManager.getState());
+                + "stop=" + needBluetoothAudioStop + ", "
+                + "BT state=" + bluetoothManager.getState());
         }
 
         // Start or stop Bluetooth SCO connection given states set earlier.
@@ -494,8 +483,8 @@ public class MagicAudioManager {
 
         // Attempt to start Bluetooth SCO audio (takes a few second to start).
         if (needBluetoothAudioStart &&
-                !needBluetoothAudioStop &&
-                !bluetoothManager.startScoAudio()) {
+            !needBluetoothAudioStop &&
+            !bluetoothManager.startScoAudio()) {
             // Remove BLUETOOTH from list of available devices since SCO failed.
             audioDevices.remove(AudioDevice.BLUETOOTH);
             audioDeviceSetUpdated = true;
@@ -526,8 +515,8 @@ public class MagicAudioManager {
             // Do the required device switch.
             setAudioDeviceInternal(newCurrentAudioDevice);
             Log.d(TAG, "New device status: "
-                    + "available=" + audioDevices + ", "
-                    + "current(new)=" + newCurrentAudioDevice);
+                + "available=" + audioDevices + ", "
+                + "current(new)=" + newCurrentAudioDevice);
             if (audioManagerListener != null) {
                 // Notify a listening client that audio device has been changed.
                 audioManagerListener.onAudioDeviceChanged(currentAudioDevice, audioDevices);
@@ -537,8 +526,7 @@ public class MagicAudioManager {
     }
 
     /**
-     * AudioDevice is the names of possible audio devices that we currently
-     * support.
+     * AudioDevice is the names of possible audio devices that we currently support.
      */
     public enum AudioDevice {
         SPEAKER_PHONE, WIRED_HEADSET, EARPIECE, BLUETOOTH, NONE
@@ -559,7 +547,7 @@ public class MagicAudioManager {
     public static interface AudioManagerListener {
         // Callback fired once audio device is changed or list of available audio devices changed.
         void onAudioDeviceChanged(
-                AudioDevice selectedAudioDevice, Set<AudioDevice> availableAudioDevices);
+            AudioDevice selectedAudioDevice, Set<AudioDevice> availableAudioDevices);
     }
 
     /* Receiver which handles changes in wired headset availability. */

+ 0 - 26
app/src/main/res/drawable/ic_baseline_attachment_24.xml

@@ -1,26 +0,0 @@
-<!--
-    @author Google LLC
-    Copyright (C) 2021 Google LLC
-
-    Licensed under the Apache License, Version 2.0 (the "License");
-    you may not use this file except in compliance with the License.
-    You may obtain a copy of the License at
-
-    http://www.apache.org/licenses/LICENSE-2.0
-
-    Unless required by applicable law or agreed to in writing, software
-    distributed under the License is distributed on an "AS IS" BASIS,
-    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-    See the License for the specific language governing permissions and
-    limitations under the License.
--->
-<vector xmlns:android="http://schemas.android.com/apk/res/android"
-    android:width="24dp"
-    android:height="24dp"
-    android:viewportWidth="24"
-    android:viewportHeight="24"
-    android:tint="?attr/colorControlNormal">
-  <path
-      android:fillColor="@android:color/white"
-      android:pathData="M2,12.5C2,9.46 4.46,7 7.5,7H18c2.21,0 4,1.79 4,4s-1.79,4 -4,4H9.5C8.12,15 7,13.88 7,12.5S8.12,10 9.5,10H17v2H9.41c-0.55,0 -0.55,1 0,1H18c1.1,0 2,-0.9 2,-2s-0.9,-2 -2,-2H7.5C5.57,9 4,10.57 4,12.5S5.57,16 7.5,16H17v2H7.5C4.46,18 2,15.54 2,12.5z"/>
-</vector>

+ 11 - 13
app/src/main/res/layout/dialog_audio_output.xml

@@ -2,9 +2,7 @@
   ~ Nextcloud Talk application
   ~
   ~ @author Marcel Hibbe
-  ~ @author Andy Scherzinger
-  ~ Copyright (C) 2021 Andy Scherzinger <info@andy-scherzinger.de>
-  ~ Copyright (C) 2021 Marcel Hibbe <marcel.hibbe@nextcloud.com>
+  ~ Copyright (C) 2022 Marcel Hibbe <marcel.hibbe@nextcloud.com>
   ~
   ~ 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
@@ -25,7 +23,7 @@
     xmlns:tools="http://schemas.android.com/tools"
     android:layout_width="match_parent"
     android:layout_height="wrap_content"
-    android:background="#121212"
+    android:background="@color/bg_call_screen_dialog"
     android:orientation="vertical"
     android:paddingBottom="@dimen/standard_padding">
 
@@ -36,7 +34,7 @@
         android:padding="@dimen/standard_padding"
         android:text="@string/audio_output_dialog_headline"
         android:textAlignment="viewStart"
-        android:textColor="#99ffffff"
+        android:textColor="@color/grey_600"
         android:textSize="@dimen/bottom_sheet_text_size" />
 
     <LinearLayout
@@ -57,7 +55,7 @@
             android:layout_height="wrap_content"
             android:contentDescription="@null"
             android:src="@drawable/ic_baseline_bluetooth_audio_24"
-            app:tint="#99ffffff" />
+            app:tint="@color/grey_600" />
 
         <androidx.appcompat.widget.AppCompatTextView
             android:id="@+id/audio_output_bluetooth_text"
@@ -67,7 +65,7 @@
             android:layout_marginStart="@dimen/standard_margin"
             android:text="@string/audio_output_bluetooth"
             android:textAlignment="viewStart"
-            android:textColor="#99ffffff"
+            android:textColor="@color/call_screen_text"
             android:textSize="@dimen/bottom_sheet_text_size" />
 
     </LinearLayout>
@@ -90,7 +88,7 @@
             android:layout_height="wrap_content"
             android:contentDescription="@null"
             android:src="@drawable/ic_volume_up_white_24dp"
-            app:tint="#99ffffff" />
+            app:tint="@color/grey_600" />
 
         <androidx.appcompat.widget.AppCompatTextView
             android:id="@+id/audio_output_speaker_text"
@@ -100,7 +98,7 @@
             android:layout_marginStart="@dimen/standard_margin"
             android:text="@string/audio_output_speaker"
             android:textAlignment="viewStart"
-            android:textColor="#99ffffff"
+            android:textColor="@color/call_screen_text"
             android:textSize="@dimen/bottom_sheet_text_size" />
 
     </LinearLayout>
@@ -123,7 +121,7 @@
             android:layout_height="wrap_content"
             android:contentDescription="@null"
             android:src="@drawable/ic_baseline_phone_in_talk_24"
-            app:tint="#99ffffff" />
+            app:tint="@color/grey_600" />
 
         <androidx.appcompat.widget.AppCompatTextView
             android:id="@+id/audio_output_earspeaker_text"
@@ -133,7 +131,7 @@
             android:layout_marginStart="@dimen/standard_margin"
             android:text="@string/audio_output_phone"
             android:textAlignment="viewStart"
-            android:textColor="#99ffffff"
+            android:textColor="@color/call_screen_text"
             android:textSize="@dimen/bottom_sheet_text_size" />
 
     </LinearLayout>
@@ -156,7 +154,7 @@
             android:layout_height="wrap_content"
             android:contentDescription="@null"
             android:src="@drawable/ic_baseline_headset_mic_24"
-            app:tint="#99ffffff" />
+            app:tint="@color/grey_600" />
 
         <androidx.appcompat.widget.AppCompatTextView
             android:id="@+id/audio_output_wired_headset_text"
@@ -166,7 +164,7 @@
             android:layout_marginStart="@dimen/standard_margin"
             android:text="@string/audio_output_wired_headset"
             android:textAlignment="viewStart"
-            android:textColor="#99ffffff"
+            android:textColor="@color/call_screen_text"
             android:textSize="@dimen/bottom_sheet_text_size" />
 
     </LinearLayout>

+ 2 - 0
app/src/main/res/values/colors.xml

@@ -78,6 +78,8 @@
     <color name="bg_message_list_outcoming_bubble_deleted">#800082C9</color>
 
     <color name="bg_bottom_sheet">#46ffffff</color>
+    <color name="bg_call_screen_dialog">#121212</color>
+    <color name="call_screen_text">#ffffffff</color>
 
     <color name="call_buttons_background">#BF999999</color>
     <color name="favorite_icon_tint">#FFCC00</color>

+ 1 - 1
scripts/analysis/findbugs-results.txt

@@ -1 +1 @@
-554
+552