From 28fb09e0b27a97e4664c9a31a3c72a067794b4c6 Mon Sep 17 00:00:00 2001 From: Scott Main Date: Mon, 23 May 2011 17:27:17 -0700 Subject: [PATCH] cherry pick Change-Id: I183ff47e59617b2c17a92b876ca8c8bcc9b45262 docs: add document for the compatibility library Change-Id: I1825ae1fba0be664a7c6a8b0ba32166f216a893f --- .../guide/practices/optimizing-for-3.0.jd | 25 +- docs/html/sdk/compatibility-library.jd | 224 ++++++++++++++++++ docs/html/sdk/sdk_toc.cs | 2 + 3 files changed, 242 insertions(+), 9 deletions(-) create mode 100644 docs/html/sdk/compatibility-library.jd diff --git a/docs/html/guide/practices/optimizing-for-3.0.jd b/docs/html/guide/practices/optimizing-for-3.0.jd index 5cd519b794304..e9683725b43e8 100644 --- a/docs/html/guide/practices/optimizing-for-3.0.jd +++ b/docs/html/guide/practices/optimizing-for-3.0.jd @@ -22,6 +22,14 @@ page.title=Optimizing Apps for Android 3.0 +

See also

+ +
    +
  1. Compatibility Library
  2. +
  3. Google I/O App source code
  4. +
+ @@ -172,7 +180,8 @@ visual elements. This is the standard theme for applications built for Android 3 application will look and feel consistent with the system and other applications when it is enabled.

Additionally, when an activity uses the holographic theme, the system enables the Action Bar for the activity. The Action Bar +href="{@docRoot}guide/topics/ui/actionbar.html">Action Bar for the activity and removes the +Options Menu button in the system bar. The Action Bar replaces the traditional title bar at the top of the activity window and provides the user access to the activity's Options Menu.

@@ -233,27 +242,26 @@ for Screen Independence.

- -

Upgrading or Developing a New App for Tablets

@@ -380,7 +388,6 @@ new graphics engine called Renderscript, and more.

href="{@docRoot}sdk/android-3.0.html">Android 3.0 Platform document.

-

Look at some samples

Many of the new features and APIs that are described above and in the +

+ +

In this document

+
    +
  1. Revisions
  2. +
  3. Installing the Compatibility Library
  4. +
  5. Setting Up a Project to Use the Library
  6. +
  7. Using Some of the Library APIs
  8. +
  9. Samples
  10. +
+ +

See also

+
    +
  1. Optimizing Apps for Android 3.0
  2. +
  3. Google I/O App source code
  4. +
+ +
+ + +

Minimum API level supported: 4

+ +

The Compatibility Library is a static library you can add to your Android application in order to +use APIs not available in older versions of the Android platform. The primary goal of the library is +to provide APIs introduced in Andriod 3.0 for older versions of Android so that all applications can +use them.

+ +

If you're not able to use APIs introduced in Android 3.0 directly, because you want to remain +backward-compatible, the Compatibility Library provides your application access to self-contained +versions of some of the latest APIs that you can use with older versions of Android. Most +importantly, the library provides implementations of the {@link android.app.Fragment} and {@link +android.content.Loader} APIs, so you can use them in a way that's compatible with devices running +Android 1.6 (API level 4) and higher. Thus, you can more easily create a single APK that supports a +majority of devices and provide larger devices (such as tablets) a fully optimized experience by +using Fragments in your activity +design.

+ + +

Revisions

+ +

The sections below provide notes about successive releases of +the Compatibility Library, as denoted by revision number.

+ + +
+ +

+ + Compatibility Library, revision 2 (May 2011) +

+ +
+
+
Changes:
+
+
    +
  • Support for fragment animations.
  • +
  • Fix {@code Fragment.onActivityResult()} bug.
  • +
+
+
+
+ +
+ + +
+ +

+ + Compatibility Library, revision 1 (March 2011) +

+ +
+

Initial release of the library.

+
+ +
+ + + +

Installing the Compatibility Library

+ +

The Compatibility Library is provided as a downloadable package from the Android SDK and AVD +Manager. To install the library:

+ +
    +
  1. Launch the SDK and AVD Manager. +

    From Eclipse, you can select Window +> Android SDK and AVD Manager. Or, launch {@code SDK Manager.exe} from +the {@code <sdk>/} directory (on Windows only) or {@code android} from the {@code +<sdk>/tools/} directory.

  2. +
  3. Expand the Android Repository, check Android Compatibility package +and click Install selected.
  4. +
  5. Proceed to install the package.
  6. +
+ +

When done, all files (including source code, samples, and the {@code .jar} file) are saved +into the <sdk>/extras/android/compatibility/ directory. The next directory +name is {@code v4}, which indicates the lowest compatible version for the library within. That +is, the code in {@code v4/} supports API level 4 and above. (There may be future libraries that +have a different minimum version, so they will be saved alongside this one.)

+ + +

Setting Up a Project to Use the Library

+ +

To add the Compatibility Library to your Android project:

+
    +
  1. In your Android project, create a directory named {@code libs} at the root of your +project (next to {@code src/}, {@code res/}, etc.)
  2. +
  3. Navigate to {@code <sdk>/extras/android/compatibility/v4/}.
  4. +
  5. Copy the {@code android-support-v4.jar} file into your project {@code libs/} directory.
  6. +
  7. Add the JAR to your project build path. In Eclipse, right-click the JAR file in the +Package Explorer, select Build Path > Add to Build Path. +You should then see the JAR file appear in a new directory called Referenced Libraries.
  8. +
+ +

Your application is now ready to use fragments, loaders and other APIs from the library. All the +provided APIs are in the {@code android.support.v4} package.

+ +

Warning: Be certain that you not confuse the standard +{@code android} packages with those in {@code android.support.v4}. Some code completion tools might +get this wrong, especially if you're building against recent versions of the platform. To be safe, +keep your build target set to the same version as you have defined for your {@code android:minSdkVersion} +and double check the import statements for classes that are duplicated in the Compatibility +Library, such as {@code SimpleCursorAdapter}.

+ + +

Using Some of the Library APIs

+ +

The Compatibility Library provides access to several classes introduced with Android 3.0, plus +some updated version of existing classes. Some of the most useful and notable classes in the +library are:

+ + + +

For each of the classes above (and others not listed), the APIs work almost exactly the same +as the counterparts in the latest version of the Android platform. Thus, you can usually refer to +the latest reference documentation for information about the supported APIs. There are some +differences, however. Most notably:

+ + + +

The Compatibility Library currently does not provide reference documentation for the included +APIs. To generate your own set, using the {@code javadoc} tool, perform the +following from a command line:

+ +
+cd <sdk>/extras/android/compatibility/v4/
+mkdir docs
+javadoc -sourcepath src/java/ -subpackages android.support.v4 -d docs
+
+

Open the {@code docs/index.html} file to begin browsing the generated documentation.

+ + +

Tip: To enable the Holographic theme on devices +running Android 3.0 or higher, declare in your manifest file that your application targets +API level 11. For example:

+
+<uses-sdk android:minSdkVersion="4" android:targetSdkVersion="11" />
+
+

This way, your application automatically receives the Holographic theme and the Action Bar for +each activity when running on Android 3.0 and higher.

+
+ +

For more information about how you can optimize your application for the latest +Android-powered devices, read Optimizing +Apps for Android 3.0.

+ + +

Samples

+ +

If you want to see some sample code that uses the Compatibility Library, take a look at the +API +Demos sample code that's included with the Samples package you can download from the AVD and SDK +Manager.

+ +

Additionally, the Google I/O App is a complete +application that uses the library to provide a single APK for both handsets and tablets and also +demonstrates some of Android's best practices in Android UI design.

+ + + + diff --git a/docs/html/sdk/sdk_toc.cs b/docs/html/sdk/sdk_toc.cs index 11f29b14eee4b..d1c06797beec5 100644 --- a/docs/html/sdk/sdk_toc.cs +++ b/docs/html/sdk/sdk_toc.cs @@ -138,6 +138,8 @@ class="new">new!
  • SDK Tools, r11 new!
  • Google USB Driver, r4
  • +
  • Compatibility Library, r2 new!