package com.angcyo.uiview.widget;

import android.content.Context;
import android.os.Build;
import android.util.AttributeSet;
import android.view.View;
import android.widget.LinearLayout;

import com.angcyo.uiview.R;

/**
 * 用来控制状态栏的padding
 * Created by angcyo on 2016-11-05.
 */

public class TitleBarLayout extends LinearLayout {

    public TitleBarLayout(Context context) {
        super(context);
    }

    public TitleBarLayout(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public TitleBarLayout(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        super.onMeasure(widthMeasureSpec, heightMeasureSpec);

        if (getChildCount() == 0) {

        } else {
//        Context context = getContext();
//        if (context instanceof Activity) {
//            if (ResUtil.isLayoutFullscreen((Activity) context)) {
//                int statusBarHeight = getResources().getDimensionPixelSize(R.dimen.status_bar_height);
//                setClipToPadding(false);
//                setClipChildren(false);
//                setPadding(getPaddingLeft(),
//                        statusBarHeight,
//                        getPaddingRight(), getPaddingBottom());
//                height = statusBarHeight + getResources().getDimensionPixelSize(R.dimen.action_bar_height);
//            }
//        }
            int statusBarHeight;
            if (!isInEditMode() && Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                statusBarHeight = getResources().getDimensionPixelSize(R.dimen.status_bar_height);
                setPadding(getPaddingLeft(), statusBarHeight, getPaddingRight(), getPaddingBottom());
                View childAt = getChildAt(0);
                int height = getMeasuredHeight();
                if (childAt != null) {
                    height = childAt.getMeasuredHeight();
                }
                super.onMeasure(widthMeasureSpec,
                        MeasureSpec.makeMeasureSpec(height + statusBarHeight, MeasureSpec.EXACTLY));
            }

//            int width = MeasureSpec.getSize(widthMeasureSpec);
//            int height = MeasureSpec.getSize(heightMeasureSpec);
//            int heightMode = MeasureSpec.getMode(heightMeasureSpec);
//            View childAt = getChildAt(0);
//            childAt.measure(widthMeasureSpec, heightMeasureSpec);
//            if (heightMode == MeasureSpec.AT_MOST) {
//                setMeasuredDimension(widthMeasureSpec, childAt.getMeasuredHeight() + statusBarHeight);
//            } else {
//                setMeasuredDimension(widthMeasureSpec, height + statusBarHeight);
//            }
        }
    }

//    @Override
//    protected void onLayout(boolean changed, int l, int t, int r, int b) {
//        int statusBarHeight = 0;
//        if (!isInEditMode() && Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
//            statusBarHeight = getResources().getDimensionPixelSize(R.dimen.status_bar_height);
//        }
//
//        if (getChildCount() > 0) {
//            View childAt = getChildAt(0);
//            childAt.layout(l, t + statusBarHeight, r, t + statusBarHeight + childAt.getMeasuredHeight());
//        }
//    }
}

@@ -164,21 +164,51 @@
 oid.
-widget.Linear
+view.ViewGroup;%0Aimport android.widget.Frame
 Layo
@@ -345,14 +345,13 @@
 nds 
-Linear
+Frame
 Layo
@@ -543,131 +543,264 @@
     
-public TitleBarLayout(Context cont
+@Override%0A    public void addView(View child, int ind
 ex
-t
 , 
-AttributeSet attrs, int defStyleAttr) %7B%0A        super(cont
+ViewGroup.LayoutParams params) %7B%0A        super.addView(child, ind
 ex
-t
 , 
-attrs, defStyleAttr);
+params);%0A        if (getChildCount() %3E 1) %7B%0A            throw new IllegalArgumentException(%22Need Only One Child View.%22);%0A        %7D
 %0A   
@@ -969,224 +969,72 @@
    i
-f (getChildCount() == 0) %7B%0A%0A        %7D else %7B%0A//        Context context = getContext();%0A//        if (context instanceof Activity) %7B%0A//            if (ResUtil.isLayoutFullscreen((Activity) context)) %7B%0A//      
+nt heightMode = MeasureSpec.getMode(heightMeasureSpec);%0A
         
   in
@@ -1033,382 +1033,94 @@
     
-  
 int 
-statusBarHeight = getResources().getDimensionPixelSize(R.dimen.status_bar_height);%0A//                setClipToPadding(false);%0A//                setClipChildren(false);%0A//                setPadding(getPaddingLeft(),%0A//                        statusBarHeight,%0A//                        getPaddingRight(), getPaddingBottom());%0A//                height = statusBarHeight +
+heightSize = MeasureSpec.getSize(heightMeasureSpec);%0A        int statusBarHeight =
  get
@@ -1165,14 +1165,14 @@
 men.
-action
+status
 _bar
@@ -1185,73 +1185,9 @@
 t);%0A
-//            %7D%0A//        %7D%0A            int statusBarHeight;%0A    
+%0A
     
@@ -1270,115 +1270,35 @@
 IPOP
-) %7B%0A                statusBarHeight = getResources().getDimensionPixelSize(R.dimen.status_bar_height);%0A    
+ && getChildCount() %3E 0) %7B%0A
     
@@ -1395,36 +1395,32 @@
 ));%0A            
-    
 View childAt = g
@@ -1433,20 +1433,17 @@
 dAt(0);%0A
-    
+%0A
         
@@ -1451,229 +1451,97 @@
    i
-nt 
+f (
 height
- = getMeasuredHeight();%0A                if (childAt != null) %7B%0A                    height = childAt.getMeasuredHeight();%0A                %7D%0A                super.onMeasure(widthMeasureSpec,%0A                       
+Mode == MeasureSpec.EXACTLY) %7B%0A                childAt.measure(widthMeasureSpec,
  Mea
@@ -1571,34 +1571,20 @@
 c(height
- + statusBarHeight
+Size
 , Measur
@@ -1617,259 +1617,20 @@
    %7D
-%0A%0A//            int width = MeasureSpec.getSize(widthMeasureSpec);%0A//            int height = MeasureSpec.getSize(heightMeasureSpec);%0A//            int heightMode = MeasureSpec.getMode(heightMeasureSpec);%0A//            View childAt = getChildAt(0);%0A//
+ else %7B%0A    
     
@@ -1691,18 +1691,19 @@
 eSpec);%0A
-//
+   
         
@@ -1710,815 +1710,170 @@
     
-if (
+ 
 height
-Mode == MeasureSpec.AT_MOST) %7B%0A//                setMeasuredDimension(widthMeasureSpec, childAt.getMeasuredHeight() + statusBarHeight);%0A//            %7D else %7B%0A//                setMeasuredDimension(widthMeasureSpec, height + statusBarHeight);%0A//            %7D%0A        %7D%0A    %7D%0A%0A//    @Override%0A//    protected void onLayout(boolean changed, int l, int t, int r, int b) %7B%0A//        int statusBarHeight = 0;%0A//        if (!isInEditMode() && Build.VERSION.SDK_INT %3E= Build.VERSION_CODES.LOLLIPOP) %7B%0A//            statusBarHeight = getResources().getDimensionPixelSize(R.dimen.status_bar_height);%0A//        %7D%0A//%0A//        if (getChildCount() %3E 0) %7B%0A//            View childAt = getChildAt(0);%0A//            childAt.layout(l, t + statusBarHeight, r, t + statusBarHeight + childAt.getMeasuredHeight
+Size = childAt.getMeasuredHeight();%0A            %7D%0A            setMeasuredDimension(getMeasuredWidth(), heightSize + statusBarHeight + getPaddingBottom
 ());%0A
-//
     
@@ -1882,14 +1882,11 @@
   %7D%0A
-//
     %7D%0A%7D
-%0A

fix title bar layout