t9search.java
来自「moblie syncml mail javame」· Java 代码 · 共 466 行 · 第 1/2 页
JAVA
466 行
/*
* Funambol is a mobile platform developed by Funambol, Inc.
* Copyright (C) 2003 - 2007 Funambol, Inc.
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU Affero General Public License version 3 as published by
* the Free Software Foundation with the addition of the following permission
* added to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED
* WORK IN WHICH THE COPYRIGHT IS OWNED BY FUNAMBOL, FUNAMBOL DISCLAIMS THE
* WARRANTY OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
*
* 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 Affero General Public License
* along with this program; if not, see http://www.gnu.org/licenses or write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301 USA.
*
* You can contact Funambol, Inc. headquarters at 643 Bair Island Road, Suite
* 305, Redwood City, CA 94063, USA, or at email address info@funambol.com.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License
* version 3, these Appropriate Legal Notices must retain the display of the
* "Powered by Funambol" logo. If the display of the logo is not reasonably
* feasible for technical reasons, the Appropriate Legal Notices must display
* the words "Powered by Funambol".
*
*
*/
package com.funambol.mailclient.ui.view;
import com.funambol.mailclient.ui.controller.UIController;
import com.funambol.util.ChunkedString;
import com.funambol.util.Log;
import com.funambol.util.StringUtil;
import com.sun.kvem.midp.pim.ContactImpl;
import java.util.Enumeration;
import java.util.Vector;
import javax.microedition.lcdui.Canvas;
//#ifdef isBlackberry
//# import net.rim.device.api.system.DeviceInfo;
//#endif
/**
* ContactItemFilter implementation for t9-like support in contact list
*
*/
public class T9Search implements ContactItemFilter {
/**
* here we keep the possible strings
*/
private Vector strings;
/*
* constants used for mapping standard phone keypad
* For non standard keyboards (e.g. blackbarry with two letters for each key)
* this strings should be changed
*/
private static String[] ABC = {"a", "b", "c"};
private static String[] DEF = {"d", "e", "f"};
private static String[] GHI = {"g", "h", "i"};
private static String[] JKL = {"j", "k", "l"};
private static String[] MNO = {"m", "n", "o"};
private static String[] PQRS = {"p", "q", "r", "s"};
private static String[] TUV = {"t", "u", "v"};
private static String[] WXYZ = {"w", "x", "y", "z"};
public T9Search() {
// strings = new Vector();
}
/**
* use the given keycode to generate the new strings.
* the new keycode is used to get the corresponding group of
* characters and they're added at the end of each search string.
*
*
*/
public void addKey(int keyCode) {
Log.info("keycode added: " + keyCode);
String[] toAppend = getStringsFromKeyCode(keyCode);
if (strings == null) {
strings = new Vector(toAppend.length);
for (int i = 0; i < toAppend.length; i++) {
strings.addElement(new StringBuffer(toAppend[i]));
}
} else {
if (toAppend.length > 0) {
//creating new stringbuffer
Vector newStringVector = new Vector(strings.size()*toAppend.length);
for (int i = 0; i < toAppend.length; i++) {
//copy the strings element to the new array
for (int k = 0; k< strings.size(); k++) {
// using a new stringbuffer, 'cause we need the old one
// to add i letters one at a time
StringBuffer newbuf = new StringBuffer(
((StringBuffer)strings.elementAt(k)).toString()
) ;
newbuf.append(toAppend[i]);
newStringVector.addElement(newbuf);
}
}
strings = newStringVector;
}
}
}
/**
* @return the vector of currently used strings
* return value can be null
*/
public Vector getStrings() {
return strings;
}
private String[] getStringsFromKeyCode(int keyCode) {
//#ifdef isBlackberry
//# String deviceName = DeviceInfo.getDeviceName().toLowerCase();
//# Log.debug("[T9Search] device name="+deviceName);
//# if (deviceName != null && ( deviceName.indexOf("8100") != -1
//# || deviceName.indexOf("8130") != -1)
//# || deviceName.indexOf("7100") != -1) {
//# return getStringsFromKeyCodePearl(keyCode);
//# } else {
//# return getStringsFromKeyCodeNormalKeyboard(keyCode);
//# }
//#else
return getStringsFromKeyCodeNormalKeyboard(keyCode);
//#endif
}
/**
* returns the array of strings corresponding to the given keycode,
* e.g. on most phones the number 2 corresponds to a,b,c.
* on qwerty devices the keycode is mapped to the correct string.
* For non standard keyboards (e.g. blackbarry with two letters for each key)
* this method should be changed.
*/
private String[] getStringsFromKeyCodeNormalKeyboard(int keyCode){
if ((char)keyCode == '2') {
return ABC;
} else if ((char)keyCode == '3') {
return DEF;
} else if ((char)keyCode == '4') {
return GHI;
} else if ((char)keyCode == '5') {
return JKL;
} else if ((char)keyCode == '6') {
return MNO;
} else if ((char)keyCode == '7') {
return PQRS;
} else if ((char)keyCode == '8') {
return TUV;
} else if ((char)keyCode == '9') {
return WXYZ;
} 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];
}
// These are the codes for the BlackBerry Pearl
private static String[] QW = { "q", "w" };
private static String[] ER = { "e", "r" };
private static String[] TY = { "t", "y" };
private static String[] UI = { "u", "i" };
private static String[] OP = { "o", "p" };
private static String[] AS = { "a", "s" };
private static String[] DF = { "d", "f" };
private static String[] GH = { "g", "h" };
private static String[] JK = { "j", "k" };
private static String[] ZX = { "z", "x" };
private static String[] CV = { "c", "v" };
private static String[] BN = { "b", "n" };
private static String[] M = { "m" };
private static String[] L = { "l" };
/**
* returns the array of strings corresponding to the given keycode. This
* method assumes the keyboard is the BlackBerry keyboard.
*
*/
private String[] getStringsFromKeyCodePearl(int keyCode){
if ((char)keyCode == 'q') {
return QW;
} else if ((char)keyCode == '1') {
return ER;
} else if ((char)keyCode == '2') {
return TY;
} else if ((char)keyCode == '3') {
return UI;
} else if ((char)keyCode == 'o') {
return OP;
} else if ((char)keyCode == 'a') {
return AS;
} else if ((char)keyCode == '4') {
return DF;
} else if ((char)keyCode == '5') {
return GH;
} else if ((char)keyCode == '6') {
return JK;
} else if ((char)keyCode == 'z') {
return ZX;
} else if ((char)keyCode == '7') {
return CV;
} else if ((char)keyCode == '8') {
return BN;
} else if ((char)keyCode == '9') {
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?