📄 keymapper.java
字号:
/*
* Copyright (C) 2006-2007 Funambol
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*
*/
package com.funambol.mailclient.ui.view;
import com.funambol.mailclient.ui.controller.UIController;
import com.funambol.util.Log;
import java.util.Enumeration;
import java.util.Vector;
import javax.microedition.lcdui.Canvas;
/**
* Helper class for t9-like support.
*
*/
public class KeyMapper {
/**
* here we keep the possible strings
*/
private StringBuffer strings[];
public KeyMapper() {
strings = new StringBuffer[0];
}
/**
* add the given keycode to the vector of keycodes
*/
public void addKey(int keyCode) {
String[] toAppend = getStringsFromKeyCode(keyCode);
if (strings.length == 0 ) {
strings = new StringBuffer[toAppend.length];
for (int i = 0; i < toAppend.length; i++) {
strings[i] = new StringBuffer(toAppend[i]);
}
} else {
if (toAppend.length >0) {
//creating new stringbuffer
StringBuffer[] newStringVector = new StringBuffer[strings.length*toAppend.length];
for (int i = 0; i < toAppend.length; i++) {
//copy the strings element to the new array
for (int k = 0; k< strings.length; k++) {
newStringVector[strings.length*i +k] = new StringBuffer(strings[k].toString()).append(toAppend[i]);
}
}
/*
for (int i = 0; i < newStringVector.length ; i++) {
newStringVector[i].append(toAppend[i%toAppend.length]);
}*/
strings = newStringVector;
}
}
}
public String[] getStrings() {
String[] ret = new String[strings.length];
for (int i = 0; i< strings.length; i++) {
ret[i] = strings[i].toString();
// Log.debug(ret[i]);
}
return ret;
}
/**
* returns the array of strings corresponding to the given keycode,
* e.g. on most phones the number 2 corresponds to a,b,c
*/
private String[] getStringsFromKeyCode(int keyCode){
if ((char)keyCode == '2') {
return new String[] {"a", "b", "c"};
} else if ((char)keyCode == '3') {
return new String[] {"d", "e", "f"};
} else if ((char)keyCode == '4') {
return new String[] {"g", "h", "i"};
} else if ((char)keyCode == '5') {
return new String[] {"j", "k", "l"};
} else if ((char)keyCode == '6') {
return new String[] {"m", "n", "o"};
} else if ((char)keyCode == '7') {
return new String[] {"p", "q", "r", "s"};
} else if ((char)keyCode == '8') {
return new String[] {"t", "u", "v"};
} else if ((char)keyCode == '9') {
return new String[] {"w", "x", "y","z"};
} else if (keyCode>0) {
String [] s = new String[1];
s[0] = "" + (char)keyCode;
return s;
}
// if nothing works, we return nothing!
return new String[0];
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -