Velocitytracker detection of finger movement speed

Source: Internet
Author: User

Activity_main.xml

1 <?XML version= "1.0" encoding= "Utf-8"?>2 <LinearLayoutxmlns:android= "Http://schemas.android.com/apk/res/android"3 Xmlns:tools= "Http://schemas.android.com/tools"4 Android:layout_width= "Match_parent"5 Android:layout_height= "Match_parent"6 Tools:context= "Sowell.oracle.com.view.MainActivity">7         <!--8 TV is used to show how fast your finger moves9      -Ten     <TextView One         Android:id= "@+id/tv" A Android:text= "AAA" - Android:layout_width= "100DP" - Android:layout_height= "Match_parent" /> the </LinearLayout>

Mainactivity.java

1  PackageSowell.oracle.com.view;2 3 Importandroid.support.v7.app.AppCompatActivity;4 ImportAndroid.os.Bundle;5 Importandroid.view.MotionEvent;6 ImportAndroid.view.VelocityTracker;7 ImportAndroid.view.View;8 ImportAndroid.widget.EditText;9 ImportAndroid.widget.TextView;Ten  One  Public classMainactivityextendsappcompatactivity { A  -      PublicVelocitytracker Velocitytracker; -      PublicTextView TV; the      Public Doublexvelocity; -      Public Doubleyvelocity; -  -      Public voidinit () { +tv=(TextView) Findviewbyid (r.id.tv); -Velocitytracker=Velocitytracker.obtain (); +     } A  at  - @Override -     protected voidonCreate (Bundle savedinstancestate) { -         Super. OnCreate (savedinstancestate); - Setcontentview (r.layout.activity_main); - init (); inTv.settext ("BBB"); -     } to  +  -     //rewrite the callback function of the Click event the @Override *      Public Booleanontouchevent (Motionevent event) { $ Panax Notoginseng         Final intAction =event.getaction (); -Velocitytracker=Velocitytracker.obtain (); the velocitytracker.addmovement (event); +  A  the         Switch(action) { +              CaseMotionevent.action_move: -Velocitytracker.computecurrentvelocity (1000);//calculate the pixels per 1000ms finger movement $xvelocity=velocitytracker.getxvelocity (); $yvelocity=velocitytracker.getyvelocity (); - Add (xvelocity,yvelocity); -                  Break; the  -              Casemotionevent.action_up:WuyiVelocitytracker.clear ();//Recycling Velocitytracker the velocitytracker.recycle (); -                  Break; Wu  -              CaseMotionevent.action_cancel: About velocitytracker.clear (); $ velocitytracker.recycle (); -                  Break; -  -         } A  +         return Super. Ontouchevent (event); the     } -  $  the  the  the  the     voidAddDoubleXDoubley) -     { in         FinalString Info=string.format ("Horizontal speed:%f\n vertical speed:%f", x, y); the Tv.settext (info); the     } About}

Velocitytracker detection of finger movement speed

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.