Skip to content

Replace deprecated methods #902

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 1 commit 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
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.os.Parcelable;
import android.support.v4.view.MotionEventCompat;
import android.support.v4.view.ViewCompat;
import android.util.AttributeSet;
import android.util.Log;
Expand Down Expand Up @@ -888,7 +887,7 @@ public boolean onInterceptTouchEvent(MotionEvent ev) {
return false;
}

final int action = MotionEventCompat.getActionMasked(ev);
final int action = ev.getAction();
final float x = ev.getX();
final float y = ev.getY();
final float adx = Math.abs(x - mInitialMotionX);
Expand Down Expand Up @@ -956,7 +955,7 @@ public boolean onTouchEvent(MotionEvent ev) {

@Override
public boolean dispatchTouchEvent(MotionEvent ev) {
final int action = MotionEventCompat.getActionMasked(ev);
final int action = ev.getAction();

if (!isEnabled() || !isTouchEnabled() || (mIsUnableToDrag && action != MotionEvent.ACTION_DOWN)) {
mDragHelper.abort();
Expand Down Expand Up @@ -1151,7 +1150,7 @@ private void setPanelStateInternal(PanelState state) {
private void applyParallaxForCurrentSlideOffset() {
if (mParallaxOffset > 0) {
int mainViewOffset = getCurrentParallaxOffset();
ViewCompat.setTranslationY(mMainView, mainViewOffset);
mMainView.setTranslationY(mainViewOffset);
}
}

Expand Down Expand Up @@ -1186,7 +1185,7 @@ private void onPanelDragged(int newTop) {
@Override
protected boolean drawChild(Canvas canvas, View child, long drawingTime) {
boolean result;
final int save = canvas.save(Canvas.CLIP_SAVE_FLAG);
final int save = canvas.save(Canvas.ALL_SAVE_FLAG);

if (mSlideableView != null && mSlideableView != child) { // if main view
// Clip against the slider; no sense drawing what will immediately be covered,
Expand Down Expand Up @@ -1305,7 +1304,7 @@ protected boolean canScroll(View v, boolean checkV, int dx, int x, int y) {
}
}
}
return checkV && ViewCompat.canScrollHorizontally(v, -dx);
return checkV && v.canScrollHorizontally(-dx);
}


Expand Down Expand Up @@ -1483,8 +1482,6 @@ public LayoutParams(Context c, AttributeSet attrs) {
this.weight = ta.getFloat(0, 0);
ta.recycle();
}


}
}
}
100 changes: 48 additions & 52 deletions library/src/main/java/com/sothree/slidinguppanel/ViewDragHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,13 @@
package com.sothree.slidinguppanel;

import android.content.Context;
import android.support.v4.view.MotionEventCompat;
import android.support.v4.view.VelocityTrackerCompat;
import android.support.v4.view.ViewCompat;
import android.support.v4.widget.ScrollerCompat;
import android.view.MotionEvent;
import android.view.VelocityTracker;
import android.view.View;
import android.view.ViewConfiguration;
import android.view.ViewGroup;
import android.view.animation.Interpolator;
import android.widget.OverScroller;

import java.util.Arrays;

Expand Down Expand Up @@ -130,7 +127,7 @@ public class ViewDragHelper {
private int mEdgeSize;
private int mTrackingEdges;

private ScrollerCompat mScroller;
private OverScroller mScroller;

private final Callback mCallback;

Expand Down Expand Up @@ -419,7 +416,7 @@ private ViewDragHelper(Context context, ViewGroup forParent, Interpolator interp
mTouchSlop = vc.getScaledTouchSlop();
mMaxVelocity = vc.getScaledMaximumFlingVelocity();
mMinVelocity = vc.getScaledMinimumFlingVelocity();
mScroller = ScrollerCompat.create(context, interpolator != null ? interpolator : sInterpolator);
mScroller = new OverScroller(context, interpolator != null ? interpolator : sInterpolator);
}

/**
Expand Down Expand Up @@ -591,8 +588,8 @@ public boolean settleCapturedViewAt(int finalLeft, int finalTop) {
}

return forceSettleCapturedViewAt(finalLeft, finalTop,
(int) VelocityTrackerCompat.getXVelocity(mVelocityTracker, mActivePointerId),
(int) VelocityTrackerCompat.getYVelocity(mVelocityTracker, mActivePointerId));
(int) mVelocityTracker.getXVelocity(mActivePointerId),
(int) mVelocityTracker.getYVelocity(mActivePointerId));
}

/**
Expand Down Expand Up @@ -724,8 +721,8 @@ public void flingCapturedView(int minLeft, int minTop, int maxLeft, int maxTop)
}

mScroller.fling(mCapturedView.getLeft(), mCapturedView.getTop(),
(int) VelocityTrackerCompat.getXVelocity(mVelocityTracker, mActivePointerId),
(int) VelocityTrackerCompat.getYVelocity(mVelocityTracker, mActivePointerId),
(int) mVelocityTracker.getXVelocity(mActivePointerId),
(int) mVelocityTracker.getYVelocity(mActivePointerId),
minLeft, maxLeft, minTop, maxTop);

setDragState(STATE_SETTLING);
Expand Down Expand Up @@ -874,11 +871,11 @@ private void saveInitialMotion(float x, float y, int pointerId) {
}

private void saveLastMotion(MotionEvent ev) {
final int pointerCount = MotionEventCompat.getPointerCount(ev);
final int pointerCount = ev.getPointerCount();
for (int i = 0; i < pointerCount; i++) {
final int pointerId = MotionEventCompat.getPointerId(ev, i);
final float x = MotionEventCompat.getX(ev, i);
final float y = MotionEventCompat.getY(ev, i);
final int pointerId = ev.getPointerId(i);
final float x = ev.getX(i);
final float y = ev.getY(i);
// Sometimes we can try and save last motion for a pointer never recorded in initial motion. In this case we just discard it.
if (mLastMotionX != null && mLastMotionY != null
&& mLastMotionX.length > pointerId && mLastMotionY.length > pointerId) {
Expand Down Expand Up @@ -969,8 +966,8 @@ protected boolean canScroll(View v, boolean checkV, int dx, int dy, int x, int y
}
}

return checkV && (ViewCompat.canScrollHorizontally(v, -dx) ||
ViewCompat.canScrollVertically(v, -dy));
return checkV && (v.canScrollHorizontally(-dx) ||
v.canScrollVertically(-dy));
}

/**
Expand All @@ -981,8 +978,8 @@ protected boolean canScroll(View v, boolean checkV, int dx, int dy, int x, int y
* @return true if the parent view should return true from onInterceptTouchEvent
*/
public boolean shouldInterceptTouchEvent(MotionEvent ev) {
final int action = MotionEventCompat.getActionMasked(ev);
final int actionIndex = MotionEventCompat.getActionIndex(ev);
final int action = ev.getAction();
final int actionIndex = ev.getActionIndex();

if (action == MotionEvent.ACTION_DOWN) {
// Reset things for a new event stream, just in case we didn't get
Expand All @@ -999,7 +996,7 @@ public boolean shouldInterceptTouchEvent(MotionEvent ev) {
case MotionEvent.ACTION_DOWN: {
final float x = ev.getX();
final float y = ev.getY();
final int pointerId = MotionEventCompat.getPointerId(ev, 0);
final int pointerId = ev.getPointerId(0);
saveInitialMotion(x, y, pointerId);

final View toCapture = findTopChildUnder((int) x, (int) y);
Expand All @@ -1016,10 +1013,10 @@ public boolean shouldInterceptTouchEvent(MotionEvent ev) {
break;
}

case MotionEventCompat.ACTION_POINTER_DOWN: {
final int pointerId = MotionEventCompat.getPointerId(ev, actionIndex);
final float x = MotionEventCompat.getX(ev, actionIndex);
final float y = MotionEventCompat.getY(ev, actionIndex);
case MotionEvent.ACTION_POINTER_DOWN: {
final int pointerId = ev.getPointerId(actionIndex);
final float x = ev.getX(actionIndex);
final float y = ev.getY(actionIndex);

saveInitialMotion(x, y, pointerId);

Expand All @@ -1041,14 +1038,14 @@ public boolean shouldInterceptTouchEvent(MotionEvent ev) {

case MotionEvent.ACTION_MOVE: {
// First to cross a touch slop over a draggable view wins. Also report edge drags.
final int pointerCount = MotionEventCompat.getPointerCount(ev);
final int pointerCount = ev.getPointerCount();
for (int i = 0; i < pointerCount && mInitialMotionX != null && mInitialMotionY != null; i++) {
final int pointerId = MotionEventCompat.getPointerId(ev, i);
final int pointerId = ev.getPointerId(i);
if (pointerId >= mInitialMotionX.length || pointerId >= mInitialMotionY.length) {
continue;
}
final float x = MotionEventCompat.getX(ev, i);
final float y = MotionEventCompat.getY(ev, i);
final float x = ev.getX(i);
final float y = ev.getY(i);
final float dx = x - mInitialMotionX[pointerId];
final float dy = y - mInitialMotionY[pointerId];

Expand All @@ -1068,8 +1065,8 @@ public boolean shouldInterceptTouchEvent(MotionEvent ev) {
break;
}

case MotionEventCompat.ACTION_POINTER_UP: {
final int pointerId = MotionEventCompat.getPointerId(ev, actionIndex);
case MotionEvent.ACTION_POINTER_UP: {
final int pointerId = ev.getPointerId(actionIndex);
clearMotionHistory(pointerId);
break;
}
Expand All @@ -1091,8 +1088,8 @@ public boolean shouldInterceptTouchEvent(MotionEvent ev) {
* @param ev The touch event received by the parent view
*/
public void processTouchEvent(MotionEvent ev) {
final int action = MotionEventCompat.getActionMasked(ev);
final int actionIndex = MotionEventCompat.getActionIndex(ev);
final int action = ev.getAction();
final int actionIndex = ev.getActionIndex();

if (action == MotionEvent.ACTION_DOWN) {
// Reset things for a new event stream, just in case we didn't get
Expand All @@ -1109,7 +1106,7 @@ public void processTouchEvent(MotionEvent ev) {
case MotionEvent.ACTION_DOWN: {
final float x = ev.getX();
final float y = ev.getY();
final int pointerId = MotionEventCompat.getPointerId(ev, 0);
final int pointerId = ev.getPointerId(0);
final View toCapture = findTopChildUnder((int) x, (int) y);

saveInitialMotion(x, y, pointerId);
Expand All @@ -1126,10 +1123,10 @@ public void processTouchEvent(MotionEvent ev) {
break;
}

case MotionEventCompat.ACTION_POINTER_DOWN: {
final int pointerId = MotionEventCompat.getPointerId(ev, actionIndex);
final float x = MotionEventCompat.getX(ev, actionIndex);
final float y = MotionEventCompat.getY(ev, actionIndex);
case MotionEvent.ACTION_POINTER_DOWN: {
final int pointerId = ev.getPointerId(actionIndex);
final float x = ev.getX(actionIndex);
final float y = ev.getY(actionIndex);

saveInitialMotion(x, y, pointerId);

Expand All @@ -1156,9 +1153,9 @@ public void processTouchEvent(MotionEvent ev) {

case MotionEvent.ACTION_MOVE: {
if (mDragState == STATE_DRAGGING) {
final int index = MotionEventCompat.findPointerIndex(ev, mActivePointerId);
final float x = MotionEventCompat.getX(ev, index);
final float y = MotionEventCompat.getY(ev, index);
final int index = ev.findPointerIndex(mActivePointerId);
final float x = ev.getX(index);
final float y = ev.getY(index);
final int idx = (int) (x - mLastMotionX[mActivePointerId]);
final int idy = (int) (y - mLastMotionY[mActivePointerId]);

Expand All @@ -1167,12 +1164,11 @@ public void processTouchEvent(MotionEvent ev) {
saveLastMotion(ev);
} else {
// Check to see if any pointer is now over a draggable view.
final int pointerCount = MotionEventCompat.getPointerCount(ev);
final int pointerCount = ev.getPointerCount();
for (int i = 0; i < pointerCount; i++) {
final int pointerId = MotionEventCompat.getPointerId(ev, i)
;
final float x = MotionEventCompat.getX(ev, i);
final float y = MotionEventCompat.getY(ev, i);
final int pointerId = ev.getPointerId(i);
final float x = ev.getX(i);
final float y = ev.getY(i);
final float dx = x - mInitialMotionX[pointerId];
final float dy = y - mInitialMotionY[pointerId];

Expand All @@ -1193,21 +1189,21 @@ public void processTouchEvent(MotionEvent ev) {
break;
}

case MotionEventCompat.ACTION_POINTER_UP: {
final int pointerId = MotionEventCompat.getPointerId(ev, actionIndex);
case MotionEvent.ACTION_POINTER_UP: {
final int pointerId = ev.getPointerId(actionIndex);
if (mDragState == STATE_DRAGGING && pointerId == mActivePointerId) {
// Try to find another pointer that's still holding on to the captured view.
int newActivePointer = INVALID_POINTER;
final int pointerCount = MotionEventCompat.getPointerCount(ev);
final int pointerCount = ev.getPointerCount();
for (int i = 0; i < pointerCount; i++) {
final int id = MotionEventCompat.getPointerId(ev, i);
final int id = ev.getPointerId(i);
if (id == mActivePointerId) {
// This one's going away, skip.
continue;
}

final float x = MotionEventCompat.getX(ev, i);
final float y = MotionEventCompat.getY(ev, i);
final float x = ev.getX(i);
final float y = ev.getY(i);
if (findTopChildUnder((int) x, (int) y) == mCapturedView &&
tryCaptureViewForDrag(mCapturedView, id)) {
newActivePointer = mActivePointerId;
Expand Down Expand Up @@ -1407,10 +1403,10 @@ public boolean isDragging() {
private void releaseViewForPointerUp() {
mVelocityTracker.computeCurrentVelocity(1000, mMaxVelocity);
final float xvel = clampMag(
VelocityTrackerCompat.getXVelocity(mVelocityTracker, mActivePointerId),
mVelocityTracker.getXVelocity(mActivePointerId),
mMinVelocity, mMaxVelocity);
final float yvel = clampMag(
VelocityTrackerCompat.getYVelocity(mVelocityTracker, mActivePointerId),
mVelocityTracker.getYVelocity(mActivePointerId),
mMinVelocity, mMaxVelocity);
dispatchViewReleased(xvel, yvel);
}
Expand Down