當前位置: 首頁>>代碼示例>>Java>>正文


Java InputDevice.getDeviceIds方法代碼示例

本文整理匯總了Java中android.view.InputDevice.getDeviceIds方法的典型用法代碼示例。如果您正苦於以下問題:Java InputDevice.getDeviceIds方法的具體用法?Java InputDevice.getDeviceIds怎麽用?Java InputDevice.getDeviceIds使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在android.view.InputDevice的用法示例。


在下文中一共展示了InputDevice.getDeviceIds方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: hasConnectedController

import android.view.InputDevice; //導入方法依賴的package包/類
/**
 * Function that returns if any controller is paired/plugged/turned on
 */
private boolean hasConnectedController(){

    /*Get a list of valid input ids and iterate through them*/
    for (int deviceId : InputDevice.getDeviceIds()) {

        InputDevice currentDevice = InputDevice.getDevice(deviceId);

        /*Device ID of the controller*/
        String controllerName = currentDevice.getName().toLowerCase(Locale.ENGLISH);

        /*Check to see if a known controller is connected*/
        if (controllerName.contains("controller") ||
                controllerName.contains("conteroller") ||
                controllerName.contains("contoroller") ||
                controllerName.contains("pad") ||
                controllerName.contains("joystick") ||
                controllerName.contains("nintendo")) {
            //|| (this.hidDevicesOK && controllerName.equals("hid_device"))){
            return true;
        }
    }
    return false;
}
 
開發者ID:frpnit,項目名稱:HeyaLauncher,代碼行數:27,代碼來源:StartUpControllerObserver.java

示例2: MotionEventSender

import android.view.InputDevice; //導入方法依賴的package包/類
public MotionEventSender() {
    try {
        Method imInstanceMethod = InputManager.class.getDeclaredMethod("getInstance");
        imInstanceMethod.setAccessible(true);
        inputManager = (InputManager) imInstanceMethod.invoke(null);

        injectInputEventMethod = InputManager.class.getDeclaredMethod("injectInputEvent",
                                                                      android.view.InputEvent.class,
                                                                      int.class);

        int[] deviceIds = InputDevice.getDeviceIds();
        for (int inputDeviceId : deviceIds) {
            InputDevice inputDevice = InputDevice.getDevice(inputDeviceId);
            int deviceSources = inputDevice.getSources();
            if ((deviceSources & InputDevice.SOURCE_TOUCHSCREEN) == InputDevice.SOURCE_TOUCHSCREEN) {
                DEVICE_ID = inputDeviceId;
                break;
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
        exitFailure();
    }

}
 
開發者ID:MusalaSoft,項目名稱:atmosphere-uiautomator-bridge,代碼行數:26,代碼來源:MotionEventSender.java

示例3: getGameControllerIds

import android.view.InputDevice; //導入方法依賴的package包/類
private List<Integer> getGameControllerIds() {
	List<Integer> gameControllerDeviceIds = new ArrayList<>();

	int[] deviceIds = InputDevice.getDeviceIds();
	for (int deviceId : deviceIds) {
		InputDevice dev = InputDevice.getDevice(deviceId);
		int sources = dev.getSources();

		if (((sources & InputDevice.SOURCE_GAMEPAD) == InputDevice.SOURCE_GAMEPAD)
				|| ((sources & InputDevice.SOURCE_JOYSTICK)
				== InputDevice.SOURCE_JOYSTICK)) {

			if (!gameControllerDeviceIds.contains(deviceId)) {
				gameControllerDeviceIds.add(deviceId);
			}
		}
	}

	return gameControllerDeviceIds;
}
 
開發者ID:TheFakeMontyOnTheRun,項目名稱:knightsofalentejo,代碼行數:21,代碼來源:GameActivity.java

示例4: scanForGamepads

import android.view.InputDevice; //導入方法依賴的package包/類
private static void scanForGamepads() {
    int[] deviceIds = InputDevice.getDeviceIds();
    if (deviceIds == null) {
        return;
    }
    for (int i=0; i < deviceIds.length; i++) {
        InputDevice device = InputDevice.getDevice(deviceIds[i]);
        if (device == null) {
            continue;
        }
        if ((device.getSources() & InputDevice.SOURCE_GAMEPAD) != InputDevice.SOURCE_GAMEPAD) {
            continue;
        }
        addGamepad(device);
    }
}
 
開發者ID:jrconlin,項目名稱:mc_backup,代碼行數:17,代碼來源:AndroidGamepadManager.java

示例5: areSonyXperiaGamepadKeysSwapped

import android.view.InputDevice; //導入方法依賴的package包/類
private static boolean areSonyXperiaGamepadKeysSwapped() {
    // The cross and circle buttons on Sony Xperia phones are swapped
    // in different regions
    // http://developer.sonymobile.com/2011/02/13/xperia-play-game-keys/
    final char DEFAULT_O_BUTTON_LABEL = 0x25CB;

    boolean swapped = false;
    int[] deviceIds = InputDevice.getDeviceIds();

    for (int i= 0; deviceIds != null && i < deviceIds.length; i++) {
        KeyCharacterMap keyCharacterMap = KeyCharacterMap.load(deviceIds[i]);
        if (keyCharacterMap != null && DEFAULT_O_BUTTON_LABEL ==
            keyCharacterMap.getDisplayLabel(KeyEvent.KEYCODE_DPAD_CENTER)) {
            swapped = true;
            break;
        }
    }
    return swapped;
}
 
開發者ID:jrconlin,項目名稱:mc_backup,代碼行數:20,代碼來源:GamepadUtils.java

示例6: gatherControllers

import android.view.InputDevice; //導入方法依賴的package包/類
private void gatherControllers(boolean sendEvent) {
	// gather all joysticks and gamepads, remove any disconnected ones
	IntMap<AndroidController> removedControllers = new IntMap<AndroidController>();
	removedControllers.putAll(controllerMap);
	
	for(int deviceId: InputDevice.getDeviceIds()) {
		InputDevice device = InputDevice.getDevice(deviceId);
		AndroidController controller = controllerMap.get(deviceId);
		if(controller != null) {
			removedControllers.remove(deviceId);
		} else {
			addController(deviceId, sendEvent);
		}
	}
	
	for(Entry<AndroidController> entry: removedControllers.entries()) {
		removeController(entry.key);
	}
}
 
開發者ID:basherone,項目名稱:libgdxcn,代碼行數:20,代碼來源:AndroidControllers.java

示例7: lookupTouchpadHardwareResolution

import android.view.InputDevice; //導入方法依賴的package包/類
/** Looks up the hardware resolution of the Glass touchpad. */
private void lookupTouchpadHardwareResolution() {
    int[] deviceIds = InputDevice.getDeviceIds();
    for (int deviceId : deviceIds) {
        InputDevice device = InputDevice.getDevice(deviceId);
        if ((device.getSources() & InputDevice.SOURCE_TOUCHPAD) != 0) {
            logVerbose("Touchpad motion range: x-axis [%d, %d] y-axis [%d, %d]",
                    device.getMotionRange(MotionEvent.AXIS_X).getMin(),
                    device.getMotionRange(MotionEvent.AXIS_X).getMax(),
                    device.getMotionRange(MotionEvent.AXIS_Y).getMin(),
                    device.getMotionRange(MotionEvent.AXIS_Y).getMax());

            mTouchpadHardwareWidth = device.getMotionRange(MotionEvent.AXIS_X).getRange();
            mTouchpadHardwareHeight = device.getMotionRange(MotionEvent.AXIS_Y).getRange();
            // Stop after we've seen the first touchpad device, because there might be multiple
            // devices in this list if the user is currently screencasting with MyGlass. The
            // first one will always be the hardware touchpad.
            break;
        }
    }
}
 
開發者ID:googleglass,項目名稱:gdk-apidemo-sample,代碼行數:22,代碼來源:TouchpadView.java

示例8: isRecognizedInputDevice

import android.view.InputDevice; //導入方法依賴的package包/類
private static boolean isRecognizedInputDevice(UsbDevice device) {
    // On KitKat and later, we can determine if this VID and PID combo
    // matches an existing input device and defer to the built-in controller
    // support in that case. Prior to KitKat, we'll always return true to be safe.
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        for (int id : InputDevice.getDeviceIds()) {
            InputDevice inputDev = InputDevice.getDevice(id);
            if (inputDev == null) {
                // Device was removed while looping
                continue;
            }

            if (inputDev.getVendorId() == device.getVendorId() &&
                    inputDev.getProductId() == device.getProductId()) {
                return true;
            }
        }

        return false;
    }
    else {
        return true;
    }
}
 
開發者ID:moonlight-stream,項目名稱:moonlight-android,代碼行數:25,代碼來源:UsbDriverService.java

示例9: getTouchDeviceName

import android.view.InputDevice; //導入方法依賴的package包/類
@Nullable
public static String getTouchDeviceName() {
    for (int id : InputDevice.getDeviceIds()) {
        InputDevice device = InputDevice.getDevice(id);
        if (supportSource(device, InputDevice.SOURCE_TOUCHSCREEN) || supportSource(device, InputDevice.SOURCE_TOUCHPAD)) {
            return device.getName();
        }
    }
    return null;
}
 
開發者ID:feifadaima,項目名稱:https-github.com-hyb1996-NoRootScriptDroid,代碼行數:11,代碼來源:InputDevices.java

示例10: inputGetInputDeviceIds

import android.view.InputDevice; //導入方法依賴的package包/類
/**
 * This method is called by SDL using JNI.
 * @return an array which may be empty but is never null.
 */
public static int[] inputGetInputDeviceIds(int sources) {
    int[] ids = InputDevice.getDeviceIds();
    int[] filtered = new int[ids.length];
    int used = 0;
    for (int i = 0; i < ids.length; ++i) {
        InputDevice device = InputDevice.getDevice(ids[i]);
        if ((device != null) && ((device.getSources() & sources) != 0)) {
            filtered[used++] = device.getId();
        }
    }
    return Arrays.copyOf(filtered, used);
}
 
開發者ID:jomof,項目名稱:cdep-android-studio-freetype-sample,代碼行數:17,代碼來源:SDLActivity.java

示例11: getInputDeviceIds

import android.view.InputDevice; //導入方法依賴的package包/類
@Override
public int[] getInputDeviceIds() {
    // add any hitherto unknown devices to our
    // collection of watched input devices
    int[] activeDevices = InputDevice.getDeviceIds();
    long time = SystemClock.elapsedRealtime();
    for ( int id : activeDevices ) {
        long[] lastContact = mDevices.get(id);
        if ( null == lastContact ) {
            // we have a new device
            mDevices.put(id, new long[] { time });
        }
    }
    return activeDevices;
}
 
開發者ID:sdrausty,項目名稱:buildAPKsSamples,代碼行數:16,代碼來源:InputManagerV9.java

示例12: getDetailedItems

import android.view.InputDevice; //導入方法依賴的package包/類
public List<ItemDetails> getDetailedItems() {
    List<ItemDetails> detailedItems = new ArrayList<>();
    int[] ids = InputDevice.getDeviceIds();
    for (int id : ids) {
        InputDevice device = InputDevice.getDevice(id);
        detailedItems.add(new ItemDetails(device.getName(), device.toString()));
    }

    return detailedItems;
}
 
開發者ID:iamtrk,項目名稱:Device-Explorer,代碼行數:11,代碼來源:Content.java

示例13: getContents

import android.view.InputDevice; //導入方法依賴的package包/類
public String getContents() {
    StringBuilder sb = new StringBuilder();
    Formatter f = new Formatter(sb, Locale.US);
    int[] ids = InputDevice.getDeviceIds();
    f.format("Device count: %d\n", ids.length);
    for (int i = 0; i < ids.length; i++) {
        int id = ids[i];
        InputDevice device = InputDevice.getDevice(id);
        f.format("#%d: id = 0x%x\n%s\n", i, id, device);
    }
    return sb.toString();
}
 
開發者ID:iamtrk,項目名稱:Device-Explorer,代碼行數:13,代碼來源:Content.java

示例14: isGameControllerConnected

import android.view.InputDevice; //導入方法依賴的package包/類
public boolean isGameControllerConnected() {
    int[] deviceIds = InputDevice.getDeviceIds();
    for (int deviceId : deviceIds) {
        InputDevice dev = InputDevice.getDevice(deviceId);
        int sources = dev.getSources();
        if (((sources & InputDevice.SOURCE_GAMEPAD) == InputDevice.SOURCE_GAMEPAD) ||
            ((sources & InputDevice.SOURCE_JOYSTICK) == InputDevice.SOURCE_JOYSTICK)) {
            return true;
        }
    }
    return false;
}
 
開發者ID:PacktPublishing,項目名稱:Android-Game-Programming,代碼行數:13,代碼來源:MainMenuFragment.java

示例15: getHardwareDevices

import android.view.InputDevice; //導入方法依賴的package包/類
public ArrayList<String> getHardwareDevices() {
	ArrayList<String> devices  = new ArrayList<String>();
	for(int deviceId : InputDevice.getDeviceIds()) {
		devices.add(InputDevice.getDevice(deviceId).getName());
	}
	
	return devices;
}
 
開發者ID:FAIMS,項目名稱:faims-android,代碼行數:9,代碼來源:BeanShellLinker.java


注:本文中的android.view.InputDevice.getDeviceIds方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。