- Updated getDisplayMetrics to make use of compilation API level 30.

- The display width is now properly took into account.
- Introduced a ignore notch setting. (design not finished)
- Use proper split screen detection.
- Proper resizing for minecraft view.
- Removed inversion of width and height when the height is greater than the height.
This commit is contained in:
SerpentSpirale 2021-01-29 16:46:26 +01:00
parent 6501b54514
commit 21969090b1
5 changed files with 73 additions and 17 deletions

View File

@ -11,6 +11,7 @@ import java.io.*;
import com.google.gson.*;
import static net.kdt.pojavlaunch.prefs.LauncherPreferences.DEFAULT_PREF;
import static net.kdt.pojavlaunch.prefs.LauncherPreferences.PREF_IGNORE_NOTCH;
public class MainActivity extends BaseMainActivity {
private ControlLayout mControlLayout;
@ -23,6 +24,8 @@ public class MainActivity extends BaseMainActivity {
super.onCreate(savedInstanceState);
initLayout(R.layout.main_with_customctrl);
Tools.ignoreNotch(PREF_IGNORE_NOTCH, this);
mClickListener = new View.OnClickListener(){
@Override
public void onClick(View view) {

View File

@ -4,11 +4,12 @@ import android.animation.ValueAnimator;
import android.content.SharedPreferences;
import android.graphics.Color;
import android.graphics.Typeface;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.support.design.widget.VerticalTabLayout.ViewPagerAdapter;
import android.util.TypedValue;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
@ -18,6 +19,7 @@ import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Toast;
import androidx.constraintlayout.widget.ConstraintLayout;
import androidx.constraintlayout.widget.Guideline;
import androidx.viewpager.widget.ViewPager;
@ -33,7 +35,11 @@ import java.io.File;
import java.util.ArrayList;
import java.util.List;
import static android.os.Build.VERSION_CODES.P;
import static net.kdt.pojavlaunch.Tools.ignoreNotch;
import static net.kdt.pojavlaunch.prefs.LauncherPreferences.PREF_HIDE_SIDEBAR;
import static net.kdt.pojavlaunch.prefs.LauncherPreferences.PREF_IGNORE_NOTCH;
import static net.kdt.pojavlaunch.prefs.LauncherPreferences.PREF_NOTCH_SIZE;
public class PojavLauncherActivity extends BaseLauncherActivity
{
@ -52,6 +58,7 @@ public class PojavLauncherActivity extends BaseLauncherActivity
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.launcher_main_v4);
@ -206,20 +213,27 @@ public class PojavLauncherActivity extends BaseLauncherActivity
statusIsLaunching(false);
initTabs(0);
LauncherPreferences.DEFAULT_PREF.registerOnSharedPreferenceChangeListener(new SharedPreferences.OnSharedPreferenceChangeListener() {
@Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
if(key.equals("hideSidebar")) {
if(key.equals("hideSidebar")){
restoreOldLook(sharedPreferences.getBoolean("hideSidebar",false));
return;
}
if(key.equals("ignoreNotch")){
ignoreNotch(sharedPreferences.getBoolean("ignoreNotch", true), PojavLauncherActivity.this);
return;
}
}
});
restoreOldLook(PREF_HIDE_SIDEBAR);
ignoreNotch(PREF_IGNORE_NOTCH, PojavLauncherActivity.this);
}
private void selectTabPage(int pageIndex){
viewPager.setCurrentItem(pageIndex);
setTabActive(pageIndex);
@ -313,5 +327,20 @@ public class PojavLauncherActivity extends BaseLauncherActivity
}
mPlayButton.setLayoutParams(params);
}
@Override
public void onAttachedToWindow() {
super.onAttachedToWindow();
if (Build.VERSION.SDK_INT >= P){
//Get the fucking notch height:
try {
PREF_NOTCH_SIZE = getWindow().getDecorView().getRootWindowInsets().getDisplayCutout().getBoundingRects().get(0).width();
}catch (Exception e){
Log.i("NOTCH DETECTION", "No notch detected, or the device if in split screen mode");
}
Tools.updateWindowSize(this);
}
}
}

View File

@ -2,8 +2,6 @@ package net.kdt.pojavlaunch;
import android.app.*;
import android.content.*;
import android.content.res.*;
import android.graphics.Point;
import android.net.*;
import android.os.*;
import android.system.*;
@ -24,6 +22,10 @@ import org.lwjgl.glfw.*;
import android.view.*;
import android.widget.Toast;
import static android.os.Build.VERSION_CODES.P;
import static net.kdt.pojavlaunch.prefs.LauncherPreferences.PREF_IGNORE_NOTCH;
import static net.kdt.pojavlaunch.prefs.LauncherPreferences.PREF_NOTCH_SIZE;
public final class Tools
{
public static final boolean ENABLE_DEV_FEATURES = BuildConfig.DEBUG;
@ -314,7 +316,17 @@ public final class Tools
public static DisplayMetrics getDisplayMetrics(Activity ctx) {
DisplayMetrics displayMetrics = new DisplayMetrics();
ctx.getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.N && (ctx.isInMultiWindowMode() || ctx.isInPictureInPictureMode())){
//For devices with free form/split screen, we need window size, not screen size.
displayMetrics = ctx.getResources().getDisplayMetrics();
}else{
ctx.getDisplay().getRealMetrics(displayMetrics);
if(!PREF_IGNORE_NOTCH){
//Remove notch width when it isn't ignored.
displayMetrics.widthPixels -= PREF_NOTCH_SIZE;
}
}
return displayMetrics;
}
@ -336,22 +348,12 @@ public final class Tools
}
public static DisplayMetrics currentDisplayMetrics;
public static void updateWindowSize(Activity ctx) {
currentDisplayMetrics = getDisplayMetrics(ctx);
Point point = new Point();
ctx.getWindowManager().getDefaultDisplay().getRealSize(point); //Used to get the full screen width/height regardless of a notch/status bar.
currentDisplayMetrics.widthPixels = point.x;
currentDisplayMetrics.heightPixels = point.y;
CallbackBridge.physicalWidth = (int) (currentDisplayMetrics.widthPixels);
CallbackBridge.physicalHeight = (int) (currentDisplayMetrics.heightPixels);
if (CallbackBridge.physicalWidth < CallbackBridge.physicalHeight) {
CallbackBridge.physicalWidth = (int) (currentDisplayMetrics.heightPixels);
CallbackBridge.physicalHeight = (int) (currentDisplayMetrics.widthPixels);
}
}
public static float dpToPx(float dp) {
@ -810,4 +812,17 @@ public final class Tools
}
}
}
public static void ignoreNotch(boolean shouldIgnore, Activity ctx){
if (Build.VERSION.SDK_INT >= P) {
if (shouldIgnore) {
ctx.getWindow().getAttributes().layoutInDisplayCutoutMode = WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES;
} else {
ctx.getWindow().getAttributes().layoutInDisplayCutoutMode = WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_NEVER;
}
ctx.getWindow().setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN, WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN);
Tools.updateWindowSize(ctx);
}
}
}

View File

@ -13,6 +13,8 @@ public class LauncherPreferences
public static boolean PREF_VERTYPE_OLDBETA = false;
public static boolean PREF_FREEFORM = false;
public static boolean PREF_HIDE_SIDEBAR = false;
public static boolean PREF_IGNORE_NOTCH = false;
public static int PREF_NOTCH_SIZE = 0;
public static float PREF_BUTTONSIZE = 100f;
public static float PREF_MOUSESCALE = 100f;
public static int PREF_LONGPRESS_TRIGGER = 500;
@ -26,6 +28,7 @@ public class LauncherPreferences
PREF_MOUSESCALE = DEFAULT_PREF.getInt("mousescale", 100);
PREF_FREEFORM = DEFAULT_PREF.getBoolean("freeform", false);
PREF_HIDE_SIDEBAR = DEFAULT_PREF.getBoolean("hideSidebar", false);
PREF_IGNORE_NOTCH = DEFAULT_PREF.getBoolean("ignoreNotch", false);
PREF_VERTYPE_RELEASE = DEFAULT_PREF.getBoolean("vertype_release", true);
PREF_VERTYPE_SNAPSHOT = DEFAULT_PREF.getBoolean("vertype_snapshot", false);
PREF_VERTYPE_OLDALPHA = DEFAULT_PREF.getBoolean("vertype_oldalpha", false);

View File

@ -38,6 +38,12 @@
android:summary="@string/mcl_setting_subtitle_hide_sidebar"
android:title="@string/mcl_setting_title_hide_sidebar"
app2:icon="@drawable/hide_sidebar" />
<androidx.preference.SwitchPreferenceCompat
android:defaultValue="true"
android:key="ignoreNotch"
android:summary="@string/mcl_setting_subtitle_hide_sidebar"
android:title="@string/mcl_setting_title_hide_sidebar"
app2:icon="@drawable/hide_sidebar" />
<androidx.preference.SwitchPreferenceCompat
android:defaultValue="true"
android:key="autoRam"