// Path: app/src/main/java/com/topnews/android/utils/SwipeLayoutManager.java
// public class SwipeLayoutManager {
// 
//     private static SwipeLayoutManager manager=null;
// 
//     private SwipeLayoutManager(){}
// 
//     public static SwipeLayoutManager getInstance(){
// 
//         if (manager==null){
//             synchronized (SwipeLayoutManager.class){
//                 if (manager==null){
//                     manager=new SwipeLayoutManager();
//                 }
//             }
//         }
// 
//         return manager;
//     }
// 
//     //用来记录当前打开的SwipeLayout
//     private SwipeLayout currentLayout;
// 
//     public void setSwipeLayout(SwipeLayout layout){
// 
//         this.currentLayout=layout;
//     }
// 
//     public SwipeLayout getSwipeLayout(){
// 
//         return currentLayout;
//     }
// 
//     public void clearSwipeLayout(){
// 
//         this.currentLayout=null;
//     }
// 
//     /**
//      * 关闭当前已经打开的swipeLayout
//      */
//     public void closeCurrentLayout(){
//         if (currentLayout!=null){
//             currentLayout.close();
//         }
//     }
// 
//     /**
//      * 判断当前是否能够滑动 如果没有打开的，则可以滑动
//      * 如果有打开的 则判断打开的swipeLayout和当前layout是否是同一个
//      * @param layout
//      * @return
//      */
//     public boolean isShouldSwipe(SwipeLayout layout){
// 
//         if(currentLayout==null){
//             return true;
//         }else{
//             return currentLayout==layout;
//         }
//     }
// }


import android.content.Context;
import android.support.v4.view.ViewCompat;
import android.support.v4.widget.ViewDragHelper;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View;
import android.widget.FrameLayout;
import com.topnews.android.utils.SwipeLayoutManager;
        super.onFinishInflate();

        contentView = getChildAt(0);
        deleteView = getChildAt(1);
    }

    //此方法在measure方法后调用
    @Override
    protected void onSizeChanged(int w, int h, int oldw, int oldh) {
        super.onSizeChanged(w, h, oldw, oldh);

        contentWidth = contentView.getMeasuredWidth();
        contentHeight = contentView.getMeasuredHeight();
        deleteWidth = deleteView.getMeasuredWidth();
        deleteHeight = deleteView.getMeasuredHeight();
    }

    @Override
    protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
        //super.onLayout(changed, left, top, right, bottom);
        contentView.layout(0,0,contentWidth,contentHeight);
        deleteView.layout(contentView.getRight(),0,contentView.getRight()+deleteWidth,deleteHeight);
    }

    @Override
    public boolean onInterceptTouchEvent(MotionEvent ev) {

        boolean result=dragHelper.shouldInterceptTouchEvent(ev);

        //如果当前有打开的，则需要直接拦截，交给onTouchEvent处理  打开的swipeLayout和当前layout不是同一个
// Path: app/src/main/java/com/topnews/android/utils/SwipeLayoutManager.java
// public class SwipeLayoutManager {
// 
//     private static SwipeLayoutManager manager=null;
// 
//     private SwipeLayoutManager(){}
// 
//     public static SwipeLayoutManager getInstance(){
// 
//         if (manager==null){
//             synchronized (SwipeLayoutManager.class){
//                 if (manager==null){
//                     manager=new SwipeLayoutManager();
//                 }
//             }
//         }
// 
//         return manager;
//     }
// 
//     //用来记录当前打开的SwipeLayout
//     private SwipeLayout currentLayout;
// 
//     public void setSwipeLayout(SwipeLayout layout){
// 
//         this.currentLayout=layout;
//     }
// 
//     public SwipeLayout getSwipeLayout(){
// 
//         return currentLayout;
//     }
// 
//     public void clearSwipeLayout(){
// 
//         this.currentLayout=null;
//     }
// 
//     /**
//      * 关闭当前已经打开的swipeLayout
//      */
//     public void closeCurrentLayout(){
//         if (currentLayout!=null){
//             currentLayout.close();
//         }
//     }
// 
//     /**
//      * 判断当前是否能够滑动 如果没有打开的，则可以滑动
//      * 如果有打开的 则判断打开的swipeLayout和当前layout是否是同一个
//      * @param layout
//      * @return
//      */
//     public boolean isShouldSwipe(SwipeLayout layout){
// 
//         if(currentLayout==null){
//             return true;
//         }else{
//             return currentLayout==layout;
//         }
//     }
// }


// Path: app/src/main/java/com/topnews/android/view/SwipeLayout.java
import android.content.Context;
import android.support.v4.view.ViewCompat;
import android.support.v4.widget.ViewDragHelper;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View;
import android.widget.FrameLayout;
import com.topnews.android.utils.SwipeLayoutManager;

        super.onFinishInflate();

        contentView = getChildAt(0);
        deleteView = getChildAt(1);
    }

    //此方法在measure方法后调用
    @Override
    protected void onSizeChanged(int w, int h, int oldw, int oldh) {
        super.onSizeChanged(w, h, oldw, oldh);

        contentWidth = contentView.getMeasuredWidth();
        contentHeight = contentView.getMeasuredHeight();
        deleteWidth = deleteView.getMeasuredWidth();
        deleteHeight = deleteView.getMeasuredHeight();
    }

    @Override
    protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
        //super.onLayout(changed, left, top, right, bottom);
        contentView.layout(0,0,contentWidth,contentHeight);
        deleteView.layout(contentView.getRight(),0,contentView.getRight()+deleteWidth,deleteHeight);
    }

    @Override
    public boolean onInterceptTouchEvent(MotionEvent ev) {

        boolean result=dragHelper.shouldInterceptTouchEvent(ev);

        //如果当前有打开的，则需要直接拦截，交给onTouchEvent处理  打开的swipeLayout和当前layout不是同一个
        if (!SwipeLayoutManager.getInstance().isShouldSwipe(this)){