Exercises Eio
1. Add a new color resource with a value of 00ff00 to your Droidl project. Within the layout file, change the textColor attribute of the TextView control to the color resource you just created. Rerun the application and view the result. 2. Add a new dimension resource with a value of 22pt to your Droidl project. Within the layout file, change the textSize attribute of the TextView control to the dimension resource you just created. Rerun the application and view the result. 3. Add a new...
Summary 1
In this hour, you've seen how different Android applications can be designed using three application components Context, Activity, and Intent. Each Android application comprises one or more activities. Top-level application functionality is accessible through the application context. Each activity has a special function and usually its own layout, or user interface. An activity is launched when the Android system matches an intent object with the most appropriate application activity, based on...
Qa Xux
Q. If I'm storing images locally, can I use the ImageSwitcher setImageURI method instead of the setImageDrawable method A. Of course. In fact, we recommend it. If the graphic is locally available, use the setImageURI method to greatly simplify the code for loading a graphic into an ImageSwitcher or ImageView control. There is no need for streams or Drawable objects in memory. Q. When using a ViewSwitcher control, can I set my own animations A. Yes, you can create any animation you want between...
Using HTTP Networking
The most common network transfer protocol is Hypertext Transfer Protocol HTTP . Most commonly used HTTP ports are open and available for use on phone networks. A fast way to get to a network resource is by retrieving a stream to the content. Many Android interfaces for reading data accept streams. One such example is XmlPullParser. The setInput method of XmlPullParser class takes an InputStream. Previously, you retrieved this stream from the resources. Now, however, you can get it from a...
Handling LongClicks with setOnLongClickListener
A long-click is a special type of click available on the Android platform. Basically, a long-click event is when a user clicks on a control for about one second. This type of click is handled separately from a regular, short click. To handle long-clicks, you need to implement the View.OnLongClickListener class and pass it into the ImageButton control's setOnLongClickListener method. OnLongClickListener has one required method you must implement onLongClick . Here is a sample implementation of...
Configuration Management for Android
Developers must try to support the widest possible range of devices, without biting off more than they can chew in terms of maintenance and configuration management. The following are some factors to consider when determining target platforms What hardware features will the application require Does the application require a touch screen A hardware keyboard A directional pad Specific screen dimensions What software features will the application require Does the application support different...
Checking Network Status
The Android SDK provides utilities for gathering information about the current state of a network. This is useful for determining whether a network connection is available before trying to use a network resource. By validating network connectivity before attempting to make a connection, you can avoid many of the failure cases common in mobile device networking applications and provide your end users with a more pleasant user experience. Retrieving Network Status Information Programmatically...
Implementing Application Activities
To implement a base Activity class, you simply copy the source file called QuizSplashActivity.java. Then you create a new class file called QuizActivity. This class should look very simple for now In the project code for this chapter, and future chapters, you will see that there is only a single drawable resource directory named drawable. Whenever the Android system goes about picking a drawable resource, it only looks in this directory instead of the three default directories, drawable-ldpi,...
Quiz Wxv
1. True or False All Android applications can and should be enhanced using social features. 2. How does the Been There, Done That application create friend relationships A. By allowing the player to search the application server for friends he or she recognizes B. By allowing the player to input a friend's email address C. By launching the Contacts application and allowing the player to choose a contact D. By allowing the player to input a friend's phone number 3. True or False The Android SDK...
Initializing an ImageSwitcher Control
To initialize an ImageSwitcher control, you simply set its ViewFactory and then use one of the three methods to set the image. In this case, you use the setImageDrawable method, like so ImageSwitcher questionImageSwitcher ImageSwitcher questionImageSwitcher.setFactory new MyImageSwitcherFactory Drawable image Unfortunately, you cannot use the setImageURI method with a remote online URL with ImageSwitcher at this time. Instead, you need to perform a bit of extra work to download the image from...
Using the Application Tab
The Application tab see Figure 5.2 contains application-wide settings, including the application label and icon, as well as information about application components such as activities, intent filters, and other application functionality, including configuration for service and content provider implementations. Java - Droidl AndroidManifest.xml - Eclipse Edit Run Navigate Search Project Refactor Win amp - - - s -- - egPl'i' Defines general information about the AndroidManifestxml Package...
Uploading Player Data with the HTTP GET Method
The player data is submitted to the application server by using the HTTP GET method via the HttpGet class. Because you are posting form query variables, you want to use the URLEncodedUtils utility with a List container of BasicNameValuePair objects to assist with creating the final URL for the request. Finally, the whole network operation must be wrapped inside the AsyncTask object so that the user interface can continue to respond while the network request is being handled. Creating an...
Working with Application Resources
Application resources are created and stored within the Android project files under the res directory. Using a well-defined but flexible directory structure, resources are organized, defined, and compiled with the application package. Application resources are not shared with the rest of the Android system. Defining application data as resources is a good programming practice. Grouping application resources together and compiling them into the application package has the following benefits Code...
Managing Application Permissions
The Android platform is built on a Linux kernel and leverages its built-in system security as part of the Android security model. Each Android application exists in its own virtual machine and operates within its own Linux user account see Figure 5.6 . Applications that want access to shared or privileged resources on the handset must declare those specific permissions in the Android manifest file. This security mechanism ensures that no application can change its behavior on-the-fly or perform...


