From d6988fea87c9a4c8e15ded16e3745244b74c71dc Mon Sep 17 00:00:00 2001 From: khanhduytran0 Date: Tue, 22 Sep 2020 13:25:40 +0700 Subject: [PATCH] Custom controls: fix wrong pos --- .../kdt/pojavlaunch/CustomControlsActivity.java | 2 +- .../net/kdt/pojavlaunch/MCLauncherActivity.java | 7 ++----- .../java/net/kdt/pojavlaunch/MainActivity.java | 1 - .../net/kdt/pojavlaunch/PojavApplication.java | 11 ----------- .../net/kdt/pojavlaunch/PojavLoginActivity.java | 17 ++++++++++++++++- .../main/java/net/kdt/pojavlaunch/Tools.java | 6 ++++++ .../value/customcontrols/CustomControls.java | 2 +- 7 files changed, 26 insertions(+), 20 deletions(-) diff --git a/app/src/main/java/net/kdt/pojavlaunch/CustomControlsActivity.java b/app/src/main/java/net/kdt/pojavlaunch/CustomControlsActivity.java index da68384a90..4a397bcc2a 100644 --- a/app/src/main/java/net/kdt/pojavlaunch/CustomControlsActivity.java +++ b/app/src/main/java/net/kdt/pojavlaunch/CustomControlsActivity.java @@ -140,7 +140,7 @@ private void save(final boolean exit) { builder.setPositiveButton(android.R.string.ok, null); builder.setNegativeButton(android.R.string.cancel, null); if (exit) { - builder.setNeutralButton("Exit without save", new AlertDialog.OnClickListener(){ + builder.setNeutralButton(R.string.mcn_exit_call, new AlertDialog.OnClickListener(){ @Override public void onClick(DialogInterface p1, int p2) { CustomControlsActivity.super.onBackPressed(); diff --git a/app/src/main/java/net/kdt/pojavlaunch/MCLauncherActivity.java b/app/src/main/java/net/kdt/pojavlaunch/MCLauncherActivity.java index 3a3eb8db16..751567a781 100644 --- a/app/src/main/java/net/kdt/pojavlaunch/MCLauncherActivity.java +++ b/app/src/main/java/net/kdt/pojavlaunch/MCLauncherActivity.java @@ -62,9 +62,6 @@ protected void onCreate(Bundle savedInstanceState) super.onCreate(savedInstanceState); gson = new Gson(); - DisplayMetrics dm = Tools.getDisplayMetrics(this); - CallbackBridge.windowWidth = dm.widthPixels; - CallbackBridge.windowHeight = dm.heightPixels; viewInit(); final View decorView = getWindow().getDecorView(); @@ -267,9 +264,9 @@ public boolean onMenuItemClick(MenuItem item) { } @Override - protected void onPostResume() - { + protected void onPostResume() { super.onPostResume(); + Tools.updateWindowSize(this); } private float updateWidthHeight() { diff --git a/app/src/main/java/net/kdt/pojavlaunch/MainActivity.java b/app/src/main/java/net/kdt/pojavlaunch/MainActivity.java index d1f51df8f3..cef0ed2419 100644 --- a/app/src/main/java/net/kdt/pojavlaunch/MainActivity.java +++ b/app/src/main/java/net/kdt/pojavlaunch/MainActivity.java @@ -171,7 +171,6 @@ public void onSystemUiVisibilityChange(int visibility) { } this.displayMetrics = Tools.getDisplayMetrics(this); - CallbackBridge.windowWidth = displayMetrics.widthPixels / scaleFactor; CallbackBridge.windowHeight = displayMetrics.heightPixels / scaleFactor; System.out.println("WidthHeight: " + CallbackBridge.windowWidth + ":" + CallbackBridge.windowHeight); diff --git a/app/src/main/java/net/kdt/pojavlaunch/PojavApplication.java b/app/src/main/java/net/kdt/pojavlaunch/PojavApplication.java index e01ff36fdc..d48a8a7276 100644 --- a/app/src/main/java/net/kdt/pojavlaunch/PojavApplication.java +++ b/app/src/main/java/net/kdt/pojavlaunch/PojavApplication.java @@ -63,17 +63,6 @@ public void uncaughtException(Thread thread, Throwable th) { LauncherPreferences.DEFAULT_PREF = PreferenceManager.getDefaultSharedPreferences(this); LauncherPreferences.loadPreferences(); - ControlButton.pixelOf2dp = (int) Tools.dpToPx(this, 2); - ControlButton.pixelOf30dp = (int) Tools.dpToPx(this, 30); - ControlButton.pixelOf50dp = (int) Tools.dpToPx(this, 50); - ControlButton.pixelOf80dp = (int) Tools.dpToPx(this, 80); - ControlButton[] specialButtons = ControlButton.getSpecialButtons(); - specialButtons[0].name = getString(R.string.control_keyboard); - specialButtons[1].name = getString(R.string.control_toggle); - specialButtons[2].name = getString(R.string.control_primary); - specialButtons[3].name = getString(R.string.control_secondary); - specialButtons[4].name = getString(R.string.control_mouse); - FontChanger.initFonts(this); } catch (Throwable th) { Intent ferrorIntent = new Intent(this, FatalErrorActivity.class); diff --git a/app/src/main/java/net/kdt/pojavlaunch/PojavLoginActivity.java b/app/src/main/java/net/kdt/pojavlaunch/PojavLoginActivity.java index c22c58db27..8e5e8fb3e5 100644 --- a/app/src/main/java/net/kdt/pojavlaunch/PojavLoginActivity.java +++ b/app/src/main/java/net/kdt/pojavlaunch/PojavLoginActivity.java @@ -47,7 +47,19 @@ public class PojavLoginActivity extends AppCompatActivity @Override protected void onCreate(Bundle savedInstanceState){ super.onCreate(savedInstanceState); // false); - + + Tools.updateWindowSize(this); + ControlButton.pixelOf2dp = (int) Tools.dpToPx(this, 2); + ControlButton.pixelOf30dp = (int) Tools.dpToPx(this, 30); + ControlButton.pixelOf50dp = (int) Tools.dpToPx(this, 50); + ControlButton.pixelOf80dp = (int) Tools.dpToPx(this, 80); + ControlButton[] specialButtons = ControlButton.getSpecialButtons(); + specialButtons[0].name = getString(R.string.control_keyboard); + specialButtons[1].name = getString(R.string.control_toggle); + specialButtons[2].name = getString(R.string.control_primary); + specialButtons[3].name = getString(R.string.control_secondary); + specialButtons[4].name = getString(R.string.control_mouse); + final View decorView = getWindow().getDecorView(); decorView.setOnSystemUiVisibilityChangeListener (new View.OnSystemUiVisibilityChangeListener() { @Override @@ -278,6 +290,9 @@ public void onCheckedChanged(CompoundButton p1, boolean p2) { @Override public void onResume() { super.onResume(); + + Tools.updateWindowSize(this); + final int uiOptions = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION; final View decorView = getWindow().getDecorView(); decorView.setSystemUiVisibility(uiOptions); diff --git a/app/src/main/java/net/kdt/pojavlaunch/Tools.java b/app/src/main/java/net/kdt/pojavlaunch/Tools.java index 0d743dd817..de2d7bdd2b 100644 --- a/app/src/main/java/net/kdt/pojavlaunch/Tools.java +++ b/app/src/main/java/net/kdt/pojavlaunch/Tools.java @@ -369,6 +369,12 @@ public static DisplayMetrics getDisplayMetrics(Activity ctx) { ctx.getWindowManager().getDefaultDisplay().getMetrics(displayMetrics); return displayMetrics; } + + public static void updateWindowSize(Activity ctx) { + DisplayMetrics dm = getDisplayMetrics(ctx); + CallbackBridge.windowWidth = dm.widthPixels; + CallbackBridge.windowHeight = dm.heightPixels; + } public static float pxToDp(Context ctx, float px) { return (px / ctx.getResources().getDisplayMetrics().density); diff --git a/app/src/main/java/net/kdt/pojavlaunch/value/customcontrols/CustomControls.java b/app/src/main/java/net/kdt/pojavlaunch/value/customcontrols/CustomControls.java index ff0ec85d43..2d4e5645f1 100644 --- a/app/src/main/java/net/kdt/pojavlaunch/value/customcontrols/CustomControls.java +++ b/app/src/main/java/net/kdt/pojavlaunch/value/customcontrols/CustomControls.java @@ -19,7 +19,7 @@ public CustomControls(List button) { // Generate default control public CustomControls(Context ctx) { this(); - this.button.add(ControlButton.getSpecialButtons()[0].clone()); // LWJGLGLFWKeycode + this.button.add(ControlButton.getSpecialButtons()[0].clone()); // Keyboard this.button.add(ControlButton.getSpecialButtons()[1].clone()); // GUI this.button.add(ControlButton.getSpecialButtons()[2].clone()); // Primary Mouse button this.button.add(ControlButton.getSpecialButtons()[3].clone()); // Secondary Mouse button