diff options
| author | Benjamin Linskey | 2025-09-29 00:43:59 -0400 |
|---|---|---|
| committer | Benjamin Linskey | 2025-09-29 00:43:59 -0400 |
| commit | 7671581ceb1bbb069d184b9d17192c6fd17c2c5c (patch) | |
| tree | 3dfd9df60a802de14d84e577bc4b0a12e2aede98 | |
| parent | ad882a468e700745c5ff8210d95df9cc2f991963 (diff) | |
| download | greek-reference-7671581ceb1bbb069d184b9d17192c6fd17c2c5c.tar.gz | |
Fix edge-to-edge layout
12 files changed, 94 insertions, 190 deletions
diff --git a/GreekReference/build.gradle b/GreekReference/build.gradle index 6bb0f62..47b26f7 100644 --- a/GreekReference/build.gradle +++ b/GreekReference/build.gradle @@ -17,11 +17,11 @@ repositories { android { namespace 'com.benlinskey.greekreference' - compileSdk 35 + compileSdk 36 defaultConfig { minSdkVersion 21 //noinspection EditedTargetSdkVersion - targetSdkVersion 35 + targetSdkVersion 36 versionCode 33 versionName "1.14.0" } @@ -59,5 +59,7 @@ dependencies { implementation 'androidx.legacy:legacy-support-v4:1.0.0' implementation 'androidx.appcompat:appcompat:1.7.1' implementation 'androidx.drawerlayout:drawerlayout:1.2.0' + implementation 'androidx.core:core:1.17.0' implementation 'com.readystatesoftware.sqliteasset:sqliteassethelper:2.0.1' + implementation 'com.google.android.material:material:1.13.0' } diff --git a/GreekReference/src/main/java/com/benlinskey/greekreference/ScrimInsetsFrameLayout.java b/GreekReference/src/main/java/com/benlinskey/greekreference/ScrimInsetsFrameLayout.java deleted file mode 100644 index 0788c7c..0000000 --- a/GreekReference/src/main/java/com/benlinskey/greekreference/ScrimInsetsFrameLayout.java +++ /dev/null @@ -1,162 +0,0 @@ -/* - * Copyright 2015 Benjamin Linskey - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/* - * Copyright 2014 Google Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/* This file has been modified from the original copy published by Google. */ - -package com.benlinskey.greekreference; - -import android.content.Context; -import android.content.res.TypedArray; -import android.graphics.Canvas; -import android.graphics.Rect; -import android.graphics.drawable.Drawable; -import androidx.core.view.ViewCompat; -import android.util.AttributeSet; -import android.widget.FrameLayout; - -/** - * A layout that draws something in the insets passed to {@link #fitSystemWindows(Rect)}, i.e. the - * area above UI chrome (status and navigation bars, overlay action bars). - * <p> - * This is a copy of a class from the Google I/O Android App (https://github.com/google/iosched) - * with a few trivial modifications. For an explanation of how this class is used, see - * http://stackoverflow.com/a/27153313/2530735. - */ -public class ScrimInsetsFrameLayout extends FrameLayout { - private Drawable mInsetForeground; - - private Rect mInsets; - private final Rect mTempRect = new Rect(); - private OnInsetsCallback mOnInsetsCallback; - - public ScrimInsetsFrameLayout(Context context) { - super(context); - init(context, null, 0); - } - - public ScrimInsetsFrameLayout(Context context, AttributeSet attrs) { - super(context, attrs); - init(context, attrs, 0); - } - - public ScrimInsetsFrameLayout(Context context, AttributeSet attrs, int defStyle) { - super(context, attrs, defStyle); - init(context, attrs, defStyle); - } - - private void init(Context context, AttributeSet attrs, int defStyle) { - final TypedArray a = context.obtainStyledAttributes(attrs, - R.styleable.ScrimInsetsView, defStyle, 0); - if (a == null) { - return; - } - mInsetForeground = a.getDrawable(R.styleable.ScrimInsetsView_insetForeground); - a.recycle(); - - setWillNotDraw(true); - } - - @Override - protected boolean fitSystemWindows(Rect insets) { - mInsets = new Rect(insets); - setWillNotDraw(mInsetForeground == null); - ViewCompat.postInvalidateOnAnimation(this); - if (mOnInsetsCallback != null) { - mOnInsetsCallback.onInsetsChanged(insets); - } - return true; // consume insets - } - - @Override - public void draw(Canvas canvas) { - super.draw(canvas); - - int width = getWidth(); - int height = getHeight(); - if (mInsets != null && mInsetForeground != null) { - int sc = canvas.save(); - canvas.translate(getScrollX(), getScrollY()); - - // Top - mTempRect.set(0, 0, width, mInsets.top); - mInsetForeground.setBounds(mTempRect); - mInsetForeground.draw(canvas); - - // Bottom - mTempRect.set(0, height - mInsets.bottom, width, height); - mInsetForeground.setBounds(mTempRect); - mInsetForeground.draw(canvas); - - // Left - mTempRect.set(0, mInsets.top, mInsets.left, height - mInsets.bottom); - mInsetForeground.setBounds(mTempRect); - mInsetForeground.draw(canvas); - - // Right - mTempRect.set(width - mInsets.right, mInsets.top, width, height - mInsets.bottom); - mInsetForeground.setBounds(mTempRect); - mInsetForeground.draw(canvas); - - canvas.restoreToCount(sc); - } - } - - @Override - protected void onAttachedToWindow() { - super.onAttachedToWindow(); - if (mInsetForeground != null) { - mInsetForeground.setCallback(this); - } - } - - @Override - protected void onDetachedFromWindow() { - super.onDetachedFromWindow(); - if (mInsetForeground != null) { - mInsetForeground.setCallback(null); - } - } - - /** - * Allows the calling container to specify a callback for custom processing when insets change (i.e. when - * {@link #fitSystemWindows(Rect)} is called. This is useful for setting padding on UI elements based on - * UI chrome insets (e.g. a Google Map or a ListView). When using with ListView or GridView, remember to set - * clipToPadding to false. - */ - public void setOnInsetsCallback(OnInsetsCallback onInsetsCallback) { - mOnInsetsCallback = onInsetsCallback; - } - - public interface OnInsetsCallback { - void onInsetsChanged(Rect insets); - } -} diff --git a/GreekReference/src/main/java/com/benlinskey/greekreference/views/MainActivity.java b/GreekReference/src/main/java/com/benlinskey/greekreference/views/MainActivity.java index c00d03d..b593ed8 100644 --- a/GreekReference/src/main/java/com/benlinskey/greekreference/views/MainActivity.java +++ b/GreekReference/src/main/java/com/benlinskey/greekreference/views/MainActivity.java @@ -26,8 +26,14 @@ import android.content.Intent; import android.content.SharedPreferences; import android.os.Bundle; import android.preference.PreferenceManager; + +import androidx.activity.EdgeToEdge; import androidx.annotation.NonNull; +import androidx.core.graphics.Insets; import androidx.core.view.MenuItemCompat; +import androidx.core.view.ViewCompat; +import androidx.core.view.WindowCompat; +import androidx.core.view.WindowInsetsCompat; import androidx.drawerlayout.widget.DrawerLayout; import androidx.appcompat.app.ActionBar; import androidx.appcompat.widget.SearchView; @@ -35,6 +41,7 @@ import androidx.appcompat.widget.Toolbar; import android.view.Menu; import android.view.MenuItem; import android.view.View; +import android.view.ViewGroup; import com.benlinskey.greekreference.views.detail.AbstractDetailFragment; import com.benlinskey.greekreference.views.list.AbstractListFragment; @@ -89,6 +96,7 @@ public class MainActivity @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); + WindowCompat.enableEdgeToEdge(getWindow()); setContentView(R.layout.activity_item_list); mMainPresenter = new MainPresenter(this, this); @@ -101,6 +109,14 @@ public class MainActivity Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar_actionbar); setSupportActionBar(toolbar); + ViewCompat.setOnApplyWindowInsetsListener(toolbar, (view, windowInsets) -> { + Insets insets = windowInsets.getInsets(WindowInsetsCompat.Type.systemBars()); + ViewGroup.MarginLayoutParams mlp = (ViewGroup.MarginLayoutParams) view.getLayoutParams(); + mlp.topMargin = insets.top; + view.setLayoutParams(mlp); + return WindowInsetsCompat.CONSUMED; + }); + // Restore any saved state. if (null == savedInstanceState) { mTitle = getString(R.string.title_lexicon); diff --git a/GreekReference/src/main/java/com/benlinskey/greekreference/views/PerseusToolActivity.java b/GreekReference/src/main/java/com/benlinskey/greekreference/views/PerseusToolActivity.java index 8f1745c..96c9310 100644 --- a/GreekReference/src/main/java/com/benlinskey/greekreference/views/PerseusToolActivity.java +++ b/GreekReference/src/main/java/com/benlinskey/greekreference/views/PerseusToolActivity.java @@ -29,11 +29,17 @@ import androidx.annotation.NonNull; import androidx.appcompat.app.ActionBar; import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.widget.Toolbar; +import androidx.core.graphics.Insets; +import androidx.core.view.ViewCompat; +import androidx.core.view.WindowCompat; +import androidx.core.view.WindowInsetsCompat; + import android.text.Html; import android.text.method.LinkMovementMethod; import android.view.KeyEvent; import android.view.Menu; import android.view.MenuItem; +import android.view.ViewGroup; import android.view.Window; import android.webkit.WebChromeClient; import android.webkit.WebSettings; @@ -62,6 +68,7 @@ public class PerseusToolActivity extends AbstractContainerActivity { protected void onCreate(Bundle savedInstanceState) { getWindow().requestFeature(Window.FEATURE_PROGRESS); super.onCreate(savedInstanceState); + WindowCompat.enableEdgeToEdge(getWindow()); setContentView(R.layout.activity_perseus_tool); // Set the status bar background color. @@ -72,7 +79,15 @@ public class PerseusToolActivity extends AbstractContainerActivity { // Set the toolbar to act as the action bar. Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar_actionbar); setSupportActionBar(toolbar); - + + ViewCompat.setOnApplyWindowInsetsListener(toolbar, (view, windowInsets) -> { + Insets insets = windowInsets.getInsets(WindowInsetsCompat.Type.systemBars()); + ViewGroup.MarginLayoutParams mlp = (ViewGroup.MarginLayoutParams) view.getLayoutParams(); + mlp.topMargin = insets.top; + view.setLayoutParams(mlp); + return WindowInsetsCompat.CONSUMED; + }); + ActionBar actionBar = getSupportActionBar(); actionBar.setDisplayHomeAsUpEnabled(true); actionBar.setTitle(getString(R.string.title_lexicon)); diff --git a/GreekReference/src/main/java/com/benlinskey/greekreference/views/SettingsActivity.java b/GreekReference/src/main/java/com/benlinskey/greekreference/views/SettingsActivity.java index d00cbbd..daca5e2 100644 --- a/GreekReference/src/main/java/com/benlinskey/greekreference/views/SettingsActivity.java +++ b/GreekReference/src/main/java/com/benlinskey/greekreference/views/SettingsActivity.java @@ -28,8 +28,14 @@ import android.preference.PreferenceFragment; import android.preference.PreferenceScreen; import androidx.appcompat.app.ActionBar; import androidx.appcompat.widget.Toolbar; +import androidx.core.graphics.Insets; +import androidx.core.view.ViewCompat; +import androidx.core.view.WindowCompat; +import androidx.core.view.WindowInsetsCompat; + import android.view.Menu; import android.view.MenuItem; +import android.view.ViewGroup; import com.benlinskey.greekreference.R; @@ -41,6 +47,7 @@ public class SettingsActivity extends AbstractContainerActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); + WindowCompat.enableEdgeToEdge(getWindow()); setContentView(R.layout.activity_settings); // Set the status bar background color. @@ -52,6 +59,14 @@ public class SettingsActivity extends AbstractContainerActivity { Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar_actionbar); setSupportActionBar(toolbar); + ViewCompat.setOnApplyWindowInsetsListener(toolbar, (view, windowInsets) -> { + Insets insets = windowInsets.getInsets(WindowInsetsCompat.Type.systemBars()); + ViewGroup.MarginLayoutParams mlp = (ViewGroup.MarginLayoutParams) view.getLayoutParams(); + mlp.topMargin = insets.top; + view.setLayoutParams(mlp); + return WindowInsetsCompat.CONSUMED; + }); + // Show the Up button in the action bar. ActionBar actionBar = getSupportActionBar(); actionBar.setDisplayHomeAsUpEnabled(true); diff --git a/GreekReference/src/main/java/com/benlinskey/greekreference/views/detail/AbstractDetailActivity.java b/GreekReference/src/main/java/com/benlinskey/greekreference/views/detail/AbstractDetailActivity.java index e1ad2df..908f55b 100644 --- a/GreekReference/src/main/java/com/benlinskey/greekreference/views/detail/AbstractDetailActivity.java +++ b/GreekReference/src/main/java/com/benlinskey/greekreference/views/detail/AbstractDetailActivity.java @@ -23,7 +23,14 @@ import android.os.Bundle; import android.preference.PreferenceManager; import androidx.appcompat.app.ActionBar; import androidx.appcompat.widget.Toolbar; +import androidx.core.graphics.Insets; +import androidx.core.view.ViewCompat; +import androidx.core.view.WindowCompat; +import androidx.core.view.WindowInsetsCompat; + import android.view.MenuItem; +import android.view.ViewGroup; +import android.view.Window; import com.benlinskey.greekreference.R; import com.benlinskey.greekreference.views.SettingsActivity; @@ -41,6 +48,7 @@ public abstract class AbstractDetailActivity extends AbstractContainerActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); + WindowCompat.enableEdgeToEdge(getWindow()); setContentView(R.layout.activity_item_detail); PreferenceManager.setDefaultValues(this, R.xml.preferences, false); @@ -53,7 +61,15 @@ public abstract class AbstractDetailActivity extends AbstractContainerActivity { // Set the toolbar to act as the action bar. Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar_actionbar); setSupportActionBar(toolbar); - + + ViewCompat.setOnApplyWindowInsetsListener(toolbar, (view, windowInsets) -> { + Insets insets = windowInsets.getInsets(WindowInsetsCompat.Type.systemBars()); + ViewGroup.MarginLayoutParams mlp = (ViewGroup.MarginLayoutParams) view.getLayoutParams(); + mlp.topMargin = insets.top; + view.setLayoutParams(mlp); + return WindowInsetsCompat.CONSUMED; + }); + // Show the Up button in the action bar. ActionBar actionBar = getSupportActionBar(); actionBar.setDisplayHomeAsUpEnabled(true); diff --git a/GreekReference/src/main/res/layout/action_bar.xml b/GreekReference/src/main/res/layout/action_bar.xml index a4bb6a4..e8307a7 100644 --- a/GreekReference/src/main/res/layout/action_bar.xml +++ b/GreekReference/src/main/res/layout/action_bar.xml @@ -21,7 +21,7 @@ xmlns:tools="http://schemas.android.com/tools" android:id="@+id/toolbar_actionbar" android:layout_width="match_parent" - android:layout_height="wrap_content" + android:layout_height="?attr/actionBarSize" android:minHeight="?attr/actionBarSize" android:background="?attr/colorPrimary" android:elevation="@dimen/action_bar_elevation" diff --git a/GreekReference/src/main/res/layout/activity_item_detail.xml b/GreekReference/src/main/res/layout/activity_item_detail.xml index 0e2325e..3b6cdba 100644 --- a/GreekReference/src/main/res/layout/activity_item_detail.xml +++ b/GreekReference/src/main/res/layout/activity_item_detail.xml @@ -1,4 +1,4 @@ -<LinearLayout +<com.google.android.material.appbar.AppBarLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_height="match_parent" @@ -12,7 +12,8 @@ android:layout_width="match_parent" android:layout_height="fill_parent" tools:context=".ItemDetailActivity" - tools:ignore="MergeRootFrame"> + tools:ignore="MergeRootFrame" + android:background="#fff"> </FrameLayout> -</LinearLayout> +</com.google.android.material.appbar.AppBarLayout> diff --git a/GreekReference/src/main/res/layout/activity_item_list.xml b/GreekReference/src/main/res/layout/activity_item_list.xml index 85667df..c33985e 100644 --- a/GreekReference/src/main/res/layout/activity_item_list.xml +++ b/GreekReference/src/main/res/layout/activity_item_list.xml @@ -4,30 +4,30 @@ xmlns:tools="http://schemas.android.com/tools" android:id="@+id/drawer_layout" android:layout_width="match_parent" - android:layout_height="match_parent" - android:fitsSystemWindows="true"> - - <LinearLayout + android:layout_height="match_parent"> + + <com.google.android.material.appbar.AppBarLayout android:layout_width="match_parent" android:layout_height="match_parent" - android:orientation="vertical"> + android:orientation="vertical" + android:fitsSystemWindows="false"> <include layout="@layout/action_bar"/> <FrameLayout android:id="@+id/item_list_container" android:layout_height="match_parent" - android:layout_width="match_parent"/> + android:layout_width="match_parent" + android:background="#fff" /> - </LinearLayout> + </com.google.android.material.appbar.AppBarLayout> - <com.benlinskey.greekreference.ScrimInsetsFrameLayout + <android.widget.FrameLayout android:id="@+id/navigation_drawer_fragment_container" android:layout_width="@dimen/navigation_drawer_width" android:layout_height="match_parent" android:layout_gravity="start" android:elevation="10dp" - android:fitsSystemWindows="true" app:insetForeground="?attr/colorPrimaryDark" tools:ignore="UnusedAttribute"> @@ -37,6 +37,6 @@ android:layout_height="match_parent" android:name="com.benlinskey.greekreference.navigationdrawer.NavigationDrawerFragment" /> - </com.benlinskey.greekreference.ScrimInsetsFrameLayout> + </android.widget.FrameLayout> </androidx.drawerlayout.widget.DrawerLayout> diff --git a/GreekReference/src/main/res/layout/activity_item_twopane.xml b/GreekReference/src/main/res/layout/activity_item_twopane.xml index d1b6b73..7d8fa38 100644 --- a/GreekReference/src/main/res/layout/activity_item_twopane.xml +++ b/GreekReference/src/main/res/layout/activity_item_twopane.xml @@ -5,6 +5,7 @@ android:id="@+id/drawer_layout" android:layout_width="match_parent" android:layout_height="match_parent" + android:background="?attr/colorPrimaryDark" tools:context=".ItemListActivity"> <LinearLayout @@ -39,14 +40,12 @@ </LinearLayout> - <com.benlinskey.greekreference.ScrimInsetsFrameLayout + <android.widget.FrameLayout android:id="@+id/navigation_drawer_fragment_container" android:layout_width="@dimen/navigation_drawer_width" android:layout_height="match_parent" android:layout_gravity="start" android:elevation="10dp" - android:fitsSystemWindows="true" - app:insetForeground="?attr/colorPrimaryDark" tools:ignore="UnusedAttribute"> <fragment android:id="@+id/navigation_drawer_fragment" @@ -55,7 +54,7 @@ android:layout_gravity="start" android:name="com.benlinskey.greekreference.navigationdrawer.NavigationDrawerFragment" /> - </com.benlinskey.greekreference.ScrimInsetsFrameLayout> + </android.widget.FrameLayout> </androidx.drawerlayout.widget.DrawerLayout> diff --git a/GreekReference/src/main/res/layout/activity_perseus_tool.xml b/GreekReference/src/main/res/layout/activity_perseus_tool.xml index fdc878f..237d06c 100644 --- a/GreekReference/src/main/res/layout/activity_perseus_tool.xml +++ b/GreekReference/src/main/res/layout/activity_perseus_tool.xml @@ -16,7 +16,7 @@ ~ limitations under the License. --> -<LinearLayout +<com.google.android.material.appbar.AppBarLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" @@ -27,6 +27,7 @@ <WebView android:id="@+id/perseus_tool_webview" android:layout_width="fill_parent" - android:layout_height="fill_parent"/> + android:layout_height="fill_parent" + android:background="#fff"/> -</LinearLayout> +</com.google.android.material.appbar.AppBarLayout> diff --git a/GreekReference/src/main/res/layout/activity_settings.xml b/GreekReference/src/main/res/layout/activity_settings.xml index 81373ae..c699e2f 100644 --- a/GreekReference/src/main/res/layout/activity_settings.xml +++ b/GreekReference/src/main/res/layout/activity_settings.xml @@ -1,6 +1,6 @@ <?xml version="1.0" encoding="utf-8"?> -<LinearLayout +<com.google.android.material.appbar.AppBarLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/root_layout" android:layout_height="match_parent" @@ -12,6 +12,7 @@ <FrameLayout android:id="@+id/container" android:layout_width="match_parent" - android:layout_height="match_parent"/> + android:layout_height="match_parent" + android:background="#fff"/> -</LinearLayout> +</com.google.android.material.appbar.AppBarLayout> |