List of usage examples for android.view KeyEvent toString
@Override
public String toString()
From source file:com.example.venkatagovardhan.docorganizer.FolderActivity.java
@Override public boolean onKeyLongPress(int keyCode, KeyEvent event) { Log.d("Key Long Press", event.toString()); if (keyCode == KeyEvent.KEYCODE_BACK) { finish();//from www . j av a 2s . co m return true; } else return super.onKeyLongPress(keyCode, event); }
From source file:org.openhab.habdroid.ui.OpenHABWidgetListActivity.java
@Override public boolean onKeyLongPress(int keyCode, KeyEvent event) { Log.d(TAG, "keyCode = " + String.format("%d", keyCode)); Log.d(TAG, "event = " + event.toString()); if (keyCode == 4) { return true; } else {/*from w ww .j a v a 2s . com*/ return super.onKeyLongPress(keyCode, event); } }
From source file:org.openhab.habdroid.ui.OpenHABMainActivity.java
@Override public boolean onKeyUp(int keyCode, KeyEvent event) { Log.v(TAG, "KeyUp: " + event.toString()); if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN || keyCode == KeyEvent.KEYCODE_VOLUME_UP) { if (pagerAdapter.getFragment(pager.getCurrentItem()) instanceof OpenHABWidgetListFragment) { OpenHABWidgetListFragment currentFragment = (OpenHABWidgetListFragment) pagerAdapter .getFragment(pager.getCurrentItem()); if (currentFragment != null && currentFragment.isVolumeHandled()) return true; }//from w w w . ja v a 2 s. c om } return super.onKeyUp(keyCode, event); }
From source file:org.openhab.habdroid.ui.OpenHABMainActivity.java
@Override public boolean onKeyDown(int keyCode, KeyEvent event) { Log.v(TAG, "KeyDown: " + event.toString()); if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) { if (pagerAdapter.getFragment(pager.getCurrentItem()) instanceof OpenHABWidgetListFragment) { OpenHABWidgetListFragment currentFragment = (OpenHABWidgetListFragment) pagerAdapter .getFragment(pager.getCurrentItem()); if (currentFragment != null) return currentFragment.onVolumeDown(); }/*from ww w. j a v a 2 s .co m*/ } else if (keyCode == KeyEvent.KEYCODE_VOLUME_UP) { if (pagerAdapter.getFragment(pager.getCurrentItem()) instanceof OpenHABWidgetListFragment) { OpenHABWidgetListFragment currentFragment = (OpenHABWidgetListFragment) pagerAdapter .getFragment(pager.getCurrentItem()); if (currentFragment != null) return currentFragment.onVolumeUp(); } } return super.onKeyDown(keyCode, event); }
From source file:com.vladstirbu.cordova.Gamepad.java
/** * @param cordova The context of the main Activity. * @param webView The associated CordovaWebView. */// w w w. j a v a 2 s. c o m @Override public void initialize(CordovaInterface cordova, CordovaWebView webView) { super.initialize(cordova, webView); this.map.put("KEYCODE_BUTTON_A", 0); this.map.put("KEYCODE_BUTTON_B", 1); this.map.put("KEYCODE_BUTTON_Y", 3); this.map.put("KEYCODE_BUTTON_X", 2); this.map.put("KEYCODE_BUTTON_L1", 4); this.map.put("KEYCODE_BUTTON_R1", 5); this.map.put("KEYCODE_BUTTON_L2", 6); this.map.put("KEYCODE_BUTTON_R2", 7); this.map.put("KEYCODE_SPACE", 8); this.map.put("KEYCODE_SELECT", 8); this.map.put("KEYCODE_ENTER", 9); this.map.put("KEYCODE_START", 9); this.map.put("KEYCODE_BUTTON_THUMBL", 10); this.map.put("KEYCODE_BUTTON_THUMBR", 11); this.map.put("KEYCODE_DPAD_UP", 12); this.map.put("KEYCODE_DPAD_DOWN", 13); this.map.put("KEYCODE_DPAD_LEFT", 14); this.map.put("KEYCODE_DPAD_RIGHT", 15); this.map.put("KEYCODE_BACK", 16); this.map.put("KEYCODE_BUTTON_MODE", 16); this.webView.setFocusable(true); this.webView.setFocusableInTouchMode(true); this.webView.requestFocus(); this.webView.setOnKeyListener(new OnKeyListener() { @Override public boolean onKey(View v, int keyCode, KeyEvent event) { //Log.v("Keyboards", String.valueOf(InputDevice.getDeviceIds().length)); //Log.v("Input", InputDevice.getDevice(1).getName()); //Log.v("Input", String.valueOf(InputDevice.getDevice(1).getSources())); //Log.v("Device id", String.valueOf(event.getDeviceId())); //Log.v("Source id", String.valueOf(event.getSource())); //Log.v("Input device", String.valueOf(InputDevice.getDevice(event.getDeviceId()).getName())); Log.v("KEY", String.valueOf(event.getScanCode())); Log.v("KEY", KeyEvent.keyCodeToString(keyCode)); //Log.v("GamePad", String.valueOf(KeyEvent.isGamepadButton(keyCode))); String jsStr = jsString(keyCode, event); if (!jsStr.isEmpty()) { self.webView.sendJavascript(jsStr); } return true; } }); this.webView.setOnGenericMotionListener(new OnGenericMotionListener() { public boolean onGenericMotion(View v, MotionEvent event) { if (event.isFromSource(InputDevice.SOURCE_CLASS_JOYSTICK)) { if (event.getAction() == MotionEvent.ACTION_MOVE) { // process the joystick movement... JSONObject data = new JSONObject(); JSONArray axes = new JSONArray(); try { axes.put(event.getAxisValue(MotionEvent.AXIS_X)); axes.put(event.getAxisValue(MotionEvent.AXIS_Y)); axes.put(event.getAxisValue(MotionEvent.AXIS_Z)); axes.put(event.getAxisValue(MotionEvent.AXIS_RZ)); data.put("deviceId", event.getDeviceId()); data.put("axes", axes); } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } self.webView.sendJavascript( "cordova.fireWindowEvent('GamepadMotion', " + data.toString() + ");"); data = new JSONObject(); try { data.put("deviceId", event.getDeviceId()); data.put("button", 6); data.put("value", event.getAxisValue(MotionEvent.AXIS_LTRIGGER)); } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } self.webView.sendJavascript( "cordova.fireWindowEvent('GamepadMotion', " + data.toString() + ");"); data = new JSONObject(); try { data.put("deviceId", event.getDeviceId()); data.put("button", 7); data.put("value", event.getAxisValue(MotionEvent.AXIS_RTRIGGER)); } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } self.webView.sendJavascript( "cordova.fireWindowEvent('GamepadMotion', " + data.toString() + ");"); float hatX = event.getAxisValue(MotionEvent.AXIS_HAT_X); float hatY = event.getAxisValue(MotionEvent.AXIS_HAT_Y); try { data = new JSONObject(); data.put("deviceId", event.getDeviceId()); data.put("button", 14); data.put("value", hatX < 0.0f); self.webView.sendJavascript( "cordova.fireWindowEvent('GamepadMotion', " + data.toString() + ");"); data = new JSONObject(); data.put("deviceId", event.getDeviceId()); data.put("button", 15); data.put("value", hatX > 0.0f); self.webView.sendJavascript( "cordova.fireWindowEvent('GamepadMotion', " + data.toString() + ");"); } catch (JSONException e) { } try { data = new JSONObject(); data.put("deviceId", event.getDeviceId()); data.put("button", 12); data.put("value", hatY < 0.0f); self.webView.sendJavascript( "cordova.fireWindowEvent('GamepadMotion', " + data.toString() + ");"); data = new JSONObject(); data.put("deviceId", event.getDeviceId()); data.put("button", 13); data.put("value", hatY > 0.0f); self.webView.sendJavascript( "cordova.fireWindowEvent('GamepadMotion', " + data.toString() + ");"); } catch (JSONException e) { } } Log.v("MOTION", event.toString()); return true; } return false; } }); Log.v("GamepadButtons", "initialized"); }