diff options
Diffstat (limited to 'docs/html')
30 files changed, 221 insertions, 50 deletions
diff --git a/docs/html/google/auth/api-client.jd b/docs/html/google/auth/api-client.jd index fda3310..402a95f 100644 --- a/docs/html/google/auth/api-client.jd +++ b/docs/html/google/auth/api-client.jd @@ -112,7 +112,7 @@ GoogleApiClient}</a>, you must specify an implementation for the callback interf href="{@docRoot}reference/com/google/android/gms/common/api/GoogleApiClient.ConnectionCallbacks.html" >{@code ConnectionCallbacks}</a> and <a href="{@docRoot}reference/com/google/android/gms/common/api/GoogleApiClient.OnConnectionFailedListener.html" ->{@code onConnectionFailedListener}</a>. These interfaces receive callbacks in +>{@code OnConnectionFailedListener}</a>. These interfaces receive callbacks in response to the asynchronous <a href="{@docRoot}reference/com/google/android/gms/common/api/GoogleApiClient.html#connect()" >{@code connect()}</a> method when the connection to Google Play services @@ -512,7 +512,7 @@ private void loadFile(String filename) { new GetFileTask().execute(filename); } -private class GetFileTask extends AsyncTask<String, Void, Void> { +private class GetFileTask extends AsyncTask<String, Void, Void> { protected void doInBackground(String filename) { Query query = new Query.Builder() .addFilter(Filters.eq(SearchableField.TITLE, filename)) diff --git a/docs/html/guide/topics/ui/controls/button.jd b/docs/html/guide/topics/ui/controls/button.jd index 41b67b7..cb274ae 100644 --- a/docs/html/guide/topics/ui/controls/button.jd +++ b/docs/html/guide/topics/ui/controls/button.jd @@ -113,7 +113,7 @@ android.view.View} that was clicked)</li> <h3 id="ClickListener">Using an OnClickListener</h3> -<p>You can also declare the click event handler pragmatically rather than in an XML layout. This +<p>You can also declare the click event handler programmatically rather than in an XML layout. This might be necessary if you instantiate the {@link android.widget.Button} at runtime or you need to declare the click behavior in a {@link android.app.Fragment} subclass.</p> diff --git a/docs/html/guide/topics/ui/controls/togglebutton.jd b/docs/html/guide/topics/ui/controls/togglebutton.jd index 3119cd9..5e2a551 100644 --- a/docs/html/guide/topics/ui/controls/togglebutton.jd +++ b/docs/html/guide/topics/ui/controls/togglebutton.jd @@ -99,7 +99,7 @@ android.widget.CompoundButton#toggle()} method to change the state.</p> <h3 id="ClickListener">Using an OnCheckedChangeListener</h3> -<p>You can also declare a click event handler pragmatically rather than in an XML layout. This +<p>You can also declare a click event handler programmatically rather than in an XML layout. This might be necessary if you instantiate the {@link android.widget.ToggleButton} or {@link android.widget.Switch} at runtime or you need to declare the click behavior in a {@link android.app.Fragment} subclass.</p> diff --git a/docs/html/images/screens_support/avds-config.png b/docs/html/images/screens_support/avds-config.png Binary files differindex 97bd5f6..e609447 100644 --- a/docs/html/images/screens_support/avds-config.png +++ b/docs/html/images/screens_support/avds-config.png diff --git a/docs/html/images/tools/as-camera-icon.png b/docs/html/images/tools/as-camera-icon.png Binary files differnew file mode 100644 index 0000000..419a88d --- /dev/null +++ b/docs/html/images/tools/as-camera-icon.png diff --git a/docs/html/images/tools/as-error.png b/docs/html/images/tools/as-error.png Binary files differnew file mode 100644 index 0000000..8865f54 --- /dev/null +++ b/docs/html/images/tools/as-error.png diff --git a/docs/html/images/tools/as-fr-device.png b/docs/html/images/tools/as-fr-device.png Binary files differnew file mode 100644 index 0000000..aec3bce --- /dev/null +++ b/docs/html/images/tools/as-fr-device.png diff --git a/docs/html/images/tools/as-fr-icon.png b/docs/html/images/tools/as-fr-icon.png Binary files differnew file mode 100644 index 0000000..9252ca1 --- /dev/null +++ b/docs/html/images/tools/as-fr-icon.png diff --git a/docs/html/images/tools/as-frag-ex.png b/docs/html/images/tools/as-frag-ex.png Binary files differnew file mode 100644 index 0000000..775fa5e --- /dev/null +++ b/docs/html/images/tools/as-frag-ex.png diff --git a/docs/html/images/tools/as-grid-layout.png b/docs/html/images/tools/as-grid-layout.png Binary files differnew file mode 100644 index 0000000..41b933a --- /dev/null +++ b/docs/html/images/tools/as-grid-layout.png diff --git a/docs/html/images/tools/as-i18n-icon.png b/docs/html/images/tools/as-i18n-icon.png Binary files differnew file mode 100644 index 0000000..d35568f --- /dev/null +++ b/docs/html/images/tools/as-i18n-icon.png diff --git a/docs/html/images/tools/as-preview-chrome.png b/docs/html/images/tools/as-preview-chrome.png Binary files differnew file mode 100644 index 0000000..716b8d7 --- /dev/null +++ b/docs/html/images/tools/as-preview-chrome.png diff --git a/docs/html/images/tools/as-preview-icon.png b/docs/html/images/tools/as-preview-icon.png Binary files differnew file mode 100644 index 0000000..59c7644 --- /dev/null +++ b/docs/html/images/tools/as-preview-icon.png diff --git a/docs/html/images/tools/as-preview-nochrome.png b/docs/html/images/tools/as-preview-nochrome.png Binary files differnew file mode 100644 index 0000000..1011e08 --- /dev/null +++ b/docs/html/images/tools/as-preview-nochrome.png diff --git a/docs/html/images/tools/as-theme-db.png b/docs/html/images/tools/as-theme-db.png Binary files differnew file mode 100644 index 0000000..beade0d --- /dev/null +++ b/docs/html/images/tools/as-theme-db.png diff --git a/docs/html/images/tools/as-theme-icon.png b/docs/html/images/tools/as-theme-icon.png Binary files differnew file mode 100644 index 0000000..0e5fdf0 --- /dev/null +++ b/docs/html/images/tools/as-theme-icon.png diff --git a/docs/html/images/training/firstapp/adt-firstapp-setup.png b/docs/html/images/training/firstapp/adt-firstapp-setup.png Binary files differindex bf95285..05e147d 100644 --- a/docs/html/images/training/firstapp/adt-firstapp-setup.png +++ b/docs/html/images/training/firstapp/adt-firstapp-setup.png diff --git a/docs/html/images/training/firstapp/adt-new-activity.png b/docs/html/images/training/firstapp/adt-new-activity.png Binary files differindex c396793..2c32dcc 100644 --- a/docs/html/images/training/firstapp/adt-new-activity.png +++ b/docs/html/images/training/firstapp/adt-new-activity.png diff --git a/docs/html/images/training/firstapp/edittext_gravity.png b/docs/html/images/training/firstapp/edittext_gravity.png Binary files differindex f78e676..bc4f7ee 100644 --- a/docs/html/images/training/firstapp/edittext_gravity.png +++ b/docs/html/images/training/firstapp/edittext_gravity.png diff --git a/docs/html/images/training/firstapp/edittext_wrap.png b/docs/html/images/training/firstapp/edittext_wrap.png Binary files differindex 156776d..fe56731 100644 --- a/docs/html/images/training/firstapp/edittext_wrap.png +++ b/docs/html/images/training/firstapp/edittext_wrap.png diff --git a/docs/html/images/training/firstapp/firstapp.png b/docs/html/images/training/firstapp/firstapp.png Binary files differindex d69cd20..581e000 100644 --- a/docs/html/images/training/firstapp/firstapp.png +++ b/docs/html/images/training/firstapp/firstapp.png diff --git a/docs/html/index.jd b/docs/html/index.jd index 5d1788a..e901652 100644 --- a/docs/html/index.jd +++ b/docs/html/index.jd @@ -22,12 +22,13 @@ page.customHeadTag=<meta name="google-site-verification" content="sa-bIAI6GKvct3 <script src="//ajax.googleapis.com/ajax/libs/swfobject/2.2/swfobject.js"></script> <div style="box-shadow: 3px 10px 18px 1px #999;width:600px;height:336px"> <div id="ytapiplayer"> - <a href="http://www.youtube.com/watch?v=WWArLD6nqrk"><img width=600 src="{@docRoot}images/video-kiwi.jpg"></a><!--You need Flash player 8+ and JavaScript enabled to view this video. --> + <a href="http://www.youtube.com/watch?v=i2uvYI6blEE"><img width=600 + src="https://i1.ytimg.com/vi/i2uvYI6blEE/maxresdefault.jpg"></a><!--You need Flash player 8+ and JavaScript enabled to view this video. --> </div> <script type="text/javascript"> var params = { allowScriptAccess: "always" }; var atts = { id: "ytapiplayer" }; - swfobject.embedSWF("//www.youtube.com/v/WWArLD6nqrk?enablejsapi=1&playerapiid=ytplayer&version=3&HD=1;rel=0;showinfo=0;modestbranding;origin=developer.android.com;autohide=1", + swfobject.embedSWF("//www.youtube.com/v/i2uvYI6blEE?enablejsapi=1&playerapiid=ytplayer&version=3&HD=1;rel=0;showinfo=0;modestbranding;origin=developer.android.com;autohide=1", "ytapiplayer", "600", "336", "8", null, null, params, atts); // Callback used to pause/resume carousel based on video state @@ -56,9 +57,8 @@ page.customHeadTag=<meta name="google-site-verification" content="sa-bIAI6GKvct3 </div> </div> <div class="content-right col-4"> - <h1 style="white-space:nowrap;line-height:1.2em;">Developer Story: <br />Kiwi, Inc.</h1> - <p>Game developer Kiwi has had five titles in the top 25 grossing on Google Play. Hear how Google Play - has helped them double revenue every six months.</p> + <h1 style="white-space:nowrap;line-height:1.2em;">Developer Story: <br />Box Inc.</h1> + <p>Box is a cloud-based platform and app for users to share business information. See how they got over 5 million downloads by leveraging the flexibility in the Android platform.</p> <p><a href="{@docRoot}distribute/googleplay/spotlight/index.html" class="button">Watch more videos </a></p> </div> </li> diff --git a/docs/html/sdk/installing/studio-layout.jd b/docs/html/sdk/installing/studio-layout.jd new file mode 100644 index 0000000..f0e5d59 --- /dev/null +++ b/docs/html/sdk/installing/studio-layout.jd @@ -0,0 +1,148 @@ +page.title=Using the Layout Editor + +@jd:body + +<div id="qv-wrapper"> +<div id="qv"> +<h2>See also</h2> +<ul> +<li><a href="{@docRoot}sdk/installing/studio.html"> +Getting Started with Android Studio</a></li> +<li><a href="{@docRoot}sdk/installing/studio-tips.html"> +Android Studio Tips and Tricks</a></li> +<li><a href="{@docRoot}sdk/installing/migrate.html"> +Migrating from Eclipse</a></li> +</div> +</div> + +<a class="notice-developers-video" +href="https://developers.google.com/events/io/sessions/324603352"> +<div> + <h3>Video</h3> + <p>What's New in Android Developer Tools</p> +</div> +</a> + +<p>Android Studio offers an advanced layout editor that allows you to drag-and-drop widgets +into your layout and preview your layout while editing the XML.</p> + +<p>Within the layout editor, you can switch between the <strong>Text</strong> view, where +you edit the XML file as text, and the <strong>Design</strong> view. Just click the +appropriate tab at the bottom of the window to display the desired editor.</p> + +<h2>Editing in the Text View</h2> + +<p>You can use the <strong>Text</strong> view to edit your layout file. This section describes +some of the features that are available in the <strong>Text</strong> view.</p> + +<h3>Preview</h3> + +<p>While editing in the <strong>Text</strong> view, you can preview the layout on devices +by opening the <strong>Preview</strong> pane available on the right side of the window. +Within the <strong>Preview</strong> pane, you can modify the preview by changing various +options at the top of the pane, including the preview device, layout theme, platform +version and more. To see a preview of how your app would look with a particular device +skin, click the preview icon +<img src="{@docRoot}images/tools/as-preview-icon.png" style="vertical-align:bottom;margin:0;height:19px" /> +and choose the desired device, such as Nexus 4:</p> + +<img src="{@docRoot}images/tools/as-preview-chrome.png" alt="" /> +<p class="img-caption"><strong>Figure 1.</strong> Previewing your app.</p> + +<p>To preview the layout on multiple devices simultaneously, select <strong>Preview All +Screen Sizes</strong> from the device drop-down. </p> + +<p>When you click in the preview image, the layout editor highlights the corresponding +section in the XML, and vice-versa.</p> + +<h3>Interactive error detection and recovery</h3> + +<p>As you edit the <strong>Text</strong> view of your layout XML file, Android Studio flags +typos and offers assistance.</p> + +<p>For example, suppose you are adding a button, and you misspell it as "Buttonn". +Android Studio helps you to correct it by displaying an error such as the following, +where you can click on "Change to Button" to fix the error in the XML file:</p> + +<img src="{@docRoot}images/tools/as-error.png" alt="" /> + +<p class="img-caption"><strong>Figure 2.</strong> Flagging errors.</p> + +<p>Android Studio also prompts you to supply missing information. For example, suppose you +start adding a fragment to your layout XML file. First of all, Android Studio displays +auto-complete suggestions as you type. Once it becomes clear that you are adding a fragment, +Android Studio displays an error panel with links that you can click to supply the missing +attributes. Clicking "Automatically add all missing attributes" in this case +does just that—it completes the fragment definition in your layout XML file:</p> + +<img src="{@docRoot}images/tools/as-frag-ex.png" alt="" /> + +<p class="img-caption"><strong>Figure 3.</strong> Supplying missing information</p> + +<h3>Picking a theme</h3> + +<p>To pick a theme for your app, click the Theme icon +<img src="{@docRoot}images/tools/as-theme-icon.png" style="vertical-align:bottom;margin:0;height:19px" />. +</p> + +<p>This displays the <strong>Select Theme</strong> dialog, where you can search for a +particular theme and/or select one from the list on the right hand side. The theme you +choose will be reflected in the previewed image.</p> + +<img src="{@docRoot}images/tools/as-theme-db.png" alt="" /> + +<p class="img-caption"><strong>Figure 4.</strong> Specifying a theme.</p> + +<h3>Localization</h3> + +<p>Android Studio provides built-in localization support. When you click the +localization icon +<img src="{@docRoot}images/tools/as-i18n-icon.png" style="vertical-align:bottom;margin:0;height:19px" />, +you can select a particular locale, add and edit translations, preview the locales your +app supports (all locales or just a single locale), and preview right-to-left layout for +languages that are RTL.</p> + +<p>See <a href="{@docRoot}training/basics/supporting-devices/languages.html">Supporting +Different Languages</a> for a description of how to support different locales in your app.</p> +<p>For example, here is a preview of a "Hello World" app for the +<img src="{@docRoot}images/tools/as-fr-icon.png" style="vertical-align:bottom;margin:0;height:19px" /> +locale:</p> + +<img src="{@docRoot}images/tools/as-fr-device.png" alt="" /> +<p class="img-caption"><strong>Figure 5.</strong> Previewing locales.</p> + +<h2>Editing in the Design View</h2> + +<p>You can switch to the graphical editor by clicking <strong>Design</strong> at the +bottom of the window. While editing in the <strong>Design</strong> view, you can show and +hide the widgets available to drag-and-drop by clicking <strong>Palette</strong> on the +left side of the window. Clicking <strong>Designer</strong> on the right side of the +window reveals a panel with a layout hierarchy and a list of properties for each view in +the layout.</p> + +<p>When you drag a widget into the graphical layout for your app, the display changes to +help you place the widget. What you see depends on the type of layout. For example, if +you're dragging a widget into a {@link android.widget.FrameLayout}, it displays a grid to +help you place the widget, as shown in figure 6:</p> + +<img src="{@docRoot}images/tools/as-grid-layout.png" alt="" /> + +<p class="img-caption"><strong>Figure 6.</strong> Using the grid layout to place a widget.</p> + +<p>Within the graphical editor, you can rearrange your app's UI by dragging widgets to +the desired location.</p> + +<h3>Taking a snapshot</h3> + +<p>When you run your app on a connected device, you can take a snapshot of it by clicking +the camera icon +<img src="{@docRoot}images/tools/as-camera-icon.png" style="vertical-align:bottom;margin:0;height:19px" /> +to the left of the logging +panel (at the bottom of the window by default). This takes a snapshot of your running app +(or whatever is currently displayed on your device) and displays it in a window. Check +<strong>Frame Screenshot</strong> to show your screenshot within the device skin of your +choice. You can also specify whether you want the image to have screen glare and/or a drop +shadow. Once you have the desired effect, you can save the image.</p> + +<p>You can use the same process to create a snapshot of your app's preview. Just click the +camera icon in the preview area and follow the steps for adding a device skin.</p> diff --git a/docs/html/sdk/installing/studio.jd b/docs/html/sdk/installing/studio.jd index ceaa70a..1850b44 100644 --- a/docs/html/sdk/installing/studio.jd +++ b/docs/html/sdk/installing/studio.jd @@ -318,6 +318,12 @@ information about how to resolve them.</p> <h2 id="Installing">Installing Android Studio</h2> +<p>Android Studio requires JDK 6 or greater (JRE alone is not sufficient). To check if you +have JDK installed (and which version), open a terminal and type <code>javac -version</code>. +If JDK is not available or the version is lower than 6, +<a href="http://www.oracle.com/technetwork/java/javase/downloads/index.html">download +JDK from here</a>.</p> +<p>To install Android Studio:</p> <ol> <li>Download the <strong>Android Studio</strong> package from above.</li> <li>Install Android Studio and the SDK tools: diff --git a/docs/html/tools/help/logcat.jd b/docs/html/tools/help/logcat.jd index ede1905..b30971e 100644 --- a/docs/html/tools/help/logcat.jd +++ b/docs/html/tools/help/logcat.jd @@ -45,7 +45,7 @@ $ adb shell <tr> <td><code>-b <buffer></code></td> - <td>Loads an alternate log buffer for viewing, such as <code>event</code> or + <td>Loads an alternate log buffer for viewing, such as <code>events</code> or <code>radio</code>. The <code>main</code> buffer is used by default. See <a href= "{@docRoot}tools/debugging/debugging-log.html#alternativeBuffers">Viewing Alternative Log Buffers</a>.</td> </tr> diff --git a/docs/html/tools/tools_toc.cs b/docs/html/tools/tools_toc.cs index a8424e6..382165c 100644 --- a/docs/html/tools/tools_toc.cs +++ b/docs/html/tools/tools_toc.cs @@ -34,7 +34,9 @@ Migrating from Eclipse</a></li> <li><a href="<?cs var:toroot ?>sdk/installing/studio-tips.html"> Tips and Tricks</a></li> - </ul> + <li><a href="<?cs var:toroot ?>sdk/installing/studio-layout.html"> + Using the Layout Editor</a></li> + </ul> </li> <li><a href="<?cs var:toroot ?>sdk/exploring.html"> <span class="en">Exploring the SDK</span></a></li> diff --git a/docs/html/training/basics/firstapp/building-ui.jd b/docs/html/training/basics/firstapp/building-ui.jd index 2615bee..179b3ac 100644 --- a/docs/html/training/basics/firstapp/building-ui.jd +++ b/docs/html/training/basics/firstapp/building-ui.jd @@ -75,16 +75,16 @@ content of the text field to another activity.</p> <h2 id="LinearLayout">Create a Linear Layout</h2> -<p>Open the <code>activity_main.xml</code> file from the <code>res/layout/</code> +<p>Open the <code>fragment_main.xml</code> file from the <code>res/layout/</code> directory.</p> <p class="note"><strong>Note:</strong> In Eclipse, when you open a layout file, you’re first shown the Graphical Layout editor. This is an editor that helps you build layouts using WYSIWYG tools. For this -lesson, you’re going to work directly with the XML, so click the <em>activity_main.xml</em> tab at +lesson, you’re going to work directly with the XML, so click the <em>fragment_main.xml</em> tab at the bottom of the screen to open the XML editor.</p> <p>The BlankActivity template you chose when you created this project includes the -<code>activity_main.xml</code> file with a {@link +<code>fragment_main.xml</code> file with a {@link android.widget.RelativeLayout} root view and a {@link android.widget.TextView} child view.</p> <p>First, delete the {@link android.widget.TextView <TextView>} element and change the {@link @@ -95,7 +95,6 @@ android:orientation}</a> attribute and set it to <code>"horizontal"</code>. The result looks like this:</p> <pre> -<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" diff --git a/docs/html/training/basics/firstapp/creating-project.jd b/docs/html/training/basics/firstapp/creating-project.jd index 9516e37..50485db 100644 --- a/docs/html/training/basics/firstapp/creating-project.jd +++ b/docs/html/training/basics/firstapp/creating-project.jd @@ -120,8 +120,8 @@ devices.</li> <strong>Finish</strong>.</li> </ol> -<p>Your Android project is now set up with some default files and you’re ready to begin -building the app. Continue to the <a href="running-app.html">next lesson</a>.</p> +<p>Your Android project is now a basic "Hello World" app that contains some default files. +To run the app, continue to the <a href="running-app.html">next lesson</a>.</p> @@ -155,8 +155,8 @@ and replace projects.</p></li> </ol> -<p>Your Android project is now set up with several default configurations and you’re ready to begin -building the app. Continue to the <a href="running-app.html">next lesson</a>.</p> +<p>Your Android project is now a basic "Hello World" app that contains some default files. +To run the app, continue to the <a href="running-app.html">next lesson</a>.</p> <p class="note"><strong>Tip:</strong> Add the <code>platform-tools/</code> as well as the <code>tools/</code> directory to your <code>PATH</code> environment variable.</p> diff --git a/docs/html/training/basics/firstapp/running-app.jd b/docs/html/training/basics/firstapp/running-app.jd index 999d399..23cedba 100644 --- a/docs/html/training/basics/firstapp/running-app.jd +++ b/docs/html/training/basics/firstapp/running-app.jd @@ -62,7 +62,7 @@ href="{@docRoot}guide/topics/manifest/uses-sdk-element.html#target">{@code andro attributes. For your first app, it should look like this:</p> <pre> <manifest xmlns:android="http://schemas.android.com/apk/res/android" ... > - <uses-sdk android:minSdkVersion="8" android:targetSdkVersion="17" /> + <uses-sdk android:minSdkVersion="8" android:targetSdkVersion="19" /> ... </manifest> </pre> diff --git a/docs/html/training/basics/firstapp/starting-activity.jd b/docs/html/training/basics/firstapp/starting-activity.jd index 712eabc..9aa25a3 100644 --- a/docs/html/training/basics/firstapp/starting-activity.jd +++ b/docs/html/training/basics/firstapp/starting-activity.jd @@ -45,7 +45,7 @@ starts a new activity when the user clicks the Send button.</p> <h2 id="RespondToButton">Respond to the Send Button</h2> -<p>To respond to the button's on-click event, open the <code>activity_main.xml</code> +<p>To respond to the button's on-click event, open the <code>fragment_main.xml</code> layout file and add the <a href="{@docRoot}reference/android/view/View.html#attr_android:onClick">{@code android:onClick}</a> attribute to the {@link android.widget.Button <Button>} element:</p> @@ -73,14 +73,6 @@ public void sendMessage(View view) { } </pre> -<p>This requires that you import the {@link android.view.View} class:</p> -<pre> -import android.view.View; -</pre> - -<p class="note"><strong>Tip:</strong> In Eclipse, press Ctrl + Shift + O to import missing classes -(Cmd + Shift + O on Mac).</p> - <p>In order for the system to match this method to the method name given to <a href="{@docRoot}reference/android/view/View.html#attr_android:onClick">{@code android:onClick}</a>, the signature must be exactly as shown. Specifically, the method must:</p> @@ -111,6 +103,14 @@ an activity called {@code DisplayMessageActivity}:</p> Intent intent = new Intent(this, DisplayMessageActivity.class); </pre> +<p>This requires that you import the {@link android.content.Intent} class:</p> +<pre> +import android.content.Intent; +</pre> + +<p class="note"><strong>Tip:</strong> In Eclipse, press Ctrl + Shift + O to import missing classes +(Cmd + Shift + O on Mac).</p> + <p>The constructor used here takes two parameters:</p> <ul> <li>A {@link @@ -151,9 +151,8 @@ intent.putExtra(EXTRA_MESSAGE, message); </pre> <p class="note"><strong>Note:</strong> -You now need import statements for <code>android.content.Intent</code> -and <code>android.widget.EditText</code>. You'll define the <code>EXTRA_MESSAGE</code> -constant in a moment.</p> +You now need an import statement for <code>android.widget.EditText</code>. +You'll define the <code>EXTRA_MESSAGE</code> constant in a moment.</p> <p>An {@link android.content.Intent} can carry a collection of various data types as key-value pairs called <em>extras</em>. The {@link android.content.Intent#putExtra putExtra()} method takes the @@ -165,7 +164,7 @@ public constant. So add the {@code EXTRA_MESSAGE} definition to the top of the { MainActivity} class:</p> <pre> -public class MainActivity extends Activity { +public class MainActivity extends ActionBarActivity { public final static String EXTRA_MESSAGE = "com.example.myfirstapp.MESSAGE"; ... } @@ -223,6 +222,7 @@ work.</p> <li><strong>Project</strong>: MyFirstApp</li> <li><strong>Activity Name</strong>: DisplayMessageActivity</li> <li><strong>Layout Name</strong>: activity_display_message</li> + <li><strong>Fragment Layout Name</strong>: fragment_display_message</li> <li><strong>Title</strong>: My Message</li> <li><strong>Hierarchial Parent</strong>: com.example.myfirstapp.MainActivity</li> <li><strong>Navigation Type</strong>: None</li> @@ -240,49 +240,65 @@ activity:</p> <ul> <li>The class already includes an implementation of the required {@link android.app.Activity#onCreate onCreate()} -method.</li> +method. You will update the implementation of this method later.</li> <li>There's also an implementation of the {@link android.app.Activity#onCreateOptionsMenu onCreateOptionsMenu()} method, but you won't need it for this app so you can remove it.</li> <li>There's also an implementation of {@link android.app.Activity#onOptionsItemSelected onOptionsItemSelected()} which handles the behavior for the action bar's <em>Up</em> behavior. Keep this one the way it is.</li> + <li>There's also a <code>PlaceholderFragment</code> class that extends +{@link android.app.Fragment}. You will not need this class in the final version of this +activity.</li> </ul> -<p>Because the {@link android.app.ActionBar} APIs are available only on {@link -android.os.Build.VERSION_CODES#HONEYCOMB} (API level 11) and higher, you must add a condition -around the {@link android.app.Activity#getActionBar()} method to check the current platform version. -Additionally, you must add the {@code @SuppressLint("NewApi")} tag to the -{@link android.app.Activity#onCreate onCreate()} method to avoid <a -href="{@docRoot}tools/help/lint.html">lint</a> errors.</p> +<p>Fragments decompose application functionality and UI into reusable modules. For more +information on fragments, see the <a href="{@docRoot}guide/components/fragments.html">Fragments +API Guide</a>. The final version of this activity does not use fragments.</p> <p>The {@code DisplayMessageActivity} class should now look like this:</p> <pre> -public class DisplayMessageActivity extends Activity { +public class DisplayMessageActivity extends ActionBarActivity { - @SuppressLint("NewApi") @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_display_message); - // Make sure we're running on Honeycomb or higher to use ActionBar APIs - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { - // Show the Up button in the action bar. - getActionBar().setDisplayHomeAsUpEnabled(true); + if (savedInstanceState == null) { + getSupportFragmentManager().beginTransaction() + .add(R.id.container, new PlaceholderFragment()).commit(); } } @Override public boolean onOptionsItemSelected(MenuItem item) { - switch (item.getItemId()) { - case android.R.id.home: - NavUtils.navigateUpFromSameTask(this); + // Handle action bar item clicks here. The action bar will + // automatically handle clicks on the Home/Up button, so long + // as you specify a parent activity in AndroidManifest.xml. + int id = item.getItemId(); + if (id == R.id.action_settings) { return true; } return super.onOptionsItemSelected(item); } + + /** + * A placeholder fragment containing a simple view. + */ + public static class PlaceholderFragment extends Fragment { + + public PlaceholderFragment() { } + + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, + Bundle savedInstanceState) { + View rootView = inflater.inflate(R.layout.fragment_display_message, + container, false); + return rootView; + } + } } </pre> @@ -422,7 +438,7 @@ public void onCreate(Bundle savedInstanceState) { <img src="{@docRoot}images/training/firstapp/firstapp.png" /> <p class="img-caption"><strong>Figure 2.</strong> Both activities in the final app, running -on Android 4.0. +on Android 4.4. <p>That's it, you've built your first Android app!</p> |
