Java Code Examples for android.view.View#getFitsSystemWindows()

The following examples show how to use android.view.View#getFitsSystemWindows() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ImmersionBar.java    From a with GNU General Public License v3.0 6 votes vote down vote up
/**
 * 支持actionBar的界面
 * Support action bar.
 */
private void supportActionBar() {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && !OSUtils.isEMUI3_1()) {
        for (int i = 0, count = mContentView.getChildCount(); i < count; i++) {
            View childView = mContentView.getChildAt(i);
            if (childView instanceof ViewGroup) {
                mBarParams.systemWindows = childView.getFitsSystemWindows();
                if (mBarParams.systemWindows) {
                    mContentView.setPadding(0, 0, 0, 0);
                    return;
                }
            }
        }
        if (mBarParams.isSupportActionBar) {
            mContentView.setPadding(0, mConfig.getStatusBarHeight() + mConfig.getActionBarHeight(), 0, 0);
        } else {
            if (mBarParams.fits)
                mContentView.setPadding(0, mConfig.getStatusBarHeight(), 0, 0);
            else
                mContentView.setPadding(0, 0, 0, 0);
        }
    }
}
 
Example 2
Source File: WindowInsetsFrameLayout.java    From earth with GNU General Public License v3.0 6 votes vote down vote up
@TargetApi(21)
private boolean applySystemWindowInsets21(WindowInsetsCompat insets) {
    boolean consumed = false;

    for (int i = 0; i < getChildCount(); i++) {
        View child = getChildAt(i);

        if (!child.getFitsSystemWindows()) {
            continue;
        }

        Rect childInsets = new Rect(
                insets.getSystemWindowInsetLeft(),
                insets.getSystemWindowInsetTop(),
                insets.getSystemWindowInsetRight(),
                insets.getSystemWindowInsetBottom());

        computeInsetsWithGravity(child, childInsets);

        ViewCompat.dispatchApplyWindowInsets(child, insets.replaceSystemWindowInsets(childInsets));

        consumed = true;
    }

    return consumed;
}
 
Example 3
Source File: TutoShowcase.java    From TutoShowcase with Apache License 2.0 6 votes vote down vote up
private TutoShowcase(@NonNull Activity activity) {
    this.sharedPreferences = activity.getSharedPreferences(SHARED_TUTO, Context.MODE_PRIVATE);
    this.container = new FrameLayout(activity);
    this.tutoView = new TutoView(activity);
    Window window = activity.getWindow();
    if (window != null) {
        ViewGroup decorView = (ViewGroup) window.getDecorView();
        if (decorView != null) {
            ViewGroup content = decorView.findViewById(android.R.id.content);
            if (content != null) {
                content.addView(container, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
                this.container.addView(tutoView, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
                if (android.os.Build.VERSION.SDK_INT >= 16) {
                    View inflatedLayout = content.getChildAt(0);
                    this.fitsSystemWindows = inflatedLayout != null && inflatedLayout.getFitsSystemWindows();
                }
            }
        }
    }
    this.container.setVisibility(View.GONE);
    ViewCompat.setAlpha(container, 0f);
}
 
Example 4
Source File: ImmersionBar.java    From MNImageBrowser with GNU General Public License v3.0 6 votes vote down vote up
/**
 * 检查布局根节点是否使用了android:fitsSystemWindows="true"属性
 * Check fits system windows boolean.
 *
 * @param view the view
 * @return the boolean
 */
public static boolean checkFitsSystemWindows(View view) {
    if (view == null) {
        return false;
    }
    if (view.getFitsSystemWindows()) {
        return true;
    }
    if (view instanceof ViewGroup) {
        ViewGroup viewGroup = (ViewGroup) view;
        for (int i = 0, count = viewGroup.getChildCount(); i < count; i++) {
            View childView = viewGroup.getChildAt(i);
            if (childView instanceof DrawerLayout) {
                if (checkFitsSystemWindows(childView)) {
                    return true;
                }
            }
            if (childView.getFitsSystemWindows()) {
                return true;
            }
        }
    }
    return false;
}
 
Example 5
Source File: ImmersionBar.java    From ImmersionBar with Apache License 2.0 6 votes vote down vote up
/**
 * 检查布局根节点是否使用了android:fitsSystemWindows="true"属性
 * Check fits system windows boolean.
 *
 * @param view the view
 * @return the boolean
 */
public static boolean checkFitsSystemWindows(View view) {
    if (view == null) {
        return false;
    }
    if (view.getFitsSystemWindows()) {
        return true;
    }
    if (view instanceof ViewGroup) {
        ViewGroup viewGroup = (ViewGroup) view;
        for (int i = 0, count = viewGroup.getChildCount(); i < count; i++) {
            View childView = viewGroup.getChildAt(i);
            if (childView instanceof DrawerLayout) {
                if (checkFitsSystemWindows(childView)) {
                    return true;
                }
            }
            if (childView.getFitsSystemWindows()) {
                return true;
            }
        }
    }
    return false;
}
 
Example 6
Source File: ImmersionBar.java    From PocketEOS-Android with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * 支持actionBar的界面
 * Support action bar.
 */
private void supportActionBar() {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && !OSUtils.isEMUI3_1()) {
        for (int i = 0, count = mContentView.getChildCount(); i < count; i++) {
            View childView = mContentView.getChildAt(i);
            if (childView instanceof ViewGroup) {
                mBarParams.systemWindows = childView.getFitsSystemWindows();
                if (mBarParams.systemWindows) {
                    mContentView.setPadding(0, 0, 0, 0);
                    return;
                }
            }
        }
        if (mBarParams.isSupportActionBar) {
            mContentView.setPadding(0, mConfig.getStatusBarHeight() + mConfig.getActionBarHeight(), 0, 0);
        } else {
            if (mBarParams.fits)
                mContentView.setPadding(0, mConfig.getStatusBarHeight(), 0, 0);
            else
                mContentView.setPadding(0, 0, 0, 0);
        }
    }
}
 
Example 7
Source File: ImmersionBar.java    From MyBookshelf with GNU General Public License v3.0 6 votes vote down vote up
/**
 * 支持actionBar的界面
 * Support action bar.
 */
private void supportActionBar() {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && !OSUtils.isEMUI3_1()) {
        for (int i = 0, count = mContentView.getChildCount(); i < count; i++) {
            View childView = mContentView.getChildAt(i);
            if (childView instanceof ViewGroup) {
                mBarParams.systemWindows = childView.getFitsSystemWindows();
                if (mBarParams.systemWindows) {
                    mContentView.setPadding(0, 0, 0, 0);
                    return;
                }
            }
        }
        if (mBarParams.isSupportActionBar) {
            mContentView.setPadding(0, mConfig.getStatusBarHeight() + mConfig.getActionBarHeight(), 0, 0);
        } else {
            if (mBarParams.fits)
                mContentView.setPadding(0, mConfig.getStatusBarHeight(), 0, 0);
            else
                mContentView.setPadding(0, 0, 0, 0);
        }
    }
}
 
Example 8
Source File: ImmersionBar.java    From PocketEOS-Android with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * 解决安卓4.4和EMUI3.1导航栏与状态栏的问题,以及系统属性fitsSystemWindows的坑
 */
private void solveNavigation() {
    for (int i = 0, count = mContentView.getChildCount(); i < count; i++) {
        View childView = mContentView.getChildAt(i);
        if (childView instanceof ViewGroup) {
            if (childView instanceof DrawerLayout) {
                View childAt1 = ((DrawerLayout) childView).getChildAt(0);
                if (childAt1 != null) {
                    mBarParams.systemWindows = childAt1.getFitsSystemWindows();
                    if (mBarParams.systemWindows) {
                        mContentView.setPadding(0, 0, 0, 0);
                        return;
                    }
                }
            } else {
                mBarParams.systemWindows = childView.getFitsSystemWindows();
                if (mBarParams.systemWindows) {
                    mContentView.setPadding(0, 0, 0, 0);
                    return;
                }
            }
        }

    }
    // 解决android4.4有导航栏的情况下,activity底部被导航栏遮挡的问题
    if (mConfig.hasNavigtionBar() && !mBarParams.fullScreenTemp && !mBarParams.fullScreen) {
        if (mConfig.isNavigationAtBottom()) { //判断导航栏是否在底部
            if (!mBarParams.isSupportActionBar) { //判断是否支持actionBar
                if (mBarParams.navigationBarEnable && mBarParams.navigationBarWithKitkatEnable) {
                    if (mBarParams.fits)
                        mContentView.setPadding(0, mConfig.getStatusBarHeight(),
                                0, mConfig.getNavigationBarHeight()); //有导航栏,获得rootView的根节点,然后设置距离底部的padding值为导航栏的高度值
                    else
                        mContentView.setPadding(0, 0, 0, mConfig.getNavigationBarHeight());
                } else {
                    if (mBarParams.fits)
                        mContentView.setPadding(0, mConfig.getStatusBarHeight(), 0, 0);
                    else
                        mContentView.setPadding(0, 0, 0, 0);
                }
            } else {
                //支持有actionBar的界面
                if (mBarParams.navigationBarEnable && mBarParams.navigationBarWithKitkatEnable)
                    mContentView.setPadding(0, mConfig.getStatusBarHeight() +
                            mConfig.getActionBarHeight() + 10, 0, mConfig.getNavigationBarHeight());
                else
                    mContentView.setPadding(0, mConfig.getStatusBarHeight() +
                            mConfig.getActionBarHeight() + 10, 0, 0);
            }
        } else {
            if (!mBarParams.isSupportActionBar) {
                if (mBarParams.navigationBarEnable && mBarParams.navigationBarWithKitkatEnable) {
                    if (mBarParams.fits)
                        mContentView.setPadding(0, mConfig.getStatusBarHeight(),
                                mConfig.getNavigationBarWidth(), 0); //不在底部,设置距离右边的padding值为导航栏的宽度值
                    else
                        mContentView.setPadding(0, 0, mConfig.getNavigationBarWidth(), 0);
                } else {
                    if (mBarParams.fits)
                        mContentView.setPadding(0, mConfig.getStatusBarHeight(), 0, 0);
                    else
                        mContentView.setPadding(0, 0, 0, 0);
                }
            } else {
                //支持有actionBar的界面
                if (mBarParams.navigationBarEnable && mBarParams.navigationBarWithKitkatEnable)
                    mContentView.setPadding(0, mConfig.getStatusBarHeight() +
                            mConfig.getActionBarHeight() + 10, mConfig.getNavigationBarWidth(), 0);
                else
                    mContentView.setPadding(0, mConfig.getStatusBarHeight() +
                            mConfig.getActionBarHeight() + 10, 0, 0);
            }
        }
    } else {
        if (!mBarParams.isSupportActionBar) {
            if (mBarParams.fits)
                mContentView.setPadding(0, mConfig.getStatusBarHeight(), 0, 0);
            else
                mContentView.setPadding(0, 0, 0, 0);
        } else {
            //支持有actionBar的界面
            mContentView.setPadding(0, mConfig.getStatusBarHeight() + mConfig.getActionBarHeight() + 10, 0, 0);
        }
    }
}
 
Example 9
Source File: DrawerLayoutContainer.java    From TelePlus-Android with GNU General Public License v2.0 4 votes vote down vote up
@SuppressLint("NewApi")
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec)
{
    int widthSize = MeasureSpec.getSize(widthMeasureSpec);
    int heightSize = MeasureSpec.getSize(heightMeasureSpec);

    setMeasuredDimension(widthSize, heightSize);
    if (Build.VERSION.SDK_INT < 21)
    {
        inLayout = true;
        if (heightSize == AndroidUtilities.displaySize.y + AndroidUtilities.statusBarHeight)
        {
            if (getLayoutParams() instanceof ViewGroup.MarginLayoutParams)
            {
                setPadding(0, AndroidUtilities.statusBarHeight, 0, 0);
            }
            heightSize = AndroidUtilities.displaySize.y;
        }
        else
        {
            if (getLayoutParams() instanceof ViewGroup.MarginLayoutParams)
            {
                setPadding(0, 0, 0, 0);
            }
        }
        inLayout = false;
    }

    final boolean applyInsets = lastInsets != null && Build.VERSION.SDK_INT >= 21;

    final int childCount = getChildCount();
    for (int i = 0; i < childCount; i++)
    {
        final View child = getChildAt(i);

        if (child.getVisibility() == GONE)
        {
            continue;
        }

        final LayoutParams lp = (LayoutParams) child.getLayoutParams();

        if (applyInsets)
        {
            if (child.getFitsSystemWindows())
            {
                dispatchChildInsets(child, lastInsets, lp.gravity);
            }
            else if (child.getTag() == null)
            {
                applyMarginInsets(lp, lastInsets, lp.gravity, Build.VERSION.SDK_INT >= 21);
            }
        }

        if (drawerLayout != child)
        {
            final int contentWidthSpec = MeasureSpec.makeMeasureSpec(widthSize - lp.leftMargin - lp.rightMargin, MeasureSpec.EXACTLY);
            final int contentHeightSpec = MeasureSpec.makeMeasureSpec(heightSize - lp.topMargin - lp.bottomMargin, MeasureSpec.EXACTLY);
            child.measure(contentWidthSpec, contentHeightSpec);
        }
        else
        {
            child.setPadding(0, 0, 0, 0);
            final int drawerWidthSpec = getChildMeasureSpec(widthMeasureSpec, minDrawerMargin + lp.leftMargin + lp.rightMargin, lp.width);
            final int drawerHeightSpec = getChildMeasureSpec(heightMeasureSpec, lp.topMargin + lp.bottomMargin, lp.height);
            child.measure(drawerWidthSpec, drawerHeightSpec);
        }
    }
}
 
Example 10
Source File: ViewCompatJB.java    From letv with Apache License 2.0 4 votes vote down vote up
public static boolean getFitsSystemWindows(View view) {
    return view.getFitsSystemWindows();
}
 
Example 11
Source File: ImmersionBar.java    From MyBookshelf with GNU General Public License v3.0 4 votes vote down vote up
/**
 * 解决安卓4.4和EMUI3.1导航栏与状态栏的问题,以及系统属性fitsSystemWindows的坑
 */
private void solveNavigation() {
    for (int i = 0, count = mContentView.getChildCount(); i < count; i++) {
        View childView = mContentView.getChildAt(i);
        if (childView instanceof ViewGroup) {
            if (childView instanceof DrawerLayout) {
                View childAt1 = ((DrawerLayout) childView).getChildAt(0);
                if (childAt1 != null) {
                    mBarParams.systemWindows = childAt1.getFitsSystemWindows();
                    if (mBarParams.systemWindows) {
                        mContentView.setPadding(0, 0, 0, 0);
                        return;
                    }
                }
            } else {
                mBarParams.systemWindows = childView.getFitsSystemWindows();
                if (mBarParams.systemWindows) {
                    mContentView.setPadding(0, 0, 0, 0);
                    return;
                }
            }
        }

    }
    // 解决android4.4有导航栏的情况下,activity底部被导航栏遮挡的问题
    if (mConfig.hasNavigtionBar() && !mBarParams.fullScreenTemp && !mBarParams.fullScreen) {
        if (mConfig.isNavigationAtBottom()) { //判断导航栏是否在底部
            if (!mBarParams.isSupportActionBar) { //判断是否支持actionBar
                if (mBarParams.navigationBarEnable && mBarParams.navigationBarWithKitkatEnable) {
                    if (mBarParams.fits)
                        mContentView.setPadding(0, mConfig.getStatusBarHeight(),
                                0, mConfig.getNavigationBarHeight()); //有导航栏,获得rootView的根节点,然后设置距离底部的padding值为导航栏的高度值
                    else
                        mContentView.setPadding(0, 0, 0, mConfig.getNavigationBarHeight());
                } else {
                    if (mBarParams.fits)
                        mContentView.setPadding(0, mConfig.getStatusBarHeight(), 0, 0);
                    else
                        mContentView.setPadding(0, 0, 0, 0);
                }
            } else {
                //支持有actionBar的界面
                if (mBarParams.navigationBarEnable && mBarParams.navigationBarWithKitkatEnable)
                    mContentView.setPadding(0, mConfig.getStatusBarHeight() +
                            mConfig.getActionBarHeight() + 10, 0, mConfig.getNavigationBarHeight());
                else
                    mContentView.setPadding(0, mConfig.getStatusBarHeight() +
                            mConfig.getActionBarHeight() + 10, 0, 0);
            }
        } else {
            if (!mBarParams.isSupportActionBar) {
                if (mBarParams.navigationBarEnable && mBarParams.navigationBarWithKitkatEnable) {
                    if (mBarParams.fits)
                        mContentView.setPadding(0, mConfig.getStatusBarHeight(),
                                mConfig.getNavigationBarWidth(), 0); //不在底部,设置距离右边的padding值为导航栏的宽度值
                    else
                        mContentView.setPadding(0, 0, mConfig.getNavigationBarWidth(), 0);
                } else {
                    if (mBarParams.fits)
                        mContentView.setPadding(0, mConfig.getStatusBarHeight(), 0, 0);
                    else
                        mContentView.setPadding(0, 0, 0, 0);
                }
            } else {
                //支持有actionBar的界面
                if (mBarParams.navigationBarEnable && mBarParams.navigationBarWithKitkatEnable)
                    mContentView.setPadding(0, mConfig.getStatusBarHeight() +
                            mConfig.getActionBarHeight() + 10, mConfig.getNavigationBarWidth(), 0);
                else
                    mContentView.setPadding(0, mConfig.getStatusBarHeight() +
                            mConfig.getActionBarHeight() + 10, 0, 0);
            }
        }
    } else {
        if (!mBarParams.isSupportActionBar) {
            if (mBarParams.fits)
                mContentView.setPadding(0, mConfig.getStatusBarHeight(), 0, 0);
            else
                mContentView.setPadding(0, 0, 0, 0);
        } else {
            //支持有actionBar的界面
            mContentView.setPadding(0, mConfig.getStatusBarHeight() + mConfig.getActionBarHeight() + 10, 0, 0);
        }
    }
}
 
Example 12
Source File: DrawerLayoutContainer.java    From TelePlus-Android with GNU General Public License v2.0 4 votes vote down vote up
@SuppressLint("NewApi")
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec)
{
    int widthSize = MeasureSpec.getSize(widthMeasureSpec);
    int heightSize = MeasureSpec.getSize(heightMeasureSpec);

    setMeasuredDimension(widthSize, heightSize);
    if (Build.VERSION.SDK_INT < 21)
    {
        inLayout = true;
        if (heightSize == AndroidUtilities.displaySize.y + AndroidUtilities.statusBarHeight)
        {
            if (getLayoutParams() instanceof ViewGroup.MarginLayoutParams)
            {
                setPadding(0, AndroidUtilities.statusBarHeight, 0, 0);
            }
            heightSize = AndroidUtilities.displaySize.y;
        }
        else
        {
            if (getLayoutParams() instanceof ViewGroup.MarginLayoutParams)
            {
                setPadding(0, 0, 0, 0);
            }
        }
        inLayout = false;
    }

    final boolean applyInsets = lastInsets != null && Build.VERSION.SDK_INT >= 21;

    final int childCount = getChildCount();
    for (int i = 0; i < childCount; i++)
    {
        final View child = getChildAt(i);

        if (child.getVisibility() == GONE)
        {
            continue;
        }

        final LayoutParams lp = (LayoutParams) child.getLayoutParams();

        if (applyInsets)
        {
            if (child.getFitsSystemWindows())
            {
                dispatchChildInsets(child, lastInsets, lp.gravity);
            }
            else if (child.getTag() == null)
            {
                applyMarginInsets(lp, lastInsets, lp.gravity, Build.VERSION.SDK_INT >= 21);
            }
        }

        if (drawerLayout != child)
        {
            final int contentWidthSpec = MeasureSpec.makeMeasureSpec(widthSize - lp.leftMargin - lp.rightMargin, MeasureSpec.EXACTLY);
            final int contentHeightSpec = MeasureSpec.makeMeasureSpec(heightSize - lp.topMargin - lp.bottomMargin, MeasureSpec.EXACTLY);
            child.measure(contentWidthSpec, contentHeightSpec);
        }
        else
        {
            child.setPadding(0, 0, 0, 0);
            final int drawerWidthSpec = getChildMeasureSpec(widthMeasureSpec, minDrawerMargin + lp.leftMargin + lp.rightMargin, lp.width);
            final int drawerHeightSpec = getChildMeasureSpec(heightMeasureSpec, lp.topMargin + lp.bottomMargin, lp.height);
            child.measure(drawerWidthSpec, drawerHeightSpec);
        }
    }
}
 
Example 13
Source File: DrawerLayout.java    From Dashchan with Apache License 2.0 4 votes vote down vote up
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
	int widthMode = MeasureSpec.getMode(widthMeasureSpec);
	int heightMode = MeasureSpec.getMode(heightMeasureSpec);
	int widthSize = MeasureSpec.getSize(widthMeasureSpec);
	int heightSize = MeasureSpec.getSize(heightMeasureSpec);

	if (widthMode != MeasureSpec.EXACTLY || heightMode != MeasureSpec.EXACTLY) {
		if (isInEditMode()) {
			// Don't crash the layout editor. Consume all of the space if specified
			// or pick a magic number from thin air otherwise.
			// TODO Better communication with tools of this bogus state.
			// It will crash on a real device.
			if (widthMode == MeasureSpec.AT_MOST) {
				widthMode = MeasureSpec.EXACTLY;
			} else if (widthMode == MeasureSpec.UNSPECIFIED) {
				widthMode = MeasureSpec.EXACTLY;
				widthSize = 300;
			}
			if (heightMode == MeasureSpec.AT_MOST) {
				heightMode = MeasureSpec.EXACTLY;
			} else if (heightMode == MeasureSpec.UNSPECIFIED) {
				heightMode = MeasureSpec.EXACTLY;
				heightSize = 300;
			}
		} else {
			throw new IllegalArgumentException(
					"DrawerLayout must be measured with MeasureSpec.EXACTLY.");
		}
	}

	setMeasuredDimension(widthSize, heightSize);

	final boolean applyInsets = mLastInsets != null && getFitsSystemWindows();
	final int layoutDirection = getLayoutDirection(this);

	// Only one drawer is permitted along each vertical edge (left / right). These two booleans
	// are tracking the presence of the edge drawers.
	boolean hasDrawerOnLeftEdge = false;
	boolean hasDrawerOnRightEdge = false;
	final int childCount = getChildCount();
	for (int i = 0; i < childCount; i++) {
		final View child = getChildAt(i);

		if (child.getVisibility() == GONE) {
			continue;
		}

		final LayoutParams lp = (LayoutParams) child.getLayoutParams();

		if (applyInsets) {
			final int cgrav = Gravity.getAbsoluteGravity(lp.gravity, layoutDirection);
			if (child.getFitsSystemWindows()) {
				IMPL.dispatchChildInsets(child, mLastInsets, cgrav);
			} else {
				IMPL.applyMarginInsets(lp, mLastInsets, cgrav);
			}
		}

		if (isContentView(child)) {
			// Content views get measured at exactly the layout's size.
			final int contentWidthSpec = MeasureSpec.makeMeasureSpec(
					widthSize - lp.leftMargin - lp.rightMargin, MeasureSpec.EXACTLY);
			final int contentHeightSpec = MeasureSpec.makeMeasureSpec(
					heightSize - lp.topMargin - lp.bottomMargin, MeasureSpec.EXACTLY);
			child.measure(contentWidthSpec, contentHeightSpec);
		} else if (isDrawerView(child)) {
			final int childGravity = getDrawerViewAbsoluteGravity(child) & Gravity.HORIZONTAL_GRAVITY_MASK;
			// Note that the isDrawerView check guarantees that childGravity here is either
			// LEFT or RIGHT
			boolean isLeftEdgeDrawer = (childGravity == Gravity.LEFT);
			if ((isLeftEdgeDrawer && hasDrawerOnLeftEdge)
					|| (!isLeftEdgeDrawer && hasDrawerOnRightEdge)) {
				throw new IllegalStateException("Child drawer has absolute gravity "
						+ gravityToString(childGravity) + " but this " + TAG + " already has a "
						+ "drawer view along that edge");
			}
			if (isLeftEdgeDrawer) {
				hasDrawerOnLeftEdge = true;
			} else {
				hasDrawerOnRightEdge = true;
			}
			final int drawerWidthSpec = getChildMeasureSpec(widthMeasureSpec,
					mMinDrawerMargin + lp.leftMargin + lp.rightMargin,
					lp.width);
			final int drawerHeightSpec = getChildMeasureSpec(heightMeasureSpec,
					lp.topMargin + lp.bottomMargin,
					lp.height);
			child.measure(drawerWidthSpec, drawerHeightSpec);
		} else {
			throw new IllegalStateException("Child " + child + " at index " + i
					+ " does not have a valid layout_gravity - must be Gravity.LEFT, "
					+ "Gravity.RIGHT or Gravity.NO_GRAVITY");
		}
	}
}
 
Example 14
Source File: WindowInsetsFrameLayout.java    From earth with GNU General Public License v3.0 4 votes vote down vote up
@TargetApi(19)
private boolean applySystemWindowInsets19(Rect insets) {
    boolean consumed = false;

    for (int i = 0; i < getChildCount(); i++) {
        View child = getChildAt(i);

        if (!child.getFitsSystemWindows()) {
            continue;
        }

        Rect childInsets = new Rect(insets);

        computeInsetsWithGravity(child, childInsets);

        child.setPadding(childInsets.left, childInsets.top, childInsets.right, childInsets.bottom);

        consumed = true;
    }

    return consumed;
}
 
Example 15
Source File: ImmersionBar.java    From a with GNU General Public License v3.0 4 votes vote down vote up
/**
 * 解决安卓4.4和EMUI3.1导航栏与状态栏的问题,以及系统属性fitsSystemWindows的坑
 */
private void solveNavigation() {
    for (int i = 0, count = mContentView.getChildCount(); i < count; i++) {
        View childView = mContentView.getChildAt(i);
        if (childView instanceof ViewGroup) {
            if (childView instanceof DrawerLayout) {
                View childAt1 = ((DrawerLayout) childView).getChildAt(0);
                if (childAt1 != null) {
                    mBarParams.systemWindows = childAt1.getFitsSystemWindows();
                    if (mBarParams.systemWindows) {
                        mContentView.setPadding(0, 0, 0, 0);
                        return;
                    }
                }
            } else {
                mBarParams.systemWindows = childView.getFitsSystemWindows();
                if (mBarParams.systemWindows) {
                    mContentView.setPadding(0, 0, 0, 0);
                    return;
                }
            }
        }

    }
    // 解决android4.4有导航栏的情况下,activity底部被导航栏遮挡的问题
    if (mConfig.hasNavigtionBar() && !mBarParams.fullScreenTemp && !mBarParams.fullScreen) {
        if (mConfig.isNavigationAtBottom()) { //判断导航栏是否在底部
            if (!mBarParams.isSupportActionBar) { //判断是否支持actionBar
                if (mBarParams.navigationBarEnable && mBarParams.navigationBarWithKitkatEnable) {
                    if (mBarParams.fits)
                        mContentView.setPadding(0, mConfig.getStatusBarHeight(),
                                0, mConfig.getNavigationBarHeight()); //有导航栏,获得rootView的根节点,然后设置距离底部的padding值为导航栏的高度值
                    else
                        mContentView.setPadding(0, 0, 0, mConfig.getNavigationBarHeight());
                } else {
                    if (mBarParams.fits)
                        mContentView.setPadding(0, mConfig.getStatusBarHeight(), 0, 0);
                    else
                        mContentView.setPadding(0, 0, 0, 0);
                }
            } else {
                //支持有actionBar的界面
                if (mBarParams.navigationBarEnable && mBarParams.navigationBarWithKitkatEnable)
                    mContentView.setPadding(0, mConfig.getStatusBarHeight() +
                            mConfig.getActionBarHeight() + 10, 0, mConfig.getNavigationBarHeight());
                else
                    mContentView.setPadding(0, mConfig.getStatusBarHeight() +
                            mConfig.getActionBarHeight() + 10, 0, 0);
            }
        } else {
            if (!mBarParams.isSupportActionBar) {
                if (mBarParams.navigationBarEnable && mBarParams.navigationBarWithKitkatEnable) {
                    if (mBarParams.fits)
                        mContentView.setPadding(0, mConfig.getStatusBarHeight(),
                                mConfig.getNavigationBarWidth(), 0); //不在底部,设置距离右边的padding值为导航栏的宽度值
                    else
                        mContentView.setPadding(0, 0, mConfig.getNavigationBarWidth(), 0);
                } else {
                    if (mBarParams.fits)
                        mContentView.setPadding(0, mConfig.getStatusBarHeight(), 0, 0);
                    else
                        mContentView.setPadding(0, 0, 0, 0);
                }
            } else {
                //支持有actionBar的界面
                if (mBarParams.navigationBarEnable && mBarParams.navigationBarWithKitkatEnable)
                    mContentView.setPadding(0, mConfig.getStatusBarHeight() +
                            mConfig.getActionBarHeight() + 10, mConfig.getNavigationBarWidth(), 0);
                else
                    mContentView.setPadding(0, mConfig.getStatusBarHeight() +
                            mConfig.getActionBarHeight() + 10, 0, 0);
            }
        }
    } else {
        if (!mBarParams.isSupportActionBar) {
            if (mBarParams.fits)
                mContentView.setPadding(0, mConfig.getStatusBarHeight(), 0, 0);
            else
                mContentView.setPadding(0, 0, 0, 0);
        } else {
            //支持有actionBar的界面
            mContentView.setPadding(0, mConfig.getStatusBarHeight() + mConfig.getActionBarHeight() + 10, 0, 0);
        }
    }
}
 
Example 16
Source File: ViewCompatJB.java    From adt-leanback-support with Apache License 2.0 4 votes vote down vote up
public static boolean getFitsSystemWindows(View view) {
    return view.getFitsSystemWindows();
}
 
Example 17
Source File: DrawerLayoutContainer.java    From Telegram-FOSS with GNU General Public License v2.0 4 votes vote down vote up
@SuppressLint("NewApi")
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    int widthSize = MeasureSpec.getSize(widthMeasureSpec);
    int heightSize = MeasureSpec.getSize(heightMeasureSpec);

    setMeasuredDimension(widthSize, heightSize);
    if (Build.VERSION.SDK_INT < 21) {
        inLayout = true;
        if (heightSize == AndroidUtilities.displaySize.y + AndroidUtilities.statusBarHeight) {
            if (getLayoutParams() instanceof ViewGroup.MarginLayoutParams) {
                setPadding(0, AndroidUtilities.statusBarHeight, 0, 0);
            }
            heightSize = AndroidUtilities.displaySize.y;
        } else {
            if (getLayoutParams() instanceof ViewGroup.MarginLayoutParams) {
                setPadding(0, 0, 0, 0);
            }
        }
        inLayout = false;
    } else {
        int newSize = heightSize - AndroidUtilities.statusBarHeight;
        if (newSize > 0 && newSize < 4096) {
            AndroidUtilities.displaySize.y = newSize;
        }
    }

    final boolean applyInsets = lastInsets != null && Build.VERSION.SDK_INT >= 21;

    final int childCount = getChildCount();
    for (int i = 0; i < childCount; i++) {
        final View child = getChildAt(i);

        if (child.getVisibility() == GONE) {
            continue;
        }

        final LayoutParams lp = (LayoutParams) child.getLayoutParams();

        if (applyInsets) {
            if (child.getFitsSystemWindows()) {
                dispatchChildInsets(child, lastInsets, lp.gravity);
            } else if (child.getTag() == null) {
                applyMarginInsets(lp, lastInsets, lp.gravity, Build.VERSION.SDK_INT >= 21);
            }
        }

        if (drawerLayout != child) {
            final int contentWidthSpec = MeasureSpec.makeMeasureSpec(widthSize - lp.leftMargin - lp.rightMargin, MeasureSpec.EXACTLY);
            final int contentHeightSpec = MeasureSpec.makeMeasureSpec(heightSize - lp.topMargin - lp.bottomMargin, MeasureSpec.EXACTLY);
            child.measure(contentWidthSpec, contentHeightSpec);
        } else {
            child.setPadding(0, 0, 0, 0);
            final int drawerWidthSpec = getChildMeasureSpec(widthMeasureSpec, minDrawerMargin + lp.leftMargin + lp.rightMargin, lp.width);
            final int drawerHeightSpec = getChildMeasureSpec(heightMeasureSpec, lp.topMargin + lp.bottomMargin, lp.height);
            child.measure(drawerWidthSpec, drawerHeightSpec);
        }
    }
}
 
Example 18
Source File: DrawerLayoutContainer.java    From Telegram with GNU General Public License v2.0 4 votes vote down vote up
@SuppressLint("NewApi")
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    int widthSize = MeasureSpec.getSize(widthMeasureSpec);
    int heightSize = MeasureSpec.getSize(heightMeasureSpec);

    setMeasuredDimension(widthSize, heightSize);
    if (Build.VERSION.SDK_INT < 21) {
        inLayout = true;
        if (heightSize == AndroidUtilities.displaySize.y + AndroidUtilities.statusBarHeight) {
            if (getLayoutParams() instanceof ViewGroup.MarginLayoutParams) {
                setPadding(0, AndroidUtilities.statusBarHeight, 0, 0);
            }
            heightSize = AndroidUtilities.displaySize.y;
        } else {
            if (getLayoutParams() instanceof ViewGroup.MarginLayoutParams) {
                setPadding(0, 0, 0, 0);
            }
        }
        inLayout = false;
    } else {
        int newSize = heightSize - AndroidUtilities.statusBarHeight;
        if (newSize > 0 && newSize < 4096) {
            AndroidUtilities.displaySize.y = newSize;
        }
    }

    final boolean applyInsets = lastInsets != null && Build.VERSION.SDK_INT >= 21;

    final int childCount = getChildCount();
    for (int i = 0; i < childCount; i++) {
        final View child = getChildAt(i);

        if (child.getVisibility() == GONE) {
            continue;
        }

        final LayoutParams lp = (LayoutParams) child.getLayoutParams();

        if (applyInsets) {
            if (child.getFitsSystemWindows()) {
                dispatchChildInsets(child, lastInsets, lp.gravity);
            } else if (child.getTag() == null) {
                applyMarginInsets(lp, lastInsets, lp.gravity, Build.VERSION.SDK_INT >= 21);
            }
        }

        if (drawerLayout != child) {
            final int contentWidthSpec = MeasureSpec.makeMeasureSpec(widthSize - lp.leftMargin - lp.rightMargin, MeasureSpec.EXACTLY);
            final int contentHeightSpec = MeasureSpec.makeMeasureSpec(heightSize - lp.topMargin - lp.bottomMargin, MeasureSpec.EXACTLY);
            child.measure(contentWidthSpec, contentHeightSpec);
        } else {
            child.setPadding(0, 0, 0, 0);
            final int drawerWidthSpec = getChildMeasureSpec(widthMeasureSpec, minDrawerMargin + lp.leftMargin + lp.rightMargin, lp.width);
            final int drawerHeightSpec = getChildMeasureSpec(heightMeasureSpec, lp.topMargin + lp.bottomMargin, lp.height);
            child.measure(drawerWidthSpec, drawerHeightSpec);
        }
    }
}