本文整理匯總了Java中android.view.KeyCharacterMap.load方法的典型用法代碼示例。如果您正苦於以下問題:Java KeyCharacterMap.load方法的具體用法?Java KeyCharacterMap.load怎麽用?Java KeyCharacterMap.load使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類android.view.KeyCharacterMap
的用法示例。
在下文中一共展示了KeyCharacterMap.load方法的13個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: sendDtmf
import android.view.KeyCharacterMap; //導入方法依賴的package包/類
/**
* Send a dtmf signal to a call
*
* @param callId the call to send the signal
* @param keyCode the keyCode to send (android style)
* @return
*/
public int sendDtmf(int callId, int keyCode) throws SameThreadException {
if (!created) {
return -1;
}
String keyPressed = "";
// Since some device (xoom...) are apparently buggy with key character
// map loading...
// we have to do crappy thing here
if (keyCode >= KeyEvent.KEYCODE_0 && keyCode <= KeyEvent.KEYCODE_9) {
keyPressed = Integer.toString(keyCode - KeyEvent.KEYCODE_0);
} else if (keyCode == KeyEvent.KEYCODE_POUND) {
keyPressed = "#";
} else if (keyCode == KeyEvent.KEYCODE_STAR) {
keyPressed = "*";
} else {
// Fallback... should never be there if using visible dialpad, but
// possible using keyboard
KeyCharacterMap km = KeyCharacterMap.load(KeyCharacterMap.NUMERIC);
keyPressed = Integer.toString(km.getNumber(keyCode));
}
return sendDtmf(callId, keyPressed);
}
示例2: areSonyXperiaGamepadKeysSwapped
import android.view.KeyCharacterMap; //導入方法依賴的package包/類
private static boolean areSonyXperiaGamepadKeysSwapped() {
// The cross and circle buttons on Sony Xperia phones are swapped
// in different regions
// http://developer.sonymobile.com/2011/02/13/xperia-play-game-keys/
final char DEFAULT_O_BUTTON_LABEL = 0x25CB;
boolean swapped = false;
int[] deviceIds = InputDevice.getDeviceIds();
for (int i= 0; deviceIds != null && i < deviceIds.length; i++) {
KeyCharacterMap keyCharacterMap = KeyCharacterMap.load(deviceIds[i]);
if (keyCharacterMap != null && DEFAULT_O_BUTTON_LABEL ==
keyCharacterMap.getDisplayLabel(KeyEvent.KEYCODE_DPAD_CENTER)) {
swapped = true;
break;
}
}
return swapped;
}
示例3: synthesizeKeyEvents
import android.view.KeyCharacterMap; //導入方法依賴的package包/類
private KeyEvent [] synthesizeKeyEvents(CharSequence cs) {
try {
if (mKeyMap == null) {
mKeyMap = KeyCharacterMap.load(
Versions.preHC ? KeyCharacterMap.ALPHA :
KeyCharacterMap.VIRTUAL_KEYBOARD);
}
} catch (Exception e) {
// KeyCharacterMap.UnavailableException is not found on Gingerbread;
// besides, it seems like HC and ICS will throw something other than
// KeyCharacterMap.UnavailableException; so use a generic Exception here
return null;
}
KeyEvent [] keyEvents = mKeyMap.getEvents(cs.toString().toCharArray());
if (keyEvents == null || keyEvents.length == 0) {
return null;
}
return keyEvents;
}
示例4: sendUnicode
import android.view.KeyCharacterMap; //導入方法依賴的package包/類
/**
* Tries to convert a unicode character to a KeyEvent and if successful sends with keyEvent().
* @param unicodeChar
* @param metaState
*/
public boolean sendUnicode (char unicodeChar, int additionalMetaState) {
KeyCharacterMap fullKmap = KeyCharacterMap.load(KeyCharacterMap.FULL);
KeyCharacterMap virtualKmap = KeyCharacterMap.load(KeyCharacterMap.VIRTUAL_KEYBOARD);
char[] s = new char[1];
s[0] = unicodeChar;
KeyEvent[] events = fullKmap.getEvents(s);
// Failing with the FULL keymap, try the VIRTUAL_KEYBOARD one.
if (events == null) {
events = virtualKmap.getEvents(s);
}
if (events != null) {
for (int i = 0; i < events.length; i++) {
KeyEvent evt = events[i];
processLocalKeyEvent(evt.getKeyCode(), evt, additionalMetaState);
KeyEvent upEvt = new KeyEvent(KeyEvent.ACTION_UP, evt.getKeyCode());
processLocalKeyEvent(upEvt.getKeyCode(), upEvt, additionalMetaState);
return true;
}
} else {
android.util.Log.e("RemoteKeyboard", "Could not use any keymap to generate KeyEvent for unicode: " + unicodeChar);
}
return false;
}
示例5: sendUnicode
import android.view.KeyCharacterMap; //導入方法依賴的package包/類
/**
* Tries to convert a unicode character to a KeyEvent and if successful sends with keyEvent().
* @param unicodeChar
*/
private void sendUnicode(char unicodeChar) {
KeyCharacterMap fullKmap = KeyCharacterMap.load(KeyCharacterMap.FULL);
KeyCharacterMap virtualKmap = KeyCharacterMap.load(KeyCharacterMap.VIRTUAL_KEYBOARD);
char[] s = new char[1];
s[0] = unicodeChar;
KeyEvent[] events = fullKmap.getEvents(s);
// Failing with the FULL keymap, try the VIRTUAL_KEYBOARD one.
if (events == null) {
events = virtualKmap.getEvents(s);
}
if (events != null) {
for (int i = 0; i < events.length; i++) {
KeyEvent evt = events[i];
processLocalKeyEvent(evt);
}
} else {
android.util.Log.w(TAG, "Could not use any keymap to generate KeyEvent for unicode: " + unicodeChar);
}
}
示例6: getAmOrPmKeyCode
import android.view.KeyCharacterMap; //導入方法依賴的package包/類
/**
* Get the keycode value for AM and PM in the current language.
*/
private int getAmOrPmKeyCode(int amOrPm) {
// Cache the codes.
if (mAmKeyCode == -1 || mPmKeyCode == -1) {
// Find the first character in the AM/PM text that is unique.
KeyCharacterMap kcm = KeyCharacterMap.load(KeyCharacterMap.VIRTUAL_KEYBOARD);
char amChar;
char pmChar;
for (int i = 0; i < Math.max(mAmText.length(), mPmText.length()); i++) {
amChar = mAmText.toLowerCase(Locale.getDefault()).charAt(i);
pmChar = mPmText.toLowerCase(Locale.getDefault()).charAt(i);
if (amChar != pmChar) {
KeyEvent[] events = kcm.getEvents(new char[]{amChar, pmChar});
// There should be 4 events: a down and up for both AM and PM.
if (events != null && events.length == 4) {
mAmKeyCode = events[0].getKeyCode();
mPmKeyCode = events[2].getKeyCode();
} else {
Log.e(TAG, "Unable to find keycodes for AM and PM.");
}
break;
}
}
}
if (amOrPm == AM) {
return mAmKeyCode;
} else if (amOrPm == PM) {
return mPmKeyCode;
}
return -1;
}
示例7: getAmOrPmKeyCode
import android.view.KeyCharacterMap; //導入方法依賴的package包/類
private int getAmOrPmKeyCode(int amOrPm) {
if (this.mAmKeyCode == -1 || this.mPmKeyCode == -1) {
KeyCharacterMap kcm = KeyCharacterMap.load(-1);
int i = 0;
while (i < Math.max(this.mAmText.length(), this.mPmText.length())) {
if (this.mAmText.toLowerCase(Locale.getDefault()).charAt(i) != this.mPmText
.toLowerCase(Locale.getDefault()).charAt(i)) {
KeyEvent[] events = kcm.getEvents(new char[]{this.mAmText.toLowerCase(Locale
.getDefault()).charAt(i), this.mPmText.toLowerCase(Locale.getDefault
()).charAt(i)});
if (events == null || events.length != 4) {
Log.e(TAG, "Unable to find keycodes for AM and PM.");
} else {
this.mAmKeyCode = events[0].getKeyCode();
this.mPmKeyCode = events[2].getKeyCode();
}
} else {
i++;
}
}
}
if (amOrPm == 0) {
return this.mAmKeyCode;
}
if (amOrPm == 1) {
return this.mPmKeyCode;
}
return -1;
}
示例8: onKeyShortcut
import android.view.KeyCharacterMap; //導入方法依賴的package包/類
@Override
public boolean onKeyShortcut(int keyCode, KeyEvent ev) {
Menu menu = getMenu();
if (menu != null) {
final KeyCharacterMap kmap = KeyCharacterMap.load(
ev != null ? ev.getDeviceId() : KeyCharacterMap.VIRTUAL_KEYBOARD);
menu.setQwertyMode(kmap.getKeyboardType() != KeyCharacterMap.NUMERIC);
menu.performShortcut(keyCode, ev, 0);
}
// This action bar always returns true for handling keyboard shortcuts.
// This will block the window from preparing a temporary panel to handle
// keyboard shortcuts.
return true;
}
示例9: getAmOrPmKeyCode
import android.view.KeyCharacterMap; //導入方法依賴的package包/類
/**
* Get the keycode value for AM and PM in the current language.
*/
private int getAmOrPmKeyCode(int amOrPm) {
// Cache the codes.
if (mAmKeyCode == -1 || mPmKeyCode == -1) {
// Find the first character in the AM/PM text that is unique.
final KeyCharacterMap kcm = KeyCharacterMap.load(KeyCharacterMap.VIRTUAL_KEYBOARD);
final CharSequence amText = mAmText.toLowerCase(mCurrentLocale);
final CharSequence pmText = mPmText.toLowerCase(mCurrentLocale);
final int N = Math.min(amText.length(), pmText.length());
for (int i = 0; i < N; i++) {
final char amChar = amText.charAt(i);
final char pmChar = pmText.charAt(i);
if (amChar != pmChar) {
// There should be 4 events: a down and up for both AM and PM.
final KeyEvent[] events = kcm.getEvents(new char[]{amChar, pmChar});
if (events != null && events.length == 4) {
mAmKeyCode = events[0].getKeyCode();
mPmKeyCode = events[2].getKeyCode();
} else {
Log.e(TAG, "Unable to find keycodes for AM and PM.");
}
break;
}
}
}
if (amOrPm == AM) {
return mAmKeyCode;
} else if (amOrPm == PM) {
return mPmKeyCode;
}
return -1;
}
示例10: getAmOrPmKeyCode
import android.view.KeyCharacterMap; //導入方法依賴的package包/類
/**
* Get the keycode value for AM and PM in the current language.
*/
private int getAmOrPmKeyCode(int amOrPm) {
// Cache the codes.
if (mAmKeyCode == -1 || mPmKeyCode == -1) {
// Find the first character in the AM/PM text that is unique.
KeyCharacterMap kcm = KeyCharacterMap.load(KeyCharacterMap.VIRTUAL_KEYBOARD);
char amChar;
char pmChar;
for (int i = 0; i < Math.max(mAmText.length(), mPmText.length()); i++) {
amChar = mAmText.toLowerCase(Locale.getDefault()).charAt(i);
pmChar = mPmText.toLowerCase(Locale.getDefault()).charAt(i);
if (amChar != pmChar) {
KeyEvent[] events = kcm.getEvents(new char[]{amChar, pmChar});
// There should be 4 events: a down and up for both AM and PM.
if (events != null && events.length == 4) {
mAmKeyCode = events[0].getKeyCode();
mPmKeyCode = events[2].getKeyCode();
} else {
Log.e(TAG, "Unable to find keycodes for AM and PM.");
}
break;
}
}
}
if (amOrPm == HALF_DAY_1) {
return mAmKeyCode;
} else if (amOrPm == HALF_DAY_2) {
return mPmKeyCode;
}
return -1;
}
示例11: getAmOrPmKeyCode
import android.view.KeyCharacterMap; //導入方法依賴的package包/類
/**
* Get the keycode value for AM and PM in the current language.
*/
private int getAmOrPmKeyCode(int amOrPm) {
// Cache the codes.
if (mAmKeyCode == -1 || mPmKeyCode == -1) {
// Find the first character in the AM/PM text that is unique.
final KeyCharacterMap kcm = KeyCharacterMap.load(KeyCharacterMap.VIRTUAL_KEYBOARD);
final CharSequence amText = mAmText.toLowerCase(mCurrentLocale);
final CharSequence pmText = mPmText.toLowerCase(mCurrentLocale);
final int N = Math.min(amText.length(), pmText.length());
for (int i = 0; i < N; i++) {
final char amChar = amText.charAt(i);
final char pmChar = pmText.charAt(i);
if (amChar != pmChar) {
// There should be 4 events: a down and up for both AM and PM.
final KeyEvent[] events = kcm.getEvents(new char[] { amChar, pmChar });
if (events != null && events.length == 4) {
mAmKeyCode = events[0].getKeyCode();
mPmKeyCode = events[2].getKeyCode();
} else {
Log.e(TAG, "Unable to find keycodes for AM and PM.");
}
break;
}
}
}
if (amOrPm == AM) {
return mAmKeyCode;
} else if (amOrPm == PM) {
return mPmKeyCode;
}
return -1;
}
示例12: getKeyCharacterMap
import android.view.KeyCharacterMap; //導入方法依賴的package包/類
@SuppressLint("InlinedApi")
@VisibleForTesting
@SuppressWarnings("deprecation")
public static KeyCharacterMap getKeyCharacterMap() {
KeyCharacterMap keyCharacterMap = null;
// KeyCharacterMap.VIRTUAL_KEYBOARD is present from API11.
// For earlier APIs we use KeyCharacterMap.BUILT_IN_KEYBOARD
if (Build.VERSION.SDK_INT < 11) {
keyCharacterMap = KeyCharacterMap.load(KeyCharacterMap.BUILT_IN_KEYBOARD);
} else {
keyCharacterMap = KeyCharacterMap.load(KeyCharacterMap.VIRTUAL_KEYBOARD);
}
return keyCharacterMap;
}
示例13: preparePanel
import android.view.KeyCharacterMap; //導入方法依賴的package包/類
private boolean preparePanel() {
// Already prepared (isPrepared will be reset to false later)
if (mMenuIsPrepared) {
return true;
}
// Init the panel state's menu--return false if init failed
if (mMenu == null || mMenuRefreshContent) {
if (mMenu == null) {
if (!initializePanelMenu() || (mMenu == null)) {
return false;
}
}
if (wActionBar != null) {
wActionBar.setMenu(mMenu, this);
}
// Call callback, and return if it doesn't want to display menu.
// Creating the panel menu will involve a lot of manipulation;
// don't dispatch change events to presenters until we're done.
mMenu.stopDispatchingItemsChanged();
if (!callbackCreateOptionsMenu(mMenu)) {
// Ditch the menu created above
mMenu = null;
if (wActionBar != null) {
// Don't show it in the action bar either
wActionBar.setMenu(null, this);
}
return false;
}
mMenuRefreshContent = false;
}
// Callback and return if the callback does not want to show the menu
// Preparing the panel menu can involve a lot of manipulation;
// don't dispatch change events to presenters until we're done.
mMenu.stopDispatchingItemsChanged();
// Restore action view state before we prepare. This gives apps
// an opportunity to override frozen/restored state in onPrepare.
if (mMenuFrozenActionViewState != null) {
mMenu.restoreActionViewStates(mMenuFrozenActionViewState);
mMenuFrozenActionViewState = null;
}
if (!callbackPrepareOptionsMenu(mMenu)) {
if (wActionBar != null) {
// The app didn't want to show the menu for now but it still exists.
// Clear it out of the action bar.
wActionBar.setMenu(null, this);
}
mMenu.startDispatchingItemsChanged();
return false;
}
// Set the proper keymap
KeyCharacterMap kmap = KeyCharacterMap.load(KeyCharacterMap.VIRTUAL_KEYBOARD);
mMenu.setQwertyMode(kmap.getKeyboardType() != KeyCharacterMap.NUMERIC);
mMenu.startDispatchingItemsChanged();
// Set other state
mMenuIsPrepared = true;
return true;
}