Fix HTMLViewer rendering when edge-to-edge is enabled.
This change makes HTMLViewer account for the window insets. Without it
when edge-to-edge mode is enabled, the page contents will be drawn
behind the status bar and the action bar.
Test: manual
Flag: EXEMPT bugfix
Bug: b/330574528
Change-Id: I9cb155e852cab0965550cfb45815c89d96745e30
diff --git a/Android.bp b/Android.bp
index 39b80a1..24f41b1 100644
--- a/Android.bp
+++ b/Android.bp
@@ -8,6 +8,7 @@
manifest: "AndroidManifest.xml",
srcs: ["**/*.java"],
exclude_srcs: ["src/com/android/htmlviewer/CarHTMLViewerActivity.java"],
+ static_libs: ["androidx.core_core"],
sdk_version: "current",
}
@@ -17,6 +18,9 @@
overrides: ["HTMLViewer"],
srcs: ["**/*.java"],
libs: ["android.car-stubs"],
- static_libs: ["car-ui-lib"],
+ static_libs: [
+ "androidx.core_core",
+ "car-ui-lib",
+ ],
sdk_version: "current",
}
diff --git a/src/com/android/htmlviewer/HTMLViewerActivity.java b/src/com/android/htmlviewer/HTMLViewerActivity.java
index 233a87d..ded052c 100644
--- a/src/com/android/htmlviewer/HTMLViewerActivity.java
+++ b/src/com/android/htmlviewer/HTMLViewerActivity.java
@@ -34,6 +34,11 @@
import android.webkit.WebViewClient;
import android.widget.Toast;
+import androidx.core.graphics.Insets;
+import androidx.core.view.ViewCompat;
+import androidx.core.view.WindowCompat;
+import androidx.core.view.WindowInsetsCompat;
+
import java.io.IOException;
import java.io.InputStream;
import java.net.URISyntaxException;
@@ -84,6 +89,7 @@
}
protected void setContentView() {
+ setupEdgeToEdge();
setContentView(R.layout.main);
}
@@ -187,4 +193,20 @@
return null;
}
}
+
+ private void setupEdgeToEdge() {
+ // Shamelessly copied from SettingsHomepageActivity
+ // https://cs.android.com/android/platform/superproject/main/+/main:packages/apps/Settings/src/com/android/settings/homepage/SettingsHomepageActivity.java;l=355;drc=6b4b7336bc0bdbbdbd144429b8dfb006503d6a7b
+ WindowCompat.setDecorFitsSystemWindows(getWindow(), false);
+ ViewCompat.setOnApplyWindowInsetsListener(findViewById(android.R.id.content),
+ (v, windowInsets) -> {
+ Insets insets = windowInsets.getInsets(WindowInsetsCompat.Type.systemBars());
+ // Apply the insets paddings to the view.
+ v.setPadding(insets.left, insets.top, insets.right, insets.bottom);
+
+ // Return CONSUMED if you don't want the window insets to keep being
+ // passed down to descendant views.
+ return WindowInsetsCompat.CONSUMED;
+ });
+ }
}