Android examples for User Interface:Key Event
Checks whether the given Key event is any of DPAD down, DPAD up, NUMPAD down or NUMPAD up.
// Copyright 2012 The Chromium Authors. All rights reserved. //package com.java2s; import android.view.KeyEvent; public class Main { /**/*from w w w .j av a2 s.c o m*/ * Checks whether the given event is any of DPAD down, DPAD up, NUMPAD down or NUMPAD up. * @param event Event to be checked. * @return Whether the event should be processed as any of navigation up or navigation down. */ public static boolean isGoUpOrDown(KeyEvent event) { return isGoDown(event) || isGoUp(event); } /** * Checks whether the given event is any of DPAD down or NUMPAD down. * @param event Event to be checked. * @return Whether the event should be processed as a navigation down. */ public static boolean isGoDown(KeyEvent event) { return isActionDown(event) && (event.getKeyCode() == KeyEvent.KEYCODE_DPAD_DOWN || (!event .isNumLockOn() && event.getKeyCode() == KeyEvent.KEYCODE_NUMPAD_2)); } /** * Checks whether the given event is any of DPAD up or NUMPAD up. * @param event Event to be checked. * @return Whether the event should be processed as a navigation up. */ public static boolean isGoUp(KeyEvent event) { return isActionDown(event) && (event.getKeyCode() == KeyEvent.KEYCODE_DPAD_UP || (!event .isNumLockOn() && event.getKeyCode() == KeyEvent.KEYCODE_NUMPAD_8)); } /** * Checks whether the given event is an ACTION_DOWN event. * @param event Event to be checked. * @return Whether the event is an ACTION_DOWN event. */ public static boolean isActionDown(KeyEvent event) { return event.getAction() == KeyEvent.ACTION_DOWN; } }