Recipe Using Image Buttons in a Table Layout

Android Scaletype

Buttons were introduced in Chapter 2. Like any view, a background image can be added to a button using the android background attribute. However, using the special ImageButton widget provides some additional layout flexibility. It specifies an image using the android src attribute as follows When used in this way, the image shows on top of a button widget.The ImageButton inherits image placement from the ImageView widget using android scaleType. Possible values and how they modify a given image...

Recipe Translating a Location to Address Reverse Geocoding

The Geocoder class provides a method to translate from an address into a latitude-longitude coordinate geocoding and from a latitude-longitude coordinate into an address reverse geocoding . Reverse geocoding might produce only a partial address, such as city and postal code, depending on the level of detail available to the location provider. This recipe uses reverse geocoding to get an address from the device's location and display to the screen, as shown in Figure 10.2.The Geocoder instance...

Recipe Starting a Service When the Camera Button Is Pressed

This recipe shows how to start a service based on a broadcasted event, such as when the camera button is pressed. The broadcast receiver is needed to listen for the specified event s and subsequently launch the service.The broadcast receiver itself is started in another component. Here, it is implemented as a standalone activity, SimpleActivity. The activity shown in Listing 3.14 sets up a broadcast receiver and sets up an intent with the filter for the camera button. The filter for...

Recipe Manipulating Raw Audio

The MediaRecorder MediaPlayer framework is useful for most audio uses, but to manipulate raw audio straight from the microphone, process it without saving to a file, and or play back raw audio, use AudioRecord AudioTrack instead. First, set the permission in the AndroidManifest XML file lt uses-permission gt Then, the steps to record are 1. Create an AudioRecord instance, specifying the following to the constructor Audio source Use one of the MediaRecorder.AudioSource choices described in the...