Android MotionEvent obtains the androidmotionevent for a long time.

Source: Internet
Author: User

Android MotionEvent obtains the androidmotionevent for a long time.

Ideas:

1. Record the aX and aY coordinates of ACTION_DOWN;

2. In ACTION_MOVE, determine whether to move the record. If you move the record, the record is canceled. If you do not move the record, the record is recorded;

3. record the time. Press the coordinates and move the coordinates to display them in TextView aa, bb, and cc;

// Statement

1 public class MainActivity extends ActionBarActivity {2     private static TextView aa, bb, cc;3     private float atime;4     private float aX, aY;5     private boolean mPressBreak = false;

// Specify

1 aa = (TextView) findViewById(R.id.textView1);2 bb = (TextView) findViewById(R.id.textView2); 3 cc = (TextView) findViewById(R.id.textView3);

 

// Obtain the compression duration

 1 @Override 2     public boolean onTouchEvent(MotionEvent event) { 3         // TODO Auto-generated method stub 4         super.onTouchEvent(event); 5         String str = ""; 6         switch (event.getAction()) { 7         case MotionEvent.ACTION_DOWN: 8             aX = event.getX(); 9             aY = event.getY();10             str = String.valueOf(aX) + " , " + String.valueOf(aY);11             bb.setText(str);12             mPressBreak = false;13             break;14         case MotionEvent.ACTION_MOVE:15 16             atime = (event.getEventTime() - event.getDownTime()) / 1000;17             str = String.valueOf(event.getX()) + " , "18                     + String.valueOf(event.getY());19             if ((Math.abs((event.getX() - aX)) > 10)20                     || (Math.abs(event.getY() - aY) > 10)) {21                 atime = 0;22                 mPressBreak = true;23             }24             break;25 26         }27 28         if (!mPressBreak) {29             aa.setText(String.valueOf((int) (atime)));30             cc.setText(str);31         }32 33         return true;34     }

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.