82 lines
2.9 KiB
Java
82 lines
2.9 KiB
Java
package dev.iris.android;
|
|
|
|
import android.app.Activity;
|
|
import android.os.Build;
|
|
import android.os.Bundle;
|
|
import android.view.WindowInsets;
|
|
import android.view.WindowInsetsAnimation;
|
|
import android.widget.FrameLayout;
|
|
import java.util.List;
|
|
|
|
public final class MainActivity extends Activity {
|
|
static {
|
|
System.loadLibrary("IRIS_NATIVE_LIBRARY");
|
|
}
|
|
|
|
@Override
|
|
public void onCreate(Bundle state) {
|
|
super.onCreate(state);
|
|
IrisView view = new IrisView(this);
|
|
view.setLayoutParams(new FrameLayout.LayoutParams(
|
|
FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.MATCH_PARENT));
|
|
view.setFocusable(true);
|
|
view.setFocusableInTouchMode(true);
|
|
FrameLayout layout = new FrameLayout(this);
|
|
layout.addView(view);
|
|
setContentView(layout);
|
|
view.requestFocus();
|
|
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
|
|
drawBehindSystemBars();
|
|
view.setWindowInsetsAnimationCallback(new WindowInsetsAnimation.Callback(
|
|
WindowInsetsAnimation.Callback.DISPATCH_MODE_CONTINUE_ON_SUBTREE) {
|
|
@Override
|
|
public WindowInsets onProgress(
|
|
WindowInsets insets, List<WindowInsetsAnimation> running) {
|
|
sendInsets(view, insets);
|
|
return insets;
|
|
}
|
|
|
|
@Override
|
|
public void onEnd(WindowInsetsAnimation animation) {
|
|
WindowInsets settled = view.getRootWindowInsets();
|
|
if (settled != null) {
|
|
sendInsets(view, settled);
|
|
}
|
|
}
|
|
});
|
|
}
|
|
|
|
view.setOnApplyWindowInsetsListener((v, insets) -> {
|
|
sendInsets((IrisView) v, insets);
|
|
return insets;
|
|
});
|
|
}
|
|
|
|
// Android 15 deprecated this API in favor of edge-to-edge enforcement,
|
|
// but API 30 through 34 still need it and Iris supports that whole range.
|
|
@SuppressWarnings("deprecation")
|
|
private void drawBehindSystemBars() {
|
|
getWindow().setDecorFitsSystemWindows(false);
|
|
}
|
|
|
|
// API 29 has no replacement for these four system-window inset getters;
|
|
// the API 30 methods cannot run on Iris's supported minimum.
|
|
@SuppressWarnings("deprecation")
|
|
private static void sendInsets(IrisView view, WindowInsets insets) {
|
|
int imeBottom = 0;
|
|
int imeVisible = 0;
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
|
|
imeBottom = insets.getInsets(WindowInsets.Type.ime()).bottom;
|
|
imeVisible = insets.isVisible(WindowInsets.Type.ime()) ? 1 : 0;
|
|
}
|
|
view.applyWindowInsets(
|
|
insets.getSystemWindowInsetLeft(),
|
|
insets.getSystemWindowInsetTop(),
|
|
insets.getSystemWindowInsetRight(),
|
|
insets.getSystemWindowInsetBottom(),
|
|
imeBottom,
|
|
imeVisible);
|
|
}
|
|
}
|