【转】网页 网站 html如何实现"关闭窗口"代码大全/今日军事新闻头条最新
(1)Gsensor的注册和监听
App -->I2C过程:App通过SensorManager.getSystemServer调用到SystemSensorManager,SystemSensorManager通过jni调用到SensorManager.cpp,后通过binder调用到SensorService。SensorService通过SystemServer启动,后调用到hal kernel。
I2C -->App过程:通过JNI调用到SystemSensorManager中的SensorEventQueue.dispatchSensorEvent,然后通过App向SensorEventQueue注册的mListener,来回调数据到App的onSensorChanged()方法。
(网图)
//frameworks/base/core/java/android/hardware/SensorManager.javapublic boolean registerListener(SensorEventListener listener, Sensor sensor,int samplingPeriodUs) {return registerListener(listener, sensor, samplingPeriodUs, null);}public boolean registerListener(SensorEventListener listener, Sensor sensor,int samplingPeriodUs, int maxReportLatencyUs) {int delay = getDelay(samplingPeriodUs);return registerListenerImpl(listener, sensor, delay, null, maxReportLatencyUs, 0);}public boolean registerListener(SensorEventListener listener, Sensor sensor,int samplingPeriodUs, Handler handler) {int delay = getDelay(samplingPeriodUs);return registerListenerImpl(listener, sensor, delay, handler, 0, 0);}public boolean registerListener(SensorEventListener listener, Sensor sensor,int samplingPeriodUs, int maxReportLatencyUs, Handler handler) {int delayUs = getDelay(samplingPeriodUs);return registerListenerImpl(listener, sensor, delayUs, handler, maxReportLatencyUs, 0);}/** @hide */
protected abstract boolean registerListenerImpl(SensorEventListener listener, Sensor sensor,int delayUs, Handler handler, int maxReportLatencyUs, int reservedFlags);
registerListenerImpl的具体实现如下:
//frameworks/base/core/java/android/hardware/SystemSensorManager.javapublic class SystemSensorManager extends SensorManager {protected boolean registerListenerImpl(SensorEventListener listener, Sensor sensor,int delayUs, Handler handler, int maxBatchReportLatencyUs, int reservedFlags) {//...synchronized (mSensorListeners) {SensorEventQueue queue = mSensorListeners.get(listener);if (queue == null) {Looper looper = (handler != null) ? handler.getLooper() : mMainLooper;final String fullClassName =listener.getClass().getEnclosingClass() != null? listener.getClass().getEnclosingClass().getName(): listener.getClass().getName();//这里创建SensorEventQueue,并调用addSensor进而调用addSensorEvent函数queue = new SensorEventQueue(listener, looper, this, fullClassName);if (!queue.addSensor(sensor, delayUs, maxBatchReportLatencyUs)) {queue.dispose();return false;}mSensorListeners.put(listener, queue);return true;} else {return queue.addSensor(sensor, delayUs, maxBatchReportLatencyUs);}}}
}
接下来我们看一下SensorEventQueue队列
static final class SensorEventQueue extends BaseEventQueue {private final SensorEventListener mListener;private final SparseArray<SensorEvent> mSensorsEvents = new SparseArray<SensorEvent>();public SensorEventQueue(SensorEventListener listener, Looper looper,SystemSensorManager manager, String packageName) {super(looper, manager, OPERATING_MODE_NORMAL, packageName);//App传过来的监听器进行赋值mListener = listener;}@Overridepublic void addSensorEvent(Sensor sensor) {SensorEvent t = new SensorEvent(Sensor.getMaxLengthValuesArray(sensor,mManager.mTargetSdkLevel));synchronized (mSensorsEvents) {mSensorsEvents.put(sensor.getHandle(), t);}}@Overridepublic void removeSensorEvent(Sensor sensor) {synchronized (mSensorsEvents) {mSensorsEvents.delete(sensor.getHandle());}}// Called from native code.@SuppressWarnings("unused")@Override//在addSensorEvent put事件后,通过mSensorsEvents.get获取事件,然后通过mListener分发,这里的mListener就是App传过来的监听接口protected void dispatchSensorEvent(int handle, float[] values, int inAccuracy,long timestamp) {final Sensor sensor = mManager.mHandleToSensor.get(handle);if (sensor == null) {// sensor disconnectedreturn;}SensorEvent t = null;synchronized (mSensorsEvents) {t = mSensorsEvents.get(handle);}//...//这里会回调注册过的监听器的onSensorChangedmListener.onSensorChanged(t);}}
后续文章所提及的屏幕旋转方向等都和这里事件分发相关。
(2)应用注册屏幕旋转事件监听
应用注册使用,通过enable和disable来控制注册和取消注册
private class OrientationEventListenerImpl extends OrientationEventListener {public OrientationEventListenerImpl(Context context) {super(context);}@Overridepublic void onOrientationChanged(int orientation) {if (orientation == ORIENTATION_UNKNOWN) {return;}//...}}mOrientationListener.enable();
mOrientationListener.disable();
如下为系统代码
//frameworks/base/core/java/android/view/OrientationEventListener.javapublic abstract class OrientationEventListener {public OrientationEventListener(Context context) {this(context, SensorManager.SENSOR_DELAY_NORMAL);}public OrientationEventListener(Context context, int rate) {mSensorManager = (SensorManager)context.getSystemService(Context.SENSOR_SERVICE);mRate = rate;mSensor = mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);if (mSensor != null) {// Create listener only if sensors do existmSensorEventListener = new SensorEventListenerImpl();}}public void enable() {if (mSensor == null) {Log.w(TAG, "Cannot detect sensors. Not enabled");return;}if (mEnabled == false) {if (localLOGV) Log.d(TAG, "OrientationEventListener enabled");mSensorManager.registerListener(mSensorEventListener, mSensor, mRate);mEnabled = true;}}public void disable() {if (mSensor == null) {Log.w(TAG, "Cannot detect sensors. Invalid disable");return;}if (mEnabled == true) {if (localLOGV) Log.d(TAG, "OrientationEventListener disabled");mSensorManager.unregisterListener(mSensorEventListener);mEnabled = false;}}class SensorEventListenerImpl implements SensorEventListener {private static final int _DATA_X = 0;private static final int _DATA_Y = 1;private static final int _DATA_Z = 2;public void onSensorChanged(SensorEvent event) {float[] values = event.values;int orientation = ORIENTATION_UNKNOWN;float X = -values[_DATA_X];float Y = -values[_DATA_Y];float Z = -values[_DATA_Z]; float magnitude = X*X + Y*Y;// Don't trust the angle if the magnitude is small compared to the y valueif (magnitude * 4 >= Z*Z) {float OneEightyOverPi = 57.29577957855f;float angle = (float)Math.atan2(-Y, X) * OneEightyOverPi;orientation = 90 - (int)Math.round(angle);// normalize to 0 - 359 rangewhile (orientation >= 360) {orientation -= 360;} while (orientation < 0) {orientation += 360;}}if (mOldListener != null) {mOldListener.onSensorChanged(Sensor.TYPE_ACCELEROMETER, event.values);}if (orientation != mOrientation) {mOrientation = orientation;//回调函数onOrientationChanged(orientation);}}//回调函数public void onAccuracyChanged(Sensor sensor, int accuracy) {}}
}
相关文章:

Android屏幕旋转流程(1)
(1)Gsensor的注册和监听 App -->I2C过程:App通过SensorManager.getSystemServer调用到SystemSensorManager,SystemSensorManager通过jni调用到SensorManager.cpp,后通过binder调用到SensorService。SensorService通…...

JS常见的运算符有哪些?
在JavaScript中,常见的运算符可以分为以下几类: 算术运算符: :加法-:减法*:乘法/:除法%:取余(模运算):递增--:递减**:幂运…...

【scikit-learn入门指南】:机器学习从零开始
1. 简介 scikit-learn是一款用于数据挖掘和数据分析的简单高效的工具,基于NumPy、SciPy和Matplotlib构建。它能够进行各种机器学习任务,如分类、回归和聚类。 2. 安装scikit-learn 在开始使用scikit-learn之前,需要确保已经安装了scikit-le…...

MEMS:Lecture 17 Noise MDS
讲义 Minimum Detectable Signal (MDS) Minimum Detectable Signal(最小可检测信号)是指当信号-噪声比(Signal-to-Noise Ratio, SNR)等于1时的输入信号水平。简单来说,MDS 是一个系统能够分辨出信号存在的最低输入信号…...

Windows运维:找到指定端口的服务
运维过windows的或多或少都遇到过需要找到一个端口对应的服务,或者是因为端口占用,或者是想看下对应的服务是哪个,那么如何操作呢?看看本文吧。 1、按照端口找到进程ID 例如想找8000端口的进程ID netstat -ano | findstr :8000 2…...

Linux文件系统讲解!
一、Linux文件系统历史 1、在早期的时候Linux各种不同发行版拥有自己各自自定义的文件系统层级结构。 2、当我用Red hat转向玩Debian时,我进入/etc我都是懵的。 3、后来Linux社区做了一个标准、FHS(文件系统标准层次结构)。来帮助Linux系统的…...

mysql集群,两主两从,使用mysql-proxy实现读写分离
主从复制 一、IP规划 服务器IP备注master1192.168.100.131master2的从master2192.168.100.132master1的从slave1192.168.100.134slave1的从slave2192.168.100.135slave2的从mysql-proxy192.168.100.137 二、具体配置 1.master1 配置ip:192.168.100.131 …...

Linux文本处理三剑客+正则表达式
Linux文本处理常用的3个命令,脚本或者文本处理任务中会用到。这里做个整理。 三者的功能都是处理文本,但侧重点各不相同,grep更适合单纯的查找或匹配文本,sed更适合编辑匹配到的文本,awk更适合格式化文本,对…...

Linux启动KKfileview文件在线浏览时报错:启动office组件失败,请检查office组件是否可用
目录 1、导论 2、报错信息 3、问题分析 4、解决方法 4.1、下载 4.2、安装步骤 1、导论 今天进行项目部署时,遇到了一个问题。在启动kkfileview时,出现了报错异常: 2024-06-09 06:36:44.765 ERROR 1 --- [ main] cn.keking.service.Of…...

React <> </>的用法
React <> </>的用法 介绍为什么使用 <>?例子解释 关于顶级元素总结 介绍 在 React 中,使用 <> 表示一个空标签或片段(Fragment),这是一个简洁的方式来包裹一…...

is not null 、StringUtils.isNotEmpty和StringUtils.isNotBlank之间的区别?
这三者主要是针对对象是否为空、是否为空串和是否为空白字符串有不同的功能。 is not null 只是说明该对象不为空,没有考虑是否为空串和空白字符串。 StringUtils.isNotEmpty检查字符串是否不为 null且长度大于零,不考虑字符串中的空白字符。 StringU…...

Git使用-gitlab上面的项目如何整到本地的idea中
场景 一般我们在开发项目或者接手某个项目时,基本都要接触Git,比如上传项目代码,下载同事给你的交接代码等等。 这是一个基本功,小小整理一下日常操作中的使用。 第一步:在 GitLab 上找到你要克隆的项目,复…...

活体检验API在Java、Python、PHP中的使用教程
活体检验API是一种基于生物特征的身份验证技术,通过分析和识别用户的生物信息来确认其身份。这种技术广泛应用于各种领域,如金融、安全、社交媒体等,以提高身份验证的安全性和准确性。以下是描述”活体检验API”背景的一些关键点:…...

智能计算系统-概述
1、人工智能技术分层 2、人工智能方向人才培养 3、课程体系的建议 4、智能系统课程对学生的价值 5、智能计算系统对老师的价值 6、什么是智能计算系统 7、智能计算系统的形态 8、智能计算系统具有重大价值 9、智能计算系统的三大困难 10、开创深度学习处理器方向 11、寒武纪的国…...

SM5101 SOP-8 充电+触摸+发执丝控制多合一IC触摸打火机专用IC
SM5101 SOP-8 2.7V 涓流充电 具电池过充过放 触摸控制 发热丝电流控制多功能为一体专用芯片 昱灿-海川 SM5101 SOP-8 充电触摸发执丝控制多合一IC触摸打火机方案 !!! 简介: SM5101是一款针对电子点烟器的专用芯片,具…...

Mysql-题目02
下面列出的( DBMS )是数据库管理系统的简称。 A、DB(数据库) B、DBA C、DBMS(数据库管理系统) D、DBS(数据库系统) 以下选项中,( 概念模式 )面向数据库设计人员&…...

Swift开发——循环执行方式
本文将介绍 Swift 语言的循环执行方式 01、循环执行方式 在Swift语言中,主要有两种循环执行控制方式: for-in结构和while结构。while结构又细分为当型while结构和直到型while结构,后者称为repeat-while结构。下面首先介绍for-in结构。 循环控制方式for-in结构可用于区间中的…...

Navicat和SQLynx产品功能比较一(整体比较)
Navicat和SQLynx都是数据库管理工具,在过去的二十年中,国内用户主要是使用Navicat偏多,一般是个人简单开发需要,数据量一般不大,开发相对简单。SQLynx是最近几年的数据库管理工具,Web开发,桌面版…...

pip 配置缓存路径
在windows操作平台,默认情况,pip下使用的系统目录 C:\Users\用名名称\AppData\Local\pip C盘是系统盘,如果常常使用pip安装会占用大量的空间很快就满,这时候就有必要变更一下缓存保存路径了。 pip 配置缓存路径: Win…...

大数据开发语言Scala(一) - Scala入门
引言 在当今的大数据时代,数据量和数据处理的复杂性不断增加,传统的编程语言已经难以满足需求。Scala作为一门新兴的编程语言,以其简洁、强大和高效的特性,迅速成为大数据开发的热门选择。本文将详细介绍Scala语言的基础知识&…...

大模型中的计算精度——FP32, FP16, bfp16之类的都是什么???
大模型中的计算精度——FP32, FP16, bfp16之类的都是什么??? 这些精度是用来干嘛的??混合精度 mixed precision training什么是混合精度?怎么转换呢? 为什么大语言模型通常使用FP32精度训练量化…...

在矩池云使用GLM-4的详细指南(无感连GitHubHuggingFace)
GLM-4-9B 是智谱 AI 推出的最新一代预训练模型 GLM-4 系列中的开源版本,在多项测试中表现出超越已有同等规模开源模型的性能,它能兼顾多轮对话、网页浏览、代码执行、多语言、长文本推理等多种功能,性能更加强大。其多模态语言模型GLM-4V-9B在…...

大模型日报2024-06-15
大模型日报 2024-06-15 大模型资讯 新技术提升大型语言模型推理能力 摘要: 一种新技术使得像GPT-4这样的大型语言模型能够通过编写Python代码,更准确地解决数值或符号推理任务。 大型语言模型革命性提升蛋白质序列理解 摘要: 研究人员将蛋白质序列与自然语言进行类比…...

【YOLO系列】YOLOv1学习(PyTorch)原理加代码
论文网址:https://arxiv.org/pdf/1506.02640 训练集博客链接:目标检测实战篇1——数据集介绍(PASCAL VOC,MS COCO)-CSDN博客 代码文件:在我资源里,但是好像还在审核,大家可以先可以,如果没有的…...

Postman接口测试工具详解:揭秘API测试的终极利器
在现代软件开发中,API接口测试是确保应用程序质量和可靠性的重要环节。Postman,作为一款功能强大且用户友好的API测试工具,受到了广大开发者和测试人员的青睐。本文将详细解析Postman的功能和优势,带你领略这款工具的魅力。 一、…...

紫光展锐5G处理器T750__国产手机芯片5G方案
展锐T750核心板采用6nm EUV制程工艺,CPU架构采用了八核设计,其中包括两个主频为2.0GHz的Arm Cortex-A76性能核心和六个主频为1.8GHz的A55小核。这种组合使得T750具备卓越的处理能力,并能在节能的同时提供出色的性能表现。该核心模块还搭载了M…...

基于深度学习的红外船舶检测识别分类完整实现数据集8000+张
随着遥感技术的快速发展,包括无人机、卫星等,红外图像在船舶检测识别中的作用日益凸显。相对于可见光图像,红外图像具有在夜晚和恶劣天气条件下高效检测识别船舶的天然优势。近年来,深度学习作为一种强大的图像处理技术࿰…...

SpringCloud跨服务远程调用
随着项目的使用者越来越多,项目承担的压力也会越来越大,为了让我们的项目能服务更多的使用者,我们不得不需要把我们的单体项目拆分成多个微服务,就比如把一个商城系统拆分成用户系统,商品系统,订单系统&…...

postgres常用查询
一.字符串截取 left: 从左往右截取字符 right: 从右往左截取字符 如截取4个字符: SELECT left( column_name, 4 ) from table SELECT right( column_name, 4 ) from table 二.条件统计 COUNT(CASE WHEN column_name ‘value’ THEN 1 END) AS count_name 如截统计值1,值2的…...

JavaFX应用
JavaFX案例:集成进度条与后台任务 在这个示例中,我们将向JavaFX应用中集成一个进度条,用来展示一个模拟的后台任务的完成进度。这将涉及JavaFX的并发特性,特别是Task类和如何在UI线程安全地更新UI组件。 假设我们想要实现一个简…...