Skip to content

Commit

Permalink
-fix bug
Browse files Browse the repository at this point in the history
  • Loading branch information
tohodog committed Aug 18, 2018
1 parent 9dd5005 commit eceafac
Show file tree
Hide file tree
Showing 21 changed files with 67 additions and 37 deletions.
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,20 @@
* 支持任意可滑动的控件
* 更多效果更新中...

Gradle
```
allprojects {
repositories {
maven {
url "https://jitpack.io"
}
}
}
dependencies {
implementation 'com.github.tohodog:QSRefreshLayout:1.1'
}
```

## XML
```
<org.song.refreshlayout.QSRefreshLayout
Expand Down
6 changes: 3 additions & 3 deletions RefreshLayout/build.gradle
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
apply plugin: 'com.android.library'

android {
compileSdkVersion 25
buildToolsVersion "25.0.3"
compileSdkVersion 26
buildToolsVersion "27.0.3"

defaultConfig {
minSdkVersion 14
Expand All @@ -21,5 +21,5 @@ android {

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:support-v4:25.3.1'
implementation 'com.android.support:support-v4:26.1.0'
}
Original file line number Diff line number Diff line change
Expand Up @@ -127,34 +127,42 @@ public boolean onInterceptTouchEvent(MotionEvent ev) {
return b;
}

private int mActivePointerId;
private volatile int mActivePointerId = MotionEvent.INVALID_POINTER_ID;
private float mInitialMotionY, mInitialMotionX;

//是否截取事件
private boolean handlerInterceptTouchEvent(MotionEvent ev, boolean isHead) {
final int action = ev.getActionMasked();
boolean mIsBeingDragged = false;
final int pointerIndex;
switch (action) {
case MotionEvent.ACTION_DOWN:
mActivePointerId = ev.getPointerId(0);
mIsBeingDragged = false;
final float initialMotionY = ev.getY(mActivePointerId);
if (mActivePointerId == MotionEvent.INVALID_POINTER_ID)
mActivePointerId = ev.getPointerId(0);
pointerIndex = ev.findPointerIndex(mActivePointerId);
if (pointerIndex < 0) {
return false;
}
final float initialMotionY = ev.getY(pointerIndex);
if (initialMotionY == -1) {
return false;
}
mInitialMotionX = ev.getX(mActivePointerId);
mInitialMotionX = ev.getX(pointerIndex);
mInitialMotionY = initialMotionY;
break;
case MotionEvent.ACTION_MOVE:
if (mActivePointerId == MotionEvent.INVALID_POINTER_ID) {
return false;
}
final int index = ev.findPointerIndex(mActivePointerId);
if (index < 0) {
pointerIndex = ev.findPointerIndex(mActivePointerId);

if (pointerIndex < 0) {
return false;
}
final float y = ev.getY(mActivePointerId);
final float x = ev.getX(mActivePointerId);

final float y = ev.getY(pointerIndex);
final float x = ev.getX(pointerIndex);

if (y == -1) {
return false;
Expand All @@ -173,11 +181,16 @@ private boolean handlerInterceptTouchEvent(MotionEvent ev, boolean isHead) {
mIsBeingDragged = false;
mActivePointerId = MotionEvent.INVALID_POINTER_ID;
break;
case MotionEvent.ACTION_POINTER_UP://兼容多个手指
final int pointerIndex = ev.getActionIndex();
final int pointerId = ev.getPointerId(pointerIndex);

case MotionEvent.ACTION_POINTER_DOWN:
final int index = ev.getActionIndex();
mActivePointerId = ev.getPointerId(index);
break;
case MotionEvent.ACTION_POINTER_UP:
final int actionIndex = ev.getActionIndex();
final int pointerId = ev.getPointerId(actionIndex);
if (pointerId == mActivePointerId) {
final int newPointerIndex = pointerIndex == 0 ? 1 : 0;
final int newPointerIndex = actionIndex == 0 ? 1 : 0;
mActivePointerId = ev.getPointerId(newPointerIndex);
}
break;
Expand Down Expand Up @@ -219,19 +232,6 @@ public boolean onTouchEvent(MotionEvent ev) {
break;
}

case MotionEvent.ACTION_POINTER_DOWN:
final int index = ev.getActionIndex();
mActivePointerId = ev.getPointerId(index);
break;

case MotionEvent.ACTION_POINTER_UP:
final int pointerIndex = ev.getActionIndex();
final int pointerId = ev.getPointerId(pointerIndex);
if (pointerId == mActivePointerId) {
final int newPointerIndex = pointerIndex == 0 ? 1 : 0;
mActivePointerId = ev.getPointerId(newPointerIndex);
}
break;

case MotionEvent.ACTION_UP:
case MotionEvent.ACTION_CANCEL: {
Expand All @@ -249,6 +249,20 @@ public boolean onTouchEvent(MotionEvent ev) {
mActivePointerId = MotionEvent.INVALID_POINTER_ID;
return false;
}


case MotionEvent.ACTION_POINTER_DOWN:
final int index = ev.getActionIndex();
mActivePointerId = ev.getPointerId(index);
break;
case MotionEvent.ACTION_POINTER_UP:
final int pointerIndex = ev.getActionIndex();
final int pointerId = ev.getPointerId(pointerIndex);
if (pointerId == mActivePointerId) {
final int newPointerIndex = pointerIndex == 0 ? 1 : 0;
mActivePointerId = ev.getPointerId(newPointerIndex);
}
break;
}

return true;
Expand All @@ -271,7 +285,8 @@ private void setDragViewOffsetAndPro(int offset, boolean requiresUpdate) {

temp1 = draggedRefreshView.getTargetOffset(temp);
temp2 = draggedRefreshView.getTargetOffset(offset);
mTarget.offsetTopAndBottom(temp2 - temp1);
if (mTarget != null)
mTarget.offsetTopAndBottom(temp2 - temp1);

temp1 = draggedRefreshView.getThisViewOffset(temp);
temp2 = draggedRefreshView.getThisViewOffset(offset);
Expand Down Expand Up @@ -337,6 +352,7 @@ protected void scrollAnimation(final int start, final int end, final int time, f
mScrollAnimator.setIntValues(start, end);
mScrollAnimator.setInterpolator(animeInterpolator);
mScrollAnimator.setDuration(time > 0 ? time : animaDuration);
//mScrollAnimator.setStartDelay(0);
mScrollAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animation) {
Expand Down
10 changes: 4 additions & 6 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
apply plugin: 'com.android.application'

android {
compileSdkVersion 25
buildToolsVersion "25.0.3"
compileSdkVersion 26
buildToolsVersion "27.0.3"


defaultConfig {
Expand Down Expand Up @@ -35,9 +35,7 @@ dependencies {

compile project(':RefreshLayout')

compile 'com.android.support:appcompat-v7:25.3.1'
compile 'com.android.support:recyclerview-v7:25.3.1'
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.android.support:recyclerview-v7:26.1.0'

compile 'com.android.support.constraint:constraint-layout:1.0.0-beta5'
testCompile 'junit:junit:4.12'
}
Binary file added app/src/main/res/drawable-hdpi/buildings.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable-hdpi/sky.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable-hdpi/sun.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable-mdpi/buildings.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable-mdpi/sky.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable-mdpi/sun.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable-xhdpi/buildings.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable-xhdpi/sky.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable-xhdpi/sun.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable-xxhdpi/buildings.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable-xxhdpi/sky.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable-xxhdpi/sun.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable-xxxhdpi/buildings.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable-xxxhdpi/sky.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable-xxxhdpi/sun.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 3 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
buildscript {
repositories {
jcenter()
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.2'
classpath 'com.android.tools.build:gradle:3.0.1'

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
Expand All @@ -15,6 +16,7 @@ buildscript {
allprojects {
repositories {
jcenter()
google()
}
}

Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip

0 comments on commit eceafac

Please sign in to comment.