From c09db62cfa5211e56e866abda5f7fd422f2d8c47 Mon Sep 17 00:00:00 2001 From: Mathias-Boulay Date: Wed, 4 Dec 2024 20:11:34 +0100 Subject: [PATCH 1/5] QoL(notification): click to go back into the current game --- app_pojavlauncher/src/main/AndroidManifest.xml | 2 +- .../main/java/net/kdt/pojavlaunch/services/GameService.java | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/app_pojavlauncher/src/main/AndroidManifest.xml b/app_pojavlauncher/src/main/AndroidManifest.xml index 98628756a7..740e44964b 100644 --- a/app_pojavlauncher/src/main/AndroidManifest.xml +++ b/app_pojavlauncher/src/main/AndroidManifest.xml @@ -106,7 +106,7 @@ diff --git a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/services/GameService.java b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/services/GameService.java index 43ab1c0879..8782113b89 100644 --- a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/services/GameService.java +++ b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/services/GameService.java @@ -13,6 +13,7 @@ import androidx.annotation.Nullable; import androidx.core.app.NotificationCompat; +import net.kdt.pojavlaunch.MainActivity; import net.kdt.pojavlaunch.R; import net.kdt.pojavlaunch.Tools; import net.kdt.pojavlaunch.utils.NotificationUtils; @@ -39,9 +40,14 @@ public int onStartCommand(Intent intent, int flags, int startId) { killIntent.putExtra("kill", true); PendingIntent pendingKillIntent = PendingIntent.getService(this, NotificationUtils.PENDINGINTENT_CODE_KILL_GAME_SERVICE , killIntent, Build.VERSION.SDK_INT >=23 ? PendingIntent.FLAG_IMMUTABLE : 0); + PendingIntent contentIntent = PendingIntent.getActivity(this, 0, + new Intent(this, MainActivity.class).setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT), + PendingIntent.FLAG_IMMUTABLE); + NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this, "channel_id") .setContentTitle(getString(R.string.lazy_service_default_title)) .setContentText(getString(R.string.notification_game_runs)) + .setContentIntent(contentIntent) .addAction(android.R.drawable.ic_menu_close_clear_cancel, getString(R.string.notification_terminate), pendingKillIntent) .setSmallIcon(R.drawable.notif_icon) .setNotificationSilent(); From 70f099821a38e6dd7e76f89f32592ce85f5cea76 Mon Sep 17 00:00:00 2001 From: Mathias-Boulay Date: Wed, 4 Dec 2024 21:24:45 +0100 Subject: [PATCH 2/5] Fix(system bars): fix colors for navigation bars --- .../main/java/net/kdt/pojavlaunch/Tools.java | 60 +++++++++---------- 1 file changed, 28 insertions(+), 32 deletions(-) diff --git a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/Tools.java b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/Tools.java index 9bc091e470..c963f707a5 100644 --- a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/Tools.java +++ b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/Tools.java @@ -33,9 +33,6 @@ import android.util.DisplayMetrics; import android.util.Log; import android.view.View; -import android.view.Window; -import android.view.WindowInsets; -import android.view.WindowInsetsController; import android.view.WindowManager; import android.widget.EditText; import android.widget.TextView; @@ -47,6 +44,10 @@ import androidx.appcompat.app.AlertDialog; import androidx.appcompat.app.AppCompatActivity; import androidx.core.app.NotificationManagerCompat; +import androidx.core.view.ViewCompat; +import androidx.core.view.WindowCompat; +import androidx.core.view.WindowInsetsCompat; +import androidx.core.view.WindowInsetsControllerCompat; import androidx.fragment.app.Fragment; import androidx.fragment.app.FragmentActivity; @@ -539,35 +540,30 @@ private static void setFullscreenLegacy(Activity activity, boolean fullscreen) { @RequiresApi(Build.VERSION_CODES.R) private static void setFullscreenSdk30(Activity activity, boolean fullscreen) { - final Window window = activity.getWindow(); - final View decorView = window.getDecorView(); - final int insetControllerFlags = WindowInsets.Type.statusBars() | WindowInsets.Type.navigationBars(); - final View.OnApplyWindowInsetsListener windowInsetsListener = (view, windowInsets) ->{ - WindowInsetsController windowInsetsController = decorView.getWindowInsetsController(); - if(windowInsetsController == null) return windowInsets; - boolean multiWindowMode = activity.isInMultiWindowMode(); - // Emulate the behaviour of the legacy function using the new flags - if(fullscreen && !multiWindowMode) { - windowInsetsController.hide(insetControllerFlags); - windowInsetsController.setSystemBarsBehavior(WindowInsetsController.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE); - window.setDecorFitsSystemWindows(false); - }else { - windowInsetsController.show(insetControllerFlags); - // Both of the constants below have the exact same numerical value, but - // for some reason the one that works below Android S was removed - // from the acceptable constants for setSystemBarsBehaviour - if (SDK_INT >= Build.VERSION_CODES.S) { - windowInsetsController.setSystemBarsBehavior(WindowInsetsController.BEHAVIOR_DEFAULT); - }else { - // noinspection WrongConstant - windowInsetsController.setSystemBarsBehavior(WindowInsetsController.BEHAVIOR_SHOW_BARS_BY_SWIPE); - } - window.setDecorFitsSystemWindows(true); - } - return windowInsets; - }; - decorView.setOnApplyWindowInsetsListener(windowInsetsListener); - windowInsetsListener.onApplyWindowInsets(decorView, null); + WindowInsetsControllerCompat windowInsetsController = + WindowCompat.getInsetsController(activity.getWindow(), activity.getWindow().getDecorView()); + if (windowInsetsController == null) { + Log.w(APP_NAME, "WindowInsetsController is null, cannot set fullscreen"); + return; + } + + // Configure the behavior of the hidden system bars. + windowInsetsController.setSystemBarsBehavior( + WindowInsetsControllerCompat.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE + ); + + ViewCompat.setOnApplyWindowInsetsListener( + activity.getWindow().getDecorView(), + (view, windowInsets) -> { + if (fullscreen && !activity.isInMultiWindowMode()) { + windowInsetsController.hide(WindowInsetsCompat.Type.systemBars()); + } else { + windowInsetsController.show(WindowInsetsCompat.Type.systemBars()); + } + + return ViewCompat.onApplyWindowInsets(view, windowInsets); + }); + } public static void setFullscreen(Activity activity, boolean fullscreen) { From e16c350d38adad1fbbd62d15c032ee637dadb992 Mon Sep 17 00:00:00 2001 From: Mathias-Boulay Date: Wed, 4 Dec 2024 21:38:53 +0100 Subject: [PATCH 3/5] Tweak(control editor): make snapping less aggressive --- .../kdt/pojavlaunch/customcontrols/ControlData.java | 3 ++- .../customcontrols/buttons/ControlDrawer.java | 9 +++++---- .../customcontrols/buttons/ControlInterface.java | 13 ++++++++++--- 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/customcontrols/ControlData.java b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/customcontrols/ControlData.java index 52798daeb0..82b041f2ab 100644 --- a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/customcontrols/ControlData.java +++ b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/customcontrols/ControlData.java @@ -7,6 +7,7 @@ import androidx.annotation.Keep; import net.kdt.pojavlaunch.Tools; +import net.kdt.pojavlaunch.customcontrols.buttons.ControlInterface; import net.kdt.pojavlaunch.prefs.LauncherPreferences; import net.kdt.pojavlaunch.utils.JSONUtils; import net.objecthunter.exp4j.ExpressionBuilder; @@ -240,7 +241,7 @@ private static void buildConversionMap() { keyValueMap.put("height", "DUMMY_HEIGHT"); keyValueMap.put("screen_width", "DUMMY_DATA"); keyValueMap.put("screen_height", "DUMMY_DATA"); - keyValueMap.put("margin", Integer.toString((int) Tools.dpToPx(2))); + keyValueMap.put("margin", Integer.toString((int) ControlInterface.getMarginDistance())); keyValueMap.put("preferred_scale", "DUMMY_DATA"); conversionMap = new WeakReference<>(keyValueMap); diff --git a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/customcontrols/buttons/ControlDrawer.java b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/customcontrols/buttons/ControlDrawer.java index 2c31604615..1f7bbadf14 100644 --- a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/customcontrols/buttons/ControlDrawer.java +++ b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/customcontrols/buttons/ControlDrawer.java @@ -61,26 +61,27 @@ private void switchButtonVisibility(){ private void alignButtons(){ if(buttons == null) return; if(drawerData.orientation == ControlDrawerData.Orientation.FREE) return; + int margin = (int) ControlInterface.getMarginDistance(); for(int i = 0; i < buttons.size(); ++i){ switch (drawerData.orientation){ case RIGHT: - buttons.get(i).setDynamicX(generateDynamicX(getX() + (drawerData.properties.getWidth() + Tools.dpToPx(2))*(i+1) )); + buttons.get(i).setDynamicX(generateDynamicX(getX() + (drawerData.properties.getWidth() + margin)*(i+1) )); buttons.get(i).setDynamicY(generateDynamicY(getY())); break; case LEFT: - buttons.get(i).setDynamicX(generateDynamicX(getX() - (drawerData.properties.getWidth() + Tools.dpToPx(2))*(i+1))); + buttons.get(i).setDynamicX(generateDynamicX(getX() - (drawerData.properties.getWidth() + margin)*(i+1))); buttons.get(i).setDynamicY(generateDynamicY(getY())); break; case UP: - buttons.get(i).setDynamicY(generateDynamicY(getY() - (drawerData.properties.getHeight() + Tools.dpToPx(2))*(i+1))); + buttons.get(i).setDynamicY(generateDynamicY(getY() - (drawerData.properties.getHeight() + margin)*(i+1))); buttons.get(i).setDynamicX(generateDynamicX(getX())); break; case DOWN: - buttons.get(i).setDynamicY(generateDynamicY(getY() + (drawerData.properties.getHeight() + Tools.dpToPx(2))*(i+1))); + buttons.get(i).setDynamicY(generateDynamicY(getY() + (drawerData.properties.getHeight() + margin)*(i+1))); buttons.get(i).setDynamicX(generateDynamicX(getX())); break; } diff --git a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/customcontrols/buttons/ControlInterface.java b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/customcontrols/buttons/ControlInterface.java index 569ddfefc9..6ae683a460 100644 --- a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/customcontrols/buttons/ControlInterface.java +++ b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/customcontrols/buttons/ControlInterface.java @@ -30,7 +30,6 @@ * sending keys has to be implemented by sub classes. */ public interface ControlInterface extends View.OnLongClickListener, GrabListener { - View getControlView(); ControlData getProperties(); @@ -214,7 +213,7 @@ default float computeCornerRadius(float radiusInPercent) { */ @SuppressWarnings("BooleanMethodIsAlwaysInverted") default boolean canSnap(ControlInterface button) { - float MIN_DISTANCE = Tools.dpToPx(8); + float MIN_DISTANCE = getSnapDistance(); if (button == this) return false; return !(net.kdt.pojavlaunch.utils.MathUtils.dist( @@ -237,7 +236,7 @@ default boolean canSnap(ControlInterface button) { * @param y Coordinate on the y axis */ default void snapAndAlign(float x, float y) { - float MIN_DISTANCE = Tools.dpToPx(8); + final float MIN_DISTANCE = getSnapDistance(); String dynamicX = generateDynamicX(x); String dynamicY = generateDynamicY(y); @@ -404,4 +403,12 @@ default boolean onLongClick(View v) { return true; } + + static float getSnapDistance() { + return Tools.dpToPx(6); + } + + static float getMarginDistance() { + return Tools.dpToPx(2); + } } From 76a76c9b32cf77b26f126c43491ba180f61c0947 Mon Sep 17 00:00:00 2001 From: Mathias-Boulay Date: Thu, 5 Dec 2024 00:29:07 +0100 Subject: [PATCH 4/5] Fix(system bars): properly remove colors in full screen --- app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/Tools.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/Tools.java b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/Tools.java index c963f707a5..beb826c564 100644 --- a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/Tools.java +++ b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/Tools.java @@ -557,8 +557,10 @@ private static void setFullscreenSdk30(Activity activity, boolean fullscreen) { (view, windowInsets) -> { if (fullscreen && !activity.isInMultiWindowMode()) { windowInsetsController.hide(WindowInsetsCompat.Type.systemBars()); + activity.getWindow().setDecorFitsSystemWindows(false); } else { windowInsetsController.show(WindowInsetsCompat.Type.systemBars()); + activity.getWindow().setDecorFitsSystemWindows(true); } return ViewCompat.onApplyWindowInsets(view, windowInsets); From a80b85df916029839b1b60d89564ca4a1adfb930 Mon Sep 17 00:00:00 2001 From: Mathias-Boulay Date: Thu, 5 Dec 2024 21:13:05 +0100 Subject: [PATCH 5/5] Fix(launcher activity): make landscape notch handling nicer --- .../java/net/kdt/pojavlaunch/LauncherActivity.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/LauncherActivity.java b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/LauncherActivity.java index 73bd5977d9..00cc8e53be 100644 --- a/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/LauncherActivity.java +++ b/app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/LauncherActivity.java @@ -156,7 +156,12 @@ public void onFragmentResumed(@NonNull FragmentManager fm, @NonNull Fragment f) @Override protected boolean shouldIgnoreNotch() { - return getResources().getConfiguration().orientation == ORIENTATION_PORTRAIT || super.shouldIgnoreNotch(); + return getResources().getConfiguration().orientation == ORIENTATION_PORTRAIT; + } + + @Override + public boolean setFullscreen() { + return false; } @Override @@ -227,11 +232,6 @@ protected void onPause() { mInstallTracker.detach(); } - @Override - public boolean setFullscreen() { - return false; - } - @Override protected void onStart() { super.onStart();