From 7f0980e6d22c8f0cf8b8504794f54a3476b7da2c Mon Sep 17 00:00:00 2001 From: Marcel Hibbe Date: Tue, 1 Feb 2022 19:14:21 +0100 Subject: [PATCH] format code + fix klint/findbugs warnings remove hardcodings Signed-off-by: Marcel Hibbe remove hardcodings Signed-off-by: Marcel Hibbe --- .../talk/activities/CallActivity.java | 4 +- .../talk/ui/dialog/AudioOutputDialog.kt | 39 ++++---- .../talk/webrtc/MagicAudioManager.java | 88 ++++++++----------- .../drawable/ic_baseline_attachment_24.xml | 26 ------ .../main/res/layout/dialog_audio_output.xml | 24 +++-- app/src/main/res/values/colors.xml | 2 + scripts/analysis/findbugs-results.txt | 2 +- 7 files changed, 78 insertions(+), 107 deletions(-) delete mode 100644 app/src/main/res/drawable/ic_baseline_attachment_24.xml diff --git a/app/src/main/java/com/nextcloud/talk/activities/CallActivity.java b/app/src/main/java/com/nextcloud/talk/activities/CallActivity.java index ef0b9a612..2080ef4af 100644 --- a/app/src/main/java/com/nextcloud/talk/activities/CallActivity.java +++ b/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) { diff --git a/app/src/main/java/com/nextcloud/talk/ui/dialog/AudioOutputDialog.kt b/app/src/main/java/com/nextcloud/talk/ui/dialog/AudioOutputDialog.kt index efb3d65b8..be3976b9c 100644 --- a/app/src/main/java/com/nextcloud/talk/ui/dialog/AudioOutputDialog.kt +++ b/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") diff --git a/app/src/main/java/com/nextcloud/talk/webrtc/MagicAudioManager.java b/app/src/main/java/com/nextcloud/talk/webrtc/MagicAudioManager.java index ff9543401..866e5c6ce 100644 --- a/app/src/main/java/com/nextcloud/talk/webrtc/MagicAudioManager.java +++ b/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 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 availableAudioDevices); + AudioDevice selectedAudioDevice, Set availableAudioDevices); } /* Receiver which handles changes in wired headset availability. */ diff --git a/app/src/main/res/drawable/ic_baseline_attachment_24.xml b/app/src/main/res/drawable/ic_baseline_attachment_24.xml deleted file mode 100644 index 91664a98e..000000000 --- a/app/src/main/res/drawable/ic_baseline_attachment_24.xml +++ /dev/null @@ -1,26 +0,0 @@ - - - - diff --git a/app/src/main/res/layout/dialog_audio_output.xml b/app/src/main/res/layout/dialog_audio_output.xml index 6b136a302..d9a2b8eb1 100644 --- a/app/src/main/res/layout/dialog_audio_output.xml +++ b/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 - ~ Copyright (C) 2021 Marcel Hibbe + ~ Copyright (C) 2022 Marcel Hibbe ~ ~ 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" /> + app:tint="@color/grey_600" /> @@ -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" /> @@ -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" /> @@ -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" /> diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml index 61726802b..b8b7d9532 100644 --- a/app/src/main/res/values/colors.xml +++ b/app/src/main/res/values/colors.xml @@ -78,6 +78,8 @@ #800082C9 #46ffffff + #121212 + #ffffffff #BF999999 #FFCC00 diff --git a/scripts/analysis/findbugs-results.txt b/scripts/analysis/findbugs-results.txt index 8d28c8c9e..4a722e9c7 100644 --- a/scripts/analysis/findbugs-results.txt +++ b/scripts/analysis/findbugs-results.txt @@ -1 +1 @@ -554 \ No newline at end of file +552 \ No newline at end of file