What is ThreadLocal

一、ThreadLocal是一个线程内部的数据存储类,只能在指定的线程存取数据。

二、只有三个方法

1
public class ThreadLocal<T>{
	public void set(T value){
		...
	}
	public T get(){
		...
	}
	protected T initialValue(){
		...
	}

}

三、内部实现大概如下:

1
private Map<Thread,Integer> threadData = new HashMap<Thread,Integer>();//内部维护一个装线程和数据的Map

threadData.put(Thread.currentThread(),data);//将线程及对应的数据装入

与synchronized

1、都是为了解决多线程中对数据访问的安全性问题。

2、synchronized采用了“以时间换空间”的方式,ThreadLocal采用了“以空间换时间”的方式。

一、define a annotation

1
@Target(ElementType.FIELD)
@Retention(RetentionPolicy.RUNTIME) 
public @interface ViewInject {  
  	int value() default 0 ;  
}

二、use the annotation

1

@ViewInject(R.id.tv_name)
private TextView myTextView;

三、parse the annotation

1
public void parseAnnotation(Class<?>  clazz) {  	//传一个类进来
    	try {  
         Field[] fields = clazz.getDeclaredFields();	//获取该类的字段
         for (Field field : fields) {  					//遍历字段
           if (field.isAnnotationPresent(ViewInject.class)) {  	//字段被注解标注
                ViewInject inject = field.getAnnotation(ViewInject.class);  	//获取注解对象
                	int id = inject.value();  										//获取注解值
                 	 if (id > 0) {  											//值是正确的
                     field.setAccessible(true);  				//该值可达
                     field.set(this, this.findViewById(id));			//给字段设置值  
                 }  
             }  
         }  
     } catch (IllegalAccessException e) {  
         e.printStackTrace();  
    } catch (IllegalArgumentException e) {  
         e.printStackTrace();  
      }  
 }

在Android自定义View中,一个标准的onMeasure()方法。

1
@Override
   protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
       super.onMeasure(widthMeasureSpec, heightMeasureSpec);
       int viewWidth = circleRadius /*默认size*/+ this.getPaddingLeft() + this.getPaddingRight();
       int viewHeight = circleRadius + this.getPaddingTop() + this.getPaddingBottom();
       int widthMode = MeasureSpec.getMode(widthMeasureSpec);//获取宽度的模式
       int widthSize = MeasureSpec.getSize(widthMeasureSpec);//获取宽度的尺寸
       int heightMode = MeasureSpec.getMode(heightMeasureSpec);//高度的模式
       int heightSize = MeasureSpec.getSize(heightMeasureSpec);//高端的尺寸
       int width;
       int height;
       //Measure Width
       if (widthMode == MeasureSpec.EXACTLY) {//指定了确定的尺寸:100dp,match_parent
           //Must be this size
           width = widthSize;
       } else if (widthMode == MeasureSpec.AT_MOST) {//wrap_content类型
           //Can't be bigger than...
           width = Math.min(viewWidth, widthSize);
       } else {
           //Be whatever you want
           width = viewWidth;
       }
       //Measure Height
       if (heightMode == MeasureSpec.EXACTLY || widthMode == MeasureSpec.EXACTLY) {
           //Must be this size
           height = heightSize;
       } else if (heightMode == MeasureSpec.AT_MOST) {
           //Can't be bigger than...
           height = Math.min(viewHeight, heightSize);
       } else {
           //Be whatever you want
           height = viewHeight;
       }
       setMeasuredDimension(width, height);
   }

基础部分

扔物线老师的:给 Android 开发者的 RxJava 详解

http://gank.io/post/560e15be2dca930e00da1083

极客学院的:《RxJava Essentials》中文翻译

http://wiki.jikexueyuan.com/project/rxjava/

一个国外的博客教程

http://blog.danlew.net/2014/09/15/grokking-rxjava-part-1/

Rx-Java操作符动态演示

http://rxmarbles.com/

RxJava-Samples

https://github.com/THEONE10211024/RxJavaSamples

RxJava-Android-Samples

https://github.com/kaushikgopal/RxJava-Android-Samples

Library

RxJava对Activity/Fragment生命周期的封装

https://github.com/trello/RxLifecycle

RxJava对SharedPreferences的封装

https://github.com/f2prateek/rx-preferences

完整项目

一个天气预报小项目

https://github.com/SmartDengg/RxWeather

重构版妹子(Rx+Retrofit+okhttp)

https://github.com/CaMnter/EasyGank

用RxJava处理和操作高斯模糊效果的简单用例

https://github.com/SmartDengg/RxBlur

Hexo是一个使用Node.js开发的静态WEB框架,今天第一次使用它搭建了自己的博客系统,是一次新的尝试,同时也学习到了很多东西,希望这个博客可以记录我未来的学习情况。

Quick Start

使用如下命令可以创建一篇新的博客

1
$ hexo new "My New Post"

More info: Writing

启动本地的Nodejs服务器

1
$ hexo server

More info: Server

生成静态页面代码

1
$ hexo generate

More info: Generating

部署到远程Github

1
$ hexo deploy

More info: Deployment