-
-
Notifications
You must be signed in to change notification settings - Fork 268
Usage
Nishant Srivastava edited this page Oct 15, 2016
·
15 revisions
The way listeners are passed,registered and unregistered has been changed since version
1.4.0
.
Sensey.getInstance().init(context);
- Create an instance of ShakeListener
ShakeDetector.ShakeListener shakeListener=new ShakeDetector.ShakeListener() {
@Override public void onShakeDetected() {
// Shake detected, do something
}
};
- Now to start listening for Shake gesture, pass the instance
shakeListener
tostartShakeDetection()
function
Sensey.getInstance().startShakeDetection(shakeListener);
If you want to modify the threshold
, pass an int
as value
Sensey.getInstance().startShakeDetection(threshold,shakeListener);
- To stop listening for Shake gesture, pass the instance
shakeListener
tostopShakeDetection()
function
Sensey.getInstance().stopShakeDetection(shakeListener);
- Create an instance of FlipListener
FlipDetector.FlipListener flipListener=new FlipDetector.FlipListener() {
@Override public void onFaceUp() {
// Device Facing up
}
@Override public void onFaceDown() {
// Device Facing down
}
};
- Now to start listening for Flip gesture, pass the instance
flipListener
tostartFlipDetection()
function
Sensey.getInstance().startFlipDetection(flipListener);
- To stop listening for Flip gesture, pass the instance
flipListener
tostopFlipDetection()
function
Sensey.getInstance().stopFlipDetection(flipListener);
- Create an instance of OrientationListener
OrientationDetector.OrientationListener orientationListener=new OrientationDetector.OrientationListener() {
@Override public void onTopSideUp() {
// Top side of device is up
}
@Override public void onBottomSideUp() {
// Bottom side of device is up
}
@Override public void onRightSideUp() {
// Right side of device is up
}
@Override public void onLeftSideUp() {
// Left side of device is up
}
};
- Now to start listening for Orientation gesture, pass the instance
orientationListener
tostartOrientationDetection()
function
Sensey.getInstance().startOrientationDetection(orientationListener);
- To stop listening for Orientation gesture, pass the instance
orientationListener
tostopOrientationDetection()
function
Sensey.getInstance().stopOrientationDetection(orientationListener);
- Create an instance of ProximityListener
ProximityDetector.ProximityListener proximityListener=new ProximityDetector.ProximityListener() {
@Override public void onNear() {
// Near to device
}
@Override public void onFar() {
// Far from device
}
};
- Now to start listening for Orientation gesture, pass the instance
proximityListener
tostartProximityDetection()
function
Sensey.getInstance().startProximityDetection(proximityListener);
- To stop listening for Orientation gesture, pass the instance
proximityListener
tostopProximityDetection()
function
Sensey.getInstance().stopProximityDetection(proximityListener);
- Create an instance of WaveListener
WaveDetector.WaveListener waveListener=new WaveDetector.WaveListener() {
@Override public void onWave() {
// Wave of hand gesture detected
}
};
- Now to start listening for Wave gesture, pass the instance
waveListener
tostartWaveDetection()
function
Sensey.getInstance().startWaveDetection(waveListener);
- To stop listening for Wave gesture, pass the instance
waveListener
tostopWaveDetection()
function
Sensey.getInstance().stopWaveDetection(waveListener);
- Create an instance of LightListener
LightDetector.LightListener lightListener=new LightDetector.LightListener() {
@Override public void onDark() {
// Dark
}
@Override public void onLight() {
// Not Dark
}
};
- Now to start listening for Orientation gesture, pass the instance
lightListener
tostartLightDetection()
function
Sensey.getInstance().startLightDetection(lightListener);
- To stop listening for Orientation gesture, pass the instance
lightListener
tostopLightDetection()
function
Sensey.getInstance().stopLightDetection(lightListener);
IMPORTANT : Implement this to intercept touch actions in activity by overriding the dispatchTouchEvent
.
@Override public boolean dispatchTouchEvent(MotionEvent event) {
// Setup onTouchEvent for detecting type of touch gesture
Sensey.getInstance().setupDispatchTouchEvent(event);
return super.dispatchTouchEvent(event);
}
- Create an instance of PinchScaleListener
PinchScaleDetector.PinchScaleListener pinchScaleListener=new PinchScaleDetector.PinchScaleListener() {
@Override public void onScale(ScaleGestureDetector scaleGestureDetector, boolean isScalingOut) {
if (isScalingOut) {
// Scaling Out;
} else {
// Scaling In
}
}
@Override public void onScaleStart(ScaleGestureDetector scaleGestureDetector) {
// Scaling Started
}
@Override public void onScaleEnd(ScaleGestureDetector scaleGestureDetector) {
// Scaling Stopped
}
};
- Now to start listening for PinchScale gesture, pass the instance
pinchScaleListener
tostartPinchScaleDetection()
function
Sensey.getInstance().startPinchScaleDetection(pinchScaleListener);
- To stop listening for PinchScale gesture, simply call
stopPinchScaleDetection()
function
Sensey.getInstance().stopPinchScaleDetection();
Don't forget to implement
dispatchTouchEvent()
as explained here
- Create an instance of TouchTypListener
TouchTypeDetector.TouchTypListener touchTypListener=new TouchTypeDetector.TouchTypListener() {
@Override public void onTwoFingerSingleTap() {
// Two finger single tap
}
@Override public void onThreeFingerSingleTap() {
// Three finger single tap
}
@Override public void onDoubleTap() {
// Double tap
}
@Override public void onScroll(int scrollDirection) {
switch (scrollDirection) {
case TouchTypeDetector.SCROLL_DIR_UP:
// Scrolling Up
break;
case TouchTypeDetector.SCROLL_DIR_DOWN:
// Scrolling Down
break;
case TouchTypeDetector.SCROLL_DIR_LEFT:
// Scrolling Left
break;
case TouchTypeDetector.SCROLL_DIR_RIGHT:
// Scrolling Right
break;
default:
// Do nothing
break;
}
}
@Override public void onSingleTap() {
// Single tap
}
@Override public void onSwipe(int swipeDirection) {
switch (swipeDirection) {
case TouchTypeDetector.SWIPE_DIR_UP:
// Swipe Up
break;
case TouchTypeDetector.SWIPE_DIR_DOWN:
// Swipe Down
break;
case TouchTypeDetector.SWIPE_DIR_LEFT:
// Swipe Left
break;
case TouchTypeDetector.SWIPE_DIR_RIGHT:
// Swipe Right
break;
default:
//do nothing
break;
}
}
@Override public void onLongPress() {
// Long press
}
};
- Now to start listening for TouchType gesture, pass the instance
touchTypListener
tostartTouchTypeDetection()
function
Sensey.getInstance().startTouchTypeDetection(touchTypListener);
- To stop listening for TouchType gesture, simply call
stopTouchTypeDetection()
function
Sensey.getInstance().stopTouchTypeDetection();
Don't forget to implement
dispatchTouchEvent()
as explained here