From 7a701024be7e58f840ebf9636cdad62ee4606b72 Mon Sep 17 00:00:00 2001 From: Scott Main Date: Mon, 16 May 2011 13:54:02 -0700 Subject: docs: add redirects to key legacy docs bug: 4439292 Change-Id: Ifd8f590504507fe417aae102a757cb7eae5507a3 --- docs/html/guide/tutorials/hello-world.html | 10 + docs/html/guide/tutorials/hello-world.jd | 569 --------------------- docs/html/guide/tutorials/index.html | 6 +- docs/html/guide/tutorials/localization/index.html | 10 + docs/html/guide/tutorials/localization/index.jd | 593 ---------------------- docs/html/guide/tutorials/notepad/index.html | 10 + docs/html/guide/tutorials/notepad/index.jd | 142 ------ docs/html/guide/tutorials/views/index.html | 10 + docs/html/guide/tutorials/views/index.jd | 118 ----- 9 files changed, 44 insertions(+), 1424 deletions(-) create mode 100644 docs/html/guide/tutorials/hello-world.html delete mode 100644 docs/html/guide/tutorials/hello-world.jd create mode 100644 docs/html/guide/tutorials/localization/index.html delete mode 100755 docs/html/guide/tutorials/localization/index.jd create mode 100644 docs/html/guide/tutorials/notepad/index.html delete mode 100644 docs/html/guide/tutorials/notepad/index.jd create mode 100644 docs/html/guide/tutorials/views/index.html delete mode 100644 docs/html/guide/tutorials/views/index.jd (limited to 'docs/html/guide/tutorials') diff --git a/docs/html/guide/tutorials/hello-world.html b/docs/html/guide/tutorials/hello-world.html new file mode 100644 index 0000000..55187bd --- /dev/null +++ b/docs/html/guide/tutorials/hello-world.html @@ -0,0 +1,10 @@ + + + +Redirecting... + + +

You should have been redirected. Please click here.

+ + \ No newline at end of file diff --git a/docs/html/guide/tutorials/hello-world.jd b/docs/html/guide/tutorials/hello-world.jd deleted file mode 100644 index 11e6497..0000000 --- a/docs/html/guide/tutorials/hello-world.jd +++ /dev/null @@ -1,569 +0,0 @@ -page.title=Hello, World -@jd:body - -
- -
- -

As a developer, you know that the first impression -of a development framework is how easy it is to write "Hello, -World." Well, on Android, it's pretty easy. -It's particularly easy if you're using Eclipse as your IDE, because we've provided a -great plugin that handles your project creation and management to greatly speed-up your -development cycles.

- -

If you are not using Eclipse, the tools provided by the Android SDK are accessible -on the command line, so you can choose your IDE or text editor. -For more information about developing with the Android SDK tools, see -the Overview -section for developing on Android.

- -

Before you start, you should already have the very latest SDK installed, and if you're using -Eclipse, you should have installed the ADT plugin as well. If you have not installed these, see -Installing the Android SDK and return -here when you've completed the installation.

- -

Create an AVD

- - - -

In this tutorial, you will run your application in the Android Emulator. -Before you can launch the emulator, you must create an -Android Virtual Device (AVD). An AVD defines the system image and -device settings used by the emulator.

- -

To create an AVD, use the "android" tool provided in the Android SDK. -Open a command prompt or terminal, navigate to the -tools/ directory in the SDK package and execute: -

-android create avd --target 2 --name my_avd
-
- -

The tool now asks if you would like to create a custom hardware profile. -For the time being, press Return to skip it ("no" is the default response). -That's it. This configures an AVD named "my_avd" that uses the Android 1.5 -platform. The AVD is now ready for use in the emulator.

- -

In the above command, the --target option is required -and specifies the deployment target to run on the emulator. -The --name option is also required and defines the -name for the new AVD.

- - -

Create a New Android Project

- -

After you've created an AVD, the next step is to start a new -Android project in Eclipse.

- -
    -
  1. From Eclipse, select File > New > Project. -

    If the ADT - Plugin for Eclipse has been successfully installed, the resulting dialog - should have a folder labeled "Android" which should contain - "Android Project". (After you create one or more Android projects, an entry for - "Android XML File" will also be available.)

    -
  2. - -
  3. Select "Android Project" and click Next.
    - -
  4. - -
  5. Fill in the project details with the following values: -
      -
    • Project name: HelloAndroid
    • -
    • Application name: Hello, Android
    • -
    • Package name: com.example.helloandroid (or your own private namespace)
    • -
    • Create Activity: HelloAndroid
    • -
    • Min SDK Version: 2
    • -
    -

    Click Finish.

    - - - -

    Here is a description of each field:

    - -
    -
    Project Name
    -
    This is the Eclipse Project name — the name of the directory - that will contain the project files.
    -
    Application Name
    -
    This is the human-readable title for your application — the name that - will appear on the Android device.
    -
    Package Name
    -
    This is the package namespace (following the same rules as for - packages in the Java programming language) that you want all your source code to - reside under. This also sets the package name under which the stub - Activity will be generated. -

    Your package name must be unique across - all packages installed on the Android system; for this reason, it's very - important to use a standard domain-style package for your - applications. The example above uses the "com.example" namespace, which is - a namespace reserved for example documentation — - when you develop your own applications, you should use a namespace that's - appropriate to your organization or entity.

    -
    Create Activity
    -
    This is the name for the class stub that will be generated by the plugin. - This will be a subclass of Android's {@link android.app.Activity} class. An - Activity is simply a class that can run and do work. It can create a UI if it - chooses, but it doesn't need to. As the checkbox suggests, this is optional, but an - Activity is almost always used as the basis for an application.
    -
    Min SDK Version
    -
    This value specifies the minimum API Level required by your application. If the API Level - entered here matches the API Level provided by one of the available targets, - then that Build Target will be automatically selected (in this case, entering - "2" as the API Level will select the Android 1.1 target). With each new - version of the Android system image and Android SDK, there have likely been - additions or changes made to the APIs. When this occurs, a new API Level is assigned - to the system image to regulate which applications are allowed to be run. If an - application requires an API Level that is higher than the level supported - by the device, then the application will not be installed.
    -
    - -

    Other fields: The checkbox for "Use default location" allows you to change - the location on disk where the project's files will be generated and stored. "Build Target" - is the platform target that your application will be compiled against - (this should be selected automatically, based on your Min SDK Version).

    - -

    Notice that the "Build Target" you've selected uses the Android 1.1 - platform. This means that your application will be compiled against the Android 1.1 - platform library. If you recall, the AVD created above runs on the Android 1.5 platform. - These don't have to match; Android applications are forward-compatible, so an application - built against the 1.1 platform library will run normally on the 1.5 platform. The reverse - is not true.

    -
  6. -
- -

Your Android project is now ready. It should be visible in the Package -Explorer on the left. -Open the HelloAndroid.java file, located inside HelloAndroid > src > -com.example.helloandroid). It should look like this:

- -
-package com.example.helloandroid;
-
-import android.app.Activity;
-import android.os.Bundle;
-
-public class HelloAndroid extends Activity {
-    /** Called when the activity is first created. */
-    @Override
-    public void onCreate(Bundle savedInstanceState) {
-        super.onCreate(savedInstanceState);
-        setContentView(R.layout.main);
-    }
-}
- -

Notice that the class is based on the {@link android.app.Activity} class. An Activity is a -single application entity that is used to perform actions. An application may have many separate -activities, but the user interacts with them one at a time. The -{@link android.app.Activity#onCreate(Bundle) onCreate()} method -will be called by the Android system when your Activity starts — -it is where you should perform all initialization and UI setup. An activity is not required to -have a user interface, but usually will.

- -

Now let's modify some code!

- - -

Construct the UI

- -

Take a look at the revised code below and then make the same changes to your HelloAndroid class. -The bold items are lines that have been added.

- -
-package com.android.helloandroid;
-
-import android.app.Activity;
-import android.os.Bundle;
-import android.widget.TextView;
-
-public class HelloAndroid extends Activity {
-   /** Called when the activity is first created. */
-   @Override
-   public void onCreate(Bundle savedInstanceState) {
-       super.onCreate(savedInstanceState);
-       TextView tv = new TextView(this);
-       tv.setText("Hello, Android");
-       setContentView(tv);
-   }
-}
- -

Tip: An easy way to add import packages to your project is -to press Ctrl-Shift-O (Cmd-Shift-O, on Mac). This is an Eclipse -shortcut that identifies missing packages based on your code and adds them for you.

- -

An Android user interface is composed of hierarchies of objects called -Views. A {@link android.view.View} is a drawable object used as an element in your UI layout, -such as a button, image, or (in this case) a text label. Each of these objects is a subclass -of the View class and the subclass that handles text is {@link android.widget.TextView}.

- -

In this change, you create a TextView with the class constructor, which accepts -an Android {@link android.content.Context} instance as its parameter. A -Context is a handle to the system; it provides services like -resolving resources, obtaining access to databases and preferences, and so -on. The Activity class inherits from Context, and because your -HelloAndroid class is a subclass of Activity, it is also a Context. So, you can -pass this as your Context reference to the TextView.

- -

Next, you define the text content with -{@link android.widget.TextView setText(CharSequence) setText()}.

- -

Finally, you pass the TextView to -{@link android.app.Activity#setContentView(View) setContentView()} in order to -display it as the content for the Activity UI. If your Activity doesn't -call this method, then no UI is present and the system will display a blank -screen.

- -

There it is — "Hello, World" in Android! The next step, of course, is -to see it running.

- - -

Run the Application

- -

The Eclipse plugin makes it very easy to run your applications:

- -
    -
  1. Select Run > Run.
  2. -
  3. Select "Android Application".
  4. -
- - - -

The Eclipse ADT will automatically create a new run configuration for your project -and the Android Emulator will automatically launch. Once the emulator is booted up, -your application will appear after a moment. You should now see something like this:

- - - -

The "Hello, Android" you see in the grey bar is actually the application title. The Eclipse plugin -creates this automatically (the string is defined in the res/values/strings.xml file and referenced -by your AndroidManifest.xml file). The text below the title is the actual text that you have -created in the TextView object.

- -

That concludes the basic "Hello World" tutorial, but you should continue reading for some more -valuable information about developing Android applications.

- - -

Upgrade the UI to an XML Layout

- -

The "Hello, World" example you just completed uses what is called a "programmatic" -UI layout. This means that you constructed and built your application's UI -directly in source code. If you've done much UI programming, you're -probably familiar with how brittle that approach can sometimes be: small -changes in layout can result in big source-code headaches. It's also very -easy to forget to properly connect Views together, which can result in errors in -your layout and wasted time debugging your code.

- -

That's why Android provides an alternate UI construction model: XML-based -layout files. The easiest way to explain this concept is to show an -example. Here's an XML layout file that is identical in behavior to the -programmatically-constructed example:

- -
<?xml version="1.0" encoding="utf-8"?>
-<TextView xmlns:android="http://schemas.android.com/apk/res/android"
-  android:layout_width="fill_parent"
-  android:layout_height="fill_parent"
-  android:text="@string/hello"/>
- -

The general structure of an Android XML layout file is simple: it's a tree -of XML elements, wherein each node is the name of a View class -(this example, however, is just one View element). You can use the -name of any class that extends {@link android.view.View} as an element in your XML layouts, -including custom View classes you define in your own code. This -structure makes it very easy to quickly build up UIs, using a more simple -structure and syntax than you would use in a programmatic layout. This model is inspired -by the web development model, wherein you can separate the presentation of your -application (its UI) from the application logic used to fetch and fill in data.

- -

In the above XML example, there's just one View element: the TextView, -which has four XML attributes. Here's a summary of what they mean:

- - - - - - - - - - - - - - - - - - - - - - - - -
- Attribute - - Meaning -
- xmlns:android - - This is an XML namespace declaration that tells the Android tools that you are going to refer to common attributes defined in the Android namespace. The outermost tag in every Android layout file must have this attribute.
-
- android:layout_width - - This attribute defines how much of the available width on the screen this View should consume. -In this case, it's the only View so you want it to take up the entire screen, which is what a value of "fill_parent" means.
-
- android:layout_height - - This is just like android:layout_width, except that it refers to available screen height. -
- android:text - - This sets the text that the TextView should display. In this example, you use a string - resource instead of a hard-coded string value. - The hello string is defined in the res/values/strings.xml file. This is the - recommended practice for inserting strings to your application, because it makes the localization - of your application to other languages graceful, without need to hard-code changes to the layout file. - For more information, see Resources - and Internationalization. -
- - -

These XML layout files belong in the res/layout/ directory of your project. The "res" is -short for "resources" and the directory contains all the non-code assets that -your application requires. In addition to layout files, resources also include assets -such as images, sounds, and localized strings.

- - - -

The Eclipse plugin automatically creates one of these layout files for you: main.xml. -In the "Hello World" application you just completed, this file was ignored and you created a -layout programmatically. This was meant to teach you more -about the Android framework, but you should almost always define your layout -in an XML file instead of in your code. -The following procedures will instruct you how to change your -existing application to use an XML layout.

- -
    -
  1. In the Eclipse Package Explorer, expand the -/res/layout/ folder and open main.xml (once opened, you might need to click -the "main.xml" tab at the bottom of the window to see the XML source). Replace the contents with -the following XML: - -
    <?xml version="1.0" encoding="utf-8"?>
    -<TextView xmlns:android="http://schemas.android.com/apk/res/android"
    -  android:layout_width="fill_parent"
    -  android:layout_height="fill_parent"
    -  android:text="@string/hello"/>
    -

    Save the file.

    -
  2. - -
  3. Inside the res/values/ folder, open strings.xml. -This is where you should save all default text strings for your user interface. If you're using Eclipse, then -ADT will have started you with two strings, hello and app_name. -Revise hello to something else. Perhaps "Hello, Android! I am a string resource!" -The entire file should now look like this: -
    -<?xml version="1.0" encoding="utf-8"?>
    -<resources>
    -    <string name="hello">Hello, Android! I am a string resource!</string>
    -    <string name="app_name">Hello, Android</string>
    -</resources>
    -
    -
  4. - -
  5. Now open and modify your HelloAndroid class use the -XML layout. Edit the file to look like this: -
    -package com.example.helloandroid;
    -
    -import android.app.Activity;
    -import android.os.Bundle;
    -
    -public class HelloAndroid extends Activity {
    -    /** Called when the activity is first created. */
    -    @Override
    -    public void onCreate(Bundle savedInstanceState) {
    -        super.onCreate(savedInstanceState);
    -        setContentView(R.layout.main);
    -    }
    -}
    - -

    When you make this change, type it by hand to try the -code-completion feature. As you begin typing "R.layout.main" the plugin will offer you -suggestions. You'll find that it helps in a lot of situations.

    - -

    Instead of passing setContentView() a View object, you give it a reference -to the layout resource. -The resource is identified as R.layout.main, which is actually a compiled object representation of -the layout defined in /res/layout/main.xml. The Eclipse plugin automatically creates this reference for -you inside the project's R.java class. If you're not using Eclipse, then the R.java class will be generated for you -when you run Ant to build the application. (More about the R class in a moment.)

    -
  6. -
- -

Now re-run your application — because you've created a launch configuration, all -you need to do is click the green arrow icon to run, or select -Run > Run History > Android Activity. Other than the change to the TextView -string, the application looks the same. After all, the point was to show that the two different -layout approaches produce identical results.

- -

Tip: Use the shortcut Ctrl-F11 -(Cmd-Shift-F11, on Mac) to run your currently visible application.

- -

Continue reading for an introduction -to debugging and a little more information on using other IDEs. When you're ready to learn more, -read Application -Fundamentals for an introduction to all the elements that make Android applications work. -Also refer to the Developer's Guide -introduction page for an overview of the Dev Guide documentation.

- - -
-

R class

-

In Eclipse, open the file named R.java (in the gen/ [Generated Java Files] folder). -It should look something like this:

- -
-package com.example.helloandroid;
-
-public final class R {
-    public static final class attr {
-    }
-    public static final class drawable {
-        public static final int icon=0x7f020000;
-    }
-    public static final class layout {
-        public static final int main=0x7f030000;
-    }
-    public static final class string {
-        public static final int app_name=0x7f040001;
-        public static final int hello=0x7f040000;
-    }
-}
-
- -

A project's R.java file is an index into all the resources defined in the -file. You use this class in your source code as a sort of short-hand -way to refer to resources you've included in your project. This is -particularly powerful with the code-completion features of IDEs like Eclipse -because it lets you quickly and interactively locate the specific reference -you're looking for.

- -

It's possible yours looks slighly different than this (perhaps the hexadecimal values are different). -For now, notice the inner class named "layout", and its -member field "main". The Eclipse plugin noticed the XML -layout file named main.xml and generated a class for it here. As you add other -resources to your project (such as strings in the res/values/string.xml file or drawables inside -the res/drawable/ direcory) you'll see R.java change to keep up.

-

When not using Eclipse, this class file will be generated for you at build time (with the Ant tool).

-

You should never edit this file by hand.

-
- -

Debug Your Project

- -

The Android Plugin for Eclipse also has excellent integration with the Eclipse -debugger. To demonstrate this, introduce a bug into -your code. Change your HelloAndroid source code to look like this:

- -
-package com.android.helloandroid;
-
-import android.app.Activity;
-import android.os.Bundle;
-
-public class HelloAndroid extends Activity {
-    /** Called when the activity is first created. */
-    @Override
-    public void onCreate(Bundle savedInstanceState) {
-        super.onCreate(savedInstanceState);
-        Object o = null;
-        o.toString();
-        setContentView(R.layout.main);
-    }
-}
- -

This change simply introduces a NullPointerException into your code. If -you run your application again, you'll eventually see this:

- - - -

Press "Force Quit" to terminate the application and close the emulator window.

- -

To find out more about the error, set a breakpoint in your source code -on the line Object o = null; (double-click on the marker bar next to the source code line). Then select Run > Debug History > Hello, -Android from the menu to enter debug mode. Your app will restart in the -emulator, but this time it will suspend when it reaches the breakpoint you -set. You can then step through the code in Eclipse's Debug Perspective, -just as you would for any other application.

- - - - -

Creating the Project without Eclipse

- -

If you don't use Eclipse (such as if you prefer another IDE, or simply use text - editors and command line tools) then the Eclipse plugin can't help you. - Don't worry though — you don't lose any functionality just because you don't - use Eclipse.

- -

The Android Plugin for Eclipse is really just a wrapper around a set of tools - included with the Android SDK. (These tools, like the emulator, aapt, adb, - ddms, and others are documented elsewhere.) - Thus, it's possible to - wrap those tools with another tool, such as an 'ant' build file.

- -

The Android SDK includes a tool named "android" that can be - used to create all the source code and directory stubs for your project, as well - as an ant-compatible build.xml file. This allows you to build your project - from the command line, or integrate it with the IDE of your choice.

- -

For example, to create a HelloAndroid project similar to the one created - in Eclipse, use this command:

- -
-android create project \
-    --package com.android.helloandroid \
-    --activity HelloAndroid \ 
-    --target 2 \
-    --path <path-to-your-project>/HelloAndroid 
-
- -

This creates the required folders and files for the project at the location - defined by the path.

- -

For more information on how to use the SDK tools to create and build projects on the command line, read -Creating and Managing Projects on the Command Line and -Building and Running Apps on the Command Line.

diff --git a/docs/html/guide/tutorials/index.html b/docs/html/guide/tutorials/index.html index 4881acf..e412dec 100644 --- a/docs/html/guide/tutorials/index.html +++ b/docs/html/guide/tutorials/index.html @@ -1,8 +1,10 @@ - + +Redirecting... -click here if you are not redirected. +

You should have been redirected. Please click here.

\ No newline at end of file diff --git a/docs/html/guide/tutorials/localization/index.html b/docs/html/guide/tutorials/localization/index.html new file mode 100644 index 0000000..2ea6661 --- /dev/null +++ b/docs/html/guide/tutorials/localization/index.html @@ -0,0 +1,10 @@ + + + +Redirecting... + + +

You should have been redirected. Please click here.

+ + \ No newline at end of file diff --git a/docs/html/guide/tutorials/localization/index.jd b/docs/html/guide/tutorials/localization/index.jd deleted file mode 100755 index 8a60814..0000000 --- a/docs/html/guide/tutorials/localization/index.jd +++ /dev/null @@ -1,593 +0,0 @@ -page.title=Hello, L10N -@jd:body - -
-
-

In this document

-
    -
  1. Create an Unlocalized App -
      -
    1. Create the Project and Layout
    2. -
    3. Create Default Resources
    4. -
    -
  2. -
  3. Run the Unlocalized App
  4. -
  5. Plan the Localization
  6. -
  7. Localize the App -
      -
    1. Localize the Strings
    2. -
    3. Localize the Images
    4. -
    -
  8. -
  9. Run and Test the Localized App
  10. -
-

See also

-
    -
  1. {@link android.widget.Button}
  2. -
  3. {@link android.widget.TextView}
  4. -
  5. {@link android.app.AlertDialog}
  6. -
-
-
- -

In this tutorial, we will create a Hello, L10N application that uses the -Android framework to selectively load resources. Then we will localize the -application by adding resources to the res/ directory.

- -

This tutorial uses the practices described in the Localization -document.

- - -

Create an Unlocalized Application

- -

The first version of the Hello, L10N application will use only the default -resource directories (res/drawable, res/layout, and -res/values). These resources are not localized — they are the -graphics, layout, and strings that we expect the application to use most often. -When a user runs the application in the default locale, or in a locale that the -application does not specifically support, the application will load resources -from these default directories.

- -

The application consists of a simple user interface that displays two -{@link android.widget.TextView} objects and a {@link android.widget.Button} image with a - background image of a national flag. When clicked, the button displays an -{@link android.app.AlertDialog} object that shows additional text.

- -

Create the Project and Layout

- -

For this application, the default language will be British English and the -default location the United Kingdom.

- -
    -
  1. Start a new project and Activity called "HelloL10N." If you are -using Eclipse, fill out these values in the New Android Project wizard: -
      -
    • Project name: HelloL10N
    • -
    • Application name: Hello, L10N
    • -
    • Package name: com.example.hellol10n (or your own private -namespace)
    • -
    • Create Activity: HelloL10N
    • -
    • Min SDK Version: 3
    • -
    -

    The basic project contains a res/ directory with -subdirectories for the three most common types of resources: graphics -(res/drawable/), layouts (res/layout/) and strings -(res/values/). Most of the localization work you do later in this -tutorial will involve adding more subdirectories to the res/ -directory.

    - plain project -
  2. -
  3. Open the res/layout/main.xml file and replace it with the -following code: -
    <?xml version="1.0" encoding="utf-8"?>
    -<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    -    android:orientation="vertical"
    -    android:layout_width="fill_parent"
    -    android:layout_height="fill_parent"
    -    >
    -<TextView
    -    android:layout_width="fill_parent" 
    -    android:layout_height="wrap_content"
    -    android:gravity="center_horizontal"
    -    android:text="@string/text_a"
    -    />
    -<TextView
    -    android:layout_width="fill_parent"
    -    android:layout_height="wrap_content"
    -    android:gravity="center_horizontal"
    -    android:text="@string/text_b"
    -    />
    -<Button
    -    android:id="@+id/flag_button"
    -    android:layout_width="wrap_content"
    -    android:layout_height="wrap_content"
    -    android:layout_gravity="center"
    -    />
    -</LinearLayout>
    -    
    - -

    The LinearLayout has two {@link android.widget.TextView} objects that will -display localized text and one {@link android.widget.Button} that shows a flag. -

    -
  4. -
- -

Create Default Resources

- -

The layout refers to resources that need to be defined.

- -
    -
  1. Create default text strings. To do this, open the res/values/strings.xml file and replace it with the following code:
    -
    <?xml version="1.0" encoding="utf-8"?>
    -<resources>
    -    <string name="app_name">Hello, L10N</string>
    -    <string name="text_a">Shall I compare thee to a summer"'"s day?</string>
    -    <string name="text_b">Thou art more lovely and more temperate.</string>
    -    <string name="dialog_title">No Localisation</string>
    -    <string name="dialog_text">This dialog box"'"s strings are not localised. For every locale, the text here will come from values/strings.xml.</string>
    -</resources>
    - -

    This code provides British English text for each string that the application -will use. When we localize this application, we will provide alternate text in -German, French, and Japanese for some of the strings.

    -
  2. -
  3. Add a default flag graphic to the res/drawable folder by -saving flag.png as -res/drawable/flag.png. When the application is not localized, it -will show a British flag.
    - -
  4. -
  5. Open HelloL10N.java (in the src/ directory) and add the -following code inside the onCreate() method (after -setContentView). - -
    // assign flag.png to the button, loading correct flag image for current locale
    -Button b;
    -(b = (Button)findViewById(R.id.flag_button)).setBackgroundDrawable(this.getResources().getDrawable(R.drawable.flag));
    -
    -// build dialog box to display when user clicks the flag
    -AlertDialog.Builder builder = new AlertDialog.Builder(this);
    -builder.setMessage(R.string.dialog_text)
    -    .setCancelable(false)
    -    .setTitle(R.string.dialog_title)
    -    .setPositiveButton("Done", new DialogInterface.OnClickListener() {
    -        public void onClick(DialogInterface dialog, int id) {
    -        dialog.dismiss();
    -        }
    -    });
    -final AlertDialog alert = builder.create();
    -
    -// set click listener on the flag to show the dialog box 
    -b.setOnClickListener(new View.OnClickListener() {
    -    public void onClick(View v) {
    -	alert.show();
    -    }
    -    });
    - -

    Tip: In Eclipse, use -Ctrl-Shift-O (Cmd-Shift-O, on Mac) to find and -add missing import packages to your project, then save the HelloL10N.java -file.

    - -

    The code that you added does the following:

    - -
      -
    • It assigns the correct flag icon to the button. - For now, no resources are defined other than the default, so this code -will always assign the contents of res/drawable/flag.png (the -British flag) as the flag icon, no matter what the locale. Once we add more -flags for different locales, this code will sometimes assign a different flag. -
    • -
    • It creates an {@link android.app.AlertDialog} object and sets a click listener so that when the -user clicks the button, the AlertDialog will display. - We will not localize the dialog text; -the AlertDialog will always display the dialog_text that is located -within res/values/strings.xml.
    • -
    - -
  6. -
- -

The project structure now looks like this:

- - nonlocalized - -

Tip: If you will want to run the application on -a device and not just on an emulator, open AndroidManifest.xml and -add android:debuggable="true" inside the -<application> element. For information about setting up the -device itself so it can run applications from your system, see Developing on a Device.

- - -

Run the Unlocalized Application

- -

Save the project and run the application to see how it works. No matter what -locale your device or emulator is set to, the application runs the same way. It -should look something like this:

- - - - - - - - - - -
The unlocalized application, running in any locale:After clicking the flag, in any locale:
nonlocalized2
-

Plan the Localization

-

The first step in localizing an application is to plan how the application -will render differently in different locales. In this application, the default -locale will be the United Kingdom. We will add some locale-specific information -for Germany, France, Canada, Japan, and the United States. Table 1 shows the -plan for how the application will appear in different locales.

- -

Table 1

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Region /
- Language
United KingdomGermanyFranceCanadaJapanUnited StatesOther Location

- English
British English text; British flag (default)-- British English text; Canadian flag- British English text; U.S. flag British English text; British flag (default)
German-German text for app_name, text_a and -text_b; German flag----German text for app_name, text_a and -text_b; British flag
French--French text for app_name, text_a and -text_b; French flagFrench text for app_name, text_a and -text_b; Canadian flag--French text for app_name, text_a and -text_b; British flag
Japanese----Japanese text for text_a and text_b; Japanese -flag-Japanese text for text_a and text_b; British -flag
Other Language------ British English text; British flag (default)
- -

Note that other behaviors are possible; for example, the -application could support Canadian English or U.S. English text. But given the -small amount of text involved, adding more versions of English would not make -this application more useful.

- -

As shown in the table above, the plan calls for five flag icons in addition -to the British flag that is already in the res/drawable/ folder. It -also calls for three sets of text strings other than the text that is in -res/values/strings.xml.

- -

Table 2 shows where the needed text strings and flag icons will go, and -specifies which ones will be loaded for which locales. (For more about the -locale codes, see -Alternate Resources.)

-

Table 2

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Locale CodeLanguage / CountryLocation of strings.xmlLocation of flag.png
DefaultEnglish / United Kingdomres/values/res/drawable/
de-rDEGerman / Germanyres/values-de/res/drawable-de-rDE/
fr-rFRFrench / Franceres/values-fr/res/drawable-fr-rFR/
fr-rCAFrench / Canadares/values-fr/res/drawable-fr-rCA/
en-rCAEnglish / Canada(res/values/)res/drawable-en-rCA/
ja-rJPJapanese / Japanres/values-ja/res/drawable-ja-rJP/
en-rUSEnglish / United States(res/values/)res/drawable-en-rUS/
- -

Tip: A folder qualifer cannot specify a region -without a language. Having a folder named res/drawable-rCA/, -for example, will prevent the application from compiling.

- -

At run time, the application will select a set of resources to load based on the locale -that is set in the user's device. In cases where no locale-specific resources -are available, the application will fall back on the defaults.

- -

For example, assume that the device's language is set to German and its -location to Switzerland. Because this application does not have a -res/drawable-de-rCH/ directory with a flag.png file in it, the system -will fall back on the default, which is the UK flag located in -res/drawable/flag.png. The language used will be German. Showing a -British flag to German speakers in Switzerland is not ideal, but for now we will -just leave the behavior as it is. There are several ways you could improve this -application's behavior if you wanted to:

- - - - -

Localize the Application

- -

Localize the Strings

- -

The application requires three more strings.xml files, one -each for German, French, and Japanese. To create these resource files within -Eclipse:

- -
    -
  1. Select File > New > Android -XML File to open the New Android XML File wizard. You can also open -the wizard by clicking its icon in the toolbar:
    -
  2. -
  3. Select L10N for the Project field, and type strings.xml into -the File field. In the left-hand list, select Language, then click the right arrow.
    -res_file_copy
  4. -
  5. Type de in the Language box and click Finish.
    - res_file_copy -

    A new file, res/values-de/strings.xml, now appears among the project -files.

  6. -
  7. Repeat the steps twice more, for the language codes fr and - ja. -Now the project includes these new skeleton files:
    - res/values-de/strings.xml
    - res/values-fr/strings.xml
    - res/values-ja/strings.xml
    -
  8. -
  9. Add localized text to the new files. To do -this, open the res/values-<qualifier>/strings.xml files and -replace the code as follows:
  10. -
- - - - - - - - - - - - - - - - - - -
FileReplace the contents with the following code:
res/values-de/strings.xml
<?xml version="1.0" encoding="utf-8"?>
-<resources>
-    <string name="app_name">Hallo, Lokalisierung</string>
-    <string name="text_a">Soll ich dich einem Sommertag vergleichen,</string>
-    <string name="text_b">Der du viel lieblicher und sanfter bist?</string>
-</resources>
res/values-fr/strings.xml
<?xml version="1.0" encoding="utf-8"?>
-<resources>
-    <string name="app_name">Bonjour, Localisation</string>
-    <string name="text_a">Irai-je te comparer au jour d'été?</string>
-    <string name="text_b">Tu es plus tendre et bien plus tempéré.</string>
-</resources> 
res/values-ja/strings.xml -
<?xml version="1.0" encoding="utf-8"?>
-<resources>
-    <string name="text_a">あなたをなにかにたとえるとしたら夏の一日でしょうか?</string>
-    <string name="text_b">だがあなたはもっと美しく、もっとおだやかです。</string>
-</resources>
- -

Tip: In the -values-<qualifier>/strings.xml files, you only need to -include text for strings that are different from the default strings. For -example, when the application runs on a device that is configured for Japanese, -the plan is for text_a and text_b to be in Japanese -while all the other text is in English, so -res/values-ja/strings.xml only needs to include text_a -and text_b.

- -

Localize the Images

- -

As shown in Table 2, the application needs six more -drawable folders, each containing a flag.png icon. Add the needed -icons and folders to your project:

- -
    -
  1. Save this German flag icon -as res/drawable-de-rDE/flag.png in the application's project -workspace. -

    For example:

    -
      -
    1. Click the link to open the flag image.
    2. -
    3. Save the image in -your-workspace/HelloL10N/res/drawable-de-rDE/ .
    4. -
    -
  2. -
  3. Save this French flag icon -as res/drawable-fr-rFR/flag.png in the application's project -workspace.
  4. -
  5. Save this Canadian flag icon -as res/drawable-fr-rCA/flag.png in the project workspace.
  6. -
  7. Save the Canadian flag icon -again, this time as res/drawable-en-rCA/flag.png in the project -workspace. (Why not have just one folder that contains the Canadian -flag? Because a folder qualifer cannot specify a region without a language. -You cannot have a folder named drawable-rCA/; instead you must -create two separate folders, one for each of the Canadian languages represented -in the application.)
  8. -
  9. Save this Japanese flag icon -as res/drawable-ja-rJP/flag.png in the project workspace.
  10. -
  11. Save this United States flag -icon as res/drawable-en-rUS/flag.png in the project workspace. -
  12. -
- -

If you are using Eclipse, refresh the project (F5). The new -res/drawable-<qualifier>/ folders should appear in the -project view.

- - -

Run and Test the Localized Application

- -

Once you've added the localized string and image resources, you are ready to - run the application and test its handling of them. To change the locale - on a device or in the emulator, use the Settings -application (Home > Menu > Settings > Locale & text > Select -locale). Depending on how a device was configured, it might not offer any -alternate locales via the Settings application, or might offer only a few. The -emulator, on the other hand, will offer a selection of all the locales that are -available in the Android system image.

- -

To set the emulator to a locale that is not available in the system image, -use the Custom Locale application, which is available in the Application -tab:

- -

custom locale app

- -

To switch to a new locale, long-press a locale name:

- -

using custom locale

- -

For a list of locales available on different versions of the Android platform, -refer to the platform notes documents, listed under "Downloadable SDK Components" -in the "SDK" tab. For example, Android 2.0 locales.

- -

Run the application for each of the expected locales, plus one unexpected -locale. Here are some of the results you should see:

- - - - - - - - - - - - - - - - - - - - - - - - - - -
LocaleOpening screen of application
German / Germany -
Specifically supported by the Hello, L10N application.
custom locale app
French / Canada -
Specifically supported by the Hello, L10N application.
custom locale app
German / Switzerland -
Only the language is specifically supported by -the Hello, L10N application.
custom locale app`
Japanese -
Specifically supported by the Hello, L10N application. -
custom locale app`
Romansh / Switzerland (custom locale rm_CH) -
Not specifically supported by the Hello, L10N -application, so the application uses the default resources.
custom locale app
diff --git a/docs/html/guide/tutorials/notepad/index.html b/docs/html/guide/tutorials/notepad/index.html new file mode 100644 index 0000000..01e4d09 --- /dev/null +++ b/docs/html/guide/tutorials/notepad/index.html @@ -0,0 +1,10 @@ + + + +Redirecting... + + +

You should have been redirected. Please click here.

+ + \ No newline at end of file diff --git a/docs/html/guide/tutorials/notepad/index.jd b/docs/html/guide/tutorials/notepad/index.jd deleted file mode 100644 index f569314..0000000 --- a/docs/html/guide/tutorials/notepad/index.jd +++ /dev/null @@ -1,142 +0,0 @@ -page.title=Notepad Tutorial -@jd:body - - -

This tutorial on writing a notepad application gives you a "hands-on" introduction -to the Android framework and the tools you use to build applications on it. -Starting from a preconfigured project file, it guides you through the process of -developing a simple notepad application and provides concrete examples of how to -set up the project, develop the application logic and user interface, and then -compile and run the application.

- -

The tutorial presents the application development as a set of -exercises (see below), each consisting of several steps. You should follow -the steps in each exercise to gradually build and refine your -application. The exercises explain each step in detail and provide all the -sample code you need to complete the application.

- -

When you are finished with the tutorial, you will have created a functioning -Android application and will have learned many of the most important -concepts in Android development. If you want to add more complex features to -your application, you can examine the code in an alternative implementation -of a Note Pad application, in the -Sample Code section.

- - - -

Who Should Use this Tutorial

- -

This tutorial is designed for experienced developers, especially those with -knowledge of the Java programming language. If you haven't written Java -applications before, you can still use the tutorial, but you might need to work -at a slower pace.

- -

Also note that this tutorial uses -the Eclipse development environment, with the Android plugin installed. If you -are not using Eclipse, you can follow the exercises and build the application, -but you will need to determine how to accomplish the Eclipse-specific -steps in your environment.

- - -

Preparing for the Exercises

- -

The tutorial assumes that you have some familiarity with basic Android -application concepts and terminology. If you are not, you -should read Application -Fundamentals before continuing.

- -

This tutorial also builds on the introductory information provided in the -Hello World -tutorial, which explains how to set up your Eclipse environment -for building Android applications. We recommend you complete the Hello World -tutorial before starting this one.

- -

To prepare for this lesson:

- -
    -
  1. Download the project - exercises archive (.zip).
  2. -
  3. Unpack the archive file to a suitable location on your machine.
  4. -
  5. Open the NotepadCodeLab folder.
  6. -
- -

Inside the NotepadCodeLab folder, you should see six project -files: Notepadv1, - Notepadv2, Notepadv3, - Notepadv1Solution, Notepadv2Solution - and Notepadv3Solution. The Notepadv# projects are -the starting points for each of the exercises, while the -Notepadv#Solution projects are the exercise - solutions. If you are having trouble with a particular exercise, you - can compare your current work against the exercise solution.

- - -

Exercises

- -

The table below lists the tutorial exercises and describes the development -areas that each covers. Each exercise assumes that you have completed any -previous exercises.

- - - - - - - - - - - - - - - - - - -
Exercise -1Start here. Construct a simple notes list that lets the user add new notes but not -edit them. Demonstrates the basics of ListActivity and creating -and handling - menu options. Uses a SQLite database to store the notes.
Exercise 2Add a second Activity to the -application. Demonstrates constructing a -new Activity, adding it to the Android manifest, passing data between the -activities, and using more advanced screen layout. Also shows how to -invoke another Activity to return a result, using -startActivityForResult().
Exercise 3Add handling of life-cycle events to -the application, to let it -maintain application state across the life cycle.
Extra -CreditDemonstrates how to use the Eclipse -debugger and how you can use it to -view life-cycle events as they are generated. This section is optional but -highly recommended.
- - - -

Other Resources and Further Learning

- diff --git a/docs/html/guide/tutorials/views/index.html b/docs/html/guide/tutorials/views/index.html new file mode 100644 index 0000000..41d6796 --- /dev/null +++ b/docs/html/guide/tutorials/views/index.html @@ -0,0 +1,10 @@ + + + +Redirecting... + + +

You should have been redirected. Please click here.

+ + \ No newline at end of file diff --git a/docs/html/guide/tutorials/views/index.jd b/docs/html/guide/tutorials/views/index.jd deleted file mode 100644 index 4e76ab9..0000000 --- a/docs/html/guide/tutorials/views/index.jd +++ /dev/null @@ -1,118 +0,0 @@ -page.title=Hello, Views -@jd:body - - - -

This collection of "Hello World"-style tutorials is designed -to get you quickly started with common Android Views and widgets. The aim is to let you copy and paste -these kinds of boring bits so you can focus on developing the code that makes your Android application rock. -Of course, we'll discuss some of the given code so that it all makes sense.

- -

Note that a certain amount of knowledge is assumed for these tutorials. If you haven't -completed the Hello, World tutorial, -please do so—it will teach you many things you should know about basic -Android development and Eclipse features. More specifically, you should know:

- -

Please, also notice that, in order to make these tutorials simple, some may -not convey the better Android coding practices. In particular, many of them -use hard-coded strings in the layout files—the better practice is to reference strings from -your strings.xml file.

-

With this knowledge, you're ready to begin, so take your pick.

- -
- - - - - - - - - -
-Spinner
- -
- - -
-ListView
- -
-
-GridView
- -
- -
-Gallery
- -
- -
-TabWidget
- -
- -
-MapView
- -
- -
-WebView
- -
- - - -

-There are plenty more Views and widgets available. See the {@link android.view.View} class -for more on View layouts, and the {@link android.widget widget package} -for more useful widgets. And for more raw code samples, visit the -Api Demos. -These can also be found offline, in /<sdk>/samples/ApiDemos.

-
- -- cgit v1.1