Skip to content

Instantly share code, notes, and snippets.

@gavingt
Last active March 31, 2019 13:12
Show Gist options
  • Save gavingt/20f01b93cd4ed36ff9b15330487b9d8d to your computer and use it in GitHub Desktop.
Save gavingt/20f01b93cd4ed36ff9b15330487b9d8d to your computer and use it in GitHub Desktop.
package appinventor.ai_GavinGT.DeliveryTipTrackerPro_ready_for_market.custom_classes;
import android.content.Context;
import android.util.AttributeSet;
import android.util.Log;
import android.view.GestureDetector;
import android.view.MotionEvent;
import android.widget.LinearLayout;
import androidx.annotation.Nullable;
public class MyLinearLayout extends LinearLayout {
GestureDetector mDetector;
public MyLinearLayout(Context context) {
super(context);
mDetector = new GestureDetector(context, new MyGestureListener());
}
public MyLinearLayout(Context context, @Nullable AttributeSet attrs) {
super(context, attrs);
mDetector = new GestureDetector(context, new MyGestureListener());
}
public MyLinearLayout(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
mDetector = new GestureDetector(context, new MyGestureListener());
}
public MyLinearLayout(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
}
@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
return mDetector.onTouchEvent(ev);
}
}
// In the SimpleOnGestureListener subclass you should override
// onDown and any other gesture that you want to detect.
class MyGestureListener extends GestureDetector.SimpleOnGestureListener {
@Override
public boolean onDown(MotionEvent event) {
Log.d("TAG","onDown: ");
// don't return false here or else none of the other
// gestures will work
return true;
}
@Override
public boolean onSingleTapConfirmed(MotionEvent e) {
Log.i("TAG", "onSingleTapConfirmed: ");
return true;
}
@Override
public boolean onScroll(MotionEvent e1, MotionEvent e2,
float distanceX, float distanceY) {
Log.i("TAG", "onScroll: ");
return true;
}
@Override
public boolean onFling(MotionEvent event1, MotionEvent event2,
float velocityX, float velocityY) {
Log.d("TAG", "onFling: ");
return true;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment