首页 文章 精选 留言 我的

精选列表

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

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 按此填写申请表格

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

Android官方开发文档Training系列课程中文版:线程执行操作之创建多线程管理器

原文地址:http://android.xsoftlab.net/training/multiple-threads/create-threadpool.html 上节课我们学习了如何定义一个任务。如果只是执行单次任务,那么刚刚所学的已经基本满足要求了。如果需要针对不同的数据执行同种任务,并且需要同一时间只能执行一项任务,那么IntentService可能会适合你。如果要使任务随着资源的可用而执行,或者同一时间需要运行多个任务,那么就需要专门管理这些线程了。Android系统为此提供了一个类,那就是传说中的ThreadPoolExecutor。它可以在线程可用时自动运行队列中的任务。如果要运行一个任务,只需要将任务添加到队列中即可。 ThreadPoolExecutor允许多个线程同时进行,所以应当确保代码是线程安全的。要确保可能会被多个线程访问到的变量被放在同步代码块中。这种方法可以防止一个线程正在读取一个变量的值,而另一个变量正在对这个变量写入新值的现象出现。通常情况下,这种现象会发生在静态变量中,但是也会发生在单例对象上。 定义线程池类 在该类内实例化一个ThreadPoolExecutor对象,并在该类内执行以下工作: 对线程池对象使用静态变量引用 在APP内通常只需要一个线程池对象的存在:为了对CPU资源或网络资源有一个单一的控制。如果含有不同的Runnable类型,你可能希望对每种类型都创建一个单独线程池,但是每种类型都还是单例类型。在这里的例子中,可以添加以下代码作为全局属性声明。 public class PhotoManager { ... static { ... // Creates a single static instance of PhotoManager sInstance = new PhotoManager(); } ... 使用私有构造方法: 私有的构造方法可以确保该类只有一个对象存在。 public class PhotoManager { ... /** * Constructs the work queues and thread pools used to download * and decode images. Because the constructor is marked private, * it's unavailable to other classes, even in the same package. */ private PhotoManager() { ... } 调用线程池的相关方法启动任务: 在线程池类内定义一个可以向线程池队列中添加任务的方法。 public class PhotoManager { ... // Called by the PhotoView to get a photo static public PhotoTask startDownload( PhotoView imageView, boolean cacheFlag) { ... // Adds a download task to the thread pool for execution sInstance. mDownloadThreadPool. execute(downloadTask.getHTTPDownloadRunnable()); ... } 在构造方法中实例化一个Handler对象,并将其连接到UI线程:Handler允许安全的调用比如View这种UI对象。大多数的UI对象只允许被UI线程访问。 private PhotoManager() { ... // Defines a Handler object that's attached to the UI thread mHandler = new Handler(Looper.getMainLooper()) { /* * handleMessage() defines the operations to perform when * the Handler receives a new Message to process. */ @Override public void handleMessage(Message inputMessage) { ... } ... } } 确定线程池参数 如果要实例化ThreadPoolExecutor对象,需要用到以下值: 线程池的初始值以及最大值: 线程数量的初始值用于指定池子的初始大小,最大值代表了该线程池所允许开放的最大并发数量。线程池中的线程数量取决于设备的可用核心数。这个值与当前的设备颇有关系: public class PhotoManager { ... /* * Gets the number of available cores * (not always the same as the maximum number of cores) */ private static int NUMBER_OF_CORES = Runtime.getRuntime().availableProcessors(); } 这个值可能不能够反映设备的物理核心数量;在一些设备上,核心是否可用取决于系统是否加载。对于这些设备,availableProcessors()返回了当前的活跃核心数量,这个值可能要比真实的总核心数要低。 存活时长及单位 线程在被关闭之间的闲置时长。这个时长由时间单元值负责解释,这些时间单位常量被定义在类TimeUnit中。 任务队列 一个持有Runnable对象的队列。为了启动线程中的执行代码,线程池管理器采用了先进先出的管理原则。在创建线程池之前需要提供一个这样的队列,使用任何实现了BlockingQueue接口的类皆可。为了匹配到APP的要求,你可以选择适当的队列实现;学习更多它们的相关知识,请参见ThreadPoolExecutor的描述文档。这里的使用了LinkedBlockingQueue: public class PhotoManager { ... private PhotoManager() { ... // A queue of Runnables private final BlockingQueue<Runnable> mDecodeWorkQueue; ... // Instantiates the queue of Runnables as a LinkedBlockingQueue mDecodeWorkQueue = new LinkedBlockingQueue<Runnable>(); ... } ... } 线程池创建 创建一个线程池,只需调用ThreadPoolExecutor()实例化一个线程池管理器就好。它会创建并管理一组线程。因为线程池大小的初始值与最大值是相同的,所以ThreadPoolExecutor()会在初始化的时候创建出所指定的线程数量: private PhotoManager() { ... // Sets the amount of time an idle thread waits before terminating private static final int KEEP_ALIVE_TIME = 1; // Sets the Time Unit to seconds private static final TimeUnit KEEP_ALIVE_TIME_UNIT = TimeUnit.SECONDS; // Creates a thread pool manager mDecodeThreadPool = new ThreadPoolExecutor( NUMBER_OF_CORES, // Initial pool size NUMBER_OF_CORES, // Max pool size KEEP_ALIVE_TIME, KEEP_ALIVE_TIME_UNIT, mDecodeWorkQueue); }

资源下载

更多资源
Mario

Mario

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

腾讯云软件源

腾讯云软件源

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

Nacos

Nacos

Nacos /nɑ:kəʊs/ 是 Dynamic Naming and Configuration Service 的首字母简称,一个易于构建 AI Agent 应用的动态服务发现、配置管理和AI智能体管理平台。Nacos 致力于帮助您发现、配置和管理微服务及AI智能体应用。Nacos 提供了一组简单易用的特性集,帮助您快速实现动态服务发现、服务配置、服务元数据、流量管理。Nacos 帮助您更敏捷和容易地构建、交付和管理微服务平台。

Spring

Spring

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

用户登录
用户注册