Skip to content
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

fixed backwards compatibility for API 8 (#694) #699

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
2 changes: 1 addition & 1 deletion demo/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ android {
}

defaultConfig {
minSdkVersion 11
minSdkVersion 8
targetSdkVersion 23
}
}
Expand Down
2 changes: 1 addition & 1 deletion demo/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
android:versionName="3.3.0">

<uses-sdk
android:minSdkVersion="11"
android:minSdkVersion="8"
android:targetSdkVersion="17" />

<application
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -896,6 +896,8 @@ public boolean onInterceptTouchEvent(MotionEvent ev) {
return false;
}
break;


}

case MotionEvent.ACTION_CANCEL:
Expand Down Expand Up @@ -1033,10 +1035,14 @@ private boolean isViewUnder(View view, int x, int y) {
private int computePanelTopPosition(float slideOffset) {
int slidingViewHeight = mSlideableView != null ? mSlideableView.getMeasuredHeight() : 0;
int slidePixelOffset = (int) (slideOffset * mSlideRange);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The logic here looks exactly the same, can you elaborate how this is solving #694?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

my guess is race condition / slower hardware, the logic IS exactly the same, but the jittery (and buggy) sliding happened because the return value (calculated in the topBoundCollapsed code below) would every now and then switch from X to -X while isSlidingUp and all calculated values would be correct
// adding this line already solved the problem
Log.d("jack", "values= " + getMeasuredHeight() + " " + getPaddingBottom() + " " + mPanelHeight + " " + slidePixelOffset );

when I added that line there for troubleshooting, the problem immediately disappeared, and seeing as the only thing happening was the 'pre-calculation' of several functioned values, having the values calculated before the actual return statement, solved the strange behavior (I considered that a better 'solution' then leaving a debug line in)

Also as it turned out, HTC desire (2.2) had the problem, another alcatel one touch (with 2.3) didn't so it might be a bit more device specific, seeing as the logic doesn't change, this will probably make it work on more (possibly slower) devices

** topBoundCollapsed in below function would be -660 instead of the expected 660 it did on 'slower slides' or just hitting DragView (for a bottom panel anyway)

private float computeSlideOffset(int topPosition) {
        // Compute the panel top position if the panel is collapsed (offset 0)
        final int topBoundCollapsed = computePanelTopPosition(0);

I agree it's been baffling me for a few days already :) but the above explanation seems to make the most sense, I do know that adding that line makes the library use-able (and sliding smooth) for me on my test device while without it the sliding is all over the place (-X here meant it wasn't sure if it wanted to be Top or Bottom Panel :) )

// fix for issue #694
int bottomPanelValue = getMeasuredHeight() - getPaddingBottom() - mPanelHeight - slidePixelOffset;
int topPanelValue = getPaddingTop() - slidingViewHeight + mPanelHeight + slidePixelOffset;


// Compute the top of the panel if its collapsed
return mIsSlidingUp
? getMeasuredHeight() - getPaddingBottom() - mPanelHeight - slidePixelOffset
: getPaddingTop() - slidingViewHeight + mPanelHeight + slidePixelOffset;
return mIsSlidingUp ? bottomPanelValue : topPanelValue;
}

/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package com.sothree.slidinguppanel;

import android.content.Context;
import android.os.Build;
import android.support.v4.view.MotionEventCompat;
import android.support.v4.view.VelocityTrackerCompat;
import android.support.v4.view.ViewCompat;
Expand Down Expand Up @@ -756,7 +757,10 @@ public boolean continueSettling(boolean deferCallbacks) {

if(!keepGoing && dy != 0) { //fix #525
//Invalid drag state
mCapturedView.setTop(0);
// fix #694 catch SDK for backwards compatibility, View.setTop(int) is an API 11 call
if(android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
mCapturedView.setTop(0);
}
return true;
}

Expand Down