首页 文章 精选 留言 我的

精选列表

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

Android GIS开发系列-- 入门季(12) 显示载天地图

在项目中可以经常需要动态加载一些图层,像投影地图服务、投影地图服务器。其实网上有大量这样的服务,比如天地图官网, 。 随便点开一个服务,里面有相关的信息。那如何加载这样图层服务呢。 一、首先感谢这篇博文ArcGIS读取天地图出现错位的情况,这篇文章的下载链接也有许多有用的资料。加载天地图用到一个关键的自定义类TianDiTuLayer View Code 另外还有三个类,TianDiTuLayerInfo、LayerInfoFactory、TianDiTuLayerTypes这里就不贴代码了。资料下载。 二、我们修改一下代码 1.常量类TDTConstant: View Code 2.TianDiTuLayer,代码如下 : View Code 3.TianDiTuInfo实体类: View Code 4.Activity代码: View Code 调用的地图服务相关信息 效果图: 没有整理与归纳的知识,一文不值!高度概括与梳理的知识,才是自己真正的知识与技能。 永远不要让自己的自由、好奇、充满创造力的想法被现实的框架所束缚,让创造力自由成长吧! 多花时间,关心他(她)人,正如别人所关心你的。理想的腾飞与实现,没有别人的支持与帮助,是万万不能的。 本文转自wenglabs博客园博客,原文链接:http://www.cnblogs.com/arxive/p/7751990.html ,如需转载请自行联系原作者

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

Android GIS开发系列-- 入门季(9) 定位当前的位置

利用MapView定位当前的位置 这里要用到Arcgis中的LocationDisplayManager这个类,由于比较简单。直接上代码: LocationDisplayManager locationDisplayManager = mMapView.getLocationDisplayManager();//获取定位类 locationDisplayManager.setShowLocation(true); locationDisplayManager.setAutoPanMode(LocationDisplayManager.AutoPanMode.LOCATION);//设置模式 locationDisplayManager.setShowPings(true); locationDisplayManager.start();//开始定位 由于是定位,在AndroidManifest文件中,要添加以下权限: <uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/> <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/> 另外如果我们想获取定位点的位置,调用代码:Point point = locationDisplayManager.getPoint();即可获取。 没有整理与归纳的知识,一文不值!高度概括与梳理的知识,才是自己真正的知识与技能。 永远不要让自己的自由、好奇、充满创造力的想法被现实的框架所束缚,让创造力自由成长吧! 多花时间,关心他(她)人,正如别人所关心你的。理想的腾飞与实现,没有别人的支持与帮助,是万万不能的。 本文转自wenglabs博客园博客,原文链接:http://www.cnblogs.com/arxive/p/7751967.html ,如需转载请自行联系原作者

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

Centos7下安装eclipse进行C/C++开发

1)下载eclipse Eclipse下载网址:https://www.eclipse.org/downloads/ 注意选择的时候选择Eclipse IDE for C/C++ Developers 2)下载cdt cdt下载网址:www.eclipse.org/cdt/ 3)安装 进入要“安装软件”的目录然后,解压eclipse-jee-kepler-RC3-Linux-gtk.tar.gz压缩包命令是 tar –zxvf eclipse-jee-kepler-RC3-linux-gtk.tar.gz得到:eclipse文件夹 4)安装cdt 在终端输入:unzip cdt-master-8.1.2.zip –d cdt,可以把cdt-master-8.1.2.zip解压并且它的内容存放在cdt文件夹下。再输入:cp –r cdt/plugins/ eclipse/,则将cdt下plugins的内容拷贝到eclipse下plugins文件夹。最后,输入cp –r cdt/features/ eclipse/,则将cdt下features的内容拷贝到eclipse下features文件夹。 到现在,安装已经完成。 5)测试Eclipse是否可以工作 直接打开eclipse文件下的eclipse文件,运行弹出窗口,测试成功,否则,不成功,请验证是否安装JDK。按照本章节操作,cetos系统必须提前安装好JDK之类的,否则会出错。 6)eclipse cdt运行c程序报错“launch failed,binary not found” 在CDT中每一次新项目建成后,系统一般默认会进行第一次的构建,也就是自动生成可执行文件。可是事实我们在刚新建的项目甚至还没有源码文 件,所以当然不 会生成可执行的文件了。当我们新建了一个源码文件时,点击执行按钮,就会弹出所说的”launch failed.Binary not found “提示说明(找不到可运行的二进制文件)。 解决办法:窗口左面的项目文件夹上右键鼠标,在弹出的菜单中选择Build Configurations —>Build selected,选择其中的debug或者release进行构建。 7)在应用菜单中添加菜单项—–把eclipse添加到应用菜单中 gnome桌面的所有菜单项都存储如下位置: /usr/share/applications/ 新建一个菜单项,直接在该目录下新建一个后缀名为.desktop的文件即可。 vim /usr/share/applications/c-eclipse.desktop 文件内容如下: [Desktop Entry] Version=1.0 Name=C-Eclipse Icon=/opt/eclipse/icon.xpm Exec=/opt/eclipse/eclipse Terminal=false Type=Application StartupNotify=true Categories=Application;Development;IDE 三、参考文章 1.http://www.centoscn.com/image-text/install/2016/0529/7296.html 2.http://www.360kb.com/kb/2_140.html 3.http://blog.csdn.net/u011345885/article/details/51871435 4.http://www.centoscn.com/CentOS/config/2015/1106/6391.html

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

某android平板项目开发笔记---计划任务备份

前言: 很久,都没更新过这个系列了…因为,除了图表以外,然后就是数据库了,调试了一个多星期的Ormlite数据库,在最新版本中(orm 4.3.3)发现了几个比较严重的bug(例如,查找id的时候无法使用Long类型),不过,还好,ormlite社区还算活跃,bug,已经在预览中修复了.关于Ormlite数据库的话,园子里面已经有了写得很不错的教程了,我就不重复他们的劳动了.然后,数据库搞定了,就是写业务了,有这么一个业务,就是,要求,在某个时间点,对插入的数据进行后台更新,然后,就涉及到了使用计划任务这么一块知识,觉得有必要做下笔记,这块,以后应该也能用到 业务说明: 在某时某刻进行数据库的备份. 相关知识: 1,时间操作 (1) 熟悉使用Calendar 1,作为定时任务,我们需要一个具体的定时时间,以前,我是用Date 类取毫秒数,然后进行计数的操作 1.1例如 //以下为以前的某项目算相隔天数的演示代码 String startDate = mDateStart.getText().toString(); String endDate = year + "-" + (month + 1) + "-" + day; Log.d("soap", startDate + "---" + endDate); DateFormat df = new SimpleDateFormat("yyyy-MM-dd"); // long day=(startC.getTime()-endC.getTime())/(24*60*60*1000); try { Date start = df.parse(startDate); Date end = df.parse(endDate); Long d = (end.getTime() - start.getTime()) / (24 * 60 * 60 * 1000); Log.d("soap", "相隔天数" + d); if (d &gt; 60) { return false; } else { return true; } } catch (ParseException e) { // TODO Auto-generated catch block e.printStackTrace(); } 以前这样写,感觉挺傻的,希望大家不要学习了,这次的业务需求,如果,是以前的话,我会一个创建具体时间字符串,然后用SimpleDateFormat,获取毫秒数,这样个人感觉,很不直观,也麻烦,也不方便国际化,我们用Calendar做就非常简单了. 1.2 定时23:00 执行备份操作 竟然是定时任务,我们就要熟悉一个android的一个用于做定时任务的类 AlarmManager 各位,先去看一下官方文档,在接着看下去吧… 这个类是的初始化是必须要用Context.getSystemService(Context.ALARM_SERVICE). 以下为定时代码块 //初始化定时类 AlarmManager am = (AlarmManager) this.getSystemService(Context.ALARM_SERVICE); //设置定时时间,1分钟后执行 Calendar c = Calendar.getInstance(); c.add(Calendar.MINUTE, 1); //设置时间到了执行的services Intent intent = new Intent(); //创建一个servcies intent.setClass(this, UpdateStatics.class); PendingIntent pi = PendingIntent.getService(this, 0, intent, 0); //设置定时 //需要android.permission.SET_TIME 权限 //第一个参数为定时类型(一共有四种,具体参见官方文档),第二个参数为设置的定时时间为long类型,第三个为执行的目标 am.set(AlarmManager.RTC_WAKEUP, c.getTimeInMillis(), pi); 以上代码就会在,1分钟后,系统执行UpdateStatics 类. 如果,我们要设置具体的时间,只要具体设置Calendar的对象即可,例如23:00分执行 c.set(Calendar.HOUR_OF_DAY, 23); c.set(Calendar.MINUTE, 0); c.set(Calendar.SECOND, 0); 总结: 使用Calendar类操作时间,和进行时间计算,设置,是十分方便的事情, 2,备份操作 1, 建一个接口类用于,监听操作. public interface CompletionListener { void onBackupComplete(); void onRestoreComplete(); void onError(int errorCode); } 2,创建一个异步备份的类 public class BackupTask extends AsyncTask<String, Void, Integer> implements CompletionListener{ //定义常量 public static final int BACKUP_SUCCESS =1; public static final int RESTORE_SUCCESS = 2; public static final int BACKUP_ERROR = 3; public static final int RESTORE_NOFLEERROR = 4; public static final String COMMAND_BACKUP = "backupDatabase"; public static final String COMMAND_RESTORE = "restroeDatabase"; private Context mContext; public BackupTask(Context context){ this.mContext = context; } @Override protected Integer doInBackground(String... params) { //1,获得数据库路径 File dbFile = mContext.getDatabasePath("xxx.db"); //2,创建保存的数据库的路径 File exportDir = new File(Environment.getExternalStorageDirectory(),"shopBackup"); if(!exportDir.exists()){ exportDir.mkdirs(); } File backup = new File(exportDir, dbFile.getName()); //3,检查操作 String command = params[0]; if(command.equals(COMMAND_BACKUP)){ //复制文件 try { backup.createNewFile(); fileCopy(dbFile, backup); return BACKUP_SUCCESS; } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); return BACKUP_ERROR; } }else{ return BACKUP_ERROR; } } private void fileCopy(File source, File dest) throws IOException { FileChannel inChannel = new FileInputStream(source).getChannel(); FileChannel outChannel = new FileOutputStream(dest).getChannel(); // FileInputStream fis = new FileInputStream(dbFile); // FileOutputStream fos = new FileOutputStream(backup); // byte buffer[] = new byte[4 * 1024]; // while(fis.read(buffer) != -1){ // fos.write(buffer); // } // fos.flush(); // long size = inChannel.size(); try { inChannel.transferTo(0, inChannel.size(), outChannel); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); }finally{ if(inChannel != null){ inChannel.close(); } if(outChannel != null){ outChannel.close(); } } } @Override protected void onPostExecute(Integer result) { // TODO Auto-generated method stub super.onPostExecute(result); switch (result) { case BACKUP_SUCCESS: onBackupComplete(); break; default: break; } } @Override public void onBackupComplete() { Log.d("backup", "ok"); } @Override public void onRestoreComplete() { // TODO Auto-generated method stub } @Override public void onError(int errorCode) { // TODO Auto-generated method stub } } 记得,设置好权限: android.permission.WRITE_EXTERNAL_STORAGE AsyncTask<Params,Progress,Result> 这个类的用法,官方文档已经解释的很详细了,这里也不做重复解释. 关于:fileCopy(File source, File dest) 这个方法,我这里改用了Nio 的方式进行操作.用注释注释的代码是一般的方式,这个两者有什么区别呢? 文档 java.nio.channels 类 FileChannel transferTo 里面有这么一句话 与从此通道读取并将内容写入目标通道的简单循环语句相比,此方法可能高效得多。很多操作系统可将字节直接从文件系统缓存传输到目标通道,而无需实际复制各字节。 看到这句话我就使用了这个方法了,然后,为了搞清楚实现的方式,我查看了一下transferTo 的源码只是一个抽象方法,然后,在的FileInputSteam里面找的了channel 的实现方法,不过可惜的,具体的实现代码,我的源码包没有. 然后我顺便比较了java 和 android java 对于获取,channel的区别 java jdk_1.6_u30 默认的fileChannel是用sun包进行实现,然后,关于实现的部分,应该要下个sun包的源码了吧,因为,没找的,就贴不出来了. public FileChannel getChannel() { synchronized (this) { if (channel == null) { channel = FileChannelImpl.open(fd, true, false, this); /* * Increment fd's use count. Invoking the channel's close() * method will result in decrementing the use count set for * the channel. */ fd.incrementAndGetUseCount(); } return channel; } android java getChannel的代码部分 public FileChannel getChannel() { // BEGIN android-changed synchronized(this) { if (channel == null) { channel = FileChannelFactory.getFileChannel(this, fd.descriptor, IFileSystem.O_RDONLY); } return channel; } // END android-changed } android java同样,我的源码包到实现filechannel 部分的代码就没了,对于获取filechannel ,google 是重写了sun那部分的代码了.至于两者的区别,我就不清楚了.有知道的朋友,望告知

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

【Android开发坑系列】如何让Service尽可能存活

流行的思路如下【2015-11-20更新】: 1.让Service杀不死。Service的onStartCommand返回START_STICKY,同时onDestroy里面调用startService启动自身。 2.让Service从后台变成前置。在Android 2.0以前有效,借助setForeground(true)。 3.让某个进程不被系统的low memory killer杀死(如数据缓存进程,或状态监控进程,或远程服务进程)。addandroid:persistent="true"into the <application> section in your AndroidManifest.xml。切记,这个不可滥用,系统中用这个的service,app一多,整个系统就完蛋了。通过实验发现即使设置了这个属性,应用程序被force kill之后还是不能重新启动起来的,应该是只对low memory killer免疫。 4.提升Service优先级。在AndroidManifest.xml文件中对于intent-filter可以通过android:priority = "1000"这个属性设置最高优先级,避免Service被系统回收。 5.定时唤醒,通过AlarmManager。(在Android 4.0之前有效,4.0之后被强杀的APP无法唤醒 参考http://www.android100.org/html/201305/06/2430.html)。 6.当应用升级之后,即使用户不点开APP,也要重启服务。因为升级APP时会发送ACTION_PACKAGE_RESTARTED,AlarmManager作为系统服务,会接受这个事件,然后startService。 7.让Service开机启动。不过现在很多手机会禁止开机启动。 8.守护进程。 参考1:http://www.bubuko.com/infodetail-474019.html 参考2:http://blog.csdn.net/hellogv/article/details/46765387 本文转自Kai的世界,道法自然博客园博客,原文链接:http://www.cnblogs.com/kaima/p/4786814.html,如需转载请自行联系原作者。

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

Android GIS开发系列-- 入门季(2) MapView与图层介绍

一、MapView MapView是Arcgis中的最基本的类,与高德地图SDK的MapView的重要性一样。MapView的创建有两种方法,一种是在Layout文件中直接写控件。一种是实例化,MapView mapView = new MapView(Context context); <com.esri.android.map.MapView android:id="@+id/map" android:layout_width="fill_parent" android:layout_height="fill_parent" /> 1.addLayer(Layerlayer),添加图层。可以添加网络图层与本地图层,tpk文件,shp文件,json数据等。 图层的添加是有顺序的,一层一层叠加,后面的图层会覆盖前面的图层。removeLayer(int index),移除图层。getLayer获取图层,通过顺序id,url地址等获取。 2.setExtent,设置MapView的所显示的范围。 3.zoomin地图缩小,zoomout地图放大。 4.setOnSingleTapListener(OnSingleTapListeneronSingleTapListener),MapView的单击事件,返回的是float screenx, float screeny,屏幕的x与y值,通过toMapPoint(float screenx, float screeny),将屏幕坐标转化为地图坐标。 5.toScreenPoint(Pointsrc),将地图坐标转化屏幕坐标。 6.setOnLongPressListener(OnLongPressListeneronLongPressListener),地图的长按事件,也是返回屏幕的x与y值。 7.getSpatialReference(),获取地图的坐标系,比如84坐标或者是墨卡托等。 8.getLocationDisplayManager(),返回LocationDisplayManager,用于地图定位的显示。 9.getCallout(),返回Callout对象,用于显示气泡弹出 二、图层 Arcgis中的图层有许多,下面是图层的关系表。主要的图层有DynamicLayer,FeatureLayer,GraphicsLayer,GroupLayer,KmlLayer,RasterLayer,TiledLayer。 ,下面的主要来介绍一下Arcgis的主要图层。 1.GraphicLayer,图形图层,只有一个子类ArcGISFeatureLayer。用户通过这个图层可以在MapView中自形绘制要素,通过样式与色彩绘制点、线、面。 2.TiledLayer,切片图层,子类有ArcGISLocalTiledLayer,TiledServiceLayer。ArcGISLocalTiledLayer可以加载本地的tpk文件与切片图层,通过其子类ArcGISTiledMapServiceLayer加载网络的切片图层。 下面的主要来介绍一下Arcgis的主要图层。 1.GraphicLayer,图形图层,只有一个子类ArcGISFeatureLayer。用户通过这个图层可以在MapView中自形绘制要素,通过样式与色彩绘制点、线、面。 2.TiledLayer,切片图层,子类有ArcGISLocalTiledLayer,TiledServiceLayer。ArcGISLocalTiledLayer可以加载本地的tpk文件与切片图层,通过其子类ArcGISTiledMapServiceLayer加载网络的切片图层。 ArcGISLocalTiledLayerlocal=newArcGISLocalTiledLayer("/sdcard/<CacheName>/Layers"); ArcGISLocalTiledLayerlocal=newArcGISLocalTiledLayer("/sdcard/<CacheName>.tpk"); 3.FeatureLayer,要素图层,没有子类,可加载本地shp文件。通过要素的特性,快速查询具体的要素信息。加载快速。 4.DynamicLayer,动态图层。主要有子类ArcGISDynamicMapServiceLayer,ArcGISImageServiceLayer, WMSLayer。前面两个用来加载网络动态图层与网络图像图层。 没有整理与归纳的知识,一文不值!高度概括与梳理的知识,才是自己真正的知识与技能。 永远不要让自己的自由、好奇、充满创造力的想法被现实的框架所束缚,让创造力自由成长吧! 多花时间,关心他(她)人,正如别人所关心你的。理想的腾飞与实现,没有别人的支持与帮助,是万万不能的。 本文转自wenglabs博客园博客,原文链接:http://www.cnblogs.com/arxive/p/7751847.html,如需转载请自行联系原作者

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

Android开发学习笔记:如何移除EditText上的输入焦点

移除EditText上的输入焦点的方法有很多种,下面介绍一种简单实用的方法。 1.先看下面代码的在模拟器上运行的效果 EditTextDemoActivity.java packagecom.android.EditTextDemo.activity; importandroid.app.Activity; importandroid.os.Bundle; publicclassEditTextDemoActivityextendsActivity{ /**Calledwhentheactivityisfirstcreated.*/ @Override publicvoidonCreate(BundlesavedInstanceState){ super.onCreate(savedInstanceState); setContentView(R.layout.main); } } main.xml <?xmlversion="1.0"encoding="utf-8"?> <LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" > <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/hello" /> <EditText android:layout_width="fill_parent" android:layout_height="wrap_content" /> <EditText android:layout_width="fill_parent" android:layout_height="wrap_content" /> </LinearLayout> strings.xml <?xmlversion="1.0"encoding="utf-8"?> <resources> <stringname="hello">HelloEditText!</string> <stringname="app_name">EditTextDemo</string> </resources> 效果图: 这时的光标是在第一个EditText闪烁的,第二个EditText却没有 2.将上面的main.xml改成如下所示,即是将第一个EditText的高度,宽度改为0dp,这样就能覆盖有光标闪烁的第一个EditText,从而达到了移除EditText上的输入焦点的效果 <?xmlversion="1.0"encoding="utf-8"?> <LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" > <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/hello" /> <EditText android:layout_width="0dp" android:layout_height="0dp" /> <EditText android:layout_width="fill_parent" android:layout_height="wrap_content" /> </LinearLayout> 效果图: 本文转自 lingdududu 51CTO博客,原文链接: http://blog.51cto.com/liangruijun/627850

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

开发Android平板电脑程序不能全屏显示问题的解决

调整了Android模拟器得大小为800*480但是,程序跑起来之后发现程序只在中间显示,分辨率任然为手机分辨率,其他地方都是黑屏。 解决方法很简单。在Manifest.xml 中的单独加入这么一句话就好了。 ?[Copy to clipboard] Downloadzuiniuwang.xml <supports-screensandroid:anydensity="true" android:largescreens="true" android:normalscreens="true" android:smallscreens="true"/> 本文转自 最牛傻蛋 51CTO博客,原文链接:http://blog.51cto.com/zuiniuwang/718268,如需转载请自行联系原作者

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

Android开发应用实例:简单计算器+多点触控

这个例子是在一个简单的整型计算器应用了多点触控:一点触控是进行加法运算,两点触控是减法运算,三点触控是乘法运算,四点触控是除法运算。还添加了选项菜单,菜单上的内容有:退出,帮助,清空。 效果图: 具体的代码: MainActivity.java packagecom.lingdududu.test; importandroid.app.Activity; importandroid.app.AlertDialog; importandroid.os.Bundle; importandroid.view.Menu; importandroid.view.MenuItem; importandroid.view.MotionEvent; importandroid.widget.EditText; importandroid.widget.Toast; /** * *@authorlingdududu *这个程序主要是解决简单的整形的四则运算,用户在前两个EditText分别输入被除数,除数, *使用多点触控,一点触控是进行加法运算,两点触控是减法运算, *三点触控是乘法运算,四点触控是除法运算 *触控之后在第三个EditText显示结果 */ publicclassMainActivityextendsActivity{ //定义日志标签 privatestaticfinalStringTag="System.out"; //菜单项ID常量 privatestaticfinalintITEM1=Menu.FIRST; privatestaticfinalintITEM2=Menu.FIRST+1; privatestaticfinalintITEM3=Menu.FIRST+2; privatestaticEditTextfirstEtx,secondEtx,resultEtx; //定义用户输入的两个数 intvalue1,value2; Stringstr; @Override publicvoidonCreate(BundlesavedInstanceState){ super.onCreate(savedInstanceState); setContentView(R.layout.main); //通过findViewById方法获得EditText实例 firstEtx=(EditText)findViewById(R.id.text1); secondEtx=(EditText)findViewById(R.id.text2); resultEtx=(EditText)findViewById(R.id.text3); //计算结果输出的EditText不可编辑 resultEtx.setFocusable(false); } //选项菜单OptionMenu publicbooleanonCreateOptionsMenu(Menumenu){ /*添加菜单项 *android.R使用的是系统自带的图标 */ menu.add(0,ITEM1,0,"退出").setIcon(android.R.drawable.ic_lock_power_off); menu.add(0,ITEM2,0,"帮助").setIcon(android.R.drawable.ic_menu_help); menu.add(0,ITEM3,0,"清空").setIcon(android.R.drawable.ic_menu_close_clear_cancel); returntrue; } //覆盖onOptionsItemSelected(MenuItemitem)来响应菜单选项被单击事件 publicbooleanonOptionsItemSelected(MenuItemitem){ switch(item.getItemId()){ //菜单项1被选择 caseITEM1: //返回主界面 finish(); break; //菜单项2被选择 caseITEM2: //在对话框AlertDialog显示帮助信息 AlertDialog.Builderdialog=newAlertDialog.Builder(this); dialog.setTitle("操作说明信息") .setMessage( "用户在前两个EditText分别输入被除数,除数。一点触控是进行加法运算,两点触控是减法运算,三点触控是乘法运算,四点触控是除法运算。" +"触摸屏幕后,在第三个EditText显示计算的结果,当离开屏幕的时候,显示结果的EditText被清空。" +"点击Menu出现选项菜单,选择清空能清空EditText里面的数据,选择退出能退出程序,回到主界面") .show(); break; //菜单项3被选择 caseITEM3: //清空EditText的数据 firstEtx.setText(""); secondEtx.setText(""); resultEtx.setText(""); break; } returntrue; } publicbooleanonTouchEvent(MotionEventevent){ //TODOAuto-generatedmethodstub //强制类型转换,将String类型转化成int类型 value1=Integer.parseInt(firstEtx.getText().toString()); value2=Integer.parseInt(secondEtx.getText().toString()); //获取触控点的数量,比如2则可能是两个手指同时按压屏幕 intnum=event.getPointerCount(); try{ if(event.getAction()==MotionEvent.ACTION_UP){ resultEtx.setText(""); } //处理多点触控 else{ //一个手指按住屏幕,进行加法运算 if(num==1){ str=String.valueOf(value1+value2); //将计算到的结果添加到第三个EditText resultEtx.setText(str); } elseif(num==2){ str=String.valueOf(value1-value2); //将计算到的结果添加到第三个EditText resultEtx.setText(str); } elseif(num==3){ str=String.valueOf(value1*value2); //将计算到的结果添加到第三个EditText resultEtx.setText(str); } elseif(num==4){ str=String.valueOf(value1/value2); //将计算到的结果添加到第三个EditText resultEtx.setText(str); } else{ } } }catch(Exceptione){ //调用Toast显示出现异常的信息 Toast.makeText(MainActivity.this,"请检查你输入的除数是否正确",Toast.LENGTH_LONG).show(); } returnsuper.onTouchEvent(event); } } main.xml <?xmlversion="1.0"encoding="utf-8"?> <LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" > <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="请输入被除数" /> <EditText android:id="@+id/text1" android:inputType="number" android:layout_width="fill_parent" android:layout_height="wrap_content" /> <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="请输入除数" /> <EditText android:id="@+id/text2" android:inputType="number" android:layout_width="fill_parent" android:layout_height="wrap_content" /> <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="计算的结果为" /> <EditText android:id="@+id/text3" android:inputType="number" android:layout_width="fill_parent" android:layout_height="wrap_content" /> <!--<Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/button" android:text="进行除法运算" />--> </LinearLayout> 本文转自 lingdududu 51CTO博客,原文链接: http://blog.51cto.com/liangruijun/687745

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

【Android游戏开发十二】详解SharedPreference 与 FIleInputStream/FileOutputStream将数...

对于游戏中的数据进行保存方式,在Android中常用的有四种保存方式,这里我先给大家统一先简单的介绍下: 1. SharedPreference 此保存方式试用于简单数据的保存,文如其名属于配置性质的保存,不适合数据比较大的保存方式; 2. 文件存储 (FIleInputStream/FileOutputStream) 此保存方式比较适合游戏的保存和使用,可以保存较大的数据,因为相对于SQLite来说更容易让童鞋们接受,此方式不仅能把数据存储在系统中也能将数据保存到SDcard中; 3.SQLite 此保存方式比较适合游戏的保存和使用,可以保存较大的数据,并且可以将自己的数据存储到文件系统或者数据库当中,也可以将自己的数据存储到SQLite数据库当中,也能将数据保存到SDcard中; 4.ContentProvider (不推荐用于游戏保存) 此保存方式不推荐用于游戏保存,因为此方式不仅能存储较大数据,还支持多个程序之间就的数据进行交换!!! 但是由于游戏中基本就不可能去访问外部应用的数据,所以对于此方式我不予讲解, 有兴趣的可以去自行百度 google 学习; 以上简单的对几种常用的保存方式进行的概述,那么,下面会详细的去分析每个的优缺点以及每种保存的实现和需要注意的地方! 下面我首先向大家介绍第一种保存方式: 保存方式之:《SharedPreference》 优点: 简单、方便、适合简单数据的快速保存 缺点:1.存数的文件只能在同一包内使用,不能在不同包之间使用! 2.默认将数据存放在系统路径下 /data/data/com.himi/ ,没有找到放SD卡上的方法。 总结:其实本保存方式如同它的名字一样是个配置保存,虽然方便,但只适合存储比较简单的数据! main.xml : <?xmlversion="1.0"encoding="utf-8"?> <LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical"android:layout_width="fill_parent" android:layout_height="fill_parent"> <TextViewandroid:layout_width="fill_parent" android:layout_height="wrap_content"android:text="保存数据练习!" android:textSize="20sp"android:textColor="#ff0000"android:id="@+id/tv_title"/> <TextViewandroid:layout_width="fill_parent" android:layout_height="wrap_content"android:text="请输入帐号"/> <EditTextandroid:layout_width="fill_parent" android:layout_height="wrap_content"android:id="@+id/editText_Login" android:text=""></EditText> <TextViewandroid:layout_width="fill_parent" android:layout_height="wrap_content"android:text="请输入密码"/> <EditTextandroid:layout_width="fill_parent" android:layout_height="wrap_content"android:id="@+id/editText_Password" android:text=""></EditText> <Buttonandroid:id="@+id/button_save"android:layout_width="wrap_content" android:layout_height="wrap_content"android:text="保存"></Button> <Buttonandroid:id="@+id/button_load"android:layout_width="wrap_content" android:layout_height="wrap_content"android:text="取出数据" android:visibility="invisible"></Button> </LinearLayout> 先把xml文件放上来的原因是因为我在此篇中介绍的 SharedPreference 和 文件存储 (FIleInputStream/FileOutputStream),都共用此xml,很简单,两个textview 两个 editview 以及两个button,这里就不多说了; 下面是SharedPreference 的代码实现和详细讲解: /** *@authorHimi *@保存方式:SharedPreference *@注意:SharedPreference可以跨程序包使用,多谢二楼童鞋提醒! *@操作模式:Context.MODE_PRIVATE:新内容覆盖原内容 *Context.MODE_APPEND:新内容追加到原内容后 *Context.MODE_WORLD_READABLE:允许其他应用程序读取 *Context.MODE_WORLD_WRITEABLE:允许其他应用程序写入,会覆盖原数据。 */ publicclassMainActivityextendsActivityimplementsOnClickListener{ privateEditTextet_login,et_password; privateButtonbtn_save; privateTextViewtv_title; privateSharedPreferencessp; @Override publicvoidonCreate(BundlesavedInstanceState){ super.onCreate(savedInstanceState); getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); this.requestWindowFeature(Window.FEATURE_NO_TITLE); setContentView(R.layout.main); btn_save=(Button)findViewById(R.id.button_save); btn_save.setOnClickListener(this); et_login=(EditText)findViewById(R.id.editText_Login); et_password=(EditText)findViewById(R.id.editText_Password); tv_title=(TextView)findViewById(R.id.tv_title); //这里我们先调用getSharedPreferences()来实例化一个SharedPreferences, //第二个参数是指:操作模式(上面对各种操作模式已有解释) sp=getSharedPreferences("Setting_himi",MODE_PRIVATE); /* *下面代码是我们要在程序刚启动的时候我们来读取之前的数据, *当然我们还没有保存任何数据所以肯定找不到!! *如果找不到也没关系会默认返回一个参数值,看下面的方法含义便知! */ sp.getString("login",""); //getString()类似哈希表,一个key一个volue, //这个方法如果找不到对应的第一个参数(key),那么将以第二个参数作为此key的返回值 et_login.setText(sp.getString("login","")); et_password.setText(sp.getString("password","")); } @Override publicvoidonClick(Viewv){ if(v==btn_save){ if(et_login.getText().toString().equals("")) tv_title.setText("请输入帐号!"); elseif(et_password.getText().toString().equals("")) tv_title.setText("请输入密码!"); else{ sp.edit() .putString("login",et_login.getText().toString()) .putString("password",et_password.getText().toString()) .commit(); //从sp.edit()开始进入编辑状态,直到commit()提交! tv_title.setText("保存成功!可重新打开此程序,测试是否已经保存数据!"+ "/n(或者在'FileExplorer'窗口下-data-data-com.himi路径下"+ "是否存在"+"了'Setting_himi.xml')"); } } } } 代码中的注释的很清楚了,比较简单,不多说了。 保存方式之: 《文件存储 OutputStream/InputStream》 优点: 1.适合游戏存储,能存储较大数据; 2.不仅能存储到系统中,也能存储到SD卡中! 总结:如果童鞋们对SQL不太熟习的话那么选择此种方式最为合适的啦、嘿嘿 /** *@authorHimi *@保存方式:Stream数据流方式 *@注意1:默认情况下,使用openFileOutput方法创建的文件只能被其调用的应用使用, *其他应用无法读取这个文件,如果需要在不同的应用中共享数据; * *@注意2:因为androidos内部闪存有限,所以适合保存较少的数据,当然我们也有解决的方法, *就是把数据保存在SD开中,这样就可以了,后面我也会向大家讲解! * *@提醒1调用FileOutputStream时指定的文件不存在,Android会自动创建它。 *另外,在默认情况下,写入的时候会覆盖原文件内容,如果想把新写入的内 *容附加到原文件内容后,则可以指定其mode为Context.MODE_APPEND。 * *@提醒2启动程序就初始化的时候一定要注意处理!代码中有注释!一定要仔细看! * *@提醒3这里我给大家讲两种方式,一种是原生态file流来写入/读入, *另外一种是用Data流包装file流进行写入/读入其实用data流来包装进行操作; *原因是:包装后支持了更多的写入/读入操作,比如:file流写入不支持 *writeUTF(Stringstr);但是用Data包装后就会支持。 * *@操作模式:Context.MODE_PRIVATE:新内容覆盖原内容 *Context.MODE_APPEND:新内容追加到原内容后 *Context.MODE_WORLD_READABLE:允许其他应用程序读取 *Context.MODE_WORLD_WRITEABLE:允许其他应用程序写入,会覆盖原数据。 */ publicclassMainActivityextendsActivityimplementsOnClickListener{ privateEditTextet_login,et_password; privateButtonbtn_save; privateTextViewtv_title; privateFileOutputStreamfos; privateFileInputStreamfis; privateDataOutputStreamdos; privateDataInputStreamdis; @Override publicvoidonCreate(BundlesavedInstanceState){ Stringtemp=null; super.onCreate(savedInstanceState); getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); this.requestWindowFeature(Window.FEATURE_NO_TITLE); setContentView(R.layout.main); btn_save=(Button)findViewById(R.id.button_save); btn_save.setOnClickListener(this); et_login=(EditText)findViewById(R.id.editText_Login); et_password=(EditText)findViewById(R.id.editText_Password); tv_title=(TextView)findViewById(R.id.tv_title); try{ //openFileInput不像sharedPreference中 //getSharedPreferences的方法那样找不到会返回默认值, //这里找不到数据文件就会报异常,所以finally里关闭流尤为重要!!! if(this.openFileInput("save.himi")!=null){ //--------------单纯用file来读入的方式----------------- //fis=this.openFileInput("save.himi"); //ByteArrayOutputStreambyteArray=new //ByteArrayOutputStream(); //byte[]buffer=newbyte[1024]; //intlen=0; //while((len=fis.read(buffer))>0){ //byteArray.write(buffer,0,len); //} //temp=byteArray.toString(); //--------------用data流包装后的读入的方式------------ fis=this.openFileInput("save.himi");//备注1 dis=newDataInputStream(fis); et_login.setText(dis.readUTF()); et_password.setText(dis.readUTF()); //这里也是在刚启动程序的时候去读入存储的数据 //读的时候要注意顺序;例如我们写入数据的时候 //先写的字符串类型,我们也要先读取字符串类型,一一对应! } }catch(FileNotFoundExceptione){ //TODOAuto-generatedcatchblock e.printStackTrace(); }catch(IOExceptione){ //TODOAuto-generatedcatchblock e.printStackTrace(); }finally{ //在finally中关闭流!因为如果找不到数据就会异常我们也能对其进行关闭操作; try{ if(this.openFileInput("save.himi")!=null){ //这里也要判断,因为找不到的情况下,两种流也不会实例化。 //既然没有实例化,还去调用close关闭它,肯定"空指针"异常!!! fis.close(); } }catch(FileNotFoundExceptione){ //TODOAuto-generatedcatchblock e.printStackTrace(); }catch(IOExceptione){ //TODOAuto-generatedcatchblock e.printStackTrace(); } } } @Override publicvoidonClick(Viewv){ if(Environment.getExternalStorageState()!=null){ //这个方法在试探终端是否有sdcard! Log.v("Himi","有SD卡"); } if(v==btn_save){ if(et_login.getText().toString().equals("")) tv_title.setText("请输入帐号!"); elseif(et_password.getText().toString().equals("")) tv_title.setText("请输入密码!"); else{ try{ //------单纯用file来写入的方式-------------- //fos=newFileOutputStream(f); //fos.write(et_login.getText().toString().getBytes()); //fos.write(et_password.getText().toString().getBytes()); //------data包装后来写入的方式-------------- fos=this.openFileOutput("save.himi",MODE_PRIVATE);//备注2 dos=newDataOutputStream(fos); dos.writeUTF(et_login.getText().toString()); dos.writeUTF(et_password.getText().toString()); tv_title.setText("保存成功!可重新打开此程序,测试是"+ "否已经保存数据!/n(或者在'FileExplorer'"+ "窗口下-data-data-com.himi-files路径下"+ "是否存在了'save.himi')"); }catch(FileNotFoundExceptione){ //TODOAuto-generatedcatchblock e.printStackTrace(); }catch(IOExceptione){ //TODOAuto-generatedcatchblock e.printStackTrace(); }finally{ //在finally中关闭流这样即使try中有异常我们也能对其进行关闭操作; try{ dos.close(); fos.close(); }catch(IOExceptione){ //TODOAuto-generatedcatchblock e.printStackTrace(); } } } } } } 以上代码中实现了两种流形式来完成写入和读入,这里我们为什么要使用Data流来包装,其实不光是获得更多的操作方式,最主要的是方便快捷,你比如用file来读入的时候,明显的复杂了一些不说,它还一次性把所有数据都取出来了,不便于对数据的处理! 强调的有几点: 1: 在一开始对数据的访问再次提醒童鞋们,这个跟sharedPreference的获取方式不一样,sharedPreference 的获取方式可以得到一个默认的值,但是你用咱们获取的是个文件 而且直接就去open这个文件,一旦不存在必定异常,所以这一块的异常处理,以及finally的处理一定要处理得当。 2.其实在一开始用data包装的时候发现写入的字符串在读入的时候发现字符乱码了,查了api才发现,api规定当写入字符串的时候必须写入UTF-8格式的编码,但是后来不知道怎么了就没事了。 - -、所以这里如果童鞋们遇到此问题,我给出大家一个解决方法,就是在写入的时候我们不要去DataOutputStream 来包装而是用,OutputStreamWriter ,因为在构造的可以设定编码! OutputStreamWriter osw = new OutputStreamWriter(fis,"UTF-8"); String content = EncodingUtils.getString(buffer,"UTF-8"); 这个也能把字符数组转码制! 这样写入的就肯定是UTF-8编码的字符啦、 下面介绍如何把我们的数据通过 OutputStream/InputStream 存入SD卡中! 其实将我们的数据放入SD卡中,无疑就需要对代码进行两处的修改: 注意:一定要有SD卡!对于如何创建SD卡在前一篇文章中已经说了两种方式,不会的童鞋可以去看下; 第一:检查是否装有SD卡; 第二: 修改读入的地方(备注1) fis = this.openFileInput("save.himi"); //这里没有路径,路径是默认的 data-data-com.himi-files下 替换成我们的SD卡的路径就可以了: File path = new File("/sdcard/himi/save.himi");//这里新建一个File目录路径 fis = new FileInputStream(path);传入路径 第三:修改写入的地方(备注2) fos = this.openFileOutput("save.himi", MODE_PRIVATE);这里也是默认路径,需要对其修改, 注意:这里修改了,那么在finally中的判定大家也要对应的适当修改; 注意:如果是系统路径,当没有此文件的时候,android 会默认创建一个!但是我们放入SD卡的时候要自己创建目录路径和文件! if(Environment.getExternalStorageState()!=null){//这个方法在试探终端是否有sdcard! Log.v("Himi","有SD卡"); Filepath=newFile("/sdcard/himi");//创建目录 Filef=newFile("/sdcard/himi/save.himi");//创建文件 if(!path.exists()){//目录不存在返回false path.mkdirs();//创建一个目录 } if(!f.exists()){//文件不存在返回false f.createNewFile();//创建一个文件 } fos=newFileOutputStream(f);//将数据存入sd卡中 } 第四: 因为我们要在SD卡中进行写入的操作,所以要在配置文件中声明权限! AndroidMainfest.xml <?xmlversion="1.0"encoding="utf-8"?> <manifestxmlns:android="http://schemas.android.com/apk/res/android" package="com.himi" android:versionCode="1" android:versionName="1.0"> <applicationandroid:icon="@drawable/icon"android:label="@string/app_name"> <activityandroid:name=".MainActivity" android:label="@string/app_name"> <intent-filter> <actionandroid:name="android.intent.action.MAIN"/> <categoryandroid:name="android.intent.category.LAUNCHER"/> </intent-filter> </activity> </application> <uses-permissionandroid:name="android.permission.WRITE_EXTERNAL_STORAGE"/> <uses-sdkandroid:minSdkVersion="4"/> </manifest> 这一句就是啦~ <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/> 为了让大家看到所放的位置,所以把整个xml放出来供参考; 那么当创建路径和文件的时候,我们对其检查SD卡中是否已经存在exists()方法 ,如果已经存在就不去创建,这样避免下次再次写入数据的时候又新建了文件和路径、 其实我们在可以在启动程序的时候判断如果没有此文件,我们可以直接紧接着创建一个文件,这些都属于优化上的了,我主要是让大家引入,学会,那么其他的简化啦,优化啦,其他方式去实现啦都留给各位同学自己了、 OK、今天就先介绍到这里,后面会单独剖析SQLite如何存入数据,以及对数据操作的! 希望大家继续关注! (推荐大家订阅本博客,因为咱的更新速度可是很快的~娃哈哈) 本篇源码:原文链接:http://www.himigame.com/android-game/327.html 新的一年了小明祝福大家新的一年里,事业顺利,身体健康,全家幸福美满! 上张本项目的截图: 本文转自 xiaominghimi 51CTO博客,原文链接:http://blog.51cto.com/xiaominghimi/606397,如需转载请自行联系原作者

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

手机开发-京东360buy手机版的图片加载

JingDong:When it render the “search result” page ,(every item has the picture) ,it will buffer all the pictures in the SD card to accelerate the display. Tested from Kevin’s emulator, we can see ,that all the images that requested are downloaded intomnt/sdcard/imagefolder. We open it with image tool ,and see that the images are exactly the same that we see from the android client. So next time ,if we want to see the previous item ,we do not need to launch the REST call again ( because it is very slow for 1G /2G network) ,instead ,it only retrieved from the SDCard locally ,which leads to a faster speed. Result analysis: Advantage: obviously reduce the times to send REST request to server and reduce the network traffic. Disadvantage: we need to clear the temp contents (buffered images ,etc) regularly. 本文转自 charles_wang888 51CTO博客,原文链接:http://blog.51cto.com/supercharles888/835920,如需转载请自行联系原作者

资源下载

更多资源
腾讯云软件源

腾讯云软件源

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

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文件系统,支持十年生命周期更新。

WebStorm

WebStorm

WebStorm 是jetbrains公司旗下一款JavaScript 开发工具。目前已经被广大中国JS开发者誉为“Web前端开发神器”、“最强大的HTML5编辑器”、“最智能的JavaScript IDE”等。与IntelliJ IDEA同源,继承了IntelliJ IDEA强大的JS部分的功能。

用户登录
用户注册