motionevent

Detecting Significant Device Motion on Android

让人想犯罪 __ 提交于 2019-12-12 10:57:02
问题 I've been trying to figure out how to make an application that detects whether the device has been moved a significant amount, something more than just shakes. I am trying to detect a distance of, say, at least a foot. Reading the Training section on the official Android Development site, my best guess is that I should be using the Significant Motion Sensor, but I can't find an example of how to use it. Do I just store my "current" location in an array, and then compare that versus the Event

Send data to arduino as long as the button is being pressed

为君一笑 提交于 2019-12-12 04:18:46
问题 I want to send data to an arduino mega 2560 as long as a button is being pressed and when that button is released it will stop sending informations. I am using onTouchListener with MotionEvent constants. But when I run this on my phone I press the button and it sends data even though after a while I release it. Where am I being wrong here? switch (v.getId()) { case R.id.left1: // check what button is pressed while(event.getAction() == MotionEvent.ACTION_DOWN) { bt.sendData("1"); // while

How to keep X and Y within layout's view ?

邮差的信 提交于 2019-12-11 18:14:44
问题 I have a FrameLayout which has a thumb image which the user can drag around. The thumb width is 10dp and height is 10dp. f = (FrameLayout) findViewById(R.id.fl); f.setOnTouchListener(flt); f.measure(MeasureSpec.UNSPECIFIED, MeasureSpec.UNSPECIFIED); width = f.getMeasuredWidth(); height = f.getMeasuredHeight(); @Override public boolean onTouch(View v, MotionEvent event) { float x = event.getX(); float y = event.getY(); switch (event.getAction()) { case MotionEvent.ACTION_DOWN: if (x<0) { x = x

Scroll even if the seekbar is touched

ぃ、小莉子 提交于 2019-12-11 07:44:35
问题 I am using a seekbar in a linearlayout in a ScroolView in a NavigationDrawer NavigationDrawer > ScrollView > LinearLayout > SeekBar + other stuff When I touch the seekbar I am unable to scroll up and down and I'd like to. Here my function which allow me to slide the seekbar instead of slide the navigation drawer private View onCritereView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View mView = inflater.inflate(R.layout.fragment_critere, container, false);

detect if the touch stopped on an android device screen

帅比萌擦擦* 提交于 2019-12-10 18:20:05
问题 I want to fire a method after a touch has been initiated and left the screen. I can detect the beginning of a touch by setting a OnTouch event to the View but can't detect when the hand leave the screen. I want to detect when does the touch stops. How can i detect this? 回答1: What you're looking for is http://developer.android.com/reference/android/view/MotionEvent.html - Specifically the use of MotionEvent.ACTION_UP . There is a lot of information on the link I've provided :) A gesture starts

event.getAction() never use MotionEvent.ACTION_UP

此生再无相见时 提交于 2019-12-10 15:21:52
问题 i have a problem with MotionEvent in the OnTouchListener. The ACTION_DOWN works perfectly, but it never use ACTION_UP I really don't know where is my problem, so if someone can help me with it, that would be really great, thank you. public class MainActivity extends Activity { View.OnTouchListener gestureListener; private static final int MIN_DISTANCE = 50; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main)

Detecting Swipe and Tap gestures

╄→尐↘猪︶ㄣ 提交于 2019-12-09 19:41:55
问题 How to detect Swipe and Tap in onTouch method? I want one of two actions to be executed when I swipe and other when I just tap. Need to know how to dell the difference between tap and swipe. Here is my code: @Override public boolean onTouch(View v, MotionEvent event) { if (event.getAction() == MotionEvent.ACTION_MOVE) { mGestureDetector.onTouchEvent(event); } switch(event.getAction()) { case MotionEvent.ACTION_DOWN: x1 = event.getX(); y1 = event.getY(); break; case MotionEvent.ACTION_UP: x2 =

Android事件处理之多点触摸与手势识别

ぐ巨炮叔叔 提交于 2019-12-09 14:56:40
一、Muilti-touch 双指缩放的实现探索: 首先要实现OnTouchListener接口,然后重写方法 : public boolean onTouch(View v, MotionEvent event); 从这个方法中我们就可以获取实现两指缩放功能的全部信息。 View v是触发事件的源,MotionEvent event即一个触摸事件。对屏幕的几乎所有操作都会触发事件,如点击、放开、滑动等。 不同的事件在MotionEvent中有不同的id,我们可以根据event.getAction() & MotionEvent.ACTION_MASK的结果来判断是何种事件。 有如下事件使我们要用到的: MotionEvent.ACTION_DOWN:在第一个点被按下时触发 MotionEvent.ACTION_UP:当屏幕上唯一的点被放开时触发 MotionEvent.ACTION_POINTER_DOWN:当屏幕上已经有一个点被按住,此时再按下其他点时触发。 MotionEvent.ACTION_POINTER_UP:当屏幕上有多个点被按住,松开其中一个点时触发(即非最后一个点被放开时)。 MotionEvent.ACTION_MOVE: 当有点在屏幕上移动时触发。值得注意的是,由于它的灵敏度很高,而我们的手指又不可能完全静止(即使我们感觉不到移动,但其实我们的手指也在不停地抖

Drawing a line following finger - motionevent.getX() and getY() incorrect UPDATE

廉价感情. 提交于 2019-12-09 02:05:04
问题 UPDATE: please read entire question again :-) Background: I have created a grid of dots by creating a custom view and then adding these views to a TableLayout . The aim is for me to be able to draw a line from one of these dots to another dot in a way so that when a dot is pressed, a line is started from the center of the pressed dot to the point where the finger is currently touching. When the finger is dragged over another dot, the line then finishes at the center of that dot. The result

What is a better way to implement a system wide side panel (similar to navigation drawer) in Android

允我心安 提交于 2019-12-08 12:20:58
问题 My aim: have a Page slide onto the screen when the user swipes in from the left side of any screen. My current solution: I start my Service (GlobalTouchService) which creates a narrow transparent view (floatingView) with an OnTouchListener this view is then added to side of the screen using WindowManager.addView on MotionEvent.ACTION_DOWN I add the inflated layout to this View (I call it innerView) on MotionEvent.ACTION_MOVE I adjust the width of the window and the left and right margins of