首页 文章 精选 留言 我的

精选列表

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

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,如需转载请自行联系原作者

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

docker学习 - docker run

docker run流程 创建容器 通过用户指定的镜像名和tag,在TagStore中查找image_id,获取image对象(本地的image json文件里有镜像信息) 检查镜像layer数(不超过127),镜像层数太多会造成性能问题 将runconfig.Config和image.Config合并 创建{Container.ID}-init和Container.ID镜像的目录,在init layer创建.dockerinit、/etc/hosts、/etc/hostname等, Container.ID镜像是read-write layer 将Container对象持久化到path.Join(Container.ID, “config.json”) 在Daemon.idIndex中注册Container.ID,在Daemon.contSt

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

MaxCompute 学习计划(三)

MapReduce/Graph 当业务逻辑实在是复杂的时候,用SQL配合UDF(包括UDAF和UDTF)也无法实现的时候,可以使用MapReduce或Graph来实现。 作业 MapReduce MapReduce文档里的十多个示例程序每个都很重要,务必每个都看懂每行代码的作用。参考链接文档。 使用Eclipse / InteliJ IDEA配置开发环境,可以修改warehouse里的数据然后观察任务的运行结果的变化。 并用客户端工具运行任务,并了解-classpath和-resources参数的区别。 通过System.out和System.err输出日志信息,并使用Logview观察服务器上的日志。 使用开发工具开发实现开窗函数。 了解沙箱。 数加的大数据开发套件里的Open MR里的每个配置,对应到MR的main函数里是什么?可以参考SDK的说

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

Python 学习笔记 - Memcached

Memcached是一个分布式内存对象缓存系统,他把数据缓存在内存里面来减少对数据库的访问,从而提高动态网页的访问速度。他的基本结构是key/value(键值对)。下面看看在Python里面如何使用。 首先来安装一下服务器端,豆子直接在一个CentOS7的机器上安装 [root@sydnagios~]#yuminstallmemcachedLoadedplugins:fastestmirror,langpacksRepodataisover2weeksold.Installyum-cron?Orrun:yummakecachefastbase|3.6kB00:00epel/x86_64/metalink|2.0kB00:00epel|4.3kB00:00extras|3.4kB00:00updates|3.4kB00:00(1/5):epel/x86_64/group_gz|170kB00:00(2/5):epel/x86_64/updateinfo|671kB00:00 然后服务器端跑起来,这个里面我指定的端口是12000,因此如果有防火墙别忘记打开对应端口 [root@sydnagios~]#memcached-d-m10-uroot-l10.2.1.107-p12000-c256-P/tmp/memcached.pid 参数说明: - d 是启动一个守护进程 - m 是分配给Memcache使用的内存数量,单位是MB - u 是运行Memcache的用户 - l 是监听的服务器IP地址 - p 是设置Memcache监听的端口,最好是 1024 以上的端口 - c 选项是最大运行的并发连接数,默认是 1024 ,按照你服务器的负载量来设定 - P 是设置保存Memcache的pid文件 打开防火墙端口 firewall-cmd--add-port=12000/tcp--permanent 接下来安装Python的客户端模块 从这里下载https://pypi.python.org/pypi/python-memcached 解压拷贝到sys.path对应的目录,就能直接用了 看看第一个例子,可以通过set来设置数据,get来获取数据。里面debug是为了显示错误的 生产环境里面不要用 #!/usr/bin/envpython#-*-coding:utf-8-*-#AuthorYuanLiimportmemcachemc=memcache.Client(['10.2.1.107:12000'],debug=True)mc.set("foo","bar")mc.add("name","John")print(mc.get('foo'))print(mc.get('name'))-----------barJohn memcached的第二个特点是他默认支持集群,原理是内存里面创建一个主机的列表;每个主机有一个权重,权重的数目和主机在列表里面出现的数目成正比。通过算法可以决定把键值对放在哪个服务器的内存里面。 例2 mc=memcache.Client([('1.1.1.1:12000',1),('1.1.1.2:12000',2),('1.1.1.3:12000',1)],debug=True)mc.set('k1','v1') 除了get和set以外,他还具有以下常用函数 add添加一条键值对,如果已经存在的 key,重复执行add操作异常 replacereplace 修改某个key的值,如果key不存在,则异常 set 和 set_multi set 设置一个键值对,如果key不存在,则创建,如果key存在,则修改set_multi 设置多个键值对,如果key不存在,则创建,如果key存在,则修改 delete 和 delete_multi delete 在Memcached中删除指定的一个键值对delete_multi 在Memcached中删除指定的多个键值对 append 和 prepend append 修改指定key的值,在该值 后面 追加内容prepend 修改指定key的值,在该值 前面 插入内容 decr 和 incr incr 自增,将Memcached中的某一个值增加 N ( N默认为1 )decr 自减,将Memcached中的某一个值减少 N ( N默认为1 ) gets 和cas 这个组合可以避免脏数据的产生,如果在gets数据,和cas数据回去这个过程中有其他用户执行了get,那么则不允许修改

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

iOS ARC学习汇总

ARC ARC是什么 ARC是iOS 5推出的新功能,全称叫 ARC(Automatic Reference Counting)。简单地说,就是编译阶段自动做了retain/release,原先需要手动添加的用来处理内存管理的引用计数的代码可以自动地由编译器完成了。就ARC并不是GC,不是运行时内存管理,不会做malloc/free的工作,它只是一种代码静态分析(Static Analyzer)工具。 比如,我们生成一个对象: addretain.png 编译器会给我们添加上retain/release/autorelease add2.png 比如,block的写法,编译器背后给我们做的事: add3.png ARC之前的手工管理内存 我们需要手动retain和 release对象。如下: // First you create an object, which you then own ("retain") // Retain count = 1 Customer *newCustomer = [[Customer alloc] init]; // Next, you do something with the new object, such as add it to an // array, which also now retains it. Retain count = 2 [customerArray addObject:newCustomer]; // When finished with the object, you relinquish (release) ownership. // Retain count = 1 [newCustomer release]; // At some point customerArray is also released, releasing all of the // objects it contains. Retain count = 0, and the original object is // finally deallocated [customerArray release]; 这个过程很容易出错。所以苹果引入ARC,在编译阶段自动帮我们做retain/release的工作,如下图,减少了很多代码。 add4.png 手工引用计数规则 用“alloc”, “new”, “copy”, or “mutableCopy”等方法生成object的时候,object 的引用计数为1. When you create an object, it has a retain count of 1. You create an object using a method whose name begins with “alloc”, “new”, “copy”, or “mutableCopy” (for example, alloc, newObject, or mutableCopy). 向object发送retain消息,它的引用计数+1. When you send an object a retain message, its retain count is incremented by 1. 向object发送release消息,引用计数-1. When you send an object a release message, its retain count is decremented by 1. 向object发送autorelease消息,引用计数-1.当引用计数为0,object被释放 。 When you send an object a autorelease message, its retain count is decremented by 1 at the end of the current autorelease pool block.If an object’s retain count is reduced to zero, it is deallocated. trace_obj.png ARC:自动引用计数 ARC模式下,引用计数的规则还起作用,只是编译器做retain,release,autorelease的工作。 内存管理和引用计数 WWDC Adopting Automatic Reference Counting 翻译 ARC基本规则 参考: Transitioning to ARC Release Notes 规则总结 规则: You cannot explicitly invoke dealloc, or implement or invoke retain, release, retainCount, or autorelease. You cannot use NSAllocateObject or NSDeallocateObject. You cannot use object pointers in C structures. There is no casual casting between id and void *. You cannot use NSAutoreleasePool objects. You cannot use memory zones. You cannot give an accessor a name that begins with new. This in turn means that you can’t, for example, // Won't work: @property NSString *newTitle; // Works: @property (getter=theNewTitle) NSString *newTitle;` Is ARC slow? It depends on what you’re measuring, but generally “no.” The compiler efficiently eliminates many extraneous retain/release calls and much effort has been invested in speeding up the Objective-C runtime in general. In particular, the common “return a retain/autoreleased object” pattern is much faster and does not actually put the object into the autorelease pool, when the caller of the method is ARC code. 引用类型: ARC强引用和弱引用 Strong reference : 强引用指针增加对象引用计数。 Weak reference :弱引用指针不增加对象引用计数,对象被释放后,指针被置为nil 引用关键字: __strong:_strong修饰符表示对对象的“强引用”。持有强引用的变量在超出其作用域时被废弃,随着强引用的失效,引用的对象会随之释放 __weak: 使用_strong修饰符的成员变量在持有对象时,很容易发生循环引用。 循环引用容易发生内存泄露。内存泄露就是应当废弃的对象在超出其生存周期后继续存在。 使用_weak修饰符可以避免循环引用。_weak修饰符还有另一有优点。在持有某对象的弱引用时,若该对象被废弃,则此弱引用将自动失效且处于nil被赋值的状态(空弱引用)。 __unsafe_unretained__ autoreleasing 使用关键字的格式,关键字在*号之后 MyClass * __weak myWeakReference; MyClass * __unsafe_unretained myUnsafeReference; 循环引用 三种循环引用的模式: 对象之间有“父子关系 Delegate模式 Blocks 解决方法: ARC循环引用 管理Autorelease Pools @autoreleasepool-内存的分配与释放 https://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/MemoryMgmt/Articles/mmAutoreleasePools.html#//apple_ref/doc/uid/20000047-CJBFBEDI 使用autorelease pool 的场景: 程序不基于 UI framework. If you are writing a program that is not based on a UI framework, such as a command-line tool. 在循环中生成大量的临时变量,可以在for循环中用autorelease pool block。 If you write a loop that creates many temporary objects. You may use an autorelease pool block inside the loop to dispose of those objects before the next iteration. Using an autorelease pool block in the loop helps to reduce the maximum memory footprint of the application. Cocoa application中的每个线程维护自己的 autorelease pool block堆栈,所以开子线程需要生成自己的autorelease pool block. You must create your own autorelease pool block as soon as the thread begins executing; otherwise, your application will leak objects. (See Autorelease Pool Blocks and Threads for details.) 对象转换 在iOS世界,主要有两种对象:Objective-C 对象和 Core Foundation 对象0。Core Foundation 对象主要是有C语言实现的 Core Foundation Framework 的对象,其中也有对象引用计数的概念,只是不是 Cocoa Framework::Foundation Framework 的 retain/release,而是自身的 CFRetain/CFRelease 接口。 这两种对象间可以互相转换和操作,不使用ARC的时候,单纯的用C原因的类型转换,不需要消耗CPU的资源,所以叫做 Toll-Free bridged 对象转换 Transitioning to ARC Release Notes __bridge` transfers a pointer between Objective-C and Core Foundation with no transfer of ownership. __bridge_retained or CFBridgingRetain casts an Objective-C pointer to a Core Foundation pointer and also transfers ownership to you. You are responsible for calling CFRelease or a related function to relinquish ownership of the object. __bridge_transfer or CFBridgingRelease moves a non-Objective-C pointer to Objective-C and also transfers ownership to ARC. ARC is responsible for relinquishing ownership of the object. 易飞扬,ARC系列 理解ARC强引用和弱引用指针类型 BeginARC WWDC Adopting Automatic Reference Counting 内存管理和引用计数

资源下载

更多资源
优质分享App

优质分享App

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

Mario

Mario

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

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

用户登录
用户注册