Compare commits

..

No commits in common. "feature/androidx" and "master" have entirely different histories.

11 changed files with 116 additions and 239 deletions

View File

@ -8,8 +8,8 @@ buildscript {
} }
} }
dependencies { dependencies {
// classpath 'com.android.tools.build:gradle:2.3.0' classpath 'com.android.tools.build:gradle:2.3.0'
// classpath 'com.github.dcendents:android-maven-plugin:1.2' classpath 'com.github.dcendents:android-maven-plugin:1.2'
// NOTE: Do not place your application dependencies here; they belong // NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files // in the individual module build.gradle files

View File

@ -5,8 +5,8 @@ import android.app.Activity;
import android.content.Intent; import android.content.Intent;
import android.os.Build; import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import androidx.recyclerview.widget.LinearLayoutManager; import android.support.v7.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView; import android.support.v7.widget.RecyclerView;
import android.util.Log; import android.util.Log;
import android.view.Menu; import android.view.Menu;
import android.view.MenuItem; import android.view.MenuItem;

View File

@ -1,7 +1,7 @@
package com.daimajia.swipedemo.adapter; package com.daimajia.swipedemo.adapter;
import android.content.Context; import android.content.Context;
import androidx.recyclerview.widget.RecyclerView; import android.support.v7.widget.RecyclerView;
import android.util.Log; import android.util.Log;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;

View File

@ -5,8 +5,8 @@ import android.content.res.TypedArray;
import android.graphics.Canvas; import android.graphics.Canvas;
import android.graphics.Rect; import android.graphics.Rect;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
import androidx.recyclerview.widget.LinearLayoutManager; import android.support.v7.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView; import android.support.v7.widget.RecyclerView;
import android.util.AttributeSet; import android.util.AttributeSet;
import android.view.View; import android.view.View;
@ -122,4 +122,4 @@ public class DividerItemDecoration extends RecyclerView.ItemDecoration {
"DividerItemDecoration can only be used with a LinearLayoutManager."); "DividerItemDecoration can only be used with a LinearLayoutManager.");
} }
} }
} }

View File

@ -1,7 +1,7 @@
package com.daimajia.swipedemo.adapter.util; package com.daimajia.swipedemo.adapter.util;
import android.content.Context; import android.content.Context;
import androidx.recyclerview.widget.RecyclerView; import android.support.v7.widget.RecyclerView;
import android.view.GestureDetector; import android.view.GestureDetector;
import android.view.MotionEvent; import android.view.MotionEvent;
import android.view.View; import android.view.View;

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<!-- A RecyclerView with some commonly used attributes --> <!-- A RecyclerView with some commonly used attributes -->
<androidx.recyclerview.widget.RecyclerView xmlns:android="http://schemas.android.com/apk/res/android" <android.support.v7.widget.RecyclerView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/recycler_view" android:id="@+id/recycler_view"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:scrollbars="vertical" /> android:scrollbars="vertical" />

View File

@ -2,6 +2,7 @@ apply plugin: 'com.android.library'
android { android {
compileSdkVersion Integer.parseInt(project.ANDROID_BUILD_SDK_VERSION) compileSdkVersion Integer.parseInt(project.ANDROID_BUILD_SDK_VERSION)
buildToolsVersion project.ANDROID_BUILD_TOOLS_VERSION
defaultConfig { defaultConfig {
minSdkVersion 9 minSdkVersion 9
@ -10,8 +11,8 @@ android {
} }
dependencies { dependencies {
compile "androidx.recyclerview:recyclerview:$androidx" compile 'com.android.support:recyclerview-v7:25.2.0'
compile 'androidx.legacy:legacy-support-v4:1.0.0' compile 'com.android.support:support-v4:25.2.0'
} }
apply from: './gradle-mvn-push.gradle' apply from: './gradle-mvn-push.gradle'

View File

@ -3,6 +3,9 @@ package com.daimajia.swipe;
import android.content.Context; import android.content.Context;
import android.content.res.TypedArray; import android.content.res.TypedArray;
import android.graphics.Rect; import android.graphics.Rect;
import android.support.v4.view.GravityCompat;
import android.support.v4.view.ViewCompat;
import android.support.v4.widget.ViewDragHelper;
import android.util.AttributeSet; import android.util.AttributeSet;
import android.view.GestureDetector; import android.view.GestureDetector;
import android.view.Gravity; import android.view.Gravity;
@ -24,10 +27,6 @@ import java.util.LinkedHashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import androidx.core.view.GravityCompat;
import androidx.core.view.ViewCompat;
import androidx.customview.widget.ViewDragHelper;
public class SwipeLayout extends FrameLayout { public class SwipeLayout extends FrameLayout {
@Deprecated @Deprecated
public static final int EMPTY_LAYOUT = -1; public static final int EMPTY_LAYOUT = -1;
@ -144,7 +143,7 @@ public class SwipeLayout extends FrameLayout {
* Called in onInterceptTouchEvent Determines if this swipe event should * Called in onInterceptTouchEvent Determines if this swipe event should
* be denied Implement this interface if you are using views with swipe * be denied Implement this interface if you are using views with swipe
* gestures As a child of SwipeLayout * gestures As a child of SwipeLayout
* *
* @return true deny false allow * @return true deny false allow
*/ */
boolean shouldDenySwipe(MotionEvent ev); boolean shouldDenySwipe(MotionEvent ev);
@ -183,9 +182,8 @@ public class SwipeLayout extends FrameLayout {
if (!mShowEntirely.containsKey(child)) { if (!mShowEntirely.containsKey(child)) {
mShowEntirely.put(child, false); mShowEntirely.put(child, false);
} }
if (mRevealListeners.get(child) == null) { if (mRevealListeners.get(child) == null)
mRevealListeners.put(child, new ArrayList<OnRevealListener>()); mRevealListeners.put(child, new ArrayList<OnRevealListener>());
}
mRevealListeners.get(child).add(l); mRevealListeners.get(child).add(l);
} }
@ -198,22 +196,17 @@ public class SwipeLayout extends FrameLayout {
* @param l the {@link com.daimajia.swipe.SwipeLayout.OnRevealListener} * @param l the {@link com.daimajia.swipe.SwipeLayout.OnRevealListener}
*/ */
public void addRevealListener(int[] childIds, OnRevealListener l) { public void addRevealListener(int[] childIds, OnRevealListener l) {
for (int i : childIds) { for (int i : childIds)
addRevealListener(i, l); addRevealListener(i, l);
}
} }
public void removeRevealListener(int childId, OnRevealListener l) { public void removeRevealListener(int childId, OnRevealListener l) {
View child = findViewById(childId); View child = findViewById(childId);
if (child == null) { if (child == null) return;
return;
}
mShowEntirely.remove(child); mShowEntirely.remove(child);
if (mRevealListeners.containsKey(child)) { if (mRevealListeners.containsKey(child)) mRevealListeners.get(child).remove(l);
mRevealListeners.get(child).remove(l);
}
} }
public void removeAllRevealListeners(int childId) { public void removeAllRevealListeners(int childId) {
@ -234,20 +227,14 @@ public class SwipeLayout extends FrameLayout {
case Bottom: case Bottom:
return getPaddingLeft(); return getPaddingLeft();
case Left: case Left:
if (left < getPaddingLeft()) { if (left < getPaddingLeft()) return getPaddingLeft();
return getPaddingLeft(); if (left > getPaddingLeft() + mDragDistance)
}
if (left > getPaddingLeft() + mDragDistance) {
return getPaddingLeft() + mDragDistance; return getPaddingLeft() + mDragDistance;
}
break; break;
case Right: case Right:
if (left > getPaddingLeft()) { if (left > getPaddingLeft()) return getPaddingLeft();
return getPaddingLeft(); if (left < getPaddingLeft() - mDragDistance)
}
if (left < getPaddingLeft() - mDragDistance) {
return getPaddingLeft() - mDragDistance; return getPaddingLeft() - mDragDistance;
}
break; break;
} }
} else if (getCurrentBottomView() == child) { } else if (getCurrentBottomView() == child) {
@ -258,9 +245,7 @@ public class SwipeLayout extends FrameLayout {
return getPaddingLeft(); return getPaddingLeft();
case Left: case Left:
if (mShowMode == ShowMode.PullOut) { if (mShowMode == ShowMode.PullOut) {
if (left > getPaddingLeft()) { if (left > getPaddingLeft()) return getPaddingLeft();
return getPaddingLeft();
}
} }
break; break;
case Right: case Right:
@ -283,12 +268,9 @@ public class SwipeLayout extends FrameLayout {
case Right: case Right:
return getPaddingTop(); return getPaddingTop();
case Top: case Top:
if (top < getPaddingTop()) { if (top < getPaddingTop()) return getPaddingTop();
return getPaddingTop(); if (top > getPaddingTop() + mDragDistance)
}
if (top > getPaddingTop() + mDragDistance) {
return getPaddingTop() + mDragDistance; return getPaddingTop() + mDragDistance;
}
break; break;
case Bottom: case Bottom:
if (top < getPaddingTop() - mDragDistance) { if (top < getPaddingTop() - mDragDistance) {
@ -307,30 +289,23 @@ public class SwipeLayout extends FrameLayout {
return getPaddingTop(); return getPaddingTop();
case Top: case Top:
if (mShowMode == ShowMode.PullOut) { if (mShowMode == ShowMode.PullOut) {
if (top > getPaddingTop()) { if (top > getPaddingTop()) return getPaddingTop();
return getPaddingTop();
}
} else { } else {
if (surfaceViewTop + dy < getPaddingTop()) { if (surfaceViewTop + dy < getPaddingTop())
return getPaddingTop(); return getPaddingTop();
} if (surfaceViewTop + dy > getPaddingTop() + mDragDistance)
if (surfaceViewTop + dy > getPaddingTop() + mDragDistance) {
return getPaddingTop() + mDragDistance; return getPaddingTop() + mDragDistance;
}
} }
break; break;
case Bottom: case Bottom:
if (mShowMode == ShowMode.PullOut) { if (mShowMode == ShowMode.PullOut) {
if (top < getMeasuredHeight() - mDragDistance) { if (top < getMeasuredHeight() - mDragDistance)
return getMeasuredHeight() - mDragDistance; return getMeasuredHeight() - mDragDistance;
}
} else { } else {
if (surfaceViewTop + dy >= getPaddingTop()) { if (surfaceViewTop + dy >= getPaddingTop())
return getPaddingTop(); return getPaddingTop();
} if (surfaceViewTop + dy <= getPaddingTop() - mDragDistance)
if (surfaceViewTop + dy <= getPaddingTop() - mDragDistance) {
return getPaddingTop() - mDragDistance; return getPaddingTop() - mDragDistance;
}
} }
} }
} }
@ -372,9 +347,7 @@ public class SwipeLayout extends FrameLayout {
@Override @Override
public void onViewPositionChanged(View changedView, int left, int top, int dx, int dy) { public void onViewPositionChanged(View changedView, int left, int top, int dx, int dy) {
View surfaceView = getSurfaceView(); View surfaceView = getSurfaceView();
if (surfaceView == null) { if (surfaceView == null) return;
return;
}
View currentBottomView = getCurrentBottomView(); View currentBottomView = getCurrentBottomView();
int evLeft = surfaceView.getLeft(), int evLeft = surfaceView.getLeft(),
evRight = surfaceView.getRight(), evRight = surfaceView.getRight(),
@ -403,15 +376,14 @@ public class SwipeLayout extends FrameLayout {
int newLeft = surfaceView.getLeft() + dx, newTop = surfaceView.getTop() + dy; int newLeft = surfaceView.getLeft() + dx, newTop = surfaceView.getTop() + dy;
if (mCurrentDragEdge == DragEdge.Left && newLeft < getPaddingLeft()) { if (mCurrentDragEdge == DragEdge.Left && newLeft < getPaddingLeft())
newLeft = getPaddingLeft(); newLeft = getPaddingLeft();
} else if (mCurrentDragEdge == DragEdge.Right && newLeft > getPaddingLeft()) { else if (mCurrentDragEdge == DragEdge.Right && newLeft > getPaddingLeft())
newLeft = getPaddingLeft(); newLeft = getPaddingLeft();
} else if (mCurrentDragEdge == DragEdge.Top && newTop < getPaddingTop()) { else if (mCurrentDragEdge == DragEdge.Top && newTop < getPaddingTop())
newTop = getPaddingTop(); newTop = getPaddingTop();
} else if (mCurrentDragEdge == DragEdge.Bottom && newTop > getPaddingTop()) { else if (mCurrentDragEdge == DragEdge.Bottom && newTop > getPaddingTop())
newTop = getPaddingTop(); newTop = getPaddingTop();
}
surfaceView.layout(newLeft, newTop, newLeft + getMeasuredWidth(), newTop + getMeasuredHeight()); surfaceView.layout(newLeft, newTop, newLeft + getMeasuredWidth(), newTop + getMeasuredHeight());
} }
@ -458,9 +430,7 @@ public class SwipeLayout extends FrameLayout {
*/ */
protected boolean isViewTotallyFirstShowed(View child, Rect relativePosition, DragEdge edge, int surfaceLeft, protected boolean isViewTotallyFirstShowed(View child, Rect relativePosition, DragEdge edge, int surfaceLeft,
int surfaceTop, int surfaceRight, int surfaceBottom) { int surfaceTop, int surfaceRight, int surfaceBottom) {
if (mShowEntirely.get(child)) { if (mShowEntirely.get(child)) return false;
return false;
}
int childLeft = relativePosition.left; int childLeft = relativePosition.left;
int childRight = relativePosition.right; int childRight = relativePosition.right;
int childTop = relativePosition.top; int childTop = relativePosition.top;
@ -470,16 +440,12 @@ public class SwipeLayout extends FrameLayout {
if ((edge == DragEdge.Right && surfaceRight <= childLeft) if ((edge == DragEdge.Right && surfaceRight <= childLeft)
|| (edge == DragEdge.Left && surfaceLeft >= childRight) || (edge == DragEdge.Left && surfaceLeft >= childRight)
|| (edge == DragEdge.Top && surfaceTop >= childBottom) || (edge == DragEdge.Top && surfaceTop >= childBottom)
|| (edge == DragEdge.Bottom && surfaceBottom <= childTop)) { || (edge == DragEdge.Bottom && surfaceBottom <= childTop)) r = true;
r = true;
}
} else if (getShowMode() == ShowMode.PullOut) { } else if (getShowMode() == ShowMode.PullOut) {
if ((edge == DragEdge.Right && childRight <= getWidth()) if ((edge == DragEdge.Right && childRight <= getWidth())
|| (edge == DragEdge.Left && childLeft >= getPaddingLeft()) || (edge == DragEdge.Left && childLeft >= getPaddingLeft())
|| (edge == DragEdge.Top && childTop >= getPaddingTop()) || (edge == DragEdge.Top && childTop >= getPaddingTop())
|| (edge == DragEdge.Bottom && childBottom <= getHeight())) { || (edge == DragEdge.Bottom && childBottom <= getHeight())) r = true;
r = true;
}
} }
return r; return r;
} }
@ -516,24 +482,16 @@ public class SwipeLayout extends FrameLayout {
} else if (getShowMode() == ShowMode.PullOut) { } else if (getShowMode() == ShowMode.PullOut) {
switch (availableEdge) { switch (availableEdge) {
case Right: case Right:
if (childLeft <= getWidth() && childRight > getWidth()) { if (childLeft <= getWidth() && childRight > getWidth()) return true;
return true;
}
break; break;
case Left: case Left:
if (childRight >= getPaddingLeft() && childLeft < getPaddingLeft()) { if (childRight >= getPaddingLeft() && childLeft < getPaddingLeft()) return true;
return true;
}
break; break;
case Top: case Top:
if (childTop < getPaddingTop() && childBottom >= getPaddingTop()) { if (childTop < getPaddingTop() && childBottom >= getPaddingTop()) return true;
return true;
}
break; break;
case Bottom: case Bottom:
if (childTop < getHeight() && childTop >= getPaddingTop()) { if (childTop < getHeight() && childTop >= getPaddingTop()) return true;
return true;
}
break; break;
} }
} }
@ -545,9 +503,7 @@ public class SwipeLayout extends FrameLayout {
Rect r = new Rect(t.getLeft(), t.getTop(), 0, 0); Rect r = new Rect(t.getLeft(), t.getTop(), 0, 0);
while (t.getParent() != null && t != getRootView()) { while (t.getParent() != null && t != getRootView()) {
t = (View) t.getParent(); t = (View) t.getParent();
if (t == this) { if (t == this) break;
break;
}
r.left += t.getLeft(); r.left += t.getLeft();
r.top += t.getTop(); r.top += t.getTop();
} }
@ -562,21 +518,13 @@ public class SwipeLayout extends FrameLayout {
DragEdge edge = getDragEdge(); DragEdge edge = getDragEdge();
boolean open = true; boolean open = true;
if (edge == DragEdge.Left) { if (edge == DragEdge.Left) {
if (dx < 0) { if (dx < 0) open = false;
open = false;
}
} else if (edge == DragEdge.Right) { } else if (edge == DragEdge.Right) {
if (dx > 0) { if (dx > 0) open = false;
open = false;
}
} else if (edge == DragEdge.Top) { } else if (edge == DragEdge.Top) {
if (dy < 0) { if (dy < 0) open = false;
open = false;
}
} else if (edge == DragEdge.Bottom) { } else if (edge == DragEdge.Bottom) {
if (dy > 0) { if (dy > 0) open = false;
open = false;
}
} }
dispatchSwipeEvent(surfaceLeft, surfaceTop, open); dispatchSwipeEvent(surfaceLeft, surfaceTop, open);
@ -642,9 +590,7 @@ public class SwipeLayout extends FrameLayout {
protected void dispatchRevealEvent(final int surfaceLeft, final int surfaceTop, final int surfaceRight, protected void dispatchRevealEvent(final int surfaceLeft, final int surfaceTop, final int surfaceRight,
final int surfaceBottom) { final int surfaceBottom) {
if (mRevealListeners.isEmpty()) { if (mRevealListeners.isEmpty()) return;
return;
}
for (Map.Entry<View, ArrayList<OnRevealListener>> entry : mRevealListeners.entrySet()) { for (Map.Entry<View, ArrayList<OnRevealListener>> entry : mRevealListeners.entrySet()) {
View child = entry.getKey(); View child = entry.getKey();
Rect rect = getRelativePosition(child); Rect rect = getRelativePosition(child);
@ -706,11 +652,10 @@ public class SwipeLayout extends FrameLayout {
mShowEntirely.put(child, true); mShowEntirely.put(child, true);
for (OnRevealListener l : entry.getValue()) { for (OnRevealListener l : entry.getValue()) {
if (mCurrentDragEdge == DragEdge.Left if (mCurrentDragEdge == DragEdge.Left
|| mCurrentDragEdge == DragEdge.Right) { || mCurrentDragEdge == DragEdge.Right)
l.onReveal(child, mCurrentDragEdge, 1, child.getWidth()); l.onReveal(child, mCurrentDragEdge, 1, child.getWidth());
} else { else
l.onReveal(child, mCurrentDragEdge, 1, child.getHeight()); l.onReveal(child, mCurrentDragEdge, 1, child.getHeight());
}
} }
} }
@ -736,16 +681,12 @@ public class SwipeLayout extends FrameLayout {
private List<OnLayout> mOnLayoutListeners; private List<OnLayout> mOnLayoutListeners;
public void addOnLayoutListener(OnLayout l) { public void addOnLayoutListener(OnLayout l) {
if (mOnLayoutListeners == null) { if (mOnLayoutListeners == null) mOnLayoutListeners = new ArrayList<OnLayout>();
mOnLayoutListeners = new ArrayList<OnLayout>();
}
mOnLayoutListeners.add(l); mOnLayoutListeners.add(l);
} }
public void removeOnLayoutListener(OnLayout l) { public void removeOnLayoutListener(OnLayout l) {
if (mOnLayoutListeners != null) { if (mOnLayoutListeners != null) mOnLayoutListeners.remove(l);
mOnLayoutListeners.remove(l);
}
} }
public void clearDragEdge() { public void clearDragEdge() {
@ -771,9 +712,7 @@ public class SwipeLayout extends FrameLayout {
} }
public void addDrag(DragEdge dragEdge, View child, ViewGroup.LayoutParams params) { public void addDrag(DragEdge dragEdge, View child, ViewGroup.LayoutParams params) {
if (child == null) { if (child == null) return;
return;
}
if (params == null) { if (params == null) {
params = generateDefaultLayoutParams(); params = generateDefaultLayoutParams();
@ -804,9 +743,7 @@ public class SwipeLayout extends FrameLayout {
@Override @Override
public void addView(View child, int index, ViewGroup.LayoutParams params) { public void addView(View child, int index, ViewGroup.LayoutParams params) {
if (child == null) { if (child == null) return;
return;
}
int gravity = Gravity.NO_GRAVITY; int gravity = Gravity.NO_GRAVITY;
try { try {
gravity = (Integer) params.getClass().getField("gravity").get(params); gravity = (Integer) params.getClass().getField("gravity").get(params);
@ -848,28 +785,23 @@ public class SwipeLayout extends FrameLayout {
protected void onLayout(boolean changed, int l, int t, int r, int b) { protected void onLayout(boolean changed, int l, int t, int r, int b) {
updateBottomViews(); updateBottomViews();
if (mOnLayoutListeners != null) { if (mOnLayoutListeners != null) for (int i = 0; i < mOnLayoutListeners.size(); i++) {
for (int i = 0; i < mOnLayoutListeners.size(); i++) { mOnLayoutListeners.get(i).onLayout(this);
mOnLayoutListeners.get(i).onLayout(this);
}
} }
} }
void layoutPullOut() { void layoutPullOut() {
View surfaceView = getSurfaceView(); View surfaceView = getSurfaceView();
Rect surfaceRect = mViewBoundCache.get(surfaceView); Rect surfaceRect = mViewBoundCache.get(surfaceView);
if (surfaceRect == null) { if (surfaceRect == null) surfaceRect = computeSurfaceLayoutArea(false);
surfaceRect = computeSurfaceLayoutArea(false);
}
if (surfaceView != null) { if (surfaceView != null) {
surfaceView.layout(surfaceRect.left, surfaceRect.top, surfaceRect.right, surfaceRect.bottom); surfaceView.layout(surfaceRect.left, surfaceRect.top, surfaceRect.right, surfaceRect.bottom);
bringChildToFront(surfaceView); bringChildToFront(surfaceView);
} }
View currentBottomView = getCurrentBottomView(); View currentBottomView = getCurrentBottomView();
Rect bottomViewRect = mViewBoundCache.get(currentBottomView); Rect bottomViewRect = mViewBoundCache.get(currentBottomView);
if (bottomViewRect == null) { if (bottomViewRect == null)
bottomViewRect = computeBottomLayoutAreaViaSurface(ShowMode.PullOut, surfaceRect); bottomViewRect = computeBottomLayoutAreaViaSurface(ShowMode.PullOut, surfaceRect);
}
if (currentBottomView != null) { if (currentBottomView != null) {
currentBottomView.layout(bottomViewRect.left, bottomViewRect.top, bottomViewRect.right, bottomViewRect.bottom); currentBottomView.layout(bottomViewRect.left, bottomViewRect.top, bottomViewRect.right, bottomViewRect.bottom);
} }
@ -878,18 +810,15 @@ public class SwipeLayout extends FrameLayout {
void layoutLayDown() { void layoutLayDown() {
View surfaceView = getSurfaceView(); View surfaceView = getSurfaceView();
Rect surfaceRect = mViewBoundCache.get(surfaceView); Rect surfaceRect = mViewBoundCache.get(surfaceView);
if (surfaceRect == null) { if (surfaceRect == null) surfaceRect = computeSurfaceLayoutArea(false);
surfaceRect = computeSurfaceLayoutArea(false);
}
if (surfaceView != null) { if (surfaceView != null) {
surfaceView.layout(surfaceRect.left, surfaceRect.top, surfaceRect.right, surfaceRect.bottom); surfaceView.layout(surfaceRect.left, surfaceRect.top, surfaceRect.right, surfaceRect.bottom);
bringChildToFront(surfaceView); bringChildToFront(surfaceView);
} }
View currentBottomView = getCurrentBottomView(); View currentBottomView = getCurrentBottomView();
Rect bottomViewRect = mViewBoundCache.get(currentBottomView); Rect bottomViewRect = mViewBoundCache.get(currentBottomView);
if (bottomViewRect == null) { if (bottomViewRect == null)
bottomViewRect = computeBottomLayoutAreaViaSurface(ShowMode.LayDown, surfaceRect); bottomViewRect = computeBottomLayoutAreaViaSurface(ShowMode.LayDown, surfaceRect);
}
if (currentBottomView != null) { if (currentBottomView != null) {
currentBottomView.layout(bottomViewRect.left, bottomViewRect.top, bottomViewRect.right, bottomViewRect.bottom); currentBottomView.layout(bottomViewRect.left, bottomViewRect.top, bottomViewRect.right, bottomViewRect.bottom);
} }
@ -898,9 +827,7 @@ public class SwipeLayout extends FrameLayout {
private boolean mIsBeingDragged; private boolean mIsBeingDragged;
private void checkCanDrag(MotionEvent ev) { private void checkCanDrag(MotionEvent ev) {
if (mIsBeingDragged) { if (mIsBeingDragged) return;
return;
}
if (getOpenStatus() == Status.Middle) { if (getOpenStatus() == Status.Middle) {
mIsBeingDragged = true; mIsBeingDragged = true;
return; return;
@ -917,18 +844,14 @@ public class SwipeLayout extends FrameLayout {
dragEdge = DragEdge.Left; dragEdge = DragEdge.Left;
} else if (distanceX < 0 && isRightSwipeEnabled()) { } else if (distanceX < 0 && isRightSwipeEnabled()) {
dragEdge = DragEdge.Right; dragEdge = DragEdge.Right;
} else { } else return;
return;
}
} else { } else {
if (distanceY > 0 && isTopSwipeEnabled()) { if (distanceY > 0 && isTopSwipeEnabled()) {
dragEdge = DragEdge.Top; dragEdge = DragEdge.Top;
} else if (distanceY < 0 && isBottomSwipeEnabled()) { } else if (distanceY < 0 && isBottomSwipeEnabled()) {
dragEdge = DragEdge.Bottom; dragEdge = DragEdge.Bottom;
} else { } else return;
return;
}
} }
setCurrentDragEdge(dragEdge); setCurrentDragEdge(dragEdge);
} }
@ -1032,9 +955,7 @@ public class SwipeLayout extends FrameLayout {
@Override @Override
public boolean onTouchEvent(MotionEvent event) { public boolean onTouchEvent(MotionEvent event) {
if (!isSwipeEnabled()) { if (!isSwipeEnabled()) return super.onTouchEvent(event);
return super.onTouchEvent(event);
}
int action = event.getActionMasked(); int action = event.getActionMasked();
gestureDetector.onTouchEvent(event); gestureDetector.onTouchEvent(event);
@ -1177,9 +1098,7 @@ public class SwipeLayout extends FrameLayout {
} }
private void performAdapterViewItemClick() { private void performAdapterViewItemClick() {
if (getOpenStatus() != Status.Close) { if (getOpenStatus() != Status.Close) return;
return;
}
ViewParent t = getParent(); ViewParent t = getParent();
if (t instanceof AdapterView) { if (t instanceof AdapterView) {
AdapterView view = (AdapterView) t; AdapterView view = (AdapterView) t;
@ -1192,16 +1111,12 @@ public class SwipeLayout extends FrameLayout {
} }
private boolean performAdapterViewItemLongClick() { private boolean performAdapterViewItemLongClick() {
if (getOpenStatus() != Status.Close) { if (getOpenStatus() != Status.Close) return false;
return false;
}
ViewParent t = getParent(); ViewParent t = getParent();
if (t instanceof AdapterView) { if (t instanceof AdapterView) {
AdapterView view = (AdapterView) t; AdapterView view = (AdapterView) t;
int p = view.getPositionForView(SwipeLayout.this); int p = view.getPositionForView(SwipeLayout.this);
if (p == AdapterView.INVALID_POSITION) { if (p == AdapterView.INVALID_POSITION) return false;
return false;
}
long vId = view.getItemIdAtPosition(p); long vId = view.getItemIdAtPosition(p);
boolean handled = false; boolean handled = false;
try { try {
@ -1314,9 +1229,7 @@ public class SwipeLayout extends FrameLayout {
* @param max max distance in dp unit * @param max max distance in dp unit
*/ */
public void setDragDistance(int max) { public void setDragDistance(int max) {
if (max < 0) { if (max < 0) max = 0;
max = 0;
}
mDragDistance = dp2px(max); mDragDistance = dp2px(max);
requestLayout(); requestLayout();
} }
@ -1349,9 +1262,7 @@ public class SwipeLayout extends FrameLayout {
* return null if there is no surface view(no children) * return null if there is no surface view(no children)
*/ */
public View getSurfaceView() { public View getSurfaceView() {
if (getChildCount() == 0) { if (getChildCount() == 0) return null;
return null;
}
return getChildAt(getChildCount() - 1); return getChildAt(getChildCount() - 1);
} }
@ -1396,14 +1307,11 @@ public class SwipeLayout extends FrameLayout {
} }
int surfaceLeft = surfaceView.getLeft(); int surfaceLeft = surfaceView.getLeft();
int surfaceTop = surfaceView.getTop(); int surfaceTop = surfaceView.getTop();
if (surfaceLeft == getPaddingLeft() && surfaceTop == getPaddingTop() && !mIsBeingDragged) { if (surfaceLeft == getPaddingLeft() && surfaceTop == getPaddingTop()) return Status.Close;
return Status.Close;
}
if (surfaceLeft == (getPaddingLeft() - mDragDistance) || surfaceLeft == (getPaddingLeft() + mDragDistance) if (surfaceLeft == (getPaddingLeft() - mDragDistance) || surfaceLeft == (getPaddingLeft() + mDragDistance)
|| surfaceTop == (getPaddingTop() - mDragDistance) || surfaceTop == (getPaddingTop() + mDragDistance)) { || surfaceTop == (getPaddingTop() - mDragDistance) || surfaceTop == (getPaddingTop() + mDragDistance))
return Status.Open; return Status.Open;
}
return Status.Middle; return Status.Middle;
} }
@ -1425,56 +1333,36 @@ public class SwipeLayout extends FrameLayout {
} }
float willOpenPercent = (isCloseBeforeDragged ? mWillOpenPercentAfterClose : mWillOpenPercentAfterOpen); float willOpenPercent = (isCloseBeforeDragged ? mWillOpenPercentAfterClose : mWillOpenPercentAfterOpen);
if (currentDragEdge == DragEdge.Left) { if (currentDragEdge == DragEdge.Left) {
if (xvel > minVelocity) { if (xvel > minVelocity) open();
open(); else if (xvel < -minVelocity) close();
} else if (xvel < -minVelocity) { else {
close();
} else {
float openPercent = 1f * getSurfaceView().getLeft() / mDragDistance; float openPercent = 1f * getSurfaceView().getLeft() / mDragDistance;
if (openPercent > willOpenPercent) { if (openPercent > willOpenPercent) open();
open(); else close();
} else {
close();
}
} }
} else if (currentDragEdge == DragEdge.Right) { } else if (currentDragEdge == DragEdge.Right) {
if (xvel > minVelocity) { if (xvel > minVelocity) close();
close(); else if (xvel < -minVelocity) open();
} else if (xvel < -minVelocity) { else {
open();
} else {
float openPercent = 1f * (-getSurfaceView().getLeft()) / mDragDistance; float openPercent = 1f * (-getSurfaceView().getLeft()) / mDragDistance;
if (openPercent > willOpenPercent) { if (openPercent > willOpenPercent) open();
open(); else close();
} else {
close();
}
} }
} else if (currentDragEdge == DragEdge.Top) { } else if (currentDragEdge == DragEdge.Top) {
if (yvel > minVelocity) { if (yvel > minVelocity) open();
open(); else if (yvel < -minVelocity) close();
} else if (yvel < -minVelocity) { else {
close();
} else {
float openPercent = 1f * getSurfaceView().getTop() / mDragDistance; float openPercent = 1f * getSurfaceView().getTop() / mDragDistance;
if (openPercent > willOpenPercent) { if (openPercent > willOpenPercent) open();
open(); else close();
} else {
close();
}
} }
} else if (currentDragEdge == DragEdge.Bottom) { } else if (currentDragEdge == DragEdge.Bottom) {
if (yvel > minVelocity) { if (yvel > minVelocity) close();
close(); else if (yvel < -minVelocity) open();
} else if (yvel < -minVelocity) { else {
open();
} else {
float openPercent = 1f * (-getSurfaceView().getTop()) / mDragDistance; float openPercent = 1f * (-getSurfaceView().getTop()) / mDragDistance;
if (openPercent > willOpenPercent) { if (openPercent > willOpenPercent) open();
open(); else close();
} else {
close();
}
} }
} }
} }
@ -1557,9 +1445,9 @@ public class SwipeLayout extends FrameLayout {
return; return;
} }
int dx, dy; int dx, dy;
if (smooth) { if (smooth)
mDragHelper.smoothSlideViewTo(getSurfaceView(), getPaddingLeft(), getPaddingTop()); mDragHelper.smoothSlideViewTo(getSurfaceView(), getPaddingLeft(), getPaddingTop());
} else { else {
Rect rect = computeSurfaceLayoutArea(false); Rect rect = computeSurfaceLayoutArea(false);
dx = rect.left - surface.getLeft(); dx = rect.left - surface.getLeft();
dy = rect.top - surface.getTop(); dy = rect.top - surface.getTop();
@ -1579,11 +1467,9 @@ public class SwipeLayout extends FrameLayout {
} }
public void toggle(boolean smooth) { public void toggle(boolean smooth) {
if (getOpenStatus() == Status.Open) { if (getOpenStatus() == Status.Open)
close(smooth); close(smooth);
} else if (getOpenStatus() == Status.Close) { else if (getOpenStatus() == Status.Close) open(smooth);
open(smooth);
}
} }
@ -1595,15 +1481,13 @@ public class SwipeLayout extends FrameLayout {
private Rect computeSurfaceLayoutArea(boolean open) { private Rect computeSurfaceLayoutArea(boolean open) {
int l = getPaddingLeft(), t = getPaddingTop(); int l = getPaddingLeft(), t = getPaddingTop();
if (open) { if (open) {
if (mCurrentDragEdge == DragEdge.Left) { if (mCurrentDragEdge == DragEdge.Left)
l = getPaddingLeft() + mDragDistance; l = getPaddingLeft() + mDragDistance;
} else if (mCurrentDragEdge == DragEdge.Right) { else if (mCurrentDragEdge == DragEdge.Right)
l = getPaddingLeft() - mDragDistance; l = getPaddingLeft() - mDragDistance;
} else if (mCurrentDragEdge == DragEdge.Top) { else if (mCurrentDragEdge == DragEdge.Top)
t = getPaddingTop() + mDragDistance; t = getPaddingTop() + mDragDistance;
} else { else t = getPaddingTop() - mDragDistance;
t = getPaddingTop() - mDragDistance;
}
} }
return new Rect(l, t, l + getMeasuredWidth(), t + getMeasuredHeight()); return new Rect(l, t, l + getMeasuredWidth(), t + getMeasuredHeight());
} }
@ -1614,15 +1498,13 @@ public class SwipeLayout extends FrameLayout {
int bl = rect.left, bt = rect.top, br = rect.right, bb = rect.bottom; int bl = rect.left, bt = rect.top, br = rect.right, bb = rect.bottom;
if (mode == ShowMode.PullOut) { if (mode == ShowMode.PullOut) {
if (mCurrentDragEdge == DragEdge.Left) { if (mCurrentDragEdge == DragEdge.Left)
bl = rect.left - mDragDistance; bl = rect.left - mDragDistance;
} else if (mCurrentDragEdge == DragEdge.Right) { else if (mCurrentDragEdge == DragEdge.Right)
bl = rect.right; bl = rect.right;
} else if (mCurrentDragEdge == DragEdge.Top) { else if (mCurrentDragEdge == DragEdge.Top)
bt = rect.top - mDragDistance; bt = rect.top - mDragDistance;
} else { else bt = rect.bottom;
bt = rect.bottom;
}
if (mCurrentDragEdge == DragEdge.Left || mCurrentDragEdge == DragEdge.Right) { if (mCurrentDragEdge == DragEdge.Left || mCurrentDragEdge == DragEdge.Right) {
bb = rect.bottom; bb = rect.bottom;
@ -1632,15 +1514,13 @@ public class SwipeLayout extends FrameLayout {
br = rect.right; br = rect.right;
} }
} else if (mode == ShowMode.LayDown) { } else if (mode == ShowMode.LayDown) {
if (mCurrentDragEdge == DragEdge.Left) { if (mCurrentDragEdge == DragEdge.Left)
br = bl + mDragDistance; br = bl + mDragDistance;
} else if (mCurrentDragEdge == DragEdge.Right) { else if (mCurrentDragEdge == DragEdge.Right)
bl = br - mDragDistance; bl = br - mDragDistance;
} else if (mCurrentDragEdge == DragEdge.Top) { else if (mCurrentDragEdge == DragEdge.Top)
bb = bt + mDragDistance; bb = bt + mDragDistance;
} else { else bt = bb - mDragDistance;
bt = bb - mDragDistance;
}
} }
return new Rect(bl, bt, br, bb); return new Rect(bl, bt, br, bb);
@ -1750,9 +1630,7 @@ public class SwipeLayout extends FrameLayout {
} }
private float getCurrentOffset() { private float getCurrentOffset() {
if (mCurrentDragEdge == null) { if (mCurrentDragEdge == null) return 0;
return 0;
}
return mEdgeSwipesOffset[mCurrentDragEdge.ordinal()]; return mEdgeSwipesOffset[mCurrentDragEdge.ordinal()];
} }

View File

@ -2,6 +2,7 @@ package com.daimajia.swipe.adapters;
import android.content.Context; import android.content.Context;
import android.database.Cursor; import android.database.Cursor;
import android.support.v4.widget.CursorAdapter;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
@ -13,8 +14,6 @@ import com.daimajia.swipe.util.Attributes;
import java.util.List; import java.util.List;
import androidx.cursoradapter.widget.CursorAdapter;
public abstract class CursorSwipeAdapter extends CursorAdapter implements SwipeItemMangerInterface, SwipeAdapterInterface { public abstract class CursorSwipeAdapter extends CursorAdapter implements SwipeItemMangerInterface, SwipeAdapterInterface {
private SwipeItemMangerImpl mItemManger = new SwipeItemMangerImpl(this); private SwipeItemMangerImpl mItemManger = new SwipeItemMangerImpl(this);

View File

@ -1,6 +1,6 @@
package com.daimajia.swipe.adapters; package com.daimajia.swipe.adapters;
import androidx.recyclerview.widget.RecyclerView; import android.support.v7.widget.RecyclerView;
import android.view.ViewGroup; import android.view.ViewGroup;
import com.daimajia.swipe.SwipeLayout; import com.daimajia.swipe.SwipeLayout;

View File

@ -2,6 +2,7 @@ package com.daimajia.swipe.adapters;
import android.content.Context; import android.content.Context;
import android.database.Cursor; import android.database.Cursor;
import android.support.v4.widget.SimpleCursorAdapter;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
@ -13,8 +14,6 @@ import com.daimajia.swipe.util.Attributes;
import java.util.List; import java.util.List;
import androidx.cursoradapter.widget.SimpleCursorAdapter;
public abstract class SimpleCursorSwipeAdapter extends SimpleCursorAdapter implements SwipeItemMangerInterface, SwipeAdapterInterface { public abstract class SimpleCursorSwipeAdapter extends SimpleCursorAdapter implements SwipeItemMangerInterface, SwipeAdapterInterface {
private SwipeItemMangerImpl mItemManger = new SwipeItemMangerImpl(this); private SwipeItemMangerImpl mItemManger = new SwipeItemMangerImpl(this);