Skip to content

Commit

Permalink
Enable edge-to-edge in the AttestationActivity
Browse files Browse the repository at this point in the history
  • Loading branch information
t895 authored and thestinger committed Apr 19, 2024
1 parent 25d2749 commit 89c391b
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 3 deletions.
24 changes: 24 additions & 0 deletions app/src/main/java/app/attestation/auditor/AttestationActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,19 @@
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewTreeObserver;
import android.widget.LinearLayout;

import androidx.activity.EdgeToEdge;
import androidx.activity.OnBackPressedCallback;
import androidx.activity.result.ActivityResultLauncher;
import androidx.activity.result.contract.ActivityResultContracts;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;
import androidx.preference.PreferenceManager;

import com.google.android.material.dialog.MaterialAlertDialogBuilder;
Expand Down Expand Up @@ -253,13 +258,32 @@ private static boolean potentialSupportedAuditee() {

@Override
protected void onCreate(Bundle savedInstanceState) {
EdgeToEdge.enable(this);
super.onCreate(savedInstanceState);

binding = ActivityAttestationBinding.inflate(getLayoutInflater());
View rootView = binding.getRoot();
setContentView(rootView);
setSupportActionBar(binding.toolbar);

ViewCompat.setOnApplyWindowInsetsListener(binding.getRoot(), (@NonNull View v, @NonNull WindowInsetsCompat insets) -> {
Insets barInsets = insets.getInsets(WindowInsetsCompat.Type.systemBars());
Insets cutoutInsets = insets.getInsets(WindowInsetsCompat.Type.displayCutout());

int leftInsets = barInsets.left + cutoutInsets.left;
int rightInsets = barInsets.right + cutoutInsets.right;

binding.toolbar.setPadding(leftInsets, 0, rightInsets, 0);
binding.content.buttons.setPadding(0, 0, 0, barInsets.bottom);

ViewGroup.MarginLayoutParams mlpScrollView = (ViewGroup.MarginLayoutParams) binding.content.scrollview.getLayoutParams();
mlpScrollView.leftMargin = leftInsets;
mlpScrollView.rightMargin = rightInsets;
binding.content.scrollview.setLayoutParams(mlpScrollView);

return insets;
});

snackbar = Snackbar.make(rootView, "", Snackbar.LENGTH_LONG);

binding.content.auditee.setOnClickListener((final View view) -> {
Expand Down
4 changes: 1 addition & 3 deletions app/src/main/res/layout/activity_attestation.xml
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http:https://schemas.android.com/apk/res/android"
xmlns:app="http:https://schemas.android.com/apk/res-auto"
xmlns:tools="http:https://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context="app.attestation.auditor.AttestationActivity">

<com.google.android.material.appbar.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay">
android:fitsSystemWindows="true">

<com.google.android.material.appbar.MaterialToolbar
android:id="@+id/toolbar"
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/layout/content_attestation.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
tools:showIn="@layout/activity_attestation">

<ScrollView
android:id="@+id/scrollview"
android:layout_width="match_parent"
android:layout_height="match_parent">

Expand Down

0 comments on commit 89c391b

Please sign in to comment.