Skip to content
This repository was archived by the owner on Feb 20, 2021. It is now read-only.
Open
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
39 changes: 16 additions & 23 deletions Library/src/com/slidinglayer/SlidingLayer.java
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ public SlidingLayer(Context context, AttributeSet attrs, int defStyle) {
init();
}

//TODO 需要研究
private void init() {
setWillNotDraw(false);
setDescendantFocusability(FOCUS_AFTER_DESCENDANTS);
Expand Down Expand Up @@ -253,7 +254,6 @@ private void switchLayer(boolean open, boolean smoothAnim, boolean forceSwitch)
private void switchLayer(final boolean open, final boolean smoothAnim, final boolean forceSwitch,
final int velocityX, final int velocityY) {
if (!forceSwitch && open == mIsOpen) {
setDrawingCacheEnabled(false);
return;
}
if (open) {
Expand Down Expand Up @@ -409,21 +409,15 @@ public void setSlidingFromShadowEnabled(boolean _slidingShadow) {

@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {

boolean handle=false;
if (!mEnabled) {
return false;
}

final int action = ev.getAction() & MotionEventCompat.ACTION_MASK;

if (action == MotionEvent.ACTION_CANCEL || action == MotionEvent.ACTION_UP) {
mIsDragging = false;
mIsUnableToDrag = false;
mActivePointerId = INVALID_POINTER;
if (mVelocityTracker != null) {
mVelocityTracker.recycle();
mVelocityTracker = null;
}
endDrag();
return false;
}

Expand Down Expand Up @@ -456,13 +450,11 @@ public boolean onInterceptTouchEvent(MotionEvent ev) {
final float yDiff = Math.abs(y - mLastY);

if (xDiff > mTouchSlop && xDiff > yDiff && allowDragingX(dx, mInitialX)) {
mIsDragging = true;
handle = true;
mLastX = x;
setDrawingCacheEnabled(true);
} else if (yDiff > mTouchSlop && yDiff > xDiff && allowDragingY(dy, mInitialY)) {
mIsDragging = true;
handle = true;
mLastY = y;
setDrawingCacheEnabled(true);
}
break;

Expand All @@ -473,13 +465,11 @@ public boolean onInterceptTouchEvent(MotionEvent ev) {
mLastX = mInitialX = MotionEventCompat.getX(ev, mActivePointerId);
mLastY = mInitialY = MotionEventCompat.getY(ev, mActivePointerId);
if (allowSlidingFromHereX(ev, mInitialX)) {
mIsDragging = false;
mIsUnableToDrag = false;
handle = false;
// If nobody else got the focus we use it to close the layer
return super.onInterceptTouchEvent(ev);
} else if (allowSlidingFromHereY(ev, mInitialY)) {
mIsDragging = false;
mIsUnableToDrag = false;
handle = false;
// If nobody else got the focus we use it to close the layer
return super.onInterceptTouchEvent(ev);
} else {
Expand All @@ -498,7 +488,7 @@ public boolean onInterceptTouchEvent(MotionEvent ev) {
mVelocityTracker.addMovement(ev);
}

return mIsDragging;
return handle;
}

@Override
Expand Down Expand Up @@ -870,7 +860,6 @@ void smoothScrollTo(int x, int y) {
*/
void smoothScrollTo(int x, int y, int velocity) {
if (getChildCount() == 0) {
setDrawingCacheEnabled(false);
return;
}
int sx = getScrollX();
Expand Down Expand Up @@ -969,7 +958,6 @@ private void completeScroll() {
boolean needPopulate = mScrolling;
if (needPopulate) {
// Done with scroll, no longer want to cache view drawing.
setDrawingCacheEnabled(false);
mScroller.abortAnimation();
int oldX = getScrollX();
int oldY = getScrollY();
Expand Down Expand Up @@ -1125,6 +1113,10 @@ protected void onLayout(boolean changed, int left, int top, int right, int botto
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
if(!mScrolling&&!mIsDragging)
{
setDrawingCacheEnabled(false);
}
}

private int[] getDestScrollPos() {
Expand Down Expand Up @@ -1247,9 +1239,10 @@ public void computeScroll() {
return;
}
}

// Done with scroll, clean up state.
completeScroll();
else
{
completeScroll();
}
}

/**
Expand Down