当前位置: 首页>>代码示例>>Java>>正文


Java InputDevice.SOURCE_CLASS_JOYSTICK属性代码示例

本文整理汇总了Java中android.view.InputDevice.SOURCE_CLASS_JOYSTICK属性的典型用法代码示例。如果您正苦于以下问题:Java InputDevice.SOURCE_CLASS_JOYSTICK属性的具体用法?Java InputDevice.SOURCE_CLASS_JOYSTICK怎么用?Java InputDevice.SOURCE_CLASS_JOYSTICK使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在android.view.InputDevice的用法示例。


在下文中一共展示了InputDevice.SOURCE_CLASS_JOYSTICK属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: processGenericEvent

public void processGenericEvent(final MotionEvent event)
{
	// Joysticks are supported since Honeycomb, but I don't care about it, because very few devices have it
	if( (event.getSource() & InputDevice.SOURCE_CLASS_JOYSTICK) == InputDevice.SOURCE_CLASS_JOYSTICK )
	{
		// event.getAxisValue(AXIS_HAT_X) and event.getAxisValue(AXIS_HAT_Y) are joystick arrow keys, on Nvidia Shield and some other joysticks
		DemoGLSurfaceView.nativeGamepadAnalogJoystickInput(
			event.getAxisValue(MotionEvent.AXIS_X), event.getAxisValue(MotionEvent.AXIS_Y),
			event.getAxisValue(MotionEvent.AXIS_Z), event.getAxisValue(MotionEvent.AXIS_RZ),
			event.getAxisValue(MotionEvent.AXIS_LTRIGGER), event.getAxisValue(MotionEvent.AXIS_RTRIGGER),
			event.getAxisValue(MotionEvent.AXIS_HAT_X), event.getAxisValue(MotionEvent.AXIS_HAT_Y),
			processGamepadDeviceId(event.getDevice()) );
		return;
	}
	// Process mousewheel
	if( event.getAction() == MotionEvent.ACTION_SCROLL )
	{
		int scrollX = Math.round(event.getAxisValue(MotionEvent.AXIS_HSCROLL));
		int scrollY = Math.round(event.getAxisValue(MotionEvent.AXIS_VSCROLL));
		DemoGLSurfaceView.nativeMouseWheel(scrollX, scrollY);
		return;
	}
	super.processGenericEvent(event);
}
 
开发者ID:NeoTerm,项目名称:NeoTerm,代码行数:24,代码来源:Video.java

示例2: onMotionEvent

/** This function MUST be called on the UI thread */
@Override
public boolean onMotionEvent(MotionEvent event) {
    if (Versions.preHCMR1) {
        return false;
    }

    switch (event.getSource() & InputDevice.SOURCE_CLASS_MASK) {
    case InputDevice.SOURCE_CLASS_POINTER:
        switch (event.getAction() & MotionEvent.ACTION_MASK) {
        case MotionEvent.ACTION_SCROLL: return handlePointerScroll(event);
        }
        break;
    case InputDevice.SOURCE_CLASS_JOYSTICK:
        switch (event.getAction() & MotionEvent.ACTION_MASK) {
        case MotionEvent.ACTION_MOVE: return handleJoystickNav(event);
        }
        break;
    }
    return false;
}
 
开发者ID:jrconlin,项目名称:mc_backup,代码行数:21,代码来源:JavaPanZoomController.java

示例3: onGenericMotion

@Override
public boolean onGenericMotion(View v, MotionEvent event) {
    if ((event.getSource() & InputDevice.SOURCE_CLASS_JOYSTICK) != 0
            && event.getAction() == MotionEvent.ACTION_MOVE) {
        List<MotionRange> motionRanges = event.getDevice().getMotionRanges();
        for(MotionRange mr : motionRanges){
            int axis = mr.getAxis();
            if(event.getAxisValue(axis) > 0.5 || event.getAxisValue(axis) < -0.5){
                Log.i(TAG, "Axis found: " + MotionEvent.axisToString(axis));
                this.mAxisName = MotionEvent.axisToString(axis);
                mValueTextView.setText(mAxisName);
            }
        }
    }else{
        Log.i(TAG, "Not a joystick event.");
    }
    return true;
}
 
开发者ID:bitcraze,项目名称:crazyflie-android-client,代码行数:18,代码来源:AxisMappingDialogPreference.java

示例4: dispatchGenericMotionEvent

/**
* This is an android event handler for generic motion events. This is triggered
* when any of the axes controls (vs simple buttons) on the joystick are used
* where each axis has a value between -1.0 and 1.0.
*/
@Override
public boolean dispatchGenericMotionEvent(MotionEvent event)
/*************************************************************************/
{
    Log.d("MainActivity", "MainActivity: dispatchGenericMotionEvent");

    initializeJoystickHandlerIfPossibleAndNecessary(event);

    boolean isJoystickEvent = ((event.getSource() & InputDevice.SOURCE_CLASS_JOYSTICK) != 0);
    boolean isActionMoveEvent = event.getAction() == MotionEvent.ACTION_MOVE;

    if (!isJoystickEvent || !isActionMoveEvent || !joystickHandler_.isInitialized())
        return super.dispatchGenericMotionEvent(event);
    
    if (joystickHandler_.onJoystickMotion(event))
        return true;

    return super.dispatchGenericMotionEvent(event);
}
 
开发者ID:willowgarage,项目名称:shield_teleop,代码行数:24,代码来源:MainActivity.java

示例5: onJoystickMotion

/**
* This method should be called from a holding widget that can intercept
* Android input events when a joystick axis control is manipulated
*/
public boolean onJoystickMotion(MotionEvent event) 
/*************************************************************************/
{
    if ((event.getSource() & InputDevice.SOURCE_CLASS_JOYSTICK) == 0)
    {
        return false;
    }

    //Update the latest axis value for each axis. The MotionEvent object contains the state of each axis.
    for (int i = 0; i < axes_.length; i++)
    {
        int axisId = axes_[i];
        float axisVal = roundToZeroIfNecessary(event.getAxisValue(axisId));
        axesValues_[i] = axisVal;
    }

    publishLatestJoystickMessage();

    return true;
}
 
开发者ID:willowgarage,项目名称:shield_teleop,代码行数:24,代码来源:JoystickNode.java

示例6: isDeviceSDLJoystick

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,代码行数:13,代码来源:SDLActivity.java

示例7: processGamepadDeviceId

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,代码行数:27,代码来源:Video.java

示例8: onGenericMotionEvent

/**
 * @see View#onGenericMotionEvent(MotionEvent)
 */
public boolean onGenericMotionEvent(MotionEvent event) {
    if (GamepadList.onGenericMotionEvent(event)) return true;
    if ((event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0) {
        switch (event.getActionMasked()) {
            case MotionEvent.ACTION_SCROLL:
                getEventForwarder().onMouseWheelEvent(event.getEventTime(), event.getX(),
                        event.getY(), event.getAxisValue(MotionEvent.AXIS_HSCROLL),
                        event.getAxisValue(MotionEvent.AXIS_VSCROLL),
                        mRenderCoordinates.getWheelScrollFactor());
                return true;
            case MotionEvent.ACTION_BUTTON_PRESS:
            case MotionEvent.ACTION_BUTTON_RELEASE:
                // TODO(mustaq): Should we include MotionEvent.TOOL_TYPE_STYLUS here?
                // crbug.com/592082
                if (event.getToolType(0) == MotionEvent.TOOL_TYPE_MOUSE) {
                    return getEventForwarder().onMouseEvent(event);
                }
        }
    } else if ((event.getSource() & InputDevice.SOURCE_CLASS_JOYSTICK) != 0) {
        if (mJoystickScrollEnabled) {
            float velocityX = getFilteredAxisValue(event, MotionEvent.AXIS_X);
            float velocityY = getFilteredAxisValue(event, MotionEvent.AXIS_Y);
            flingViewport(event.getEventTime(), -velocityX, -velocityY, true);
            return true;
        }
    }
    return mContainerViewInternals.super_onGenericMotionEvent(event);
}
 
开发者ID:mogoweb,项目名称:365browser,代码行数:31,代码来源:ContentViewCore.java

示例9: isPanningControl

public static boolean isPanningControl(MotionEvent event) {
    if (Build.VERSION.SDK_INT < 12) {
        return false;
    }
    if ((event.getSource() & InputDevice.SOURCE_CLASS_MASK) != InputDevice.SOURCE_CLASS_JOYSTICK) {
        return false;
    }
    if (isValueInDeadZone(event, MotionEvent.AXIS_X)
            && isValueInDeadZone(event, MotionEvent.AXIS_Y)
            && isValueInDeadZone(event, MotionEvent.AXIS_Z)
            && isValueInDeadZone(event, MotionEvent.AXIS_RZ)) {
        return false;
    }
    return true;
}
 
开发者ID:jrconlin,项目名称:mc_backup,代码行数:15,代码来源:GamepadUtils.java

示例10: isGamepad

/**
 * 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,代码行数:15,代码来源:FullscreenActivity.java

示例11: onGenericMotion

@Override
public boolean onGenericMotion (View view, MotionEvent motionEvent) {
	if((motionEvent.getSource() & InputDevice.SOURCE_CLASS_JOYSTICK) == 0) return false;
	AndroidController controller = controllerMap.get(motionEvent.getDeviceId());
	if(controller != null) {
		synchronized(eventQueue) {
			final int historySize = motionEvent.getHistorySize();
			int axisIndex = 0;
           for (int axisId: controller.axesIds) {
           	float axisValue = motionEvent.getAxisValue(axisId);
           	if(controller.getAxis(axisIndex) == axisValue) {
           		axisIndex++;
           		continue;
           	}
           	AndroidControllerEvent event = eventPool.obtain();
  				event.type = AndroidControllerEvent.AXIS;
  				event.controller = controller;
  				event.code = axisIndex;
  				event.axisValue = axisValue;
  				eventQueue.add(event);
  				axisIndex++;
           }
		}
		return true;
	}
	return false;
}
 
开发者ID:basherone,项目名称:libgdxcn,代码行数:27,代码来源:AndroidControllers.java

示例12: dispatchGenericMotionEvent

@Override
public boolean dispatchGenericMotionEvent(MotionEvent event) {
    // Check that the event came from a joystick since a generic motion event could be almost anything.
    if ((event.getSource() & InputDevice.SOURCE_CLASS_JOYSTICK) != 0 && event.getAction() == MotionEvent.ACTION_MOVE && mController instanceof GamepadController) {
        mGamepadController.dealWithMotionEvent(event);
        updateFlightData();
        return true;
    } else {
        return super.dispatchGenericMotionEvent(event);
    }
}
 
开发者ID:bitcraze,项目名称:crazyflie-android-client,代码行数:11,代码来源:MainActivity.java

示例13: onGenericMotionEvent

@Override
public boolean onGenericMotionEvent(MotionEvent event) {
    ensureInitialized();

    // Check that the event came from a joystick since a generic motion event
    // could be almost anything.
    if ((event.getSource() & InputDevice.SOURCE_CLASS_JOYSTICK) != 0
            && event.getAction() == MotionEvent.ACTION_MOVE) {
        // Cache the most recently obtained device information.
        // The device information may change over time but it can be
        // somewhat expensive to query.
        if (mLastInputDevice == null || mLastInputDevice.getId() != event.getDeviceId()) {
            mLastInputDevice = event.getDevice();
            // It's possible for the device id to be invalid.
            // In that case, getDevice() will return null.
            if (mLastInputDevice == null) {
                return false;
            }
        }

        // Ignore joystick while the DPad is pressed to avoid conflicting motions.
        if (mDPadState != 0) {
            return true;
        }

        // Process all historical movement samples in the batch.
        final int historySize = event.getHistorySize();
        for (int i = 0; i < historySize; i++) {
            processJoystickInput(event, i);
        }

        // Process the current movement sample in the batch.
        processJoystickInput(event, -1);
        return true;
    }
    return super.onGenericMotionEvent(event);
}
 
开发者ID:vogellacompany,项目名称:codeexamples-android,代码行数:37,代码来源:GameView.java

示例14: dispatchGenericMotionEvent

@Override
public boolean dispatchGenericMotionEvent(MotionEvent event) {
    // Check that the event came from a joystick since a generic motion event
    // could be almost anything.
    if ((event.getSource() & InputDevice.SOURCE_CLASS_JOYSTICK) != 0
            && event.getAction() == MotionEvent.ACTION_MOVE) {
        // Update device state for visualization and logging.
        InputDeviceState state = getInputDeviceState(event);
        if (state != null && state.onJoystickMotion(event)) {
            mSummaryAdapter.show(state);
        }
    }
    return super.dispatchGenericMotionEvent(event);
}
 
开发者ID:vogellacompany,项目名称:codeexamples-android,代码行数:14,代码来源:GameControllerInput.java

示例15: initializeJoystickHandlerIfPossibleAndNecessary

/**
* Until we get a joystick event, it is not certain what InputDevice corresponds to the joystick
* Though there are methods for introspection, I was in a hurry and this does the job.
*/
private void initializeJoystickHandlerIfPossibleAndNecessary(InputEvent event)
/*************************************************************************/
{
    if ((!joystickHandler_.isInitialized()) && (event.getSource() & InputDevice.SOURCE_CLASS_JOYSTICK) != 0)
        joystickHandler_.initializeDevice(event.getDevice());
}
 
开发者ID:willowgarage,项目名称:shield_teleop,代码行数:10,代码来源:MainActivity.java


注:本文中的android.view.InputDevice.SOURCE_CLASS_JOYSTICK属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。