diff options
Diffstat (limited to 'docs/html/training')
34 files changed, 322 insertions, 58 deletions
diff --git a/docs/html/training/animation/anim_page_transformer_depth.mp4 b/docs/html/training/animation/anim_page_transformer_depth.mp4 Binary files differnew file mode 100644 index 0000000..ba21663 --- /dev/null +++ b/docs/html/training/animation/anim_page_transformer_depth.mp4 diff --git a/docs/html/training/animation/anim_page_transformer_depth.ogv b/docs/html/training/animation/anim_page_transformer_depth.ogv Binary files differnew file mode 100644 index 0000000..929735a --- /dev/null +++ b/docs/html/training/animation/anim_page_transformer_depth.ogv diff --git a/docs/html/training/animation/anim_page_transformer_depth.webm b/docs/html/training/animation/anim_page_transformer_depth.webm Binary files differnew file mode 100644 index 0000000..37ab4e1 --- /dev/null +++ b/docs/html/training/animation/anim_page_transformer_depth.webm diff --git a/docs/html/training/animation/anim_page_transformer_zoomout.mp4 b/docs/html/training/animation/anim_page_transformer_zoomout.mp4 Binary files differnew file mode 100644 index 0000000..598e964 --- /dev/null +++ b/docs/html/training/animation/anim_page_transformer_zoomout.mp4 diff --git a/docs/html/training/animation/anim_page_transformer_zoomout.ogv b/docs/html/training/animation/anim_page_transformer_zoomout.ogv Binary files differnew file mode 100644 index 0000000..60b86af --- /dev/null +++ b/docs/html/training/animation/anim_page_transformer_zoomout.ogv diff --git a/docs/html/training/animation/anim_page_transformer_zoomout.webm b/docs/html/training/animation/anim_page_transformer_zoomout.webm Binary files differnew file mode 100644 index 0000000..fc599a0 --- /dev/null +++ b/docs/html/training/animation/anim_page_transformer_zoomout.webm diff --git a/docs/html/training/animation/cardflip.jd b/docs/html/training/animation/cardflip.jd index ab3eb3a..1477f9f 100644 --- a/docs/html/training/animation/cardflip.jd +++ b/docs/html/training/animation/cardflip.jd @@ -21,6 +21,16 @@ trainingnavtop=true <a href="#animate">Animate the Card Flip</a> </li> </ol> + <h2> + Try it out + </h2> + <div class="download-box"> + <a href="{@docRoot}shareables/training/Animations.zip" class= + "button">Download the sample app</a> + <p class="filename"> + Animations.zip + </p> + </div> </div> </div> <p> This lesson shows you how to do a card flip diff --git a/docs/html/training/animation/crossfade.jd b/docs/html/training/animation/crossfade.jd index 99e879b..2fbb6c0 100644 --- a/docs/html/training/animation/crossfade.jd +++ b/docs/html/training/animation/crossfade.jd @@ -20,6 +20,16 @@ trainingnavtop=true <a href="#animate">Crossfade the Views</a> </li> </ol> + <h2> + Try it out + </h2> + <div class="download-box"> + <a href="{@docRoot}shareables/training/Animations.zip" class= + "button">Download the sample app</a> + <p class="filename"> + Animations.zip + </p> + </div> </div> </div> diff --git a/docs/html/training/animation/layout.jd b/docs/html/training/animation/layout.jd index b8e0077..e3a47d6 100644 --- a/docs/html/training/animation/layout.jd +++ b/docs/html/training/animation/layout.jd @@ -11,7 +11,16 @@ trainingnavtop=true <li><a href="#views">Create the Layout</a></li> <li><a href="#add">Add, Update, or Remove Items from the Layout</a></li> </ol> - + <h2> + Try it out + </h2> + <div class="download-box"> + <a href="{@docRoot}shareables/training/Animations.zip" class= + "button">Download the sample app</a> + <p class="filename"> + Animations.zip + </p> + </div> </div> </div> diff --git a/docs/html/training/animation/screen-slide.jd b/docs/html/training/animation/screen-slide.jd index 8a7af67..716805e 100755..100644 --- a/docs/html/training/animation/screen-slide.jd +++ b/docs/html/training/animation/screen-slide.jd @@ -9,15 +9,26 @@ trainingnavtop=true <ol> <li><a href="#views">Create the Views</a></li> <li><a href="#fragment">Create the Fragment</a></li> - <li><a href="#viewpager">Animate the Screen Slide</a></li> + <li><a href="#viewpager">Add a ViewPager</a></li> + <li><a href="#pagetransformer">Customize the Animation with PageTransformer</a></li> </ol> + <h2> + Try it out + </h2> + <div class="download-box"> + <a href="{@docRoot}shareables/training/Animations.zip" class= + "button">Download the sample app</a> + <p class="filename"> + Animations.zip + </p> + </div> </div> </div> <p> Screen slides are transitions between one entire screen to another and are common with UIs like setup wizards or slideshows. This lesson shows you how to do screen slides with a {@link android.support.v4.view.ViewPager} provided by the <a href= - "{@docRoot}/tools/extras/support-library.html">support library</a>. + "{@docRoot}tools/extras/support-library.html">support library</a>. {@link android.support.v4.view.ViewPager}s can animate screen slides automatically. Here's what a screen slide looks like that transitions from one screen of content to the next: @@ -89,7 +100,7 @@ public class ScreenSlidePageFragment extends Fragment { } </pre> -<h2 id="viewpager">Screen Slides with ViewPager</h2> +<h2 id="viewpager">Add a ViewPager</h2> <p>{@link android.support.v4.view.ViewPager}s have built-in swipe gestures to transition through pages, and they display screen slide animations by default, so you don't need to create any. {@link android.support.v4.view.ViewPager}s use @@ -112,12 +123,12 @@ fragment class that you created earlier. <ul> <li>Sets the content view to be the layout with the {@link android.support.v4.view.ViewPager}.</li> - <li>Create a class that extends the {@link android.support.v13.app.FragmentStatePagerAdapter} abstract class. Implement + <li>Creates a class that extends the {@link android.support.v13.app.FragmentStatePagerAdapter} abstract class and implements the {@link android.support.v4.app.FragmentStatePagerAdapter#getItem getItem()} method to supply instances of <code>ScreenSlidePageFragment</code> as new pages. The pager adapter also requires that you implement the {@link android.support.v4.view.PagerAdapter#getCount getCount()} method, which returns the amount of pages the adapter will create (five in the example). <li>Hooks up the {@link android.support.v4.view.PagerAdapter} to the {@link android.support.v4.view.ViewPager}</code>.</li> - <li>Handle's the device's back button by moving backwards in the virtual stack of fragments. + <li>Handles the device's back button by moving backwards in the virtual stack of fragments. If the user is already on the first page, go back on the activity back stack.</li> </ul> @@ -182,4 +193,179 @@ public class ScreenSlidePagerActivity extends FragmentActivity { } } } -</pre>
\ No newline at end of file +</pre> + + +<h2 id="pagetransformer">Customize the Animation with PageTransformer</h2> + +<p>To display a different animation from the default screen slide animation, implement the + {@link android.support.v4.view.ViewPager.PageTransformer} interface and supply it to + the view pager. The interface exposes a single method, {@link android.support.v4.view.ViewPager.PageTransformer#transformPage transformPage()}. At each point in the screen's transition, this method is called once for each visible page (generally there's only one visible page) and for adjacent pages just off the screen. + For example, if page three is visible and the user drags towards page four, + {@link android.support.v4.view.ViewPager.PageTransformer#transformPage transformPage()} is called + for pages two, three, and four at each step of the gesture.</p> + + <p> + In your implementation of {@link android.support.v4.view.ViewPager.PageTransformer#transformPage transformPage()}, + you can then create custom slide animations by determining which pages need to be transformed based on the + position of the page on the screen, which is obtained from the <code>position</code> parameter + of the {@link android.support.v4.view.ViewPager.PageTransformer#transformPage transformPage()} method.</p> + +<p>The <code>position</code> parameter indicates where a given page is located relative to the center of the screen. +It is a dynamic property that changes as the user scrolls through the pages. When a page fills the screen, its position value is <code>0</code>. +When a page is drawn just off the right side of the screen, its position value is <code>1</code>. If the user scrolls halfway between pages one and two, page one has a position of -0.5 and page two has a position of 0.5. Based on the position of the pages on the screen, you can create custom slide animations by setting page properties with methods such as {@link android.view.View#setAlpha setAlpha()}, {@link android.view.View#setTranslationX setTranslationX()}, or + {@link android.view.View#setScaleY setScaleY()}.</p> + + +<p>When you have an implementation of a {@link android.support.v4.view.ViewPager.PageTransformer PageTransformer}, +call {@link android.support.v4.view.ViewPager#setPageTransformer setPageTransformer()} with + your implementation to apply your custom animations. For example, if you have a + {@link android.support.v4.view.ViewPager.PageTransformer PageTransformer} named + <code>ZoomOutPageTransformer</code>, you can set your custom animations + like this:</p> +<pre> +ViewPager pager = (ViewPager) findViewById(R.id.pager); +... +pager.setPageTransformer(true, new ZoomOutPageTransformer()); +</pre> + + +<p>See the <a href="#zoom-out">Zoom-out page transformer</a> and <a href="#depth-page">Depth page transformer</a> +sections for examples and videos of a {@link android.support.v4.view.ViewPager.PageTransformer PageTransformer}.</p> + + +<h3 id="zoom-out">Zoom-out page transformer</h3> +<p> + This page transformer shrinks and fades pages when scrolling between + adjacent pages. As a page gets closer to the center, it grows back to + its normal size and fades in. +</p> + +<div class="framed-galaxynexus-land-span-8"> + <video class="play-on-hover" autoplay> + <source src="anim_page_transformer_zoomout.mp4" type="video/mp4"> + <source src="anim_page_transformer_zoomout.webm" type="video/webm"> + <source src="anim_page_transformer_zoomout.ogv" type="video/ogg"> + </video> +</div> + +<div class="figure-caption"> + <code>ZoomOutPageTransformer</code> example + <div class="video-instructions"> </div> +</div> + + +<pre> +public class ZoomOutPageTransformer implements ViewPager.PageTransformer { + private static float MIN_SCALE = 0.85f; + private static float MIN_ALPHA = 0.5f; + + public void transformPage(View view, float position) { + int pageWidth = view.getWidth(); + int pageHeight = view.getHeight(); + + if (position < -1) { // [-Infinity,-1) + // This page is way off-screen to the left. + view.setAlpha(0); + + } else if (position <= 1) { // [-1,1] + // Modify the default slide transition to shrink the page as well + float scaleFactor = Math.max(MIN_SCALE, 1 - Math.abs(position)); + float vertMargin = pageHeight * (1 - scaleFactor) / 2; + float horzMargin = pageWidth * (1 - scaleFactor) / 2; + if (position < 0) { + view.setTranslationX(horzMargin - vertMargin / 2); + } else { + view.setTranslationX(-horzMargin + vertMargin / 2); + } + + // Scale the page down (between MIN_SCALE and 1) + view.setScaleX(scaleFactor); + view.setScaleY(scaleFactor); + + // Fade the page relative to its size. + view.setAlpha(MIN_ALPHA + + (scaleFactor - MIN_SCALE) / + (1 - MIN_SCALE) * (1 - MIN_ALPHA)); + + } else { // (1,+Infinity] + // This page is way off-screen to the right. + view.setAlpha(0); + } + } +} +</pre> + +<h3 id="depth-page">Depth page transformer</h3> +<p> +This page transformer uses the default slide animation for sliding pages +to the left, while using a "depth" animation for sliding pages to the +right. This depth animation fades the page out, and scales it down linearly. +</p> + +<div class="framed-galaxynexus-land-span-8"> + <video class="play-on-hover" autoplay> + <source src="anim_page_transformer_depth.mp4" type="video/mp4"> + <source src="anim_page_transformer_depth.webm" type="video/webm"> + <source src="anim_page_transformer_depth.ogv" type="video/ogg"> + </video> +</div> + +<div class="figure-caption"> + <code>DepthPageTransformer</code> example + <div class="video-instructions"> </div> +</div> + +<p class="note"><strong>Note:</strong> During the depth animation, the default animation (a screen slide) still +takes place, so you must counteract the screen slide with a negative X translation. + +For example: + +<pre> +view.setTranslationX(-1 * view.getWidth() * position); +</pre> + +The following example shows how to counteract the default screen slide animation +in a working page transformer: +</p> + +<pre> + +public class DepthPageTransformer implements ViewPager.PageTransformer { + private static float MIN_SCALE = 0.75f; + + public void transformPage(View view, float position) { + int pageWidth = view.getWidth(); + + if (position < -1) { // [-Infinity,-1) + // This page is way off-screen to the left. + view.setAlpha(0); + + } else if (position <= 0) { // [-1,0] + // Use the default slide transition when moving to the left page + view.setAlpha(1); + view.setTranslationX(0); + view.setScaleX(1); + view.setScaleY(1); + + } else if (position <= 1) { // (0,1] + // Fade the page out. + view.setAlpha(1 - position); + + // Counteract the default slide transition + view.setTranslationX(pageWidth * -position); + + // Scale the page down (between MIN_SCALE and 1) + float scaleFactor = MIN_SCALE + + (1 - MIN_SCALE) * (1 - Math.abs(position)); + view.setScaleX(scaleFactor); + view.setScaleY(scaleFactor); + + } else { // (1,+Infinity] + // This page is way off-screen to the right. + view.setAlpha(0); + } + } +} +</pre> + diff --git a/docs/html/training/animation/zoom.jd b/docs/html/training/animation/zoom.jd index 5dc2b6c..6a38e7d 100644 --- a/docs/html/training/animation/zoom.jd +++ b/docs/html/training/animation/zoom.jd @@ -19,6 +19,16 @@ trainingnavtop=true <a href="#animate">Zoom the View</a> </li> </ol> + <h2> + Try it out + </h2> + <div class="download-box"> + <a href="{@docRoot}shareables/training/Animations.zip" class= + "button">Download the sample app</a> + <p class="filename"> + Animations.zip + </p> + </div> </div> </div> <p> diff --git a/docs/html/training/articles/smp.jd b/docs/html/training/articles/smp.jd index 53d7879..d46787d 100644 --- a/docs/html/training/articles/smp.jd +++ b/docs/html/training/articles/smp.jd @@ -628,7 +628,7 @@ array.</p> <p>The “loop_until” seen in previous examples has been expanded to show the load of B into reg0. reg1 is assigned the numeric value 8, and reg2 is loaded from -the address [A+reg1] (same location that thread 1 is accessing).</p> +the address [A+reg1] (the same location that thread 1 is accessing).</p> <p>This will not behave correctly because the load from B could be observed after the load from [A+reg1]. We can fix this with a load/load barrier after @@ -640,7 +640,7 @@ the loop, but on ARM we can also just do this:</p> <th>Thread 2</th> </tr> <tr> -<td><code>A = 41<br /> +<td><code>[A+8] = 41<br /> <em>store/store barrier</em><br /> B = 1 // “A is ready”</code></td> <td><code>loop:<br /> diff --git a/docs/html/training/basics/activity-lifecycle/recreating.jd b/docs/html/training/basics/activity-lifecycle/recreating.jd index 1a65e71..71fd5dd 100644 --- a/docs/html/training/basics/activity-lifecycle/recreating.jd +++ b/docs/html/training/basics/activity-lifecycle/recreating.jd @@ -126,7 +126,7 @@ can save the state of the view hierarchy.</p> state from the {@link android.os.Bundle} that the system passes your activity. Both the {@link android.app.Activity#onCreate onCreate()} and {@link android.app.Activity#onRestoreInstanceState onRestoreInstanceState()} callback methods receive -the same {@link android.os.Bundle} that containes the instance state information.</p> +the same {@link android.os.Bundle} that contains the instance state information.</p> <p>Because the {@link android.app.Activity#onCreate onCreate()} method is called whether the system is creating a new instance of your activity or recreating a previous one, you must check diff --git a/docs/html/training/basics/activity-lifecycle/starting.jd b/docs/html/training/basics/activity-lifecycle/starting.jd index dd17304..dce6e30 100644 --- a/docs/html/training/basics/activity-lifecycle/starting.jd +++ b/docs/html/training/basics/activity-lifecycle/starting.jd @@ -265,7 +265,7 @@ signal that your activity instance is being completely removed from the system m with the activity and your activity should perform most cleanup during {@link android.app.Activity#onPause} and {@link android.app.Activity#onStop}. However, if your activity includes background threads that you created during {@link -android.app.Activity#onCreate onCreate()} or other other long-running resources that could +android.app.Activity#onCreate onCreate()} or other long-running resources that could potentially leak memory if not properly closed, you should kill them during {@link android.app.Activity#onDestroy}.</p> diff --git a/docs/html/training/basics/data-storage/databases.jd b/docs/html/training/basics/data-storage/databases.jd index 3a717dd..8b11983 100644 --- a/docs/html/training/basics/data-storage/databases.jd +++ b/docs/html/training/basics/data-storage/databases.jd @@ -288,7 +288,7 @@ String selection = FeedReaderContract.FeedEntry.COLUMN_NAME_ENTRY_ID + " LI // Specify arguments in placeholder order. String[] selelectionArgs = { String.valueOf(rowId) }; // Issue SQL statement. -db.delete(table_name, mySelection, selectionArgs); +db.delete(table_name, selection, selectionArgs); </pre> diff --git a/docs/html/training/basics/data-storage/shared-preferences.jd b/docs/html/training/basics/data-storage/shared-preferences.jd index 67f45cb..099da67 100644 --- a/docs/html/training/basics/data-storage/shared-preferences.jd +++ b/docs/html/training/basics/data-storage/shared-preferences.jd @@ -115,7 +115,7 @@ present. For example:</p> <pre> SharedPreferences sharedPref = getActivity().getPreferences(Context.MODE_PRIVATE); -long default = getResources().getInteger(R.string.saved_high_score_default)); -long highScore = sharedPref.getInt(getString(R.string.saved_high_score), default); +int defaultValue = getResources().getInteger(R.string.saved_high_score_default); +long highScore = sharedPref.getInt(getString(R.string.saved_high_score), defaultValue); </pre> diff --git a/docs/html/training/basics/firstapp/running-app.jd b/docs/html/training/basics/firstapp/running-app.jd index 7866083..999d399 100644 --- a/docs/html/training/basics/firstapp/running-app.jd +++ b/docs/html/training/basics/firstapp/running-app.jd @@ -52,7 +52,27 @@ project:</p> <dd>The <a href="{@docRoot}guide/topics/manifest/manifest-intro.html">manifest file</a> describes the fundamental characteristics of the app and defines each of its components. You'll learn about various declarations in this file as you read more training -classes.</dd> +classes. + <p>One of the most important elements your manifest should include is the <a +href="{@docRoot}guide/topics/manifest/uses-sdk-element.html">{@code <uses-sdk>}</a> +element. This declares your app's compatibility with different Android versions using the <a +href="{@docRoot}guide/topics/manifest/uses-sdk-element.html#min">{@code android:minSdkVersion}</a> +and <a +href="{@docRoot}guide/topics/manifest/uses-sdk-element.html#target">{@code android:targetSdkVersion}</a> +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" /> + ... +</manifest> +</pre> +<p>You should always set the <a +href="{@docRoot}guide/topics/manifest/uses-sdk-element.html#target">{@code android:targetSdkVersion}</a> +as high as possible and test your app on the corresponding platform version. For more information, +read <a href="{@docRoot}training/basics/supporting-devices/platforms.html">Supporting Different +Platform Versions</a>.</p> + + </dd> <dt><code>src/</code></dt> <dd>Directory for your app's main source files. By default, it includes an {@link android.app.Activity} class that runs when your app is launched using the app icon.</dd> diff --git a/docs/html/training/basics/firstapp/starting-activity.jd b/docs/html/training/basics/firstapp/starting-activity.jd index 8943c9d..65f22901 100644 --- a/docs/html/training/basics/firstapp/starting-activity.jd +++ b/docs/html/training/basics/firstapp/starting-activity.jd @@ -249,16 +249,29 @@ you won't need it for this app so you can remove it.</li> Keep this one the way it is.</li> </ul> -<p>The class should look like this:</p> +<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>The {@code DisplayMessageActivity} class should now look like this:</p> <pre> public class DisplayMessageActivity extends Activity { + + @SuppressLint("NewApi") @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_display_message); - // Show the Up button in the action bar. - getActionBar().setDisplayHomeAsUpEnabled(true); + + // 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); + } } @Override diff --git a/docs/html/training/basics/fragments/support-lib.jd b/docs/html/training/basics/fragments/support-lib.jd index ba10b78..cc867d3 100644 --- a/docs/html/training/basics/fragments/support-lib.jd +++ b/docs/html/training/basics/fragments/support-lib.jd @@ -12,7 +12,7 @@ next.link=creating.html <div id="tb"> <h2>This lesson teaches you to</h2> <ol> - <li><a href="#Setup">Set Up Your Project With the Support Library</a></li> + <li><a href="#Setup">Set Up Your Project with the Support Library</a></li> <li><a href="#Apis">Import the Support Library APIs</a></li> </ol> <h2>You should also read</h2> @@ -23,7 +23,7 @@ next.link=creating.html </div> <p>The Android <a href="{@docRoot}tools/extras/support-library.html">Support Library</a> provides a JAR -file with an API library that allow you to use some of the more recent Android APIs in your app +file with an API library that allows you to use some of the more recent Android APIs in your app while running on earlier versions of Android. For instance, the Support Library provides a version of the {@link android.app.Fragment} APIs that you can use on Android 1.6 (API level 4) and higher.</p> @@ -32,7 +32,7 @@ higher.</p> to build a dynamic app UI.</p> -<h2 id="Setup">Set Up Your Project With the Support Library</h2> +<h2 id="Setup">Set Up Your Project with the Support Library</h2> <div class="figure" style="width:527px"> <img src="{@docRoot}images/training/basics/sdk-manager.png" alt="" /> @@ -43,7 +43,7 @@ Android Support package selected.</p> <p>To set up your project:</p> <ol> - <li>Downlad the Android Support package using the SDK Manager</li> + <li>Download the Android Support package using the SDK Manager.</li> <li>Create a <code>libs</code> directory at the top level of your Android project.</li> <li>Locate the JAR file for the library you want to use and copy it into the <code>libs/</code> diff --git a/docs/html/training/basics/location/geocoding.jd b/docs/html/training/basics/location/geocoding.jd index 6364976..3192d14 100644 --- a/docs/html/training/basics/location/geocoding.jd +++ b/docs/html/training/basics/location/geocoding.jd @@ -82,7 +82,7 @@ private class ReverseGeocodingTask extends AsyncTask<Location, Void, Void> // Update UI field with the exception. Message.obtain(mHandler, UPDATE_ADDRESS, e.toString()).sendToTarget(); } - if (addresses != null &s;&s; addresses.size() > 0) { + if (addresses != null && addresses.size() > 0) { Address address = addresses.get(0); // Format the first line of address (if available), city, and country name. String addressText = String.format("%s, %s, %s", @@ -95,4 +95,4 @@ private class ReverseGeocodingTask extends AsyncTask<Location, Void, Void> return null; } } -</pre>
\ No newline at end of file +</pre> diff --git a/docs/html/training/basics/network-ops/xml.jd b/docs/html/training/basics/network-ops/xml.jd index b148257..0ea696d 100644 --- a/docs/html/training/basics/network-ops/xml.jd +++ b/docs/html/training/basics/network-ops/xml.jd @@ -551,5 +551,5 @@ private InputStream downloadUrl(String urlString) throws IOException { conn.setDoInput(true); // Starts the query conn.connect(); - InputStream stream = conn.getInputStream(); + return conn.getInputStream(); }</pre> diff --git a/docs/html/training/basics/supporting-devices/screens.jd b/docs/html/training/basics/supporting-devices/screens.jd index 8697cd5..1114f21 100644 --- a/docs/html/training/basics/supporting-devices/screens.jd +++ b/docs/html/training/basics/supporting-devices/screens.jd @@ -108,7 +108,7 @@ MyProject/ <p>By default, the <code>layout/main.xml</code> file is used for portrait orientation.</p> -<p>If you want a provide a special layout for landscape, including while on large screens, then +<p>If you want to provide a special layout for landscape, including while on large screens, then you need to use both the <code>large</code> and <code>land</code> qualifier:</p> <pre class="classic no-pretty-print"> diff --git a/docs/html/training/connect-devices-wirelessly/nsd.jd b/docs/html/training/connect-devices-wirelessly/nsd.jd index d2b01a1..30f5c49 100644 --- a/docs/html/training/connect-devices-wirelessly/nsd.jd +++ b/docs/html/training/connect-devices-wirelessly/nsd.jd @@ -28,9 +28,9 @@ next.link=wifi-direct.html <h2>Try it out</h2> <div class="download-box"> - <a href="{@docRoot}shareables/training/nsdchat.zip" class="button">Download + <a href="{@docRoot}shareables/training/NsdChat.zip" class="button">Download the sample app</a> - <p class="filename">nsdchat.zip</p> + <p class="filename">NsdChat.zip</p> </div> </p> diff --git a/docs/html/training/connect-devices-wirelessly/wifi-direct.jd b/docs/html/training/connect-devices-wirelessly/wifi-direct.jd index 99bb243..b8ed664 100644 --- a/docs/html/training/connect-devices-wirelessly/wifi-direct.jd +++ b/docs/html/training/connect-devices-wirelessly/wifi-direct.jd @@ -263,7 +263,7 @@ public void onReceive(Context context, Intent intent) { // asynchronous call and the calling activity is notified with a // callback on PeerListListener.onPeersAvailable() if (mManager != null) { - mManager.requestPeers(mChannel, peerListener); + mManager.requestPeers(mChannel, peerListListener); } Log.d(WiFiDirectActivity.TAG, "P2P peers changed"); }... diff --git a/docs/html/training/custom-views/create-view.jd b/docs/html/training/custom-views/create-view.jd index 674bcc9..b849cb3 100644 --- a/docs/html/training/custom-views/create-view.jd +++ b/docs/html/training/custom-views/create-view.jd @@ -68,8 +68,8 @@ This constructor allows the layout editor to create and edit an instance of your <pre class="prettyprint"> class PieChart extends View { - public PieChart(Context ctx, AttributeSet attrs) { - super(ctx, attrs); + public PieChart(Context context, AttributeSet attrs) { + super(context, attrs); } } </pre> @@ -104,7 +104,7 @@ enable this behavior in your custom view, you must: </p> <pre> -<resources>; +<resources> <declare-styleable name="PieChart"> <attr name="showText" format="boolean" /> <attr name="labelPosition" format="enum"> @@ -189,8 +189,8 @@ enable this behavior in your custom view, you must: reads its attributes:</p> <pre> -public PieChart(Context ctx, AttributeSet attrs) { - super(ctx, attrs); +public PieChart(Context context, AttributeSet attrs) { + super(context, attrs); TypedArray a = context.getTheme().obtainStyledAttributes( attrs, R.styleable.PieChart, diff --git a/docs/html/training/custom-views/index.jd b/docs/html/training/custom-views/index.jd index 0661c05..cec75b4 100644 --- a/docs/html/training/custom-views/index.jd +++ b/docs/html/training/custom-views/index.jd @@ -17,12 +17,12 @@ next.link=create-view.html <h2>You should also read</h2> <ul> - <li><a href="{@docRoot}/guide/topics/ui/custom-components.html">Custom Components</a> + <li><a href="{@docRoot}guide/topics/ui/custom-components.html">Custom Components</a> </li> - <li><a href="{@docRoot}/guide/topics/ui/ui-events.html">Input Events</a></li> - <li><a href="{@docRoot}/guide/topics/graphics/prop-animation.html">Property + <li><a href="{@docRoot}guide/topics/ui/ui-events.html">Input Events</a></li> + <li><a href="{@docRoot}guide/topics/graphics/prop-animation.html">Property Animation</a></li> - <li><a href="{@docRoot}/guide/topics/graphics/hardware-accel.html">Hardware + <li><a href="{@docRoot}guide/topics/graphics/hardware-accel.html">Hardware Acceleration</a></li> <li><a href="{@docRoot}guide/topics/ui/accessibility/index.html"> Accessibility</a> developer guide</li> diff --git a/docs/html/training/displaying-bitmaps/cache-bitmap.jd b/docs/html/training/displaying-bitmaps/cache-bitmap.jd index 2a333cc..417ec5b 100644 --- a/docs/html/training/displaying-bitmaps/cache-bitmap.jd +++ b/docs/html/training/displaying-bitmaps/cache-bitmap.jd @@ -101,19 +101,20 @@ private LruCache<String, Bitmap> mMemoryCache; @Override protected void onCreate(Bundle savedInstanceState) { ... - // Get memory class of this device, exceeding this amount will throw an - // OutOfMemory exception. - final int memClass = ((ActivityManager) context.getSystemService( - Context.ACTIVITY_SERVICE)).getMemoryClass(); + // Get max available VM memory, exceeding this amount will throw an + // OutOfMemory exception. Stored in kilobytes as LruCache takes an + // int in its constructor. + final int maxMemory = (int) (Runtime.getRuntime().maxMemory() / 1024); // Use 1/8th of the available memory for this memory cache. - final int cacheSize = 1024 * 1024 * memClass / 8; + final int cacheSize = maxMemory / 8; mMemoryCache = new LruCache<String, Bitmap>(cacheSize) { @Override protected int sizeOf(String key, Bitmap bitmap) { - // The cache size will be measured in bytes rather than number of items. - return bitmap.getByteCount(); + // The cache size will be measured in kilobytes rather than + // number of items. + return bitmap.getByteCount() / 1024; } }; ... diff --git a/docs/html/training/displaying-bitmaps/load-bitmap.jd b/docs/html/training/displaying-bitmaps/load-bitmap.jd index c0a5709..283f272 100644 --- a/docs/html/training/displaying-bitmaps/load-bitmap.jd +++ b/docs/html/training/displaying-bitmaps/load-bitmap.jd @@ -110,12 +110,17 @@ public static int calculateInSampleSize( int inSampleSize = 1; if (height > reqHeight || width > reqWidth) { - if (width > height) { - inSampleSize = Math.round((float)height / (float)reqHeight); - } else { - inSampleSize = Math.round((float)width / (float)reqWidth); - } + + // Calculate ratios of height and width to requested height and width + final int heightRatio = Math.round((float) height / (float) reqHeight); + final int widthRatio = Math.round((float) width / (float) reqWidth); + + // Choose the smallest ratio as inSampleSize value, this will guarantee + // a final image with both dimensions larger than or equal to the + // requested height and width. + inSampleSize = heightRatio < widthRatio ? heightRatio : widthRatio; } + return inSampleSize; } </pre> diff --git a/docs/html/training/in-app-billing/purchase-iab-products.jd b/docs/html/training/in-app-billing/purchase-iab-products.jd index d5f6634..7fa77d3 100644 --- a/docs/html/training/in-app-billing/purchase-iab-products.jd +++ b/docs/html/training/in-app-billing/purchase-iab-products.jd @@ -65,7 +65,7 @@ IabHelper.OnIabPurchaseFinishedListener mPurchaseFinishedListener else if (purchase.getSku().equals(SKU_GAS)) { // consume the gas and update the UI } - else (purchase.getSku().equals(SKU_PREMIUM)) { + else if (purchase.getSku().equals(SKU_PREMIUM)) { // give user access to premium content and update the UI } } diff --git a/docs/html/training/managing-audio/volume-playback.jd b/docs/html/training/managing-audio/volume-playback.jd index 76abbb6..be0f583 100644 --- a/docs/html/training/managing-audio/volume-playback.jd +++ b/docs/html/training/managing-audio/volume-playback.jd @@ -153,4 +153,4 @@ important when your application isn’t visible and therefore can’t be control UI.</p> <p>A better approach is to register and unregister the media button event receiver when your -application gains and losses the audio focus. This is covered in detail in the next lesson.</p> +application gains and loses the audio focus. This is covered in detail in the next lesson.</p> diff --git a/docs/html/training/multiple-apks/texture.jd b/docs/html/training/multiple-apks/texture.jd index e4ea72b..c49cc95 100644 --- a/docs/html/training/multiple-apks/texture.jd +++ b/docs/html/training/multiple-apks/texture.jd @@ -90,8 +90,8 @@ cell represents an APK.</p> <tbody> <tr> <td class="blueCell">ETC1</td> - <td class="greenCell">ATI</td> - <td class="redCell">PowerVR</td> + <td class="redCell">ATI</td> + <td class="greenCell">PowerVR</td> </tr> </tbody> </table> diff --git a/docs/html/training/multiple-threads/create-threadpool.jd b/docs/html/training/multiple-threads/create-threadpool.jd index 4a4ddb1..e22afd3 100644 --- a/docs/html/training/multiple-threads/create-threadpool.jd +++ b/docs/html/training/multiple-threads/create-threadpool.jd @@ -46,7 +46,7 @@ trainingnavtop=true <code>synchronized</code> block. This approach will prevent one thread from reading the variable while another is writing to it. Typically, this situation arises with static variables, but it also occurs in any object that is only instantiated once. To learn more about this, read the - <a href="{@docRoot}http://developer.android.com/guide/components/processes-and-threads.html"> + <a href="{@docRoot}guide/components/processes-and-threads.html"> Processes and Threads</a> API guide. </p> diff --git a/docs/html/training/notepad/notepad-ex2.jd b/docs/html/training/notepad/notepad-ex2.jd index 1334d7a..895a071 100644 --- a/docs/html/training/notepad/notepad-ex2.jd +++ b/docs/html/training/notepad/notepad-ex2.jd @@ -100,7 +100,7 @@ public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuIn </ol> <h2>Step 3</h2> - <p>Now that the we've registered our ListView for a context menu and defined our context menu item, we need + <p>Now that we've registered our ListView for a context menu and defined our context menu item, we need to handle the callback when it is selected. For this, we need to identify the list ID of the selected item, then delete it. So fill in the <code>onContextItemSelected()</code> method like this:</p> diff --git a/docs/html/training/sharing/send.jd b/docs/html/training/sharing/send.jd index 741c017..9cb8eac 100644 --- a/docs/html/training/sharing/send.jd +++ b/docs/html/training/sharing/send.jd @@ -32,7 +32,7 @@ Intent Filters</a></li> <p>When you construct an intent, you must specify the action you want the intent to "trigger." Android defines several actions, including {@link android.content.Intent#ACTION_SEND} which, as you can probably guess, indicates that the intent is sending data from one activity to another, -even across process boundaries. To send data to another activity, all you need to do is speicify +even across process boundaries. To send data to another activity, all you need to do is specify the data and its type, the system will identify compatible receiving activities and display them to the user (if there are multiple options) or immediately start the activity (if there is only one option). Similarly, you can advertise the data types that your activities support receiving @@ -95,7 +95,7 @@ Intent sendIntent = new Intent(); sendIntent.setAction(Intent.ACTION_SEND); sendIntent.putExtra(Intent.EXTRA_TEXT, "This is my text to send."); sendIntent.setType("text/plain"); -startActivity(<strong>Intent.createChooser(sendIntent, getResources().getText(R.string.send_to)</strong>); +startActivity(<strong>Intent.createChooser(sendIntent, getResources().getText(R.string.send_to))</strong>); </pre> <p>The resulting dialog is shown in figure 1.</p> |
