Skip to content

Commit

Permalink
maxSlide is read each time it's used
Browse files Browse the repository at this point in the history
  • Loading branch information
PierfrancescoSoffritti committed Jul 16, 2016
1 parent 7d5d526 commit 10f017f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,10 @@ public class SlidingDrawer extends LinearLayout {
private final int touchSlop = viewConfiguration.getScaledTouchSlop();

// view that will slide
private View slidableView;
private @NonNull View slidableView;

// view that won't slide
private @NonNull View nonSlidableView;

// current slide value, between 1.0 and 0.0 (1.0 = EXPANDED, 0.0 = COLLAPSED)
private float currentSlide;
Expand All @@ -75,7 +78,7 @@ public class SlidingDrawer extends LinearLayout {
private final static int mCoveredFadeColor = 0x99000000;

// max value by which sliding view can slide.
private int maxSlide;
// private int maxSlide;
private final int minSlide = 0;

// duration of the slide in milliseconds, when executed automatically
Expand Down Expand Up @@ -190,6 +193,8 @@ public boolean onInterceptTouchEvent(MotionEvent event) {
public boolean onTouchEvent(MotionEvent event) {
float eventY = event.getY();

final float maxSlide = nonSlidableView.getHeight();

switch (event.getAction()) {
case MotionEvent.ACTION_UP:
// complete the slide if it's not completed yet.
Expand Down Expand Up @@ -217,6 +222,8 @@ else if(eventY + dY < minSlide)
}

private void completeSlide(float currentSlide, @SlidingDirection int direction) {
final float maxSlide = nonSlidableView.getHeight();

float finalY = -1;

switch (direction) {
Expand Down Expand Up @@ -248,6 +255,8 @@ else if(currentSlide == 0)
}

private float normalizeSlide(float currentY) {
final float maxSlide = nonSlidableView.getHeight();

// currentSlide_Normalized : x = 1 : maxSliding
return Math.abs(currentY - maxSlide) / maxSlide;
}
Expand All @@ -257,6 +266,8 @@ private float normalizeSlide(float currentY) {
* @param newPositionNormalized new view position, normalized
*/
private void updateSliding(float newPositionNormalized) {
final float maxSlide = nonSlidableView.getHeight();

currentSlide = newPositionNormalized;

state = currentSlide == 1 ? EXPANDED : currentSlide == 0 ? COLLAPSED : SLIDING;
Expand Down Expand Up @@ -318,7 +329,7 @@ protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
private void initSlidingChild() {
slidableView = findViewById(R.id.slidable_view);

maxSlide = findViewById(R.id.non_slidable_view).getHeight();
nonSlidableView = findViewById(R.id.non_slidable_view);

// the collapsed view is the view shown when the slidableView is collapsed.
// it's important to add padding to its bottom, otherwise some content will be offscreen-
Expand All @@ -332,10 +343,12 @@ private void initSlidingChild() {
* @param root the view that needs padding
*/
private void addPadding(View root) {
final float maxSlide = nonSlidableView.getHeight();

int top = root.getPaddingTop();
int left = root.getPaddingLeft();
int right = root.getPaddingRight();
int bottom = maxSlide;
int bottom = (int) maxSlide;

root.setPadding(left, top, right, bottom);
}
Expand Down

0 comments on commit 10f017f

Please sign in to comment.