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


Java InputDevice.getSources方法代碼示例

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


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

示例1: 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

示例2: 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

示例3: 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

示例4: checkGameControllers

import android.view.InputDevice; //導入方法依賴的package包/類
/**
 * Check for any game controllers that are connected already.
 */
private void checkGameControllers() {
    Log.d(TAG, "checkGameControllers");
    int[] deviceIds = mInputManager.getInputDeviceIds();
    for (int deviceId : deviceIds) {
        InputDevice dev = InputDevice.getDevice(deviceId);
        int sources = dev.getSources();

        // Verify that the device has gamepad buttons, control sticks, or
        // both.
        if (((sources & InputDevice.SOURCE_GAMEPAD) == InputDevice.SOURCE_GAMEPAD)
                || ((sources & InputDevice.SOURCE_JOYSTICK)
                    == InputDevice.SOURCE_JOYSTICK)) {
            // This device is a game controller. Store its device ID.
            if (!mConnectedDevices.contains(deviceId)) {
                mConnectedDevices.add(deviceId);
                if (mCurrentDeviceId == -1) {
                    mCurrentDeviceId = deviceId;
                    mControllerView.setCurrentControllerNumber(dev.getControllerNumber());
                    mControllerView.invalidate();
                }
            }
        }
    }
}
 
開發者ID:googlesamples,項目名稱:androidtv-VisualGameController,代碼行數:28,代碼來源:FullscreenActivity.java

示例5: 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

示例6: 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

示例7: isDeviceSDLJoystick

import android.view.InputDevice; //導入方法依賴的package包/類
public static boolean isDeviceSDLJoystick(int deviceId) {
    InputDevice device = InputDevice.getDevice(deviceId);
    // We cannot use InputDevice.isVirtual before API 16, so let's accept
    // only nonnegative device ids (VIRTUAL_KEYBOARD equals -1)
    if ((device == null) || (deviceId < 0)) {
        return false;
    }
    int sources = device.getSources();
    return (((sources & InputDevice.SOURCE_CLASS_JOYSTICK) == InputDevice.SOURCE_CLASS_JOYSTICK) ||
            ((sources & InputDevice.SOURCE_DPAD) == InputDevice.SOURCE_DPAD) ||
            ((sources & InputDevice.SOURCE_GAMEPAD) == InputDevice.SOURCE_GAMEPAD)
    );
}
 
開發者ID:jomof,項目名稱:cdep-android-studio-freetype-sample,代碼行數:14,代碼來源:SDLActivity.java

示例8: findControllersAndAttachShips

import android.view.InputDevice; //導入方法依賴的package包/類
void findControllersAndAttachShips() {
    int[] deviceIds = mInputManager.getInputDeviceIds();
    for (int deviceId : deviceIds) {
        InputDevice dev = mInputManager.getInputDevice(deviceId);
        int sources = dev.getSources();
        // if the device is a gamepad/joystick, create a ship to represent it
        if (((sources & InputDevice.SOURCE_GAMEPAD) == InputDevice.SOURCE_GAMEPAD) ||
                ((sources & InputDevice.SOURCE_JOYSTICK) == InputDevice.SOURCE_JOYSTICK)) {
            // if the device has a gamepad or joystick
            getShipForId(deviceId);
        }
    }
}
 
開發者ID:sdrausty,項目名稱:buildAPKsSamples,代碼行數:14,代碼來源:GameView.java

示例9: processGamepadDeviceId

import android.view.InputDevice; //導入方法依賴的package包/類
public static int processGamepadDeviceId(InputDevice device)
{
	if( device == null )
		return 0;
	int source = device.getSources();
	if( (source & InputDevice.SOURCE_CLASS_JOYSTICK) != InputDevice.SOURCE_CLASS_JOYSTICK &&
		(source & InputDevice.SOURCE_GAMEPAD) != InputDevice.SOURCE_GAMEPAD )
	{
		return 0;
	}
	int deviceId = device.getId();
	for( int i = 0; i < gamepadIds.length; i++ )
	{
		if (gamepadIds[i] == deviceId)
			return i + 1;
	}
	for( int i = 0; i < gamepadIds.length; i++ )
	{
		if (gamepadIds[i] == 0)
		{
			Log.i("SDL", "libSDL: gamepad added: deviceId " + deviceId + " gamepadId " + (i + 1));
			gamepadIds[i] = deviceId;
			return i + 1;
		}
	}
	return 0;
}
 
開發者ID:NeoTerm,項目名稱:NeoTerm,代碼行數:28,代碼來源:Video.java

示例10: 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

示例11: refreshGamepads

import android.view.InputDevice; //導入方法依賴的package包/類
@TargetApi(16)
private void refreshGamepads() throws JSONException
{
	int[] deviceIds = InputDevice.getDeviceIds();
	this.gamepads = new JSONArray();
	for (int i = 0; i < deviceIds.length; i++)
	{
		int deviceId = deviceIds[i];

		InputDevice inputDevice = InputDevice.getDevice(deviceId);
		int sources = inputDevice.getSources();
		boolean isJoystick = (sources & InputDevice.SOURCE_JOYSTICK) != 0;
		boolean isGamepad = (sources & InputDevice.SOURCE_GAMEPAD) != 0;
		boolean isVirtual = inputDevice.isVirtual();
		int motionRangesCount = inputDevice.getMotionRanges().size();
		// Only handle joysticks or gamepads that have more than one motionRanges
		// and that are not virtual (the NVIDIA Shield has virtual mouse cursor
		// that is identified as a joystick).
		if (!isVirtual && (isJoystick || isGamepad) && motionRangesCount > 0)
		{
			// System.out.println(inputDevice.getName() + ": isJoystick = "
			// + isJoystick + ", isGamepad = " + isGamepad + ", isVirtual = "
			// + isVirtual + ", motionRangesCount = " + motionRangesCount);
			gamepads.put(createGamepadForInputDevice(InputDevice
					.getDevice(deviceId)));
		}
	}
}
 
開發者ID:WinnipegAndroid,項目名稱:cordova-android-tv,代碼行數:29,代碼來源:CordovaPluginGamepad.java

示例12: availablePointerAndHoverTypes

import android.view.InputDevice; //導入方法依賴的package包/類
/**
 * @return an array of two ints: result[0] represents the pointer-types and result[1] represents
 *         the hover-types supported by the device, where each int is the union (bitwise OR) of
 *         corresponding type (PointerType/HoverType) bits.
 */
@CalledByNative
private static int[] availablePointerAndHoverTypes() {
    int[] result = new int[2];
    result[0] = result[1] = 0;

    for (int deviceId : InputDevice.getDeviceIds()) {
        InputDevice inputDevice = InputDevice.getDevice(deviceId);
        if (inputDevice == null) continue;

        int sources = inputDevice.getSources();

        if (hasSource(sources, InputDevice.SOURCE_MOUSE)
                || hasSource(sources, InputDevice.SOURCE_STYLUS)
                || hasSource(sources, InputDevice.SOURCE_TOUCHPAD)
                || hasSource(sources, InputDevice.SOURCE_TRACKBALL)) {
            result[0] |= PointerType.FINE;
        } else if (hasSource(sources, InputDevice.SOURCE_TOUCHSCREEN)) {
            result[0] |= PointerType.COARSE;
        }

        if (hasSource(sources, InputDevice.SOURCE_MOUSE)
                || hasSource(sources, InputDevice.SOURCE_TOUCHPAD)
                || hasSource(sources, InputDevice.SOURCE_TRACKBALL)) {
            result[1] |= HoverType.HOVER;
        } else if (hasSource(sources, InputDevice.SOURCE_STYLUS)
                || hasSource(sources, InputDevice.SOURCE_TOUCHSCREEN)) {
            result[1] |= HoverType.NONE;
        }

        // Remaining InputDevice sources: SOURCE_DPAD, SOURCE_GAMEPAD, SOURCE_JOYSTICK,
        // SOURCE_KEYBOARD, SOURCE_TOUCH_NAVIGATION, SOURCE_UNKNOWN
    }

    if (result[0] == 0) result[0] = PointerType.NONE;
    if (result[1] == 0) result[1] = HoverType.NONE;

    return result;
}
 
開發者ID:mogoweb,項目名稱:365browser,代碼行數:44,代碼來源:TouchDevice.java

示例13: onInputDeviceAdded

import android.view.InputDevice; //導入方法依賴的package包/類
@Override
public void onInputDeviceAdded(int deviceId) {
    InputDevice device = InputDevice.getDevice(deviceId);
    if (device == null) {
        return;
    }
    if ((device.getSources() & InputDevice.SOURCE_GAMEPAD) == InputDevice.SOURCE_GAMEPAD) {
        addGamepad(device);
    }
}
 
開發者ID:jrconlin,項目名稱:mc_backup,代碼行數:11,代碼來源:AndroidGamepadManager.java

示例14: isGamepad

import android.view.InputDevice; //導入方法依賴的package包/類
/**
 * Utility method to determine if input device is a gamepad.
 * 
 * @param device
 * @return
 */
private boolean isGamepad(InputDevice device) {
    if ((device.getSources() &
            InputDevice.SOURCE_GAMEPAD) == InputDevice.SOURCE_GAMEPAD
            || (device.getSources() &
            InputDevice.SOURCE_CLASS_JOYSTICK) == InputDevice.SOURCE_JOYSTICK) {
        return true;
    }
    return false;
}
 
開發者ID:googlesamples,項目名稱:androidtv-VisualGameController,代碼行數:16,代碼來源:FullscreenActivity.java

示例15: 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) {
            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:longzheng,項目名稱:PTVGlass,代碼行數:16,代碼來源:TouchpadView.java


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