From b10a222ee72a1627ed1b20efbc3e7e9d71104b3c Mon Sep 17 00:00:00 2001 From: Aayush Gupta Date: Sat, 2 Nov 2024 15:39:51 +0530 Subject: [PATCH] ExactCalculator: Setup for edge to edge support Change-Id: Id77e643af7600fac4599d9641e6bf887f18aa18e Signed-off-by: Aayush Gupta --- res/drawable/activity_background.xml | 15 +++++++++++++++ res/layout-land/activity_calculator.xml | 1 + res/layout/activity_calculator.xml | 1 + src/com/android/calculator2/Calculator.java | 15 +++++++++++++++ 4 files changed, 32 insertions(+) create mode 100644 res/drawable/activity_background.xml diff --git a/res/drawable/activity_background.xml b/res/drawable/activity_background.xml new file mode 100644 index 00000000..5e0f602c --- /dev/null +++ b/res/drawable/activity_background.xml @@ -0,0 +1,15 @@ + + + + + + + diff --git a/res/layout-land/activity_calculator.xml b/res/layout-land/activity_calculator.xml index 85d8b6ce..364eeb05 100644 --- a/res/layout-land/activity_calculator.xml +++ b/res/layout-land/activity_calculator.xml @@ -9,6 +9,7 @@ android:id="@+id/main_calculator" android:layout_width="match_parent" android:layout_height="match_parent" + android:background="@drawable/activity_background" android:orientation="vertical" app:layoutDescription="@xml/activity_calculator_scene"> diff --git a/res/layout/activity_calculator.xml b/res/layout/activity_calculator.xml index 5d5cfb35..fecd892d 100644 --- a/res/layout/activity_calculator.xml +++ b/res/layout/activity_calculator.xml @@ -9,6 +9,7 @@ android:id="@+id/main_calculator" android:layout_width="match_parent" android:layout_height="match_parent" + android:background="@drawable/activity_background" android:orientation="vertical" app:layoutDescription="@xml/activity_calculator_scene"> diff --git a/src/com/android/calculator2/Calculator.java b/src/com/android/calculator2/Calculator.java index 770f2670..06ff16fe 100644 --- a/src/com/android/calculator2/Calculator.java +++ b/src/com/android/calculator2/Calculator.java @@ -51,6 +51,10 @@ import androidx.appcompat.widget.Toolbar; import androidx.constraintlayout.motion.widget.MotionLayout; import androidx.core.content.ContextCompat; +import androidx.core.graphics.Insets; +import androidx.core.view.ViewCompat; +import androidx.core.view.WindowCompat; +import androidx.core.view.WindowInsetsCompat; import androidx.fragment.app.Fragment; import androidx.fragment.app.FragmentManager; @@ -304,6 +308,7 @@ protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_calculator); + setupEdgeToEdge(); setSupportActionBar((Toolbar) findViewById(R.id.toolbar)); // Hide all default options in the ActionBar. @@ -1251,4 +1256,14 @@ public void onContextMenuClosed(Menu menu) { public interface OnDisplayMemoryOperationsListener { boolean shouldDisplayMemory(); } + + private void setupEdgeToEdge() { + WindowCompat.setDecorFitsSystemWindows(getWindow(), false); + ViewCompat.setOnApplyWindowInsetsListener(requireViewById(R.id.main_calculator), + (v, windowInsets) -> { + Insets insets = windowInsets.getInsets(WindowInsetsCompat.Type.systemBars()); + v.setPadding(0, insets.top, 0, insets.bottom); + return WindowInsetsCompat.CONSUMED; + }); + } }