QoL update (#6350)

* QoL(notification): click to go back into the current game

* Fix(system bars): fix colors for navigation bars

* Tweak(control editor): make snapping less aggressive

* Fix(system bars): properly remove colors in full screen
This commit is contained in:
Mathias Boulay 2024-12-06 21:04:17 +01:00 committed by GitHub
parent bc7dfeacfd
commit 1af64382eb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 60 additions and 47 deletions

View File

@ -106,7 +106,7 @@
<activity <activity
android:name=".MainActivity" android:name=".MainActivity"
android:configChanges="keyboardHidden|orientation|screenSize|smallestScreenSize|screenLayout|keyboard|navigation|uiMode" android:configChanges="keyboardHidden|orientation|screenSize|smallestScreenSize|screenLayout|keyboard|navigation|uiMode"
android:launchMode="standard" android:launchMode="singleTop"
android:process=":game" android:process=":game"
android:screenOrientation="sensorLandscape" /> android:screenOrientation="sensorLandscape" />

View File

@ -156,7 +156,12 @@ public class LauncherActivity extends BaseActivity {
@Override @Override
protected boolean shouldIgnoreNotch() { protected boolean shouldIgnoreNotch() {
return getResources().getConfiguration().orientation == ORIENTATION_PORTRAIT || super.shouldIgnoreNotch(); return getResources().getConfiguration().orientation == ORIENTATION_PORTRAIT;
}
@Override
public boolean setFullscreen() {
return false;
} }
@Override @Override
@ -227,11 +232,6 @@ public class LauncherActivity extends BaseActivity {
mInstallTracker.detach(); mInstallTracker.detach();
} }
@Override
public boolean setFullscreen() {
return false;
}
@Override @Override
protected void onStart() { protected void onStart() {
super.onStart(); super.onStart();

View File

@ -33,9 +33,6 @@ import android.util.ArrayMap;
import android.util.DisplayMetrics; import android.util.DisplayMetrics;
import android.util.Log; import android.util.Log;
import android.view.View; import android.view.View;
import android.view.Window;
import android.view.WindowInsets;
import android.view.WindowInsetsController;
import android.view.WindowManager; import android.view.WindowManager;
import android.widget.EditText; import android.widget.EditText;
import android.widget.TextView; import android.widget.TextView;
@ -47,6 +44,10 @@ import androidx.annotation.RequiresApi;
import androidx.appcompat.app.AlertDialog; import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.NotificationManagerCompat; 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.Fragment;
import androidx.fragment.app.FragmentActivity; import androidx.fragment.app.FragmentActivity;
@ -539,35 +540,32 @@ public final class Tools {
@RequiresApi(Build.VERSION_CODES.R) @RequiresApi(Build.VERSION_CODES.R)
private static void setFullscreenSdk30(Activity activity, boolean fullscreen) { private static void setFullscreenSdk30(Activity activity, boolean fullscreen) {
final Window window = activity.getWindow(); WindowInsetsControllerCompat windowInsetsController =
final View decorView = window.getDecorView(); WindowCompat.getInsetsController(activity.getWindow(), activity.getWindow().getDecorView());
final int insetControllerFlags = WindowInsets.Type.statusBars() | WindowInsets.Type.navigationBars(); if (windowInsetsController == null) {
final View.OnApplyWindowInsetsListener windowInsetsListener = (view, windowInsets) ->{ Log.w(APP_NAME, "WindowInsetsController is null, cannot set fullscreen");
WindowInsetsController windowInsetsController = decorView.getWindowInsetsController(); return;
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);
// 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());
activity.getWindow().setDecorFitsSystemWindows(false);
} else {
windowInsetsController.show(WindowInsetsCompat.Type.systemBars());
activity.getWindow().setDecorFitsSystemWindows(true);
} }
return windowInsets;
}; return ViewCompat.onApplyWindowInsets(view, windowInsets);
decorView.setOnApplyWindowInsetsListener(windowInsetsListener); });
windowInsetsListener.onApplyWindowInsets(decorView, null);
} }
public static void setFullscreen(Activity activity, boolean fullscreen) { public static void setFullscreen(Activity activity, boolean fullscreen) {

View File

@ -7,6 +7,7 @@ import android.util.ArrayMap;
import androidx.annotation.Keep; import androidx.annotation.Keep;
import net.kdt.pojavlaunch.Tools; import net.kdt.pojavlaunch.Tools;
import net.kdt.pojavlaunch.customcontrols.buttons.ControlInterface;
import net.kdt.pojavlaunch.prefs.LauncherPreferences; import net.kdt.pojavlaunch.prefs.LauncherPreferences;
import net.kdt.pojavlaunch.utils.JSONUtils; import net.kdt.pojavlaunch.utils.JSONUtils;
import net.objecthunter.exp4j.ExpressionBuilder; import net.objecthunter.exp4j.ExpressionBuilder;
@ -240,7 +241,7 @@ public class ControlData {
keyValueMap.put("height", "DUMMY_HEIGHT"); keyValueMap.put("height", "DUMMY_HEIGHT");
keyValueMap.put("screen_width", "DUMMY_DATA"); keyValueMap.put("screen_width", "DUMMY_DATA");
keyValueMap.put("screen_height", "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"); keyValueMap.put("preferred_scale", "DUMMY_DATA");
conversionMap = new WeakReference<>(keyValueMap); conversionMap = new WeakReference<>(keyValueMap);

View File

@ -61,26 +61,27 @@ public class ControlDrawer extends ControlButton {
private void alignButtons(){ private void alignButtons(){
if(buttons == null) return; if(buttons == null) return;
if(drawerData.orientation == ControlDrawerData.Orientation.FREE) return; if(drawerData.orientation == ControlDrawerData.Orientation.FREE) return;
int margin = (int) ControlInterface.getMarginDistance();
for(int i = 0; i < buttons.size(); ++i){ for(int i = 0; i < buttons.size(); ++i){
switch (drawerData.orientation){ switch (drawerData.orientation){
case RIGHT: 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())); buttons.get(i).setDynamicY(generateDynamicY(getY()));
break; break;
case LEFT: 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())); buttons.get(i).setDynamicY(generateDynamicY(getY()));
break; break;
case UP: 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())); buttons.get(i).setDynamicX(generateDynamicX(getX()));
break; break;
case DOWN: 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())); buttons.get(i).setDynamicX(generateDynamicX(getX()));
break; break;
} }

View File

@ -30,7 +30,6 @@ import org.lwjgl.glfw.CallbackBridge;
* sending keys has to be implemented by sub classes. * sending keys has to be implemented by sub classes.
*/ */
public interface ControlInterface extends View.OnLongClickListener, GrabListener { public interface ControlInterface extends View.OnLongClickListener, GrabListener {
View getControlView(); View getControlView();
ControlData getProperties(); ControlData getProperties();
@ -214,7 +213,7 @@ public interface ControlInterface extends View.OnLongClickListener, GrabListener
*/ */
@SuppressWarnings("BooleanMethodIsAlwaysInverted") @SuppressWarnings("BooleanMethodIsAlwaysInverted")
default boolean canSnap(ControlInterface button) { default boolean canSnap(ControlInterface button) {
float MIN_DISTANCE = Tools.dpToPx(8); float MIN_DISTANCE = getSnapDistance();
if (button == this) return false; if (button == this) return false;
return !(net.kdt.pojavlaunch.utils.MathUtils.dist( return !(net.kdt.pojavlaunch.utils.MathUtils.dist(
@ -237,7 +236,7 @@ public interface ControlInterface extends View.OnLongClickListener, GrabListener
* @param y Coordinate on the y axis * @param y Coordinate on the y axis
*/ */
default void snapAndAlign(float x, float y) { default void snapAndAlign(float x, float y) {
float MIN_DISTANCE = Tools.dpToPx(8); final float MIN_DISTANCE = getSnapDistance();
String dynamicX = generateDynamicX(x); String dynamicX = generateDynamicX(x);
String dynamicY = generateDynamicY(y); String dynamicY = generateDynamicY(y);
@ -404,4 +403,12 @@ public interface ControlInterface extends View.OnLongClickListener, GrabListener
return true; return true;
} }
static float getSnapDistance() {
return Tools.dpToPx(6);
}
static float getMarginDistance() {
return Tools.dpToPx(2);
}
} }

View File

@ -13,6 +13,7 @@ import android.os.Process;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import androidx.core.app.NotificationCompat; import androidx.core.app.NotificationCompat;
import net.kdt.pojavlaunch.MainActivity;
import net.kdt.pojavlaunch.R; import net.kdt.pojavlaunch.R;
import net.kdt.pojavlaunch.Tools; import net.kdt.pojavlaunch.Tools;
import net.kdt.pojavlaunch.utils.NotificationUtils; import net.kdt.pojavlaunch.utils.NotificationUtils;
@ -39,9 +40,14 @@ public class GameService extends Service {
killIntent.putExtra("kill", true); killIntent.putExtra("kill", true);
PendingIntent pendingKillIntent = PendingIntent.getService(this, NotificationUtils.PENDINGINTENT_CODE_KILL_GAME_SERVICE PendingIntent pendingKillIntent = PendingIntent.getService(this, NotificationUtils.PENDINGINTENT_CODE_KILL_GAME_SERVICE
, killIntent, Build.VERSION.SDK_INT >=23 ? PendingIntent.FLAG_IMMUTABLE : 0); , 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") NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this, "channel_id")
.setContentTitle(getString(R.string.lazy_service_default_title)) .setContentTitle(getString(R.string.lazy_service_default_title))
.setContentText(getString(R.string.notification_game_runs)) .setContentText(getString(R.string.notification_game_runs))
.setContentIntent(contentIntent)
.addAction(android.R.drawable.ic_menu_close_clear_cancel, getString(R.string.notification_terminate), pendingKillIntent) .addAction(android.R.drawable.ic_menu_close_clear_cancel, getString(R.string.notification_terminate), pendingKillIntent)
.setSmallIcon(R.drawable.notif_icon) .setSmallIcon(R.drawable.notif_icon)
.setNotificationSilent(); .setNotificationSilent();