Java Code Examples for android.view.KeyEvent#KEYCODE_0

The following examples show how to use android.view.KeyEvent#KEYCODE_0 . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TimePickerDialog.java    From AlarmOn with Apache License 2.0 6 votes vote down vote up
private static int getValFromKeyCode(int keyCode) {
    switch (keyCode) {
        case KeyEvent.KEYCODE_0:
            return 0;
        case KeyEvent.KEYCODE_1:
            return 1;
        case KeyEvent.KEYCODE_2:
            return 2;
        case KeyEvent.KEYCODE_3:
            return 3;
        case KeyEvent.KEYCODE_4:
            return 4;
        case KeyEvent.KEYCODE_5:
            return 5;
        case KeyEvent.KEYCODE_6:
            return 6;
        case KeyEvent.KEYCODE_7:
            return 7;
        case KeyEvent.KEYCODE_8:
            return 8;
        case KeyEvent.KEYCODE_9:
            return 9;
        default:
            return -1;
    }
}
 
Example 2
Source File: SwitchTimePicker.java    From Android-SwitchDateTimePicker with Apache License 2.0 6 votes vote down vote up
private int getValFromKeyCode(int keyCode) {
    switch (keyCode) {
        case KeyEvent.KEYCODE_0:
            return 0;
        case KeyEvent.KEYCODE_1:
            return 1;
        case KeyEvent.KEYCODE_2:
            return 2;
        case KeyEvent.KEYCODE_3:
            return 3;
        case KeyEvent.KEYCODE_4:
            return 4;
        case KeyEvent.KEYCODE_5:
            return 5;
        case KeyEvent.KEYCODE_6:
            return 6;
        case KeyEvent.KEYCODE_7:
            return 7;
        case KeyEvent.KEYCODE_8:
            return 8;
        case KeyEvent.KEYCODE_9:
            return 9;
        default:
            return -1;
    }
}
 
Example 3
Source File: TimePickerDialog.java    From cathode with Apache License 2.0 6 votes vote down vote up
private static int getValFromKeyCode(int keyCode) {
  switch (keyCode) {
    case KeyEvent.KEYCODE_0:
      return 0;
    case KeyEvent.KEYCODE_1:
      return 1;
    case KeyEvent.KEYCODE_2:
      return 2;
    case KeyEvent.KEYCODE_3:
      return 3;
    case KeyEvent.KEYCODE_4:
      return 4;
    case KeyEvent.KEYCODE_5:
      return 5;
    case KeyEvent.KEYCODE_6:
      return 6;
    case KeyEvent.KEYCODE_7:
      return 7;
    case KeyEvent.KEYCODE_8:
      return 8;
    case KeyEvent.KEYCODE_9:
      return 9;
    default:
      return -1;
  }
}
 
Example 4
Source File: GridTimePickerDialog.java    From BottomSheetPickers with Apache License 2.0 6 votes vote down vote up
private static int getValFromKeyCode(int keyCode) {
    switch (keyCode) {
        case KeyEvent.KEYCODE_0:
            return 0;
        case KeyEvent.KEYCODE_1:
            return 1;
        case KeyEvent.KEYCODE_2:
            return 2;
        case KeyEvent.KEYCODE_3:
            return 3;
        case KeyEvent.KEYCODE_4:
            return 4;
        case KeyEvent.KEYCODE_5:
            return 5;
        case KeyEvent.KEYCODE_6:
            return 6;
        case KeyEvent.KEYCODE_7:
            return 7;
        case KeyEvent.KEYCODE_8:
            return 8;
        case KeyEvent.KEYCODE_9:
            return 9;
        default:
            return -1;
    }
}
 
Example 5
Source File: TimePickerDialog.java    From narrate-android with Apache License 2.0 6 votes vote down vote up
private static int getValFromKeyCode(int keyCode) {
    switch (keyCode) {
        case KeyEvent.KEYCODE_0:
            return 0;
        case KeyEvent.KEYCODE_1:
            return 1;
        case KeyEvent.KEYCODE_2:
            return 2;
        case KeyEvent.KEYCODE_3:
            return 3;
        case KeyEvent.KEYCODE_4:
            return 4;
        case KeyEvent.KEYCODE_5:
            return 5;
        case KeyEvent.KEYCODE_6:
            return 6;
        case KeyEvent.KEYCODE_7:
            return 7;
        case KeyEvent.KEYCODE_8:
            return 8;
        case KeyEvent.KEYCODE_9:
            return 9;
        default:
            return -1;
    }
}
 
Example 6
Source File: PjSipService.java    From CSipSimple with GNU General Public License v3.0 6 votes vote down vote up
/**
 * 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);
}
 
Example 7
Source File: TimePickerDialog.java    From AssistantBySDK with Apache License 2.0 6 votes vote down vote up
private static int getValFromKeyCode(int keyCode) {
    switch (keyCode) {
        case KeyEvent.KEYCODE_0:
            return 0;
        case KeyEvent.KEYCODE_1:
            return 1;
        case KeyEvent.KEYCODE_2:
            return 2;
        case KeyEvent.KEYCODE_3:
            return 3;
        case KeyEvent.KEYCODE_4:
            return 4;
        case KeyEvent.KEYCODE_5:
            return 5;
        case KeyEvent.KEYCODE_6:
            return 6;
        case KeyEvent.KEYCODE_7:
            return 7;
        case KeyEvent.KEYCODE_8:
            return 8;
        case KeyEvent.KEYCODE_9:
            return 9;
        default:
            return -1;
    }
}
 
Example 8
Source File: IMEService.java    From TVRemoteIME with GNU General Public License v2.0 6 votes vote down vote up
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
	if(handleKeyboardFocusEvent(keyCode)) return true;
	if (Environment.needDebug) {
		Environment.debug(TAG, "keydown-event:" + keyCode);
	}
	//同步软键盘状态处理代码:不处理以下按键事件则有可能物理键盘字符输入与软键盘的大小写状态不同步
	if(keyCode == KeyEvent.KEYCODE_CAPS_LOCK) capsOn = !capsOn;
	if ((keyCode >= KeyEvent.KEYCODE_0 && keyCode <= KeyEvent.KEYCODE_9)) {
		if(commitText(String.valueOf(keyCode - KeyEvent.KEYCODE_0))) return true;
	} else if (keyCode >= KeyEvent.KEYCODE_A && keyCode <= KeyEvent.KEYCODE_Z) {
		if (commitText(String.valueOf((char) ((capsOn ? 65 : 97) + keyCode - KeyEvent.KEYCODE_A))))
			return true;
	}
	return super.onKeyDown(keyCode, event);
}
 
Example 9
Source File: TimePickerDialog.java    From MaterialDateTimePicker with Apache License 2.0 6 votes vote down vote up
private static int getValFromKeyCode(int keyCode) {
    switch (keyCode) {
        case KeyEvent.KEYCODE_0:
            return 0;
        case KeyEvent.KEYCODE_1:
            return 1;
        case KeyEvent.KEYCODE_2:
            return 2;
        case KeyEvent.KEYCODE_3:
            return 3;
        case KeyEvent.KEYCODE_4:
            return 4;
        case KeyEvent.KEYCODE_5:
            return 5;
        case KeyEvent.KEYCODE_6:
            return 6;
        case KeyEvent.KEYCODE_7:
            return 7;
        case KeyEvent.KEYCODE_8:
            return 8;
        case KeyEvent.KEYCODE_9:
            return 9;
        default:
            return -1;
    }
}
 
Example 10
Source File: NumericTextView.java    From DateTimePicker with Apache License 2.0 5 votes vote down vote up
private static boolean isKeyCodeNumeric(int keyCode) {
    return keyCode == KeyEvent.KEYCODE_0 || keyCode == KeyEvent.KEYCODE_1
            || keyCode == KeyEvent.KEYCODE_2 || keyCode == KeyEvent.KEYCODE_3
            || keyCode == KeyEvent.KEYCODE_4 || keyCode == KeyEvent.KEYCODE_5
            || keyCode == KeyEvent.KEYCODE_6 || keyCode == KeyEvent.KEYCODE_7
            || keyCode == KeyEvent.KEYCODE_8 || keyCode == KeyEvent.KEYCODE_9;
}
 
Example 11
Source File: GUIListeners.java    From Beats with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
static public int keyCode2Direction(int keyCode) {
	/* interprets a keyCode as a direction
	 * input:   keyCode  - a key code passed to handler           
	 * output: [0 1 2 3] -> [left down up right]; -1 -> unknown
	 */
	switch (keyCode) {
	// WASD, ZX-NM spread, AS-KL spread
	// 12-90 spread, D-Pad
	// Headphone music controller
	case KeyEvent.KEYCODE_A: case KeyEvent.KEYCODE_Z:
	case KeyEvent.KEYCODE_1: case KeyEvent.KEYCODE_DPAD_LEFT:
	case KeyEvent.KEYCODE_MEDIA_PREVIOUS: case KeyEvent.KEYCODE_MEDIA_REWIND:
	case KeyEvent.KEYCODE_BUTTON_X:
		return 0;
	case KeyEvent.KEYCODE_S: case KeyEvent.KEYCODE_X:
	case KeyEvent.KEYCODE_2: case KeyEvent.KEYCODE_DPAD_DOWN:
	case KeyEvent.KEYCODE_MEDIA_STOP:
	case KeyEvent.KEYCODE_BUTTON_A:
		return 1;
	case KeyEvent.KEYCODE_W: case KeyEvent.KEYCODE_N: case KeyEvent.KEYCODE_K:
	case KeyEvent.KEYCODE_9: case KeyEvent.KEYCODE_DPAD_UP:
	case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
	case KeyEvent.KEYCODE_BUTTON_Y:
		return 2;
	case KeyEvent.KEYCODE_D: case KeyEvent.KEYCODE_M: case KeyEvent.KEYCODE_L:
	case KeyEvent.KEYCODE_0: case KeyEvent.KEYCODE_DPAD_RIGHT:
	case KeyEvent.KEYCODE_MEDIA_NEXT: case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD:
	case KeyEvent.KEYCODE_BUTTON_B:
		return 3;
	default:
		return -1;
	}
}
 
Example 12
Source File: TimePickerDialog.java    From AssistantBySDK with Apache License 2.0 4 votes vote down vote up
/**
 * For keyboard mode, processes key events.
 * @param keyCode the pressed key.
 * @return true if the key was successfully processed, false otherwise.
 */
private boolean processKeyUp(int keyCode) {
    if (keyCode == KeyEvent.KEYCODE_ESCAPE || keyCode == KeyEvent.KEYCODE_BACK) {
        if(isCancelable()) dismiss();
        return true;
    } else if (keyCode == KeyEvent.KEYCODE_TAB) {
        if(mInKbMode) {
            if (isTypedTimeFullyLegal()) {
                finishKbMode(true);
            }
            return true;
        }
    } else if (keyCode == KeyEvent.KEYCODE_ENTER) {
        if (mInKbMode) {
            if (!isTypedTimeFullyLegal()) {
                return true;
            }
            finishKbMode(false);
        }
        if (mCallback != null) {
            mCallback.onTimeSet(this,
                    mTimePicker.getHours(), mTimePicker.getMinutes(), mTimePicker.getSeconds());
        }
        dismiss();
        return true;
    } else if (keyCode == KeyEvent.KEYCODE_DEL) {
        if (mInKbMode) {
            if (!mTypedTimes.isEmpty()) {
                int deleted = deleteLastTypedKey();
                String deletedKeyStr;
                if (deleted == getAmOrPmKeyCode(AM)) {
                    deletedKeyStr = mAmText;
                } else if (deleted == getAmOrPmKeyCode(PM)) {
                    deletedKeyStr = mPmText;
                } else {
                    deletedKeyStr = String.format("%d", getValFromKeyCode(deleted));
                }
                Utils.tryAccessibilityAnnounce(mTimePicker,
                        String.format(mDeletedKeyFormat, deletedKeyStr));
                updateDisplay(true);
            }
        }
    } else if (keyCode == KeyEvent.KEYCODE_0 || keyCode == KeyEvent.KEYCODE_1
            || keyCode == KeyEvent.KEYCODE_2 || keyCode == KeyEvent.KEYCODE_3
            || keyCode == KeyEvent.KEYCODE_4 || keyCode == KeyEvent.KEYCODE_5
            || keyCode == KeyEvent.KEYCODE_6 || keyCode == KeyEvent.KEYCODE_7
            || keyCode == KeyEvent.KEYCODE_8 || keyCode == KeyEvent.KEYCODE_9
            || (!mIs24HourMode &&
                    (keyCode == getAmOrPmKeyCode(AM) || keyCode == getAmOrPmKeyCode(PM)))) {
        if (!mInKbMode) {
            if (mTimePicker == null) {
                // Something's wrong, because time picker should definitely not be null.
                Log.e(TAG, "Unable to initiate keyboard mode, TimePicker was null.");
                return true;
            }
            mTypedTimes.clear();
            tryStartingKbMode(keyCode);
            return true;
        }
        // We're already in keyboard mode.
        if (addKeyIfLegal(keyCode)) {
            updateDisplay(false);
        }
        return true;
    }
    return false;
}
 
Example 13
Source File: Apps.java    From emerald with GNU General Public License v3.0 4 votes vote down vote up
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
	if (event.getAction() != KeyEvent.ACTION_DOWN) {
		return super.onKeyDown(keyCode, event);
	}
	if (keyCode == KeyEvent.KEYCODE_MENU) {
		menu();
		return true;
	} else if (keyCode == KeyEvent.KEYCODE_BACK) {
		//Log.v(APP_TAG, "BACK pressed");
		if (searchIsOpened) {
			closeSearch();
		} else if (!isDefaultLauncher()) {
			finish();
			return true;
		} else {
			if (categories.getCurCategory().equals(CategoryManager.HIDDEN)) {
				findViewById(R.id.quit_hidden_apps).setVisibility(View.GONE);
				hideMainBarIfNeeded();
			}
			categories.prevCategory();
		}
		loadFilteredApps();
		return true;
	} else if (event.isAltPressed()) {
		if (keyCode >= KeyEvent.KEYCODE_1 && keyCode <= KeyEvent.KEYCODE_9) {
			Object app = dock.getApp(keyCode-KeyEvent.KEYCODE_1);
			if (app != null) {
				if (app instanceof AppData) {
					launch((AppData)app);
				} else if (app instanceof ShortcutData) {
					launch((ShortcutData)app);
				}
				return true;
			} else {
				return super.onKeyDown(keyCode, event);
			}
		} else if (keyCode == KeyEvent.KEYCODE_0 && !searchIsOpened) {
			openSearch();
		} else if (keyCode == KeyEvent.KEYCODE_DPAD_LEFT) {
			categories.setCurCategory(categories.getCategory(CategoryManager.PREVIOUS));
			loadFilteredApps();
		} else if (keyCode == KeyEvent.KEYCODE_DPAD_RIGHT) {
			categories.setCurCategory(categories.getCategory(CategoryManager.NEXT));
			loadFilteredApps();
		} else if (keyCode == KeyEvent.KEYCODE_DPAD_UP) {
			openCategoriesList();
		} else {
			return super.onKeyDown(keyCode, event);
		}
		return super.onKeyDown(keyCode, event);
	} else if (keyCode == KeyEvent.KEYCODE_DPAD_CENTER || keyCode == KeyEvent.KEYCODE_ENTER) {
		View view = getCurrentFocus();
		if (view != null) {
			Object viewTag = view.getTag();
			if (viewTag instanceof AppData) {
				launch((AppData)viewTag);
				return true;
			} else if (viewTag instanceof ShortcutData) {
				launch((ShortcutData)viewTag);
				return true;
			}
			return super.onKeyDown(keyCode, event);
		}
		return super.onKeyDown(keyCode, event);
	} else if (keyCode == KeyEvent.KEYCODE_VOLUME_UP) {
		if (options.getBoolean(Keys.VOLUME_BUTTONS, false)) {
			categories.setCurCategory(categories.getCategory(CategoryManager.PREVIOUS));
			loadFilteredApps();
			return true;
		} else {
			return super.onKeyDown(keyCode, event);
		}
	} else if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) {
		if (options.getBoolean(Keys.VOLUME_BUTTONS, false)) {
			categories.setCurCategory(categories.getCategory(CategoryManager.NEXT));
			loadFilteredApps();
			return true;
		} else {
			return super.onKeyDown(keyCode, event);
		}
	} else {
		return super.onKeyDown(keyCode, event);
	}
}
 
Example 14
Source File: TimePickerDialog.java    From date_picker_converter with Apache License 2.0 4 votes vote down vote up
/**
 * For keyboard mode, processes key events.
 * @param keyCode the pressed key.
 * @return true if the key was successfully processed, false otherwise.
 */
private boolean processKeyUp(int keyCode) {
    if (keyCode == KeyEvent.KEYCODE_ESCAPE || keyCode == KeyEvent.KEYCODE_BACK) {
        if(isCancelable()) dismiss();
        return true;
    } else if (keyCode == KeyEvent.KEYCODE_TAB) {
        if(mInKbMode) {
            if (isTypedTimeFullyLegal()) {
                finishKbMode(true);
            }
            return true;
        }
    } else if (keyCode == KeyEvent.KEYCODE_ENTER) {
        if (mInKbMode) {
            if (!isTypedTimeFullyLegal()) {
                return true;
            }
            finishKbMode(false);
        }
        if (mCallback != null) {
            mCallback.onTimeSet(this,
                    mTimePicker.getHours(), mTimePicker.getMinutes(), mTimePicker.getSeconds());
        }
        dismiss();
        return true;
    } else if (keyCode == KeyEvent.KEYCODE_DEL) {
        if (mInKbMode) {
            if (!mTypedTimes.isEmpty()) {
                int deleted = deleteLastTypedKey();
                String deletedKeyStr;
                if (deleted == getAmOrPmKeyCode(AM)) {
                    deletedKeyStr = mAmText;
                } else if (deleted == getAmOrPmKeyCode(PM)) {
                    deletedKeyStr = mPmText;
                } else {
                    deletedKeyStr = String.format(mLocale, "%d", getValFromKeyCode(deleted));
                }
                Utils.tryAccessibilityAnnounce(mTimePicker,
                        String.format(mDeletedKeyFormat, deletedKeyStr));
                updateDisplay(true);
            }
        }
    } else if (keyCode == KeyEvent.KEYCODE_0 || keyCode == KeyEvent.KEYCODE_1
            || keyCode == KeyEvent.KEYCODE_2 || keyCode == KeyEvent.KEYCODE_3
            || keyCode == KeyEvent.KEYCODE_4 || keyCode == KeyEvent.KEYCODE_5
            || keyCode == KeyEvent.KEYCODE_6 || keyCode == KeyEvent.KEYCODE_7
            || keyCode == KeyEvent.KEYCODE_8 || keyCode == KeyEvent.KEYCODE_9
            || (!mIs24HourMode &&
                    (keyCode == getAmOrPmKeyCode(AM) || keyCode == getAmOrPmKeyCode(PM)))) {
        if (!mInKbMode) {
            if (mTimePicker == null) {
                // Something's wrong, because time picker should definitely not be null.
                Log.e(TAG, "Unable to initiate keyboard mode, TimePicker was null.");
                return true;
            }
            mTypedTimes.clear();
            tryStartingKbMode(keyCode);
            return true;
        }
        // We're already in keyboard mode.
        if (addKeyIfLegal(keyCode)) {
            updateDisplay(false);
        }
        return true;
    }
    return false;
}
 
Example 15
Source File: TimePickerDialog.java    From Conquer with Apache License 2.0 4 votes vote down vote up
/**
 * For keyboard mode, processes key events.
 *
 * @param keyCode the pressed key.
 * @return true if the key was successfully processed, false otherwise.
 */
private boolean processKeyUp(int keyCode) {
    if (keyCode == KeyEvent.KEYCODE_ESCAPE || keyCode == KeyEvent.KEYCODE_BACK) {
        dismiss();
        return true;
    } else if (keyCode == KeyEvent.KEYCODE_TAB) {
        if (mInKbMode) {
            if (isTypedTimeFullyLegal()) {
                finishKbMode(true);
            }
            return true;
        }
    } else if (keyCode == KeyEvent.KEYCODE_ENTER) {
        if (mInKbMode) {
            if (!isTypedTimeFullyLegal()) {
                return true;
            }
            finishKbMode(false);
        }
        if (mCallback != null) {
            mCallback.onTimeSet(mTimePicker,
                    mTimePicker.getHours(), mTimePicker.getMinutes());
        }
        dismiss();
        return true;
    } else if (keyCode == KeyEvent.KEYCODE_DEL) {
        if (mInKbMode) {
            if (!mTypedTimes.isEmpty()) {
                int deleted = deleteLastTypedKey();
                String deletedKeyStr;
                if (deleted == getAmOrPmKeyCode(AM)) {
                    deletedKeyStr = mAmText;
                } else if (deleted == getAmOrPmKeyCode(PM)) {
                    deletedKeyStr = mPmText;
                } else {
                    deletedKeyStr = String.format("%d", getValFromKeyCode(deleted));
                }
                Utils.tryAccessibilityAnnounce(mTimePicker,
                        String.format(mDeletedKeyFormat, deletedKeyStr));
                updateDisplay(true);
            }
        }
    } else if (keyCode == KeyEvent.KEYCODE_0 || keyCode == KeyEvent.KEYCODE_1
            || keyCode == KeyEvent.KEYCODE_2 || keyCode == KeyEvent.KEYCODE_3
            || keyCode == KeyEvent.KEYCODE_4 || keyCode == KeyEvent.KEYCODE_5
            || keyCode == KeyEvent.KEYCODE_6 || keyCode == KeyEvent.KEYCODE_7
            || keyCode == KeyEvent.KEYCODE_8 || keyCode == KeyEvent.KEYCODE_9
            || (!mIs24HourMode &&
            (keyCode == getAmOrPmKeyCode(AM) || keyCode == getAmOrPmKeyCode(PM)))) {
        if (!mInKbMode) {
            if (mTimePicker == null) {
                // Something's wrong, because time picker should definitely not be null.
                Log.e(TAG, "Unable to initiate keyboard mode, TimePicker was null.");
                return true;
            }
            mTypedTimes.clear();
            tryStartingKbMode(keyCode);
            return true;
        }
        // We're already in keyboard mode.
        if (addKeyIfLegal(keyCode)) {
            updateDisplay(false);
        }
        return true;
    }
    return false;
}
 
Example 16
Source File: GridTimePickerDialog.java    From BottomSheetPickers with Apache License 2.0 4 votes vote down vote up
/**
 * For keyboard mode, processes key events.
 * @param keyCode the pressed key.
 * @return true if the key was successfully processed, false otherwise.
 */
private boolean processKeyUp(int keyCode) {
    if (keyCode == KeyEvent.KEYCODE_ESCAPE || keyCode == KeyEvent.KEYCODE_BACK) {
        dismiss();
        return true;
    } else if (keyCode == KeyEvent.KEYCODE_TAB) {
        if(mInKbMode) {
            if (isTypedTimeFullyLegal()) {
                finishKbMode(true);
            }
            return true;
        }
    } else if (keyCode == KeyEvent.KEYCODE_ENTER) {
        if (mInKbMode) {
            if (!isTypedTimeFullyLegal()) {
                return true;
            }
            finishKbMode(false);
        }
        onTimeSet(mTimePicker, mTimePicker.getHours(), mTimePicker.getMinutes());
        return true;
    } else if (keyCode == KeyEvent.KEYCODE_DEL) {
        if (mInKbMode) {
            if (!mTypedTimes.isEmpty()) {
                int deleted = deleteLastTypedKey();
                String deletedKeyStr;
                if (deleted == getAmOrPmKeyCode(HALF_DAY_1)) {
                    deletedKeyStr = mAmText;
                } else if (deleted == getAmOrPmKeyCode(HALF_DAY_2)) {
                    deletedKeyStr = mPmText;
                } else {
                    deletedKeyStr = String.format("%d", getValFromKeyCode(deleted));
                }
                Utils.tryAccessibilityAnnounce(mTimePicker,
                        String.format(mDeletedKeyFormat, deletedKeyStr));
                updateDisplay(true);
            }
        }
    } else if (keyCode == KeyEvent.KEYCODE_0 || keyCode == KeyEvent.KEYCODE_1
            || keyCode == KeyEvent.KEYCODE_2 || keyCode == KeyEvent.KEYCODE_3
            || keyCode == KeyEvent.KEYCODE_4 || keyCode == KeyEvent.KEYCODE_5
            || keyCode == KeyEvent.KEYCODE_6 || keyCode == KeyEvent.KEYCODE_7
            || keyCode == KeyEvent.KEYCODE_8 || keyCode == KeyEvent.KEYCODE_9
            || (!mIs24HourMode &&
                    (keyCode == getAmOrPmKeyCode(HALF_DAY_1) || keyCode == getAmOrPmKeyCode(HALF_DAY_2)))) {
        if (!mInKbMode) {
            if (mTimePicker == null) {
                // Something's wrong, because time picker should definitely not be null.
                Log.e(TAG, "Unable to initiate keyboard mode, TimePicker was null.");
                return true;
            }
            mTypedTimes.clear();
            tryStartingKbMode(keyCode);
            return true;
        }
        // We're already in keyboard mode.
        if (addKeyIfLegal(keyCode)) {
            updateDisplay(false);
        }
        return true;
    }
    return false;
}
 
Example 17
Source File: TimePickerDialog.java    From Blackbulb with GNU General Public License v3.0 4 votes vote down vote up
/**
 * For keyboard mode, processes key events.
 * @param keyCode the pressed key.
 * @return true if the key was successfully processed, false otherwise.
 */
private boolean processKeyUp(int keyCode) {
    if (keyCode == KeyEvent.KEYCODE_ESCAPE || keyCode == KeyEvent.KEYCODE_BACK) {
        if(isCancelable()) dismiss();
        return true;
    } else if (keyCode == KeyEvent.KEYCODE_TAB) {
        if(mInKbMode) {
            if (isTypedTimeFullyLegal()) {
                finishKbMode(true);
            }
            return true;
        }
    } else if (keyCode == KeyEvent.KEYCODE_ENTER) {
        if (mInKbMode) {
            if (!isTypedTimeFullyLegal()) {
                return true;
            }
            finishKbMode(false);
        }
        if (mCallback != null) {
            mCallback.onTimeSet(this,
                    mTimePicker.getHours(), mTimePicker.getMinutes(), mTimePicker.getSeconds());
        }
        dismiss();
        return true;
    } else if (keyCode == KeyEvent.KEYCODE_DEL) {
        if (mInKbMode) {
            if (!mTypedTimes.isEmpty()) {
                int deleted = deleteLastTypedKey();
                String deletedKeyStr;
                if (deleted == getAmOrPmKeyCode(AM)) {
                    deletedKeyStr = mAmText;
                } else if (deleted == getAmOrPmKeyCode(PM)) {
                    deletedKeyStr = mPmText;
                } else {
                    deletedKeyStr = String.format("%d", getValFromKeyCode(deleted));
                }
                Utils.tryAccessibilityAnnounce(mTimePicker,
                        String.format(mDeletedKeyFormat, deletedKeyStr));
                updateDisplay(true);
            }
        }
    } else if (keyCode == KeyEvent.KEYCODE_0 || keyCode == KeyEvent.KEYCODE_1
            || keyCode == KeyEvent.KEYCODE_2 || keyCode == KeyEvent.KEYCODE_3
            || keyCode == KeyEvent.KEYCODE_4 || keyCode == KeyEvent.KEYCODE_5
            || keyCode == KeyEvent.KEYCODE_6 || keyCode == KeyEvent.KEYCODE_7
            || keyCode == KeyEvent.KEYCODE_8 || keyCode == KeyEvent.KEYCODE_9
            || (!mIs24HourMode &&
                    (keyCode == getAmOrPmKeyCode(AM) || keyCode == getAmOrPmKeyCode(PM)))) {
        if (!mInKbMode) {
            if (mTimePicker == null) {
                // Something's wrong, because time picker should definitely not be null.
                Log.e(TAG, "Unable to initiate keyboard mode, TimePicker was null.");
                return true;
            }
            mTypedTimes.clear();
            tryStartingKbMode(keyCode);
            return true;
        }
        // We're already in keyboard mode.
        if (addKeyIfLegal(keyCode)) {
            updateDisplay(false);
        }
        return true;
    }
    return false;
}
 
Example 18
Source File: TimePickerDialog.java    From AlarmOn with Apache License 2.0 4 votes vote down vote up
/**
 * For keyboard mode, processes key events.
 * @param keyCode the pressed key.
 * @return true if the key was successfully processed, false otherwise.
 */
private boolean processKeyUp(int keyCode) {
    if (keyCode == KeyEvent.KEYCODE_ESCAPE || keyCode == KeyEvent.KEYCODE_BACK) {
        if(isCancelable()) dismiss();
        return true;
    } else if (keyCode == KeyEvent.KEYCODE_TAB) {
        if(mInKbMode) {
            if (isTypedTimeFullyLegal()) {
                finishKbMode(true);
            }
            return true;
        }
    } else if (keyCode == KeyEvent.KEYCODE_ENTER) {
        if (mInKbMode) {
            if (!isTypedTimeFullyLegal()) {
                return true;
            }
            finishKbMode(false);
        }
        if (mCallback != null) {
            mCallback.onTimeSet(mTimePicker,
                    mTimePicker.getHours(), mTimePicker.getMinutes(), mTimePicker.getSeconds());
        }
        dismiss();
        return true;
    } else if (keyCode == KeyEvent.KEYCODE_DEL) {
        if (mInKbMode) {
            if (!mTypedTimes.isEmpty()) {
                int deleted = deleteLastTypedKey();
                String deletedKeyStr;
                if (deleted == getAmOrPmKeyCode(AM)) {
                    deletedKeyStr = mAmText;
                } else if (deleted == getAmOrPmKeyCode(PM)) {
                    deletedKeyStr = mPmText;
                } else {
                    deletedKeyStr = String.format("%d", getValFromKeyCode(deleted));
                }
                Utils.tryAccessibilityAnnounce(mTimePicker,
                        String.format(mDeletedKeyFormat, deletedKeyStr));
                updateDisplay(true);
            }
        }
    } else if (keyCode == KeyEvent.KEYCODE_0 || keyCode == KeyEvent.KEYCODE_1
            || keyCode == KeyEvent.KEYCODE_2 || keyCode == KeyEvent.KEYCODE_3
            || keyCode == KeyEvent.KEYCODE_4 || keyCode == KeyEvent.KEYCODE_5
            || keyCode == KeyEvent.KEYCODE_6 || keyCode == KeyEvent.KEYCODE_7
            || keyCode == KeyEvent.KEYCODE_8 || keyCode == KeyEvent.KEYCODE_9
            || (!mIs24HourMode &&
                    (keyCode == getAmOrPmKeyCode(AM) || keyCode == getAmOrPmKeyCode(PM)))) {
        if (!mInKbMode) {
            if (mTimePicker == null) {
                // Something's wrong, because time picker should definitely not be null.
                Log.e(TAG, "Unable to initiate keyboard mode, TimePicker was null.");
                return true;
            }
            mTypedTimes.clear();
            tryStartingKbMode(keyCode);
            return true;
        }
        // We're already in keyboard mode.
        if (addKeyIfLegal(keyCode)) {
            updateDisplay(false);
        }
        return true;
    }
    return false;
}
 
Example 19
Source File: TimePickerDialog.java    From MaterialDateTimePicker with Apache License 2.0 4 votes vote down vote up
/**
 * For keyboard mode, processes key events.
 * @param keyCode the pressed key.
 * @return true if the key was successfully processed, false otherwise.
 */
private boolean processKeyUp(int keyCode) {
    if (keyCode == KeyEvent.KEYCODE_TAB) {
        if(mInKbMode) {
            if (isTypedTimeFullyLegal()) {
                finishKbMode(true);
            }
            return true;
        }
    } else if (keyCode == KeyEvent.KEYCODE_ENTER) {
        if (mInKbMode) {
            if (!isTypedTimeFullyLegal()) {
                return true;
            }
            finishKbMode(false);
        }
        if (mCallback != null) {
            mCallback.onTimeSet(this,
                    mTimePicker.getHours(), mTimePicker.getMinutes(), mTimePicker.getSeconds());
        }
        dismiss();
        return true;
    } else if (keyCode == KeyEvent.KEYCODE_DEL) {
        if (mInKbMode) {
            if (!mTypedTimes.isEmpty()) {
                int deleted = deleteLastTypedKey();
                String deletedKeyStr;
                if (deleted == getAmOrPmKeyCode(AM)) {
                    deletedKeyStr = mAmText;
                } else if (deleted == getAmOrPmKeyCode(PM)) {
                    deletedKeyStr = mPmText;
                } else {
                    deletedKeyStr = String.format(mLocale, "%d", getValFromKeyCode(deleted));
                }
                Utils.tryAccessibilityAnnounce(mTimePicker,
                        String.format(mDeletedKeyFormat, deletedKeyStr));
                updateDisplay(true);
            }
        }
    } else if (keyCode == KeyEvent.KEYCODE_0 || keyCode == KeyEvent.KEYCODE_1
            || keyCode == KeyEvent.KEYCODE_2 || keyCode == KeyEvent.KEYCODE_3
            || keyCode == KeyEvent.KEYCODE_4 || keyCode == KeyEvent.KEYCODE_5
            || keyCode == KeyEvent.KEYCODE_6 || keyCode == KeyEvent.KEYCODE_7
            || keyCode == KeyEvent.KEYCODE_8 || keyCode == KeyEvent.KEYCODE_9
            || (!mIs24HourMode &&
                    (keyCode == getAmOrPmKeyCode(AM) || keyCode == getAmOrPmKeyCode(PM)))) {
        if (!mInKbMode) {
            if (mTimePicker == null) {
                // Something's wrong, because time picker should definitely not be null.
                Log.e(TAG, "Unable to initiate keyboard mode, TimePicker was null.");
                return true;
            }
            mTypedTimes.clear();
            tryStartingKbMode(keyCode);
            return true;
        }
        // We're already in keyboard mode.
        if (addKeyIfLegal(keyCode)) {
            updateDisplay(false);
        }
        return true;
    }
    return false;
}
 
Example 20
Source File: SwitchTimePicker.java    From Android-SwitchDateTimePicker with Apache License 2.0 4 votes vote down vote up
/**
 * For keyboard mode, processes key events.
 *
 * @param keyCode the pressed key.
 * @return true if the key was successfully processed, false otherwise.
 */
private boolean processKeyUp(int keyCode) {
    if (keyCode == KeyEvent.KEYCODE_ESCAPE || keyCode == KeyEvent.KEYCODE_BACK) {
        //dismiss();
        return true;
    } else if (keyCode == KeyEvent.KEYCODE_TAB) {
        if (mInKbMode) {
            if (isTypedTimeFullyLegal()) {
                finishKbMode(true);
            }
            return true;
        }
    } else if (keyCode == KeyEvent.KEYCODE_ENTER) {
        if (mInKbMode) {
            if (!isTypedTimeFullyLegal()) {
                return true;
            }
            finishKbMode(false);
        }
        if (onTimeSelectedListener != null) {
            onTimeSelectedListener.onTimeSelected(mTimePicker.getHours(), mTimePicker.getMinutes());
        }
        //dismiss();
        return true;
    } else if (keyCode == KeyEvent.KEYCODE_DEL) {
        if (mInKbMode) {
            if (!mTypedTimes.isEmpty()) {
                int deleted = deleteLastTypedKey();
                String deletedKeyStr;
                if (deleted == getAmOrPmKeyCode(AM)) {
                    deletedKeyStr = mAmText;
                } else if (deleted == getAmOrPmKeyCode(PM)) {
                    deletedKeyStr = mPmText;
                } else {
                    deletedKeyStr = String.format(Locale.getDefault(), "%d", getValFromKeyCode(deleted));
                }
                Utils.tryAccessibilityAnnounce(mTimePicker,
                        String.format(mDeletedKeyFormat, deletedKeyStr));
                updateDisplay(true);
            }
        }
    } else if (keyCode == KeyEvent.KEYCODE_0 || keyCode == KeyEvent.KEYCODE_1
            || keyCode == KeyEvent.KEYCODE_2 || keyCode == KeyEvent.KEYCODE_3
            || keyCode == KeyEvent.KEYCODE_4 || keyCode == KeyEvent.KEYCODE_5
            || keyCode == KeyEvent.KEYCODE_6 || keyCode == KeyEvent.KEYCODE_7
            || keyCode == KeyEvent.KEYCODE_8 || keyCode == KeyEvent.KEYCODE_9
            || (!mIs24HourMode &&
            (keyCode == getAmOrPmKeyCode(AM) || keyCode == getAmOrPmKeyCode(PM)))) {
        if (!mInKbMode) {
            if (mTimePicker == null) {
                // Something's wrong, because time picker should definitely not be null.
                Log.e(TAG, "Unable to initiate keyboard mode, TimePicker was null.");
                return true;
            }
            mTypedTimes.clear();
            tryStartingKbMode(keyCode);
            return true;
        }
        // We're already in keyboard mode.
        if (addKeyIfLegal(keyCode)) {
            updateDisplay(false);
        }
        return true;
    }
    return false;
}