Android - SurfaceViewRenderer on a floating window gets rendered out of its containing layout.

530 views
Skip to first unread message

Miguel del Amor

unread,
Dec 12, 2018, 4:49:59 AM12/12/18
to discuss-webrtc

device-2018-12-11-175318.png


I'm creating a floating popup with a surface view into it, in this manner:

 LayoutInflater.from(contextWeak.get()).inflate(R.layout.layout_floating_widget, null); int type;
 
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
 type
= WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY;
 
} else {
 type
= WindowManager.LayoutParams.TYPE_TOAST;
 
}

 
WindowManager.LayoutParams params = new WindowManager.LayoutParams(
 
WindowManager.LayoutParams.WRAP_CONTENT,
 
WindowManager.LayoutParams.WRAP_CONTENT,
 type
,
 
WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE,
 
PixelFormat.TRANSLUCENT);

 
//Specify the view position
 
params.gravity = Gravity.LEFT | Gravity.CENTER; //Initially view will be added to top-left corner
 
params.x = 0;
 
params.y = 0;

 
//Add the view to the window
 mWindowManager
= (WindowManager) contextWeak.get().getSystemService(WINDOW_SERVICE);
 mWindowManager
.addView(mFloatingView, params);

 localVideoView
= mFloatingView.findViewById(R.id.local_gl_surface_view);
 remoteVideoView
= mFloatingView.findViewById(R.id.remote_gl_surface_view);
 localVideoView
.setZOrderOnTop(true);
 remoteVideoView
.setZOrderOnTop(true);

And the xml
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="wrap_content" android:layout_height="wrap_content">
   
<!--Root container-->
   
<RelativeLayout android:id="@+id/root_container" android:layout_width="wrap_content" android:layout_height="wrap_content" tools:ignore="UselessParent">
     
<RelativeLayout android:id="@+id/collapse_view" android:layout_width="wrap_content" android:visibility="visible" android:layout_height="wrap_content" android:orientation="vertical" android:background="#ccc">
     
<LinearLayout android:id="@+id/video" android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="vertical">
         
<org.webrtc.SurfaceViewRenderer android:id="@+id/remote_gl_surface_view" android:layout_width="150dp" android:layout_height="100dp" />
         
<org.webrtc.SurfaceViewRenderer android:id="@+id/local_gl_surface_view" android:layout_width="150dp" android:layout_height="100dp" />
     
</LinearLayout>
     
<!--Close button-->
     
<ImageView android:id="@+id/close_btn" android:layout_width="20dp" android:layout_height="20dp" android:src="@drawable/ic_close" tools:ignore="ContentDescription" android:layout_toEndOf="@id/video"/>
   
</RelativeLayout>
</RelativeLayout>
</FrameLayout>

On Android 9 it's properly rendered and I can drag it with its content, but on Android 6 I'm seeing the SurfaceView being rendered like out of the layout and I can drag it but it drags the popup without the SurfaceView.

Image showing the issue: https://imgur.com/a/ai79aI7
Video showing the issue: https://imgur.com/a/ChltcBT

I've created the question also on StackOverflow -> https://stackoverflow.com/questions/53728963/surfaceview-getting-rendered-out-of-layout

Miguel del Amor

unread,
Dec 12, 2018, 5:22:49 AM12/12/18
to discuss-webrtc
This project that just shows floating camera preview does same bad behavior -> https://github.com/alexjlockwood/floating-camera
Reply all
Reply to author
Forward
0 new messages