Android Focus小结

Android 12 input子系统梳理12 -- Input ANR -- focus event ANR 问题 (可参见ANR专题,这里附上一个blog link) https://www.jianshu.com/p/b8b35d3ee052 一句话,ANR是在native层InputDispatcher里埋雷并捕获,通过jni通知到java层。 https://zhuanlan.zhihu.com/p/53331495?from_voters_page=true 这里简单分析一个Focus event ANR。 Line 520288: 09-01 13:53... 阅读详情

Android Focus的管理

本篇题目是“Android Focus管理”,内容包括Input focus和Accessibility focus。
文章大纲:

  • focus的分类

  • Input focus
    window focus的控制逻辑

    window内view focus的控制逻辑
    touch mode如何发生变化,发生变化后对view的影响,比如已经highlight的UI是否会清除?

  • Accessibility focus
    哪些内容?

Touch mode: Touch mode 下,大部分view是不需要有focus 效果的;很多view也不愿意在touch mode下设置为focusable。

1. Focus

类型Input FocusAccessibility Focus
定义用于标识当前接收用户输入(如键盘、方向键)的视图。无障碍服务(如屏幕阅读器)用于标识当前正在操作的界面元素,帮助残障用户感知界面内容
用户群体所有用户。主要服务于残障用户(如视力障碍)。
触发方式用户点击、键盘导航、代码设置。无障碍服务手势(如 TalkBack 的滑动导航)。
可见性可能伴随光标或高亮效果。通常通过无障碍服务的高亮框或语音反馈体现。

2. Input Focus

  • 由系统或开发者直接控制,通过 View.requestFocus() 设置。
    setFocusable: view是否可以收到焦点。
    setFocusableInTouchMode(…) 这个view在touch mode是否可以收到焦点。
  • 通过 View.isFocused() 判断是否获得焦点。
  • 直接影响用户输入事件(如键盘输入、方向键导航)。

Input focus会影响Key event的派发,可以分为两个层级来理解:

  1. Window 层级,Input 模块在派发key event时会找到focused window
  2. View 层级,ViewRootImpl接收到Input 模块派发给的key event后,在View hierarchy中找到focused view,将event派发给它
    View对象作为view hierarchy中的一员,持有焦点时:
    • event派发时可以找到它
    • 为了用户容易注意到它,highlight的UI效果是有必要的

Q:Focus是怎么在不同window之间转移的?
A: DisplayContent中的findFocusedWindowIfNeeded(int topFocusedDisplayId)方法用于查找focused window,查找的具体逻辑在lamda function mFindFocusedWindow中,updateFocusedWindowLocked(...)方法会调用findFocusedWindowIfNeeded(int topFocusedDisplayId)方法,找到focused window后会更新mCurrentFocus,mCurrentFocus是一个WindowState类型的包内可见全局变量。InputMonitor的updateInputFocusRequest(...)方法会用到该变量,将window相关信息设置到input module。Input module会上报FOCUS event给ViewRootImpl通知Window focus发生了变化,继而处理view hierarchy内focus的逻辑,比如 focus清理逻辑,旧UI hightlight 效果清除和新UI highlight 绘制等。DisplayContent方法的调用触发场景很多,调用代码也有多处;ActiviytRecord,ActivityTaskManagerService,RootWindowContainer,WindowManagerService,WindowState和WindowToken都有调用。

关注InputDispatcher中的如下两个Event:

  • EventEntry::Type::FOCUS
    通知ViewRootImpl, window Focus发生了变化
  • EventEntry::Type::TOUCH_MODE_CHANGED
    通知ViewRootImpl,touch mode发生了变化

View.java中的requestFocus()方法
View.java中requestFocus()方法会触发其parent的requestChildFocus(...)方法,最终会调用到ViewRootImpl的requestChildFocus(...)方法,继而会调用performTraversals()方法,该方法会把measuge, relayout和draw都执行一遍,在这个过程中focused window会通知到input module。

view调用requestFocus申请焦点,如果成功拿到焦点会发送sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_FOCUSED);

InputDispatcher中的几个方法的调用:

  1. setFocusedWindow(…)
    该方法调用的路径有很多,把能看懂或者比较明显可能触发的操作总结如下:
  • WindowManagerService中的relayoutWindow(...) 方法可能会触发
  • WindowManagerService中的addWindow() 方法可能会触发
SurfaceComposerClientandroid_view_surfaceControlSurfaceControl#TransactionInputMonitor#UpdateInputForAllWindowsConsumerInputMonitorDisplayContentRootWindowContainerWindowManagerServiceXSurfaceComposerClientandroid_view_surfaceControlSurfaceControl#TransactionInputMonitor#UpdateInputForAllWindowsConsumerInputMonitorDisplayContentRootWindowContainerWindowManagerServiceXActivityRecord,ActivityTaskManagerService, WindowState和 RootWindowContainer等都可能会调用该方法mCurrentFocus = newFocus该方法调用的地方很多:Transaction: mInputWindowCommands.focusRequests.push_back(request)opt[updateInputWindows]updateFocusedWindowLocked(int mode, boolean updateInputWindows))updateFocusedWindowLocked(int mode, boolean updateInputWindows))updateFocusedWindowLocked(int mode, boolean updateInputWindows))setInputFocusLw(int mode, boolean updateInputWindows))updateInputWindowsLw(false)scheduleUpdateInputWindows()updateInputWindows(...)updateInputFocusRequest(...)requestFocus(...)setFocusedWindow(...)nativeSetFocusedWindow(...):Transaction:setFocusedWindow(...)
ViewRootImplWindowInputEventReceiverInputChannelInputPublisherInputDispatcherInputManagerSurfaceFlingerSchedulerHandler$MessageQueueViewRootImplWindowInputEventReceiverInputChannelInputPublisherInputDispatcherInputManagerSurfaceFlingerSchedulerHandler$MessageQueueEventEntry::Type::FOCUS中间省略了几个方法InputTransport.cppInputMessage::Type::FOCUSViewRootImpl的内部类onFrameSignal(...)commit(...)updateInputFlinger(...)setFocusedWindow(...)setFocusedWindow(...)enqueueFocusEventLocked(...)dispatchFocusLocked(...)dispatchEventLocked(...)startDispatchCycleLocked(...)publishFocusEvent(...)sendMessage(...)onFocusEvent(...)windowFocusChanged(bool hasFocus)
  1. setInputWindowsLocked(…)
    根据该方法的注释,该方法会从InputManagerService中被调用,但是从source code 中并未从InputManagerService中发现相关code。在InputDispatcher内部有调用。

  2. onWindowInfosChanged(…)

InputDispatcherDispatcherWindowListener$InputDispatcherWindowInfosListenerInvokerSurfaceFlingerSchedulerHandler$MessageQueueInputDispatcherDispatcherWindowListener$InputDispatcherWindowInfosListenerInvokerSurfaceFlingerSchedulerHandler$MessageQueue继承了android::impl::MessageQueueSurfaceFlinger的initScheduler方法构造了Scheduler 对象onFrameSignal(...)commit(...)updateInputFlinger(...)windowInfosChanged(gui::WindowInfosUpdate update, reportedListeners, forceImmediateCall)onWindowInfosChanged(const gui::WindowInfosUpdate& update)onWindowInfosChanged(update)setInputWindowsLocked(windowInfoHandles, displayId)
  1. setFocusedApplication
    Java层调用DisplayContent.java中的setFocusedApp(...) 方法可以更新Input 模块中的mFocucusedApplicationHandlesByDisplay中的值,在派发Key event时该变量会被用到,处理ANR相关逻辑。
InputDispatcherInputManagerServiceInputMonitorDisplayContentXInputDispatcherInputManagerServiceInputMonitorDisplayContentXActivityRecord.java, ActivityTaskManagerService.java, Task.java, TaskFragment.java和WindowOrganizerController.java都会调用该方法update mFocusedApplicationHandlesByDisplaysetFocusedApp(ActivityRecord newFocus)setFocusedAppLw(newFocus)setFocusedApplication(displayId, applicationHandle)setFocusedApplication(displayId, applicationHandle)setFocusedApplicationLocked(displayId, applicationHandle)

打开input cycle的log
在’frameworks/native/services/inputfliger/dispatcher/DebugConfig.h‘中介绍了打开不同input log的方式,下面是一个例子:

adb shell setprop persist.log.tag.InputDispatcherDispatchCycle D

不过有次尝试不成功,没去查证为什么,deepseek 给了下面的命令,倒是起作用了:

adb shell setprop persist.log.tag.InputDispatcher DEBUG
adb shell setprop persist.log.tag.InputDispatcher VERBOSE

打开input trace

# 启用 INPUT 标签(0x80)
adb shell setprop debug.atrace.tags.enableflags 0x80

# 启动跟踪(需要 root 或 userdebug 设备)
adb shell cmd stats print-logs

# 开始记录跟踪数据(保存到 /data/local/tmp/input_trace)
adb shell atrace --async_start -b 4096 input

# 停止跟踪
adb shell atrace --async_stop > /data/local/tmp/input_trace

# 导出到本地
adb pull /data/local/tmp/input_trace .

# 使用 Perfetto 打开跟踪文件
https://ui.perfetto.dev/

InputDispatcher在派发motion 时,依照前后顺序-from front to back 确认window是否可以接受该event:

  1. window没有FLAG_NOT_TOUCHABLE flag
    FLAG_NOT_TOUCH_MODAL:允许将其window范围外的pointer event(比如,touch screen)派发给其后面的window。
    FLAG_NOT_FOCUSABLE:表明window不take input focus,用户发的key或者button event会给后面可以take input focus的window。这个flag会enable FLAG_NOT_TOUCH_MODAL
    FLAG_NOT_TOUCHABLE: 表明window不能接收touch events,以便将touch events留给它后面(z order)的window。
  2. window的touchable region包含当前motion event的坐标

3.Accessibility Focus

  • 由无障碍服务(如 TalkBack)独立管理。
  • 通过 AccessibilityNodeInfo 的isAccessibilityFocused() 判断。
  • 开发者可通过AccessibilityNodeInfo来让相应的View申请Accessibility focus
    accessibilityNodeInfo.performAction(ACTION_ACCESSIBILITY_FOCUS);
    

View.java内在处理该action时会调用requestAccessibilityFocus()方法来请求Accessibility focus。


frameworks/native/libs/gui/include/gui/WindowInfo.h

【Android 】零基础到飞升 | ScrollView(滚动条) 2.4.1 ScrollView(滚动条) 本节引言: 本节带来的是Android基本UI控件中的第十个:ScrollView(滚动条),或者我们应该叫他 竖直滚动条,对应的另外一个水平方向上的滚动条:HorizontalScrollView,先来一发官方文档 的链接:ScrollView,我们可以看到类的结构如下: 嘿嘿,原来是一个FrameLayout的容器,不过在他的基础上添加了滚动,允许显示的比实际多的内容! 另外,只能够往里面放置一个子元素,可以是单一的组件,又或者一个布局包裹着的复杂的层次结构 阅读详情

相关推荐

android 焦点事件

android中焦点事件源码,项目中经常会用到的。值得收藏下。资源共享!

Android和焦点相关的ANR

在android设备上和焦点相关的anr我认为有两种。

qq_41095045的博客 1871

Unity游戏开发客户端面经——网络(初级)

Unity游戏开发客户端面经 之 网络 篇

Sea3752的博客 1万+

Android 输入法窗口焦点获取流程(2) ,输入法窗口和应用窗口绑定

Android焦点流程

u010573857的博客 4780

Tessy单元测试软件安装与破解避坑指南(附个人使用路径设置详解)

本文详细介绍了Tessy单元测试软件的安装与配置全流程,包括系统需求、服务器连接设置、环境变量配置等关键步骤,帮助开发者避开常见陷阱。特别提供了个人使用路径设置详解,确保Tessy在嵌入式开发环境中高效运行,适用于汽车电子、工业控制等领域。

weixin_33709364的博客 346

YOLOv5 改进点总览:轻量化、高精度的背后有哪些魔改?

YOLOv5是由Ultralytics团队开发的高效目标检测模型,其核心改进包括:主干网络采用CSPDarknet53提升梯度传播效率;特征融合使用PANet增强小目标识别;输出结构采用解耦头设计优化定位和分类任务。此外,YOLOv5通过CIoU损失函数、Mosaic数据增强和SimOTA标签分配机制进一步提升性能。模型支持多种推理格式(ONNX/TensorRT等),并具备自动锚框匹配和多尺度训练功能,使其在轻量化(yolov5s仅7MB)与高性能(最高51.2% mAP)间取得平衡,但缺乏正式论文支撑是

guoguozgw的博客 1806

Android UI事件处理、focus处理

在Android平台上,捕获用户在界面上的触发事件有很多种方法,View类就提供这些方法。你在使用各种View视图来布局界面时,会发现几个公用的回调方法来捕捉有用的UI触发事件,当事件在某个View对象上被触发时,这些方法会被系统框架通过这个对象所调用,例如:当一个View(如一个Button)被点击,onTouchEvent()方法会在该对象上被调用,所以,为了捕获和处理事件,必须去继承某个类,

zeng622peng的专栏 3094

LSTM 怎么进行二维数据的输入呢

尽管LSTM并不天然地适用于处理图像、视频等二维数据,但通过时间序列化、卷积特征提取和双向LSTM等方法,我们可以将二维数据转化为适合LSTM输入的形式,从而利用LSTM的强大记忆能力和长期依赖学习能力对二维数据进行建模。未来的研究方向可以考虑将LSTM与其他模型结合,例如将LSTM与卷积神经网络(Convolutional Neural Network, CNN)结合,利用CNN提取图像的空间特征,然后利用LSTM学习时间序列的长期依赖;

xiamu_CDA的博客 1038

android 按钮焦点事件,Android焦点事件分发与传递机制

如果您对TouchEvent事件分发机制不太了解的,可以参考我的这篇文章——安卓TounchEvent事件分发机制。问题:TV端焦点满天飞,如何解决和处理?记得初入TV开发,以为很简单。TV的这些界面与布局太简单了,分分钟就可以把页面搭建出来,处理好,然后就没有然后了。。。。下面我们就从源码来带大家进行安卓TV焦点事件的传递这里先给出Android系统View的绘制流程:依次执行View类里面的如...

weixin_42099633的博客 592

802.1x之EAP-TLS测试方法

CA证书一般是由权威的认证机构发出,用来验证该机构签名的证书,持有CA证书的设备可以验证对端的证书是否由自己信任的机构颁发的。在我们内部使用证书时,我没可以自己充当CA认证机构,管理私钥和CA证书,使用他们签名服务器、客户端证书。2、使用证书请求文件server_csr.pem、CA私钥、CA公钥生成服务器证书(正常情况下自己不拥有CA私钥,是把证书请求文件发给认证机构,由认证机构返回证书)进行802.1x EAP-TLS认证时需要IPC、服务器分别存储CA证书、设备证书、私钥,通过交换证书实现身份验证。

写作是为了更好的思考 2164

嵌入式工程师必学(118):MCU的硬件定时器和中断

大多数微处理器都有一个或多个可编程硬件定时器,这些定时器包括对中断的支持。可以有不同类型的计时器,用于不同的应用程序。例如,LPC1768 具有四个 32 位通用定时器、一个看门狗定时器、一个重复中断定时器、一个系统滴答定时器、一个正交编码器接口、6 个 PWM 输出和一个支持中断的实时时钟。硬件定时器用于计时和计数作,允许处理器在 timer 进程运行时继续执行其他进程。硬件定时器是一种使用 clock 信号来增加 register 的电路。

码农17年的博客 211

Android Camera 使用小结

http://www.cnblogs.com/franksunny/archive/2011/11/17/2252926.html Android手机关于Camera的使用,一是拍照,二是摄像,由于Android提供了强大的组件功能,为此对于在Android手机系统上进行Camera的开发,我们可以使用两类方法:一是借助Intent和MediaSt...

aikb6223的博客 106

Cleo Synchronization接口任意文件读取漏洞CVE-2024-50623 附POC

微信公众号搜索:南风漏洞复现文库该文章 南风漏洞复现文库 公众号首发Cleo。

nnn2188185的博客 480

Android AudioFocus机制小结

abandonAudioFocus的flow /frameworks/base/services/core/java/com/android/server/audio/MediaFocusControl.java MediaFocusControl.java --> 这个类才是真正完成requestaudiofocus和abandonaudiofocus操作的 abandonAudioFo...

OneGit 1524

ABAP RAP 行为建模深入学习:从 Behavior Definition 到 Behavior Implementation 的完整实践指南

ABAP RAP开发指南:业务行为定义与实现 本文介绍SAP RAP框架中业务对象行为的开发方法: 分层设计 Behavior Definition声明业务能力(增删改查、校验、动作等) Behavior Implementation在ABAP类中编写具体逻辑 核心组件 使用BDL定义业务行为 通过FOR BEHAVIOR OF绑定行为池类(ABP) 在本地类实现校验/确定/动作逻辑 关键特性 支持managed/unmanaged两种实现模式 提供草稿表、并发控制等企业级功能 通过EML以别名访问实体 开

2007 年 ~ 2025 年,深耕 SAP 技术 18 年 414

WINCC7.3破解文件

WINCC7.3硬件够破解文件,有需要的下载!WINCC7.3硬件够破解文件,有需要的下载!

android 代码设置 键盘适应_H5 键盘兼容性小结

在 H5 项目中,我们会经常遇到页面中存在单个甚至多个 input/textarea 输入框与底部固定元素的布局情况。在 input/textarea 输入框获取焦点时,会自动触发键盘弹起,而键盘弹出在 ios 与 android 的 webview 中表现并非一致,同时当我们主动触发键盘收起时也同样存在差异化。而无论如何,我们希望功能流畅的同时,尽量保持用户体验的一致性,因此有了下面一系列兼容性...

weixin_30533933的博客 287

jre9下载 jdk9

(Java SE Runtime Environment 9.0) 9.0u175 官方最新版 【x86|x64】

android 键盘遮盖输入框_H5 键盘兼容性小结

在 H5 项目中,我们会经常遇到页面中存在单个甚至多个 input/textarea 输入框与底部固定元素的布局情况。在 input/textarea 输入框获取焦点时,会自动触发键盘弹起,而键盘弹出在 ios 与 android 的 webview 中表现并非一致,同时当我们主动触发键盘收起时也同样存在差异化。而无论如何,我们希望功能流畅的同时,尽量保持用户体验的一致性,因此有了下面一系列兼容性...

weixin_33427833的博客 393

假人有限元模型

假人模型,车辆碰撞假人有限元模型,适合做乘员安全的研究者利用

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

Android按键超时的ANR原理小结

1) 按键处理主要的功臣是WindowManagerService. mInputManager @WindowManagerService.java mInputManager = new InputManager(context, this);   @InputManager.java      public InputManager(Context context, W

wuhengde的专栏 8989

Readest 的 D-pad 空间导航架构:Android TV / 蓝牙遥控器与桌面键盘的无障碍导航实现

本篇技术指南围绕 Readest 中 D-pad(方向键/十字键)空间导航的实现展开,介绍其在 Android TV 蓝牙遥控器与桌面键盘场景下的架构设计、关键文件、核心实现原理,以及开发过程中踩过的 7 类典型坑位。读完本文,你将掌握 Readest 如何在"零第三方依赖"前提下,用两个同名 `useSpatialNavigation` Hook 分别支撑阅读器工具栏与书架网格的空间导航,理解

gitblog_00994的博客 857

camera_click,camera_focus无法客制化研究(一)

第一次尝试: 将二者放置在第三方 Y:\6592\alps\wingcust\wt98601\w98601c4\vendor\artifacts\out\target\product\wt98601\system\media\audio\ui下 会在编译preloader的时候,把它copy到system下去,可以使用./mk n pl来做验证; 但是在后续 Y:\659

973

html-docx-js 变更日志深度解读:从 0.1.0 到 0.3.1 的浏览器端 HTML 转 DOCX 技术演进

html-docx-js 是一个在浏览器端把完整 HTML 文档转换为 DOCX(Microsoft Word 2007 及以后版本使用的开放文档格式)的轻量级 JavaScript 库。本文以仓库根目录的 [CHANGELOG.md](https://link.gitcode.com/i/c8ba05b472bf6e7cbe5ae60f5869655b) 为版本演进骨架,逐条解读 0.1.0 →

gitblog_00043的博客 483

Android 中 KeyEvent keycode 配置 及 转换原理

添加自定义 KeyEvent 键值一、Kernel 修改1. 修改 input.h 添加keycode 定义 (16 进制)2. 修改 msm8909-mtp.dtsi 添加上报 (16 进制)二、Android 代码修改1. 修改 input-event-codes.h (16 进制)2. 修改 kl 文件(十进制)3. native 层 keycodes 重映射(十进制)3.1 修改 keyc...

|~~~热爱生活、努力学习的小伙汁~~~| 7973

h5如何动态获取键盘高度_H5 键盘兼容性小结

在 H5 项目中,我们会经常遇到页面中存在单个甚至多个 input/textarea 输入框与底部固定元素的布局情况。在 input/textarea 输入框获取焦点时,会自动触发键盘弹起,而键盘弹出在 ios 与 android 的 webview 中表现并非一致,同时当我们主动触发键盘收起时也同样存在差异化。而无论如何,我们希望功能流畅的同时,尽量保持用户体验的一致性,因此有了下面一系列兼容性...

weixin_42449311的博客 4892

Flutter 仓库 Android Agent:面向 Android 团队的专用 AI 代理配置与 Skills 机制解析

Flutter 主仓库的 `.agents` 目录下维护了一组面向不同团队的"人格化"AI 代理配置,其中 `android-agent` 是专为 Flutter 引擎与框架中 Android 相关代码(Java、Kotlin、Gradle 配置、Android SDK 交互、Android embedding 层)打造的专用代理。读完本文,你将理解 `android-agent` 的四个构成文件

gitblog_00358的博客 980

ScrollView 使用小结

忙忙碌碌的一个多月又结束了,连续奋战到凌晨四点的两周也成为了过去式….此次上线因为添加了视频直播和点播功能,所以比较赶,真是分分钟要猝死的赶脚.不过此次又是上线又是对旧知识的巩固和对新技术的探究,此次用到的ScrollView比较多,写一篇文章用以积累.从谷歌的文档我们可以得到ScrollView是一个可以滚动的用户布局容器,它可以让在手机屏幕上展示不开的情况下滚动展示。ScrollView是一个F

qq_35598366的博客 557

Android16 EDLA CtsWindowManagerDeviceInput存在fail方法 testReceiveKeysOnTopOfKeyguard和 testPointerCaptur

Android16 EDLA CtsWindowManagerDeviceInput测试失败分析 本文记录了Android16 EDLA版本中CtsWindowManagerDeviceInput测试项的两个失败案例及其解决方法: testReceiveKeysOnTopOfKeyguard失败原因: 与config.xml中config_disableLockscreenByDefault设置为true有关 系统不能设置默认不锁屏状态,否则会导致测试结果不符 testPointerCaptureWhenF

wenzhi的博客 1389
上一篇: Android graphics - 框架摘要
下一篇: Android Graphics - openGL and Vulkan小结
一只特立独行的Yang
博客等级 码龄12年 105粉丝 38原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值