diff --git a/docs/html/training/wearables/ui/2d-picker.jd b/docs/html/training/wearables/ui/2d-picker.jd index 8f4d8af196678..68f98b7c4d55e 100644 --- a/docs/html/training/wearables/ui/2d-picker.jd +++ b/docs/html/training/wearables/ui/2d-picker.jd @@ -9,6 +9,11 @@ page.title=Creating a 2D Picker
To implement this pattern, you add a GridViewPager element to the layout
-of your activity and implement an adapter that provides a set of pages by extending
-the FragmentGridPagerAdapter class.
Note: The GridViewPager sample in the Android SDK
-demonstrates how to use the GridViewPager layout in your apps. This sample is
-located in the android-sdk/samples/android-20/wearable/GridViewPager directory.
To implement this pattern, you add a
+GridViewPager
+element to the layout of your activity and implement an adapter that provides a set of pages by
+extending the
+FragmentGridPagerAdapter
+class.
Add a GridViewPager element to your layout definition as follows:
Add a
+GridViewPager
+element to your layout definition as follows:
<android.support.wearable.view.GridViewPager @@ -49,18 +55,20 @@ your 2D picker works on both round and square devices.Implement a Page Adapter
-A page adapter provides a set of pages to populate a
+GridViewPagercomponent. To -implement this adapter, you extend theFragmentGridPageAdapterclass from the -Wearable UI LibraryA page adapter provides a set of pages to populate a +
-GridViewPager+component. To implement this adapter, you extend the +FragmentGridPagerAdapter+class from the Wearable UI LibraryFor example, the GridViewPager sample in the Android SDK contains -the following adapter implementation that provides a set of static cards with custom background +
The following snippet shows how to provide a set of static cards with custom background images:
public class SampleGridPagerAdapter extends FragmentGridPagerAdapter { private final Context mContext; + private List-mRows; public SampleGridPagerAdapter(Context ctx, FragmentManager fm) { super(fm); @@ -68,8 +76,8 @@ public class SampleGridPagerAdapter extends FragmentGridPagerAdapter { } static final int[] BG_IMAGES = new int[] { - R.drawable.debug_background_1, ... - R.drawable.debug_background_5 + R.drawable.debug_background_1, ... + R.drawable.debug_background_5 }; // A simple container for static data in each page @@ -89,8 +97,11 @@ public class SampleGridPagerAdapter extends FragmentGridPagerAdapter { }
The picker calls
+getFragmentandgetBackgroundto retrieve the content -to display at each position of the grid:The adapter calls +
getFragment()+and +getBackgroundForRow()+to retrieve the content to display for each row:// Obtain the UI fragment at the specified position @@ -111,16 +122,39 @@ public Fragment getFragment(int row, int col) { return fragment; } -// Obtain the background image for the page at the specified position +// Obtain the background image for the row @Override -public ImageReference getBackground(int row, int column) { - return ImageReference.forDrawable(BG_IMAGES[row % BG_IMAGES.length]); +public Drawable getBackgroundForRow(int row) { + return mContext.getResources().getDrawable( + (BG_IMAGES[row % BG_IMAGES.length]), null); +} + ++ +The following example shows how to retrieve the background to display for a specific page +in the grid: +
+ ++// Obtain the background image for the specific page +@Override +public Drawable getBackgroundForPage(int row, int column) { + if( row == 2 && column == 1) { + // Place image at specified position + return mContext.getResources().getDrawable(R.drawable.bugdroid_large, null); + } else { + // Default to background image for row + return GridPagerAdapter.BACKGROUND_NONE; + } }-The
+getRowCountmethod tells the picker how many rows of content are -available, and thegetColumnCountmethod tells the picker how many columns -of content are available for each of the rows.The +
getRowCount()+method tells the adapter how many rows of content are +available, and the +getColumnCount()+method tells the adapter how many columns of content are available for each of the rows.// Obtain the number of pages (vertical) @@ -137,10 +171,13 @@ public int getColumnCount(int rowNum) {The adapter implementation details depend on your particular set of pages. Each page provided -by the adapter is of type
+by the adapter is of type +Fragment. In this example, each page is a -CardFragmentinstance that uses one of the default card layouts. However, you can -combine different types of pages in the same 2D picker, such as cards, action icons, and custom -layouts depending on your use cases.Fragment. +In this example, each page is a +CardFragment+instance that uses one of the default card layouts. However, you can combine different types of +pages in the same 2D picker, such as cards, action icons, and custom layouts depending on your use +cases.@@ -149,24 +186,30 @@ The GridViewPager sample.
Not all rows need to have the same number of pages. Notice that in this example the number of -colums is different for each row. You can also use a
+colums is different for each row. You can also use a +GridViewPagercomponent to -implement a 1D picker with only one row or only one column.GridViewPager+component to implement a 1D picker with only one row or only one column. -
GridViewPagerprovides support for scrolling in cards whose content does not fit +The +
-GridViewPager+class provides support for scrolling in cards whose content does not fit the device screen. This example configures each card to expand as required, so users can scroll through the card's content. When users reach the end of a scrollable card, a swipe in the same direction shows the next page on the grid, if one is available.You can specify a custom background for each page with the
+getBackground()method. -When users swipe to navigate across pages,GridViewPagerapplies parallax -and crossfade effects between different backgrounds automatically.You can specify a custom background for each page with the +
getBackgroundForPage()+method. When users swipe to navigate across pages, the +GridViewPager+class applies parallax and crossfade effects between different backgrounds automatically.Assign an adapter instance to the page grid
In your activity, assign an instance of your adapter implementation to the -
+GridViewPagercomponent:GridViewPager+component: -+public class MainActivity extends Activity { @Override diff --git a/docs/html/training/wearables/ui/cards.jd b/docs/html/training/wearables/ui/cards.jd index 21f7e5c81e109..9ad87ad0565bf 100644 --- a/docs/html/training/wearables/ui/cards.jd +++ b/docs/html/training/wearables/ui/cards.jd @@ -21,16 +21,23 @@ page.title=Creating Cards This lesson shows you how to create cards in your Android Wear apps.The Wearable UI Library provides implementations of cards specifically designed for wearable -devices. This library contains the
CardFrameclass, which wraps views inside -a card-styled frame with a white background, rounded corners, and a light-drop shadow. -CardFramecan only contain one direct child, usually a layout manager, to which +devices. This library contains the +CardFrame+class, which wraps views inside a card-styled frame with a white background, rounded corners, and a +light-drop shadow. A +CardFrame+instance can only contain one direct child, usually a layout manager, to which you can add other views to customize the content inside the card.You can add cards to your app in two ways:
CardFragment class.CardScrollView in your layout.CardFragment
+ class.CardScrollView
+ instance in your layout.Note: This lesson shows you how to add cards to Android Wear @@ -41,22 +48,31 @@ Features to Notifications.
The CardFragment class provides a default card layout with a title, a
-description, and an icon. Use this approach to add cards to your app if the default card layout
-shown in figure 1 meets your needs.
The
+CardFragment
+class provides a default card layout with a title, a description, and an icon. Use this approach to
+add cards to your app if the default card layout shown in figure 1 meets your needs.
-Figure 1. The default CardFragment layout.
Figure 1. The default
+CardFragment
+layout.
To add a CardFragment to your app:
To add a
+CardFragment
+instance to your app:
CardFragment instance in your activityCardFragment instance to its containerCardFragment
+instance in your activityCardFragment
+instance to its containerThe following sample code shows the code for the screen display shown in Figure 1:
+The following sample code shows the code for the screen display shown in figure 1:
<android.support.wearable.view.BoxInsetLayout @@ -76,7 +92,9 @@ android:layout_width="match_parent"> </android.support.wearable.view.BoxInsetLayout>-
The following code adds the CardFragment instance to the activity in Figure 1:
The following code adds the
+CardFragment
+instance to the activity in figure 1:
protected void onCreate(Bundle savedInstanceState) {
@@ -93,8 +111,11 @@ protected void onCreate(Bundle savedInstanceState) {
}
-To create a card with a custom layout using CardFragment, extend this class
-and override its onCreateContentView method.
To create a card with a custom layout using the
+CardFragment
+class, extend the class and override its
+onCreateContentView
+method.
onCreateContentView method.
approach when you want to define a custom layout for the card inside a layout definition file.
-Figure 2. Adding a CardFrame to your
-layout.
Figure 2. Adding a
+CardFrame
+to your layout.
The following layout code sample demonstrates a vertical linear layout with two elements. You can create more complex layouts to fit the needs of your app.
@@ -152,7 +174,9 @@ android:layout_width="match_parent"> </android.support.wearable.view.BoxInsetLayout> -The CardScrollView element in the example layout above lets you assign gravity to
+
The
+<CardScrollView>
+element detects the shape of the screen and displays the card differently
on round and square devices, using wider side margins on round screens. However,
-placing the CardScrollView element inside a BoxInsetLayout and using the
-layout_box="bottom" attribute is useful to align the card to the bottom of round
-screens without cropping its content.
<CardScrollView>
+element inside a
+<BoxInsetLayout>
+and using the layout_box="bottom" attribute is useful to align the card to the bottom
+of round screens without cropping its content.
diff --git a/docs/html/training/wearables/ui/confirm.jd b/docs/html/training/wearables/ui/confirm.jd
index 07a352f9239f8..1f33085672f4d 100644
--- a/docs/html/training/wearables/ui/confirm.jd
+++ b/docs/html/training/wearables/ui/confirm.jd
@@ -52,12 +52,18 @@ gets notified if the user cancels the action and when the timer expires.
To show a confirmation timer when users complete an action in your app:
DelayedConfirmationView element to your layout.DelayedConfirmationListener interface in your activity.<DelayedConfirmationView>
+element to your layout.DelayedConfirmationListener
+interface in your activity.Add the DelayedConfirmationView element to your layout as follows:
Add the
+<DelayedConfirmationView>
+element to your layout as follows:
<android.support.wearable.view.DelayedConfirmationView @@ -125,19 +131,24 @@ A confirmation animation.Show Confirmation Animations
To show a confirmation animation when users complete an action in your app, create an intent -that starts
+that starts +ConfirmationActivityfrom one of your activities. You can specify -one of the these animations with theEXTRA_ANIMATION_TYPEintent extra:ConfirmationActivity+from one of your activities. You can specify +one of the these animations with the +EXTRA_ANIMATION_TYPE+intent extra:
SUCCESS_ANIMATIONFAILURE_ANIMATIONOPEN_ON_PHONE_ANIMATIONSUCCESS_ANIMATIONFAILURE_ANIMATIONOPEN_ON_PHONE_ANIMATIONYou can also add a message that appears under the confirmation icon.
-To use the ConfirmationActivity in your app, first declare this activity in your
-manifest file:
To use the
+ConfirmationActivity
+in your app, first declare this activity in your manifest file:
<manifest> @@ -161,5 +172,6 @@ intent.putExtra(ConfirmationActivity.EXTRA_MESSAGE, startActivity(intent);-
After showing the confirmation animation, ConfirmationActivity finishes and your
-activity resumes.
After showing the confirmation animation,
+ConfirmationActivity
+finishes and your activity resumes.
For more immersive experiences, like an app that can scroll a map in any direction, you can
disable the swipe to exit gesture in your app. However, if you disable it, you must implement
the long-press-to-dismiss UI pattern to let users exit your app using the
-DismissOverlayView class from the Wearable UI Library.
-You must also inform your users the first time they run your app that they can exit using
-a long press.
DismissOverlayView
+class from the Wearable UI Library. You must also inform your users the first time they run your app
+that they can exit using a long press.
For design guidelines about exiting Android Wear activities, see Breaking out of the card.
@@ -51,9 +51,14 @@ exit your app, as described in the next section.To use the DissmissOverlayView class in your activity, add this element to
-your layout definition such that it covers the whole screen and is placed above all other views.
-For example:
To use the
+DismissOverlayView
+class in your activity, add this element to your layout definition such that it covers the whole
+screen and is placed above all other views.
The following example shows how to add the
+<DismissOverlayView>
+element:
<FrameLayout @@ -70,10 +75,12 @@ For example: <FrameLayout>-
In your activity, obtain the DismissOverlayView element and set some introductory
-text. This text is shown to users the first time they run your app to inform them that they
-can exit the app using a long press gesture. Then use a GestureDetector to detect
-a long press:
In your activity, obtain the
+<DismissOverlayView>
+element and set some introductory text. This text is shown to users the first time they run your app
+to inform them that they can exit the app using a long press gesture. Then use a
+GestureDetector
+to detect a long press:
public class WearActivity extends Activity {
@@ -106,5 +113,7 @@ public class WearActivity extends Activity {
}
-When the system detects a long press gesture, DismissOverlayView shows an
-Exit button, which terminates your activity if the user presses it.
When the system detects a long press gesture, the
+<DismissOverlayView>
+element shows an Exit button, which terminates your activity if the user presses
+it.
The WatchViewStub class included in the Wearable UI Library lets you specify
-different layout definitions for square and round screens. This class detects the screen shape
-at runtime and inflates the corresponding layout.
The
+WatchViewStub
+class included in the Wearable UI Library lets you specify different layout definitions for square
+and round screens. This class detects the screen shape at runtime and inflates the corresponding
+layout.
To use this class for handling different screen shapes in your app:
WatchViewStub as the main element of your activity's layout.WatchViewStub
+as the main element of your activity's layout.rectLayout
attribute.roundLayout
@@ -142,7 +146,8 @@ The system inflates the correct layout at runtime depending on the screen shape.
The layouts that you specify for square or round screens are not inflated until
-WatchViewStub detects the shape of the screen, so your app cannot access their views
+WatchViewStub
+detects the shape of the screen, so your app cannot access their views
immediately. To access these views, set a listener in your activity to be notified when
the shape-specific layout has been inflated:
Figure 2. Window insets on a round screen.
-The BoxInsetLayout class included in the Wearable UI Library extends
+
The
+BoxInsetLayout
+class included in the Wearable UI Library extends
{@link android.widget.FrameLayout} and lets you define a single layout that works for both square
and round screens. This class applies the required window insets depending on the screen shape
and lets you easily align views on the center or near the edges of the screen.
The gray square in figure 2 shows the area where BoxInsetLayout can automatically
-place its child views on round screens after applying the required window insets. To be displayed
-inside this area, children views specify the layout_box atribute with these values:
+
The gray square in figure 2 shows the area where
+BoxInsetLayout
+can automatically place its child views on round screens after applying the required window insets.
+To be displayed inside this area, children views specify the layout_box atribute with
+these values:
Figure 3. A layout definition that works on both square and round screens.
-The layout shown in figure 3 uses BoxInsetLayout and works on square and
-round screens:
The layout shown in figure 3 uses the
+<BoxInsetLayout>
+element and works on square and round screens:
<android.support.wearable.view.BoxInsetLayout @@ -243,19 +253,21 @@ round screens:
android:padding="15dp"
This line assigns padding to the BoxInsetLayout element. Because the window
- insets on round devices are larger than 15dp, this padding only applies to square screens.
This line assigns padding to the
+ <BoxInsetLayout>
+ element. Because the window insets on round devices are larger than 15dp, this padding only
+ applies to square screens.
android:padding="5dp"
This line assigns padding to the inner FrameLayout element. This padding applies
- to both square and round screens. The total padding between the buttons and the window insets
- is 20 dp on square screens (15+5) and 5 dp on round screens.
This line assigns padding to the inner {@link android.widget.FrameLayout} element. This padding + applies to both square and round screens. The total padding between the buttons and the window + insets is 20 dp on square screens (15+5) and 5 dp on round screens.
app:layout_box="all"
This line ensures that the FrameLayout element and its children are boxed inside
- the area defined by the window insets on round screens. This line has no effect on square
- screens.
This line ensures that the {@link android.widget.FrameLayout} element and its children are + boxed inside the area defined by the window insets on round screens. This line has no effect on + square screens.
Lists let users select an item from a set of choices easily on wearable devices. This lesson shows you how to create lists in your Android Wear apps.
-The Wearable UI Library includes the WearableListView class, which is a list
-implementation optimized for wearable devices..
Note: The Notifications sample in the Android SDK
-demonstrates how to use WearableListView in your apps. This sample is located in
-the android-sdk/samples/android-20/wearable/Notifications directory.
The Wearable UI Library includes the
+WearableListView
+class, which is a list implementation optimized for wearable devices.
To create a list in your Android Wear apps:
WearableListView element to your activity's layout definition.WearableListView
+element to your activity's layout definition.
-Figure 3: -A list view on Android Wear.
-WearableListView element.WearableListView
+element.
+Figure 1. +A list view on Android Wear.
+These steps are described in detail in the following sections.
The following layout adds a list view to an activity using a BoxInsetLayout, so
-the list is displayed properly on both round and square devices:
The following layout adds a list view to an activity using a
+<BoxInsetLayout>
+element, so the list is displayed properly on both round and square devices:
<android.support.wearable.view.BoxInsetLayout @@ -80,12 +86,14 @@ the list is displayed properly on both round and square devices:Create a Layout Implementation for List Items
In many cases, each list item consists of an icon and a description. The -Notifications sample from the Android SDK implements a custom layout that extends +Notifications sample implements a custom +layout that extends {@link android.widget.LinearLayout} to incorporate these two elements inside each list item. This layout also implements the methods in the -
+WearableListView.OnCenterProximityListener +interface to change the color of the item's icon and fade the text in response to events from the +WearableListView.OnCenterProximityListenerinterface -to change the color of the item's icon and fade the text in response to events from -WearableListViewas the user scrolls through the list.WearableListView+element as the user scrolls through the list.public class WearableListItemLayout extends LinearLayout @@ -141,9 +149,13 @@ public class WearableListItemLayout extends LinearLayoutYou can also create animator objects to enlarge the icon of the center item in the list. You can -use the
@@ -185,7 +197,9 @@ and a text view whose IDs match those in the layout implementation class:onCenterPosition()andonNonCenterPosition()callback methods -in theWearableListView.OnCenterProximityListenerinterface to manage your -animators. For more information about animators, see +use the +onCenterPosition()+and +onNonCenterPosition()+callback methods in the +WearableListView.OnCenterProximityListener+interface to manage your animators. For more information about animators, see Animating with ObjectAnimator.Create an Adapter to Populate the List
-The adapter populates the
WearableListViewwith content. The following simple +The adapter populates the +
WearableListView.OnCenterProximityListener+element with content. The following simple adapter populates the list with elements based on an array of strings:@@ -247,9 +261,10 @@ private static final class Adapter extends WearableListView.Adapter {Associate the Adapter and Set a Click Listener
-In your activity, obtain a reference to the
+WearableListViewelement from -your layout, assign an instance of the adapter to populate the list, and set a click listener -to complete an action when the user selects a particular list item.In your activity, obtain a reference to the +
WearableListView.OnCenterProximityListener+element from your layout, assign an instance of the adapter to populate the list, and set a click +listener to complete an action when the user selects a particular list item.public class WearActivity extends Activity