mirror of
https://github.com/AngelAuraMC/Amethyst-Android.git
synced 2025-09-17 00:29:50 -04:00
Handle configuration changes to resize the surface;
Deal with surface creation/destruction;
This commit is contained in:
parent
88f31df1f1
commit
8c7bba530e
@ -11,11 +11,13 @@ import static org.lwjgl.glfw.CallbackBridge.windowWidth;
|
|||||||
import android.app.*;
|
import android.app.*;
|
||||||
import android.content.*;
|
import android.content.*;
|
||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
|
import android.content.res.Configuration;
|
||||||
import android.os.*;
|
import android.os.*;
|
||||||
import android.util.*;
|
import android.util.*;
|
||||||
import android.view.*;
|
import android.view.*;
|
||||||
import android.widget.*;
|
import android.widget.*;
|
||||||
|
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
import androidx.drawerlayout.widget.*;
|
import androidx.drawerlayout.widget.*;
|
||||||
import com.google.android.material.navigation.*;
|
import com.google.android.material.navigation.*;
|
||||||
import com.kdt.LoggerView;
|
import com.kdt.LoggerView;
|
||||||
@ -44,6 +46,7 @@ public class BaseMainActivity extends BaseActivity {
|
|||||||
|
|
||||||
private boolean mIsResuming = false;
|
private boolean mIsResuming = false;
|
||||||
|
|
||||||
|
ControlLayout mControlLayout;
|
||||||
private MinecraftGLSurfaceView minecraftGLView;
|
private MinecraftGLSurfaceView minecraftGLView;
|
||||||
private static Touchpad touchpad;
|
private static Touchpad touchpad;
|
||||||
private LoggerView loggerView;
|
private LoggerView loggerView;
|
||||||
@ -69,6 +72,7 @@ public class BaseMainActivity extends BaseActivity {
|
|||||||
GLOBAL_CLIPBOARD = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
|
GLOBAL_CLIPBOARD = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
|
||||||
touchCharInput = findViewById(R.id.mainTouchCharInput);
|
touchCharInput = findViewById(R.id.mainTouchCharInput);
|
||||||
loggerView = findViewById(R.id.mainLoggerView);
|
loggerView = findViewById(R.id.mainLoggerView);
|
||||||
|
mControlLayout = findViewById(R.id.main_control_layout);
|
||||||
|
|
||||||
mProfile = PojavProfile.getCurrentProfileContent(this);
|
mProfile = PojavProfile.getCurrentProfileContent(this);
|
||||||
minecraftProfile = LauncherProfiles.mainProfileJson.profiles.get(mProfile.selectedProfile);
|
minecraftProfile = LauncherProfiles.mainProfileJson.profiles.get(mProfile.selectedProfile);
|
||||||
@ -187,6 +191,13 @@ public class BaseMainActivity extends BaseActivity {
|
|||||||
super.onStop();
|
super.onStop();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onConfigurationChanged(@NonNull Configuration newConfig) {
|
||||||
|
super.onConfigurationChanged(newConfig);
|
||||||
|
Tools.getDisplayMetrics(this);
|
||||||
|
minecraftGLView.refreshSize();
|
||||||
|
}
|
||||||
|
|
||||||
public static void fullyExit() {
|
public static void fullyExit() {
|
||||||
android.os.Process.killProcess(android.os.Process.myPid());
|
android.os.Process.killProcess(android.os.Process.myPid());
|
||||||
}
|
}
|
||||||
|
@ -47,10 +47,8 @@ public class MinecraftGLSurfaceView extends SurfaceView {
|
|||||||
private TextView mPointerDebugTextView;
|
private TextView mPointerDebugTextView;
|
||||||
/* Resolution scaler option, allow downsizing a window */
|
/* Resolution scaler option, allow downsizing a window */
|
||||||
private final float mScaleFactor = LauncherPreferences.DEFAULT_PREF.getInt("resolutionRatio",100)/100f;
|
private final float mScaleFactor = LauncherPreferences.DEFAULT_PREF.getInt("resolutionRatio",100)/100f;
|
||||||
/* Display properties, such as resolution and DPI */
|
|
||||||
private final DisplayMetrics mDisplayMetrics = Tools.getDisplayMetrics((Activity) getContext());
|
|
||||||
/* Sensitivity, adjusted according to screen size */
|
/* Sensitivity, adjusted according to screen size */
|
||||||
private final double mSensitivityFactor = (1.4 * (1080f/ mDisplayMetrics.heightPixels));
|
private final double mSensitivityFactor = (1.4 * (1080f/ Tools.getDisplayMetrics((Activity) getContext()).heightPixels));
|
||||||
/* Use to detect simple and double taps */
|
/* Use to detect simple and double taps */
|
||||||
private final TapDetector mSingleTapDetector = new TapDetector(1, TapDetector.DETECTION_METHOD_BOTH);
|
private final TapDetector mSingleTapDetector = new TapDetector(1, TapDetector.DETECTION_METHOD_BOTH);
|
||||||
private final TapDetector mDoubleTapDetector = new TapDetector(2, TapDetector.DETECTION_METHOD_DOWN);
|
private final TapDetector mDoubleTapDetector = new TapDetector(2, TapDetector.DETECTION_METHOD_DOWN);
|
||||||
@ -140,19 +138,23 @@ public class MinecraftGLSurfaceView extends SurfaceView {
|
|||||||
@Override
|
@Override
|
||||||
public void surfaceCreated(@NonNull SurfaceHolder holder) {
|
public void surfaceCreated(@NonNull SurfaceHolder holder) {
|
||||||
|
|
||||||
|
|
||||||
//Load Minecraft options:
|
//Load Minecraft options:
|
||||||
MCOptionUtils.load();
|
MCOptionUtils.load();
|
||||||
|
MCOptionUtils.set("fullscreen", "off");
|
||||||
MCOptionUtils.set("overrideWidth", String.valueOf(windowWidth));
|
MCOptionUtils.set("overrideWidth", String.valueOf(windowWidth));
|
||||||
MCOptionUtils.set("overrideHeight", String.valueOf(windowHeight));
|
MCOptionUtils.set("overrideHeight", String.valueOf(windowHeight));
|
||||||
MCOptionUtils.save();
|
MCOptionUtils.save();
|
||||||
getMcScale();
|
getMcScale();
|
||||||
// Should we do that?
|
// Resize stuff
|
||||||
if(isCalled) return;
|
if(isCalled){
|
||||||
|
//getHolder().setFixedSize(windowWidth, windowHeight);
|
||||||
|
//JREUtils.setupBridgeWindow(getHolder().getSurface());
|
||||||
|
return;
|
||||||
|
}
|
||||||
isCalled = true;
|
isCalled = true;
|
||||||
|
|
||||||
getHolder().setFixedSize(windowWidth, windowHeight);
|
refreshSize();
|
||||||
|
|
||||||
|
|
||||||
JREUtils.setupBridgeWindow(getHolder().getSurface());
|
JREUtils.setupBridgeWindow(getHolder().getSurface());
|
||||||
|
|
||||||
new Thread(() -> {
|
new Thread(() -> {
|
||||||
@ -169,18 +171,12 @@ public class MinecraftGLSurfaceView extends SurfaceView {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void surfaceChanged(@NonNull SurfaceHolder holder, int format, int width, int height) {
|
public void surfaceChanged(@NonNull SurfaceHolder holder, int format, int width, int height) {
|
||||||
windowWidth = Tools.getDisplayFriendlyRes(mDisplayMetrics.widthPixels, mScaleFactor);
|
refreshSize();
|
||||||
windowHeight = Tools.getDisplayFriendlyRes(mDisplayMetrics.heightPixels, mScaleFactor);
|
|
||||||
CallbackBridge.sendUpdateWindowSize(windowWidth, windowHeight);
|
|
||||||
getMcScale();
|
|
||||||
Toast.makeText(getContext(), "width: " + width, Toast.LENGTH_SHORT).show();
|
|
||||||
Toast.makeText(getContext(), "height: " + height, Toast.LENGTH_SHORT).show();
|
|
||||||
getHolder().setFixedSize(windowWidth, windowHeight);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void surfaceDestroyed(@NonNull SurfaceHolder holder) {
|
public void surfaceDestroyed(@NonNull SurfaceHolder holder) {
|
||||||
|
JREUtils.releaseBridgeWindow();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -588,6 +584,26 @@ public class MinecraftGLSurfaceView extends SurfaceView {
|
|||||||
mPointerDebugTextView.setVisibility(mPointerDebugTextView.getVisibility() == View.GONE ? View.VISIBLE : View.GONE);
|
mPointerDebugTextView.setVisibility(mPointerDebugTextView.getVisibility() == View.GONE ? View.VISIBLE : View.GONE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Called when the size need to be set at any point during the surface lifecycle **/
|
||||||
|
public void refreshSize(){
|
||||||
|
windowWidth = Tools.getDisplayFriendlyRes(Tools.currentDisplayMetrics.widthPixels, mScaleFactor);
|
||||||
|
windowHeight = Tools.getDisplayFriendlyRes(Tools.currentDisplayMetrics.heightPixels, mScaleFactor);
|
||||||
|
getHolder().setFixedSize(windowWidth, windowHeight);
|
||||||
|
|
||||||
|
// Set the new frame size
|
||||||
|
|
||||||
|
MCOptionUtils.load();
|
||||||
|
MCOptionUtils.set("overrideWidth", String.valueOf(windowWidth));
|
||||||
|
MCOptionUtils.set("overrideHeight", String.valueOf(windowHeight));
|
||||||
|
MCOptionUtils.save();
|
||||||
|
|
||||||
|
CallbackBridge.sendUpdateWindowSize(windowWidth, windowHeight);
|
||||||
|
getMcScale();
|
||||||
|
//Toast.makeText(getContext(), "width: " + width, Toast.LENGTH_SHORT).show();
|
||||||
|
//Toast.makeText(getContext(), "height: " + height, Toast.LENGTH_SHORT).show();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
/** A small interface called when the listener is ready for the first time */
|
/** A small interface called when the listener is ready for the first time */
|
||||||
public interface SurfaceReadyListener {
|
public interface SurfaceReadyListener {
|
||||||
void isReady();
|
void isReady();
|
||||||
|
@ -243,14 +243,17 @@ public final class Tools {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
/*
|
||||||
minecraftArgs.add("--width");
|
minecraftArgs.add("--width");
|
||||||
minecraftArgs.add(Integer.toString(CallbackBridge.windowWidth));
|
minecraftArgs.add(Integer.toString(CallbackBridge.windowWidth));
|
||||||
minecraftArgs.add("--height");
|
minecraftArgs.add("--height");
|
||||||
minecraftArgs.add(Integer.toString(CallbackBridge.windowHeight));
|
minecraftArgs.add(Integer.toString(CallbackBridge.windowHeight));
|
||||||
|
|
||||||
minecraftArgs.add("--fullscreenWidth");
|
minecraftArgs.add("--fullscreenWidth");
|
||||||
minecraftArgs.add(Integer.toString(CallbackBridge.windowWidth));
|
minecraftArgs.add(Integer.toString(CallbackBridge.windowWidth));
|
||||||
minecraftArgs.add("--fullscreenHeight");
|
minecraftArgs.add("--fullscreenHeight");
|
||||||
minecraftArgs.add(Integer.toString(CallbackBridge.windowHeight));
|
minecraftArgs.add(Integer.toString(CallbackBridge.windowHeight));
|
||||||
|
*/
|
||||||
|
|
||||||
String[] argsFromJson = JSONUtils.insertJSONValueList(
|
String[] argsFromJson = JSONUtils.insertJSONValueList(
|
||||||
splitAndFilterEmpty(
|
splitAndFilterEmpty(
|
||||||
@ -280,7 +283,7 @@ public final class Tools {
|
|||||||
strList.add(arg);
|
strList.add(arg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
strList.add("--fullscreen");
|
//strList.add("--fullscreen");
|
||||||
return strList.toArray(new String[0]);
|
return strList.toArray(new String[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -547,6 +547,7 @@ public class JREUtils {
|
|||||||
public static native boolean dlopen(String libPath);
|
public static native boolean dlopen(String libPath);
|
||||||
public static native void setLdLibraryPath(String ldLibraryPath);
|
public static native void setLdLibraryPath(String ldLibraryPath);
|
||||||
public static native void setupBridgeWindow(Object surface);
|
public static native void setupBridgeWindow(Object surface);
|
||||||
|
public static native void releaseBridgeWindow();
|
||||||
public static native void setupExitTrap(Context context);
|
public static native void setupExitTrap(Context context);
|
||||||
// Obtain AWT screen pixels to render on Android SurfaceView
|
// Obtain AWT screen pixels to render on Android SurfaceView
|
||||||
public static native int[] renderAWTScreenFrame(/* Object canvas, int width, int height */);
|
public static native int[] renderAWTScreenFrame(/* Object canvas, int width, int height */);
|
||||||
|
@ -674,6 +674,12 @@ JNIEXPORT void JNICALL Java_net_kdt_pojavlaunch_utils_JREUtils_setupBridgeWindow
|
|||||||
free(ptrStr);
|
free(ptrStr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
JNIEXPORT void JNICALL
|
||||||
|
Java_net_kdt_pojavlaunch_utils_JREUtils_releaseBridgeWindow(JNIEnv *env, jclass clazz) {
|
||||||
|
ANativeWindow_release(potatoBridge.androidWindow);
|
||||||
|
}
|
||||||
|
|
||||||
void* pojavGetCurrentContext() {
|
void* pojavGetCurrentContext() {
|
||||||
switch (config_renderer) {
|
switch (config_renderer) {
|
||||||
case RENDERER_GL4ES:
|
case RENDERER_GL4ES:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user