鸿蒙开源组件——传感器封装

jacksky
发布于 2021-11-26 18:24
浏览
0收藏

鸿蒙开源组件——传感器封装-鸿蒙开发者社区sensey

项目介绍

  • 项目名称:sensey
  • 所属系列:openharmony 第三方组件适配移植
  • 功能:传感器封装
  • 项目移植状态:主功能完成
  • 调用差异:无 (TouchType中的onTwoFingerSingleTap、onThreeFingerSingleTap、onScroll、onSwipe功能尚未实现)
  • 开发版本:sdk6,DevEco Studio2.2 beta1
  • 基线版本:Release v1.9.0

效果演示鸿蒙开源组件——传感器封装-鸿蒙开发者社区

安装教程

1.在moudle级别下的build.gradle文件中添加依赖

// 添加maven仓库
repositories {
    maven {
        url 'https://s01.oss.sonatype.org/content/repositories/releases/'
    }
}

2.在entry模块的build.gradle文件中,

// 添加依赖库
dependencies {
    implementation 'com.gitee.chinasoft_ohos:sensey:1.0.1'   
}

如无法运行,删除项目.gradle,.idea,build,gradle,build.gradle文件, 并依据自己的版本创建新项目,将新项目的对应文件复制到根目录下

使用说明

Ohos library which makes playing with sensor events & detecting gestures a breeze.

The library is built for simplicity and ease of use. It eliminates most boilerplate code for dealing with setting up sensor based event and gesture detection on Ohos.

Supported gestures/events

Gesture Methods Usage
Flip onFaceUp
onFaceDown
Link
Light onDark
onLight
Link
Orientation onTopSideUp
onBottomSideUp
onLeftSideUp
onRightSideUp
Link
PinchScale onScale
onScaleStart
onScaleEnd
Link
Proximity onNear
onFar
Link
Shake onShakeDetected
onShakeStopped
Link
Wave onWave Link
Chop onChop Link
WristTwist onWristTwist Link
Movement onMovement
onStationary
Link
SoundLevel onSoundDetected Link
RotationAngle onRotation Link
TiltDirection onTiltInAxisX
onTiltInAxisY
onTiltInAxisZ
Link
Scoop onScooped Link
PickupDevice onDevicePickedUp
onDevicePutDown
Link
Steps stepInformation Link
TouchType onDoubleTap
onScroll(direction)
onSingleTap
onSwipeLeft
onSwipeRight
onLongPress
onTwoFingerSingleTap
onThreeFingerSingleTap
Link
  • Java 调用示例 **
  • To initialize Sensey under your onActive() in the ability/abilitySlice, call
    Sensey.getInstance().init(context);​
  • To stop Sensey, under your onInactive() in the ability/abilitySlice, call
     // *** IMPORTANT ***
     // Stop Sensey and release the context held by it
     Sensey.getInstance().stop();​
  • Next to enable shake detection
  • 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 shakeListener to startShakeDetection() 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 shakeListener to stopShakeDetection() function
    Sensey.getInstance().stopShakeDetection(shakeListener);​

测试信息

CodeCheck代码测试无异常
CloudTest代码测试无异常
安全病毒安全检测通过
当前版本demo功能与原组件基本无差异

版本迭代

  • 1.0.1

版权和许可信息

Licensed under the Apache License, Version 2.0, click here for the full license.

sensey-master.zip 36.25M 16次下载
已于2021-11-26 18:24:22修改
收藏
回复
举报
回复
    相关推荐