Merge "Fix crash during Bluetooth on/off stress test" into lmp-mr1-dev
diff --git a/docs/html/guide/topics/text/creating-input-method.jd b/docs/html/guide/topics/text/creating-input-method.jd
index 802b58a..424a21c 100644
--- a/docs/html/guide/topics/text/creating-input-method.jd
+++ b/docs/html/guide/topics/text/creating-input-method.jd
@@ -41,8 +41,8 @@
 <p>
     To add an IME to the Android system, you create an Android application
     containing a class that extends {@link android.inputmethodservice.InputMethodService}. In
-    addition, you usually create a "settings" activity that passes options to the IME
-    service. You can also define a settings UI that's displayed as part of the system settings.
+    addition, you usually create a "settings" activity that passes options to the IME service. You
+    can also define a settings UI that's displayed as part of the system settings.
 </p>
 <p>This guide covers the following:</p>
 <ul>
@@ -70,29 +70,22 @@
     <strong>Figure 1.</strong> The life cycle of an IME.
 </p>
 <p>
-    The following sections describe how to implement the UI and code associated
-with an IME that
+    The following sections describe how to implement the UI and code associated with an IME that
     follows this lifecycle.
 </p>
 <h2 id="DefiningIME">Declaring IME Components in the Manifest</h2>
 <p>
-    In the Android system, an IME is an Android application that contains a
-special IME service.
-    The application's manifest file must declare the service, request the
-necessary permissions,
-    provide an intent filter that matches the action
-<code>action.view.InputMethod</code>, and
-    provide metadata that defines characteristics of the IME. In addition, to
-provide a settings
-    interface that allows the user to modify the behavior of the IME, you can
-define a "settings"
+    In the Android system, an IME is an Android application that contains a special IME service.
+    The application's manifest file must declare the service, request the necessary permissions,
+    provide an intent filter that matches the action <code>action.view.InputMethod</code>, and
+    provide metadata that defines characteristics of the IME. In addition, to provide a settings
+    interface that allows the user to modify the behavior of the IME, you can define a "settings"
     activity that can be launched from System Settings.
 </p>
 <p>
     The following snippet declares an IME service. It requests the permission
-{@link android.Manifest.permission#BIND_INPUT_METHOD} to allow the service to
-connect the IME to
-    the system, sets up an intent filter that matches the action
+    {@link android.Manifest.permission#BIND_INPUT_METHOD} to allow the service to connect the IME
+    to the system, sets up an intent filter that matches the action
     <code>android.view.InputMethod</code>, and defines metadata for the IME:
 </p>
 <pre>
@@ -108,10 +101,8 @@
     &lt;/service&gt;
 </pre>
 <p>
-    This next snippet declares the settings activity for the IME. It has an
-intent filter for
-    {@link android.content.Intent#ACTION_MAIN} that indicates this activity is
-the main entry point
+    This next snippet declares the settings activity for the IME. It has an intent filter for
+    {@link android.content.Intent#ACTION_MAIN} that indicates this activity is the main entry point
     for the IME application:</p>
 <pre>
     &lt;!-- Optional: an activity for controlling the IME settings --&gt;
@@ -127,23 +118,18 @@
 </p>
 <h2 id="IMEAPI">The Input Method API</h2>
 <p>
-    Classes specific to IMEs are found in the {@link android.inputmethodservice} and {@link android.view.inputmethod}
-    packages. The {@link android.view.KeyEvent} class is important for handling keyboard
-    characters.
+    Classes specific to IMEs are found in the {@link android.inputmethodservice} and
+    {@link android.view.inputmethod} packages. The {@link android.view.KeyEvent} class is
+    important for handling keyboard characters.
 </p>
 <p>
     The central part of an IME is a service component, a class that extends
-    {@link android.inputmethodservice.InputMethodService}. In addition to
-implementing the
-    normal service lifecycle, this class has callbacks for providing your IME's
-UI, handling user
-    input, and delivering text to the field that currently has focus. By
-default, the
-    {@link android.inputmethodservice.InputMethodService} class provides most
-of the implementation
-    for managing the state and visibility of the IME and communicating with the
-current
-    input field.
+    {@link android.inputmethodservice.InputMethodService}. In addition to implementing the
+    normal service lifecycle, this class has callbacks for providing your IME's UI, handling user
+    input, and delivering text to the field that currently has focus. By default, the
+    {@link android.inputmethodservice.InputMethodService} class provides most of the implementation
+    for managing the state and visibility of the IME and communicating with the current input
+    field.
 </p>
 <p>
     The following classes are also important:
@@ -152,45 +138,32 @@
     <dt>{@link android.view.inputmethod.BaseInputConnection}</dt>
     <dd>
         Defines the communication channel from an {@link android.view.inputmethod.InputMethod}
-        back to the application that is receiving its input. You use it to read
-text around the
-        cursor, commit text to the text box, and send raw key events to the
-application.
-        Applications should extend this class rather than implementing the base
-interface
+        back to the application that is receiving its input. You use it to read text around the
+        cursor, commit text to the text box, and send raw key events to the application.
+        Applications should extend this class rather than implementing the base interface
         {@link android.view.inputmethod.InputConnection}.
     </dd>
     <dt>{@link android.inputmethodservice.KeyboardView}</dt>
     <dd>
-        An extension of {@link android.view.View} that renders a keyboard and
-responds to user
+        An extension of {@link android.view.View} that renders a keyboard and responds to user
         input events. The keyboard layout is specified by an instance of
-        {@link android.inputmethodservice.Keyboard}, which you can define in an
-XML file.
+        {@link android.inputmethodservice.Keyboard}, which you can define in an XML file.
     </dd>
 </dl>
 <h2 id="IMEUI">Designing the Input Method UI</h2>
 <p>
-    There are two main visual elements for an IME: the <strong>input</strong>
-view and the
-    <strong>candidates</strong> view. You only have to implement the elements
-that are relevant to
+    There are two main visual elements for an IME: the <strong>input</strong> view and the
+    <strong>candidates</strong> view. You only have to implement the elements that are relevant to
     the input method you're designing.
 </p>
 <h3 id="InputView">Input view</h3>
 <p>
-    The input view is the UI where the user inputs text in the form of
-keyclicks, handwriting or
-    gestures. When the IME is displayed for the first time, the system calls
-the
-    {@link android.inputmethodservice.InputMethodService#onCreateInputView()}
-callback. In your
-    implementation of this method, you create the layout you want to display in
-the IME
-    window and return the layout to the system. This snippet is an example of
-implementing the
-    {@link android.inputmethodservice.InputMethodService#onCreateInputView()}
-method:
+    The input view is the UI where the user inputs text in the form of keyclicks, handwriting or
+    gestures. When the IME is displayed for the first time, the system calls the
+    {@link android.inputmethodservice.InputMethodService#onCreateInputView()} callback. In your
+    implementation of this method, you create the layout you want to display in the IME
+    window and return the layout to the system. This snippet is an example of implementing the
+    {@link android.inputmethodservice.InputMethodService#onCreateInputView()} method:
 <pre>
     &#64;Override
     public View onCreateInputView() {
@@ -215,17 +188,12 @@
 </p>
 <h3 id="CandidateView">Candidates view</h3>
 <p>
-    The candidates view is the UI where the IME displays potential word
-corrections or
+    The candidates view is the UI where the IME displays potential word corrections or
     suggestions for the user to select. In the IME lifecycle, the system calls
-    {@link android.inputmethodservice.InputMethodService#onCreateCandidatesView()} when
-it's ready
-    to display the candidates view. In your implementation of this method,
-return a layout that shows
-    word suggestions, or return null if you don’t want to show anything. A
-null response is the
-    default behavior, so you don’t have to implement this if you don’t
-provide suggestions.</p>
+    {@link android.inputmethodservice.InputMethodService#onCreateCandidatesView()} when it's ready
+    to display the candidates view. In your implementation of this method, return a layout that
+    shows word suggestions, or return null if you don’t want to show anything. A null response is
+    the default behavior, so you don’t have to implement this if you don’t provide suggestions.</p>
 <p>
     For an example implementation that provides user suggestions, see the
     <a href="https://android.googlesource.com/platform/development/+/master/samples/SoftKeyboard/">
@@ -237,32 +205,22 @@
 </p>
 <h4>Handling multiple screen sizes</h4>
 <p>
-    The UI for your IME must be able to scale for different screen sizes, and
-it also
-    must handle both landscape and portrait orientations. In non-fullscreen IME
-mode, leave
-    sufficient space for the application to show the text field and any
-associated context, so that
-    no more than half the screen is occupied by the IME. In fullscreen IME mode
-this is not an
+    The UI for your IME must be able to scale for different screen sizes, and it also
+    must handle both landscape and portrait orientations. In non-fullscreen IME mode, leave
+    sufficient space for the application to show the text field and any associated context, so that
+    no more than half the screen is occupied by the IME. In fullscreen IME mode this is not an
     issue.
 </p>
 <h4>Handling different input types</h4>
 <p>
-    Android text fields allow you to set a specific input type, such as free
-form text, numbers,
-    URLs, email addresses, and search strings. When you implement a new IME,
-you need to
-    detect the input type of each field and provide the appropriate interface
-for it. However, you
-    don't have to set up your IME to check that the user entered text
-valid for the
-    input type; that's the responsibility of the application that owns the text
-field.
+    Android text fields allow you to set a specific input type, such as free-form text, numbers,
+    URLs, email addresses, and search strings. When you implement a new IME, you need to detect
+    the input type of each field and provide the appropriate interface for it. However, you
+    don't have to set up your IME to check that the user entered text valid for the input type;
+    that's the responsibility of the application that owns the text field.
 </p>
 <p>
-    For example, here are screenshots of the interfaces that the Latin IME
-provided with the
+    For example, here are screenshots of the interfaces that the Latin IME provided with the
     Android platform provides for text and phone number inputs:
 </p>
 <img src="{@docRoot}resources/articles/images/inputmethod_text_type_screenshot.png" alt="" height="142" id="figure2" />
@@ -273,18 +231,14 @@
 <p>
     When an input field receives focus and your IME starts, the system calls
     {@link android.inputmethodservice.InputMethodService#onStartInputView(EditorInfo, boolean) onStartInputView()},
-    passing in an {@link android.view.inputmethod.EditorInfo} object that
-    contains details about the input type and other attributes of the text
-field. In this object,
-    the {@link android.view.inputmethod.EditorInfo#inputType} field contains
-the text field's input
+    passing in an {@link android.view.inputmethod.EditorInfo} object that contains details about
+    the input type and other attributes of the text field. In this object, the
+    {@link android.view.inputmethod.EditorInfo#inputType} field contains the text field's input
     type.
 </p>
 <p>
-    The {@link android.view.inputmethod.EditorInfo#inputType} field is an
-<code>int</code>
-    that contains bit patterns for various input type settings. To test it for
-the text field's
+    The {@link android.view.inputmethod.EditorInfo#inputType} field is an <code>int</code>
+    that contains bit patterns for various input type settings. To test it for the text field's
     input type, mask it with the constant {@link android.text.InputType#TYPE_MASK_CLASS}, like
     this:
 </p>
@@ -297,8 +251,7 @@
 <dl>
     <dt>{@link android.text.InputType#TYPE_CLASS_NUMBER}</dt>
     <dd>
-        A text field for entering numbers. As illustrated in the previous
-screen shot, the
+        A text field for entering numbers. As illustrated in the previous screen shot, the
         Latin IME displays a number pad for fields of this type.
     </dd>
     <dt>{@link android.text.InputType#TYPE_CLASS_DATETIME}</dt>
@@ -315,103 +268,86 @@
     </dd>
 </dl>
 <p>
-    These constants are described in more detail in the reference documentation
-for
+    These constants are described in more detail in the reference documentation for
     {@link android.text.InputType}.
 </p>
 <p>
-    The {@link android.view.inputmethod.EditorInfo#inputType} field can contain
-other bits that
+    The {@link android.view.inputmethod.EditorInfo#inputType} field can contain other bits that
     indicate a variant of the text field type, such as:
 </p>
 <dl>
     <dt>{@link android.text.InputType#TYPE_TEXT_VARIATION_PASSWORD}</dt>
     <dd>
-        A variant of {@link android.text.InputType#TYPE_CLASS_TEXT} for
-entering passwords. The
+        A variant of {@link android.text.InputType#TYPE_CLASS_TEXT} for entering passwords. The
         input method will display dingbats instead of the actual text.
     </dd>
     <dt>{@link android.text.InputType#TYPE_TEXT_VARIATION_URI}</dt>
     <dd>
-        A variant of {@link android.text.InputType#TYPE_CLASS_TEXT} for
-entering web URLs and
+        A variant of {@link android.text.InputType#TYPE_CLASS_TEXT} for entering web URLs and
         other Uniform Resource Identifiers (URIs).
     </dd>
     <dt>{@link android.text.InputType#TYPE_TEXT_FLAG_AUTO_COMPLETE}</dt>
     <dd>
-        A variant of {@link android.text.InputType#TYPE_CLASS_TEXT} for
-entering text that the
-        application "auto-completes" from a dictionary, search, or other
-facility.
+        A variant of {@link android.text.InputType#TYPE_CLASS_TEXT} for entering text that the
+        application "auto-completes" from a dictionary, search, or other facility.
     </dd>
 </dl>
 <p>
-    Remember to mask {@link android.view.inputmethod.EditorInfo#inputType} with
-the appropriate
-    constant when you test for these variants. The available mask constants are
-listed in the
+    Remember to mask {@link android.view.inputmethod.EditorInfo#inputType} with the appropriate
+    constant when you test for these variants. The available mask constants are listed in the
     reference documentation for {@link android.text.InputType}.
 </p>
 <p class="caution">
-    <strong>Caution:</strong> In your own IME, make sure you handle text
-correctly when you send it
-    to a password field. Hide the password in your UI both in the input view
-and in the candidates
-    view. Also remember that you shouldn't store passwords on a device. To
-learn more, see the <a href="{@docRoot}guide/practices/security.html">Designing for Security</a>
- guide.
+    <strong>Caution:</strong> In your own IME, make sure you handle text correctly when you send it
+    to a password field. Hide the password in your UI both in the input view and in the candidates
+    view. Also remember that you shouldn't store passwords on a device. To learn more, see the
+    <a href="{@docRoot}guide/practices/security.html">Designing for Security</a> guide.
 </p>
 <h2 id="SendText">Sending Text to the Application</h2>
 <p>
-    As the user inputs text with your IME, you can send text to the application
-by
-    sending individual key events or by editing the text around the cursor in
-the application's text
+    As the user inputs text with your IME, you can send text to the application by sending
+    individual key events or by editing the text around the cursor in the application's text
     field. In either case, you use an instance of {@link android.view.inputmethod.InputConnection}
     to deliver the text. To get this instance, call
     {@link android.inputmethodservice.InputMethodService#getCurrentInputConnection InputMethodService.getCurrentInputConnection()}.
 </p>
 <h3 id="EditingCursor">Editing the text around the cursor</h3>
 <p>
-    When you're handling the editing of existing text in a text field, some of
-the more useful
+    When you're handling the editing of existing text in a text field, some of the more useful
     methods in {@link android.view.inputmethod.BaseInputConnection} are:
 </p>
 <dl>
     <dt>
         {@link android.view.inputmethod.BaseInputConnection#getTextBeforeCursor(int, int) getTextBeforeCursor()}</dt>
     <dd>
-        Returns a {@link java.lang.CharSequence} containing the number of
-requested characters
+        Returns a {@link java.lang.CharSequence} containing the number of requested characters
         before the current cursor position.
     </dd>
     <dt>
         {@link android.view.inputmethod.BaseInputConnection#getTextAfterCursor(int, int) getTextAfterCursor()}
     </dt>
     <dd>
-        Returns a {@link java.lang.CharSequence} containing the number of
-requested characters following the current cursor position.
+        Returns a {@link java.lang.CharSequence} containing the number of requested characters
+        following the current cursor position.
     </dd>
     <dt>
         {@link android.view.inputmethod.BaseInputConnection#deleteSurroundingText(int, int) deleteSurroundingText()}
     </dt>
     <dd>
-        Deletes the specified number of characters before and following the
-current cursor
+        Deletes the specified number of characters before and following the current cursor
         position.
     </dd>
     <dt>
         {@link android.view.inputmethod.BaseInputConnection#commitText(CharSequence, int) commitText()}
     </dt>
     <dd>
-        Commit a {@link java.lang.CharSequence} to the text field and set a new
-cursor
+        Commit a {@link java.lang.CharSequence} to the text field and set a new cursor
         position.
     </dd>
 </dl>
 <p>
-    For example, the following snippet shows how to replace the four characters to
-the left of the cursor with the text "Hello!":
+    For example, the following snippet shows how to replace the four characters to the left of the
+    cursor with the text "Hello!":
 </p>
 <pre>
     InputConnection ic = getCurrentInputConnection();
@@ -424,12 +360,9 @@
 </pre>
 <h3 id="ComposeThenCommit">Composing text before committing</h3>
 <p>
-    If your IME does text prediction or requires multiple steps to compose a
-glyph or
-    word, you can show the progress in the text field until the user commits
-the word, and then you
-    can replace the partial composition with the completed text. You may give
-special treatment to
+    If your IME does text prediction or requires multiple steps to compose a glyph or
+    word, you can show the progress in the text field until the user commits the word, and then you
+    can replace the partial composition with the completed text. You may give special treatment to
     the text by adding a "span" to it when you pass it to
 {@link android.view.inputmethod.InputConnection#setComposingText setComposingText()}.
 </p>
@@ -465,14 +398,10 @@
 </p>
 <h3 id="HardwareKeyEvents">Intercepting hardware key events</h3>
 <p>
-    Even though the input method window doesn't have explicit focus, it
-receives hardware key
-    events first and can choose to consume them or forward them along to the
-application. For
-    example, you may want to consume the directional keys to navigate within
-your UI for candidate
-    selection during composition. You may also want to trap the back key to
-dismiss any popups
+    Even though the input method window doesn't have explicit focus, it receives hardware key
+    events first and can choose to consume them or forward them along to the application. For
+    example, you may want to consume the directional keys to navigate within your UI for candidate
+    selection during composition. You may also want to trap the back key to dismiss any popups
     originating from the input method window.</p>
 <p>
     To intercept hardware keys, override
@@ -483,45 +412,36 @@
     SoftKeyboard</a> sample app for an example.
 </p>
 <p>
-    Remember to call the <code>super()</code> method for keys you don't want to
-handle yourself.
+    Remember to call the <code>super()</code> method for keys you don't want to handle yourself.
 </p>
 <h2 id="IMESubTypes">Creating an IME Subtype</h2>
 <p>
-    Subtypes allow the IME to expose multiple input modes and languages
-supported by an IME. A subtype can represent:
+    Subtypes allow the IME to expose multiple input modes and languages supported by an IME. A
+    subtype can represent:
 </p>
 <ul>
     <li>A locale such as en_US or fr_FR</li>
     <li>An input mode such as voice, keyboard, or handwriting</li>
     <li>
-        Other input styles, forms, or properties specific to the IME, such as
-10-key or qwerty
+        Other input styles, forms, or properties specific to the IME, such as 10-key or qwerty
         keyboard layouts.
     </li>
 </ul>
 <p>
-    Basically, the mode can be any text such as "keyboard", "voice", and so
-forth. A subtype can also expose a combination of these.
+    Basically, the mode can be any text such as "keyboard", "voice", and so forth. A subtype can
+    also expose a combination of these.
 </p>
 
 <p>
-    Subtype information is used for an IME switcher dialog that's available
-from the notification
-    bar and also for IME settings. The information also allows the framework to
-bring up a
-    specific subtype of an IME directly. When you build an IME, use the subtype
-facility, because
-    it helps the user identify and switch between different IME languages and
-modes.
+    Subtype information is used for an IME switcher dialog that's available from the notification
+    bar and also for IME settings. The information also allows the framework to bring up a
+    specific subtype of an IME directly. When you build an IME, use the subtype facility, because
+    it helps the user identify and switch between different IME languages and modes.
 </p>
 <p>
-    You define subtypes in one of the input method's XML resource files, using
-the
-    <code>&lt;subtype&gt;</code> element. The following snippet defines an IME
-with two
-    subtypes: a keyboard subtype for the US English locale, and another
-keyboard subtype for the
+    You define subtypes in one of the input method's XML resource files, using the
+    <code>&lt;subtype&gt;</code> element. The following snippet defines an IME with two
+    subtypes: a keyboard subtype for the US English locale, and another keyboard subtype for the
     French language locale for France:
 </p>
 <pre>
@@ -546,10 +466,8 @@
 /&gt;
 </pre>
 <p>
-    To ensure that your subtypes are labeled correctly in the UI, use %s to get
-a subtype label
-    that is the same as the subtype’s locale label. This is demonstrated in
-the next two snippets.
+    To ensure that your subtypes are labeled correctly in the UI, use %s to get a subtype label
+    that is the same as the subtype’s locale label. This is demonstrated in the next two snippets.
     The first snippet shows part of the input method's XML file:
 </p>
 <pre>
@@ -560,10 +478,8 @@
         android:imeSubtypeMode="keyboard" /&gt;
 </pre>
 <p>
-    The next snippet is part of the IME's <code>strings.xml</code> file. The
-string
-    resource <code>label_subtype_generic</code>, which is used by the input
-method UI definition to
+    The next snippet is part of the IME's <code>strings.xml</code> file. The string
+    resource <code>label_subtype_generic</code>, which is used by the input method UI definition to
     set the subtype's label, is defined as:
 </p>
 <pre>
@@ -575,12 +491,9 @@
 </p>
 <h3 id="SubtypeProcessing">Choosing IME subtypes from the notification bar</h3>
 <p>
-    The Android system manages all subtypes exposed by all IMEs. IME subtypes
-are
-    treated as modes of the IME they belong to. In the notification bar, a user
-can select an
-    available subtype for the currently-set IME, as shown in the following
-screenshot:
+    The Android system manages all subtypes exposed by all IMEs. IME subtypes are
+    treated as modes of the IME they belong to. In the notification bar, a user can select an
+    available subtype for the currently-set IME, as shown in the following screenshot:
 </p>
 <img
 src="{@docRoot}resources/articles/images/inputmethod_subtype_notification.png"
@@ -599,9 +512,9 @@
 </p>
 <h3 id="SubtypeSettings">Choosing IME subtypes from System Settings</h3>
 <p>
-    A user can control how subtypes are used in the “Language &amp; input”
-settings panel in the
-    System Settings area. In the <a href="https://android.googlesource.com/platform/development/+/master/samples/SoftKeyboard/">
+    A user can control how subtypes are used in the “Language &amp; input” settings panel in the
+    System Settings area. In the
+    <a href="https://android.googlesource.com/platform/development/+/master/samples/SoftKeyboard/">
     SoftKeyboard</a> sample app, the file <code>InputMethodSettingsFragment.java</code> contains an
     implementation that facilitates a subtype enabler in the IME settings. Refer to the
     <a href="https://android.googlesource.com/platform/development/+/master/samples/SoftKeyboard/">
@@ -617,15 +530,14 @@
 
 <h2 id="Switching">Switching among IME Subtypes</h2>
 
-<p>You can allow users to switch easily among multiple IME subtypes by providing
-a switching key, such as the globe-shaped language icon, as part of the keyboard. Doing so greatly
-improves the keyboard's usability, and can help avoid user frustration.
+<p>You can allow users to switch easily among multiple IME subtypes by providing a switching key,
+such as the globe-shaped language icon, as part of the keyboard. Doing so greatly improves the
+keyboard's usability, and can help avoid user frustration.
 To enable such switching, perform the following steps:</p>
 <p>
 <ol>
-    <li>Declare <code>supportsSwitchingToNextInputMethod = "true"</code> in the
-input method's XML resource files. Your declaration
-    should look similar to the following snippet:
+    <li>Declare <code>supportsSwitchingToNextInputMethod = "true"</code> in the input method's XML
+    resource files. Your declaration should look similar to the following snippet:
     <pre>
 &lt;input-method xmlns:android="http://schemas.android.com/apk/res/android"
         android:settingsActivity="com.example.softkeyboard.Settings"
@@ -646,8 +558,7 @@
     <strong>Caution:</strong> Prior to Android 5.0 (API level 21),
 {@link android.view.inputmethod.InputMethodManager#switchToNextInputMethod switchToNextInputMethod()}
 is not aware of the <code>supportsSwitchingToNextInputMethod</code> attribute. If the user switches
-into an IME without a switching key, he or she may get stuck in that IME, unable to switch out of it
-easily.</p>
+into an IME without a switching key, he or she may get stuck in that IME, unable to switch out of it easily.</p>
 
 <p>
 
@@ -662,31 +573,23 @@
     Provide a way for users to set options directly from the IME's UI.
 </li>
 <li>
-    Because multiple IMEs may be installed on the device, provide a way for the
-user to switch to a
+    Because multiple IMEs may be installed on the device, provide a way for the user to switch to a
     different IME directly from the input method UI.
 </li>
 <li>
-    Bring up the IME's UI quickly. Preload or load on demand any large
-resources so that users
-    see the IME as soon as they tap on a text field. Cache resources and views
-for subsequent
+    Bring up the IME's UI quickly. Preload or load on demand any large resources so that users
+    see the IME as soon as they tap on a text field. Cache resources and views for subsequent
     invocations of the input method.
 </li>
 <li>
-    Conversely, you should release large memory allocations soon after the
-input method window is
-    hidden, so that applications can have sufficient memory to run. Consider
-using a delayed message
-    to release resources if the IME is in a hidden state for a few seconds.
+    Conversely, you should release large memory allocations soon after the input method window is
+    hidden, so that applications can have sufficient memory to run. Consider using a delayed
+    message to release resources if the IME is in a hidden state for a few seconds.
 </li>
 <li>
-    Make sure that users can enter as many characters as possible for the
-language or locale
-    associated with the IME. Remember that users may use punctuation in
-passwords or user
-    names, so your IME has to provide many different characters to allow users
-to enter a
+    Make sure that users can enter as many characters as possible for the language or locale
+    associated with the IME. Remember that users may use punctuation in passwords or user
+    names, so your IME has to provide many different characters to allow users to enter a
     password and get access to the device.
 </li>
 </ul>
\ No newline at end of file
diff --git a/tools/layoutlib/bridge/src/android/animation/AnimatorInflater_Delegate.java b/tools/layoutlib/bridge/src/android/animation/AnimatorInflater_Delegate.java
new file mode 100644
index 0000000..d8a6ffc
--- /dev/null
+++ b/tools/layoutlib/bridge/src/android/animation/AnimatorInflater_Delegate.java
@@ -0,0 +1,59 @@
+/*
+ * Copyright (C) 2014 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.animation;
+
+import com.android.tools.layoutlib.annotations.LayoutlibDelegate;
+
+import android.content.Context;
+import android.content.res.Resources;
+import android.content.res.Resources.NotFoundException;
+import android.content.res.Resources.Theme;
+import android.util.AttributeSet;
+
+/**
+ * Delegate providing alternate implementation to static methods in {@link AnimatorInflater}.
+ */
+public class AnimatorInflater_Delegate {
+
+    @LayoutlibDelegate
+    /*package*/ static Animator loadAnimator(Context context, int id)
+            throws NotFoundException {
+        return loadAnimator(context.getResources(), context.getTheme(), id);
+    }
+
+    @LayoutlibDelegate
+    /*package*/ static Animator loadAnimator(Resources resources, Theme theme, int id)
+            throws NotFoundException {
+        return loadAnimator(resources, theme, id, 1);
+    }
+
+    @LayoutlibDelegate
+    /*package*/ static Animator loadAnimator(Resources resources, Theme theme, int id,
+            float pathErrorScale) throws NotFoundException {
+        // This is a temporary fix to http://b.android.com/77865. This skips loading the
+        // animation altogether.
+        // TODO: Remove this override when Path.approximate() is supported.
+        return new FakeAnimator();
+    }
+
+    @LayoutlibDelegate
+    /*package*/ static ValueAnimator loadAnimator(Resources res, Theme theme,
+            AttributeSet attrs, ValueAnimator anim, float pathErrorScale)
+            throws NotFoundException {
+        return anim;
+    }
+}
diff --git a/tools/layoutlib/bridge/src/android/animation/FakeAnimator.java b/tools/layoutlib/bridge/src/android/animation/FakeAnimator.java
new file mode 100644
index 0000000..78aedc5
--- /dev/null
+++ b/tools/layoutlib/bridge/src/android/animation/FakeAnimator.java
@@ -0,0 +1,52 @@
+/*
+ * Copyright (C) 2014 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.animation;
+
+/**
+ * A fake implementation of Animator which doesn't do anything.
+ */
+public class FakeAnimator extends Animator {
+    @Override
+    public long getStartDelay() {
+        return 0;
+    }
+
+    @Override
+    public void setStartDelay(long startDelay) {
+
+    }
+
+    @Override
+    public Animator setDuration(long duration) {
+        return this;
+    }
+
+    @Override
+    public long getDuration() {
+        return 0;
+    }
+
+    @Override
+    public void setInterpolator(TimeInterpolator value) {
+
+    }
+
+    @Override
+    public boolean isRunning() {
+        return false;
+    }
+}
diff --git a/tools/layoutlib/bridge/src/android/content/res/AssetManager_Delegate.java b/tools/layoutlib/bridge/src/android/content/res/AssetManager_Delegate.java
index 914a359..e0d3b8c 100644
--- a/tools/layoutlib/bridge/src/android/content/res/AssetManager_Delegate.java
+++ b/tools/layoutlib/bridge/src/android/content/res/AssetManager_Delegate.java
@@ -38,8 +38,4 @@
         Resources_Theme_Delegate.getDelegateManager().removeJavaReferenceFor(theme);
     }
 
-    @LayoutlibDelegate
-    /*package*/ static void applyThemeStyle(long theme, int styleRes, boolean force) {
-        Resources_Theme_Delegate.getDelegateManager().getDelegate(theme).force = force;
-    }
 }
diff --git a/tools/layoutlib/bridge/src/android/content/res/BridgeResources.java b/tools/layoutlib/bridge/src/android/content/res/BridgeResources.java
index dd573be..66126af 100644
--- a/tools/layoutlib/bridge/src/android/content/res/BridgeResources.java
+++ b/tools/layoutlib/bridge/src/android/content/res/BridgeResources.java
@@ -163,7 +163,7 @@
         Pair<String, ResourceValue> value = getResourceValue(id, mPlatformResourceFlag);
 
         if (value != null) {
-            return ResourceHelper.getDrawable(value.getSecond(), mContext);
+            return ResourceHelper.getDrawable(value.getSecond(), mContext, theme);
         }
 
         // id was not found or not resolved. Throw a NotFoundException.
diff --git a/tools/layoutlib/bridge/src/android/content/res/BridgeTypedArray.java b/tools/layoutlib/bridge/src/android/content/res/BridgeTypedArray.java
index 28a109d..a2bd6d7 100644
--- a/tools/layoutlib/bridge/src/android/content/res/BridgeTypedArray.java
+++ b/tools/layoutlib/bridge/src/android/content/res/BridgeTypedArray.java
@@ -32,6 +32,7 @@
 import org.xmlpull.v1.XmlPullParser;
 import org.xmlpull.v1.XmlPullParserException;
 
+import android.content.res.Resources.Theme;
 import android.graphics.drawable.Drawable;
 import android.util.DisplayMetrics;
 import android.util.TypedValue;
@@ -116,6 +117,13 @@
     }
 
     /**
+     * Set the theme to be used for inflating drawables.
+     */
+    public void setTheme(Theme theme) {
+        mTheme = theme;
+    }
+
+    /**
      * Return the number of values in this array.
      */
     @Override
@@ -663,7 +671,7 @@
         }
 
         ResourceValue value = mResourceData[index];
-        return ResourceHelper.getDrawable(value, mContext);
+        return ResourceHelper.getDrawable(value, mContext, mTheme);
     }
 
 
diff --git a/tools/layoutlib/bridge/src/android/content/res/Resources_Theme_Delegate.java b/tools/layoutlib/bridge/src/android/content/res/Resources_Theme_Delegate.java
index f4a9f52..4bd83e9 100644
--- a/tools/layoutlib/bridge/src/android/content/res/Resources_Theme_Delegate.java
+++ b/tools/layoutlib/bridge/src/android/content/res/Resources_Theme_Delegate.java
@@ -39,9 +39,6 @@
  */
 public class Resources_Theme_Delegate {
 
-    // Whether to use the Theme.mThemeResId as primary theme.
-    boolean force;
-
     // ---- delegate manager ----
 
     private static final DelegateManager<Resources_Theme_Delegate> sManager =
@@ -58,7 +55,8 @@
             Resources thisResources, Theme thisTheme,
             int[] attrs) {
         boolean changed = setupResources(thisTheme);
-        TypedArray ta = RenderSessionImpl.getCurrentContext().obtainStyledAttributes(attrs);
+        BridgeTypedArray ta = RenderSessionImpl.getCurrentContext().obtainStyledAttributes(attrs);
+        ta.setTheme(thisTheme);
         restoreResources(changed);
         return ta;
     }
@@ -69,7 +67,9 @@
             int resid, int[] attrs)
             throws NotFoundException {
         boolean changed = setupResources(thisTheme);
-        TypedArray ta = RenderSessionImpl.getCurrentContext().obtainStyledAttributes(resid, attrs);
+        BridgeTypedArray ta = RenderSessionImpl.getCurrentContext().obtainStyledAttributes(resid,
+                attrs);
+        ta.setTheme(thisTheme);
         restoreResources(changed);
         return ta;
     }
@@ -79,8 +79,9 @@
             Resources thisResources, Theme thisTheme,
             AttributeSet set, int[] attrs, int defStyleAttr, int defStyleRes) {
         boolean changed = setupResources(thisTheme);
-        TypedArray ta = RenderSessionImpl.getCurrentContext().obtainStyledAttributes(set, attrs,
-                defStyleAttr, defStyleRes);
+        BridgeTypedArray ta = RenderSessionImpl.getCurrentContext().obtainStyledAttributes(set,
+                attrs, defStyleAttr, defStyleRes);
+        ta.setTheme(thisTheme);
         restoreResources(changed);
         return ta;
     }
@@ -91,8 +92,8 @@
             int resid, TypedValue outValue,
             boolean resolveRefs) {
         boolean changed = setupResources(thisTheme);
-        boolean found =  RenderSessionImpl.getCurrentContext().resolveThemeAttribute(
-                resid, outValue, resolveRefs);
+        boolean found =  RenderSessionImpl.getCurrentContext().resolveThemeAttribute(resid,
+                outValue, resolveRefs);
         restoreResources(changed);
         return found;
     }
@@ -107,14 +108,29 @@
     // ---- private helper methods ----
 
     private static boolean setupResources(Theme thisTheme) {
-        Resources_Theme_Delegate themeDelegate = sManager.getDelegate(thisTheme.getNativeTheme());
-        StyleResourceValue style = resolveStyle(thisTheme.getAppliedStyleResId());
-        if (style != null) {
-            RenderSessionImpl.getCurrentContext().getRenderResources()
-                    .applyStyle(style, themeDelegate.force);
-            return true;
+        // Key is a space-separated list of theme ids applied that have been merged into the
+        // BridgeContext's theme to make thisTheme.
+        String[] appliedStyles = thisTheme.getKey().split(" ");
+        boolean changed = false;
+        for (String s : appliedStyles) {
+            if (s.isEmpty()) {
+                continue;
+            }
+            // See the definition of force parameter in Theme.applyStyle().
+            boolean force = false;
+            if (s.charAt(s.length() - 1) == '!') {
+                force = true;
+                s = s.substring(0, s.length() - 1);
+            }
+            int styleId = Integer.parseInt(s, 16);
+            StyleResourceValue style = resolveStyle(styleId);
+            if (style != null) {
+                RenderSessionImpl.getCurrentContext().getRenderResources().applyStyle(style, force);
+                changed = true;
+            }
+
         }
-        return false;
+        return changed;
     }
 
     private static void restoreResources(boolean changed) {
diff --git a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeContext.java b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeContext.java
index 04a52ea..d804230 100644
--- a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeContext.java
+++ b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeContext.java
@@ -115,7 +115,7 @@
     private int mDynamicIdGenerator = 0x02030000; // Base id for R.style in custom namespace
 
     // cache for TypedArray generated from IStyleResourceValue object
-    private Map<int[], Map<Integer, TypedArray>> mTypedArrayCache;
+    private Map<int[], Map<Integer, BridgeTypedArray>> mTypedArrayCache;
     private BridgeInflater mBridgeInflater;
 
     private BridgeContentResolver mContentResolver;
@@ -467,7 +467,7 @@
 
 
     @Override
-    public final TypedArray obtainStyledAttributes(int[] attrs) {
+    public final BridgeTypedArray obtainStyledAttributes(int[] attrs) {
         // No style is specified here, so create the typed array based on the default theme
         // and the styles already applied to it. A null value of style indicates that the default
         // theme should be used.
@@ -475,7 +475,7 @@
     }
 
     @Override
-    public final TypedArray obtainStyledAttributes(int resid, int[] attrs)
+    public final BridgeTypedArray obtainStyledAttributes(int resid, int[] attrs)
             throws Resources.NotFoundException {
         // get the StyleResourceValue based on the resId;
         StyleResourceValue style = getStyleByDynamicId(resid);
@@ -485,9 +485,9 @@
         }
 
         if (mTypedArrayCache == null) {
-            mTypedArrayCache = new HashMap<int[], Map<Integer,TypedArray>>();
+            mTypedArrayCache = new HashMap<int[], Map<Integer,BridgeTypedArray>>();
 
-            Map<Integer, TypedArray> map = new HashMap<Integer, TypedArray>();
+            Map<Integer, BridgeTypedArray> map = new HashMap<Integer, BridgeTypedArray>();
             mTypedArrayCache.put(attrs, map);
 
             BridgeTypedArray ta = createStyleBasedTypedArray(style, attrs);
@@ -497,14 +497,14 @@
         }
 
         // get the 2nd map
-        Map<Integer, TypedArray> map = mTypedArrayCache.get(attrs);
+        Map<Integer, BridgeTypedArray> map = mTypedArrayCache.get(attrs);
         if (map == null) {
-            map = new HashMap<Integer, TypedArray>();
+            map = new HashMap<Integer, BridgeTypedArray>();
             mTypedArrayCache.put(attrs, map);
         }
 
         // get the array from the 2nd map
-        TypedArray ta = map.get(resid);
+        BridgeTypedArray ta = map.get(resid);
 
         if (ta == null) {
             ta = createStyleBasedTypedArray(style, attrs);
@@ -515,12 +515,12 @@
     }
 
     @Override
-    public final TypedArray obtainStyledAttributes(AttributeSet set, int[] attrs) {
+    public final BridgeTypedArray obtainStyledAttributes(AttributeSet set, int[] attrs) {
         return obtainStyledAttributes(set, attrs, 0, 0);
     }
 
     @Override
-    public TypedArray obtainStyledAttributes(AttributeSet set, int[] attrs,
+    public BridgeTypedArray obtainStyledAttributes(AttributeSet set, int[] attrs,
             int defStyleAttr, int defStyleRes) {
 
         Map<String, String> defaultPropMap = null;
diff --git a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/ResourceHelper.java b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/ResourceHelper.java
index 22f8e1c..677c744 100644
--- a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/ResourceHelper.java
+++ b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/ResourceHelper.java
@@ -32,6 +32,7 @@
 import org.xmlpull.v1.XmlPullParserException;
 
 import android.content.res.ColorStateList;
+import android.content.res.Resources.Theme;
 import android.graphics.Bitmap;
 import android.graphics.Bitmap_Delegate;
 import android.graphics.NinePatch_Delegate;
@@ -166,6 +167,17 @@
      * @param context the current context
      */
     public static Drawable getDrawable(ResourceValue value, BridgeContext context) {
+        return getDrawable(value, context, null);
+    }
+
+    /**
+     * Returns a drawable from the given value.
+     * @param value The value that contains a path to a 9 patch, a bitmap or a xml based drawable,
+     * or an hexadecimal color
+     * @param context the current context
+     * @param theme the theme to be used to inflate the drawable.
+     */
+    public static Drawable getDrawable(ResourceValue value, BridgeContext context, Theme theme) {
         if (value == null) {
             return null;
         }
@@ -209,7 +221,7 @@
                     BridgeXmlBlockParser blockParser = new BridgeXmlBlockParser(
                             parser, context, value.isFramework());
                     try {
-                        return Drawable.createFromXml(context.getResources(), blockParser);
+                        return Drawable.createFromXml(context.getResources(), blockParser, theme);
                     } finally {
                         blockParser.ensurePopped();
                     }
diff --git a/tools/layoutlib/create/src/com/android/tools/layoutlib/create/CreateInfo.java b/tools/layoutlib/create/src/com/android/tools/layoutlib/create/CreateInfo.java
index f20b890..2fcdf34 100644
--- a/tools/layoutlib/create/src/com/android/tools/layoutlib/create/CreateInfo.java
+++ b/tools/layoutlib/create/src/com/android/tools/layoutlib/create/CreateInfo.java
@@ -137,13 +137,13 @@
      * The list of methods to rewrite as delegates.
      */
     public final static String[] DELEGATE_METHODS = new String[] {
+        "android.animation.AnimatorInflater#loadAnimator",  // TODO: remove when Path.approximate() is supported.
         "android.app.Fragment#instantiate", //(Landroid/content/Context;Ljava/lang/String;Landroid/os/Bundle;)Landroid/app/Fragment;",
         "android.content.res.Resources$Theme#obtainStyledAttributes",
         "android.content.res.Resources$Theme#resolveAttribute",
         "android.content.res.Resources$Theme#resolveAttributes",
         "android.content.res.AssetManager#newTheme",
         "android.content.res.AssetManager#deleteTheme",
-        "android.content.res.AssetManager#applyThemeStyle",
         "android.content.res.TypedArray#getValueAt",
         "android.content.res.TypedArray#obtain",
         "android.graphics.BitmapFactory#finishDecode",