I would suggest the following well known and widely used solution instead of the ClosableSlidingLayout
you now have (actually, the horizontal swipe could be removed from it completely). This handles the swipe easily and nicely and could be used for both directions, to open up from More and to close down:
public class SwipeFrameLayout extends android.widget.FrameLayout {
private final GestureDetector gestureDetector;
protected OnHorizontalSwipe horizontalListener;
protected OnVerticalSwipe verticalListener;
public interface OnHorizontalSwipe {
public boolean onSwipeLeft();
public boolean onSwipeRight();
}
public interface OnVerticalSwipe {
public boolean onSwipeUp();
public boolean onSwipeDown();
}
public SwipeFrameLayout(Context context) {
super(context);
gestureDetector = new GestureDetector(context, new GestureListener());
}
public SwipeFrameLayout(Context context, AttributeSet attrs) {
super(context, attrs);
gestureDetector = new GestureDetector(context, new GestureListener());
}
public SwipeFrameLayout(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
gestureDetector = new GestureDetector(context, new GestureListener());
}
@Override
public boolean dispatchTouchEvent(MotionEvent e) {
gestureDetector.onTouchEvent(e);
return super.dispatchTouchEvent(e);
}
public void setHorizontalListener(OnHorizontalSwipe horizontalListener) {
this.horizontalListener = horizontalListener;
}
public void setVerticalListener(OnVerticalSwipe verticalListener) {
this.verticalListener = verticalListener;
}
private final class GestureListener extends SimpleOnGestureListener {
private static final int SWIPE_DISTANCE_THRESHOLD = 100;
private static final int SWIPE_VELOCITY_THRESHOLD = 100;
@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
float dX = e2.getX() - e1.getX();
float dY = e2.getY() - e1.getY();
if (Math.abs(dX) > Math.abs(dY) && Math.abs(dX) > SWIPE_DISTANCE_THRESHOLD && Math.abs(velocityX) > SWIPE_VELOCITY_THRESHOLD) {
if (dX > 0) {
if (horizontalListener != null)
return horizontalListener.onSwipeRight();
}
else {
if (horizontalListener != null)
return horizontalListener.onSwipeLeft();
}
}
else if (Math.abs(dY) > Math.abs(dX) && Math.abs(dY) > SWIPE_DISTANCE_THRESHOLD && Math.abs(velocityY) > SWIPE_VELOCITY_THRESHOLD) {
if (dY > 0) {
if (verticalListener != null)
return verticalListener.onSwipeDown();
}
else {
if (verticalListener != null)
return verticalListener.onSwipeUp();
}
}
return false;
}
}
}