package com.angcyo.uiview.viewgroup;

import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Canvas;
import android.graphics.drawable.Drawable;
import android.support.v4.content.ContextCompat;
import android.support.v4.view.GestureDetectorCompat;
import android.util.AttributeSet;
import android.view.GestureDetector;
import android.view.MotionEvent;
import android.widget.RelativeLayout;

import com.angcyo.uiview.R;

/**
 * Copyright (C) 2016,深圳市红鸟网络科技股份有限公司 All rights reserved.
 * 项目名称：
 * 类的描述：
 * 创建人员：Robi
 * 创建时间：2017/05/05 16:29
 * 修改人员：Robi
 * 修改时间：2017/05/05 16:29
 * 修改备注：
 * Version: 1.0.0
 */
public class RRelativeLayout extends RelativeLayout {

    onInterceptTouchListener mOnInterceptTouchListener;
    private Drawable mBackgroundDrawable;
    private GestureDetectorCompat mGestureDetectorCompat;

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

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

    public RRelativeLayout(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.RRelativeLayout);
        mBackgroundDrawable = typedArray.getDrawable(R.styleable.RRelativeLayout_r_background);
        typedArray.recycle();
        initLayout();
    }

    private void initLayout() {
        setWillNotDraw(false);
        mGestureDetectorCompat = new GestureDetectorCompat(getContext(),
                new GestureDetector.SimpleOnGestureListener() {
                    @Override
                    public boolean onSingleTapUp(MotionEvent e) {
                        if (mOnInterceptTouchListener != null) {
                            return mOnInterceptTouchListener.onSingleTapUp(e);
                        }
                        return super.onSingleTapUp(e);
                    }
                });
    }

    @Override
    public void draw(Canvas canvas) {
        if (mBackgroundDrawable != null) {
            mBackgroundDrawable.setBounds(canvas.getClipBounds());
            mBackgroundDrawable.draw(canvas);
        }
        super.draw(canvas);
        if (!isEnabled()) {
            canvas.drawColor(ContextCompat.getColor(getContext(), R.color.default_base_tran_dark2));
        }
    }

    @Override
    public boolean onTouchEvent(MotionEvent event) {
        if (!isEnabled()) {
            return true;
        }
        return super.onTouchEvent(event);
    }

    public void setOnInterceptTouchListener(onInterceptTouchListener onInterceptTouchListener) {
        mOnInterceptTouchListener = onInterceptTouchListener;
    }

    @Override
    public boolean dispatchTouchEvent(MotionEvent ev) {
        mGestureDetectorCompat.onTouchEvent(ev);
        return super.dispatchTouchEvent(ev);
    }

    @Override
    public boolean onInterceptTouchEvent(MotionEvent ev) {
        if (!isEnabled()) {
            return true;
        }
        return super.onInterceptTouchEvent(ev);
    }

    public interface onInterceptTouchListener {
        boolean onSingleTapUp(MotionEvent e);
    }
}

@@ -172,16 +172,21 @@
 rawable.
+Color
 Drawable
@@ -188,16 +188,105 @@
 wable;%0D%0A
+import android.graphics.drawable.Drawable;%0D%0Aimport android.support.annotation.ColorInt;%0D%0A
 import a
@@ -3279,32 +3279,274 @@
 (ev);%0D%0A    %7D%0D%0A%0D%0A
+    public void setRBackgroundDrawable(@ColorInt int color) %7B%0D%0A        setRBackgroundDrawable(new ColorDrawable(color));%0D%0A    %7D%0D%0A%0D%0A    public void setRBackgroundDrawable(Drawable drawable) %7B%0D%0A        mBackgroundDrawable = drawable;%0D%0A    %7D%0D%0A%0D%0A
     public inter

add set method