Methods Summary |
---|
private void | cancelExpansion(ExpandableView child)
if (child.getActualHeight() == child.getMinHeight()) {
return;
}
ObjectAnimator anim = ObjectAnimator.ofInt(child, "actualHeight",
child.getActualHeight(), child.getMinHeight());
anim.setInterpolator(mInterpolator);
anim.setDuration(SPRING_BACK_ANIMATION_LENGTH_MS);
anim.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
mCallback.setUserLockedChild(child, false);
}
});
anim.start();
|
private void | cancelExpansion()
ValueAnimator anim = ValueAnimator.ofFloat(mLastHeight, 0);
anim.setInterpolator(mInterpolator);
anim.setDuration(SPRING_BACK_ANIMATION_LENGTH_MS);
anim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animation) {
mDragDownCallback.setEmptyDragAmount((Float) animation.getAnimatedValue());
}
});
anim.start();
|
private void | captureStartingChild(float x, float y)
if (mStartingChild == null) {
mStartingChild = findView(x, y);
if (mStartingChild != null) {
mCallback.setUserLockedChild(mStartingChild, true);
}
}
|
private ExpandableView | findView(float x, float y)
mHost.getLocationOnScreen(mTemp2);
x += mTemp2[0];
y += mTemp2[1];
return mCallback.getChildAtRawPosition(x, y);
|
private void | handleExpansion(float heightDelta, ExpandableView child)
if (heightDelta < 0) {
heightDelta = 0;
}
boolean expandable = child.isContentExpandable();
float rubberbandFactor = expandable
? RUBBERBAND_FACTOR_EXPANDABLE
: RUBBERBAND_FACTOR_STATIC;
float rubberband = heightDelta * rubberbandFactor;
if (expandable && (rubberband + child.getMinHeight()) > child.getMaxHeight()) {
float overshoot = (rubberband + child.getMinHeight()) - child.getMaxHeight();
overshoot *= (1 - RUBBERBAND_FACTOR_STATIC);
rubberband -= overshoot;
}
child.setActualHeight((int) (child.getMinHeight() + rubberband));
|
public boolean | onInterceptTouchEvent(android.view.MotionEvent event)
final float x = event.getX();
final float y = event.getY();
switch (event.getActionMasked()) {
case MotionEvent.ACTION_DOWN:
mDraggedFarEnough = false;
mDraggingDown = false;
mStartingChild = null;
mInitialTouchY = y;
mInitialTouchX = x;
break;
case MotionEvent.ACTION_MOVE:
final float h = y - mInitialTouchY;
if (h > mTouchSlop && h > Math.abs(x - mInitialTouchX)) {
mDraggingDown = true;
captureStartingChild(mInitialTouchX, mInitialTouchY);
mInitialTouchY = y;
mInitialTouchX = x;
mDragDownCallback.onTouchSlopExceeded();
return true;
}
break;
}
return false;
|
public boolean | onTouchEvent(android.view.MotionEvent event)
if (!mDraggingDown) {
return false;
}
final float x = event.getX();
final float y = event.getY();
switch (event.getActionMasked()) {
case MotionEvent.ACTION_MOVE:
mLastHeight = y - mInitialTouchY;
captureStartingChild(mInitialTouchX, mInitialTouchY);
if (mStartingChild != null) {
handleExpansion(mLastHeight, mStartingChild);
} else {
mDragDownCallback.setEmptyDragAmount(mLastHeight);
}
if (mLastHeight > mMinDragDistance) {
if (!mDraggedFarEnough) {
mDraggedFarEnough = true;
mDragDownCallback.onThresholdReached();
}
} else {
if (mDraggedFarEnough) {
mDraggedFarEnough = false;
mDragDownCallback.onDragDownReset();
}
}
return true;
case MotionEvent.ACTION_UP:
if (mDraggedFarEnough && mDragDownCallback.onDraggedDown(mStartingChild,
(int) (y - mInitialTouchY))) {
if (mStartingChild == null) {
mDragDownCallback.setEmptyDragAmount(0f);
}
mDraggingDown = false;
} else {
stopDragging();
return false;
}
break;
case MotionEvent.ACTION_CANCEL:
stopDragging();
return false;
}
return false;
|
private void | stopDragging()
if (mStartingChild != null) {
cancelExpansion(mStartingChild);
} else {
cancelExpansion();
}
mDraggingDown = false;
mDragDownCallback.onDragDownReset();
|