Skip to content

Added function to manually reset offsets of bottomview #190

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,13 @@
buildscript {
repositories {
jcenter()
maven {
url "https://jitpack.io"
}
}
dependencies {
classpath 'com.android.tools.build:gradle:1.0.0'
classpath 'com.github.dcendents:android-maven-plugin:1.2'

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
Expand All @@ -15,5 +19,8 @@ buildscript {
allprojects {
repositories {
jcenter()
maven {
url "https://jitpack.io"
}
}
}
12 changes: 11 additions & 1 deletion library/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,14 @@ dependencies {
compile 'com.android.support:recyclerview-v7:21.0.0'
compile 'com.android.support:support-v4:22.1.1'
}
apply from: './gradle-mvn-push.gradle'
apply from: './gradle-mvn-push.gradle'

apply plugin: 'android-maven'
// build a jar with source files
task sourcesJar(type: Jar) {
from android.sourceSets.main.java.srcDirs
classifier = 'sources'
}
artifacts {
archives sourcesJar
}
23 changes: 19 additions & 4 deletions library/src/main/java/com/daimajia/swipe/SwipeLayout.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ public class SwipeLayout extends FrameLayout {
private boolean mSwipeEnabled = true;
private boolean[] mSwipesEnabled = new boolean[]{true, true, true, true};
private boolean mClickToClose = false;
private AttributeSet attrs;

public enum DragEdge {
Left,
Expand All @@ -81,15 +82,14 @@ public SwipeLayout(Context context, AttributeSet attrs) {

public SwipeLayout(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
this.attrs = attrs;
mDragHelper = ViewDragHelper.create(this, mDragHelperCallback);
mTouchSlop = ViewConfiguration.get(context).getScaledTouchSlop();

TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.SwipeLayout);
resetOffsets();
int dragEdgeChoices = a.getInt(R.styleable.SwipeLayout_drag_edge, DRAG_RIGHT);
mEdgeSwipesOffset[DragEdge.Left.ordinal()] = a.getDimension(R.styleable.SwipeLayout_leftEdgeSwipeOffset, 0);
mEdgeSwipesOffset[DragEdge.Right.ordinal()] = a.getDimension(R.styleable.SwipeLayout_rightEdgeSwipeOffset, 0);
mEdgeSwipesOffset[DragEdge.Top.ordinal()] = a.getDimension(R.styleable.SwipeLayout_topEdgeSwipeOffset, 0);
mEdgeSwipesOffset[DragEdge.Bottom.ordinal()] = a.getDimension(R.styleable.SwipeLayout_bottomEdgeSwipeOffset, 0);

setClickToClose(a.getBoolean(R.styleable.SwipeLayout_clickToClose, mClickToClose));

if ((dragEdgeChoices & DRAG_LEFT) == DRAG_LEFT) {
Expand All @@ -110,6 +110,21 @@ public SwipeLayout(Context context, AttributeSet attrs, int defStyle) {

}

/**
* Reset offsets of BottomView to prevent it scrolling across the screen when
* Certain versions of the close method are manually used.
* close(true, true) at the least.
*/
public void resetOffsets() {
TypedArray a = getContext() .obtainStyledAttributes(attrs, R.styleable.SwipeLayout);

mEdgeSwipesOffset[DragEdge.Left.ordinal()] = a.getDimension(R.styleable.SwipeLayout_leftEdgeSwipeOffset, 0);
mEdgeSwipesOffset[DragEdge.Right.ordinal()] = a.getDimension(R.styleable.SwipeLayout_rightEdgeSwipeOffset, 0);
mEdgeSwipesOffset[DragEdge.Top.ordinal()] = a.getDimension(R.styleable.SwipeLayout_topEdgeSwipeOffset, 0);
mEdgeSwipesOffset[DragEdge.Bottom.ordinal()] = a.getDimension(R.styleable.SwipeLayout_bottomEdgeSwipeOffset, 0);
a.recycle();
}

public interface SwipeListener {
void onStartOpen(SwipeLayout layout);

Expand Down