From 0afe3f80f427d0bd27bafc0f7561c270c6049f8b Mon Sep 17 00:00:00 2001 From: Arthur Ivanets Date: Sun, 5 Apr 2020 01:54:35 +0300 Subject: [PATCH] Add the Window Inset Change handling mechanism --- .../com/arthurivanets/demo/ui/MainActivity.kt | 13 +++++++ app/src/main/res/values/styles.xml | 1 + .../bottomsheets/BottomSheetContainer.java | 37 +++++++++++++++++++ common/constants.gradle | 6 +-- 4 files changed, 54 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/com/arthurivanets/demo/ui/MainActivity.kt b/app/src/main/java/com/arthurivanets/demo/ui/MainActivity.kt index 5399eee..c58ba6c 100644 --- a/app/src/main/java/com/arthurivanets/demo/ui/MainActivity.kt +++ b/app/src/main/java/com/arthurivanets/demo/ui/MainActivity.kt @@ -17,6 +17,7 @@ package com.arthurivanets.demo.ui import android.os.Bundle +import android.view.View import androidx.appcompat.app.AppCompatActivity import com.arthurivanets.bottomsheets.BottomSheet import com.arthurivanets.bottomsheets.ktx.actionPickerConfig @@ -47,6 +48,7 @@ class MainActivity : AppCompatActivity() { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) init() + enableFullScreenMode() } @@ -77,6 +79,17 @@ class MainActivity : AppCompatActivity() { } + private fun enableFullScreenMode() { + window.decorView.systemUiVisibility = ( + View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN + or + View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION + or + View.SYSTEM_UI_FLAG_LAYOUT_STABLE + ) + } + + private fun showCustomBottomSheet() { dismissBottomSheet() diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml index 26cfc0d..7ae83d2 100644 --- a/app/src/main/res/values/styles.xml +++ b/app/src/main/res/values/styles.xml @@ -5,6 +5,7 @@ @color/colorPrimary @color/colorPrimaryDark @color/colorAccent + true diff --git a/bottomsheets-core/src/main/java/com/arthurivanets/bottomsheets/BottomSheetContainer.java b/bottomsheets-core/src/main/java/com/arthurivanets/bottomsheets/BottomSheetContainer.java index 70a330d..d4be801 100644 --- a/bottomsheets-core/src/main/java/com/arthurivanets/bottomsheets/BottomSheetContainer.java +++ b/bottomsheets-core/src/main/java/com/arthurivanets/bottomsheets/BottomSheetContainer.java @@ -28,6 +28,7 @@ import android.view.MotionEvent; import android.view.View; import android.view.ViewGroup; +import android.view.WindowInsets; import android.view.animation.Interpolator; import android.widget.FrameLayout; @@ -101,6 +102,7 @@ private void init(Activity hostActivity) { initContainer(hostActivity); initResources(hostActivity); initBottomSheet(); + requestWindowInsetsWhenAttached(); } @@ -174,6 +176,41 @@ private void initBottomSheet() { } + @Override + public final WindowInsets onApplyWindowInsets(WindowInsets insets) { + mBottomSheetView.setPadding( + mBottomSheetView.getPaddingLeft(), + mBottomSheetView.getPaddingTop(), + mBottomSheetView.getPaddingRight(), + (int) (insets.getSystemWindowInsetBottom() + mConfig.getExtraPaddingBottom()) + ); + + return insets; + } + + + private void requestWindowInsetsWhenAttached() { + if(isAttachedToWindow()) { + requestApplyInsets(); + } else { + addOnAttachStateChangeListener(new OnAttachStateChangeListener() { + + @Override + public void onViewAttachedToWindow(View view) { + removeOnAttachStateChangeListener(this); + requestApplyInsets(); + } + + @Override + public void onViewDetachedFromWindow(View view) { + // do nothing + } + + }); + } + } + + @Override protected final LayoutParams generateDefaultLayoutParams() { final LayoutParams layoutParams = new LayoutParams( diff --git a/common/constants.gradle b/common/constants.gradle index eb73fd9..eb851a3 100644 --- a/common/constants.gradle +++ b/common/constants.gradle @@ -17,7 +17,7 @@ project.ext { compileSdk = 29 targetSdk = 29 - minSdk = 18 + minSdk = 21 supportLibraryVersion = "1.1.0" recyclerViewVersion = "1.1.0" @@ -32,8 +32,8 @@ project.ext { releaseRepoName = "maven" releaseUserOrg = "arthurlabs" releaseGroupId = "com.arthurivanets.bottomsheet" - releaseVersion = "1.1.4" - releaseVersionCode = 16 + releaseVersion = "1.2.0" + releaseVersionCode = 17 releaseWebsite = "https://github.com/arthur3486/bottomsheet" releaseLicense = ["Apache-2.0"]