Skip to content

Instantly share code, notes, and snippets.

@gavingt
Created March 31, 2019 15:43
Show Gist options
  • Save gavingt/3ab312979d105b8bd71829bc219512a3 to your computer and use it in GitHub Desktop.
Save gavingt/3ab312979d105b8bd71829bc219512a3 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());
}
@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
return mDetector.onTouchEvent(ev);
}
@Override
public boolean onTouchEvent(MotionEvent ev) {
mDetector.onTouchEvent(ev);
return true;
}
}
// 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 onScroll(MotionEvent e1, MotionEvent e2,
float distanceX, float distanceY) {
Log.i("TAG", "onScroll: ");
return true;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment