diff options
author | Ricardo Cervera <rcervera@google.com> | 2014-03-14 17:54:11 +0000 |
---|---|---|
committer | Android Git Automerger <android-git-automerger@android.com> | 2014-03-14 17:54:11 +0000 |
commit | 4656ac9fe6de1f67026f5bef1c55cb14ba4c0b13 (patch) | |
tree | 6ec87acb2fb2ca759fa57727a70d36cb7be1ddc8 | |
parent | cfa561cad838a70f04086488229be23d8f2f6e4c (diff) | |
parent | d387206a84a35b86663adb5bf00671cafbf6aee4 (diff) | |
download | frameworks_base-4656ac9fe6de1f67026f5bef1c55cb14ba4c0b13.zip frameworks_base-4656ac9fe6de1f67026f5bef1c55cb14ba4c0b13.tar.gz frameworks_base-4656ac9fe6de1f67026f5bef1c55cb14ba4c0b13.tar.bz2 |
am d387206a: am 7890eeff: am 882ba89b: am 50694917: am 7e566239: Merge "docs: Updated Building your First App tutorial. Bug: 13429905" into klp-docs
* commit 'd387206a84a35b86663adb5bf00671cafbf6aee4':
docs: Updated Building your First App tutorial. Bug: 13429905
-rw-r--r-- | docs/html/images/screens_support/avds-config.png | bin | 66715 -> 48973 bytes | |||
-rw-r--r-- | docs/html/images/training/firstapp/adt-firstapp-setup.png | bin | 81191 -> 56191 bytes | |||
-rw-r--r-- | docs/html/images/training/firstapp/adt-new-activity.png | bin | 55693 -> 44442 bytes | |||
-rw-r--r-- | docs/html/images/training/firstapp/edittext_gravity.png | bin | 7420 -> 6606 bytes | |||
-rw-r--r-- | docs/html/images/training/firstapp/edittext_wrap.png | bin | 7402 -> 6773 bytes | |||
-rw-r--r-- | docs/html/images/training/firstapp/firstapp.png | bin | 37195 -> 27370 bytes | |||
-rw-r--r-- | docs/html/training/basics/firstapp/building-ui.jd | 7 | ||||
-rw-r--r-- | docs/html/training/basics/firstapp/creating-project.jd | 8 | ||||
-rw-r--r-- | docs/html/training/basics/firstapp/running-app.jd | 2 | ||||
-rw-r--r-- | docs/html/training/basics/firstapp/starting-activity.jd | 76 |
10 files changed, 54 insertions, 39 deletions
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/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/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> |