List of usage examples for android.view InputDevice SOURCE_MOUSE
int SOURCE_MOUSE
To view the source code for android.view InputDevice SOURCE_MOUSE.
Click Source Link
From source file:Main.java
@SuppressLint("InlinedApi") public static String getSourcesString(int sources) { List<String> names = new ArrayList<String>(); addString(sources, InputDevice.SOURCE_KEYBOARD, names); addString(sources, InputDevice.SOURCE_DPAD, names); addString(sources, InputDevice.SOURCE_GAMEPAD, names); addString(sources, InputDevice.SOURCE_TOUCHSCREEN, names); addString(sources, InputDevice.SOURCE_MOUSE, names); addString(sources, InputDevice.SOURCE_STYLUS, names); addString(sources, InputDevice.SOURCE_TOUCHPAD, names); addString(sources, InputDevice.SOURCE_JOYSTICK, names); return TextUtils.join(", ", names); }
From source file:Main.java
/** * Gets the name of the source performing an action. * /*from w ww . j a va2 s . c o m*/ * @param source A number representing the source. * * @return The name of the source. */ public static String getSourceName(int source) { switch (source) { case InputDevice.SOURCE_CLASS_BUTTON: return "BUTTON"; case InputDevice.SOURCE_CLASS_POINTER: return "POINTER"; case InputDevice.SOURCE_CLASS_TRACKBALL: return "TRACKBALL"; case InputDevice.SOURCE_CLASS_POSITION: return "POSITION"; case InputDevice.SOURCE_CLASS_JOYSTICK: return "JOYSTICK"; case InputDevice.SOURCE_DPAD: return "dpad"; case InputDevice.SOURCE_GAMEPAD: return "gamepad"; case InputDevice.SOURCE_JOYSTICK: return "joystick"; case InputDevice.SOURCE_KEYBOARD: return "keyboard"; case InputDevice.SOURCE_MOUSE: return "mouse"; case InputDevice.SOURCE_STYLUS: return "stylus"; case InputDevice.SOURCE_TOUCHPAD: return "touchpad"; case InputDevice.SOURCE_TOUCHSCREEN: return "touchscreen"; case InputDevice.SOURCE_TRACKBALL: return "trackball"; case InputDevice.SOURCE_UNKNOWN: return "unknown"; default: return "source_" + source; } }
From source file:org.connectbot.util.TerminalTextViewOverlay.java
@Override public boolean onTouchEvent(MotionEvent event) { if (event.getAction() == MotionEvent.ACTION_DOWN) { // Selection may be beginning. Sync the TextView with the buffer. refreshTextFromBuffer();/*from w ww .j a v a 2s .c om*/ } // Mouse input is treated differently: if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH && MotionEventCompat.getSource(event) == InputDevice.SOURCE_MOUSE) { if (onMouseEvent(event, terminalView.bridge)) { return true; } terminalView.viewPager.setPagingEnabled(true); } else { if (terminalView.onTouchEvent(event)) { return true; } } return super.onTouchEvent(event); }
From source file:org.connectbot.util.TerminalTextViewOverlay.java
/** * Takes an android mouse event and produces a Java InputEvent modifiers int which can be * passed to vt320.// w ww . j av a 2 s . c om * @param mouseEvent The {@link MotionEvent} which should be a mouse click or release. * @return A Java InputEvent modifier int. See * http://docs.oracle.com/javase/7/docs/api/java/awt/event/InputEvent.html */ @TargetApi(14) private static int mouseEventToJavaModifiers(MotionEvent mouseEvent) { if (MotionEventCompat.getSource(mouseEvent) != InputDevice.SOURCE_MOUSE) return 0; int mods = 0; // See http://docs.oracle.com/javase/7/docs/api/constant-values.html int buttonState = mouseEvent.getButtonState(); if ((buttonState & MotionEvent.BUTTON_PRIMARY) != 0) mods |= 16; if ((buttonState & MotionEvent.BUTTON_SECONDARY) != 0) mods |= 8; if ((buttonState & MotionEvent.BUTTON_TERTIARY) != 0) mods |= 4; // Note: Meta and Ctrl are intentionally swapped here to keep logic in vt320 simple. int meta = mouseEvent.getMetaState(); if ((meta & KeyEvent.META_META_ON) != 0) mods |= 2; if ((meta & KeyEvent.META_SHIFT_ON) != 0) mods |= 1; if ((meta & KeyEvent.META_CTRL_ON) != 0) mods |= 4; return mods; }
From source file:com.amazon.appstream.fireclient.FireClientActivity.java
/** * A "generic motion event" includes joystick and mouse motion * when the mouse button isn't down. In our simple sample, we're * not handling the joystick, but this is where any such code * would live./*ww w . ja v a2 s . com*/ * * This will only ever be called in HONEYCOMB_MR1 (12) or later, so I'm marking the * function using \@TargetApi to allow it to call the super. */ @TargetApi(Build.VERSION_CODES.HONEYCOMB_MR1) @Override public boolean dispatchGenericMotionEvent(MotionEvent event) { if (event.getSource() == InputDevice.SOURCE_MOUSE) { event.getPointerCoords(0, mCoordHolder); switch (event.getAction()) { case MotionEvent.ACTION_HOVER_MOVE: AppStreamInterface.mouseEvent((int) mCoordHolder.x, (int) mCoordHolder.y, 0); break; default: return super.dispatchGenericMotionEvent(event); } return true; } else if (event.getSource() == InputDevice.SOURCE_JOYSTICK) { Log.v(TAG, "Joystick event:" + event.toString()); if (!mInitializedJoystick) { mInitializedJoystick = true; InputDevice joystick = InputDevice.getDevice(event.getDeviceId()); InputDevice.MotionRange lThumbX = joystick.getMotionRange(MotionEvent.AXIS_X, InputDevice.SOURCE_JOYSTICK); InputDevice.MotionRange lThumbY = joystick.getMotionRange(MotionEvent.AXIS_Y, InputDevice.SOURCE_JOYSTICK); InputDevice.MotionRange rThumbX = joystick.getMotionRange(MotionEvent.AXIS_Z); InputDevice.MotionRange rThumbY = joystick.getMotionRange(MotionEvent.AXIS_RZ); InputDevice.MotionRange rTrigger = joystick.getMotionRange(MotionEvent.AXIS_GAS); if (rTrigger == null) { rTrigger = joystick.getMotionRange(MotionEvent.AXIS_RTRIGGER); mRTrigger = MotionEvent.AXIS_RTRIGGER; } InputDevice.MotionRange lTrigger = joystick.getMotionRange(MotionEvent.AXIS_BRAKE); if (lTrigger == null) { lTrigger = joystick.getMotionRange(MotionEvent.AXIS_LTRIGGER); mLTrigger = MotionEvent.AXIS_LTRIGGER; } List<InputDevice.MotionRange> ranges = joystick.getMotionRanges(); InputDevice.MotionRange dPad = null; String name = joystick.getName(); /* The Amazon Fire Game Controller follows the NVidia standard of sending AXIS_HAT_X/AXIS_HAT_Y results when the user hits the D-Pad. Only if we return false from dispatchGenericMotionEvent() will it then send DPAD keycodes. But the most popular Android joystick on the market at this time, the Nyko Playpad Pro, returns AXIS_HAT_X/AXIS_HAT_Y results when the left analog stick hits its extremes, meaning that the analog stick will generate DPAD keys if we return false. The Nyko generates DPAD keys directly for the DPAD controller. So we have two incompatible standards fighting with each other. Probably the safest thing to do would be to ask the user to press on their DPAD and see what messages we get, but that is beyond the scope of this example code. */ if (name.equals("Amazon Fire Game Controler")) { for (int i = 0; i < ranges.size(); ++i) { InputDevice.MotionRange range = ranges.get(i); int axis = range.getAxis(); if (axis == MotionEvent.AXIS_HAT_X || axis == MotionEvent.AXIS_HAT_Y) { dPad = ranges.get(i); break; } } } JoystickHelper.joystickDeadZones(lTrigger, rTrigger, lThumbX, lThumbY, rThumbX, rThumbY, dPad); } float lThumbX = event.getAxisValue(MotionEvent.AXIS_X); float lThumbY = -event.getAxisValue(MotionEvent.AXIS_Y); float rThumbX = event.getAxisValue(MotionEvent.AXIS_Z); float rThumbY = -event.getAxisValue(MotionEvent.AXIS_RZ); float lTrigger = event.getAxisValue(mLTrigger); float rTrigger = event.getAxisValue(mRTrigger); float hatX = event.getAxisValue(MotionEvent.AXIS_HAT_X); float hatY = event.getAxisValue(MotionEvent.AXIS_HAT_Y); JoystickHelper.setJoystickState(lTrigger, rTrigger, lThumbX, lThumbY, rThumbX, rThumbY, hatX, hatY); return true; } return super.dispatchGenericMotionEvent(event); }
From source file:org.ulteo.ovd.AndRdpActivity.java
@Override public boolean dispatchKeyEvent(KeyEvent event) { AudioManager audioManager;/*from ww w . j av a2s . co m*/ if (Config.DEBUG) Log.i(Config.TAG, "AndRdpActivity.dispatchKeyEvent " + event); // Disable keypress if it is from a mouse or touchpad. if (event.getDeviceId() >= 0) { InputDevice dev = InputDevice.getDevice(event.getDeviceId()); if (dev.getSources() == InputDevice.SOURCE_MOUSE || dev.getSources() == InputDevice.SOURCE_TOUCHPAD) return true; } if (event.getAction() == KeyEvent.ACTION_DOWN) { switch (event.getKeyCode()) { case KeyEvent.KEYCODE_MENU: OnThreeFingers(null); return true; case KeyEvent.KEYCODE_BACK: Log.i(Config.TAG, "Back key pressed"); askLogoutDialog(); return true; case KeyEvent.KEYCODE_VOLUME_UP: audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE); audioManager.adjustStreamVolume(AudioManager.STREAM_MUSIC, AudioManager.ADJUST_RAISE, AudioManager.FLAG_SHOW_UI); return true; case KeyEvent.KEYCODE_VOLUME_DOWN: audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE); audioManager.adjustStreamVolume(AudioManager.STREAM_MUSIC, AudioManager.ADJUST_LOWER, AudioManager.FLAG_SHOW_UI); return true; } } else if (event.getAction() == KeyEvent.ACTION_UP) { switch (event.getKeyCode()) { case KeyEvent.KEYCODE_MENU: case KeyEvent.KEYCODE_BACK: case KeyEvent.KEYCODE_VOLUME_UP: case KeyEvent.KEYCODE_VOLUME_DOWN: return true; } } if (isLoggedIn() && rdp.dispatchKeyEvent(event)) return true; return super.dispatchKeyEvent(event); }
From source file:com.amazon.appstream.sampleclient.SampleClientActivity.java
/** * A "generic motion event" includes joystick and mouse motion * when the mouse button isn't down. In our simple sample, we're * not handling the joystick, but this is where any such code * would live.// w w w. j av a2s .co m * * This will only ever be called in HONEYCOMB_MR1 (12) or later, so I'm marking the * function using \@TargetApi to allow it to call the super. */ @TargetApi(Build.VERSION_CODES.HONEYCOMB_MR1) @Override public boolean dispatchGenericMotionEvent(MotionEvent event) { if (event.getSource() == InputDevice.SOURCE_MOUSE) { event.getPointerCoords(0, mCoordHolder); switch (event.getAction()) { case MotionEvent.ACTION_HOVER_MOVE: AppStreamInterface.mouseEvent((int) mCoordHolder.x, (int) mCoordHolder.y, 0); break; default: return super.dispatchGenericMotionEvent(event); } return true; } return super.dispatchGenericMotionEvent(event); }