Skip to content

Commit

Permalink
Don't allow fullscreen option on devices with top-left camera cutout.
Browse files Browse the repository at this point in the history
  • Loading branch information
CDrummond committed Aug 10, 2024
1 parent 5b7b0a1 commit c5dba34
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 4 deletions.
6 changes: 5 additions & 1 deletion fastlane/metadata/android/en-US/changelogs/603.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
Fixed
Improved

• Use WindowInsets to calculate top and bottom padding required.

Fixed

• Fix starting Squeezelite (via Termux)
• Don't allow fullscreen option on devices with top-left camera cutout.
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,7 @@ private String getConfiguredUrl() {
if (scale<5) {
adjust += (5-scale)/10.0;
}
Utils.cutoutTopLeft(this);
builder.appendQueryParameter("topPad", ""+(int) Math.ceil(Utils.getTopPadding(this)*adjust));
builder.appendQueryParameter("botPad", ""+(int)Math.ceil(Utils.getBottomPadding(this)*adjust));
if (!Utils.usingGestureNavigation(this)) {
Expand Down Expand Up @@ -339,7 +340,8 @@ private void setDefaults() {
editor.putBoolean(SettingsActivity.KEEP_SCREEN_ON_PREF_KEY, false);
modified=true;
}
if (!sharedPreferences.contains(SettingsActivity.FULLSCREEN_PREF_KEY)) {
if (!sharedPreferences.contains(SettingsActivity.FULLSCREEN_PREF_KEY) ||
(sharedPreferences.getBoolean(SettingsActivity.FULLSCREEN_PREF_KEY, false) && Utils.cutoutTopLeft(this))) {
editor.putBoolean(SettingsActivity.FULLSCREEN_PREF_KEY, false);
modified=true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ public static boolean isVisible() {
}

private SettingsFragment fragment;
private SettingsActivity activity;

@Override
protected void onCreate(Bundle savedInstanceState) {
Expand All @@ -86,6 +87,7 @@ protected void onCreate(Bundle savedInstanceState) {

visible = true;
setContentView(R.layout.settings_activity);
activity = this;
fragment = new SettingsFragment();
fragment.setActivity(this);
getSupportFragmentManager()
Expand Down Expand Up @@ -268,7 +270,7 @@ public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
});
}

final Preference defaultPlayerButton = getPreferenceManager().findPreference("default_player");
final Preference defaultPlayerButton = getPreferenceManager().findPreference(DEFAULT_PLAYER_PREF_KEY);
if (defaultPlayerButton != null) {
String defaultPlayer = sharedPreferences.getString(DEFAULT_PLAYER_PREF_KEY, null);
if (defaultPlayer!=null && !defaultPlayer.isEmpty()) {
Expand Down Expand Up @@ -387,6 +389,13 @@ public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
}
}

if (Utils.cutoutTopLeft(activity)) {
SwitchPreferenceCompat fullscreenPref = getPreferenceManager().findPreference("fullscreen");
if (null != fullscreenPref) {
fullscreenPref.setVisible(false);
}
}

updateListSummary(ORIENTATION_PREF_KEY);
updateListSummary(ON_CALL_PREF_KEY);
updateListSummary(PLAYER_APP_PREF_KEY);
Expand Down
19 changes: 18 additions & 1 deletion lms-material/src/main/java/com/craigd/lmsmaterial/app/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,40 @@
import android.content.pm.PackageManager;
import android.content.res.Resources;
import android.graphics.Insets;
import android.graphics.Rect;
import android.os.Build;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.DisplayCutout;
import android.view.Window;
import android.view.WindowInsets;

import androidx.core.app.ActivityCompat;
import androidx.core.app.NotificationManagerCompat;

import java.util.List;

public class Utils {
public static final String LOG_TAG = "LMS";

public static float convertPixelsToDp(float px, Context context){
return px / ((float) context.getResources().getDisplayMetrics().densityDpi / DisplayMetrics.DENSITY_DEFAULT);
}

public static boolean cutoutTopLeft(Activity activity) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
DisplayCutout displayCutout = activity.getWindowManager().getDefaultDisplay().getCutout();
if (null != displayCutout) {
List<Rect> rects = displayCutout.getBoundingRects();
for (Rect rect : rects) {
if (rect.left >= 0 && rect.left <= 10 && rect.width() > 100 && rect.width()<300) {
return true;
}
}
}
}
return false;
}

public static boolean usingGestureNavigation(Activity activity) {
Resources resources = activity.getResources();
@SuppressLint("DiscouragedApi") int resourceId = resources.getIdentifier("config_navBarInteractionMode", "integer", "android");
Expand Down

0 comments on commit c5dba34

Please sign in to comment.