首页 文章 精选 留言 我的

精选列表

搜索[官方镜像],共10000篇文章
优秀的个人博客,低调大师

Android官方开发文档Training系列课程中文版:Activity测试之创建功能性测试

原文地址:http://android.xsoftlab.net/training/activity-testing/activity-functional-testing.html 功能性测试包括模拟用户操作之类的组件验证。例如开发者可以通过功能性测试来验证在用户执行了UI操作之后Activity是否启动了Activity。 如要为Activity创建功能性测试,测试类应当继承ActivityInstrumentationTestCase2。与ActivityUnitTestCase不同,ActivityInstrumentationTestCase2既可以与Android系统通信,又能使程序可以接收键盘输入事件与屏幕点击事件。 验证功能行为 一般功能性测试可能会有以下测试目的: 验证在某个UI控制器被按下后,目标Activity是否被启动。 验证目标Activity是否将在启动之前的用户输入数据正确显示。 开发者所实现的代码可能如下: @MediumTest public void testSendMessageToReceiverActivity() { final Button sendToReceiverButton = (Button) mSenderActivity.findViewById(R.id.send_message_button); final EditText senderMessageEditText = (EditText) mSenderActivity.findViewById(R.id.message_input_edit_text); // Set up an ActivityMonitor ... // Send string input value ... // Validate that ReceiverActivity is started ... // Validate that ReceiverActivity has the correct data ... // Remove the ActivityMonitor ... } 测试框架会等待ReceiverActivity启动,否则的话将会在超时后返回null。如果ReceiverActivity启动,那么ActivityMonitor则会收到一个命中。开发者可以通过断言方法来验证ReceiverActivity是否被启动,命中数是否会如所期望的那样有所增长。 设置ActivityMonitor 如果需要监视Activity,可以注册ActivityMonitor。当目标Activity启动时,系统会通知ActivityMonitor一个事件。如果目标Activity启动,那么ActivityMonitor的计数器则会更新。 一般使用ActivityMonitor应当执行以下步骤: 1.通过getInstrumentation()方法获得用于测试的Instrumentation实例。 2.通过Instrumentation的addMonitor()重载方法将Instrumentation.ActivityMonitor的实例添加到当前的instrumentation中,具体的匹配规则可由IntentFilter或者类名指定。 3.等待被监视的Activity启动。 4.验证监视器的数字增长。 5.移除监视器。 例如: // Set up an ActivityMonitor ActivityMonitor receiverActivityMonitor = getInstrumentation().addMonitor(ReceiverActivity.class.getName(), null, false); // Validate that ReceiverActivity is started TouchUtils.clickView(this, sendToReceiverButton); ReceiverActivity receiverActivity = (ReceiverActivity) receiverActivityMonitor.waitForActivityWithTimeout(TIMEOUT_IN_MS); assertNotNull("ReceiverActivity is null", receiverActivity); assertEquals("Monitor for ReceiverActivity has not been called", 1, receiverActivityMonitor.getHits()); assertEquals("Activity is of wrong type", ReceiverActivity.class, receiverActivity.getClass()); // Remove the ActivityMonitor getInstrumentation().removeMonitor(receiverActivityMonitor); 使用Instrumentation发送键盘事件 如果Activity含有EditText,可能需要测试用户是否可以对其输入数据。 一般来说,要发送字符串到EditText,应当: 1.在runOnMainSync()方法中运行requestFocus()同步方法,这样会使UI线程一直等待接收焦点。 2.调用waitForIdleSync()方法使主线程变为空闲状态。 3.通过sendStringSync()方法发送一条字符串给EditText。 例如: // Send string input value getInstrumentation().runOnMainSync(new Runnable() { @Override public void run() { senderMessageEditText.requestFocus(); } }); getInstrumentation().waitForIdleSync(); getInstrumentation().sendStringSync("Hello Android!"); getInstrumentation().waitForIdleSync();

优秀的个人博客,低调大师

Android官方开发文档Training系列课程中文版:后台加载数据之处理CursorLoader的查询结果

原文地址:http://android.xsoftlab.net/training/load-data-background/handle-results.html 就像上节课所说的,我们应该在onCreateLoader()内使用CursorLoader来加载数据。那么在数据加载完毕之后,加载结果会通过LoaderCallbacks.onLoadFinished()方法传回到实现类中。该方法的其中一个参数为包含查询结果的Cursor对象。你可以通过这个对象来更新UI数据或者用它来做进一步的操作。 除了onCreateLoader()及onLoadFinished()这两个方法之外,还应当实现onLoaderReset()方法。这个方法会在上面返回的Cursor对象所关联的数据发生变化时调用。如果数据发生了变化,那么Android框架会重新进行查询。 处理查询结果 为了显示Cursor对象中的数据,这里需要实现AdapterView的相关方法以及CursorAdapter的相关方法。系统会自动的将Cursor中的数据转换到View上。 你可以在展示数据之前将数据与Adapter对象进行关联,这样的话系统才会自动的更新View: public String[] mFromColumns = { DataProviderContract.IMAGE_PICTURENAME_COLUMN }; public int[] mToFields = { R.id.PictureName }; // Gets a handle to a List View ListView mListView = (ListView) findViewById(R.id.dataList); /* * Defines a SimpleCursorAdapter for the ListView * */ SimpleCursorAdapter mAdapter = new SimpleCursorAdapter( this, // Current context R.layout.list_item, // Layout for a single row null, // No Cursor yet mFromColumns, // Cursor columns to use mToFields, // Layout fields to use 0 // No flags ); // Sets the adapter for the view mListView.setAdapter(mAdapter); ... /* * Defines the callback that CursorLoader calls * when it's finished its query */ @Override public void onLoadFinished(Loader<Cursor> loader, Cursor cursor) { ... /* * Moves the query results into the adapter, causing the * ListView fronting this adapter to re-display */ mAdapter.changeCursor(cursor); } 移除旧的Cursor引用 CursorLoader会在Cursor处于无效状态时对其进行重置。这种事件会经常发生,因为Cursor所关联的数据会经常发生变化。在重新查询之前,系统会调用所实现的onLoaderReset()方法。在该方法内,应将当前Cursor的所持有的引用置空,以防止内存泄露。一旦onLoaderReset()方法执行完毕,CursorLoader就会重新进行查询。 /* * Invoked when the CursorLoader is being reset. For example, this is * called if the data in the provider changes and the Cursor becomes stale. */ @Override public void onLoaderReset(Loader<Cursor> loader) { /* * Clears out the adapter's reference to the Cursor. * This prevents memory leaks. */ mAdapter.changeCursor(null); }

优秀的个人博客,低调大师

Android官方开发文档Training系列课程中文版:键盘输入处理之指定输入的类型

原文地址:http://android.xsoftlab.net/training/keyboard-input/index.html 引言 在文本框接收到焦点时,Android系统会在屏幕上显示一个软键盘。为了提供良好的用户体验,你可以指定相关输入类型的特性,以及输入法应当如何展现。 除了屏幕上的软键盘之外,Android还支持实体键盘,所以APP如何与各种类型的键盘交互这件事情,就变得很重要了。 指定输入的类型 每一个文本框必定只有一种输入类型,比如一个电子邮件地址,一个电话号码或者是常规文本。所以为每一个文本框指定输入类型就变得很重要,这样的话系统才会显示正确的输入法。 你可以指定比如输入方法所提供的拼写建议、首字母大写、以及输入法右下角按钮的行为(Done或者Next)。这节课主要介绍如何指定这些特性。 指定键盘类型 你应该总是为文本框声明输入类型,通过android:inputType属性可以为文本框添加输入类型。 比如,如果你希望文本框的输入类型为电话号码,可以使用”phone”: <EditText android:id="@+id/phone" android:layout_width="fill_parent" android:layout_height="wrap_content" android:hint="@string/phone_hint" android:inputType="phone" /> 或者如果文本框主要是用于输入密码的,可以使用”textPassword”隐藏用户的输入文本: <EditText android:id="@+id/password" android:hint="@string/password_hint" android:inputType="textPassword" ... /> android:inputType含有多种指定的输入类型,并且一些值可以组合使用。 开启拼写检查与其它功能 android:inputType属性允许你可以为输入类型指定多种行为。更重要的一点是,如果文本框的重点在基础文本输入上(如文本消息),你应当使用”textAutoCorrect”开启拼写检查。 你还可以为android:inputType属性指定多种不同的行为以及输入类型。比如,下面的例子就展示了如何同时开启首字母大写以及拼写检查的功能: <EditText android:id="@+id/message" android:layout_width="wrap_content" android:layout_height="wrap_content" android:inputType= "textCapSentences|textAutoCorrect" ... /> 指定输入法按钮的行为 大多数的输入法都在右下角提供了一个用户功能按钮,这对于当前的文本框来说是极为恰当的。在默认情况下,系统使用这个按钮来实现Next或者Done功能。除非你的文本框允许多行情况的出现(比如使用了android:inputType=”textMultiLine”)。在这种情况下,该功能按钮是一个回车按钮。然而,你可以指定一些更加符合你文本框的特别功能,比如Send或Go。 为了指定键盘的功能按钮,需要使用属性android:imeOptions,并需要执行比如”actionSend”或”actionSearch”之类的值: <EditText android:id="@+id/search" android:layout_width="fill_parent" android:layout_height="wrap_content" android:hint="@string/search_hint" android:inputType="text" android:imeOptions="actionSend" /> 接下来可以通过TextView.OnEditorActionListener来监听功能按钮的按下事件,并需要在该监听器内响应正确的IME功能ID,该ID定义与EditorInfo中,比如下面使用的就是IME_ACTION_SEND: EditText editText = (EditText) findViewById(R.id.search); editText.setOnEditorActionListener(new OnEditorActionListener() { @Override public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { boolean handled = false; if (actionId == EditorInfo.IME_ACTION_SEND) { sendMessage(); handled = true; } return handled; } });

优秀的个人博客,低调大师

如果想从jenkins直接生成docker镜像,并推送到harbor中,最简单的脚本如何实现?

如果不考虑意外, 第一版最简单的构思如下: #!/usr/bin/env python # -*- coding: utf-8 -*- import getopt, sys import subprocess import os site_name = app_name = dep_version = war_name = "" docker_harbor_ip = "x.x.x.x" docker_login_name = "boss" docker_login_password = "client" #参数用法 def usage(): print "./docker.py -s site -a app -d dev --war=war_name" sys.exit() #获取参数 def get_opt(): try: opts, args = getopt.getopt(sys.argv[1:], "hs:a:d:", ["help", "war="]) except getopt.GetoptError: print "getopt function has error.." usage() for o, a in opts: if o in ("-h", "--help"): usage() if o in ("-s"): site_name = a if o in ("-a"): app_name = a if o in ("-d"): dep_version = a if o in ("--war"): war_name = a return site_name, app_name, dep_version, war_name #执行shell命令 def docker_cmd(cmd): return_code = subprocess.call(cmd, shell=True) if return_code != 0: print "command === %s === error" % (cmd) usage() return return_code def main(): site_name, app_name, dep_version, war_name = get_opt() if "" in [site_name, app_name, dep_version, war_name]: print "args have empty value..." usage() docker_login = 'docker login -u %s -p %s http://%s' % (docker_login_name, docker_login_password, docker_harbor_ip ) docker_tag = 'docker build -t %s/%s/%s:%s .' % (docker_harbor_ip , site_name.lower(), app_name.lower(), dep_version) docker_push = 'docker push %s/%s/%s:%s' % (docker_harbor_ip , site_name.lower(), app_name.lower(),dep_version) for cmd in [docker_login, docker_tag, docker_push]: docker_cmd(cmd) print "docker cmd is run..." if __name__ =='__main__': main()

优秀的个人博客,低调大师

CNCFxLFOSSA云原生专业人才培养计划,免费申请官方基金会认证学习及考试机会

CNCFxLFOSSA云原生专业人才培养计划 CNCF X LFOSSA Cloud Native Talent Developement Program 在一个不断扩大的云原生服务市场,人才短缺是企业HR永恒的烦恼。经验告诉我们,企业IT人员,例如项目经理和产品经理,他们并不一定要有计算机相关学位,但是一个认可的云原生资格证书是必不可少的。针对这个需求,CNCF推出了KCNA (Kubernetes And Cloud Native Associate)认证和培训,目的是赋予认证者全面的K8s和云原生知识,同时拥有足够的能力分析问题和解决问题。 With growing cloud-native services market, talent shortage is always an pain point to HR of the enterprises. From our experience, enterprise IT personnel, such as Project Managers and Product Managers, don't need to have a Computer Science-related Degree, but an accredited cloud-native qualification is essential for them to equip with corresponding skills for everyday work. Therefore, CNCF has launched the KCNA (Kubernetes And Cloud Native Associate) certification and training, which aims to let KCNA certified holders get comprehensive K8s and cloud native knowledge, and with sufficient capabilty to analyze and solve problems. 为了在云原生业界培养更多开源人才,CNCF和LFOSSA合作一起举办CNCFXLFOSSA云原生专业人才培养计划,填妥以下的表格,表达你对你云原生事业的规划和热诚!成功申请人士将获得免费参加KCNA+准备课程LFS250(价值:人民币1988元)的机会! In order to develop more talents in Cloud Native Industry, CNCF and Linux Foundation Open Source Software Academy launch the CNCF X LFOSSA Cloud Native Talent Developement Program in China. To apply for this program, please fill out and submit the online form, and show us your enthuastism to your Cloud Native career as well as your career planning. LFOSSA will sponsor the successful applicants to take KCNA certification exam and the online selfpaced course, LFS250 to prepare for this certification. 我们将在6月8日下午进行KCNA发布会,更多详情给按这里。 Who should participate? 谁应该参加? HR Manager 人力资源经理 IT Manager IT 经理 IT Sales IT 销售人员 IT Sales Engineer IT 销售工程师 IT Pre-Sales IT 售前人员 IT Consultant IT 顾问 Prodcut Manager 产品经理 Project Manager 项目经理 Developers who are new to Cloud Native希望加入原生行列的开发人员 Training Organizations and Instructors 培训机构及培训导师 Country 国家: Mainland China, Taiwan, Hong Kong, Macau & Asia Pacific 中国,台湾,香港,澳门及亚太区等 Important Dates 重要时间点: Application Deadline: Jun 24, 2022 Notification and Annoucement of Successful Applicants: 3rd week of July, 2022 Time for Successful Applicants to take KCNA: July - Dec, 2022 申请截止日:6月24日 公布时间:7月第三周 成功申请人参与考试时间:8月至12月底 Click here to fill out the application form 按此填写申请表格

优秀的个人博客,低调大师

CNCFxLFOSSA云原生专业人才培养计划,免费申请基金会官方认证学习及考试机会

CNCFxLFOSSA云原生专业人才培养计划 CNCF X LFOSSA Cloud Native Talent Developement Program 在一个不断扩大的云原生服务市场,人才短缺是企业HR永恒的烦恼。经验告诉我们,企业IT人员,例如项目经理和产品经理,他们并不一定要有计算机相关学位,但是一个认可的云原生资格证书是必不可少的。针对这个需求,CNCF推出了KCNA (Kubernetes And Cloud Native Associate)认证和培训,目的是赋予认证者全面的K8s和云原生知识,同时拥有足够的能力分析问题和解决问题。 With growing cloud-native services market, talent shortage is always an pain point to HR of the enterprises. From our experience, enterprise IT personnel, such as Project Managers and Product Managers, don't need to have a Computer Science-related Degree, but an accredited cloud-native qualification is essential for them to equip with corresponding skills for everyday work. Therefore, CNCF has launched the KCNA (Kubernetes And Cloud Native Associate) certification and training, which aims to let KCNA certified holders get comprehensive K8s and cloud native knowledge, and with sufficient capabilty to analyze and solve problems. 为了在云原生业界培养更多开源人才,CNCF和LFOSSA合作一起举办CNCFXLFOSSA云原生专业人才培养计划,填妥以下的表格,表达你对你云原生事业的规划和热诚!成功申请人士将获得免费参加KCNA+准备课程LFS250(价值:人民币1988元)的机会! In order to develop more talents in Cloud Native Industry, CNCF and Linux Foundation Open Source Software Academy launch the CNCF X LFOSSA Cloud Native Talent Developement Program in China. To apply for this program, please fill out and submit the online form, and show us your enthuastism to your Cloud Native career as well as your career planning. LFOSSA will sponsor the successful applicants to take KCNA certification exam and the online selfpaced course, LFS250 to prepare for this certification. 我们将在6月8日下午进行KCNA发布会,更多详情给按这里。 Who should participate? 谁应该参加? HR Manager 人力资源经理 IT Manager IT 经理 IT Sales IT 销售人员 IT Sales Engineer IT 销售工程师 IT Pre-Sales IT 售前人员 IT Consultant IT 顾问 Prodcut Manager 产品经理 Project Manager 项目经理 Developers who are new to Cloud Native希望加入原生行列的开发人员 Training Organizations and Instructors 培训机构及培训导师 Country 国家: Mainland China, Taiwan, Hong Kong, Macau & Asia Pacific 中国,台湾,香港,澳门及亚太区等 Important Dates 重要时间点: Application Deadline: Jun 24, 2022 Notification and Annoucement of Successful Applicants: 3rd week of July, 2022 Time for Successful Applicants to take KCNA: July - Dec, 2022 申请截止日:6月24日 公布时间:7月第三周 成功申请人参与考试时间:8月至12月底 Click here to fill out the application form 按此填写申请表格

资源下载

更多资源
优质分享App

优质分享App

近一个月的开发和优化,本站点的第一个app全新上线。该app采用极致压缩,本体才4.36MB。系统里面做了大量数据访问、缓存优化。方便用户在手机上查看文章。后续会推出HarmonyOS的适配版本。

Spring

Spring

Spring框架(Spring Framework)是由Rod Johnson于2002年提出的开源Java企业级应用框架,旨在通过使用JavaBean替代传统EJB实现方式降低企业级编程开发的复杂性。该框架基于简单性、可测试性和松耦合性设计理念,提供核心容器、应用上下文、数据访问集成等模块,支持整合Hibernate、Struts等第三方框架,其适用范围不仅限于服务器端开发,绝大多数Java应用均可从中受益。

Rocky Linux

Rocky Linux

Rocky Linux(中文名:洛基)是由Gregory Kurtzer于2020年12月发起的企业级Linux发行版,作为CentOS稳定版停止维护后与RHEL(Red Hat Enterprise Linux)完全兼容的开源替代方案,由社区拥有并管理,支持x86_64、aarch64等架构。其通过重新编译RHEL源代码提供长期稳定性,采用模块化包装和SELinux安全架构,默认包含GNOME桌面环境及XFS文件系统,支持十年生命周期更新。

Sublime Text

Sublime Text

Sublime Text具有漂亮的用户界面和强大的功能,例如代码缩略图,Python的插件,代码段等。还可自定义键绑定,菜单和工具栏。Sublime Text 的主要功能包括:拼写检查,书签,完整的 Python API , Goto 功能,即时项目切换,多选择,多窗口等等。Sublime Text 是一个跨平台的编辑器,同时支持Windows、Linux、Mac OS X等操作系统。

用户登录
用户注册