-
-
Notifications
You must be signed in to change notification settings - Fork 268
Usage
Nishant Srivastava edited this page Jun 24, 2016
·
15 revisions
- Initialize Sensey under your onCreate() in the activity/service
Sensey.getInstance().init(context);
-
Next to enable detection for
-
Shake
Sensey.getInstance().startShakeDetection(new ShakeDetector.ShakeListener() { @Override public void onShakeDetected() { // Shake detected, do something } });
If you want to modify the
threshold
, pass anint
as valueSensey.getInstance().startShakeDetection(threshold, new ShakeDetector.ShakeListener() { @Override public void onShakeDetected() { // Shake detected, do something } });
-
Flip
Sensey.getInstance().startFlipDetection(new FlipDetector.FlipListener() { @Override public void onFaceUp() { // Face up detected, do something } @Override public void onFaceDown() { // Face down detected, do something } });
-
Orientation
Sensey.getInstance().startOrientationDetection(new OrientationDetector.OrientationListener() { @Override public void onTopSideUp() { // Top side up detected, do something } @Override public void onBottomSideUp() { // Bottom side up detected, do something } @Override public void onRightSideUp() { // Right side up detected, do something } @Override public void onLeftSideUp() { // Left side up detected, do something } });
-
Proximity
Sensey.getInstance().startProximityDetection(new ProximityDetector.ProximityListener() { @Override public void onNear() { // Near, do something } @Override public void onFar() { // far, do something } });
-
Light
Sensey.getInstance().startLightetection(new LightDetector.LightListener() { @Override public void onDark() { // Dark } @Override public void onLight() { // Light } });
If you want to modify the
threshold
, pass anint
as valueSensey.getInstance().startLightetection(threshold,new LightDetector.LightListener() { @Override public void onDark() { // Dark } @Override public void onLight() { // Light } });
-
TouchType
Sensey.getInstance().startTouchTypeDetection(new TouchTypeDetector.TouchTypListener() { @Override public void onDoubleTap() { System.out.println("Double Tap"); } @Override public void onScroll(int scroll_dir) { switch (scroll_dir) { case TouchTypeDetector.SCROLL_DIR_UP: System.out.println("Scrolling Up"); break; case TouchTypeDetector.SCROLL_DIR_DOWN: System.out.println("Scrolling Down"); break; case TouchTypeDetector.SCROLL_DIR_LEFT: System.out.println("Scrolling Left"); break; case TouchTypeDetector.SCROLL_DIR_RIGHT: System.out.println("Scrolling Right"); break; } } @Override public void onSingleTap() { System.out.println("Single Tap"); } @Override public void onSwipeLeft() { System.out.println("Swipe Left"); } @Override public void onSwipeRight() { System.out.println("Swipe Right"); } @Override public void onLongPress() { System.out.println("Long press"); } }); // IMPORTANT : Implement this to intercept touch action in activity @Override public boolean dispatchTouchEvent(MotionEvent event) { // Setup onTouchEvent for detecting type of touch gesture Sensey.getInstance().setupDispatchTouchEvent(event); return super.dispatchTouchEvent(event); }
-
-
To disable detection for
- Shake
Sensey.getInstance().stopShakeDetection();
- Flip
Sensey.getInstance().stopFlipDetection();
- Orientation
Sensey.getInstance().stopOrientationDetection();
- Proximity
Sensey.getInstance().stopProximityDetection();
- Light
Sensey.getInstance().stopLightDetection();
- TouchType
Sensey.getInstance().stopTouchTypeDetection();