From 55fd0c1c0a934ab014a77f5199f3a4db7279e73c Mon Sep 17 00:00:00 2001 From: ppamorim Date: Thu, 14 May 2015 14:54:44 -0300 Subject: [PATCH] some methods added' --- .../ppamorim/dragger/DraggerActivity.java | 8 ++++ .../github/ppamorim/dragger/DraggerPanel.java | 20 +++++----- .../github/ppamorim/dragger/DraggerView.java | 38 ++----------------- 3 files changed, 22 insertions(+), 44 deletions(-) diff --git a/dragger/src/main/java/com/github/ppamorim/dragger/DraggerActivity.java b/dragger/src/main/java/com/github/ppamorim/dragger/DraggerActivity.java index 8bf5790..eed9c38 100644 --- a/dragger/src/main/java/com/github/ppamorim/dragger/DraggerActivity.java +++ b/dragger/src/main/java/com/github/ppamorim/dragger/DraggerActivity.java @@ -30,6 +30,10 @@ public class DraggerActivity extends AppCompatActivity { super.setContentView(draggerPanel); } + public DraggerPanel getDraggerPanel() { + return draggerPanel; + } + public void setShadowView(int shadowResID) { this.shadowResID = shadowResID; } @@ -63,4 +67,8 @@ public void setDraggerCallback(DraggerCallback draggerCallback) { draggerPanel.setDraggerCallback(draggerCallback); } + public void setSlideEnabled(boolean enabled) { + draggerPanel.setSlideEnabled(enabled); + } + } diff --git a/dragger/src/main/java/com/github/ppamorim/dragger/DraggerPanel.java b/dragger/src/main/java/com/github/ppamorim/dragger/DraggerPanel.java index d5e4d7d..fa7f22e 100644 --- a/dragger/src/main/java/com/github/ppamorim/dragger/DraggerPanel.java +++ b/dragger/src/main/java/com/github/ppamorim/dragger/DraggerPanel.java @@ -26,11 +26,6 @@ public class DraggerPanel extends FrameLayout { private static final float DEFAULT_DRAG_LIMIT = 0.5f; private static final int DEFAULT_DRAG_POSITION = DraggerPosition.TOP.ordinal(); - private float dragLimit; - private DraggerPosition dragPosition; - - private TypedArray attributes; - private DraggerView draggerView; private FrameLayout dragView; private FrameLayout shadowView; @@ -49,6 +44,10 @@ public DraggerPanel(Context context, AttributeSet attrs, int defStyle) { initializeAttributes(attrs); } + public DraggerView getDraggerView() { + return draggerView; + } + public void setDraggerLimit(float draggerLimit) { draggerView.setDraggerLimit(draggerLimit); } @@ -61,12 +60,15 @@ public void setDraggerCallback(DraggerCallback draggerCallback) { draggerView.setDraggerCallback(draggerCallback); } + public void setSlideEnabled(boolean enabled) { + draggerView.setSlideEnabled(enabled); + } + private void initializeAttributes(AttributeSet attrs) { TypedArray attributes = getContext().obtainStyledAttributes(attrs, R.styleable.dragger_layout); - this.dragLimit = attributes.getFloat(R.styleable.dragger_layout_drag_limit, DEFAULT_DRAG_LIMIT); - this.dragPosition = DraggerPosition.getDragPosition( - attributes.getInt(R.styleable.dragger_layout_drag_position, DEFAULT_DRAG_POSITION)); - this.attributes = attributes; + setDraggerLimit(attributes.getFloat(R.styleable.dragger_layout_drag_limit, DEFAULT_DRAG_LIMIT)); + setDraggerPosition(DraggerPosition.getDragPosition( + attributes.getInt(R.styleable.dragger_layout_drag_position, DEFAULT_DRAG_POSITION))); } /** diff --git a/dragger/src/main/java/com/github/ppamorim/dragger/DraggerView.java b/dragger/src/main/java/com/github/ppamorim/dragger/DraggerView.java index 381e7b2..5f88203 100644 --- a/dragger/src/main/java/com/github/ppamorim/dragger/DraggerView.java +++ b/dragger/src/main/java/com/github/ppamorim/dragger/DraggerView.java @@ -18,7 +18,6 @@ import android.app.Activity; import android.content.Context; import android.content.res.TypedArray; -import android.os.Build; import android.os.Handler; import android.support.v4.view.MotionEventCompat; import android.support.v4.view.ViewCompat; @@ -26,7 +25,6 @@ import android.util.AttributeSet; import android.view.MotionEvent; import android.view.View; -import android.widget.AbsListView; import android.widget.FrameLayout; import com.nineoldandroids.view.ViewHelper; @@ -120,7 +118,7 @@ public DraggerView(Context context, AttributeSet attrs, int defStyle) { } @Override public boolean onInterceptTouchEvent(MotionEvent ev) { - if (!isEnabled() || isListOnTop()) { + if (!isEnabled() || canSlide()) { return false; } final int action = MotionEventCompat.getActionMasked(ev); @@ -176,44 +174,14 @@ private void setHorizontalDragRange(float horizontalDragRange) { this.horizontalDragRange = horizontalDragRange; } - public boolean isListOnTop() { + public boolean canSlide() { return canSlide; } - public void setCanSlide(boolean canSlide) { + public void setSlideEnabled(boolean canSlide) { this.canSlide = canSlide; } - public boolean canScrollUp(View view) { - if (Build.VERSION.SDK_INT < 14) { - if (view instanceof AbsListView) { - final AbsListView absListView = (AbsListView) view; - return absListView.getChildCount() > 0 - && (absListView.getFirstVisiblePosition() > 0 || absListView - .getChildAt(0).getTop() < absListView.getPaddingTop()); - } else { - return view.getScrollY() > 0; - } - } else { - return ViewCompat.canScrollVertically(view, -1); - } - } - - public boolean canScrollDown(View view) { - if (Build.VERSION.SDK_INT < 14) { - if (view instanceof AbsListView) { - final AbsListView absListView = (AbsListView) view; - return absListView.getChildCount() > 0 - && (absListView.getFirstVisiblePosition() > 0 || absListView - .getChildAt(0).getBottom() < absListView.getPaddingBottom()); - } else { - return view.getScrollY() > 0; - } - } else { - return ViewCompat.canScrollVertically(view, -1); - } - } - public float getDragLimit() { return dragLimit; }