Remaining Positive

One email that shows how it’s done. “Remaining Positive” is published by Alex Boast.

Smartphone

独家优惠奖金 100% 高达 1 BTC + 180 免费旋转




Android Gestures Tutorial

Gestures are important for application of any category to boost the app user interface and provide comfort and ease of use to the users. Gestures are always linked to animations in a mobile app. And this animations are essential to maintain an illusion of interactivity for the app users. So when they are paired with app gestures, they make the brain believe it’s interacting with the tangible objects.

Moreover, the animations are invaluable to provide visual feedbacks to the user. Therefore, without such animations, the users won’t be sure whether the gesture action is completed successfully or not. Even the simplest gesture — Pull-to-Refresh feels so intuitive that it is being used by countless mobile applications.

Lets say that one doesn’t add a pull to refresh button in their app (one reason could be that one forgets to add it; another reason could be no need to add it, probably because of automatic updation of feeds/information, an example of which is firebase onDataChange() listener). In such a case, even if there is no need to use a pull to refresh view, the user is still in the impression that the app under use lacks basic UI principles.

Required or not, a developer should account for all possible conditions for occurrences of gestures within an app, and implement them correctly. In this post, we will make a simple gesture detector app to detect:

Note: To hop on the tutorial code directly, you may fork/clone/download the GitHub repository:

Lets begin making our gesture detector app using the following steps:

6. Now, we want to change the mTextView text when a gesture is performed by the user. In each of the overridden methods, write code to change the mTextView text same as the operation being performed. For example, inside onSingleTapConfirmed() method, you need to mTextView.setText(“On Single Tap”). Also remember to return true; inside the method after all inside code is written (it is a way of indicating other overridden methods that the performed gesture has already been taken care of by this method!).

7. To make all of the above code, we will have to create an instance of GestureDetector (call it mGestureDetector), and pass the context and GestureDetector (“this” in case of implementation of class) parameters through its constructors.

8. Last thing we want to do is to override onTouchEvent() [ control+enter for Mac, command+enter for Windows -> “override methods” -> start typing “onTouchEvent”, select onTouchEvent ]. Before super implementation in this method, you should pass the event as parameter to the mGestureDetector.onTouchEvent(MotionEvent event).

Your java class now should look like this:

Thats it! You have a working gesture detector app with only a few simple steps. Now that you have these concepts in mind, the applications as to what you can do with these features is endless!

I hope this post was of useful context to you. If it was, please hit the heart ❤ for this post. And as usual, happy programming. :)

Add a comment

Related posts:

Use JSforce and Firebase Functions to query Salesforce data

First of all you will need a Salesforce user account with sufficient persmissions to query the data you need. If you’re the Salesforce admin then this shouldn’t be a problem, otherwise just find your…

Find The Cheapest Domain Registration For Your Next Domain

Domain registrars are organizations that administer and register domain names for international websites. The value of choosing the right domain cannot be overstated, as it can deceive a consumer in…

Coinbase secures first crypto licence in Germany

We are delighted to announce that the German Federal Financial Supervisory Authority (BaFin) has awarded Coinbase Germany GmbH a licence for crypto custody and trading, under the new licensing regime…