Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

QoL update #6350

Merged
merged 5 commits into from
Dec 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app_pojavlauncher/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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" />

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -227,11 +232,6 @@ protected void onPause() {
mInstallTracker.detach();
}

@Override
public boolean setFullscreen() {
return false;
}

@Override
protected void onStart() {
super.onStart();
Expand Down
62 changes: 30 additions & 32 deletions app_pojavlauncher/src/main/java/net/kdt/pojavlaunch/Tools.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand Down Expand Up @@ -539,35 +540,32 @@ 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());
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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
* sending keys has to be implemented by sub classes.
*/
public interface ControlInterface extends View.OnLongClickListener, GrabListener {

View getControlView();

ControlData getProperties();
Expand Down Expand Up @@ -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(
Expand All @@ -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);

Expand Down Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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();
Expand Down
Loading