Fix grid/list items being occluded by the navbar on Q with gestures off

This commit is contained in:
Cameron Gutman
2019-08-13 22:18:03 -07:00
parent ad3614c58e
commit 5b5277bf3f
10 changed files with 64 additions and 26 deletions

View File

@@ -560,6 +560,7 @@ public class AppView extends Activity implements AdapterFragmentCallbacks {
}
}
});
UiHelper.applyStatusBarPadding(listView);
registerForContextMenu(listView);
listView.requestFocus();
}

View File

@@ -716,6 +716,7 @@ public class PcView extends Activity implements AdapterFragmentCallbacks {
}
}
});
UiHelper.applyStatusBarPadding(listView);
registerForContextMenu(listView);
}

View File

@@ -15,6 +15,9 @@ import android.preference.PreferenceManager;
import android.preference.PreferenceScreen;
import android.util.Range;
import android.view.Display;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import com.limelight.LimeLog;
import com.limelight.PcView;
@@ -121,9 +124,17 @@ public class StreamSettings extends Activity {
.apply();
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = super.onCreateView(inflater, container, savedInstanceState);
UiHelper.applyStatusBarPadding(view);
return view;
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.preferences);
PreferenceScreen screen = getPreferenceScreen();

View File

@@ -5,6 +5,7 @@ import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.SharedPreferences;
import android.content.res.Configuration;
import android.graphics.Insets;
import android.os.Build;
import android.view.View;
import android.view.WindowInsets;
@@ -40,7 +41,24 @@ public class UiHelper {
}
}
public static void notifyNewRootView(Activity activity)
public static void applyStatusBarPadding(View view) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
// This applies the padding that we omitted in notifyNewRootView() on Q
view.setOnApplyWindowInsetsListener(new View.OnApplyWindowInsetsListener() {
@Override
public WindowInsets onApplyWindowInsets(View view, WindowInsets windowInsets) {
view.setPadding(view.getPaddingLeft(),
view.getPaddingTop(),
view.getPaddingRight(),
windowInsets.getTappableElementInsets().bottom);
return windowInsets;
}
});
view.requestApplyInsets();
}
}
public static void notifyNewRootView(final Activity activity)
{
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
// Allow this non-streaming activity to layout under notches.
@@ -55,13 +73,25 @@ public class UiHelper {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
// Draw under the status bar on Android Q devices
activity.getWindow().getDecorView().setOnApplyWindowInsetsListener(new View.OnApplyWindowInsetsListener() {
// Using getDecorView() here breaks the translucent status/navigation bar when gestures are disabled
activity.findViewById(android.R.id.content).setOnApplyWindowInsetsListener(new View.OnApplyWindowInsetsListener() {
@Override
public WindowInsets onApplyWindowInsets(View view, WindowInsets windowInsets) {
view.setPadding(windowInsets.getSystemWindowInsetLeft(),
windowInsets.getSystemWindowInsetTop(),
windowInsets.getSystemWindowInsetRight(),
// Use the tappable insets so we can draw under the status bar in gesture mode
Insets tappableInsets = windowInsets.getTappableElementInsets();
view.setPadding(tappableInsets.left,
tappableInsets.top,
tappableInsets.right,
0);
// Show a translucent navigation bar if we can't tap there
if (tappableInsets.bottom != 0) {
activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
}
else {
activity.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
}
return windowInsets;
}
});