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 ; }
Get the keycode value for AM and PM in the current language .