Html.fromhtml 方法支持的参数

Tags Format
b, strong Bold
i, em, cite, dfn Italics
u Underline
sub Subtext
sup Supertext
big Big
small Small
tt Monospace
h1 … h6 Headlines
img Image
font Font face and color
blockquote For longer quotes
a Link
div, p Paragraph
br Linefeed

Protobuf Micro

Install:

  1. Download protomicro at: https://code.google.com/p/micro-protobuf/

  2. $ ./configure

  3. $ make

    If errors as below:
    make[2]: [message.lo] Error 1
    make[1]:
    [all-recursive] Error 1
    make: * [all] Error 2

    Add “#include “ in src/google/protobuf/message.cc

  4. Create file protoc in /usr/local/bin/
    $ make install

USAGE:

  1. Define .proto file

  2. Create a java class in out_dir.
    $ /usr/local/bin/protoc —-javamicro_out=”our_dir” *.proto

  3. Use the java class。

  4. Import com.google.protobuf.micro in micro-protobuf-read-only/java/src/main/java/。

Activity being created twice, when back from camera Intent

  • Android may choose to destroy an Activity that is waiting for the call to onActivityResult; especially when free memory is running low. Some devices appear more aggressive about destroying Activitys that are on the task stack. I can reliably recreate the issue on a Samsung device set to a debugging mode called “strict mode”.

  • You can verify whether this is your issue by logging calls to onCreate & onDestroy.

  • In the case of a destroyed activity, when the activity result needs to be processed, Android will recreate the Activity, passing a savedInstanceState to onCreate. So, the remedy is to check the value of savedInstanceState in your GetImageActivity.onCreate. If it is not null then don’t make any calls to startActivity because your Activity is being recreated to call onActivityResult.

ActionBarCompat

  • 有三种Theme:
    Theme.AppCompat 深色主题,继承自android:Theme
    Theme.AppCompat.Light 浅色主题,继承自android:Theme.Light
    Theme.AppCompat.Light.DarkActionBar 浅色主题,ActionBar是深色主题,继承自android:Theme.Light

  • 可以使用ActionBarStyleGenerator开始进行自定义,不过功能有限,只能自定义背景色,图标和前景色通常还需要自行修改。另外这个站点生成的文件命名采用添加后缀的方式,不是很符合android的风格。

  • 所有属性进行自定义时,需要同时添加android:xxx和xxx两项,前者v14+使用,后者v14-使用或者使用values和values-v14分别定义

  • ActionBar默认大小
    以Galaxy Nexus portrait模式为例
    高度:48dp(portrait), 40dp(landcape)
    右侧按钮宽度:56dp
    paddingLeft、paddingRight:12dp

  • 自定义方式:修改Theme里的属性,或者actionBarWidgetTheme里面的属性
    如果属性是color/dimen/drawable,则可以直接设置
    如果属性是textAppearance/style,则还需要进一步定义,此时要注意该属性值需要继承自合适的类型
    某些dimen属性无法修改,可以通过修改图标大小的方式间接完成,例如想让up图标距离两侧的边距增大,就只能够修改up图标大小,让两侧的透明区域增大

  • ActionBar的自定义包括:

1
2
3
4
5
6
7
8
9
10
11
ActionBar的自定义:背景、标题、进度条、按钮
actionBarStyle: << Widget.AppCompat.Light.ActionBar.Solid.Inverse
background/backgroundStacked/backgroundSplit: Drawable
titleTextStyle: << TextAppearance.AppCompat.Widget.ActionBar.Title.Inverse
subtitleTextStyle: << TextAppearance.AppCompat.Widget.ActionBar.Subtitle.Inverse
progressBarStyle: << Widget.AppCompat.ProgressBar.Horizontal
indeterminateProgressStyle: << Widget.AppCompat.ProgressBar
divider: << Drawable
displayOptions:useLogo|showHome|homeAsUp|showTitle|showCustom
actionButtonStyle: << Widget.AppCompat.ActionButton
background: Drawable, 默认为?attr/actionBarItemBackground

abc_action_menu_item_layout为布局文件,paddingLeft/Right为8,paddingTop/Bottom为4,不可修改,因此portrait模式下图标大小应该不超过40dp(56-2*8) x 40dp(48-2*4),而landscape模式下由于action bar高度仅为40dp,因此图标大小不超过32dp x 32dp。所以通常做图标时取小的尺寸做成32dp x 32dp

1
2
actionOverflowButtonStyle: << Widget.AppCompat.ActionButton.Overflow
src: Drawable

使用OverflowMenuButton实现,没有使用布局资源,默认paddingLeft/Right为12,因此Overflow图标的建议大小为32dp(56-12*2) x 32dp

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
homeAsUpIndicator: << Drawable
actionBarSize: dimen 高度
ActionMode的自定义:背景,左侧对勾图标
actionModeBackground/actionModeSplitBackground: Drawable
actionModeCloseButtonStyle: << Widget.AppCompat.ActionButton.CloseMode
actionModeCloseDrawable: Drawable
Spinner的样式:
actionBarWidgetTheme
actionDropDownStyle: << Widget.AppCompat.Spinner.DropDown.ActionBar
background: Drawable
popupBackground: Drawable
dropDownSelector: Drawable
SpinnerItem的样式通过SpinnerAdapter的getView进行设置
OverflowMenu的样式:实现类MenuPopupHelper
actionBarWidgetTheme
popupMenuStyle
popupBackground: Drawable
dropDownListViewStyle
listSelector: Drawable
divider: Drawable
OverflowMenu Item的样式: 高度、字体 (默认布局:abc_popup_menu_item_layout)
actionBarWidgetTheme
textAppearanceLargePopupMenu: << TextAppearance.AppCompat.Widget.PopupMenu.Large
dropdownListPreferredItemHeight: dimen
  • 对ABC代码的修改:在2.x版本的系统上依旧显示Overflow Button:ActionBarPolicy#showsOverflowMenuButton,始终返回true

优化listView

  1. Use the View Holder pattern
  2. Do as little work as possible in getView()
  3. Reduce unnecessary overdraw
  4. Flatten the view hierarchy

AOP

AOP即面向切面编程。AspectJ是AOP最早成熟的Java实现,它稍微扩展了一下Java语言,增加了一些Keyword:

  • Aspect:用来定义切面,该切面可以包含多个切入点和通知,而且标签内部的通知和切入点定义是无序的
  • Pointcut:表示一个切入点或触发点,切入点支持的切入点指示符有几种,execution表示执行点,call表示调用点
  • execution:使用“execution(方法表达式)”匹配方法执行,方法表达式的格式(注解? 修饰符? 返回值类型 类型声明?方法名(参数列表) 异常列表?)
  • Advice:Pointcut被触发,所产生相应的动作。Advice在AspectJ有三种:before、 after、Around(调用先后均执行)

“今天开始blog搬家了”

我是一名Android程序员,写此博客的目的有两点,第一方便记录知识,第二写着玩。