首页 文章 精选 留言 我的

精选列表

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

AIDL深入学习

以下两种方式都是基于bindService启动服务。 1)一种简单的实现跨进程的方式(Binder,Messenger) http://www.open-open.com/lib/view/open1469493830770.html 使用Messenger的好处就是如果有多个请求,不会冲突,会将请求放入请求队列中一个一个执行任务。 首先要明确哪个是客户端,哪个是服务端。 Service是声明在服务端工程里的,因为要被客户端工程调用到,所以是隐式声明的: ` <service android:name=".aidl.MessengerServiceDemo" android:enabled="true" android:exported="true"> <intent-filter> <action android:name="com.lypeer.messenger"></action> <category android:name="android.intent.category.DEFAULT"/> </intent-filter> </service> <activity android:name=".aidl.ActivityMessenger"/>` 服务端工程安装好后,开启客户端工程,绑定服务端声明的服务。(服务端服务不一定要事先开启了,声明了即可。) 注意:客户端工程隐式调用服务端开启的那个service,传给intent的包名是服务端的包名,并非自己的包名。 `public class MainActivity extends AppCompatActivity { static final int MSG_SAY_HELLO = 1; Messenger mService = null; boolean mBound; private ServiceConnection mConnection = new ServiceConnection() { public void onServiceConnected(ComponentName className, IBinder service) { //接收onBind()传回来的IBinder,并用它构造Messenger mService = new Messenger(service); mBound = true; } public void onServiceDisconnected(ComponentName className) { mService = null; mBound = false; } }; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); findViewById(R.id.sample_text).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { sayHello(view); } }); } //调用此方法时会发送信息给服务端 public void sayHello(View v) { if (!mBound) return; //发送一条信息给服务端 Message msg = Message.obtain(null, MSG_SAY_HELLO, 1, 2); try { mService.send(msg); } catch (RemoteException e) { e.printStackTrace(); } } @Override protected void onStart() { super.onStart(); //绑定服务端的服务,此处的action是service在Manifests文件里面声明的 Intent intent = new Intent(); intent.setAction("com.lypeer.messenger"); //不要忘记了包名,不写会报错 intent.setPackage("com.example.lianxiang.cmakedemo1"); bindService(intent, mConnection, Context.BIND_AUTO_CREATE); } @Override protected void onStop() { super.onStop(); // Unbind from the service if (mBound) { unbindService(mConnection); mBound = false; } } }` 这样,在客户端就可以操作,实现与服务端工程的一个交互。 Messenger实现的进程间的交互,只是信息的传递,客户端无法直接调用服务端的方法,所以AIDL就是解决的这个问题。 2)AIDLhttp://www.open-open.com/lib/view/open1469493649028.html(上) 按照博主所说的,结果能实现。 2-1)新建aidl文件,注意新建的规则。 2-2)注意aidl及java类的目录的问题,并且保证服务端与客户端都存在aidl与java文件。 2-3)服务端声明service,service里调用aidl自动生成的java类。 2-4)客户端绑定服务端的service,调用aidl转化的类。 本文转自屠夫章哥 51CTO博客,原文链接:http://blog.51cto.com/4259297/2065985,如需转载请自行联系原作者

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

lvm相关命令学习

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 我的博客已迁移到xdoujiang.com请去那边和我交流 基础环境 1、当前版本 cat /etc/debian_version 7.8 2、安装包lvm2 apt-get install lvm2-y 一、将sdbsdcsdd三块分区加到卷组(hadoop),并创建5G的逻辑卷(hadoop1),PE默认 1、使用pvcreate命令将sdbsdcsdd分区创建成物理卷(pvcreate-initializeadiskorpartition for usebyLVM) pvcreate /dev/sdb /dev/sdc /dev/sdd Writingphysicalvolumedatatodisk "/dev/sdb" Physicalvolume "/dev/sdb" successfullycreated Writingphysicalvolumedatatodisk "/dev/sdc" Physicalvolume "/dev/sdc" successfullycreated Writingphysicalvolumedatatodisk "/dev/sdd" Physicalvolume "/dev/sdd" successfullycreated EXAMPLES Initializepartition #4onthethirdSCSIdiskandtheentirefifthSCSIdiskforlaterusebyLVM: pvcreate /dev/sdc4 /dev/sde 2、使用pvs或pvdisplay命令查看 1)pvs(pvs-reportinformationaboutphysicalvolumes) PVVGFmtAttrPSizePFree /dev/sdb lvm2a--10.00g10.00g /dev/sdc lvm2a--10.00g10.00g /dev/sdd lvm2a--10.00g10.00g 2)pvdisplay(pvdisplay-displayattributesofaphysicalvolume) "/dev/sdb" isanewphysicalvolumeof "10.00GiB" ---NEWPhysicalvolume--- PVName /dev/sdb VGName PVSize10.00GiB AllocatableNO PESize0 TotalPE0 FreePE0 AllocatedPE0 PVUUIDOkVC5O-SWOq-daXZ-BrNy-Hy83-G9Sm-d8bMT4 "/dev/sdc" isanewphysicalvolumeof "10.00GiB" ---NEWPhysicalvolume--- PVName /dev/sdc VGName PVSize10.00GiB AllocatableNO PESize0 TotalPE0 FreePE0 AllocatedPE0 PVUUID7vg9eM-pIRR-Ahi0-BNvn-A1pr-WQa0-hvdC9X "/dev/sdd" isanewphysicalvolumeof "10.00GiB" ---NEWPhysicalvolume--- PVName /dev/sdd VGName PVSize10.00GiB AllocatableNO PESize0 TotalPE0 FreePE0 AllocatedPE0 PVUUIDMyPYTC-Vk4P-ltjL-SX6w-jK3V-422c-HACxOK 3、使用vgcreate命令创建hadoop卷组并将sdbsdcsdd加入到卷组里(vgcreate-createavolumegroup) vgcreatehadoop /dev/sdb /dev/sdc /dev/sdd Volumegroup "hadoop" successfullycreated 这里使用默认的PE4MB EXAMPLES Tocreateavolumegroupnamedtest_vgusingphysicalvolumes /dev/sdk1 ,and /dev/sdl1 withdefaultphysicalextentsizeof4MB: vgcreatetest_vg /dev/sdk1 /dev/sdl1 4、使用vgs或vgdisplay命令查看 1)vgs(vgs-reportinformationaboutvolume groups ) VG #PV#LV#SNAttrVSizeVFree hadoop300wz--n-29.99g29.99g 2)vgdisplay(vgdisplay-displayattributesofvolume groups ) ---Volumegroup--- VGNamehadoop SystemID Formatlvm2 MetadataAreas3 MetadataSequenceNo1 VGAccess read /write VGStatusresizable MAXLV0 CurLV0 OpenLV0 MaxPV0 CurPV3 ActPV3 VGSize29.99GiB PESize4.00MiB TotalPE7677 AllocPE/Size0/0 FreePE/Size7677/29.99GiB VGUUID9BpObQ-0qNt-7MRM-cJ4Y-aMyE-5ZEd-GoSi9N 5、使用lvcreate命令创建逻辑卷为hadoop1大小是5G(lvcreatecreatesanewlogicalvolume in avolumegroup) lvcreate-L5G-nhadoop1hadoop Logicalvolume "hadoop1" created -L,--sizeLogicalVolumeSize[bBsSkKmMgGtTpPeE] Givesthesizetoallocate for thenewlogicalvolume.AsizesuffixofK for kilobytes,M for megabytes, G for gigabytes,T for terabytes,P for petabytesorE for exabytesisoptional.Defaultunitismegabytes. 6、使用lvs或lvdisplay命令查看 1)lvs(lvs-reportinformationaboutlogicalvolumes) LVVGAttrLSizePoolOriginData%MoveLogCopy%Convert hadoop1hadoop-wi-a---5.00g 2)lvdisplay(lvdisplay-displayattributesofalogicalvolume) ---Logicalvolume--- LVPath /dev/hadoop/hadoop1 LVNamehadoop1 VGNamehadoop LVUUIDy8CHyc-G7du-h9jZ-XV4T-dvZC-bzv1-NdsbS0 LVWriteAccess read /write LVCreationhost, time debian,2015-06-1223:51:09-0400 LVStatusavailable #open0 LVSize5.00GiB CurrentLE1280 Segments1 Allocationinherit Readaheadsectorsauto -currently set to256 Blockdevice254:0 7、将 /dev/hadoop/hadoop1 格式化成ext4 mkfs.ext4 /dev/hadoop/hadoop1 8、写进 /etc/fatab 中并挂载 /dev/mapper/hadoop-hadoop1 /hadoop ext4defaults00 mount -a 9、查看是否挂载成功 df -Th FilesystemTypeSizeUsedAvailUse%Mountedon rootfsrootfs9.2G1.7G7.1G19%/ udevdevtmpfs10M010M0% /dev tmpfstmpfs99M256K99M1% /run /dev/disk/by-uuid/f730250f-21de-45dd-a3e7-6c5d74508f4b ext49.2G1.7G7.1G19%/ tmpfstmpfs5.0M05.0M0% /run/lock tmpfstmpfs961M0961M0% /run/shm /dev/sda5 ext417G180M16G2% /opt /dev/mapper/hadoop-hadoop1 ext45.0G138M4.6G3% /hadoop 二、将 /dev/mapper/hadoop-hadoop1 逻辑卷夸大到40G并挂载 1、使用pvcreate命令将sde分区创建成物理卷 pvcreate /dev/sde Writingphysicalvolumedatatodisk "/dev/sde" Physicalvolume "/dev/sde" successfullycreated 2、使用vgextend命令将sde加入到卷组hadoop(vgextend-addphysicalvolumestoavolumegroup) vgextendhadoop /dev/sde Volumegroup "hadoop" successfullyextended Examples vgextendvg00 /dev/sda4 /dev/sdn1 triestoextendtheexistingvolumegroupvg00 bythenewphysicalvolumes(seepvcreate(8)) /dev/sdn1 and /dev/sda4 . 3、先查看下卷组有多少PE vgdisplay ---Volumegroup--- VGNamehadoop SystemID Formatlvm2 MetadataAreas4 MetadataSequenceNo8 VGAccess read /write VGStatusresizable MAXLV0 CurLV1 OpenLV1 MaxPV0 CurPV4 ActPV4 VGSize39.98GiB PESize4.00MiB TotalPE10236 AllocPE/Size8956/34.98GiB FreePE/Size1280/5.00GiB VGUUID9BpObQ-0qNt-7MRM-cJ4Y-aMyE-5ZEd-GoSi9N 一共有10236个PE 4、使用lvextend命令将现有逻辑卷为hadoop1增大到40G(lvextend-extendthesizeofalogicalvolume) lvextend-l10236 /dev/hadoop/hadoop1 Extendinglogicalvolumehadoop1to39.98GiB Logicalvolumehadoop1successfullyresized -l,--extents[+]LogicalExtentsNumber[%{VG|LV|PVS|FREE|ORIGIN}] Extendor set thelogicalvolumesize in units oflogicalextents. 5、使用resize2fs命令扩大文件系统(resize2fs-ext2 /ext3/ext4 file systemresizer) resize2fs /dev/hadoop/hadoop1 resize2fs1.42.5(29-Jul-2012) Filesystemat /dev/hadoop/hadoop1 ismountedon /hadoop ;on-lineresizingrequired old_desc_blocks=1,new_desc_blocks=3 Performinganon-lineresizeof /dev/hadoop/hadoop1 to10481664(4k)blocks. Thefilesystemon /dev/hadoop/hadoop1 isnow10481664blockslong. 6、最后检查下是否扩大到40G了 df -Th FilesystemTypeSizeUsedAvailUse%Mountedon rootfsrootfs9.2G1.7G7.1G19%/ udevdevtmpfs10M010M0% /dev tmpfstmpfs99M260K99M1% /run /dev/disk/by-uuid/f730250f-21de-45dd-a3e7-6c5d74508f4b ext49.2G1.7G7.1G19%/ tmpfstmpfs5.0M05.0M0% /run/lock tmpfstmpfs961M0961M0% /run/shm /dev/sda5 ext417G180M16G2% /opt /dev/mapper/hadoop-hadoop1 ext440G143M38G1% /hadoop 三、参考文章 https: //wiki .archlinux.org /index .php /LVM_ %28%E7%AE%80%E4%BD%93%E4%B8%AD%E6%96%87%29 本文转自 xdoujiang 51CTO博客,原文链接:http://blog.51cto.com/7938217/1661595,如需转载请自行联系原作者

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

Hadoop学习笔记一

第一个hands-on入门程序: 参考 http://blog.csdn.net/sim_szm/article/details/12578055 搭建环境并跑WordCount程序,区别是我安装的是最新的hadoop版本0.23.11,JDK我使用的是Sun JDK,Linux使用的是国产的Kylin。 问题一:Error: JAVA_HOME is not set and could not be found. 解决方案: /etc/profile 文件中export JAVA_HOME ${HADOOP_HOME}/libexec/hadoop-config.sh 显式export JAVA_HOME ${HADOOP_HOME}/etc/hadoop/yarn-env.sh显式export JAVA_HOME 问题二:NameNode 没有启动 解决方案: 删除core-site.xml文件中配置的tmp目录 运行 hadoop namenode -format 命令 再运行sbin目录下的start-dfs.sh脚步启动NameNode和datanode 问题三:为何需要SSH 解决方案:Hadoop集 群成员的通讯机制都是使用SSH,即使是单机环境,内部脚本也会运行 ssh localhost进行处理,所以安装SSH是必须的。 本文转自sarchitect 51CTO博客,原文链接:http://blog.51cto.com/stevex/1535193,如需转载请自行联系原作者

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

iOS学习——ViewController(六)

ViewController是iOS应用程序中重要的部分,是应用程序数据和视图之间的重要桥梁,ViewController管理应用中的众多视图。 iOS的SDK中提供很多原生ViewController,以支持标准的用户界面,例如表视图控制器(UITableViewController)、导航控制器(UINavigationController)、标签栏控制器(UITabbarController)和iPad专有的UISplitViewController等。 按结构可以对iOS的所有ViewController分成两类: 1、主要用于展示内容的ViewController,这种ViewController主要用于为用户展示内容,并与用户交互,如UITableViewController,UIViewController。 2、用于控制和显示其他ViewController的ViewController。这种ViewController一般都是一个ViewController的容器。如UINavigationController,UITabbarController。它们都有一个属性:viewControllers。其中UINavigationController表示一种Stack式结构,push一个ViewController或pop一次,因此后一个ViewController一般会依赖前一个ViewController。而UITabbarController表示一个Array结构,各个ViewController是并列的。 ViewController使用 UIViewController可以使用两种方式创建,1、xib方式,2、代码方式 1)xib方式 Command+N 新建文件,选Cocoa Touch UIViewController subclass,SubClass of UIViewController,勾选with XIB for user interface。定义ViewController名字是MainViewController,最终生成MainViewController.h MainViewController.m MainViewController.xib三个文件。在AppDelegate.m文件的 didFinishLaunchingWithOptions方法中加载xib文件。 self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; // Override point for customization after application launch. self.window.backgroundColor = [UIColor whiteColor]; MainUIViewController *vc=[[MainUIViewController alloc]initWithNibName:@"MainUIViewController" bundle:nil]; self.window.rootViewController=vc; [self.window makeKeyAndVisible]; return YES; 加载xib文件后,在xib文件拖拽几个控件可看到效果。 2)代码创建 Command+N 新建文件UIViewController文件,在AppDelegate.m文件的didFinishLaunchingWithOptions方法中使用。在UIViewController的loadView方法中使用代码创建view。 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; // Override point for customization after application launch. self.window.backgroundColor = [UIColor whiteColor]; // MainUIViewController *vc=[[MainUIViewController alloc]initWithNibName:@"MainUIViewController" bundle:nil]; // self.window.rootViewController=vc; RootViewController *rc=[[RootViewController alloc] init]; self.window.rootViewController=rc; [self.window makeKeyAndVisible]; return YES; } 创建View - (void)loadView{ [super loadView]; UIView *view=[[UIView alloc]initWithFrame:[UIScreen mainScreen].applicationFrame]; view.alpha=0.5; view.backgroundColor=[UIColor cyanColor]; self.view=view; } ViewController的生命周期 前面写了iOS应用程序的生命周期,这里会写到ViewController的生命周期,这个更像Android的Activity的生命周期(见文章最后的图)。ViewController生命周期会经历初始化、加载视图、销毁视图、生命结束等过程。 1)init方法 初始化ViewController本身。 2)loadView方法 当view需要被展示而它却是nil时,viewController会调用该方法。 如果代码维护View的话需要重写此方法,使用xib维护View的话不用重写。 3)viewDidLoad方法 执行完loadView后继续执行viewDidLoad,loadView时还没有view,而viewDidLoad时view已经创建好了。 4)viewDidUnload方法 当系统内存吃紧的时候会调用该方法,内存吃紧时,在iPhone OS 3.0之前didReceiveMemoryWarning是释放无用内存的唯一方式,但是OS 3.0及以后viewDidUnload方法是更好的方式。 在该方法中将所有IBOutlet(无论是property还是实例变量)置为nil(系统release view时已经将其release掉了)。 在该方法中释放其他与view有关的对象、其他在运行时创建(但非系统必须)的对象、在viewDidLoad中被创建的对象、缓存数据等。 一般认为viewDidUnload是viewDidLoad的镜像,因为当view被重新请求时,viewDidLoad还会重新被执行。 5)dealloc 释放其他资源或内存。 viewController的生命周期图 ViewController加载view过程,见下图(loadView) 1)loadView ViewController卸载View过程见(unLoadView) 2)unLoadView /** * @author 张兴业 * http://blog.csdn.net/xyz_lmn * iOS入门群: 83702688 * android开发进阶群: 241395671 * 我的新浪微博: @张兴业TBOW */ 参考: https://developer.apple.com/library/ios/#featuredarticles/ViewControllerPGforiPhoneOS/Introduction/Introduction.html#//apple_ref/doc/uid/TP40007457-CH1-SW1 http://xcodev.com/341.html http://iostrack.com/post/2012-07-20/40029700941 Activity生命周期 本文转自xyz_lmn51CTO博客,原文链接: http://blog.51cto.com/xyzlmn/1230733,如需转载请自行联系原作者

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

开始python学习了

今晚折腾了半天,终于在mac上把python开发ide搞好了。 本来是打算使用eclipse+pydev的,结果在eclipse marketplace里面搜索到得pydev插件无法安装,一直是提示网络连接错误。 后面找到Komodo edit,打开之后在界面上没有找到直观的运行和调试python的菜单选项,也放弃了。 接下来,安装了pythonCharm,界面有点类似android studio和eclipse,所以很快就找到了运行和调试菜单项。 所以,就选它了,O(∩_∩)O~。 本文转自leipei博客园博客,原文链接:http://www.cnblogs.com/leipei2352/p/4449132.html,如需转载请自行联系原作者

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

docker学习笔记(1)

(1)Docker介绍 关于Docker的介绍,我就不列举出来了。到百度、谷歌搜索。非常多介绍文章。以下我给出官网的介绍:https://www.docker.com/whatisdocker/ (2)体验Docker Docker官网提供了一个体验的交互教程:https://www.docker.com/tryit/ 想要尝尝鲜的能够去试一试。对docker有个大概了解。 (3)Ubuntu下Docker的安装 不同系统下docker的安装有些不一样,以下我是在ubuntu14.04 x64系统下安装。Docker官方推荐最佳的系统是Ubuntu x64。 $ sudo apt-get update $ sudo apt-get install docker.io $ sudo ln -sf /usr/bin/docker.io /usr/local/bin/docker $ sudo sed -i '$acomplete -F _docker docker' /etc/bash_completion.d/docker.i 假设想要使用最新的Docker,要检查APT系统能处理https,文件 /usr/lib/apt/methods/https 应该存在,假设不存在。则须要安装包 apt-transport-https apt-get update apt-get install apt-transport-https 然后。加入docker repositor $ sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 36A1D7869245C8950F966E92D8576A8BA88D21 $ sudo sh -c "echo deb https://get.docker.io/ubuntu docker main\ > /etc/apt/sources.list.d/docker.list" $ sudo apt-get update $ sudo apt-get install lxc-docker 到这里,docker安装完毕,要检验docker是否成功安装,能够输入以下命令检查: $ sudo docker run -i -t ubuntu /bin/bas 备注:其它操作系统。如Centos、Debian的安装见官网教程:https://docs.docker.com/installation/#installation (4)经常使用命令 在上面的安装完毕后。在终端命令行下输入:docker,会列出非常多命令,以下我列举几个最经常使用的命令。 A、docker images--------------查看images B、docker ps--------------------查看正在执行的container C、docker pull ----------------下载image活repository D、docker commit------------创建新的image E、docker rm-------------------删除container F、docker rmi-------------------删除image G、docker run-----------------在新的container中执行image或command (5)在docker下安装ubuntu A、docker pull ubuntu:14.04 这个命令表示下载ubuntu 14.04版镜像 下载完毕后。我们能够输入docker images查看全部镜像。能够看到我们刚刚下载的ubuntu镜像。 B、执行ubuntu 14.04 镜像 docker run -i -t ubuntu:14.04 输入docker run命令能够查看run下的參数意义。成功执行后,我们会进入例如以下的终端显示界面: b2a2e188ae57表示HOSTNAME。这里你执行的结果可能和我不一样,以下你就能够在这个ubuntu系统下操作。 C、保存操作记录 在进入到虚拟系统后。我们在里面做一些操作,比如在根文件夹下创建一个test.txt文件。 touch test.txt。 然后退出系统:exit。 在下次我们再次执行这个系统时,会发如今根文件夹下不存在test.txt,也就是说我们之前的操作没有保存。要想保存在虚拟系统里的操作。要用到docker commit命令 在我们运行了touch test.txt创建了文件后,使用exit退出系统。 然后输入:docker commit b2a2 ubuntu:14.04,这里b2a2是之前执行的image的标示ID。不用输入所有。仅仅需4个左右字符就可以。 这个命令表示将之前对镜像的操作保存到ubuntu:14.04下。也就是我们执行的镜像,下次再次执行docker run -t -i ubuntu:14.04,就能够看到根文件夹下的test.txt文件。假设想对保存到新的镜像。仅仅需将ubuntu:14.04改成你想要的名称就可以。 如:docker commit b2a2 myubuntu,输入docker iamges。就能够看到myubuntu,当然之前的ubuntu:14.04还在。 參考: (1)https://docs.docker.com/installation/#installation 本文转自mfrbuaa博客园博客,原文链接:http://www.cnblogs.com/mfrbuaa/p/5227674.html,如需转载请自行联系原作者

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

IOS开发博客学习

M了个J :http://www.cnblogs.com/mjios/tag/objective-c/ http://www.cnblogs.com/tianjian/p/3358602.html Cocos2d-x VS环境配置 泰然论坛:http://www.ityran.com/archives/category/cocos2d-iphone 1.http://www.cnblogs.com/zilongshanren/archive/2011/09/19/2181558.html 非常适用的入门教程 2.http://www.cnblogs.com/BigPolarBear/tag/iOS/ 3.一些相应的环境配置,以及简单语法介绍,适合入门 http://blog.csdn.net/xiaominghimi/article/details/6937685 http://blog.csdn.net/sdhjob/article/details/8173176 沈大海 4.Cocos2d-x的使用 http://cocos2d.cocoachina.com/ http://cocos2d.cocoachina.com/resource 重要的博客http://blog.csdn.net/honghaier/article/details/7887873 Cocos2d-x视频教程 http://www.tudou.com/plcover/Yofz8yOj62c/ 5.http://www.cnblogs.com/zilongshanren/archive/2012/02/17/2356516.htm http://www.cnblogs.com/zilongshanren/tag/cocos2d/ 8.http://blog.csdn.net/honghaier/article/details/7887873重点 OC知识点 1.http://rzchina.blog.163.com/blog/#m=0&t=1&c=fks_084069084082083074087082094095085094080066084083087074083 本文转自夏雪冬日博客园博客,原文链接:http://www.cnblogs.com/heyonggang/p/3351269.html,如需转载请自行联系原作者

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

SpringCloud学习资料大全

此篇文章主要整理一些优秀的博客及别人已经整理好的脚手架项目,帮助想用sc(spring cloud简称sc,后文同)而又无处下手的小白快速使用这个高(diao)大(zha)上(tian)的微服务框架。當然如果你對spring boot沒有瞭解的話,建議你先簡單學習一下然後再著手SC。 技术落地方案 http://www.jianshu.com/p/1c0ee18140c2 SC优秀博客 许进 跟我学Spring Cloud 方志朋 Spring Cloud 专栏 程序猿DD liaokailin的专栏 周立 Spring Cloud SpringCloud官方网站 [英文](http://projects.spring.io/spring-cloud/) [中文](https://springcloud.cc/) 推荐github和码云上的sc项目 脚手架项目 SpringCloud-Learning Spring Cloud微服务实战视频教程配套代码 基于 Spring Cloud 的微服务架构 文档类 使用Spring Cloud与Docker实战微服务

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

Android AIDL学习(二)

本文主要写在同一个module中如何使用不同进程的服务。 在测试机的/mnt/sdcard/路径下放一首mp3格式的音乐文件,故音乐文件的路径为/mnt/sdcard/music.mp3。 新建项目,使用默认module,在moudle下新建AIDL文件夹,创建一个AIDL文件IPlayServiceAIDL.aidl,并在文件中添加play()与stop()方法,aidl文件中不可使用private,protected,public等关键词,但返回值要标明,创建好之后点击build->make project来编译工程。 package com.mazaiting.aidldemo2; interface IPlayServiceAIDL { void play(); void stop(); void basicTypes(int anInt, long aLong, boolean aBoolean, float aFloat, double aDouble, String aString); } 在项目的java目录下创建PlayService.java类,并继承Service。在PlayService中的onBind方法中返回一个IBinder对象,这个对象可new IPlayServiceAIDL.Stub()来得到,并实现其中的方法,如果哪个方法你不需要,则可以不实现它。 public class PlayService extends Service { private MediaPlayer mediaPlayer; public PlayService() { } @Override public IBinder onBind(Intent intent) { try{ mediaPlayer = new MediaPlayer(); String path = Environment.getExternalStorageDirectory()+"/music.mp3"; File file = new File(path); FileInputStream fis = new FileInputStream(file); mediaPlayer.setDataSource(fis.getFD()); mediaPlayer.setLooping(true); }catch (Exception e){ e.printStackTrace(); } return mBinder; } private IBinder mBinder = new IPlayServiceAIDL.Stub(){ @Override public void play() throws RemoteException { if (mediaPlayer.isPlaying()){ return; } mediaPlayer.prepareAsync(); mediaPlayer.setOnPreparedListener(new MediaPlayer.OnPreparedListener() { @Override public void onPrepared(MediaPlayer mp) { mediaPlayer.start(); } }); } @Override public void stop() throws RemoteException { if (mediaPlayer.isPlaying()){ mediaPlayer.stop(); } } @Override public void basicTypes(int anInt, long aLong, boolean aBoolean, float aFloat, double aDouble, String aString) throws RemoteException { } }; } 接下来在AndroidManifest.xml文件中对PlayService进行配置,首先先配置一个访问内存卡的权限,其次在service节点内配置android:process=":remote",此语句表示运行在remote进程中,最后在service节点下配置intent-filter,并在intent-filter中配置action,action的name属性就配置为PlayService的包名+类型。 <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> <application android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:supportsRtl="true" android:theme="@style/AppTheme"> <activity android:name=".MainActivity"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <service android:name=".PlayService" android:enabled="true" android:exported="true" android:process=":remote"> <intent-filter> <action android:name="com.mazaiting.aidldemo2.PlayService" /> </intent-filter> </service> </application> 简单的编写MainActivity.java的布局文件,两个水平排列的按钮,一个用于播放音乐,一个用于暂停播放。 <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/activity_main" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="horizontal" > <Button android:id="@+id/btn_start" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="start" /> <Button android:id="@+id/btn_stop" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="stop" /> </LinearLayout> 接下来实现MainActivity.java中的代码,按钮的初始化及设置点击事件不再赘述,在onResume方法中调用bindService对服务进行绑定, 此方法有三个参数,第一个参数为Intent,并为其设置Action,第二个参数为ServiceConnection对象,方法中用于获得AIDL远程调用的对象,第三个方法参数为一个int值,一般设置它为 Context.BIND_AUTO_CREATE。在onPause方法中调用unbindService对绑定的服务进行解绑。点击按钮时分别调用start,stop方法来控制音乐的播放与暂停。 public class MainActivity extends AppCompatActivity implements View.OnClickListener { private static final String ACTION = "com.mazaiting.aidldemo2.PlayService"; private Button btnStart,btnStop; private IPlayServiceAIDL mBinder; private ServiceConnection mConncet = new ServiceConnection() { @Override public void onServiceConnected(ComponentName name, IBinder service) { mBinder = IPlayServiceAIDL.Stub.asInterface(service); } @Override public void onServiceDisconnected(ComponentName name) { mBinder = null; } }; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); initView(); } @Override protected void onResume() { super.onResume(); Intent service = new Intent(ACTION); bindService(service,mConncet, Context.BIND_AUTO_CREATE); } @Override protected void onPause() { super.onPause(); unbindService(mConncet); } private void initView() { btnStart = (Button) findViewById(R.id.btn_start); btnStop = (Button) findViewById(R.id.btn_stop); btnStart.setOnClickListener(this); btnStop.setOnClickListener(this); } @Override public void onClick(View v) { switch (v.getId()){ case R.id.btn_start: try { mBinder.play(); } catch (RemoteException e) { e.printStackTrace(); } break; case R.id.btn_stop: try { mBinder.stop(); } catch (RemoteException e) { e.printStackTrace(); } break; } } }

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

Android AIDL学习(一)

在测试机的/mnt/sdcard/路径下放一首mp3格式的音乐文件,故音乐文件的路径为/mnt/sdcard/music.mp3 在Android Studio中创建一个空的Android项目,在项目下新建client与server两个module。 首先操作server这个module,先创建一个AIDL文件夹,在Studio中可以直接选择AIDL文件夹新建,因此不用考虑文件的路径,直接选择默认的就好,接下来在AIDL文件夹下新建IPlayServiceAIDL.aidl文件,直接选择AIDL文件新建,则可以省去自己写文件中的部分代码。接下来在添加两个方法,一个为play(),一个为stop(),切勿使用private,protected,public来修饰,但必须要写返回值。然后build->make project编译工程。 package com.mazaiting.server; interface IPlayServiceAIDL { void play(); void stop(); void basicTypes(int anInt, long aLong, boolean aBoolean, float aFloat, double aDouble, String aString); } 编译成功后,如下图路径中所示,会生成一个IPlayServiceAIDL文件。 接下来在java的包下创建一个PlayService,创建时最好创建一个Service文件,这样可以少写一些代码。由于本文主要写AIDL的使用,故主要说明AIDL的使用流程,至于如何播放音频,后续再进行讲解。接着在 PlayService中的onBind方法中返回一个IBinder对象,这个IBinder对象是由IPlayServiceAIDL.Stub 创建出来的,IBinder对象创建方法如下: private IBinder mBinder = new IPlayServiceAIDL.Stub(){ @Override public void play() throws RemoteException { } @Override public void stop() throws RemoteException { } @Override public void basicTypes(int anInt, long aLong, boolean aBoolean, float aFloat, double aDouble, String aString) throws RemoteException { } }; 在onBinder方法中将mBinder返回就好。PlayService完整代码如下: public class PlayService extends Service { private MediaPlayer mediaPlayer; public PlayService() { } @Override public IBinder onBind(Intent intent) { try{ mediaPlayer = new MediaPlayer(); String path = Environment.getExternalStorageDirectory()+"/music.mp3"; File file = new File(path); FileInputStream fis = new FileInputStream(file); mediaPlayer.setDataSource(fis.getFD()); mediaPlayer.setLooping(true); }catch (Exception e){ e.printStackTrace(); } return mBinder; } private IBinder mBinder = new IPlayServiceAIDL.Stub(){ @Override public void play() throws RemoteException { if (mediaPlayer.isPlaying()){ return; } mediaPlayer.prepareAsync(); mediaPlayer.setOnPreparedListener(new MediaPlayer.OnPreparedListener() { @Override public void onPrepared(MediaPlayer mp) { mediaPlayer.start(); } }); } @Override public void stop() throws RemoteException { if (mediaPlayer.isPlaying()){ mediaPlayer.stop(); } } @Override public void basicTypes(int anInt, long aLong, boolean aBoolean, float aFloat, double aDouble, String aString) throws RemoteException { } }; } 打开server这个module中的AndroidManifest.xml,并配置清单文件。 首先需要配置访问内存卡权限android.permission.READ_EXTERNAL_STORAGE,其次需要在service节点中配置android:process=":remote" 属性,表示运行在单独的进程,并在service节点下intent-filter中配置action为com.mazaiting.server.PlayService。配置清单如下: <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/> <application android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:supportsRtl="true" android:theme="@style/AppTheme"> <service android:name=".PlayService" android:process=":remote" android:enabled="true" android:exported="true"> <intent-filter> <action android:name="com.mazaiting.server.PlayService"/> </intent-filter> </service> </application> 6.接下来操作client这个module,在client中创建AIDL文件夹,将server中的IPlayServiceAIDL.adil文件拷贝到client的AIDL文件夹中,拷贝时注意文件的包名,路径一定要相同。如图: 目录结构 注意观察两个aidl文件夹下的包名及文件,是完全相同的。 7.在java中创建MainActivity.java,并创建activity_main.xml布局文件,其中布局文件内容为: <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/activity_main" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="horizontal" tools:context="com.mazaiting.aidldemo1.MainActivity" > <Button android:id="@+id/btn_start" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="start" /> <Button android:id="@+id/btn_stop" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="stop" /> </LinearLayout> 接下来编写Activity中的代码,远程调用时我们需要调用boolean bindService(Intent service, ServiceConnection conn, int flags)方法来进行绑定,其中Intent 为其设置PlayService的action,ServiceConncetion的创建代码如下: private ServiceConnection mConncet = new ServiceConnection() { @Override public void onServiceConnected(ComponentName name, IBinder service) { mBinder = IPlayServiceAIDL.Stub.asInterface(service); } @Override public void onServiceDisconnected(ComponentName name) { mBinder = null; } }; mBinder是一个IPlayServiceAIDL对象,在onResume中调用bindService,在onPause中调用unbindService来解除绑定。 MainActivity中的全部代码如下: public class MainActivity extends AppCompatActivity implements View.OnClickListener { private static final String ACTION = "com.mazaiting.server.PlayService"; private Button btnStart,btnStop; private IPlayServiceAIDL mBinder; private ServiceConnection mConncet = new ServiceConnection() { @Override public void onServiceConnected(ComponentName name, IBinder service) { mBinder = IPlayServiceAIDL.Stub.asInterface(service); } @Override public void onServiceDisconnected(ComponentName name) { mBinder = null; } }; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); initView(); } @Override protected void onResume() { super.onResume(); Intent service = new Intent(ACTION); bindService(service,mConncet, Context.BIND_AUTO_CREATE); } @Override protected void onPause() { super.onPause(); unbindService(mConncet); } private void initView() { btnStart = (Button) findViewById(R.id.btn_start); btnStop = (Button) findViewById(R.id.btn_stop); btnStart.setOnClickListener(this); btnStop.setOnClickListener(this); } @Override public void onClick(View v) { switch (v.getId()){ case R.id.btn_start: try { mBinder.play(); } catch (RemoteException e) { e.printStackTrace(); } break; case R.id.btn_stop: try { mBinder.stop(); } catch (RemoteException e) { e.printStackTrace(); } break; } } }

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

Android Animation学习笔记

关于动画的实现,Android提供了Animation,在Android SDK介绍了2种Animation模式: 1. Tween Animation:通过对场景里的对象不断做图像变换(平移、缩放、旋转)产生动画效果,即是一种渐变动画; 2. Frame Animation:顺序播放事先做好的图像,是一种画面转换动画。 动画类型 下面先来看看Android提供的动画类型。Android的animation由四种类型组成 在XML文件中: alpha 渐变透明度动画效果 scale 渐变尺寸伸缩动画效果 translate 画面转换位置移动动画效果 rotate 画面转移旋转动画效果 在Java 源码中定义了相应的类,可以使用这些类的方法来获取和操作相应的属性: AlphaAnimation渐变透明度动画效果 ScaleAnimation渐变尺寸伸缩动画效果 TranslateAnimation画面转换位置移动动画效果 RotateAnimation画面转移旋转动画效果 Tween Animation 一个tween动画将对视图对象中的内容进行一系列简单的转换(位置,大小,旋转,透明性)。如果你有一个文本视图对象,你可以移动它,旋转它,让它变大或让它变小,如果文字下面还有背景图像,背景图像也会随着文件进行转换。 使用XML来定义Tween Animation 动画的XML文件在工程中res/anim目录,这个文件必须包含一个根元素,可以使<alpha><scale> <translate> <rotate>插值元素或者是把上面的元素都放入<set>元素组中,默认情况下,所以的动画指令都是同时发生的,为了让他们按序列发生,需要设置一个特殊的属性startOffset。动画的指令定义了你想要发生什么样的转换,当他们发生了,应该执行多长时间,转换可以是连续的也可以使同时的。例如,你让文本内容从左边移动到右边,然后旋转180度,或者在移动的过程中同时旋转,没个转换需要设置一些特殊的参数(开始和结束的大小尺寸的大小变化,开始和结束的旋转角度等等,也可以设置些基本的参数(例如,开始时间与周期),如果让几个转换同时发生,可以给它们设置相同的开始时间,如果按序列的话,计算开始时间加上其周期。 Tween Animation共同的节点属性 属性[类型] 功能 备注 Duration[long] 属性为动画持续时间 时间以毫秒为单位 fillAfter [boolean] 当设置为true ,该动画转化在动画结束后被应用 fillBefore[boolean] 当设置为true ,该动画转化在动画开始前被应用 interpolator 指定一个动画的插入器 有一些常见的插入器 accelerate_decelerate_interpolator 加速-减速 动画插入器 accelerate_interpolator 加速-动画插入器 decelerate_interpolator 减速- 动画插入器 其他的属于特定的动画效果 repeatCount[int] 动画的重复次数 RepeatMode[int] 定义重复的行为 1:重新开始 2:plays backward startOffset[long] 动画之间的时间间隔,从上次动画停多少时间开始执行下个动画 zAdjustment[int] 定义动画的Z Order的改变 0:保持Z Order不变 1:保持在最上层 -1:保持在最下层 表二 XML节点 功能说明 alpha 渐变透明度动画效果 <alpha android:fromAlpha=”0.1″ android:toAlpha=”1.0″ android:duration=”3000″ /> fromAlpha 属性为动画起始时透明度 0.0表示完全透明 1.0表示完全不透明 以上值取0.0-1.0之间的float数据类型的数字 duration为动画持续时间,ms单位 toAlpha 属性为动画结束时透明度 表三 scale 渐变尺寸伸缩动画效果 <scale android:interpolator= “@android:anim/accelerate_decelerate_interpolator” android:fromXScale=”0.0″ android:toXScale=”1.4″ android:fromYScale=”0.0″ android:toYScale=”1.4″ android:pivotX=”50%” android:pivotY=”50%” android:fillAfter=”false” android:startOffset=“700” android:duration=”700″ android:repeatCount=”10″ /> fromXScale[float] fromYScale[float] 为动画起始时,X、Y坐标上的伸缩尺寸 0.0表示收缩到没有 1.0表示正常无伸缩 值小于1.0表示收缩 值大于1.0表示放大 toXScale [float] toYScale[float] 为动画结束时,X、Y坐标上的伸缩尺寸 pivotX[float] pivotY[float] 为动画相对于物件的X、Y坐标的开始位置 属性值说明:从0%-100%中取值,50%为物件的X或Y方向坐标上的中点位置 表四 translate 画面转换位置移动动画效果 <translate android:fromXDelta=”30″ android:toXDelta=”-80″ android:fromYDelta=”30″ android:toYDelta=”300″ android:duration=”2000″ /> fromXDelta toXDelta 为动画、结束起始时 X坐标上的位置 fromYDelta toYDelta 为动画、结束起始时 Y坐标上的位置 表五 rotate 画面转移旋转动画效果 <rotate android:interpolator=”@android:anim/accelerate_decelerate_interpolator” android:fromDegrees=”0″ android:toDegrees=”+350″ android:pivotX=”50%” android:pivotY=”50%” android:duration=”3000″ /> fromDegrees 为动画起始时物件的角度 说明 当角度为负数——表示逆时针旋转 当角度为正数——表示顺时针旋转 (负数from——to正数:顺时针旋转) (负数from——to负数:逆时针旋转) (正数from——to正数:顺时针旋转) (正数from——to负数:逆时针旋转) toDegrees 属性为动画结束时物件旋转的角度 可以大于360度 pivotX pivotY 为动画相对于物件的X、Y坐标的开始位 说明:以上两个属性值 从0%-100%中取值 50%为物件的X或Y方向坐标上的中点位置 下面给出一个完整的XML定义(SDK提供) <set android:shareInterpolator="false" xmlns:android="http://schemas.android.com/apk/res/android"> <scale android:interpolator="@android:anim/accelerate_decelerate_interpolator" android:fromXScale="1.0" android:toXScale="1.4" android:fromYScale="1.0" android:toYScale="0.6" android:pivotX="50%" android:pivotY="50%" android:fillAfter="false" android:duration="700" /> <set android:interpolator="@android:anim/decelerate_interpolator"> <scale android:fromXScale="1.4" android:toXScale="0.0" android:fromYScale="0.6" android:toYScale="0.0" android:pivotX="50%" android:pivotY="50%" android:startOffset="700" android:duration="400" android:fillBefore="false" /> <rotate android:fromDegrees="0" android:toDegrees="-45" android:toYScale="0.0" android:pivotX="50%" android:pivotY="50%" android:startOffset="700" android:duration="400" /> </set> </set> Tween Animation如何使用 使用AnimationUtils类的静态方法loadAnimation()来加载XML中的动画XML文件 //main.xml中的ImageView ImageView spaceshipImage = (ImageView) findViewById(R.id.spaceshipImage); //加载动画 Animation hyperspaceJumpAnimation =AnimationUtils.loadAnimation(this, R.anim.hyperspace_jump); //使用ImageView显示动画 spaceshipImage.startAnimation(hyperspaceJumpAnimation); 如何在Java代码中定义动画 //在代码中定义 动画实例对象 private Animation myAnimation_Alpha; private Animation myAnimation_Scale; private Animation myAnimation_Translate; private Animation myAnimation_Rotate; //根据各自的构造方法来初始化一个实例对象 myAnimation_Alpha=new AlphaAnimation(0.1f, 1.0f); myAnimation_Scale =new ScaleAnimation(0.0f, 1.4f, 0.0f, 1.4f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f); myAnimation_Translate=new TranslateAnimation(30.0f, -80.0f, 30.0f, 300.0f); myAnimation_Rotate=new RotateAnimation(0.0f, +350.0f, Animation.RELATIVE_TO_SELF,0.5f,Animation.RELATIVE_TO_SELF, 0.5f); interpolator的解释 interpolator定义一个动画的变化率(the rate of change)。这使得基本的动画效果(alpha, scale, translate, rotate)得以加速,减速,重复等。 Interpolator 定义了动画的变化速度,可以实现匀速、正加速、负加速、无规则变加速等。Interpolator 是基类,封装了所有 Interpolator 的共同方法,它只有一个方法,即 getInterpolation (float input),该方法 maps a point on the timeline to a multiplier to be applied to the transformations of an animation。Android 提供了几个 Interpolator 子类,实现了不同的速度曲线,如下: AccelerateDecelerateInterpolator 在动画开始与介绍的地方速率改变比较慢,在中间的时候加速 AccelerateInterpolator 在动画开始的地方速率改变比较慢,然后开始加速 CycleInterpolator 动画循环播放特定的次数,速率改变沿着正弦曲线 DecelerateInterpolator 在动画开始的地方速率改变比较慢,然后开始减速 LinearInterpolator 在动画的以均匀的速率改变 Frame Animation Frame Animation是顺序播放事先做好的图像,跟电影类似。不同于animation package, Android SDK提供了另外一个类AnimationDrawable来定义、使用Frame Animation。 Frame Animation可以在XML Resource定义(还是存放到res\anim文件夹下),也可以使用AnimationDrawable中的API定义。由于Tween Animation与Frame Animation有着很大的不同,因此XML定义的格式也完全不一样,其格式是:首先是animation-list根节点,animation-list根节点中包含多个item子节点,每个item节点定义一帧动画,当前帧的drawable资源和当前帧持续的时间。下面对节点的元素加以说明: XML属性 说明 drawable 当前帧引用的drawable资源 duration 当前帧显示的时间(毫秒为单位) oneshot 如果为true,表示动画只播放一次停止在最后一帧上,如果设置为false表示动画循环播放。 variablePadding If true, allows the drawable’s padding to change based on the current state that is selected. visible 规定drawable的初始可见性,默认为flase; 下面就给个具体的XML例子,来定义一帧一帧的动画: <animation-list xmlns:android="http://schemas.android.com/apk/res/android" android:oneshot="true"> <item android:drawable="@drawable/rocket_thrust1" android:duration="200" /> <item android:drawable="@drawable/rocket_thrust2" android:duration="200" /> <item android:drawable="@drawable/rocket_thrust3" android:duration="200" /></animation-list> 上面的XML就定义了一个Frame Animation,其包含3帧动画,3帧动画中分别应用了drawable中的3张图片:rocket_thrust1,rocket_thrust2,rocket_thrust3,每帧动画持续200毫秒。 然后我们将以上XML保存在res/anim/文件夹下,命名为rocket_thrust.xml,显示动画的代码: AnimationDrawable rocketAnimation;public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); ImageView rocketImage = (ImageView) findViewById(R.id.rocket_image); rocketImage.setBackgroundResource(R.anim.rocket_thrust); rocketAnimation = (AnimationDrawable) rocketImage.getBackground();}public boolean onTouchEvent(MotionEvent event) { if (event.getAction() == MotionEvent.ACTION_DOWN) { rocketAnimation.start(); return true; } return super.onTouchEvent(event);} 代码运行的结果:3张图片按照顺序的播放一次. 有一点需要强调的是:启动Frame Animation动画的代码rocketAnimation.start();不能在OnCreate()中,因为在OnCreate()中AnimationDrawable还没有完全的与ImageView绑定,在OnCreate()中启动动画,就只能看到第一张图片。这里实在拖曳事件中实现的。 下面,阅读Android SDK中对AnimationDrawable的介绍,有个简单的了解: AnimationDrawable 获取、设置动画的属性 int getDuration() 获取动画的时长 int getNumberOfFrames() 获取动画的帧数 boolean isOneShot() Void setOneShot(boolean oneshot) 获取oneshot属性 设置oneshot属性 void inflate(Resurce r,XmlPullParser p, AttributeSet attrs) 增加、获取帧动画 Drawable getFrame(int index) 获取某帧的Drawable资源 void addFrame(Drawable frame,int duration) 为当前动画增加帧(资源,持续时长) 动画控制 void start() 开始动画 void run() 外界不能直接掉调用,使用start()替代 boolean isRunning() 当前动画是否在运行 void stop() 停止当前动画 本文转自feisky博客园博客,原文链接:http://www.cnblogs.com/feisky/archive/2010/01/11/1644482.html,如需转载请自行联系原作者

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

Android Service学习笔记

一 什么是Service 服务是运行在后台的一段代码。它可以运行在它自己的进程,也可以运行在其他应用程序进程的上下文(context)里面,这取决于自身的需要。其它的组件可以绑定到一个服务(Service)上面,通过远程过程调用(RPC)来调用这个方法。例如媒体播放器的服务,当用户退出媒体选择用户界面,仍然希望音乐依然可以继续播放,这时就是由服务(service)来保证当用户界面关闭时音乐继续播放的。 它跟Activity的级别差不多,但是他不能自己运行,需要通过某一个Activity或者其他Context对象来调用,Context.startService()和Context.bindService()。两种启动Service的方式有所不同。这里要说明一下的是如果你在Service的onCreate或者onStart做一些很耗时间的事情,最好在Service里启动一个线程来完成,因为Service是跑在主线程中,会影响到你的UI操作或者阻塞主线程中的其他事情。什么时候需要Service呢?比如播放多媒体的时候用户启动了其他Activity这个时候程序要在后台继续播放,比如检测SD卡上文件的变化,再或者在后台记录你地理信息位置的改变等等。 二 如何使用Service 1.第一种是通过调用Context.startService()启动,调用Context.stopService()结束,startService()可以传递参数给Service。 2.第二种方式是通过调用Context.bindService()启动,调用Context.unbindservice()结束,还可以通过ServiceConnection访问Service。 二者可以混合使用,比如说我可以先startService再bindservice。 三 service生命周期 startService后,即使调用startService的进程结束了,Service仍然还存在,直到有进程调用stopService,或者Service自己自杀(stopSelf())。bindService后,Service就和调用bindService的进程同生共死了,也就是说当调用bindService的进程死了,那么它bind的Service也要跟着被结束,当然期间也可以调用unbindservice让Service结束。 两种方式混合使用时,比如说你startService了,我bindService了,那么只有你stopService了而且也unbindservice了,这个Service才会被结束。 Android系统将会尝试保留那些启动了的或者是绑定了服务的进程。如果该服务正在进程的onCreate(), onStart(),或者onDestroy()这些方法中执行时,那么主进程将会成为一个前台进程,以确保此代码不会被停止。如果服务已经开始,那么它的主进程会就重要性而言低于所有可见的进程但高于不可见的进程,由于只有少数几个进程是用户可见的,所以只要不是内存特别低,该服务不会停止.。如果有多个客户端绑定了服务,只要客户端中的一个对于用户是可见的,即认为该服务可见。 如果Service还没有运行,则android先调用onCreate()然后调用onStart();如果Service已经运行,则只调用onStart(),所以一个Service的onStart方法可能会重复调用多次。 stopService的时候直接onDestroy,如果是调用者自己直接退出而没有调用stopService的话,Service会一直在后台运行。该Service的调用者再启动起来后可以通过stopService关闭Service。 所以调用startService的生命周期为:onCreate --> onStart(可多次调用) --> onDestroy 使用context.bindService()启动Service会经历: context.bindService()->onCreate()->onBind()->Service running onUnbind() -> onDestroy() ->Service stop onBind将返回给客户端一个IBind接口实例,IBind允许客户端回调服务的方法,比如得到Service运行的状态或其他操作。这个时候把调用者(Context,例如Activity)会和Service绑定在一起,Context退出了,Srevice就会调用onUnbind->onDestroy相应退出。 所以调用bindService的生命周期为:onCreate --> onBind(只一次,不可多次绑定) --> onUnbind --> onDestory。 所以,在Service每一次的开启关闭过程中,只有onStart可被多次调用(通过多次startService调用),其他onCreate,onBind,onUnbind,onDestory在一个生命周期中只能被调用一次。 本文转自feisky博客园博客,原文链接:http://www.cnblogs.com/feisky/archive/2010/06/14/1758336.html,如需转载请自行联系原作者

资源下载

更多资源
优质分享App

优质分享App

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

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应用均可从中受益。

Sublime Text

Sublime Text

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

用户登录
用户注册
修改密码
忘记密码