2014年6月27日星期五

Android sdk manger cannot download anything in China

因为goagent不能用了,所以只能用改hosts了。
1.先选中Force https://... sources to be fetched using http://...
2. hosts里面添加:
203.208.46.146 dl.google.com
203.208.46.146 dl-ssl.google.com

2014年6月15日星期日

proguard与gson,searchview (v7)

与proguard同时使用要注意:

使用gson时(参见https://code.google.com/p/google-gson/source/browse/trunk/examples/android-proguard-example/proguard.cfg):
##---------------Begin: proguard configuration for Gson  ----------
# Gson uses generic type information stored in a class file when working with fields. Proguard
# removes such information by default, so configure it to keep all of it.
-keepattributes Signature

# For using GSON @Expose annotation
-keepattributes *Annotation*

# Gson specific classes
-keep class sun.misc.Unsafe { *; }
#-keep class com.google.gson.stream.** { *; }

# Application classes that will be serialized/deserialized over Gson
-keep class com.google.gson.examples.android.model.** { *; }

##---------------End: proguard configuration for Gson  ----------

使用android support v7中的searchview时:
-keep class android.support.v7.widget.SearchView { *; }

2013年9月2日星期一

判断statusbar是否存在

private boolean checkStatusbar(){
   Rect rect=new Rect();
   getWindow().getDecorView().getWindowVisibleDisplayFrame(rect);
   //屏幕高度还有别的办法得到,不赘述
   return (rect.bottom-rect.top)
           ==getResources().getDisplayMetrics().heightPixels;
}

另一种计算一般statusbar高度的方法(固定值,不是实时的高度):
(参考http://mrtn.me/blog/2012/03/17/get-the-height-of-the-status-bar-in-android/)
private int getStatusBarHeight() {
   int result = 0;
   int resourceId = getResources()
           .getIdentifier("status_bar_height", "dimen", "android");
   if (resourceId > 0) {
         result = getResources().getDimensionPixelSize(resourceId);
   }
 return result;
}

2013年8月31日星期六

onTouchEvent, onClick及onLongClick中各事件的顺序

(首先要知道:Returns true if the listener consumed event, false otherwise.)

onTouchEvent的一般过程:
   down-- move --up

全返回false:
down--move--longClick--move--up--onClick

onLongClick返回true:
down--move--longClick--move--up

up返回true:
短按:
down--move--up------longClick(??why?)
长按:
down--move--longClick--move--up

move返回true:
无影响

down返回true:  (不是点击事件)
短按:
没有click
长按:
没有click和longClick

blogspot插入代码

用google-code-prettify.
1.修改布局,在header里面加上:
<link href="http://google-code-prettify.googlecode.com/svn/trunk/src/prettify.css" rel="stylesheet" type="text/css"></link>
<script src="http://google-code-prettify.googlecode.com/svn/trunk/src/prettify.js" type="text/javascript">

2.<body onload="prettyPrint()">

3.将代码放在标签中<pre class="prettyprint">...</pre>
或者<code class="prettyprint">...</code>
html代码还需要转化.
xml标签可能需要用:
&lt;  替换  <
&gt;  替换  >

2013年8月23日星期五

Show screen of details about a particular application

public static void showDetailsOfApp(Context context,
 String packageName) {
 Intent intent = new Intent();
 final int apiLevel = Build.VERSION.SDK_INT;
 if (apiLevel >= 9) {
 intent.setAction(Settings.ACTION_APPLICATION_DETAILS_SETTINGS)
//  .setData(Uri.fromParts("package", packageName, null));
  .setData(Uri.parse("package:"+packageName));
 } else {
  final String appPkgName = (apiLevel == 8 ? "pkg"
    : "com.android.settings.ApplicationPkgName");
    intent.setAction(Intent.ACTION_VIEW)
    .setClassName("com.android.settings",
      "com.android.settings.InstalledAppDetails")
    .putExtra(appPkgName, packageName);
    }
  context.startActivity(intent);
  }