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;
}
}