1
0
Fork 0

fixed incorrect edge-to-edge behavior on Samsung S25 causing unnecessary bottom padding

This commit is contained in:
sspanak 2025-03-05 12:42:05 +02:00 committed by Dimo Karaivanov
parent 91d2476dc6
commit 742a3ed883
8 changed files with 60 additions and 4 deletions

View file

@ -5,7 +5,10 @@ import android.content.res.Configuration;
import android.content.res.Resources;
import android.os.Build;
import androidx.annotation.NonNull;
import io.github.sspanak.tt9.R;
import io.github.sspanak.tt9.preferences.settings.SettingsStore;
public class DeviceInfo extends HardwareInfo {
public static final boolean AT_LEAST_ANDROID_6 = Build.VERSION.SDK_INT >= Build.VERSION_CODES.M;
@ -26,7 +29,11 @@ public class DeviceInfo extends HardwareInfo {
}
public static int getNavigationBarHeight(Context context, boolean isLandscape) {
public static int getNavigationBarHeight(@NonNull Context context, @NonNull SettingsStore settings, boolean isLandscape) {
if (!settings.getPrecalculateNavbarHeight()) {
return 0;
}
Resources resources = getResources(context);
// navBarMode = 0: 3-button, 1 = 2-button, 2 = gesture

View file

@ -11,6 +11,9 @@ import android.view.KeyEvent;
import androidx.annotation.NonNull;
public class HardwareInfo {
public static final boolean IS_SAMSUNG = Build.MANUFACTURER.equals("samsung") || Build.MANUFACTURER.equals("Samsung") || Build.MANUFACTURER.equals("SAMSUNG");
private static Resources resources;

View file

@ -25,6 +25,7 @@ public class DebugScreen extends BaseScreenFragment {
(new ItemText(activity, findPreference(DEVICE_INFO_CONTAINER))).populate(new DeviceInfo().toString()).enableClickHandler();
(new ItemExportLogcat(findPreference(ItemExportLogcat.NAME), activity)).enableClickHandler();
(new ItemDemoMode(findPreference(ItemDemoMode.NAME), activity)).populate().enableClickHandler();
(new ItemPrecalculateNavbarHeight(activity.getSettings(), findPreference(ItemPrecalculateNavbarHeight.NAME))).populate();
resetFontSize(false);
}

View file

@ -0,0 +1,32 @@
package io.github.sspanak.tt9.preferences.screens.debug;
import androidx.annotation.NonNull;
import androidx.preference.Preference;
import androidx.preference.SwitchPreferenceCompat;
import io.github.sspanak.tt9.hacks.DeviceInfo;
import io.github.sspanak.tt9.preferences.items.ItemClickable;
import io.github.sspanak.tt9.preferences.settings.SettingsStore;
public class ItemPrecalculateNavbarHeight extends ItemClickable {
public static final String NAME = "hack_precalculate_navbar_height_v3";
private final SettingsStore settings;
public ItemPrecalculateNavbarHeight(@NonNull SettingsStore settings, Preference item) {
super(item);
this.settings = settings;
}
@Override
protected boolean onClick(Preference p) {
return true;
}
void populate() {
if (item != null) {
((SwitchPreferenceCompat) item).setChecked(settings.getPrecalculateNavbarHeight());
item.setVisible(DeviceInfo.AT_LEAST_ANDROID_15);
}
}
}

View file

@ -51,7 +51,6 @@ class SettingsHacks extends BaseSettings {
* There were reports about this on <a href="https://github.com/sspanak/tt9/issues/117">Kyocera KYF31</a>
* and on <a href="https://github.com/sspanak/tt9/issues/399">CAT S22</a>.
*/
public int getKeyPadDebounceTime() {
int defaultTime = DeviceInfo.isCatS22Flip() ? 50 : 0;
defaultTime = DeviceInfo.isQinF21() ? 20 : defaultTime;
@ -73,4 +72,14 @@ class SettingsHacks extends BaseSettings {
public boolean getAllowComposingText() {
return prefs.getBoolean("pref_allow_composing_text", true);
}
/**
* On Samsung S25 (SM-S931B), edge-to-edge does not work like on Pixel/Xiaomi/etc. Like on Android 14,
* the navigation bar is subtracted from the initial available screen size, so we must not add padding
* to compensate.
* @see <a href="https://github.com/sspanak/tt9/issues/755">extra space at the bottom of the layout</a>
*/
public boolean getPrecalculateNavbarHeight() {
return prefs.getBoolean("hack_precalculate_navbar_height_v3", !DeviceInfo.IS_SAMSUNG);
}
}

View file

@ -106,7 +106,7 @@ abstract class BaseMainLayout {
boolean isLandscape = DeviceInfo.isLandscapeOrientation(view.getContext());
int bottomPadding = isLandscape ? e2ePaddingBottomLandscape : e2ePaddingBottomPortrait;
bottomPadding = bottomPadding < 0 ? DeviceInfo.getNavigationBarHeight(view.getContext(), isLandscape) : bottomPadding;
bottomPadding = bottomPadding < 0 ? DeviceInfo.getNavigationBarHeight(view.getContext(), tt9.getSettings(), isLandscape) : bottomPadding;
view.setPadding(view.getPaddingLeft(), 0, view.getPaddingRight(), bottomPadding);
}

View file

@ -116,7 +116,7 @@ class MainLayoutNumpad extends BaseMainLayout {
int bottomPadding = 0;
if (DeviceInfo.AT_LEAST_ANDROID_15) {
bottomPadding = isLandscape ? e2ePaddingBottomLandscape : e2ePaddingBottomPortrait;
bottomPadding = bottomPadding < 0 ? DeviceInfo.getNavigationBarHeight(tt9.getApplicationContext(), isLandscape) : bottomPadding;
bottomPadding = bottomPadding < 0 ? DeviceInfo.getNavigationBarHeight(tt9.getApplicationContext(), tt9.getSettings(), isLandscape) : bottomPadding;
}
int screenHeight = DeviceInfo.getScreenHeight(tt9.getApplicationContext()) - bottomPadding;

View file

@ -12,6 +12,10 @@
android:title="@string/pref_category_usage_stats" />
<PreferenceCategory app:title="Hacks" app:singleLineTitle="true">
<SwitchPreferenceCompat
app:key="hack_precalculate_navbar_height_v3"
app:title="Precalculate Navbar Height" />
<SwitchPreferenceCompat
app:key="pref_demo_mode"
app:title="Demo Mode" />