motionevent

Android ACTION_UP does not get fired after ACTION_MOVE

别说谁变了你拦得住时间么 提交于 2019-12-24 10:47:27
问题 I'm trying to create a view programmatically, and change its background according to its click state. I know I can do this with xml drawables, but I want to learn to program it too. But if I press on my view, then slide my finger, the view gets stuck in pressed state. (white = 0xaaffffff background) My code is this : Edit: I solved the problem. Here is the working code : mainContainer.setOnTouchListener(new OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { //

How do I make the coordinates of MotionEvent match the ones of a scaled canvas?

◇◆丶佛笑我妖孽 提交于 2019-12-24 01:15:44
问题 I have a Canvas that is scaled so everything fits better: @Override public void draw(Canvas c){ super.draw(c); final float scaleFactorX = getWidth()/(WIDTH*1.f); final float scaleFactorY = getHeight()/(HEIGHT*1.f); if(c!=null) { final int savedState = c.save(); c.scale(scaleFactorX, scaleFactorY); (rendering) c.restoreToCount(savedState); } } It scales based on these two: public static final int WIDTH = 856; public static final int HEIGHT = 1050; Which causes the problem that the coordinates

Motionevent Action_MOVE keeps firing X and Y even if not moved

倖福魔咒の 提交于 2019-12-23 12:27:24
问题 I am trying out simple program that have sounds based if moved. so at the beginning I have down - which play sound 1 and from then every move it is keeps playing a sound. At count 4 I have made it to play from start. here is the problem: When I don't move my finger and hold it in the same place the sound still keeps 1 by 1 - Figured out the x and y value firing. How do I stop this?? OnTouchListener MyOnTouchListener= new OnTouchListener() { public boolean onTouch(View view, MotionEvent event)

Rotation of layout changes the co-ordinate of the motion event

Deadly 提交于 2019-12-22 17:46:49
问题 i am cropping a image by the help of a child relative layout and i am moving it by motion event over a parent relative layout(containing image-view to be cropped). ..but when i rotate parent layout (in which i have the image view ) by 90 deg. the behavior of motion event co-ordinate changes,and does not work(drag and zoom of child layout)properly.. please somebody tell me how to fix this..i have done some research and found about the AXIS_ORIENTATION in motionevent class but did not get any

Gamepad Support Android

蹲街弑〆低调 提交于 2019-12-21 05:21:45
问题 I am trying to add gamepad support to my game but I can't find anywhere how to get the motion events from a gamepad's joysticks. I have something like this but it never seems to get called or do anything. I am testing on a XOOM with JellyBean and my gamepad works for navigating around the menus. @Override public boolean onGenericMotionEvent(MotionEvent e) { if ((e.getDevice().getSources() & InputDevice.SOURCE_CLASS_JOYSTICK) != 0) { float x = e.getX(); float y = e.getY(); mJoy1.set(x, y);

Gamepad Support Android

假装没事ソ 提交于 2019-12-21 05:21:13
问题 I am trying to add gamepad support to my game but I can't find anywhere how to get the motion events from a gamepad's joysticks. I have something like this but it never seems to get called or do anything. I am testing on a XOOM with JellyBean and my gamepad works for navigating around the menus. @Override public boolean onGenericMotionEvent(MotionEvent e) { if ((e.getDevice().getSources() & InputDevice.SOURCE_CLASS_JOYSTICK) != 0) { float x = e.getX(); float y = e.getY(); mJoy1.set(x, y);

Simulate a mouse input on android

别说谁变了你拦得住时间么 提交于 2019-12-21 02:36:08
问题 Imagine that I have a service that receives coordinates from a bluetooth device, now I want to display a mouse cursor whenever it moves. I managed to send MotionEvents with a toolType = TOOL_TYPE_MOUSE but I don't get the native android mouse cursor displayed on screen. The events I am sending look like these: 05-14 13:38:05.043: I/onTouchEvent(30301): MotionEvent { action=ACTION_DOWN, id[0]=0, x[0]=498.0, y[0]=996.0, toolType[0]=TOOL_TYPE_MOUSE, buttonState=0, metaState=0, flags=0x0,

onInterceptTouchEvent never receives action_move

家住魔仙堡 提交于 2019-12-21 02:30:10
问题 I have a custom ViewGroup with an override of onInterceptTouchEvent(). It receives ACTION_DOWN but never receives ACTION_MOVE. It is my understanding that, unless it returns "true", it should receive all MotionEvents. The ViewGroup contains two views, an ImageView and a GridLayout. My intercept code is: @Override public boolean onInterceptTouchEvent(MotionEvent ev) { final int action = ev.getAction(); switch (action & MotionEvent.ACTION_MASK) { case MotionEvent.ACTION_DOWN: logD ("DDV

What's the difference between ACTION_CANCEL and ACTION_UP in MotionEvent?

社会主义新天地 提交于 2019-12-20 12:17:30
问题 I want to track a finger touch on the screen. So what I did was to start recording the position when MotionEvent triggers ACTION_DOWN , but how do I know when the action is finished, at ACTION_CANCEL , or ACTION_UP ? What's the exact difference between them? 回答1: MotionEvent: ACTION_UP: A pressed gesture has finished, the motion contains the final release location as well as any intermediate points since the last down or move event. ACTION_CANCEL: The current gesture has been aborted. ACTION

android: how can I detect when user touch left 20% of view area?

Deadly 提交于 2019-12-12 17:24:24
问题 In an activity by using public boolean dispatchTouchEvent(MotionEvent ev) how can I know an user is touching left Y-axis of 20% edge area? It should be generic and orientation handled. I don't want to create any hidden view on that. 回答1: Get device width Calculate left 20% width size (from 0 to X) Use event.getX() Check that event.getX() is inside device with 20% example : public class YourActivity extends Activity { private LinearLayout background; private float xValue, yValue,