xianzhez notes


  • Home

  • Categories

  • Archives

  • Tags

Effective JAVA

Posted on 2017-09-28   |   In Reading

1. Introduction

A method’s signature consists of its name and the types of its formal parameters; the signature does not include the method’s return type.

2. Creating and Destroying Objects

Item 1: Consider static factory methods instead of constructors.

Advantage

One advantage of static factory methods is that, unlike constructors, they have names.

A second advantage of static factory methods is that, unlike constructors, they are not required to create a new object each time they’re invoked.

A third advantage of static factory methods is that, unlike constructors, they can return an object of any subtype of their return type.

A fourth advantage of static factory methods is that they reduce the verbosity of creating parameterized type instances.

Read more »

Android Dev Tips

Posted on 2017-08-10   |   In Android
  1. onLongClick() 返回true时会自动震动
  1. getLocationInWindow 不算notification bar

getLocationOnScreen 整个屏幕

3.

fillBefore是指动画结束时画面停留在此动画的第一帧; 默认值为true

fillAfter是指动画结束是画面停留在此动画的最后一帧。默认值为false

Read more »

Eloquent Javascript

Posted on 2017-07-08   |   In Web

#Eloquent JavaScript

#3 FUNCHTIONS

函数体内可以嵌套函数。

只有函数体才可以定义作用域,其它用{}定义的区域,都将作用于全局。

函数变量可以被重新赋值。

函数在作用域的任何地方都可以定义,并且在任何地方都可以使用,不会按照先后顺序执行。

不要在条件语句以及循环语句中定义函数。

递归调用会比循环引用的速度慢很多,应该避免递归。

准则:

  • The basic rule, which has been repeated by many programmers and with which I wholeheartedly agree, is to not worry about efficiency until you know for sure that the program is too slow.

  • A useful principle is not to add cleverness unless you are absolutely sure you’re going to need it.

  • A pure function is a specific kind of value-producing function that not only has no side effects but also doesn’t rely on side effects from other code.

    Still, there’s no need to feel bad when writing functions that are not pure or to wage a holy war to purge them from your code. Side effects are often useful.

Read more »

Universal Image Loader

Posted on 2017-04-08   |   In Android

UIL_Universal Image Loader

1. Setup

Maven dependency:

1
2
3
4
5
6
7
8
<dependency>
<groupId>com.nostra13.universalimageloader</groupId>
<artifactId>universal-image-loader</artifactId>
<version>1.9.4</version>
</dependency>
Gradle dependency:
compile 'com.nostra13.universalimageloader:universal-image-loader:1.9.4'

Manifest:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
<manifest>
<!-- Include following permission if you load images from Internet -->
<uses-permission android:name="android.permission.INTERNET" />
<!-- Include following permission if you want to cache images on SD card -->
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
...
</manifest>
Usage:
public class MyActivity extends Activity {
@Override
public void onCreate() {
super.onCreate();
// Create global configuration and initialize ImageLoader with this config
ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(this)
...
.build();
ImageLoader.getInstance().init(config);
...
}
}
Read more »

Fresco Arch

Posted on 2017-03-18   |   In Android

#Fresco

##Outline

  1. Architecture
  2. Usage
  3. Drawee
  4. ImagePipeline

##Architecture

##Memory

####Regions of Memory

  1. Java Heap: limited, GC
  2. Native Heap: as large as the memory size; Program is responsible for freeing memory
  3. Ashmen: (Anonymous Shared Memory) like native heap; pin or unpin, lazy free purging facility.

####Purgeable bitmaps

1
2
3
BitmapFactory.Options = new BitmapFactory.Options();
options.inPurgeable = true;
Bitmap bitmap = BitmapFactory.decodeByteArray(jepeg, 0, jpeg.length, options);
Read more »

Design Pattern

Posted on 2016-09-03   |   In CS Base

Design Pattern

1、简单工厂模式

解决对象创建问题。(抽象工厂模式利用反射可以减少选择判断,从而减少需求增加时带来的变化)

2、策略模式(Strategy)

策略模式,定义算法家族,分别封装起来,让它们之间可以相互替换,此模式让算法的变化,不会影响到使用算法的客户。

策略模式就是用来封装算法的,但在实践中,我们发现可以用它来封装几乎任何类型的规则,只要在分析过程中听到需要在不同时间应用不同的业务规则,就可以考虑使用策略模式处理这种变化的可能性。

Read more »

Gradle Learning

Posted on 2016-08-20   |   In Android

#1. Groovy

Groovy是一种动态语言。语言与Java相通,又像一种脚本语言。Groovy会先将Code编译成Java类字节码,然后通过JVM来执行。

###搭建开发环境
groovy

###前提语法

  • 注释标记和Java一样,支持//或者/**/
  • Groovy语句可以不用分号结尾
  • Groovy支持动态类型,即定义变量的时候可以不指定类型。Groovy中,变量定义可以使用关键字def。def不是必须的,但是为了代码清晰,建议还是使用def关键字。
  • 函数定义时,参数的类型可以不指定。
  • Groovy中函数的返回值也可以是无类型的。但必须使用def关键字。如果指定了函数返回类型,则可不必加def关键字来定义函数。无类型的函数的最后一行代码的执行结果就是本函数的返回值。

    1
    //无类型的函数定义,必须使用 def 关键字 def nonReturnTypeFunc(){ last_line //最后一行代码的执行结果就是本函数的返回值 } //如果指定了函数返回类型,则可不必加 def 关键字来定义函数 String getString(){ return "I am a string" }
Read more »

Android Debug Bridge

Posted on 2016-07-26   |   In Android

Android Debug Bridge

XIANZHEZ: 关于ADB的工作方式简介其实看developer的介绍(https://developer.android.com/studio/command-line/adb.html#howadbworks)就足够了。
本文基于developer上的介绍以及开发经验做一个简单的总结,用于备忘查阅。

基本介绍

Android Debug Bridge(adb)是一个功能强大的命令行工具,可以用于连接Android设备或emulator。尤其是在Android开发过程中可以起到很大的帮助作用。Android Studio等IDE以及一些常用工具(如DDMS)都会用到adb。

Read more »

精简必备版Vim快捷键

Posted on 2016-07-04   |   In Linux

进入vi的命令

  • vi filename :打开或新建文件,并将光标置于第一行首

vi 关闭文件

  • :w //保存文件
  • :q //退出编辑器,如果文件已修改请使用下面的命令
  • :q! //退出编辑器,且不保存
  • :wq //退出编辑器,且保存文件

移动光标类命令

  • h :光标左移一个字符
  • l :光标右移一个字符
  • k或Ctrl+p:光标上移一行
  • j或Ctrl+n :光标下移一行

  • space:光标右移一个字符

  • Backspace:光标左移一个字符
    Read more »

Vim Shortcut

Posted on 2016-07-03   |   In Tools

vi(vim)是上Linux非常常用的编辑器,很多Linux发行版都默认安装了vi(vim)。vi(vim)命令繁多但是如果使用灵活之后将会大大提高效率。vi是“visual interface”的缩写,vim是vi IMproved(增强版的vi)。在一般的系统管理维护中vi就够用,如果想使用代码加亮的话可以使用vim。

vi有3个模式:插入模式、命令模式、低行模式

  1. 插入模式:在此模式下可以输入字符,按ESC将回到命令模式。
  2. 命令模式:可以移动光标、删除字符等。
  3. 低行模式:可以保存文件、退出vi、设置vi、查找等功能(低行模式也可以看作是命令模式里的)。

进入vi的命令

  • vi filename :打开或新建文件,并将光标置于第一行首
  • vi +n filename :打开文件,并将光标置于第n行首
  • vi + filename :打开文件,并将光标置于最后一行首
  • vi +/pattern filename:打开文件,并将光标置于第一个与pattern匹配的串处
  • vi -r filename :在上次正用vi编辑时发生系统崩溃,恢复filename
  • vi -o/O filename1 filename2 ... :打开多个文件,依次进行编辑
Read more »
123
xianzhez

xianzhez

25 posts
9 categories
14 tags
© 2017 xianzhez
Powered by Hexo
Theme - NexT.Muse