发现Android编程中的一个问题:如果在一个ListView上面放置一个可以接收焦点的东西,比如Button,当使用向上方向键滚动ListView到第一条后,焦点会移到上面的Button上,这个没问题。但然后使用向下的方向键时,焦点会跳到ListView中当前窗口的最下面一条,而不是焦点离开时的第一条。在ListView下方有Button的时候,向上移动焦点,也会出现类似的情况。
这个问题在Android的示例里面也有,ApiDemos->Views->Tabs->Content By Intent。这个示例里当使用方向键从list这个Tab向下移动焦点的时候,会跳过一屏的条目。
在网上搜了一下,仅仅有一个人提到了这个问题,但没有看到解答。
我查了一下源代码,实现设置焦点的代码是:
git://android.git.kernel.org/platform/frameworks/base.git›core›java›android›widget›ListView.java
@Override
protected void onFocusChanged(boolean gainFocus, int direction, Rect previouslyFocusedRect) {
super.onFocusChanged(gainFocus, direction, previouslyFocusedRect);
int closetChildIndex = -1;
if (gainFocus && previouslyFocusedRect != null) {
previouslyFocusedRect.offset(mScrollX, mScrollY);
// figure out which item should be selected based on previously
// focused rect
Rect otherRect = mTempRect;
int minDistance = Integer.MAX_VALUE;
final int childCount = getChildCount();
final int firstPosition = mFirstPosition;
final ListAdapter adapter = mAdapter;
for (int i = 0; i < childCount; i++) {
// only consider selectable views
if (!adapter.isEnabled(firstPosition + i)) {
continue;
}
View other = getChildAt(i);
other.getDrawingRect(otherRect);
offsetDescendantRectToMyCoords(other, otherRect);
int distance = getDistance(previouslyFocusedRect, otherRect, direction);
if (distance < minDistance) {
minDistance = distance;
closetChildIndex = i;
}
}
}
if (closetChildIndex >= 0) {
setSelection(closetChildIndex + mFirstPosition);
} else {
requestLayout();
}
}
通过debug发现,previouslyFocusedRect在这里是ListView的,而不是之前焦点View的。在按向下键时,getDistance比较ListView的bottom和各个child的top,当然会选中离ListView下沿最近的。具体为什么会previouslyFocusedRect是ListView,我还没有深入分析。
一个解决办法
这不是一个根本解决的方法:写一个新的class,继承ListView,覆盖onFocusChanged。
@Override
protected void onFocusChanged(boolean gainFocus, int direction, Rect previouslyFocusedRect) {
super.onFocusChanged(gainFocus, direction, previouslyFocusedRect);
if (gainFocus && previouslyFocusedRect != null) {
final ListAdapter adapter = getAdapter();
final int count = adapter.getCount();
switch (direction) {
case FOCUS_DOWN:
for (int i = 0; i < count; i++) {
if (!adapter.isEnabled(i)) {
continue;
}
setSelection(i);
break;
}
break;
case FOCUS_UP:
for (int i = count-1; i>=0; i--) {
if (!adapter.isEnabled(i)) {
continue;
}
setSelection(i);
break;
}
break;
default:
break;
}
}
}
在这里,我只处理了FOCUS_DOWN和FOCUS_UP。由于不能访问mFirstPosition,处理也做了简化:焦点从上方移下来时选择第一个能选择的,从下方移上来时选择最后一个能选择的。
各种电子设备有着不同分辨率的屏幕,除了用 长x宽 多少像素表示之外,还有各自的名称,如手机上常见的QVGA, HVGA和电视常见的1080p, 1080i。
这个说几个常用的:
VGA:是指640×480。经常在VGA前面加些修饰,表明和VGA的关系。比如QVGA是指Quarter VGA,也就是VGA的1/4,320×240。类似的,HVGA是Half-size VGA,有两种half的方式,分别是480×320和640×240。SVGA是指Super VGA, 800×600。WVGA是指Wide VGA,高度是480,但有几个不同的宽度:800、848、854。其中854×480是16:9的,又叫做FWVGA(Full WVGA)。
电视屏幕,经常看到720p、1080i、1080p,这里的数字是指屏幕的高度,可以按照16:9的比例,算出宽度。而字母p是指逐行扫描,i是指隔行扫描。逐行扫描效果要比各行扫描好。
- 720p = 1280×720逐行扫描
- 1080i = 1920×1080隔行扫描
- 1080p = 1920×1080逐行扫描
在wikipedia上,有详细的列表可以查阅。
下面是一个常用分辨率的比较图:来源

分类: Android 标签: 1080i, 1080p, 320x240, 480x320, 640x240, 800x600, FWVGA, HVGA, QVGA, SVGA, WVGA, 分辨率, 屏幕
从2月9日开始,@BeijingAir修改了报告的内容,从原来的报告过去1小时和当天平均值改为PM2.5和Ozone两个值。
原来的格式为:
2-9-2010 ; 11:00 ; Latest Hour ; 0.091 ; 169 ; Unhealthy ; Today’s Avg ; 0.216 ; 266 ; Very Unhealthy
现在的格式为:
02-21-2010; 09:00; PM2.5; 189.0; 239; Very Unhealthy // Ozone; 0.9; 1; Good
@BeijingAir是美驻华使馆在使馆区设置的一个空气检测站,将数据每隔一小时自动发送到twitter上。以前的数值仅仅为PM2.5,2月9日之后增加了Ozone。
几种污染物
PM2.5是Particulate matter 2.5的缩写,指大气中直径小于或等于2.5微米的颗粒物,也称为可入肺颗粒物。会进入肺部的气体交换区(肺泡),引起血管炎和动脉粥样硬化,进而导致心脏病和其他循环系统疾病。
PM10指直径等于或小于10微米,可以进入人的呼吸系统的颗粒物,也称为可吸入颗粒物。10微米到2.5微米的颗粒,部分会被肺呼出,部分被支气管和肺部组织吸附。
PM100指直径小于和等于100微米的颗粒物,也称总悬浮颗粒物。大于10微米的大多数被鼻腔和咽喉阻挡,不会造成麻烦。
PM2.5的影响
大气中PM-2.5污染控制的意义与途径一文中提到:
- PM-2.5是导致城市人为能见度下降的祸首
- PM-2.5是城市大气污染物中损害人体健康的元凶
什么是Ozone
Ozone是臭氧(O3) (感谢ushuz)
解读@BeijingAir数据
目前@BeijingAir的数据格式为:
日期; 时间; PM2.5; PM2.5浓度; PM2.5空气质量指数; 健康等级 // Ozone; Ozone浓度; Ozone指数; Ozone健康等级
PM2.5的空气质量指数
Air Quality Index
Levels of Health Concern |
Numerical
Value |
Meaning |
| Good |
0 to 50
|
Air quality is considered satisfactory, and air pollution poses little or no risk |
| Moderate |
51 to 100
|
Air quality is acceptable; however, for some pollutants there may be a moderate health concern for a very small number of people who are unusually sensitive to air pollution. |
| Unhealthy for Sensitive Groups |
101 to 150
|
Members of sensitive groups may experience health effects. The general public is not likely to be affected. |
|
|
151 to 200
|
Everyone may begin to experience health effects; members of sensitive groups may experience more serious health effects. |
| Very Unhealthy |
201 to 300
|
Health alert: everyone may experience more serious health effects |
| Hazardous |
301 to 500
|
Health warnings of emergency conditions. The entire population is more likely to be affected. |
(来源)
Ozone指数
| Air Quality Index |
Protect Your Health |
Good
(0-50) |
No health impacts are expected when air quality is in this range. |
Moderate
(51-100) |
Unusually sensitive people should consider limiting prolonged outdoor exertion. |
Unhealthy for Sensitive Groups
(101-150) |
The following groups should limit prolonged outdoor exertion:
- People with lung disease, such as asthma
- Children and older adults
- People who are active outdoors
|
Unhealthy
(151-200) |
The following groups should avoid prolonged outdoor exertion:
- People with lung disease, such as asthma
- Children and older adults
- People who are active outdoors
Everyone else should limit prolonged outdoor exertion. |
Very Unhealthy
(201-300) |
The following groups should avoid all outdoor exertion:
- People with lung disease, such as asthma
- Children and older adults
- People who are active outdoors
Everyone else should limit outdoor exertion. |
(来源)
在这篇文章里我说了用adb修改hosts文件的方法,但这个方法是要通过USB连接PC机的。如果刷了CM Recovery的话,可以进入Recovery Mode中的shell进行修改。
进入shell后,需要先执行
mount /system
之后,hosts文件就在/system/etc/hosts,可以用vi编辑了。
另外,在vi里,要退出编辑模式,可以按”Back”键。
刚刚从招行客服收到的传真,记录下来,以备后用。
收款银行之代理银行:招商银行纽约分行
- Intermediary Bank: China Merchants Bank, New York, SWIFT CODE: CMBCUS33
收款银行:招商银行总行,中国深圳深南大道7088号
- Beneficiary’s Bank : China Merchants Bank, H.O. Shenzhen, China, SWIFT CODE: CMBCCNBS
收款人名称:境内个人以我行开户证件姓名的汉语拼音为准,境外个人以我行开户证件姓名为准
- Beneficiary’s name : _________
收款人账号:16位卡号或包括区号在内的一卡通12位卡号
- Beneficiary’s A/C No.:__________
收款银行地址:深圳市深南大道7088号招商银行大厦
- Beneficiary’s Bank Address: China Merchants Bank Tower NO. 7088, Shennan Boulevard, Shenzhen, China
