mirror of
https://github.com/AngelAuraMC/Amethyst-Android.git
synced 2025-08-03 15:49:58 -04:00
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:
parent
bc7dfeacfd
commit
1af64382eb
@ -106,7 +106,7 @@
|
||||
<activity
|
||||
android:name=".MainActivity"
|
||||
android:configChanges="keyboardHidden|orientation|screenSize|smallestScreenSize|screenLayout|keyboard|navigation|uiMode"
|
||||
android:launchMode="standard"
|
||||
android:launchMode="singleTop"
|
||||
android:process=":game"
|
||||
android:screenOrientation="sensorLandscape" />
|
||||
|
||||
|
@ -156,7 +156,12 @@ public class LauncherActivity extends BaseActivity {
|
||||
|
||||
@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 @@ public class LauncherActivity extends BaseActivity {
|
||||
mInstallTracker.detach();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean setFullscreen() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStart() {
|
||||
super.onStart();
|
||||
|
@ -33,9 +33,6 @@ import android.util.ArrayMap;
|
||||
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.annotation.RequiresApi;
|
||||
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,32 @@ public final class Tools {
|
||||
|
||||
@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());
|
||||
activity.getWindow().setDecorFitsSystemWindows(false);
|
||||
} else {
|
||||
windowInsetsController.show(WindowInsetsCompat.Type.systemBars());
|
||||
activity.getWindow().setDecorFitsSystemWindows(true);
|
||||
}
|
||||
|
||||
return ViewCompat.onApplyWindowInsets(view, windowInsets);
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
public static void setFullscreen(Activity activity, boolean fullscreen) {
|
||||
|
@ -7,6 +7,7 @@ import android.util.ArrayMap;
|
||||
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 @@ public class ControlData {
|
||||
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);
|
||||
|
@ -61,26 +61,27 @@ public class ControlDrawer extends ControlButton {
|
||||
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;
|
||||
}
|
||||
|
@ -30,7 +30,6 @@ import org.lwjgl.glfw.CallbackBridge;
|
||||
* sending keys has to be implemented by sub classes.
|
||||
*/
|
||||
public interface ControlInterface extends View.OnLongClickListener, GrabListener {
|
||||
|
||||
View getControlView();
|
||||
|
||||
ControlData getProperties();
|
||||
@ -214,7 +213,7 @@ public interface ControlInterface extends View.OnLongClickListener, GrabListener
|
||||
*/
|
||||
@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 @@ public interface ControlInterface extends View.OnLongClickListener, GrabListener
|
||||
* @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 @@ public interface ControlInterface extends View.OnLongClickListener, GrabListener
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static float getSnapDistance() {
|
||||
return Tools.dpToPx(6);
|
||||
}
|
||||
|
||||
static float getMarginDistance() {
|
||||
return Tools.dpToPx(2);
|
||||
}
|
||||
}
|
||||
|
@ -13,6 +13,7 @@ import android.os.Process;
|
||||
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 class GameService extends Service {
|
||||
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();
|
||||
|
Loading…
x
Reference in New Issue
Block a user