Posts Tagged ‘Activity’

Android: Detecting Double Tap Events

Click here to read Android: Detecting Double Tap Events

This Android tutorial explains how to create an Activity that “listens” to double tap events. Doing that isn’t as trivial as getting a single tap from the screen, however writing a code that registers when the screen has been touched twice isn’t complex either. The example featured in this post works on the emulator and on a real Android device.

To implement the double tap, some classes and interfaces are going to be needed, but it’s best to show the example Activity code before explaining each one of them: (more…)

Android: reading float values from a XML file

Click here to read Android: reading float values from a XML file

When programming an Android app, data such as integers, drawables and strings can be loaded from XML files through the Resources class, using their automatically generated IDs. But a float can’t be placed in these XML files, since the Resources class won’t generate IDs for it. This post will focus on explaining how to load a float, and some other values from a customized XML file. All code featured in this tutorial is available at the end of the post.

It’s worth mentioning that this example uses the XmlResourceParser class (a XML pull parser) to read the contents from a XML file. This is just one of the three available methods of retrieving the contents of a XML file in Android. That being said, the first thing we are going to need is the XML file. (more…)

Android: changing the ringer volume

Click here to read Android: changing the ringer volume

Another Android tutorial, this time, explaining how to change the different sound volumes of the Android system, such as the ringer, music and notification loudness. The source code featured below is available for download at the end of the post.

Using a seek bar to control audio’s volume in Android is a lot like changing the screen brightness with a seek bar. However, instead of using a ContentResolver to obtain the service that controls the audio, Android has a class that makes everything easier, named AudioManager. So, the example here will basically obtain a reference to the AudioManager and will use it to get the current ringer volume and use it to set the progress of a seek bar. When changed, the seek bar progress will set the value of the sound volume. Here is the code: (more…)

Android: Acessing the gyroscope sensor for simple applications

Click here to read Android: Acessing the gyroscope sensor for simple applications

This post explains how to get values from the gyroscope (or any sensor that returns the device’s relative angle) to create simple application. The reason why I’m stating ‘for simple applications’ is because the code featured here is already deprecated. I’m just explaining how to do it because it still works, and it’s very clean and short to explain, as opposed to the new method, which is much more accurate but more complex to implement.

Still, it’s possible to use it for simple applications, although, if the application requires accuracy from the sensors, such as augmented reality applications or even games, it’s recommended to use the getRotationMatrix() method from the Sensor Manger class instead.

With that said, the following code just prints the rotation values from the gyroscope on the screen: (more…)

Android: Changing the animation between Activities

Click here to read Android: Changing the animation between Activities

This post features how to change Android’s default animation when switching between Activities. Before reading the rest, please know that the code that changes the standard animation be found at the API Demo that comes with the Android SDK. But since there’s a lack of proper documentation regarding this subject and it’s difficult to find a place explaining it, here is a post that helps in aiding these two problems.

So, the code to change the animation between two Activities is very simple: just call the overridePendingTransition() from the current Activity, after starting a new Intent. This method is available from Android version 2.0 (API level 5), and it takes two parameters, that are used to define the enter and exit animations of your current Activity. Here’s an example: (more…)