Skip to content

Commit

Permalink
some methods added'
Browse files Browse the repository at this point in the history
  • Loading branch information
ppamorim committed May 14, 2015
1 parent ee76f97 commit 55fd0c1
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -63,4 +67,8 @@ public void setDraggerCallback(DraggerCallback draggerCallback) {
draggerPanel.setDraggerCallback(draggerCallback);
}

public void setSlideEnabled(boolean enabled) {
draggerPanel.setSlideEnabled(enabled);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
}
Expand All @@ -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)));
}

/**
Expand Down
38 changes: 3 additions & 35 deletions dragger/src/main/java/com/github/ppamorim/dragger/DraggerView.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,13 @@
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;
import android.support.v4.widget.ViewDragHelper;
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;

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
}
Expand Down

1 comment on commit 55fd0c1

@ppamorim
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a gambiarra jejejeje

Please sign in to comment.