-
-
Notifications
You must be signed in to change notification settings - Fork 268
Usage
The way listeners are passed, registered and unregistered has been changed since version
1.4.0.
Sensey.getInstance().init(context);If you wish to alter the sampling period of data by Sensey, use the below init function
Sensey.getInstance().init(context,samplingPeriod)where samplingPeriod can be anyone from the below options
Sensey.SAMPLING_PERIOD_FASTESTSensey. SAMPLING_PERIOD_GAME-
Sensey. SAMPLING_PERIOD_NORMAL// Default Sensey. SAMPLING_PERIOD_UI
// *** IMPORTANT ***
// Stop Sensey and release the context held by it
Sensey.getInstance().stop();- Create an instance of ShakeListener
ShakeDetector.ShakeListener shakeListener=new ShakeDetector.ShakeListener() {
@Override public void onShakeDetected() {
// Shake detected, do something
}
@Override public void onShakeStopped() {
// Shake stopped, do something
}
};- Now to start listening for Shake gesture, pass the instance
shakeListenertostartShakeDetection()function
Sensey.getInstance().startShakeDetection(shakeListener);If you want to modify the threshold and time before declaring that shake gesture is stopped, use
Sensey.getInstance().startShakeDetection(threshold,timeBeforeDeclaringShakeStopped,shakeListener);- To stop listening for Shake gesture, pass the instance
shakeListenertostopShakeDetection()function
Sensey.getInstance().stopShakeDetection(shakeListener);- Create an instance of MovementListener
MovementDetector.MovementListener movementListener=new MovementDetector.MovementListener() {
@Override public void onMovement() {
// Movement detected, do something
}
@Override public void onStationary() {
// Movement stopped, do something
}
};- Now to start listening for Movement gesture, pass the instance
movementListenertostartMovementDetection()function
Sensey.getInstance().startMovementDetection(movementListener);If you want to modify the threshold and time before declaring that movement gesture is stopped, use
Sensey.getInstance().startMovementDetection(threshold,timeBeforeDeclaringStationary,movementListener);- To stop listening for Movement gesture, pass the instance
movementListenertostopMovementDetection()function
Sensey.getInstance().stopMovementDetection(movementListener);- Create an instance of PickupDeviceListener
PickupDeviceDetector.PickupDeviceListener pickupDeviceListener = new PickupDeviceDetector.PickupDeviceListener() {
@Override
public void onDevicePickedUp() {
// Device picked up
}
@Override
public void onDevicePutDown() {
// Device put down
}
};- Now to start listening for PickupDevice gesture, pass the instance
pickupDeviceListenertostartPickupDeviceDetection()function
Sensey.getInstance().startPickupDeviceDetection(pickupDeviceListener);- To stop listening for PickupDevice gesture, pass the instance
pickupDeviceListenertostopPickupDeviceDetection()function
Sensey.getInstance().stopPickupDeviceDetection(pickupDeviceListener);- Create an instance of ScoopListener
ScoopDetector.ScoopListener scoopListener=new ScoopDetector.ScoopListener() {
@Override
public void onScooped() {
// Scoop gesture detected, do something
}
};- Now to start listening for Scoop gesture, pass the instance
scoopListenertostartScoopDetection()function
Sensey.getInstance().startScoopDetection(scoopListener);- To stop listening for Scoop gesture, pass the instance
scoopListenertostopScoopDetection()function
Sensey.getInstance().stopScoopDetection(scoopListener);- Create an instance of ScoopListener
StepListener stepListener= new StepListener() {
@Override
public void stepInformation(final int noOfSteps,
final float distanceInMeter,
final int stepActivityType) {
// Steps are detected
String typeOfActivity;
switch (stepActivityType) {
case StepDetectorUtil.ACTIVITY_RUNNING:
// Running;
break;
case StepDetectorUtil.ACTIVITY_WALKING:
// Walking;
break;
default:
// Not moving, still;
break;
}
}
};- Now to start listening for Steps, pass the instance
stepListenertostartStepDetection()function
Sensey.getInstance().startStepDetection(context, stepListener, StepDetectorUtil.MALE);where
StepDetectorUtilhas 2 possible valuesMALEandFEMALEas the third argument.
- To stop listening for Steps, pass the instance
stepListenertostopStepDetection()function
Sensey.getInstance().stopStepDetection(stepListener);- Create an instance of ChopListener
ChopDetector.ChopListener chopListener=new ChopDetector.ChopListener() {
@Override public void onChop() {
// Chop gesture detected, do something
}
};- Now to start listening for Chop gesture, pass the instance
chopListenertostartChopDetection()function
Sensey.getInstance().startChopDetection(chopListener);If you want to modify the threshold and time for chop gesture, use
Sensey.getInstance().startChopDetection(threshold,timeForChopGesture,chopListener);- To stop listening for Chop gesture, pass the instance
chopListenertostopChopDetection()function
Sensey.getInstance().stopChopDetection(chopListener);- Create an instance of WristTwistListener
WristTwistDetector.WristTwistListener wristTwistListener=new WristTwistDetector.WristTwistListener() {
@Override public void onWristTwist() {
// Wrist Twist gesture detected, do something
}
};- Now to start listening for Wrist Twist gesture, pass the instance
wristTwistListenertostartWristTwistDetection()function
Sensey.getInstance().startWristTwistDetection(wristTwistListener);If you want to modify the threshold and time for wrist twist gesture, use
Sensey.getInstance().startWristTwistDetection(threshold,timeForWristTwistGesture,wristTwistListener);- To stop listening for Wrist Twist gesture, pass the instance
wristTwistListenertostopWristTwistDetection()function
Sensey.getInstance().stopWristTwistDetection(wristTwistListener);- Create an instance of SoundLevelListener
SoundLevelDetector.SoundLevelListener soundLevelListener=new SoundLevelDetector.SoundLevelListener() {
@Override public void onSoundDetected(float level) {
//Sound Level in dB is detected, do something
}
};- Now to start listening for Sound Level, pass the instance
soundLevelListenertostartSoundLevelDetection()function
Sensey.getInstance().startSoundLevelDetection(soundLevelListener);- To stop listening for Sound Level, pass the instance
soundLevelListenertostopSoundLevelDetection()function
Sensey.getInstance().stopSoundLevelDetection(soundLevelListener);- 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
flipListenertostartFlipDetection()function
Sensey.getInstance().startFlipDetection(flipListener);- To stop listening for Flip gesture, pass the instance
flipListenertostopFlipDetection()function
Sensey.getInstance().stopFlipDetection(flipListener);- Create an instance of RotationAngleListener
RotationAngleDetector.RotationAngleListener rotationAngleListener =new RotationAngleDetector.RotationAngleListener() {
@Override
public void onRotation(float angleInAxisX, float angleInAxisY, float angleInAxisZ) {
// Do something with the angles, values are in degrees
}
};- Now to start listening for RotationAngle gesture, pass the instance
rotationAngleListenertostartRotationAngleDetection()function
Sensey.getInstance().startRotationAngleDetection(rotationAngleListener);- To stop listening for RotationAngle gesture, pass the instance
rotationAngleListenertostopRotationAngleDetection()function
Sensey.getInstance().stopRotationAngleDetection(rotationAngleListener);- Create an instance of TiltDirectionListener
TiltDirectionDetector.TiltDirectionListener tiltDirectionListener=new TiltDirectionDetector.TiltDirectionListener() {
@Override
public void onTiltInAxisX(int direction) {
// Do something with tilt direction on x-axis
}
@Override
public void onTiltInAxisY(int direction) {
// Do something with tilt direction on y-axis
}
@Override
public void onTiltInAxisZ(int direction) {
// Do something with tilt direction on z-axis
}
};where direction can have either of the value:TiltDirectionDetector.DIRECTION_CLOCKWISE or TiltDirectionDetector.DIRECTION_ANTICLOCKWISE
- Now to start listening for TiltDirection gesture, pass the instance
TiltDirectionListenertostartTiltDirectionDetection()function
Sensey.getInstance().startTiltDirectionDetection(TiltDirectionListener);- To stop listening for TiltDirection gesture, pass the instance
TiltDirectionListenertostopTiltDirectionDetection()function
Sensey.getInstance().stopTiltDirectionDetection(TiltDirectionListener);- 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
orientationListenertostartOrientationDetection()function
Sensey.getInstance().startOrientationDetection(orientationListener);- To stop listening for Orientation gesture, pass the instance
orientationListenertostopOrientationDetection()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
proximityListenertostartProximityDetection()function
Sensey.getInstance().startProximityDetection(proximityListener);- To stop listening for Orientation gesture, pass the instance
proximityListenertostopProximityDetection()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
waveListenertostartWaveDetection()function
Sensey.getInstance().startWaveDetection(waveListener);- To stop listening for Wave gesture, pass the instance
waveListenertostopWaveDetection()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
lightListenertostartLightDetection()function
Sensey.getInstance().startLightDetection(lightListener);- To stop listening for Orientation gesture, pass the instance
lightListenertostopLightDetection()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
pinchScaleListenertostartPinchScaleDetection()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 fingers single tap
}
@Override public void onThreeFingerSingleTap() {
// Three fingers 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
touchTypListenertostartTouchTypeDetection()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