List of usage examples for android.view InputDevice getName
public String getName()
From source file:ch.jeda.platform.android.CanvasFragment.java
private static EventSource mapDevice(final android.view.InputEvent event) { final android.view.InputDevice device = event.getDevice(); final int id = device.getId(); if (!INPUT_DEVICE_MAP.containsKey(id)) { INPUT_DEVICE_MAP.put(id, new EventSource(device.getName())); }/* w w w .ja va2s. co m*/ return INPUT_DEVICE_MAP.get(id); }
From source file:org.uoyabause.android.tv.GameSelectActivity.java
@Override public boolean dispatchKeyEvent(KeyEvent event) { InputDevice dev = InputDevice.getDevice(event.getDeviceId()); if (dev != null && dev.getName().contains("HuiJia")) { if (event.getKeyCode() > 200) { return true; }/*from w w w .j a v a 2 s .co m*/ } return super.dispatchKeyEvent(event); }
From source file:net.pocketmagic.android.eventinjector.MainActivity.java
/** * Populated the listview with discovered devices, and the spinner with * those that are open/*from w w w . j av a2 s . c o m*/ */ private void PopulateListView() { m_lvDevices.post(new Runnable() { public void run() { m_lvDevices.setAdapter(null); ArrayList<ListViewItem> m_Devices = new ArrayList<ListViewItem>(); for (InputDevice idev : events.m_Devs) { ListViewItem device = new ListViewItem(idev.getName(), idev.getPath(), idev.getOpen(), idLVFirstItem + idev.getId()); m_Devices.add(device); } CustomAdapter m_lvAdapter = new CustomAdapter(MainActivity.this, m_Devices); if (m_lvDevices != null) m_lvDevices.setAdapter(m_lvAdapter); } }); m_selDevSpinner.post(new Runnable() { public void run() { ArrayList<String> openDevs = new ArrayList<String>(); for (InputDevice idev : events.m_Devs) { if (idev.getOpen()) openDevs.add(idev.getName()); } // populate spinner ArrayAdapter<String> adapter = new ArrayAdapter<String>(MainActivity.this, android.R.layout.simple_spinner_item, openDevs); adapter.setDropDownViewResource(android.R.layout.select_dialog_singlechoice); // changes spin size and popup box size/color m_selDevSpinner.setAdapter(adapter); } }); }
From source file:net.pocketmagic.android.eventinjector.MainActivity.java
/** * Finds an open device that has a name containing keypad. This probably is * the event node associated with the keypad Its purpose is to handle all * hardware Android buttons such as Back, Home, Volume, etc Key codes are * defined in input.h (see NDK) , or use the Event Monitor to see keypad * messages This function sends the Settings key *//* w ww.j ava 2s . c o m*/ public void SendSettingsKeyToKeypad() { for (InputDevice idev : events.m_Devs) { // * Finds an open device that has a name containing keypad. This // probably is the keypad associated event node if (idev.getOpen() && idev.getName().contains("keypad")) { idev.SendKey(139, true); // settings key down idev.SendKey(139, false); // settings key up } } }
From source file:net.pocketmagic.android.eventinjector.MainActivity.java
/** * Finds an open device that has a name containing keypad. This probably is * the event node associated with the keypad Its purpose is to handle all * hardware Android buttons such as Back, Home, Volume, etc Key codes are * defined in input.h (see NDK) , or use the Event Monitor to see keypad * messages This function sends the BACK key *///from w w w. j a v a 2 s . c o m public void SendBackKeyToKeypad() { for (InputDevice idev : events.m_Devs) { // * Finds an open device that has a name containing keypad. This // probably is the keypad associated event node if (idev.getOpen() && idev.getName().contains("keypad")) { idev.SendKey(158, true); // Back key down idev.SendKey(158, false); // back key up } } }
From source file:net.pocketmagic.android.eventinjector.MainActivity.java
/** * Finds an open device that has a name containing keypad. This probably is * the event node associated with the keypad Its purpose is to handle all * hardware Android buttons such as Back, Home, Volume, etc Key codes are * defined in input.h (see NDK) , or use the Event Monitor to see keypad * messages This function sends the HOME key *///from w ww . j a v a 2 s. co m public void SendHomeKeyToKeypad() { boolean found = false; for (InputDevice idev : events.m_Devs) { // * Finds an open device that has a name containing keypad. This // probably is the keypad associated event node if (idev.getOpen() && idev.getName().contains("key")) { idev.SendKey(102, true); // home key down idev.SendKey(102, false); // home key up found = true; break; } } if (found == false) Toast.makeText(this, "Keypad not found.", Toast.LENGTH_SHORT).show(); }
From source file:net.pocketmagic.android.eventinjector.MainActivity.java
/** * Starts our event monitor thread that does the data extraction via polling * all data is displayed in the textview, as type-code-value, see input.h in * the Android NDK for more details Monitor output is also sent to Logcat, * so make sure you used that as well//from w w w. ja v a 2 s .c om */ public void StartEventMonitor() { m_bMonitorOn = true; Thread b = new Thread(new Runnable() { public void run() { while (m_bMonitorOn) { for (InputDevice idev : events.m_Devs) { // Open more devices to see their messages if (idev.getOpen() && (0 == idev.getPollingEvent())) { final String line = idev.getName() + ":" + idev.getSuccessfulPollingType() + " " + idev.getSuccessfulPollingCode() + " " + idev.getSuccessfulPollingValue(); Log.d(LT, "Event:" + line); // update textview to show data // if (idev.getSuccessfulPollingValue() != 0) m_tvMonitor.post(new Runnable() { public void run() { m_tvMonitor.setText(line); } }); } } } } }); b.start(); }
From source file:com.goodhustle.ouyaunitybridge.OuyaUnityActivity.java
private ArrayList<Device> checkDevices() { //Get a list of all device id's and assign them to players. ArrayList<Device> devices = new ArrayList<Device>(); int[] deviceIds = InputDevice.getDeviceIds(); for (int count = 0; count < deviceIds.length; count++) { InputDevice d = InputDevice.getDevice(deviceIds[count]); if (!d.isVirtual()) { Device device = new Device(); device.id = d.getId();//from www. j a v a 2 s . c om device.player = OuyaController.getPlayerNumByDeviceId(device.id); if (device.player != DEVICE_NOT_OUYACONTROLLER_COMPATIBLE) { device.name = d.getName(); devices.add(device); } } } return devices; }
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.//from w w w . j av a2 s. c om * * 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); }