mirror of
https://code.gri.mw/GUI/grim.git
synced 2026-07-15 11:18:55 +00:00
android: refactor display cutouts
This commit is contained in:
@@ -1,11 +1,12 @@
|
||||
package mw.gri.android;
|
||||
|
||||
import android.hardware.SensorManager;
|
||||
import android.os.Bundle;
|
||||
import android.os.Process;
|
||||
import android.system.ErrnoException;
|
||||
import android.system.Os;
|
||||
import android.util.Log;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.OrientationEventListener;
|
||||
import com.google.androidgamesdk.GameActivity;
|
||||
|
||||
public class MainActivity extends GameActivity {
|
||||
@@ -22,31 +23,23 @@ public class MainActivity extends GameActivity {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
OrientationEventListener orientationEventListener = new OrientationEventListener(this,
|
||||
SensorManager.SENSOR_DELAY_GAME) {
|
||||
@Override
|
||||
public void onOrientationChanged(int orientation) {
|
||||
onDisplayCutoutsChanged(Utils.getDisplayCutouts(MainActivity.this));
|
||||
}
|
||||
};
|
||||
if (orientationEventListener.canDetectOrientation()) {
|
||||
orientationEventListener.enable();
|
||||
}
|
||||
onDisplayCutoutsChanged(Utils.getDisplayCutouts(MainActivity.this));
|
||||
|
||||
BackgroundService.start(getApplicationContext());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
if (!mManualExit) {
|
||||
BackgroundService.stop(getApplicationContext());
|
||||
// Temporary fix to prevent app hanging when closed from recent apps
|
||||
Process.killProcess(Process.myPid());
|
||||
}
|
||||
super.onDestroy();
|
||||
}
|
||||
|
||||
public int[] getDisplayCutouts() {
|
||||
return Utils.getDisplayCutouts(this);
|
||||
}
|
||||
|
||||
private boolean mManualExit = false;
|
||||
|
||||
// Called from native code
|
||||
public void onExit() {
|
||||
mManualExit = true;
|
||||
BackgroundService.stop(getApplicationContext());
|
||||
finish();
|
||||
}
|
||||
native void onDisplayCutoutsChanged(int[] cutouts);
|
||||
|
||||
@Override
|
||||
public boolean onKeyDown(int keyCode, KeyEvent event) {
|
||||
@@ -58,4 +51,24 @@ public class MainActivity extends GameActivity {
|
||||
}
|
||||
|
||||
public native void onBackButtonPress();
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
if (!mManualExit) {
|
||||
BackgroundService.stop(getApplicationContext());
|
||||
// Temporary fix to prevent app hanging when closed from recent apps
|
||||
Process.killProcess(Process.myPid());
|
||||
}
|
||||
super.onDestroy();
|
||||
}
|
||||
|
||||
|
||||
private boolean mManualExit = false;
|
||||
|
||||
// Called from native code
|
||||
public void onExit() {
|
||||
mManualExit = true;
|
||||
BackgroundService.stop(getApplicationContext());
|
||||
finish();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user