From 98d0e964943c9752288e523f8411b8a057bd25a7 Mon Sep 17 00:00:00 2001 From: Amit Kumar Date: Mon, 12 Oct 2020 19:25:01 +0530 Subject: [PATCH] Use insettable for widgets page so that edit button is not hidden behind nav bar. --- .../core/customviews/HorizontalPager.java | 10 +++++++++ .../core/customviews/InsettableFrameLayout.kt | 21 +++++++++++++++++++ .../customviews/InsettableScrollLayout.java | 13 +----------- .../features/launcher/LauncherActivity.java | 3 ++- app/src/main/res/layout/widgets_page.xml | 4 ++-- 5 files changed, 36 insertions(+), 15 deletions(-) create mode 100644 app/src/main/java/foundation/e/blisslauncher/core/customviews/InsettableFrameLayout.kt diff --git a/app/src/main/java/foundation/e/blisslauncher/core/customviews/HorizontalPager.java b/app/src/main/java/foundation/e/blisslauncher/core/customviews/HorizontalPager.java index c7c3e81eba..aa8cdf2068 100755 --- a/app/src/main/java/foundation/e/blisslauncher/core/customviews/HorizontalPager.java +++ b/app/src/main/java/foundation/e/blisslauncher/core/customviews/HorizontalPager.java @@ -563,6 +563,16 @@ public class HorizontalPager extends ViewGroup implements Insettable { } } + @Override + public void onViewAdded(View child) { + super.onViewAdded(child); + Log.d(TAG, "onViewAdded() called with: child = [" + child + "]"); + if (child instanceof Insettable) { + Log.d(TAG, "child is instance of insettable"); + ((Insettable) child).setInsets(insets); + } + } + public static class SavedState extends BaseSavedState { int currentScreen = -1; diff --git a/app/src/main/java/foundation/e/blisslauncher/core/customviews/InsettableFrameLayout.kt b/app/src/main/java/foundation/e/blisslauncher/core/customviews/InsettableFrameLayout.kt new file mode 100644 index 0000000000..373db03b4c --- /dev/null +++ b/app/src/main/java/foundation/e/blisslauncher/core/customviews/InsettableFrameLayout.kt @@ -0,0 +1,21 @@ +package foundation.e.blisslauncher.core.customviews + +import android.content.Context +import android.util.AttributeSet +import android.view.WindowInsets +import android.widget.FrameLayout +import foundation.e.blisslauncher.BlissLauncher + +class InsettableFrameLayout(private val mContext: Context, attrs: AttributeSet?) : FrameLayout( + mContext, attrs +), Insettable { + + override fun setInsets(insets: WindowInsets?) { + if (insets == null) return + val deviceProfile = BlissLauncher.getApplication(mContext).deviceProfile + setPadding( + paddingLeft, paddingTop, + paddingRight, paddingBottom + insets.systemWindowInsetBottom + ) + } +} \ No newline at end of file diff --git a/app/src/main/java/foundation/e/blisslauncher/core/customviews/InsettableScrollLayout.java b/app/src/main/java/foundation/e/blisslauncher/core/customviews/InsettableScrollLayout.java index 725dbfa64a..126f21834c 100644 --- a/app/src/main/java/foundation/e/blisslauncher/core/customviews/InsettableScrollLayout.java +++ b/app/src/main/java/foundation/e/blisslauncher/core/customviews/InsettableScrollLayout.java @@ -2,13 +2,12 @@ package foundation.e.blisslauncher.core.customviews; import android.content.Context; import android.util.AttributeSet; -import android.view.WindowInsets; import android.widget.ScrollView; import androidx.annotation.NonNull; import androidx.annotation.Nullable; -public class InsettableScrollLayout extends ScrollView implements Insettable { +public class InsettableScrollLayout extends ScrollView { public InsettableScrollLayout(@NonNull Context context) { super(context); @@ -21,14 +20,4 @@ public class InsettableScrollLayout extends ScrollView implements Insettable { public InsettableScrollLayout(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); } - - @Override - public void setInsets(WindowInsets insets) { - if(insets == null) return; - int top = getPaddingTop(); - int left = getPaddingLeft(); - int right = getPaddingRight(); - int bottom = getPaddingBottom(); - setPadding(left, top, right, bottom + insets.getSystemWindowInsetBottom()); - } } diff --git a/app/src/main/java/foundation/e/blisslauncher/features/launcher/LauncherActivity.java b/app/src/main/java/foundation/e/blisslauncher/features/launcher/LauncherActivity.java index 7b79beb9f5..d97c275890 100755 --- a/app/src/main/java/foundation/e/blisslauncher/features/launcher/LauncherActivity.java +++ b/app/src/main/java/foundation/e/blisslauncher/features/launcher/LauncherActivity.java @@ -101,6 +101,7 @@ import foundation.e.blisslauncher.core.customviews.BlissFrameLayout; import foundation.e.blisslauncher.core.customviews.BlissInput; import foundation.e.blisslauncher.core.customviews.DockGridLayout; import foundation.e.blisslauncher.core.customviews.HorizontalPager; +import foundation.e.blisslauncher.core.customviews.InsettableFrameLayout; import foundation.e.blisslauncher.core.customviews.InsettableRelativeLayout; import foundation.e.blisslauncher.core.customviews.InsettableScrollLayout; import foundation.e.blisslauncher.core.customviews.PageIndicatorLinearLayout; @@ -1284,7 +1285,7 @@ public class LauncherActivity extends AppCompatActivity implements } private void createWidgetsPage() { - widgetsPage = (FrameLayout) getLayoutInflater().inflate(R.layout.widgets_page, + widgetsPage = (InsettableFrameLayout) getLayoutInflater().inflate(R.layout.widgets_page, mHorizontalPager, false); widgetContainer = widgetsPage.findViewById(R.id.widget_container); /*widgetsPage.setPadding(0, diff --git a/app/src/main/res/layout/widgets_page.xml b/app/src/main/res/layout/widgets_page.xml index e235979643..cd4b3abb93 100755 --- a/app/src/main/res/layout/widgets_page.xml +++ b/app/src/main/res/layout/widgets_page.xml @@ -1,5 +1,5 @@ - - \ No newline at end of file + \ No newline at end of file -- GitLab