mirror of
https://github.com/nextcloud/talk-android
synced 2025-07-11 14:54:09 +01:00
Better permissions support
Signed-off-by: Mario Danic <mario@lovelyhq.com>
This commit is contained in:
parent
55a6bb8d61
commit
32308d8c55
@ -144,8 +144,6 @@ public class CallActivity extends AppCompatActivity {
|
|||||||
|
|
||||||
@BindView(R.id.pip_video_view)
|
@BindView(R.id.pip_video_view)
|
||||||
SurfaceViewRenderer pipVideoView;
|
SurfaceViewRenderer pipVideoView;
|
||||||
@BindView(R.id.full_screen_surface_view)
|
|
||||||
SurfaceViewRenderer fullScreenVideoView;
|
|
||||||
@BindView(R.id.relative_layout)
|
@BindView(R.id.relative_layout)
|
||||||
RelativeLayout relativeLayout;
|
RelativeLayout relativeLayout;
|
||||||
@BindView(R.id.remote_renderers_layout)
|
@BindView(R.id.remote_renderers_layout)
|
||||||
@ -300,8 +298,10 @@ public class CallActivity extends AppCompatActivity {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
MagicPeerConnectionWrapper magicPeerConnectionWrapper;
|
||||||
for (int i = 0; i < magicPeerConnectionWrapperList.size(); i++) {
|
for (int i = 0; i < magicPeerConnectionWrapperList.size(); i++) {
|
||||||
magicPeerConnectionWrapperList.get(i).sendChannelData(new DataChannelMessage(message));
|
magicPeerConnectionWrapper = magicPeerConnectionWrapperList.get(i);
|
||||||
|
magicPeerConnectionWrapper.sendChannelData(new DataChannelMessage(message));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -318,7 +318,7 @@ public class CallActivity extends AppCompatActivity {
|
|||||||
|
|
||||||
toggleMedia(audioOn, false);
|
toggleMedia(audioOn, false);
|
||||||
} else if (EffortlessPermissions.somePermissionPermanentlyDenied(this, PERMISSIONS_MICROPHONE)) {
|
} else if (EffortlessPermissions.somePermissionPermanentlyDenied(this, PERMISSIONS_MICROPHONE)) {
|
||||||
// Some permission is permanently denied so we cannot request them normally.
|
// Microphone permission is permanently denied so we cannot request it normally.
|
||||||
OpenAppDetailsDialogFragment.show(
|
OpenAppDetailsDialogFragment.show(
|
||||||
R.string.nc_microphone_permission_permanently_denied,
|
R.string.nc_microphone_permission_permanently_denied,
|
||||||
R.string.nc_permissions_settings, this);
|
R.string.nc_permissions_settings, this);
|
||||||
@ -347,7 +347,7 @@ public class CallActivity extends AppCompatActivity {
|
|||||||
|
|
||||||
toggleMedia(videoOn, true);
|
toggleMedia(videoOn, true);
|
||||||
} else if (EffortlessPermissions.somePermissionPermanentlyDenied(this, PERMISSIONS_CAMERA)) {
|
} else if (EffortlessPermissions.somePermissionPermanentlyDenied(this, PERMISSIONS_CAMERA)) {
|
||||||
// Some permission is permanently denied so we cannot request them normally.
|
// Camera permission is permanently denied so we cannot request it normally.
|
||||||
OpenAppDetailsDialogFragment.show(
|
OpenAppDetailsDialogFragment.show(
|
||||||
R.string.nc_camera_permission_permanently_denied,
|
R.string.nc_camera_permission_permanently_denied,
|
||||||
R.string.nc_permissions_settings, this);
|
R.string.nc_permissions_settings, this);
|
||||||
@ -414,18 +414,10 @@ public class CallActivity extends AppCompatActivity {
|
|||||||
|
|
||||||
// setting this to true because it's not shown by default
|
// setting this to true because it's not shown by default
|
||||||
pipVideoView.setMirror(true);
|
pipVideoView.setMirror(true);
|
||||||
rootEglBase = EglBase.create();
|
|
||||||
pipVideoView.init(rootEglBase.getEglBaseContext(), null);
|
pipVideoView.init(rootEglBase.getEglBaseContext(), null);
|
||||||
pipVideoView.setZOrderMediaOverlay(true);
|
pipVideoView.setZOrderMediaOverlay(true);
|
||||||
pipVideoView.setEnableHardwareScaler(true);
|
pipVideoView.setEnableHardwareScaler(true);
|
||||||
pipVideoView.setScalingType(RendererCommon.ScalingType.SCALE_ASPECT_FIT);
|
pipVideoView.setScalingType(RendererCommon.ScalingType.SCALE_ASPECT_FIT);
|
||||||
|
|
||||||
fullScreenVideoView.setMirror(true);
|
|
||||||
fullScreenVideoView.init(rootEglBase.getEglBaseContext(), null);
|
|
||||||
fullScreenVideoView.setZOrderMediaOverlay(true);
|
|
||||||
fullScreenVideoView.setEnableHardwareScaler(true);
|
|
||||||
fullScreenVideoView.setScalingType(RendererCommon.ScalingType.SCALE_ASPECT_FILL);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@AfterPermissionGranted(100)
|
@AfterPermissionGranted(100)
|
||||||
@ -433,10 +425,12 @@ public class CallActivity extends AppCompatActivity {
|
|||||||
if (EffortlessPermissions.hasPermissions(this, PERMISSIONS_CALL)) {
|
if (EffortlessPermissions.hasPermissions(this, PERMISSIONS_CALL)) {
|
||||||
if (!cameraInitialized) {
|
if (!cameraInitialized) {
|
||||||
cameraInitialization();
|
cameraInitialization();
|
||||||
|
onCameraClick();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!microphoneInitialized) {
|
if (!microphoneInitialized) {
|
||||||
microphoneInitialization();
|
microphoneInitialization();
|
||||||
|
onMicrophoneClick();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!inCall) {
|
if (!inCall) {
|
||||||
@ -448,16 +442,15 @@ public class CallActivity extends AppCompatActivity {
|
|||||||
cameraInitialization();
|
cameraInitialization();
|
||||||
onCameraClick();
|
onCameraClick();
|
||||||
} else if (!EffortlessPermissions.hasPermissions(this, PERMISSIONS_CAMERA)) {
|
} else if (!EffortlessPermissions.hasPermissions(this, PERMISSIONS_CAMERA)) {
|
||||||
cameraControlButton.setImageResource(R.drawable.ic_videocam_off_white_24px);
|
cameraControlButton.setVisibility(View.GONE);
|
||||||
cameraSwitchButton.setEnabled(false);
|
cameraSwitchButton.setVisibility(View.GONE);
|
||||||
cameraSwitchButton.setAlpha(0.5f);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (EffortlessPermissions.hasPermissions(this, PERMISSIONS_MICROPHONE)) {
|
if (EffortlessPermissions.hasPermissions(this, PERMISSIONS_MICROPHONE)) {
|
||||||
microphoneInitialization();
|
microphoneInitialization();
|
||||||
onMicrophoneClick();
|
onMicrophoneClick();
|
||||||
} else if (!EffortlessPermissions.hasPermissions(this, PERMISSIONS_MICROPHONE)) {
|
} else if (!EffortlessPermissions.hasPermissions(this, PERMISSIONS_MICROPHONE)) {
|
||||||
microphoneControlButton.setImageResource(R.drawable.ic_mic_off_white_24px);
|
microphoneControlButton.setVisibility(View.GONE);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!inCall) {
|
if (!inCall) {
|
||||||
@ -472,12 +465,17 @@ public class CallActivity extends AppCompatActivity {
|
|||||||
|
|
||||||
@AfterPermissionDenied(100)
|
@AfterPermissionDenied(100)
|
||||||
private void onPermissionsDenied() {
|
private void onPermissionsDenied() {
|
||||||
|
microphoneControlButton.setVisibility(View.GONE);
|
||||||
|
cameraControlButton.setVisibility(View.GONE);
|
||||||
|
cameraSwitchButton.setVisibility(View.GONE);
|
||||||
if (!inCall) {
|
if (!inCall) {
|
||||||
startCall();
|
startCall();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void basicInitialization() {
|
private void basicInitialization() {
|
||||||
|
rootEglBase = EglBase.create();
|
||||||
|
|
||||||
//Initialize PeerConnectionFactory globals.
|
//Initialize PeerConnectionFactory globals.
|
||||||
PeerConnectionFactory.InitializationOptions initializationOptions = PeerConnectionFactory.InitializationOptions
|
PeerConnectionFactory.InitializationOptions initializationOptions = PeerConnectionFactory.InitializationOptions
|
||||||
.builder(this)
|
.builder(this)
|
||||||
@ -489,6 +487,9 @@ public class CallActivity extends AppCompatActivity {
|
|||||||
PeerConnectionFactory.Options options = new PeerConnectionFactory.Options();
|
PeerConnectionFactory.Options options = new PeerConnectionFactory.Options();
|
||||||
peerConnectionFactory = new PeerConnectionFactory(options);
|
peerConnectionFactory = new PeerConnectionFactory(options);
|
||||||
|
|
||||||
|
peerConnectionFactory.setVideoHwAccelerationOptions(rootEglBase.getEglBaseContext(),
|
||||||
|
rootEglBase.getEglBaseContext());
|
||||||
|
|
||||||
//Create MediaConstraints - Will be useful for specifying video and audio constraints.
|
//Create MediaConstraints - Will be useful for specifying video and audio constraints.
|
||||||
audioConstraints = new MediaConstraints();
|
audioConstraints = new MediaConstraints();
|
||||||
videoConstraints = new MediaConstraints();
|
videoConstraints = new MediaConstraints();
|
||||||
@ -528,11 +529,13 @@ public class CallActivity extends AppCompatActivity {
|
|||||||
localMediaStream.addTrack(localVideoTrack);
|
localMediaStream.addTrack(localVideoTrack);
|
||||||
|
|
||||||
//create a videoRenderer based on SurfaceViewRenderer instance
|
//create a videoRenderer based on SurfaceViewRenderer instance
|
||||||
localRenderer = new VideoRenderer(fullScreenVideoView);
|
localRenderer = new VideoRenderer(pipVideoView);
|
||||||
// And finally, with our VideoRenderer ready, we
|
// And finally, with our VideoRenderer ready, we
|
||||||
// can add our renderer to the VideoTrack.
|
// can add our renderer to the VideoTrack.
|
||||||
localVideoTrack.addRenderer(localRenderer);
|
localVideoTrack.addRenderer(localRenderer);
|
||||||
|
|
||||||
|
cameraSwitchButton.setVisibility(View.VISIBLE);
|
||||||
|
|
||||||
cameraInitialized = true;
|
cameraInitialized = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -552,7 +555,7 @@ public class CallActivity extends AppCompatActivity {
|
|||||||
registerNetworkReceiver();
|
registerNetworkReceiver();
|
||||||
}
|
}
|
||||||
|
|
||||||
@OnClick({R.id.full_screen_surface_view, R.id.remote_renderers_layout})
|
@OnClick({R.id.pip_video_view, R.id.remote_renderers_layout})
|
||||||
public void showCallControls() {
|
public void showCallControls() {
|
||||||
if (callControls.getVisibility() != View.VISIBLE) {
|
if (callControls.getVisibility() != View.VISIBLE) {
|
||||||
animateCallControls(true, 0);
|
animateCallControls(true, 0);
|
||||||
@ -1010,15 +1013,6 @@ public class CallActivity extends AppCompatActivity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void gotRemoteStream(MediaStream stream, String session) {
|
private void gotRemoteStream(MediaStream stream, String session) {
|
||||||
if (fullScreenVideoView != null) {
|
|
||||||
remoteRenderersLayout.setVisibility(View.VISIBLE);
|
|
||||||
pipVideoView.setVisibility(View.VISIBLE);
|
|
||||||
localVideoTrack.removeRenderer(localRenderer);
|
|
||||||
localRenderer = new VideoRenderer(pipVideoView);
|
|
||||||
localVideoTrack.addRenderer(localRenderer);
|
|
||||||
relativeLayout.removeView(fullScreenVideoView);
|
|
||||||
}
|
|
||||||
|
|
||||||
removeMediaStream(session);
|
removeMediaStream(session);
|
||||||
|
|
||||||
if (stream.videoTracks.size() == 1) {
|
if (stream.videoTracks.size() == 1) {
|
||||||
@ -1032,13 +1026,12 @@ public class CallActivity extends AppCompatActivity {
|
|||||||
.surface_view);
|
.surface_view);
|
||||||
surfaceViewRenderer.setMirror(false);
|
surfaceViewRenderer.setMirror(false);
|
||||||
surfaceViewRenderer.init(rootEglBase.getEglBaseContext(), null);
|
surfaceViewRenderer.init(rootEglBase.getEglBaseContext(), null);
|
||||||
surfaceViewRenderer.setZOrderMediaOverlay(true);
|
surfaceViewRenderer.setZOrderMediaOverlay(false);
|
||||||
surfaceViewRenderer.setEnableHardwareScaler(true);
|
surfaceViewRenderer.setEnableHardwareScaler(true);
|
||||||
surfaceViewRenderer.setScalingType(RendererCommon.ScalingType.SCALE_ASPECT_FIT);
|
surfaceViewRenderer.setScalingType(RendererCommon.ScalingType.SCALE_ASPECT_FIT);
|
||||||
VideoRenderer remoteRenderer = new VideoRenderer(surfaceViewRenderer);
|
VideoRenderer remoteRenderer = new VideoRenderer(surfaceViewRenderer);
|
||||||
videoTrack.addRenderer(remoteRenderer);
|
videoTrack.addRenderer(remoteRenderer);
|
||||||
remoteRenderersLayout.addView(relativeLayout);
|
remoteRenderersLayout.addView(relativeLayout);
|
||||||
relativeLayout.invalidate();
|
|
||||||
gotNick(session, getPeerConnectionWrapperForSessionId(session).getNick());
|
gotNick(session, getPeerConnectionWrapperForSessionId(session).getNick());
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
Log.d(TAG, "Failed to create a new video view");
|
Log.d(TAG, "Failed to create a new video view");
|
||||||
@ -1073,14 +1066,16 @@ public class CallActivity extends AppCompatActivity {
|
|||||||
public void onStart() {
|
public void onStart() {
|
||||||
super.onStart();
|
super.onStart();
|
||||||
eventBus.register(this);
|
eventBus.register(this);
|
||||||
startVideoCapture();
|
if (videoOn && cameraInitialized) {
|
||||||
|
startVideoCapture();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onStop() {
|
public void onStop() {
|
||||||
super.onStop();
|
super.onStop();
|
||||||
eventBus.unregister(this);
|
eventBus.unregister(this);
|
||||||
if (videoCapturer != null) {
|
if (videoCapturer != null && videoOn && cameraInitialized) {
|
||||||
try {
|
try {
|
||||||
videoCapturer.stopCapture();
|
videoCapturer.stopCapture();
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
|
@ -76,7 +76,7 @@ public class MagicPeerConnectionWrapper {
|
|||||||
|
|
||||||
peerConnection = peerConnectionFactory.createPeerConnection(iceServerList, mediaConstraints,
|
peerConnection = peerConnectionFactory.createPeerConnection(iceServerList, mediaConstraints,
|
||||||
new MagicPeerConnectionObserver());
|
new MagicPeerConnectionObserver());
|
||||||
peerConnection.addStream(mediaStream);
|
peerConnection.addStream(localMediaStream);
|
||||||
|
|
||||||
this.sessionId = sessionId;
|
this.sessionId = sessionId;
|
||||||
this.mediaConstraints = mediaConstraints;
|
this.mediaConstraints = mediaConstraints;
|
||||||
@ -293,7 +293,6 @@ public class MagicPeerConnectionWrapper {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onAddTrack(RtpReceiver rtpReceiver, MediaStream[] mediaStreams) {
|
public void onAddTrack(RtpReceiver rtpReceiver, MediaStream[] mediaStreams) {
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -27,18 +27,13 @@
|
|||||||
android:fitsSystemWindows="true"
|
android:fitsSystemWindows="true"
|
||||||
tools:context=".activities.CallActivity">
|
tools:context=".activities.CallActivity">
|
||||||
|
|
||||||
<org.webrtc.SurfaceViewRenderer
|
|
||||||
android:id="@+id/full_screen_surface_view"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="match_parent"/>
|
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:id="@+id/remote_renderers_layout"
|
android:id="@+id/remote_renderers_layout"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:animateLayoutChanges="true"
|
android:animateLayoutChanges="true"
|
||||||
android:orientation="vertical"
|
android:background="#000000"
|
||||||
android:visibility="invisible">
|
android:orientation="vertical">
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
<org.webrtc.SurfaceViewRenderer
|
<org.webrtc.SurfaceViewRenderer
|
||||||
@ -91,7 +86,8 @@
|
|||||||
android:layout_height="48dp"
|
android:layout_height="48dp"
|
||||||
android:layout_toEndOf="@id/call_control_microphone"
|
android:layout_toEndOf="@id/call_control_microphone"
|
||||||
android:background="?android:selectableItemBackgroundBorderless"
|
android:background="?android:selectableItemBackgroundBorderless"
|
||||||
android:src="@drawable/ic_switch_video_white_24px"/>
|
android:src="@drawable/ic_switch_video_white_24px"
|
||||||
|
android:visibility="invisible"/>
|
||||||
|
|
||||||
</RelativeLayout>
|
</RelativeLayout>
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user