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


Java MotionEvent.getSource方法代碼示例

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


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

示例1: onGenericMotionEvent

import android.view.MotionEvent; //導入方法依賴的package包/類
@TargetApi(12)
public boolean onGenericMotionEvent(MotionEvent event) {
    if ((event.getSource() & 2) != 0) {
        switch (event.getAction()) {
            case 8:
                if (this.mTouchMode == -1) {
                    float hscroll = event.getAxisValue(10);
                    if (hscroll != 0.0f) {
                        int delta = (int) (getHorizontalScrollFactor() * hscroll);
                        if (!trackMotionScroll(delta, delta)) {
                            return true;
                        }
                    }
                }
                break;
        }
    }
    return super.onGenericMotionEvent(event);
}
 
開發者ID:JackChan1999,項目名稱:letv,代碼行數:20,代碼來源:AbsHListView.java

示例2: onGenericMotionEvent

import android.view.MotionEvent; //導入方法依賴的package包/類
@TargetApi(Build.VERSION_CODES.HONEYCOMB_MR1)
@Override
public boolean onGenericMotionEvent(MotionEvent event) {
	if ((event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0) {
		switch (event.getAction()) {
		case MotionEvent.ACTION_SCROLL: {
			if (mTouchMode == TOUCH_MODE_REST) {
				final float hscroll = event
						.getAxisValue(MotionEvent.AXIS_HSCROLL);
				if (hscroll != 0) {
					final int delta = (int) (hscroll * getHorizontalScrollFactor());
					if (!trackMotionScroll(delta, delta)) {
						return true;
					}
				}
			}
		}
		}
	}
	return super.onGenericMotionEvent(event);
}
 
開發者ID:junchenChow,項目名稱:exciting-app,代碼行數:22,代碼來源:AbsHListView.java

示例3: onGenericMotionEvent

import android.view.MotionEvent; //導入方法依賴的package包/類
@Override
public boolean onGenericMotionEvent(MotionEvent event) {
    mInputManager.onGenericMotionEvent(event);

    // Check that the event came from a joystick or gamepad since a generic
    // motion event could be almost anything. API level 18 adds the useful
    // event.isFromSource() helper function.
    int eventSource = event.getSource();
    if ((((eventSource & InputDevice.SOURCE_GAMEPAD) == InputDevice.SOURCE_GAMEPAD) ||
            ((eventSource & InputDevice.SOURCE_JOYSTICK) == InputDevice.SOURCE_JOYSTICK))
            && event.getAction() == MotionEvent.ACTION_MOVE) {
        int id = event.getDeviceId();
        if (-1 != id) {
            Ship curShip = getShipForId(id);
            if (curShip.onGenericMotionEvent(event)) {
                return true;
            }
        }
    }
    return super.onGenericMotionEvent(event);
}
 
開發者ID:sdrausty,項目名稱:buildAPKsSamples,代碼行數:22,代碼來源:GameView.java

示例4: onGenericMotionEvent

import android.view.MotionEvent; //導入方法依賴的package包/類
@Override
public boolean onGenericMotionEvent(MotionEvent event) {

	if ((event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0) {
		switch (event.getAction()) {
		case MotionEvent.ACTION_SCROLL: {
			final float vscroll = event.getAxisValue(MotionEvent.AXIS_VSCROLL);
			if(DBG) Log.d(TAG,"onGenericMotionEvent ACTION_SCROLL vscroll="+vscroll);
			if (vscroll != 0) {
				final int index = mLayout.getFrontCoverIndex();
				int targetIndex;
				if (index+vscroll<0) {
					targetIndex=0;
				} else if (index+vscroll >= mCovers.size()-1) {
					targetIndex = mCovers.size()-1;
				} else {
					targetIndex = (int)(index+vscroll+0.5);
				}
				float targetScroll = mLayout.getScrollingPositionToCenterThisCover(targetIndex);
				mAnimHandler.startScrollingAnimPosition(targetScroll, AnimHandler.SPEED_FAST);
			}
		}
		}
	}
	return super.onGenericMotionEvent(event);
}
 
開發者ID:archos-sa,項目名稱:aos-MediaLib,代碼行數:27,代碼來源:CoverRoll3D.java

示例5: processGenericEvent

import android.view.MotionEvent; //導入方法依賴的package包/類
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,代碼行數:25,代碼來源:Video.java

示例6: onGenericMotionEvent

import android.view.MotionEvent; //導入方法依賴的package包/類
@Override
public boolean onGenericMotionEvent(MotionEvent event) {
    if ((event.getSource() & InputDevice.SOURCE_CLASS_POINTER) != 0) {
        switch (event.getAction()) {
            case MotionEvent.ACTION_SCROLL: {
                // Handle mouse (or ext. device) by shifting the page depending on the scroll
                final float vscroll;
                final float hscroll;
                if ((event.getMetaState() & KeyEvent.META_SHIFT_ON) != 0) {
                    vscroll = 0;
                    hscroll = event.getAxisValue(MotionEvent.AXIS_VSCROLL);
                } else {
                    vscroll = -event.getAxisValue(MotionEvent.AXIS_VSCROLL);
                    hscroll = event.getAxisValue(MotionEvent.AXIS_HSCROLL);
                }
                if (hscroll != 0 || vscroll != 0) {
                    boolean isForwardScroll = mIsRtl ? (hscroll < 0 || vscroll < 0)
                                                     : (hscroll > 0 || vscroll > 0);
                    if (isForwardScroll) {
                        scrollRight();
                    } else {
                        scrollLeft();
                    }
                    return true;
                }
            }
        }
    }
    return super.onGenericMotionEvent(event);
}
 
開發者ID:enricocid,項目名稱:LaunchEnr,代碼行數:31,代碼來源:PagedView.java

示例7: handleMotionEvent

import android.view.MotionEvent; //導入方法依賴的package包/類
@Override
public boolean handleMotionEvent(MotionEvent event) {
    if ((event.getSource() & InputDevice.SOURCE_JOYSTICK) != 0) {
        int actionPointerIndex = event.getActionIndex();
        int action = event.getActionMasked();
        switch(action) {
            case MotionEvent.ACTION_MOVE:
                SDLJoystick joystick = getJoystick(event.getDeviceId());
                if ( joystick != null ) {
                    for (int i = 0; i < joystick.axes.size(); i++) {
                        InputDevice.MotionRange range = joystick.axes.get(i);
                        /* Normalize the value to -1...1 */
                        float value = ( event.getAxisValue( range.getAxis(), actionPointerIndex) - range.getMin() ) / range.getRange() * 2.0f - 1.0f;
                        SDLActivity.onNativeJoy(joystick.device_id, i, value );
                    }
                    for (int i = 0; i < joystick.hats.size(); i+=2) {
                        int hatX = Math.round(event.getAxisValue( joystick.hats.get(i).getAxis(), actionPointerIndex ) );
                        int hatY = Math.round(event.getAxisValue( joystick.hats.get(i+1).getAxis(), actionPointerIndex ) );
                        SDLActivity.onNativeHat(joystick.device_id, i/2, hatX, hatY );
                    }
                }
                break;
            default:
                break;
        }
    }
    return true;
}
 
開發者ID:jomof,項目名稱:cdep-android-studio-freetype-sample,代碼行數:29,代碼來源:SDLActivity.java

示例8: onGenericMotion

import android.view.MotionEvent; //導入方法依賴的package包/類
@Override
public boolean onGenericMotion(View v, MotionEvent event) {
    float x, y;
    int action;

    switch ( event.getSource() ) {
        case InputDevice.SOURCE_JOYSTICK:
        case InputDevice.SOURCE_GAMEPAD:
        case InputDevice.SOURCE_DPAD:
            return SDLActivity.handleJoystickMotionEvent(event);

        case InputDevice.SOURCE_MOUSE:
            action = event.getActionMasked();
            switch (action) {
                case MotionEvent.ACTION_SCROLL:
                    x = event.getAxisValue(MotionEvent.AXIS_HSCROLL, 0);
                    y = event.getAxisValue(MotionEvent.AXIS_VSCROLL, 0);
                    SDLActivity.onNativeMouse(0, action, x, y);
                    return true;

                case MotionEvent.ACTION_HOVER_MOVE:
                    x = event.getX(0);
                    y = event.getY(0);

                    SDLActivity.onNativeMouse(0, action, x, y);
                    return true;

                default:
                    break;
            }
            break;

        default:
            break;
    }

    // Event was not managed
    return false;
}
 
開發者ID:jomof,項目名稱:cdep-android-studio-freetype-sample,代碼行數:40,代碼來源:SDLActivity.java

示例9: onGenericMotionEvent

import android.view.MotionEvent; //導入方法依賴的package包/類
public boolean onGenericMotionEvent (final MotionEvent event) {
	if (event.getAction() == MotionEvent.ACTION_MOVE && (event.getSource() & InputDevice.SOURCE_CLASS_JOYSTICK) == InputDevice.SOURCE_CLASS_JOYSTICK) {
		GenericGamepad gamepad = Mapper.instance.resolveGamepad(event.getDevice().getDescriptor(), event.getDeviceId());
		
		if (gamepad == null) {
			Log.d(LOGTAG, "Event from unknown descriptor " + event.getDevice().getDescriptor());
			return false;
		}
		
		float axisRx = 0;
		float axisRy = 0;
		
		if (gamepad.axisRx != 0) {
			axisRx = event.getAxisValue(Math.abs(gamepad.axisRx)) * (gamepad.axisRx > 0 ? 1 : -1);
		}
		if (gamepad.axisRx != 0) {
			axisRy = event.getAxisValue(Math.abs(gamepad.axisRy)) * (gamepad.axisRy > 0 ? 1 : -1);
		}
		if (Math.abs(axisRx) < 0.1) {
			axisRx = 0;
		}
		if (Math.abs(axisRy) < 0.1) {
			axisRy = 0;
		}

		gamepadMouseMoveX = axisRx * 2;
		gamepadMouseMoveY = axisRy * 2;
		
		float hatx = event.getAxisValue(MotionEvent.AXIS_HAT_X);
		float haty = event.getAxisValue(MotionEvent.AXIS_HAT_Y);
		
		float axisx = event.getAxisValue(MotionEvent.AXIS_X);
		float axisy = event.getAxisValue(MotionEvent.AXIS_Y);
		
		listener.onAxisChange(gamepad, axisx, axisy, hatx, haty, axisRx, axisRy);
		
		String deviceDescriptor = event.getDevice().getDescriptor();
		int deviceId = event.getDevice().getId();
		
		float triggerL = event.getAxisValue(MotionEvent.AXIS_LTRIGGER);
		float triggerR = event.getAxisValue(MotionEvent.AXIS_RTRIGGER);
		if (triggerL == 0) {
			triggerL = event.getAxisValue(MotionEvent.AXIS_BRAKE);
		}
		if (triggerR == 0) {
			triggerR = event.getAxisValue(MotionEvent.AXIS_GAS);
		}
		
		listener.onTriggers(deviceDescriptor, deviceId, Math.abs(triggerL)>=deadzone, Math.abs(triggerR)>=deadzone);
		listener.onTriggersAnalog(gamepad, deviceId, triggerL, triggerR);

		return true;

	}
	return false;
}
 
開發者ID:fcatrin,項目名稱:retroxlibs,代碼行數:57,代碼來源:AnalogGamepad.java

示例10: getSource

import android.view.MotionEvent; //導入方法依賴的package包/類
public static int getSource(MotionEvent event) {
    return event.getSource();
}
 
開發者ID:JackChan1999,項目名稱:boohee_v5.6,代碼行數:4,代碼來源:MotionEventCompatGingerbread.java

示例11: process

import android.view.MotionEvent; //導入方法依賴的package包/類
public void process(final MotionEvent event)
{
	int hwMouseEvent =  ((event.getSource() & InputDevice.SOURCE_MOUSE) == InputDevice.SOURCE_MOUSE || Globals.ForceHardwareMouse) ? Mouse.MOUSE_HW_INPUT_MOUSE :
						((event.getSource() & InputDevice.SOURCE_STYLUS) == InputDevice.SOURCE_STYLUS) ? Mouse.MOUSE_HW_INPUT_STYLUS :
						Mouse.MOUSE_HW_INPUT_FINGER;
	if( ExternalMouseDetected != hwMouseEvent )
	{
		ExternalMouseDetected = hwMouseEvent;
		DemoGLSurfaceView.nativeHardwareMouseDetected(hwMouseEvent);
	}
	super.process(event);
	if( !Globals.FingerHover && ExternalMouseDetected == Mouse.MOUSE_HW_INPUT_FINGER )
		return; // Finger hover disabled in settings
	if( (event.getAction() & MotionEvent.ACTION_MASK) == MotionEvent.ACTION_HOVER_MOVE ) // Support bluetooth/USB mouse - available since Android 3.1
	{
		int action;
		// TODO: it is possible that multiple pointers return that event, but we're handling only pointer #0
		if( touchEvents[0].down )
			action = Mouse.SDL_FINGER_UP;
		else
			action = Mouse.SDL_FINGER_HOVER;
		touchEvents[0].down = false;
		touchEvents[0].x = (int)event.getX();
		touchEvents[0].y = (int)event.getY();
		touchEvents[0].pressure = Mouse.MAX_HOVER_DISTANCE;
		touchEvents[0].size = 0;
		//if( event.getAxisValue(MotionEvent.AXIS_DISTANCE) != 0.0f )
		InputDevice device = InputDevice.getDevice(event.getDeviceId());
		if( device != null && device.getMotionRange(MotionEvent.AXIS_DISTANCE) != null &&
			device.getMotionRange(MotionEvent.AXIS_DISTANCE).getRange() > 0.0f )
			touchEvents[0].pressure = (int)((event.getAxisValue(MotionEvent.AXIS_DISTANCE) -
					device.getMotionRange(MotionEvent.AXIS_DISTANCE).getMin()) * Mouse.MAX_PRESSURE / device.getMotionRange(MotionEvent.AXIS_DISTANCE).getRange());
		DemoGLSurfaceView.nativeMotionEvent( touchEvents[0].x, touchEvents[0].y, action, 0, touchEvents[0].pressure, touchEvents[0].size );
	}
	if( (event.getAction() & MotionEvent.ACTION_MASK) == MotionEvent.ACTION_HOVER_EXIT ) // Update screen for finger hover
	{
		touchEvents[0].pressure = Mouse.HOVER_REDRAW_SCREEN;
		touchEvents[0].size = 0;
		DemoGLSurfaceView.nativeMotionEvent( touchEvents[0].x, touchEvents[0].y, Mouse.SDL_FINGER_HOVER, 0, touchEvents[0].pressure, touchEvents[0].size );
	}
}
 
開發者ID:NeoTerm,項目名稱:NeoTerm,代碼行數:42,代碼來源:Video.java


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