Merge \"docs: Updated Create custom drawer view section with new xml attributes.\" into mnc-io-docs

am: 9f1952a77b

Change-Id: Ied1d1112ef47428795113ed86d1ed9b1bf5b30d0
This commit is contained in:
sreevanis
2016-07-11 21:07:37 +00:00
committed by android-build-merger

View File

@@ -12,7 +12,7 @@ page.image=/wear/preview/images/card_drawer.png
<ol> <ol>
<li><a href="#create a drawer">Create a Drawer Layout</a></li> <li><a href="#create a drawer">Create a Drawer Layout</a></li>
<li><a href="#initialize">Initialize the Drawer List</a></li> <li><a href="#initialize">Initialize the Drawer List</a></li>
<li><a href="#creating">Create a Custom View Drawer</a></li> <li><a href="#creating">Create a Custom Drawer View</a></li>
<li><a href="#listen to events">Listen for Drawer Events</a></li> <li><a href="#listen to events">Listen for Drawer Events</a></li>
<li><a href=#peeking">Peeking Drawers</a></li> <li><a href=#peeking">Peeking Drawers</a></li>
</ol> </ol>
@@ -37,8 +37,8 @@ page.image=/wear/preview/images/card_drawer.png
</div> </div>
</div> </div>
<p>As part of the <a href="http://www.google.com/design/spec-wear">Material Design</a> <p>As part of the <a href="http://www.google.com/design/spec-wear">Material Design</a>
for Android Wear, Wear 2.0 adds interactive navigation and action drawers. for Android Wear, Wear 2.0 adds interactive navigation and action drawers.
The navigation drawer appears at the top of the screen and lets users jump to The navigation drawer appears at the top of the screen and lets users jump to
different views within different views within
the app, similar to the navigation drawer on a phone. The action drawer appears the app, similar to the navigation drawer on a phone. The action drawer appears
at the bottom of the screen and provides context-specific actions for the user, at the bottom of the screen and provides context-specific actions for the user,
@@ -59,7 +59,8 @@ the opposite direction. </p>
<div class="cols"> <div class="cols">
<p>This lesson describes how to implement action and navigation drawers in your <p>This lesson describes how to implement action and navigation drawers in your
app using the {@code WearableDrawerLayout} APIs. app using the {@code WearableDrawerLayout} APIs. For more information, see the
downloadable <a href="{@docRoot}preview/setup-sdk.html#docs-dl">API reference</a>.
</p> </p>
<h2 id="create a drawer">Create a Drawer Layout</h2> <h2 id="create a drawer">Create a Drawer Layout</h2>
@@ -99,41 +100,44 @@ To add an action or a navigation drawer, declare your user interface with a
&lt;/android.support.wearable.view.drawer.WearableDrawerLayout> &lt;/android.support.wearable.view.drawer.WearableDrawerLayout>
</pre> </pre>
<h2 id="initialize">Initialize the Drawer List</h2> <h2 id="initialize">Initialize the Drawer List</h2>
<p>One of the first things you need to do in your activity is to initialize the <p>One of the first things you need to do in your activity is to initialize the
drawers list of items. You should implement {@code WearableNavigationDrawerAdapter} drawers list of items. You should implement {@code WearableNavigationDrawerAdapter}
to populate the navigation drawer contents. To populate the action drawer with to populate the navigation drawer contents. To populate the action drawer with
a list of actions, inflate an XML file into the Menu (via MenuInflater).</p> a list of actions, inflate an XML file into the Menu (via {@code MenuInflater}).
</p>
<p>The following code snippet shows how to initialize the contents of your drawers: <p>The following code snippet shows how to initialize the contents of your drawers:
</p> </p>
<pre> <pre>
public class MainActivity extends WearableActivity implements public class MainActivity extends WearableActivity implements
WearableActionDrawer.OnMenuItemClickListener{ WearableActionDrawer.OnMenuItemClickListener{
private WearableDrawerLayout mwearableDrawerLayout; private WearableDrawerLayout mwearableDrawerLayout;
private WearableNavigationDrawer mWearableNavigationDrawer; private WearableNavigationDrawer mWearableNavigationDrawer;
private WearableActionDrawer mWearableActionDrawer; private WearableActionDrawer mWearableActionDrawer;
... ...
&#64;Override &#64;Override
public void onCreate(Bundle savedInstanceState) { public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main); setContentView(R.layout.activity_main);
...... ......
// Main Wearable Drawer Layout that wraps all content // Main Wearable Drawer Layout that wraps all content
mWearableDrawerLayout = (WearableDrawerLayout) findViewById(R.id.drawer_layout); mWearableDrawerLayout = (WearableDrawerLayout) findViewById(R.id.drawer_layout);
// Top Navigation Drawer // Top Navigation Drawer
mWearableNavigationDrawer = (WearableNavigationDrawer) findViewById(R.id.top_navigation_drawer); mWearableNavigationDrawer = (WearableNavigationDrawer) findViewById(R.id.top_navigation_drawer);
mWearableNavigationDrawer.setAdapter(new YourImplementationNavigationAdapter(this)); mWearableNavigationDrawer.setAdapter(new YourImplementationNavigationAdapter(this));
// Peeks Navigation drawer on the top. // Peeks Navigation drawer on the top.
mWearableDrawerLayout.peekDrawer(Gravity.TOP); mWearableDrawerLayout.peekDrawer(Gravity.TOP);
// Bottom Action Drawer // Bottom Action Drawer
mWearableActionDrawer = (WearableActionDrawer) findViewById(R.id.bottom_action_drawer); mWearableActionDrawer = (WearableActionDrawer) findViewById(R.id.bottom_action_drawer);
@@ -149,44 +153,58 @@ WearableActionDrawer.OnMenuItemClickListener{
} }
</pre> </pre>
<h2 id="creating">Create a Custom View Drawer</h2>
<p>To use custom views in drawers, add <code>WearableDrawerView</code> to the <h2 id="creating">Create a Custom Drawer View</h2>
<code>WearableDrawerLayout</code>. To set the contents of the drawer, call <code>
<a href="https://x20web.corp.google.com/~psoulos/docs/reference/android/support/wearable/view/drawer/WearableDrawerView.html#setDrawerContent(android.view.View)">setDrawerContent(View)</a></code> <p>To use custom views in drawers, add <code>WearableDrawerView</code> to the
instead of manually adding the view to the hierarchy. You must also specify the <code>WearableDrawerLayout</code>. To set the peek view and drawer contents, add
drawer position with the <code>android:layout_gravity</code> attribute. </p> them as children of the {@code WearableDrawerView} and specify their IDs in the
<p> The following example specifies a top drawer:</p> {@code peek_view} and {@code drawer_content} attributes respectively. You must
also specify the drawer position with the {@code android:layout_gravity}
attribute. </p>
<p> The following example specifies a top drawer with peek view and drawer
contents:</p>
<pre> <pre>
&lt;android.support.wearable.view.drawer.WearableDrawerLayout&gt; &lt;android.support.wearable.view.drawer.WearableDrawerView
&lt;FrameLayout android:layout_width="match_parent"
android:id=”@+id/content” /&gt; android:layout_height="match_parent"
android:layout_gravity="top"
&lt;WearableDrawerView android:background="@color/red"
android:layout_width=”match_parent app:drawer_content="@+id/drawer_content"
andndroid:layout_height=”match_parent” app:peek_view="@+id/peek_view">
android:layout_gravity=”top”&gt; &lt;FrameLayout
&lt;FrameLayout android:id="@id/drawer_content"
android:id=”@+id/top_drawer_content” /&gt; android:layout_width="match_parent"
&lt;/WearableDrawerView&gt; android:layout_height="match_parent">
&lt;/android.support.wearable.view.drawer.WearableDrawerView&gt; &lt;!-- Drawer content goes here. -->
&lt;/FrameLayout>
&lt;LinearLayout
android:id="@id/peek_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:orientation="horizontal">
&lt;!-- Peek view content goes here. -->
&lt;LinearLayout>
&lt;/android.support.wearable.view.drawer.WearableDrawerView>
</pre> </pre>
<h2 id="listen to events">Listen for Drawer Events</h2> <h2 id="listen to events">Listen for Drawer Events</h2>
<p>To listen for drawer events, call {@code setDrawerStateCallback()}on your <p>To listen for drawer events, call {@code setDrawerStateCallback()} on your
{@code WearableDrawerLayout} and pass it an implementation of {@code WearableDrawerLayout} and pass it an implementation of
{@code WearableDrawerLayout.DrawerStateCallback}. This interface provides callbacks {@code WearableDrawerLayout.DrawerStateCallback}. This interface provides callbacks
for drawer events such as <code>onDrawerOpened()</code>, for drawer events such as <code>onDrawerOpened()</code>,
<code>onDrawerClosed(),</code> and <code>onDrawerStatechanged()</code>.</p> <code>onDrawerClosed(),</code> and <code>onDrawerStatechanged()</code>.</p>
<h2 id="peeking">Peeking Drawers</h2> <h2 id="peeking">Peeking Drawers</h2>
<p>To set the drawers to temporarily appear, call <code>peekDrawer()</code> on <p>To set the drawers to temporarily appear, call <code>peekDrawer()</code> on
your {@code WearableDrawerLayout} and pass it the {@code Gravity} of the drawer. your {@code WearableDrawerLayout} and pass it the {@code Gravity} of the drawer.
This feature is especially useful because it allows immediate access to the This feature is especially useful because it allows immediate access to the
alternate drawer views or actions associated with it. </p> alternate drawer views or actions associated with it: </p>
<pre>{@code mWearableDrawerLayout.peekDrawer(Gravity.BOTTOM);}</pre>
<pre>{@code mWearableDrawerLayout.peekDrawer</code>(<code>Gravity.BOTTOM);}</pre>
<p>You can also call {@code setPeekContent()} on your drawer to display a custom
view when the drawer is peeking.</p>