11package com .daimajia .swipe ;
22
33import android .content .Context ;
4+ import android .content .res .TypedArray ;
45import android .graphics .Rect ;
56import android .support .v4 .view .ViewCompat ;
67import android .support .v4 .widget .ViewDragHelper ;
@@ -23,8 +24,8 @@ public class SwipeLayout extends FrameLayout {
2324 private ViewDragHelper mDragHelper ;
2425
2526 private int mDragDistance = 0 ;
26- private DragEdge mDragEdge = DragEdge . Right ;
27- private ShowMode mShowMode = ShowMode . PullOut ;
27+ private DragEdge mDragEdge ;
28+ private ShowMode mShowMode ;
2829
2930 private List <SwipeListener > mSwipeListeners = new ArrayList <SwipeListener >();
3031 private Map <View , ArrayList <OnRevealListener >> mRevealListeners = new HashMap <View , ArrayList <OnRevealListener >>();
@@ -53,6 +54,12 @@ public SwipeLayout(Context context, AttributeSet attrs) {
5354 public SwipeLayout (Context context , AttributeSet attrs , int defStyle ) {
5455 super (context , attrs , defStyle );
5556 mDragHelper = ViewDragHelper .create (this , mDragHelperCallback );
57+
58+ TypedArray a = context .obtainStyledAttributes (attrs , R .styleable .SwipeLayout );
59+ int ordinal = a .getInt (R .styleable .SwipeLayout_drag_edge , DragEdge .Right .ordinal ());
60+ mDragEdge = DragEdge .values ()[ordinal ];
61+ ordinal = a .getInt (R .styleable .SwipeLayout_show_mode , ShowMode .PullOut .ordinal ());
62+ mShowMode = ShowMode .values ()[ordinal ];
5663 }
5764
5865
@@ -594,7 +601,7 @@ void layoutLayDown(){
594601 @ Override
595602 protected void onMeasure (int widthMeasureSpec , int heightMeasureSpec ) {
596603 super .onMeasure (widthMeasureSpec , heightMeasureSpec );
597-
604+
598605 if (mDragEdge == DragEdge .Left || mDragEdge == DragEdge .Right )
599606 mDragDistance = getBottomView ().getMeasuredWidth ();
600607 else
0 commit comments