首页 文章 精选 留言 我的

精选列表

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

Android设备兼容性 2

版权声明:本文为sydMobile原创文章,转载请务必注明出处! https://blog.csdn.net/sydMobile/article/details/78144278 文章最早发布于我的微信公众号中,欢迎大家扫描下面二维码关注微信公众获取更多干货资源。 本文为sydMobile原创文章,可以随意转载,但请务必注明出处! 翻译自Android官方文档加入了自己的理解! Controlling Your App’s Availability to Devices 控制你的程序的可用性在不同的设备上 Android supports a variety of features your app can leverage through platform APIs. Some features are hardware-based (such as a compass sensor), some are software-based (such as app widgets), and some are dependent on the platform version. Not every device supports every feature, so you may need to control your app’s availability to devices based on your app’s required features. Android支持许多的功能,你的APP可以通过API充分的利用这些功能。一些功能是硬件作为支持(比如指南针传感器),一些是软件作为支持(比如APP小空间),还有一些依赖于平台的版本(也就是Android平台的版本)不是每个设备都支持Android的所以功能。所以你需要根据你的app所需要的特点来控制你的APP的实现。 To achieve the largest user-base possible for your app, you should strive to support as many device configurations as possible using a single APK. In most situations, you can do so by disabling optional features at runtime and providing app resources with alternatives for different configurations (such as different layouts for different screen sizes). If necessary, however, you can restrict your app’s availability to devices through Google Play Store based on the following device characteristics: 为了让你的APP实现最大的用户量,你应该努力的去支持大量的设备通过用一个APK,在大多数情况下,你可以舍弃一些不必要的功能提供一些在不同设备上必须的资源(比如为不同的屏幕尺寸添加不同的布局文件,这就是屏幕适配的一种方式)如果有必要的话,你也可以通过Google Play来限制一些不可以使用的设备。 Device features 设备特点 In order for you to manage your app’s availability based on device features, Android defines feature IDs for any hardware or software feature that may not be available on all devices. For instance, the feature ID for the compass sensor is FEATURE_SENSOR_COMPASS and the feature ID for app widgets is FEATURE_APP_WIDGETS. 为了让您根据设备功能来管理应用的可用性,Android定义了所有设备可能无法使用的任何硬件或软件功能的功能ID。 例如,罗盘传感器的功能ID为FEATURE_SENSOR_COMPASS,应用程序小部件的功能ID为FEATURE_APP_WIDGETS。 If necessary, you can prevent users from installing your app when their devices don’t provide a given feature by declaring it with a element in your app’s manifest file. 如果需要,您可以通过在应用程序的清单文件中使用元素声明该设备,从而避免用户安装应用程序。 For example, if your app does not make sense on a device that lacks a compass sensor, you can declare the compass sensor as required with the following manifest tag: <manifest ... > <uses-feature android:name="android.hardware.sensor.compass" android:required="true" /> ... </manifest> 例如,如果您的应用在缺少罗盘传感器的设备上无效,则可以根据需要使用以下清单标签声明罗盘传感器: Google Play Store compares the features your app requires to the features available on each user’s device to determine whether your app is compatible with each device. If the device does not provide all the features your app requires, the user cannot install your app. Google Play商店将您的应用所需的功能与每个用户设备上的功能进行比较,以确定您的应用是否与每个设备兼容。 如果设备没有提供您的应用所需的所有功能,则用户无法安装您的应用。 However, if your app’s primary functionality does not require a device feature, you should set the required attribute to “false” and check for the device feature at runtime. If the app feature is not available on the current device, gracefully degrade the corresponding app feature. For example, you can query whether a feature is available by calling hasSystemFeature() like this: PackageManager pm = getPackageManager(); if (!pm.hasSystemFeature(PackageManager.FEATURE_SENSOR_COMPASS)) { // This device does not have a compass, turn off the compass feature disableCompassFeature(); } 然而,如果您的应用程序的主要功能不需要设备功能,则应将所需属性设置为“false”,并在运行时检查设备功能。 如果应用功能在当前设备上不可用,则会适当地降低相应的应用功能。 例如,您可以通过调用hasSystemFeature()来查询功能是否可用: For information about all the filters you can use to control the availability of your app to users through Google Play Store, see the Filters on Google Play document. 有关所有过滤器的信息,可以通过Google Play商店来控制用户的应用程序的可用性,请参阅Google Play上的过滤器文档。 Note: Some system permissions implicitly require the availability of a device feature. For example, if your app requests permission to access to BLUETOOTH, this implicitly requires the FEATURE_BLUETOOTH device feature. You can disable filtering based on this feature and make your app available to devices without Bluetooth by setting the required attribute to “false” in the tag. For more information about implicitly required device features, read Permissions that Imply Feature Requirements. 注意:某些系统权限隐含地要求设备功能的可用性。 例如,如果您的应用程序请求访问BLUETOOTH的权限,则会隐式地需要FEATURE_BLUETOOTH设备功能。 您可以根据此功能禁用过滤,并通过在标签中将所需属性设置为“false”,使您的应用程序可用于无蓝牙设备。 有关隐式需要的设备功能的更多信息,请阅读具有要求功能要求的权限。 未完待续…. 扫一扫关注微信公众号,获取更多干货和资源。

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

Android测试驱动开发实践2

在实际项目开发过程中,一般先实现核心功能,最后再做辅助性功能,这样可以尽快验证Idea的正确性,同时有助于让老板、投资人或客户看到可运行的产品,从而对产品充满信心,加大对项目的支持。 但是对于我们这个项目而言,我们首先需要得到一个 Android应用MVC的架构体系,因此我们首先来实现一些典型功能,但是可以完整体现MVC架构的功能。在此我们选择任何应用程序在启动时都会显示的Splash页面,通常这个页面会显示一个应用图片,过30秒左右再显示程序的主界面,应用在这段时间完成数据加载等准备 工作。 在这里我们要稍微背离一下 测试驱动开发的标准方法,原因是我们在进行Android应用开发,由于Android系统限制有很多方面是很难做 单元测试的,硬做单元测试,除了理论上的有效性外,没有任何实际意义。 在这里,我们采用验收测试驱动开发的理念,即我们开发足够功能来满足一个验收 测试用例。这里我们选择的一个验收测试用例为:应用在开启时,先显示10秒应用图片,然后自动进入应用首页,也就是我们通常所看到的Splash屏幕功能。 我们首先定义SplashActivity类,代码如下所示: package com.bjcic.wkj; import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.view.WindowManager; public class SplashActivity extends Activity { // 生命周期方法---开始 @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); //全屏 setContentView(R.layout.splash); getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); appModel = (AppModel)getApplication(); appController = appModel.getAppController(); appController.postDelayed(new Runnable() { /** * 隔10秒钟启动主页面 */ @Override public void run() { appController.processEvent(new AppEvent(SplashActivity.this, AppEvent.EVE_SPLASH_END, null)); } }, AppKeys.SPLASH_DURATION); // 启动异步任务准备应用数据 } // 生命周期方法---结束 private AppController appController = null; private AppModel appModel = null; } 这个Activity所对应的布局文件为: <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" android:background="@drawable/splash"> </LinearLayout> 布局文件就是定义了一下Splash屏幕的背景图。 这里我们引入了AppController类,是应用的控制器类。Activity中用户的操作和系统的状态改变都会生成相应的事件,由AppController.processEvent来进行统一处理,同时异步任务、线程等产生的需要界面更新的操作,通过向AppController发送Message来实现(因为AppController继承了Handler类)。具体代码如下所示: package com.bjcic.wkj; import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.os.Handler; import android.os.Message; import android.util.Log; public class AppController extends Handler { public AppController(AppModel appModel) { super(); this.appModel = appModel; } /** * Activity中会根据用户的操作或系统状态,产生对应的事件,发送给AppController进行统一处理。 * @param event */ public void processEvent(AppEvent event) { switch (event.getEventId()) { case AppEvent.EVE_SPLASH_END: // 从Splash界面显示主界面 showMainActivity((Activity)event.getContext(), event.getParams()); break; default: break; } } /** * 异步任务、线程、后台服务等需要更新界面时,向AppController发送消息即可 */ @Override public void handleMessage(Message msg) { super.handleMessage(msg); } /** * 关闭Splash页面并打开应用主界面 * @param activity * @param params */ private void showMainActivity(Activity activity, Bundle params) { Log.d("wkj", "activity=" + activity + "; c=" + MainActivity.class + "!"); Intent intent = new Intent(activity, MainActivity.class); activity.startActivity(intent); activity.finish(); } private AppModel appModel = null; } 在上面的代码中,事件处理函数直接写在的应用总的Controller中,其实也可以写到具体的Controller中,为了代码的可维护性,最好还是将事件处理写到对应模块的Controller中比较好。 下面就是AppEvent的定义: package com.bjcic.wkj; import android.content.Context; import android.os.Bundle; public class AppEvent { public AppEvent(Context context, int eventId, Bundle params) { this.context = context; this.eventId = eventId; this.params = params; } public Context getContext() { return context; } public void setContext(Context context) { this.context = context; } public Bundle getParams() { return params; } public int getEventId() { return eventId; } public void setEventId(int eventId) { this.eventId = eventId; } public final static int EVE_NONE = 0; public final static int EVE_SPLASH_END = 1; // Splash界面显示时间到期 private Context context = null; private int eventId = 0; private Bundle params = null; } 在上面的事件定义中,事件中包含当前的Activity,事件ID和事件参数,这样AppController就可以直接对事件进行处理了。 最后,我们在Splash页面停留10秒,这里需要定义一个常量,我们将应用中需要用到的重要常量,统一定义到AppKeys中,如下所示: package com.bjcic.wkj; public class AppKeys { public final static long SPLASH_DURATION = 10 * 1000; } 好的,现在可以运行这个应用程序了,如果一切正常,应该可以看到一个Splash页面显示10秒钟后,进入到程序主界面中。至此我们的第一个验收测试用例就顺利通过了。 这时,我们再回到WkjTest这个工程中,以Android Junit形式运行MainActivityTest,这时应该显示所有测试用例全部通过。 注:大家也许注意到了,测试驱动开发是以一小步一小步的开发测试为基础的,在实际工作中,有一半愉上的程序员喜欢先把所有代码写好,然后在进行调试。当然也有一部分开发人员写一点调一点,这纯属于习惯性问题,不存在孰优孰劣的问题。但是采用测试驱动开发方法学,就要采用后面的工作方式。 因此,测试驱动开发不一定适合所有人,对于喜欢一次性先把代码写好,然后进行调试的人来说,让他们接受测试驱动开发的工作方式是很困难的,这一点希望大家能够重视起来。 最新内容请见作者的GitHub页:http://qaseven.github.io/

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

【20160924】GOCVHelper 图像增强部分(2

//填充孔洞 //fillholes MatfillHoles(Matsrc){ Matdst=getInnerHoles(src); threshold(dst,dst,0,255,THRESH_BINARY_INV); dst=src+dst; returndst; } //获得图像中白色的比率 floatgetWhiteRate(Matsrc){ intiWhiteSum=0; for(intx=0;x<src.rows;x++){ for(inty=0;y<src.cols;y++){ if(src.at<uchar>(x,y)!=0) iWhiteSum=iWhiteSum+1; } } return(float)iWhiteSum/(float)(src.rows*src.cols); } //获得内部孔洞图像 MatgetInnerHoles(Matsrc){ Matclone=src.clone(); srand((unsigned)time(NULL));//生成时间种子 floatfPreRate=getWhiteRate(clone); floatfAftRate=0; do{ clone=src.clone(); //xy对于colsrows floodFill(clone,Point((int)rand()%src.cols,(int)rand()%src.rows),Scalar(255)); fAftRate=getWhiteRate(clone); }while(fAftRate<0.6); returnclone; } //endoffillHoles 填充孔洞算法是我参考相关资料自己实现的。填充孔洞的关键在于获得“内部孔洞图像”。我采用的方法是在图像上随机寻找一个点作为floodfill的初始点,然后以scalar(255)来进行填充。重复这个过程,直到整个图片的白色值占到了全部图像的60%. 填充前 填充后 来自为知笔记(Wiz) 目前方向:图像拼接融合、图像识别 联系方式:jsxyhelu@foxmail.com

资源下载

更多资源
Mario

Mario

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

Eclipse

Eclipse

Eclipse 是一个开放源代码的、基于Java的可扩展开发平台。就其本身而言,它只是一个框架和一组服务,用于通过插件组件构建开发环境。幸运的是,Eclipse 附带了一个标准的插件集,包括Java开发工具(Java Development Kit,JDK)。

JDK

JDK

JDK是 Java 语言的软件开发工具包,主要用于移动设备、嵌入式设备上的java应用程序。JDK是整个java开发的核心,它包含了JAVA的运行环境(JVM+Java系统类库)和JAVA工具。

Sublime Text

Sublime Text

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