app/internal/window: [Android] replace RegisterFragment with Do

Do is a function for accessing the underlying Android View in a safe
context, the main thread. Do is

- more general than RegisterFragment and may be expanded to other platforms
- simpler to implement (from the Gio side)

and as a bonus, the Do implementation avoids a race condition where
a call to RegisterFragment during an Activity re-create would be ignored.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
Elias Naur
2020-06-13 16:09:33 +02:00
parent f36674ddb3
commit 8688ed95c2
4 changed files with 60 additions and 57 deletions
-25
View File
@@ -191,31 +191,6 @@ public final class GioView extends SurfaceView implements Choreographer.FrameCal
return onBack(nhandle);
}
void registerFragment(String del) {
final Class cls;
try {
cls = getContext().getClassLoader().loadClass(del);
} catch (ClassNotFoundException e) {
throw new RuntimeException("RegisterFragment: fragment class not found: " + e.getMessage());
}
final Fragment frag;
try {
frag = (Fragment)cls.newInstance();
} catch (IllegalAccessException | InstantiationException | ExceptionInInitializerError | SecurityException | ClassCastException e) {
throw new RuntimeException("RegisterFragment: error instantiating fragment: " + e.getMessage());
}
final FragmentManager fm;
try {
fm = ((Activity)getContext()).getFragmentManager();
} catch (ClassCastException e) {
throw new RuntimeException("RegisterFragment: cannot get fragment manager from View Context: " + e.getMessage());
}
FragmentTransaction ft = fm.beginTransaction();
ft.add(frag, del);
ft.commitNow();
}
static private native long onCreateView(GioView view);
static private native void onDestroyView(long handle);
static private native void onStartView(long handle);