2

I've searched high and low for days to get to the bottom of this issue, and being a bit of a java newbie I'm getting nowhere...

the following code demonstrates the issue. The code works, but it really shouldn't.

The full code is here https://github.com/martyzz1/cordova-plugin-opentok/blob/master/src/android/OpenTokAndroidPlugin.java

The 2 (or more, but in our case 2) views are a 2 way video with the subscriber view being full page size, and the publisher being a small thumbnail with a higher zindex which appears over the subscriber view in the bottom right hand corner. The code worked fine on android <= 25, but on android 8 the thumbnail appears underneath (and hence hidden).

I looked through the android 8 changes docs, but couldn't see anything that looked like it would explain the difference. e.g. that switching the order of the list of views makes it work. I'm also able to switch the zindex values during runtime, and redraw the windows and the the code behaves correctly. e.g. lowering the zindex of publisher to less than session hides the thumbnail and increasing it shows the thumbnail.

I have tried using setZ, setElevation, bringtoFront, addView(mView, index) addView(mView, -1) And I'm just outta ideas. Can anybody help?

public class CustomComparator implements Comparator<RunnableUpdateViews> {
        @Override
        public int compare(RunnableUpdateViews object1, RunnableUpdateViews object2) {
            if (android.os.Build.VERSION.SDK_INT > 25) {
                return object1.getZIndex() - object2.getZIndex();
            } else {
                return object2.getZIndex() - object1.getZIndex();
            }
        }
    }
public void updateZIndices() {
        allStreamViews = new ArrayList<RunnableUpdateViews>();
        for (Map.Entry<String, RunnableSubscriber> entry : subscriberCollection.entrySet()) {
            allStreamViews.add(entry.getValue());
        }
        if (myPublisher != null) {
            allStreamViews.add(myPublisher);
        }
        Collections.sort(allStreamViews, new CustomComparator());

        int index = 1;

        ViewGroup parent = (ViewGroup) cordova.getActivity().findViewById(android.R.id.content);
        for (RunnableUpdateViews viewContainer : allStreamViews) {
            if (null != parent) {
                //viewContainer.mView.bringToFront();
                //int  zind = viewContainer.getZIndex();
                //float zindF = zind;
                //this.mView.setElevation(zindF);

                parent.removeView(viewContainer.mView);
                parent.addView(viewContainer.mView);
                //index += 1;
            } else {
                Log.i(TAG, "parent was null");
            }
        }
        /*for (int i = 0; i < allStreamViews.size(); i++) {
            allStreamViews.get(i).mView.invalidate();
        }
        parent.invalidate();*/
    }

    public int getZIndex() {
        try {
            Log.i(TAG, "getZIndex " + mProperty.getString(0));
            return mProperty.getInt(5);
        } catch (Exception e) {
            Log.i(TAG, "getZIndex() exception" + e.toString());
            return 0;
        }
    }
  • The commented out code shows alternative solutions I tried, but nothing seemed to work. – Martin Moss Jan 09 '18 at 13:41
  • possibly this may have been an intermittent version issue, but I've not been able to test and confirm.... https://github.com/opentok/cordova-plugin-opentok/issues/11#issuecomment-375856156 – Martin Moss Apr 03 '18 at 22:56

2 Answers2

0

Not sure if it is the case. But when we added the possibility to load the cams behind the webview. We found out that at the moment all cams are on the same view and same Z position.

With the use of TranslationZ they are on different levels. See next implementation: https://github.com/Mediapioniers/cordova-plugin-opentok/tree/feat.cams_behind_webview_z-index?files=1

Mark Veenstra
  • 4,691
  • 6
  • 35
  • 66
0

setZOrderOnTop and setZOrderMediaOverlay are really the only ways to change the order of SurfaceViews with respect to each other. See https://stackoverflow.com/a/22746240/468405 for more information.

Joel
  • 2,654
  • 6
  • 31
  • 46