mirror of
https://github.com/nextcloud/talk-android.git
synced 2024-11-27 08:55:54 +03:00
parent
482e91655c
commit
ca31e5e967
5 changed files with 123 additions and 16 deletions
|
@ -72,6 +72,7 @@ import com.nextcloud.talk.models.json.signaling.SignalingOverall;
|
|||
import com.nextcloud.talk.models.json.signaling.settings.IceServer;
|
||||
import com.nextcloud.talk.models.json.signaling.settings.SignalingSettingsOverall;
|
||||
import com.nextcloud.talk.utils.ApiUtils;
|
||||
import com.nextcloud.talk.utils.MagicFlipView;
|
||||
import com.nextcloud.talk.utils.animations.PulseAnimation;
|
||||
import com.nextcloud.talk.utils.bundle.BundleKeys;
|
||||
import com.nextcloud.talk.utils.database.user.UserUtils;
|
||||
|
@ -152,6 +153,9 @@ public class CallController extends BaseController {
|
|||
Manifest.permission.RECORD_AUDIO
|
||||
};
|
||||
|
||||
@BindView(R.id.callControlEnableSpeaker)
|
||||
MagicFlipView callControlEnableSpeaker;
|
||||
|
||||
@BindView(R.id.pip_video_view)
|
||||
SurfaceViewRenderer pipVideoView;
|
||||
@BindView(R.id.relative_layout)
|
||||
|
@ -300,6 +304,10 @@ public class CallController extends BaseController {
|
|||
Log.e(TAG, "Failed to evict cache");
|
||||
}
|
||||
|
||||
if (isVoiceOnlyCall) {
|
||||
callControlEnableSpeaker.setVisibility(View.VISIBLE);
|
||||
}
|
||||
|
||||
callControls.setZ(100.0f);
|
||||
basicInitialization();
|
||||
|
||||
|
@ -330,7 +338,7 @@ public class CallController extends BaseController {
|
|||
|
||||
// Create and audio manager that will take care of audio routing,
|
||||
// audio modes, audio device enumeration etc.
|
||||
audioManager = MagicAudioManager.create(getApplicationContext());
|
||||
audioManager = MagicAudioManager.create(getApplicationContext(), !isVoiceOnlyCall);
|
||||
// Store existing audio settings and change audio mode to
|
||||
// MODE_IN_COMMUNICATION for best possible VoIP performance.
|
||||
Log.d(TAG, "Starting the audio manager...");
|
||||
|
@ -422,7 +430,7 @@ public class CallController extends BaseController {
|
|||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||
requestPermissions(PERMISSIONS_CALL, 100);
|
||||
} else {
|
||||
onRequestPermissionsResult(100, PERMISSIONS_CALL, new int[]{1});
|
||||
onRequestPermissionsResult(100, PERMISSIONS_CALL, new int[]{1, 1});
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -586,6 +594,20 @@ public class CallController extends BaseController {
|
|||
return true;
|
||||
}
|
||||
|
||||
@OnClick(R.id.callControlEnableSpeaker)
|
||||
public void onEnableSpeakerphoneClick() {
|
||||
if (audioManager != null) {
|
||||
audioManager.toggleUseSpeakerphone();
|
||||
if (audioManager.isSpeakerphoneAutoOn()) {
|
||||
callControlEnableSpeaker.getFrontImageView().setImageDrawable(getResources().getDrawable(R.drawable
|
||||
.ic_speaker_white_24dp));
|
||||
} else {
|
||||
callControlEnableSpeaker.getFrontImageView().setImageDrawable(getResources().getDrawable(R.drawable
|
||||
.ic_hearing_white_24dp));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@OnClick(R.id.call_control_microphone)
|
||||
public void onMicrophoneClick() {
|
||||
if (getActivity() != null && EffortlessPermissions.hasPermissions(getActivity(), PERMISSIONS_MICROPHONE)) {
|
||||
|
|
|
@ -59,7 +59,7 @@ public class MagicAudioManager {
|
|||
private static final String SPEAKERPHONE_FALSE = "false";
|
||||
private final Context magicContext;
|
||||
// Contains speakerphone setting: auto, true or false
|
||||
private final String useSpeakerphone;
|
||||
private String useSpeakerphone;
|
||||
// Handles all tasks related to Bluetooth headset devices.
|
||||
private final MagicBluetoothManager bluetoothManager;
|
||||
private AudioManager audioManager;
|
||||
|
@ -96,7 +96,23 @@ public class MagicAudioManager {
|
|||
// Callback method for changes in audio focus.
|
||||
private AudioManager.OnAudioFocusChangeListener audioFocusChangeListener;
|
||||
|
||||
private MagicAudioManager(Context context) {
|
||||
public void toggleUseSpeakerphone() {
|
||||
if (useSpeakerphone.equals(SPEAKERPHONE_FALSE)) {
|
||||
useSpeakerphone = SPEAKERPHONE_AUTO;
|
||||
setDefaultAudioDevice(AudioDevice.SPEAKER_PHONE);
|
||||
} else {
|
||||
useSpeakerphone = SPEAKERPHONE_FALSE;
|
||||
setDefaultAudioDevice(AudioDevice.EARPIECE);
|
||||
}
|
||||
|
||||
updateAudioDeviceState();
|
||||
}
|
||||
|
||||
public boolean isSpeakerphoneAutoOn() {
|
||||
return (useSpeakerphone.equals(SPEAKERPHONE_AUTO));
|
||||
}
|
||||
|
||||
private MagicAudioManager(Context context, boolean useProximitySensor) {
|
||||
Log.d(TAG, "ctor");
|
||||
ThreadUtils.checkIsOnMainThread();
|
||||
magicContext = context;
|
||||
|
@ -105,7 +121,13 @@ public class MagicAudioManager {
|
|||
wiredHeadsetReceiver = new WiredHeadsetReceiver();
|
||||
amState = AudioManagerState.UNINITIALIZED;
|
||||
|
||||
useSpeakerphone = SPEAKERPHONE_AUTO;
|
||||
if (useProximitySensor) {
|
||||
useSpeakerphone = SPEAKERPHONE_AUTO;
|
||||
} else {
|
||||
useSpeakerphone = SPEAKERPHONE_FALSE;
|
||||
}
|
||||
|
||||
|
||||
if (useSpeakerphone.equals(SPEAKERPHONE_FALSE)) {
|
||||
defaultAudioDevice = AudioDevice.EARPIECE;
|
||||
} else {
|
||||
|
@ -130,8 +152,8 @@ public class MagicAudioManager {
|
|||
/**
|
||||
* Construction.
|
||||
*/
|
||||
public static MagicAudioManager create(Context context) {
|
||||
return new MagicAudioManager(context);
|
||||
public static MagicAudioManager create(Context context, boolean useProximitySensor) {
|
||||
return new MagicAudioManager(context, useProximitySensor);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -140,14 +162,6 @@ public class MagicAudioManager {
|
|||
*/
|
||||
private void onProximitySensorChangedState() {
|
||||
|
||||
if (proximitySensor.sensorReportsNearState()) {
|
||||
EventBus.getDefault().post(new PeerConnectionEvent(PeerConnectionEvent.PeerConnectionEventType
|
||||
.SENSOR_NEAR, null, null, null));
|
||||
} else {
|
||||
EventBus.getDefault().post(new PeerConnectionEvent(PeerConnectionEvent.PeerConnectionEventType
|
||||
.SENSOR_FAR, null, null, null));
|
||||
}
|
||||
|
||||
if (!useSpeakerphone.equals(SPEAKERPHONE_AUTO)) {
|
||||
return;
|
||||
}
|
||||
|
@ -160,10 +174,17 @@ public class MagicAudioManager {
|
|||
// Sensor reports that a "handset is being held up to a person's ear",
|
||||
// or "something is covering the light sensor".
|
||||
setAudioDeviceInternal(MagicAudioManager.AudioDevice.EARPIECE);
|
||||
|
||||
EventBus.getDefault().post(new PeerConnectionEvent(PeerConnectionEvent.PeerConnectionEventType
|
||||
.SENSOR_FAR, null, null, null));
|
||||
|
||||
} else {
|
||||
// Sensor reports that a "handset is removed from a person's ear", or
|
||||
// "the light sensor is no longer covered".
|
||||
setAudioDeviceInternal(MagicAudioManager.AudioDevice.SPEAKER_PHONE);
|
||||
|
||||
EventBus.getDefault().post(new PeerConnectionEvent(PeerConnectionEvent.PeerConnectionEventType
|
||||
.SENSOR_NEAR, null, null, null));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
25
app/src/main/res/drawable/ic_hearing_white_24dp.xml
Normal file
25
app/src/main/res/drawable/ic_hearing_white_24dp.xml
Normal file
|
@ -0,0 +1,25 @@
|
|||
<!--
|
||||
~ Nextcloud Talk application
|
||||
~
|
||||
~ @author Mario Danic
|
||||
~ Copyright (C) 2017-2018 Mario Danic <mario@lovelyhq.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
|
||||
~ 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/>.
|
||||
-->
|
||||
|
||||
<vector android:autoMirrored="true" android:height="24dp"
|
||||
android:tint="#FFFFFF" android:viewportHeight="24.0"
|
||||
android:viewportWidth="24.0" android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<path android:fillColor="#FF000000" android:pathData="M17,20c-0.29,0 -0.56,-0.06 -0.76,-0.15 -0.71,-0.37 -1.21,-0.88 -1.71,-2.38 -0.51,-1.56 -1.47,-2.29 -2.39,-3 -0.79,-0.61 -1.61,-1.24 -2.32,-2.53C9.29,10.98 9,9.93 9,9c0,-2.8 2.2,-5 5,-5s5,2.2 5,5h2c0,-3.93 -3.07,-7 -7,-7S7,5.07 7,9c0,1.26 0.38,2.65 1.07,3.9 0.91,1.65 1.98,2.48 2.85,3.15 0.81,0.62 1.39,1.07 1.71,2.05 0.6,1.82 1.37,2.84 2.73,3.55 0.51,0.23 1.07,0.35 1.64,0.35 2.21,0 4,-1.79 4,-4h-2c0,1.1 -0.9,2 -2,2zM7.64,2.64L6.22,1.22C4.23,3.21 3,5.96 3,9s1.23,5.79 3.22,7.78l1.41,-1.41C6.01,13.74 5,11.49 5,9s1.01,-4.74 2.64,-6.36zM11.5,9c0,1.38 1.12,2.5 2.5,2.5s2.5,-1.12 2.5,-2.5 -1.12,-2.5 -2.5,-2.5 -2.5,1.12 -2.5,2.5z"/>
|
||||
</vector>
|
26
app/src/main/res/drawable/ic_speaker_white_24dp.xml
Normal file
26
app/src/main/res/drawable/ic_speaker_white_24dp.xml
Normal file
|
@ -0,0 +1,26 @@
|
|||
<!--
|
||||
~ Nextcloud Talk application
|
||||
~
|
||||
~ @author Mario Danic
|
||||
~ Copyright (C) 2017-2018 Mario Danic <mario@lovelyhq.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
|
||||
~ 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/>.
|
||||
-->
|
||||
|
||||
<vector android:autoMirrored="true" android:height="24dp"
|
||||
android:tint="#FFFFFF" android:viewportHeight="24.0"
|
||||
android:viewportWidth="24.0" android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<path android:fillColor="#FFFFFF"
|
||||
android:pathData="M17,2L7,2c-1.1,0 -2,0.9 -2,2v16c0,1.1 0.9,1.99 2,1.99L17,22c1.1,0 2,-0.9 2,-2L19,4c0,-1.1 -0.9,-2 -2,-2zM12,4c1.1,0 2,0.9 2,2s-0.9,2 -2,2c-1.11,0 -2,-0.9 -2,-2s0.89,-2 2,-2zM12,20c-2.76,0 -5,-2.24 -5,-5s2.24,-5 5,-5 5,2.24 5,5 -2.24,5 -5,5zM12,12c-1.66,0 -3,1.34 -3,3s1.34,3 3,3 3,-1.34 3,-3 -1.34,-3 -3,-3z"/>
|
||||
</vector>
|
|
@ -140,6 +140,19 @@
|
|||
app:enableInitialAnimation="false"
|
||||
app:frontBackgroundColor="@color/nc_darkRed"
|
||||
app:frontImage="@drawable/ic_call_end_white_24px"/>
|
||||
|
||||
<com.nextcloud.talk.utils.MagicFlipView
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:id="@+id/callControlEnableSpeaker"
|
||||
android:layout_width="60dp"
|
||||
android:layout_height="60dp"
|
||||
android:layout_marginStart="20dp"
|
||||
app:checked="false"
|
||||
android:visibility="gone"
|
||||
app:enableInitialAnimation="false"
|
||||
app:frontBackgroundColor="@color/colorPrimary"
|
||||
app:frontImage="@drawable/ic_hearing_white_24dp"/>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</RelativeLayout>
|
||||
</RelativeLayout>
|
||||
|
|
Loading…
Reference in a new issue