From 250e1256b9bb72c29e174f9dd73cff59893ac607 Mon Sep 17 00:00:00 2001 From: seven332 Date: Fri, 1 Apr 2016 19:18:00 +0800 Subject: [PATCH] Add insert helper for SlidingDrawerLayout --- .../SlidingDrawerLayout.java | 14 ++++++++ .../SlidingDrawerLayoutInsetsHelper.java | 23 +++++++++++++ .../SlidingDrawerLayoutInsetsHelperL.java | 32 +++++++++++++++++++ 3 files changed, 69 insertions(+) create mode 100644 app/src/main/java/com/hippo/widget/slidingdrawerlayout/SlidingDrawerLayoutInsetsHelper.java create mode 100644 app/src/main/java/com/hippo/widget/slidingdrawerlayout/SlidingDrawerLayoutInsetsHelperL.java diff --git a/app/src/main/java/com/hippo/widget/slidingdrawerlayout/SlidingDrawerLayout.java b/app/src/main/java/com/hippo/widget/slidingdrawerlayout/SlidingDrawerLayout.java index 6d7b82f09..2f700cdf4 100644 --- a/app/src/main/java/com/hippo/widget/slidingdrawerlayout/SlidingDrawerLayout.java +++ b/app/src/main/java/com/hippo/widget/slidingdrawerlayout/SlidingDrawerLayout.java @@ -99,6 +99,16 @@ public class SlidingDrawerLayout extends ViewGroup implements ValueAnimator.Anim Build.VERSION.SDK_INT >= 21; private static final int DRAWER_ELEVATION = 10; //dp + private static final SlidingDrawerLayoutInsetsHelper INSETS_HELPER; + + static { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { + INSETS_HELPER = new SlidingDrawerLayoutInsetsHelperL(); + } else { + INSETS_HELPER = null; + } + } + private float mDrawerElevation; private int mMinDrawerMargin; @@ -221,6 +231,10 @@ public class SlidingDrawerLayout extends ViewGroup implements ValueAnimator.Anim mNavigationBarPaint.setColor(Color.BLACK); setWillNotDraw(false); + + if (INSETS_HELPER != null) { + INSETS_HELPER.setupForWindowInsets(this); + } } public void setDrawerListener(DrawerListener listener) { diff --git a/app/src/main/java/com/hippo/widget/slidingdrawerlayout/SlidingDrawerLayoutInsetsHelper.java b/app/src/main/java/com/hippo/widget/slidingdrawerlayout/SlidingDrawerLayoutInsetsHelper.java new file mode 100644 index 000000000..ac9eb09f5 --- /dev/null +++ b/app/src/main/java/com/hippo/widget/slidingdrawerlayout/SlidingDrawerLayoutInsetsHelper.java @@ -0,0 +1,23 @@ +/* + * Copyright 2016 Hippo Seven + * + * 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. + */ + +package com.hippo.widget.slidingdrawerlayout; + +import android.view.View; + +public interface SlidingDrawerLayoutInsetsHelper { + void setupForWindowInsets(View view); +} diff --git a/app/src/main/java/com/hippo/widget/slidingdrawerlayout/SlidingDrawerLayoutInsetsHelperL.java b/app/src/main/java/com/hippo/widget/slidingdrawerlayout/SlidingDrawerLayoutInsetsHelperL.java new file mode 100644 index 000000000..29c81d815 --- /dev/null +++ b/app/src/main/java/com/hippo/widget/slidingdrawerlayout/SlidingDrawerLayoutInsetsHelperL.java @@ -0,0 +1,32 @@ +/* + * Copyright 2016 Hippo Seven + * + * 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. + */ + +package com.hippo.widget.slidingdrawerlayout; + +import android.support.v4.view.ViewCompat; +import android.view.View; + +public class SlidingDrawerLayoutInsetsHelperL implements SlidingDrawerLayoutInsetsHelper { + + @Override + public void setupForWindowInsets(View view) { + if (ViewCompat.getFitsSystemWindows(view)) { + // Now set the sys ui flags to enable us to lay out in the window insets + view.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE + | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN); + } + } +}