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;
}
});

View File

@@ -3,9 +3,6 @@
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".PcView" >
<RelativeLayout
@@ -25,6 +22,8 @@
android:id="@+id/no_pc_found_layout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:layout_centerInParent="true"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true">

View File

@@ -8,4 +8,5 @@
android:stretchMode="spacingWidthUniform"
android:focusable="true"
android:focusableInTouchMode="true"
android:clipToPadding="false"
android:gravity="center"/>

View File

@@ -8,4 +8,5 @@
android:stretchMode="spacingWidthUniform"
android:focusable="true"
android:focusableInTouchMode="true"
android:clipToPadding="false"
android:gravity="center"/>

View File

@@ -1,19 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<ListView
android:id="@+id/fragmentView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/list_view_unselected"
android:fastScrollEnabled="true"
android:longClickable="false"
android:focusable="true"
android:focusableInTouchMode="true"
android:stackFromBottom="false" >
</ListView>
</LinearLayout>
<ListView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/fragmentView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fastScrollEnabled="true"
android:longClickable="false"
android:focusable="true"
android:focusableInTouchMode="true"
android:stackFromBottom="false"
android:clipToPadding="false"/>

View File

@@ -9,4 +9,5 @@
android:focusable="true"
android:focusableInTouchMode="true"
android:nextFocusLeft="@id/settingsButton"
android:clipToPadding="false"
android:gravity="center"/>

View File

@@ -9,4 +9,5 @@
android:focusable="true"
android:focusableInTouchMode="true"
android:nextFocusLeft="@id/settingsButton"
android:clipToPadding="false"
android:gravity="center"/>