首页 文章 精选 留言 我的

精选列表

搜索[android jetpack],共10000篇文章
优秀的个人博客,低调大师

android 测试Activity,Content Provider,Service,测试些什么?(摘取自官网,个人翻译…欢迎校正)

Activity Input validation: Test that an activity responds correctly to input values in an EditText View. Set up a keystroke sequence, send it to the activity, and then usefindViewById(int)to examine the state of the View. You can verify that a valid keystroke sequence enables an OK button, while an invalid one leaves the button disabled. You can also verify that the Activity responds to invalid input by setting error messages in the View. 输入验证:测试一个activity对EditText View输入做出正确地反应.设置按键顺序,并且发送到activity中,还有使用findViewById()用来验证View的状态是否正常.你可以验证一个有效的按键序列在OK按钮上是有效的,当输入一个无效的按键会使按钮失效.你也可以验证当输入无效的设置在View中activity会做出何种反应. Lifecycle events: Test that each of your application's activities handles lifecycle events correctly. In general, lifecycle events are actions, either from the system or from the user, that trigger a callback method such asonCreate()oronClick(). For example, an activity should respond to pause or destroy events by saving its state. Remember that even a change in screen orientation causes the current activity to be destroyed, so you should test that accidental device movements don't accidentally lose the application state. 生命周期事件:测试你每一个应用程序activity 的 handles 在 生命周期里面都是正确的.通常来讲,生命周期事件都是action动作,任何来自于系统或者用户,将会触发回调方法,例如onCreate()或者onClick().举个例子,一个activity应该对pause或者destoryed做出反应来并且保存它的状态.记住,实际上屏幕方向的改变事件会导致当前activity被销毁,所以你应该测试程序在设备运行中发生意外事件时不会偶然间丢失程序的状态. Intents: Test that each activity correctly handles the intents listed in the intent filter specified in its manifest. You can useActivityInstrumentationTestCase2to send mock Intents to the activity under test. Intens:测试每一个activity对指定在manifest的intent-filter里的intents做出正确的处理.你可以使用ActivityInstrumentationTestCase2发送一个模拟Intents 到activity 在测试中 Runtime configuration changes: Test that each activity responds correctly to the possible changes in the device's configuration while your application is running. These include a change to the device's orientation, a change to the current language, and so forth. Handling these changes is described in detail in the topicHandling Runtime Changes. 改变运行时的设置:在程序运行时,测试每个activity都能对可能改变的设备配置做出正确的响应.这些改变包括改变设备的屏幕方向,改变当前语言,等等.Handing这些改变具体描述在Handling Runtime Changes. Screen sizes and resolutions: Before you publish your application, make sure to test it on all of the screen sizes and densities on which you want it to run. You can test the application on multiple sizes and densities using AVDs, or you can test your application directly on the devices that you are targeting. For more information, see the topicSupporting Multiple Screens. 屏幕的兼容性:在你发布你的程序之前,请确认测试好所有你想运行的屏幕大小.你可以使用AVDs测试你的应用程式在多种屏幕大小下,或者你可以直接测试你的程序在目标设备上.更多的信息,可以看这篇Supporting Multiple Screens. Content Provider Test with resolver methods: Even though you can instantiate a provider object inProviderTestCase2, you should always test with a resolver object using the appropriate URI. This ensures that you are testing the provider using the same interaction that a regular application would use. 测试解析方法:尽管你可以在providerTestCase2中实现一个provider,但是你应该始终用一个resolver对象测试合适的 URI.这可以确保你正在测试的provider 是在同一个应用程序中使用同样的操作. Test a public provider as a contract: If you intent your provider to be public and available to other applications, you should test it as a contract. This includes the following ideas: 测试一个公共的provider的协定:如果你想你的provider是一个公共的和可被其它程序访问的,你应该测试它的协定.这里包括了一些主意: Test with constants that your provider publicly exposes. For example, look for constants that refer to column names in one of the provider's data tables. These should always be constants publicly defined by the provider. 测试provider所有公开的常量.比如,在常量中有个列名是归类在provider’s data表中.这些常量应该始终定义在你的provider中 Test all the URIs offered by your provider. Your provider may offer several URIs, each one referring to a different aspect of the data. TheNote Padsample, for example, features a provider that offers one URI for retrieving a list of notes, another for retrieving an individual note by it's database ID, and a third for displaying notes in a live folder. 测试Provider提供的所有URIs.Provider可能提供一些URIs在data中每个都涉及到不同的方式.例如在NOTE PAD 例子中,比如,一个provider提供一个uri 用于回收一个列表的笔记记录,另外一个使用databas Id用于回收一条笔记记录,和 还有一个用于显示笔记在一个折叠面板上 Test invalid URIs: Your unit tests should deliberately call the provider with an invalid URI, and look for errors. Good provider design is to throw an IllegalArgumentException for invalid URIs. 测试无效的URIs:你的单元测试应该故意的调用provider使用一个无效的URI,并且,查看这些错误.在使用无效的URIs时,好的provider的设计是会抛出一个IllegalArgumentException异常. Test the standard provider interactions: Most providers offer six access methods: query, insert, delete, update, getType, and onCreate(). Your tests should verify that all of these methods work. These are described in more detail in the topicContent Providers. 测试标准的provider的操作.很多 providers 提供6个访问方法:查询,插入,删除,更新,获取类型,和onCreate().你的测试应该验证所有这些方法都是正常运行的.这些的详细描述可参阅Content Providers. Test business logic: Don't forget to test the business logic that your provider should enforce. Business logic includes handling of invalid values, financial or arithmetic calculations, elimination or combining of duplicates, and so forth. A content provider does not have to have business logic, because it may be implemented by activities that modify the data. If the provider does implement business logic, you should test it. 测试业务逻辑:不要忘记测试业务逻辑你的provider是可以实现的.业务逻辑包括处理无效的数据,财务或者算术的计算,消除或者联级复制,等等.一个content provider 不要有太多的业务逻辑,因为,这可能导致改变数据时部分业务逻辑被实现.如果你的provider实现了业务逻辑,你应该测试它. services Ensure that theonCreate()is called in response toContext.startService()orContext.bindService(). Similarly, you should ensure thatonDestroy()is called in response toContext.stopService(),Context.unbindService(),stopSelf(), orstopSelfResult(). 确定onCreate()方法是响应Context.startService() 或者Context.binServ()的调用.同样,你应该确定onDestoy()方法是响应Context.stopService(),Context.unbindService(),stopSelf(), orstopSelfResult(). 的调用 Test that your Service correctly handles multiple calls fromContext.startService(). Only the first call triggersService.onCreate(), but all calls trigger a call toService.onStartCommand(). In addition, remember thatstartService()calls don't nest, so a single call toContext.stopService()orService.stopSelf()(but notstopSelf(int)) will stop the Service. You should test that your Service stops at the correct point. 测试Service在Context.startService()的多次调用下正常运行.只有在第一次调用时触发Service.onCreate().但是,其它所有的调用都在Service.onStartCommand()触发.另外,记住startService()不支持嵌套调用!还有单独调用Context.stopService()或者Service.stopSelf()(但是不是stopSelf(int))将会停止Service.你应该测试你的Service在正确的点上停止. Test any business logic that your Service implements. Business logic includes checking for invalid values, financial and arithmetic calculations, and so forth. 测试Service实现的是所有业务逻辑.这些业务逻辑包括检查无效的值,财务和算术运算,等等 本文转自 liam2199 博客,原文链接:http://blog.51cto.com/youxilua/772686 如需转载请自行联系原作者

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

【读书笔记《Android游戏编程之从零开始》】15.游戏开发基础(剪切区域)

剪切区域也称为可视区域,是由画布进行设置的;它指的是在画布上设置一块区域,当画布一旦设置了可视区域,那么除此区域外,绘制的任何内容都将看不到;可视区域可以是圆形、矩形等等。 画布提供了三种设置可视区域的方法。 1.通过坐标,设置矩形可视区域 clipRect(int left,int top,int right,int bottom) 作用:为画布设置矩形可视区域 第一、二个参数:为可视区域的左上角 第三、四个参数:为可视区域的右下角2.利用 Path 来设置可视区域的形状 clipPath(Path path) 作用:为画布设置可视区域 参数:Path实例3.利用 Region 来对画布设置可视区域 clipRegion(Region region) 作用:为画布设置可视区域 参数:Region 实例 Region 表示区域的集合,所以它可以设置多个区域块,而且可以通过这些区域块之间的关系来处理一些问题;比如 Region 设置它所有区域块相交的区域是否可见、设置相交区域只让交集显示等等。 Region 常用函数: op(Rect rect,Op op) 作用:设置区域块 第一个参数:Rect 实例 第二个参数:Region.Op 静态值,表示区域块的显示方式。其中区域块的显示方式如下: Region.Op.UNION: 区域全部显示 Region.Op.INTERSECT:区域的交集显示 Region.Op.XOR:不显示交集区域 下面是实例演示,效果图如下: 创建新项目,游戏框架为 SurfaceView 游戏框架。具体步骤参照“11.游戏开发基础(SurfaceView 游戏框架、View 和 SurfaceView 的区别)”。 修改 MySurfaceView类中的绘图函数如下: private void myDraw() { try { canvas = sfh.lockCanvas(); if (canvas != null) { //通过图片资源生成一张Bitmap 位图 Bitmap bmp = BitmapFactory.decodeResource(this.getResources(), R.drawable.pic01); canvas.save(); canvas.drawText("原图:", 20, 20, paint); canvas.drawBitmap(bmp, 20, 30,paint); canvas.restore(); canvas.save(); canvas.drawText("通过坐标,设置矩形可视区域:", 20, 320, paint); /** * 为画布设置矩形可视区域 * 第一、二个参数为可视区域的左上角 * 第三、四个参数为可视区域的右下角 */ canvas.clipRect(20,330,bmp.getWidth()+20,bmp.getHeight()/2+330); canvas.drawBitmap(bmp, 20, 330,paint); canvas.restore(); canvas.save(); canvas.drawText("利用 Path 来设置可视区域的形状,这里为圆形可视区域:", 20, 620, paint); Path path = new Path(); path.addCircle(20+bmp.getWidth()/2, 630+bmp.getHeight()/2, bmp.getWidth()/2, Direction.CCW); /** * 为画布设置可视区域 * 参数:Path实例 * 利用Paht 可以为位图设置任何需要的可视区域,这里是设置一个圆形可视区域。 */ canvas.clipPath(path); canvas.drawBitmap(bmp, 20, 630, paint); canvas.restore(); canvas.save(); canvas.drawText("利用 Region 来对画布设置可视区域:", 20, 920, paint); Region region = new Region(); //区域块全部显示 region.op(new Rect(20,930,120,1030), Region.Op.UNION); //不显示交集区域 region.op(new Rect(50,930,100,1080), Region.Op.XOR); canvas.clipRegion(region); canvas.drawBitmap(bmp, 20, 930, paint); canvas.restore(); } } catch (Exception e) { } finally { if (canvas != null) { sfh.unlockCanvasAndPost(canvas); } } } 本文转自叶超Luka博客园博客,原文链接:http://www.cnblogs.com/yc-755909659/p/4164979.html,如需转载请自行联系原作者

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

Android -- 拷贝assets下的资源文件到SD卡中(可以超过1M)

很多手机游戏,在安装APK之后都得需要下载相应的资源包,然后才能进入游戏。 有这样一个需求:就是游戏中需要的资源包打在APK内,随apk一起进行安装到手机中。 这样就不需要,在安装APK之后,去下载资源。(这样APK的大小就会大一些) 于是在网上就开始找对应的直接访问随apk一起安装到手机中的资源。比如在assets目录下放置了一个“test.zip”的资源。当apk安装之后,可能我就需要访问这个"test.zip"资源文件。(可能我会去解压到某处) 在网上找了很长时间,说什么在assets下的资源怎么怎么不能超过1M、或者要分成多个不超过1M的小文件,然后用的时候在拼成一个大文件、说什么要用到什么数据库。总之说的,感觉没有一个有用的。 于是自己就实现了一个从assets下拷贝资源到sd卡中的一个功能。这里不限制非得拷贝到sd卡中。 之所以要拷贝出来,是因为在assets内的资源随apk安装之后,不好访问。所以想拷贝到一个容易访问的地方。比如是一个assets下的是一个zip文件,为需要在安装之后进行解压。而解压的时候我又想使用 ant.jar (支持编码) 。于是我先将zip资源拷贝到一个地方,然后在进行解压。 private void copyBigDataToSD(String strOutFileName) throws IOException { InputStream myInput; OutputStream myOutput = new FileOutputStream(strOutFileName); myInput = this.getAssets().open("yphone.zip"); byte[] buffer = new byte[1024]; int length = myInput.read(buffer); while(length > 0) { myOutput.write(buffer, 0, length); length = myInput.read(buffer); } myOutput.flush(); myInput.close(); myOutput.close(); } 备注:参数为要拷贝的目的地例如“/mnt/sdcard/test/Out.zip”; 此处“myInput = cGameActivity.getAssets().open("yphone.zip"); ”open 的是你放在assets下的资源的名称。本例放的是一个叫"yphone.zip"的文件; 在进行测试的时候发现在资源文件很大时,例如200M左右,可能会报错。 但可以保证的是100M一下的没问题。 本文转自我爱物联网博客园博客,原文链接:http://www.cnblogs.com/yydcdut/p/3744873.html,如需转载请自行联系原作者

资源下载

更多资源
Mario

Mario

马里奥是站在游戏界顶峰的超人气多面角色。马里奥靠吃蘑菇成长,特征是大鼻子、头戴帽子、身穿背带裤,还留着胡子。与他的双胞胎兄弟路易基一起,长年担任任天堂的招牌角色。

腾讯云软件源

腾讯云软件源

为解决软件依赖安装时官方源访问速度慢的问题,腾讯云为一些软件搭建了缓存服务。您可以通过使用腾讯云软件源站来提升依赖包的安装速度。为了方便用户自由搭建服务架构,目前腾讯云软件源站支持公网访问和内网访问。

Spring

Spring

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

Sublime Text

Sublime Text

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

用户登录
用户注册