待机/主屏界面输入数字1~9后跳转到了联系人界面。
待机规则:如果输入的是0~9或者+*#,会切换到拨号界面;输入其它字符,则切换到联系人界面。
原因分析:模拟器输入1~9,看到的是1~9;手机键盘输入1~9,实际输入的是.adgj...。可以在写信窗口验证键盘输入。
解决方法:在待机程序中添加keyCode的处理,如果keyCode的值是KeyEvent.KEYCODE_0~KEYCODE_9或者KeyEvent.KEYCODE_STAR、KeyEvent.KEYCODE_POUND、KeyEvent.KEYCODE_PLUS,转换成对应的是0~9或者+*#,其它流程不变。另外,模拟器的*和#的keyCode值与10个数字的keyCode值重叠(电脑键盘传输造成的,手机键盘不存在这个问题),这块也需要作特殊处理。
代码如下:
public final class com.android.launcher.Launcher
{
……
public final static String KEY_STAR = "*";
public final static String KEY_POUND = "#";
public final static String KEY_PLUS = "+";
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
boolean handled = super.onKeyDown(keyCode, event);
if (!handled && keyCode != KeyEvent.KEYCODE_ENTER) {
boolean gotKey = TextKeyListener.getInstance().onKeyDown(mWorkspace, mDefaultKeySsb,
keyCode, event);
if (gotKey && mDefaultKeySsb != null && mDefaultKeySsb.length() > 0) {
// something usable has been typed - dispatch it now.
String str = mDefaultKeySsb.toString();
boolean isDialable = true;
//for emunlator
if ( keyCode >= KeyEvent.KEYCODE_0 && keyCode<= KeyEvent.KEYCODE_9 )
{
if ( ! KEY_STAR.equals( str ) && ! KEY_POUND.equals( str ) )
{//for emulator
str = String.valueOf( keyCode2Value(keyCode) );
}
}
else if ( keyCode == KeyEvent.KEYCODE_STAR )
{
str = KEY_STAR;
}
else if ( keyCode == KeyEvent.KEYCODE_POUND )
{
str = KEY_POUND;
}
else if ( keyCode == KeyEvent.KEYCODE_PLUS )
{
str = KEY_PLUS;
}
else
{
final int count = str.length();
for (int i = 0; i < count; i++)
{
if (!PhoneNumberUtils.isReallyDialable(str.charAt(i)))
{
isDialable = false;
break;
}
}
}
Intent intent;
if (isDialable) {
intent = new Intent(Intent.ACTION_DIAL, Uri.fromParts("tel", str, null));
} else {
intent = new Intent(Contacts.Intents.UI.FILTER_CONTACTS_ACTION);
intent.putExtra(Contacts.Intents.UI.FILTER_TEXT_EXTRA_KEY, str);
}
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
try {
startActivity(intent);
} catch (android.content.ActivityNotFoundException ex) {
// Oh well... no one knows how to filter/dial. Life goes on.
}
mDefaultKeySsb.clear();
mDefaultKeySsb.clearSpans();
Selection.setSelection(mDefaultKeySsb, 0);
return true;
}
}
return handled;
}
private int keyCode2Value( int keyCode )
{
switch ( keyCode )
{
case KeyEvent.KEYCODE_0:
return ToneGenerator.TONE_DTMF_0;
case KeyEvent.KEYCODE_1:
return ToneGenerator.TONE_DTMF_1;
case KeyEvent.KEYCODE_2:
return ToneGenerator.TONE_DTMF_2;
case KeyEvent.KEYCODE_3:
return ToneGenerator.TONE_DTMF_3;
case KeyEvent.KEYCODE_4:
return ToneGenerator.TONE_DTMF_4;
case KeyEvent.KEYCODE_5:
return ToneGenerator.TONE_DTMF_5;
case KeyEvent.KEYCODE_6:
return ToneGenerator.TONE_DTMF_6;
case KeyEvent.KEYCODE_7:
return ToneGenerator.TONE_DTMF_7;
case KeyEvent.KEYCODE_8:
return ToneGenerator.TONE_DTMF_8;
case KeyEvent.KEYCODE_9:
return ToneGenerator.TONE_DTMF_9;
case KeyEvent.KEYCODE_STAR://*
return ToneGenerator.TONE_DTMF_P;
case KeyEvent.KEYCODE_POUND://#
return ToneGenerator.TONE_DTMF_S;
case KeyEvent.KEYCODE_PLUS://+
// return ToneGenerator.;
default:
return 0;
}
}
……
}
本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/netpirate/archive/2009/06/26/4300157.aspx
posted on 2009-08-29 23:29
Xu Jianxiang 阅读(527)
评论(0) 编辑 收藏 所属分类:
Android