Skip to content

Commit

Permalink
add ConstraintLayout for dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
cgspine committed Aug 6, 2019
1 parent 14f1a59 commit 14577d7
Show file tree
Hide file tree
Showing 4 changed files with 110 additions and 3 deletions.
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ allprojects {
targetSdkVersion = 28
compileSdkVersion = 28
supportVersion = "28.0.0"
constraintLayoutVersion = "1.1.3"

qmuiArchVersion = "0.6.0"
qmuiGroup = "com.qmuiteam"
Expand Down
3 changes: 2 additions & 1 deletion qmui/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ dependencies {
api "com.android.support:recyclerview-v7:$supportVersion"
api "com.android.support:appcompat-v7:$supportVersion"
api "com.android.support:design:$supportVersion"
api "com.android.support:support-vector-drawable:$supportVersion" // need Gradle Plugin v1.5.0 or above
api "com.android.support:support-vector-drawable:$supportVersion"
api "com.android.support.constraint:constraint-layout:$constraintLayoutVersion"
lintChecks project(':lintrule')
//test
testImplementation 'junit:junit:4.12'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import android.support.design.widget.CoordinatorLayout;
import android.support.v4.view.ViewCompat;
import android.support.v4.view.WindowInsetsCompat;
import android.support.v4.widget.DrawerLayout;
import android.view.DisplayCutout;
import android.view.Gravity;
import android.view.View;
Expand All @@ -38,6 +39,7 @@
import com.qmuiteam.qmui.widget.IWindowInsetLayout;

import java.lang.ref.WeakReference;
import java.util.ArrayList;

/**
* @author cginechen
Expand All @@ -46,6 +48,7 @@

public class QMUIWindowInsetHelper {
private static final Object KEYBOARD_CONSUMER = new Object();
private static ArrayList<Class<? extends ViewGroup>> sCustomHandlerContainerList = new ArrayList<>();
private final int KEYBOARD_HEIGHT_BOUNDARY;
private final WeakReference<IWindowInsetLayout> mWindowInsetLayoutWR;
private int sApplySystemWindowInsetsCount = 0;
Expand Down Expand Up @@ -254,8 +257,22 @@ public static boolean jumpDispatch(View child) {
}

public static boolean isHandleContainer(View child) {
return child instanceof IWindowInsetLayout ||
child instanceof CoordinatorLayout;
boolean ret = child instanceof IWindowInsetLayout ||
child instanceof CoordinatorLayout ||
child instanceof DrawerLayout;
if (ret) {
return true;
}
for (Class<? extends View> clz : sCustomHandlerContainerList) {
if (clz.isInstance(child)) {
return true;
}
}
return false;
}

public static void addHandleContainer(Class<? extends ViewGroup> clazz) {
sCustomHandlerContainerList.add(clazz);
}

@SuppressLint("RtlHardcoded")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
/*
* Tencent is pleased to support the open source community by making QMUI_Android available.
*
* Copyright (C) 2017-2018 THL A29 Limited, a Tencent company. All rights reserved.
*
* Licensed under the MIT License (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
*
* http://opensource.org/licenses/MIT
*
* 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.qmuiteam.qmui.widget;

import android.content.Context;
import android.content.res.Configuration;
import android.graphics.Rect;
import android.os.Build;
import android.support.constraint.ConstraintLayout;
import android.support.v4.view.ViewCompat;
import android.util.AttributeSet;

import com.qmuiteam.qmui.util.QMUIWindowInsetHelper;

/**
* From: https://github.com/oxoooo/earth/blob/30bd82fac7867be596bddf3bd0b32d8be3800665/app/src/main/java/ooo/oxo/apps/earth/widget/WindowInsetsFrameLayout.java
* 教程(英文): https://medium.com/google-developers/why-would-i-want-to-fitssystemwindows-4e26d9ce1eec#.6i7s7gyam
* 教程翻译: https://github.com/bboyfeiyu/android-tech-frontier/blob/master/issue-35/%E4%B8%BA%E4%BB%80%E4%B9%88%E6%88%91%E4%BB%AC%E8%A6%81%E7%94%A8fitsSystemWindows.md
* <p>
* 对于Keyboard的处理我们需要格外小心,这个组件不能只是处理状态栏,因为android还存在NavBar
* 当windowInsets.bottom > 100dp的时候,我们认为是弹起了键盘。一旦弹起键盘,那么将由QMUIWindowInsetLayout消耗掉,其子view的windowInsets.bottom传递为0
*
* @author cginechen
* @date 2016-03-25
*/
public class QMUIWindowInsetLayout2 extends ConstraintLayout implements IWindowInsetLayout {
protected QMUIWindowInsetHelper mQMUIWindowInsetHelper;

public QMUIWindowInsetLayout2(Context context) {
this(context, null);
}

public QMUIWindowInsetLayout2(Context context, AttributeSet attrs) {
this(context, attrs, 0);
}

public QMUIWindowInsetLayout2(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
mQMUIWindowInsetHelper = new QMUIWindowInsetHelper(this, this);
}


@SuppressWarnings("deprecation")
@Override
protected boolean fitSystemWindows(Rect insets) {
if (Build.VERSION.SDK_INT >= 19 && Build.VERSION.SDK_INT < 21) {
return applySystemWindowInsets19(insets);
}
return super.fitSystemWindows(insets);
}

@Override
public boolean applySystemWindowInsets19(Rect insets) {
return mQMUIWindowInsetHelper.defaultApplySystemWindowInsets19(this, insets);
}

@Override
public boolean applySystemWindowInsets21(Object insets) {
return mQMUIWindowInsetHelper.defaultApplySystemWindowInsets21(this, insets);
}

@Override
protected void onAttachedToWindow() {
super.onAttachedToWindow();
ViewCompat.requestApplyInsets(this);
}

@Override
protected void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
// xiaomi 8 not reapply insets default...
ViewCompat.requestApplyInsets(this);
}
}

0 comments on commit 14577d7

Please sign in to comment.