List of usage examples for android.view InputDevice getId
public int getId()
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())); }/*from www . j a va 2s .c om*/ return INPUT_DEVICE_MAP.get(id); }
From source file:com.example.android.visualgamecontroller.FullscreenActivity.java
@Override public boolean onGenericMotionEvent(final MotionEvent ev) { // Log.d(TAG, "onGenericMotionEvent: " + ev); InputDevice device = ev.getDevice(); // Only care about game controllers. if (device != null && device.getId() == mCurrentDeviceId) { if (isGamepad(device)) { for (AxesMapping axesMapping : AxesMapping.values()) { mAxes[axesMapping.ordinal()] = getCenteredAxis(ev, device, axesMapping.getMotionEvent()); }/*w ww . j a v a 2 s . c o m*/ mControllerView.invalidate(); return true; } } return super.onGenericMotionEvent(ev); }
From source file:com.example.android.visualgamecontroller.FullscreenActivity.java
@Override public boolean onKeyDown(final int keyCode, KeyEvent ev) { // Log.d(TAG, "onKeyDown: " + ev); InputDevice device = ev.getDevice(); // Only care about game controllers. if (device != null && device.getId() == mCurrentDeviceId) { if (isGamepad(device)) { int index = getButtonMappingIndex(keyCode); if (index >= 0) { mButtons[index] = 1;//www . ja va2s . c o m mControllerView.invalidate(); } return true; } } return super.onKeyDown(keyCode, ev); }
From source file:com.example.android.visualgamecontroller.FullscreenActivity.java
@Override public boolean onKeyUp(final int keyCode, KeyEvent ev) { // Log.d(TAG, "onKeyUp: " + ev); InputDevice device = ev.getDevice(); // Only care about game controllers. if (device != null && device.getId() == mCurrentDeviceId) { if (isGamepad(device)) { int index = getButtonMappingIndex(keyCode); if (index >= 0) { mButtons[index] = 0;//from w w w . ja va2 s . c om mControllerView.invalidate(); } return true; } } return super.onKeyUp(keyCode, ev); }
From source file:net.pocketmagic.android.eventinjector.MainActivity.java
public void onClick(View v) { int id = v.getId(); if (id >= idLVFirstItem) { int nLVIndexClick = id - idLVFirstItem; Log.d(LT, "LV Item Click:" + nLVIndexClick); for (InputDevice idev : events.m_Devs) { if (idev.getId() == nLVIndexClick) { if (idev.Open(true)) { // refresh listview PopulateListView();//w ww . ja v a 2 s . c o m // inform user Toast.makeText(this, "Device opened successfully!", Toast.LENGTH_SHORT).show(); } else { Toast.makeText(this, "Device failed to open. Do you have root?", Toast.LENGTH_SHORT).show(); } break; } } } switch (id) { case idButScan: { Log.d(LT, "Scanning for input dev files."); // init event node files int res = events.Init(); // debug results Log.d(LT, "Event files:" + res); // try opening all PopulateListView(); } case idButInjectKey: if (m_selectedDev != -1) { // see input.h in Android NDK, sequence represents the codes for // pocketmagic.net final int keys[] = new int[] { 25, 24, 46, 37, 18, 20, 50, 30, 34, 23, 46, 52, 49, 18, 20 }; // send all these keys with half a second delay Thread sender = new Thread(new Runnable() { public void run() { for (int i = 0; i < keys.length; i++) { Log.d(LT, "Sending:" + keys[i] + " to:" + events.m_Devs.get(m_selectedDev).getName()); events.m_Devs.get(m_selectedDev).SendKey(keys[i], true); // key down events.m_Devs.get(m_selectedDev).SendKey(keys[i], false); // key up // a short delay before next character, just for // testing purposes try { Thread.sleep(2000); } catch (InterruptedException e) { e.printStackTrace(); } } } }); sender.start(); } else Toast.makeText(this, "Select a valid device first, using the spinner to the left.", Toast.LENGTH_SHORT).show(); break; case idButInjectTouch: // absolute coordinates, on my device they go up to 570x960 if (m_selectedDev != -1) events.m_Devs.get(m_selectedDev).SendTouchDownAbs(155, 183); else Toast.makeText(this, "Select a valid device first, using the spinner to the left.", Toast.LENGTH_SHORT).show(); break; case idButTest: Thread sender = new Thread(new Runnable() { public void run() { for (int i = 0; i < 5; i++) { SendHomeKeyToKeypad(); // a short delay before next character, just for testing // purposes try { Thread.sleep(2000); } catch (InterruptedException e) { e.printStackTrace(); } } } }); sender.start(); break; case idButMonitorStart: if (m_bMonitorOn) Toast.makeText(this, "Event monitor already working. Consider opening more devices to monitor.", Toast.LENGTH_SHORT).show(); else { m_tvMonitor.post(new Runnable() { public void run() { m_tvMonitor.setText("Event Monitor running, waiting for data."); } }); StartEventMonitor(); } break; case idButMonitorStop: Toast.makeText(this, "Event monitor stopped.", Toast.LENGTH_SHORT).show(); StopEventMonitor(); m_tvMonitor.post(new Runnable() { public void run() { m_tvMonitor.setText("Event Monitor stopped."); } }); break; } }
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 a va 2 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:com.google.fpl.voltair.VoltAirActivity.java
/** * @brief Returns the hardware deviceId of the touch screen input device, or -1 if none exists. * @note If multiple touch screen devices are present, this returns the id of the first one * discovered./*from w ww . ja v a 2 s .c o m*/ */ public int getTouchScreenDeviceId() { for (int deviceId : mInputManager.getInputDeviceIds()) { InputDevice device = mInputManager.getInputDevice(deviceId); if (isSourceType(device, InputDevice.SOURCE_TOUCHSCREEN)) { return device.getId(); } } return -1; }
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(); device.player = OuyaController.getPlayerNumByDeviceId(device.id); if (device.player != DEVICE_NOT_OUYACONTROLLER_COMPATIBLE) { device.name = d.getName(); devices.add(device);/*from w w w. ja v a 2 s . co m*/ } } } return devices; }