2 8 Las tres gráficas siguientes pueden representar la relación que hay entre
42. Utiliza la teoría cinética de los gases para explicar que si un gas experimenta transformaciones a presión constante, al duplicar
Now that we have the Android SDK and PhoneGap installed, (and our PATH variable
updated), we need to create a device emulator that will allow us to test our code in a simulated environment.
1. To see a list of available targets, enter the following:
android list targets
I downloaded all of the SDK platforms, so running this command on my machine lists four options:
jsc-mbp:~ jstark$ android list targets
Available Android targets: id: 1 or "android-3" Name: Android 1.5 Type: Platform API level: 3 Revision: 4
Skins: HVGA (default), HVGA-L, HVGA-P, QVGA-L, QVGA-P id: 2 or "android-4"
Name: Android 1.6 Type: Platform API level: 4 Revision: 3
Skins: HVGA (default), QVGA, WVGA800, WVGA854 id: 3 or "android-7"
Name: Android 2.1-update1 Type: Platform
API level: 7 Revision: 2
Skins: HVGA (default), QVGA, WQVGA400, WQVGA432, WVGA800, WVGA854 id: 4 or "android-8"
Name: Android 2.2 Type: Platform API level: 8 Revision: 1
Skins: HVGA (default), QVGA, WQVGA400, WQVGA432, WVGA800, WVGA854
Take note of the ID string listed in the output for Android 2.1 (i.e., android-7). This SDK is the most widely deployed platform at the time of this writing. 2. Enter the following command to create your AVD:
android create avd -n mySim -t android-7
Here we’re telling Android to create a virtual device (avd) with the name (-n) “mySim” that targets (-t) the android-7 platform.
When asked if you want to configure custom options, just type no and press Enter.
The process should only take a few seconds and when it’s complete, the emulator is installed.
3. To launch the emulator, enter the following command:
emulator -avd mySim
Here we’re using the emulator command to launch the Android Virtual Device that
we just created. The -avd flag is followed by the name you chose when creating
your AVD in the previous step.
Wait while the emulator initializes and eventually displays the phone’s home screen (Figure 7-6). The first launch can take a minute or two, so be patient.
Figure 7-6. The Android Virtual Device (AVD) allows you to test and debug your app without using an actual phone
Build KiloGap
Next, we’re going to convert our web app into a native Android app. The gang at Nitobi has created a little helper application named droidgap to help us with this. When you run droidgap, it’ll ask you a few questions and insert your answers into a bunch of locations throughout a template to create your project. It’s very cool; in fact, if you ever run into someone from Nitobi, you should buy him a martini.
The Android SDK requires Apache Ant, which is included with Mac OS X and many versions of Linux. If you’re using Windows, see http://ant .apache.org/manual/install.html. You will need to install Ant before you can run droidgap.
1. To begin the wizard, launch the Terminal application and enter the following command:
droidgap wiz
The wizard will ask you for a few pieces of information that will be used to generate
your PhoneGap project (Figure 7-7).
Figure 7-7. The droidgap wizard asks you a few questions and builds a customized Android project based on your answers
2. When prompted, enter a name for your app. This is the name that will be displayed to the user in various places on the phone (e.g., beneath the home screen icon for your app, in the list of applications). I’m going to enter “Kilo.”
3. When prompted, enter a package name for your app. The package name serves as a unique identifier for your app. Typically, people use reverse domain name syntax
for app package names. I’m going to enter com.jonathanstark.kilo, but you should
use your own domain name.
4. When prompted, enter the path to the folder on your computer that contains the HTML, CSS, and JavaScript files for your web app. My files are in a folder named
www on my desktop (Figure 7-8), so I’ll enter:
~/Desktop/www
Figure 7-8. My HTML, CSS, and JavaScript files are in a folder named www on my desktop
5. When prompted, enter a directory path for your project. The directory must not already exist—droidgap is going to create it for you. If a directory exists at the path you specify, droidgap will give you an error and ask for a different path. I want droidgap to put my PhoneGap project on my desktop in a directory named Kilo- Gap, so I’m going to enter the following:
~/Desktop/KiloGap
6. When prompted, enter the Android SDK platform you are targeting. If you fol- lowed the instructions above to install all Android SDK platforms, your target platform ID is android-7.
If you want to target a different platform, you can get a list of available platform IDs by leaving the platform ID blank and pressing Enter. In the list that appears, the first line of each entry will have an ID displayed as both an integer and string (e.g., id: 2 or "android-4"). Enter the string version of the ID without quotes (i.e.,
android-4) when the droidgap prompt returns.
After entering the target SDK ID, droidgap will build your project and put the files in the output directory you specified. The process should only take a couple of seconds (Figure 7-9).
Figure 7-9. droidgap will build your project and put the files in the output directory you specified
If you navigate to the ~/Desktop/KiloGap/assets/www/ directory, you’ll notice that droidgap has deposited a file named phonegap.js alongside your other application files. This is the file that PhoneGap uses to expose certain native device functionality via
JavaScript. To make use of phonegap.js, you have to include it in the head section of
your index.html file like so:
... <head>
<title>Kilo</title>
<link type="text/css" rel="stylesheet" media="screen" href="jqtouch/jqtouch.css"/> <link type="text/css" rel="stylesheet"
media="screen" href="themes/jqt/theme.css"/> <link type="text/css" rel="stylesheet"
media="screen" href="kilo.css"/>
<script type="text/javascript" src="phonegap.js" charset="utf-8"></script>
<script type="text/javascript" src="jqtouch/jquery.js" charset="utf-8"></script> <script type="text/javascript" src="jqtouch/jqtouch.js" charset="utf-8"></script> <script type="text/javascript" src="kilo.js" charset="utf-8"></script>
</head> ...