Merge "Add WAD/WND sample to :support-wear-demos" into oc-support-26.1-dev
diff --git a/samples/SupportWearDemos/AndroidManifest.xml b/samples/SupportWearDemos/AndroidManifest.xml
index 4e4fb60..04e3e68 100644
--- a/samples/SupportWearDemos/AndroidManifest.xml
+++ b/samples/SupportWearDemos/AndroidManifest.xml
@@ -20,13 +20,11 @@
 
     <application android:icon="@drawable/app_sample_code" android:label="SupportWearDemos"
             android:theme="@android:style/Theme.DeviceDefault">
-        <activity android:name="com.example.android.support.wear.app.SimpleWearableRecyclerViewDemo">
-        </activity>
-        <activity android:name="com.example.android.support.wear.app.WearableSwitchDemo">
-        </activity>
-        <activity android:name="com.example.android.support.wear.app.CircularProgressLayoutDemo">
-        </activity>
-        <activity android:name="com.example.android.support.wear.app.MainDemoActivity">
+        <activity android:name=".app.SimpleWearableRecyclerViewDemo" />
+        <activity android:name=".app.WearableSwitchDemo" />
+        <activity android:name=".app.CircularProgressLayoutDemo" />
+        <activity android:name=".app.drawers.WearableDrawersDemo" android:exported="true" />
+        <activity android:name=".app.MainDemoActivity">
             <intent-filter>
                 <action android:name="android.intent.action.MAIN" />
                 <category android:name="android.intent.category.LAUNCHER" />
diff --git a/samples/SupportWearDemos/build.gradle b/samples/SupportWearDemos/build.gradle
index d9d7e29..df63aac 100644
--- a/samples/SupportWearDemos/build.gradle
+++ b/samples/SupportWearDemos/build.gradle
@@ -49,8 +49,8 @@
     }
 
     compileOptions {
-        sourceCompatibility JavaVersion.VERSION_1_7
-        targetCompatibility JavaVersion.VERSION_1_7
+        sourceCompatibility JavaVersion.VERSION_1_8
+        targetCompatibility JavaVersion.VERSION_1_8
     }
 }
 
diff --git a/samples/SupportWearDemos/res/layout/wearable_drawers_demo.xml b/samples/SupportWearDemos/res/layout/wearable_drawers_demo.xml
new file mode 100644
index 0000000..27843e0
--- /dev/null
+++ b/samples/SupportWearDemos/res/layout/wearable_drawers_demo.xml
@@ -0,0 +1,39 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+  ~ Copyright (C) 2017 The Android Open Source Project
+  ~
+  ~ Licensed under the Apache License, Version 2.0 (the "License");
+  ~ you may not use this file except in compliance with the License.
+  ~ You may obtain a copy of the License at
+  ~
+  ~      http://www.apache.org/licenses/LICENSE-2.0
+  ~
+  ~ Unless required by applicable law or agreed to in writing, software
+  ~ distributed under the License is distributed on an "AS IS" BASIS,
+  ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  ~ See the License for the specific language governing permissions and
+  ~ limitations under the License.
+  -->
+
+<android.support.wear.widget.drawer.WearableDrawerLayout
+    xmlns:android="http://schemas.android.com/apk/res/android"
+    xmlns:app="http://schemas.android.com/apk/res-auto"
+    android:layout_width="match_parent"
+    android:layout_height="match_parent">
+
+    <FrameLayout
+        android:id="@+id/fragment_container"
+        android:layout_width="match_parent"
+        android:layout_height="match_parent" />
+
+    <android.support.wear.widget.drawer.WearableNavigationDrawerView
+        android:id="@+id/nav_drawer"
+        android:layout_width="match_parent"
+        android:layout_height="match_parent" />
+
+    <android.support.wear.widget.drawer.WearableActionDrawerView
+        android:id="@+id/action_drawer"
+        android:layout_width="match_parent"
+        android:layout_height="match_parent"
+        app:actionMenu="@menu/action_drawer_menu" />
+</android.support.wear.widget.drawer.WearableDrawerLayout>
diff --git a/samples/SupportWearDemos/res/layout/wearable_drawers_frame_layout_demo.xml b/samples/SupportWearDemos/res/layout/wearable_drawers_frame_layout_demo.xml
new file mode 100644
index 0000000..90e3d42
--- /dev/null
+++ b/samples/SupportWearDemos/res/layout/wearable_drawers_frame_layout_demo.xml
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+  ~ Copyright (C) 2017 The Android Open Source Project
+  ~
+  ~ Licensed under the Apache License, Version 2.0 (the "License");
+  ~ you may not use this file except in compliance with the License.
+  ~ You may obtain a copy of the License at
+  ~
+  ~      http://www.apache.org/licenses/LICENSE-2.0
+  ~
+  ~ Unless required by applicable law or agreed to in writing, software
+  ~ distributed under the License is distributed on an "AS IS" BASIS,
+  ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  ~ See the License for the specific language governing permissions and
+  ~ limitations under the License.
+  -->
+
+<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    android:layout_width="match_parent"
+    android:layout_height="match_parent">
+
+    <TextView
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:layout_gravity="center"
+        android:text="FrameLayout"/>
+
+</FrameLayout>
diff --git a/samples/SupportWearDemos/res/layout/wearable_drawers_scroll_view_demo.xml b/samples/SupportWearDemos/res/layout/wearable_drawers_scroll_view_demo.xml
new file mode 100644
index 0000000..9b58bbc
--- /dev/null
+++ b/samples/SupportWearDemos/res/layout/wearable_drawers_scroll_view_demo.xml
@@ -0,0 +1,47 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+  ~ Copyright (C) 2017 The Android Open Source Project
+  ~
+  ~ Licensed under the Apache License, Version 2.0 (the "License");
+  ~ you may not use this file except in compliance with the License.
+  ~ You may obtain a copy of the License at
+  ~
+  ~      http://www.apache.org/licenses/LICENSE-2.0
+  ~
+  ~ Unless required by applicable law or agreed to in writing, software
+  ~ distributed under the License is distributed on an "AS IS" BASIS,
+  ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  ~ See the License for the specific language governing permissions and
+  ~ limitations under the License.
+  -->
+
+<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
+    android:layout_width="match_parent"
+    android:layout_height="match_parent"
+    android:nestedScrollingEnabled="true">
+
+    <LinearLayout
+        android:layout_width="match_parent"
+        android:layout_height="wrap_content"
+        android:orientation="vertical">
+        <TextView
+            android:layout_width="match_parent"
+            android:layout_height="wrap_content"
+            android:gravity="center"
+            android:paddingTop="30dp"
+            android:paddingStart="30dp"
+            android:paddingEnd="30dp"
+            android:paddingBottom="10dp"
+            android:text="ScrollView Fragment"
+            style="@android:style/TextAppearance.Material.Title"/>
+        <TextView
+            android:layout_width="match_parent"
+            android:layout_height="wrap_content"
+            android:paddingBottom="30dp"
+            android:paddingStart="30dp"
+            android:paddingEnd="30dp"
+            android:text="@string/lorem_ipsum"
+            style="@android:style/TextAppearance.Material.Body1"/>
+    </LinearLayout>
+
+</ScrollView>
diff --git a/samples/SupportWearDemos/res/menu/action_drawer_menu.xml b/samples/SupportWearDemos/res/menu/action_drawer_menu.xml
new file mode 100644
index 0000000..ba81111
--- /dev/null
+++ b/samples/SupportWearDemos/res/menu/action_drawer_menu.xml
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="utf-8"?>
+<menu xmlns:android="http://schemas.android.com/apk/res/android">
+    <item android:title="Item 1" android:icon="@android:drawable/ic_menu_add"/>
+    <item android:title="Item 2" android:icon="@android:drawable/ic_menu_agenda"/>
+    <item android:title="Item 3" android:icon="@android:drawable/ic_menu_call"/>
+    <item android:title="Item 4" android:icon="@android:drawable/ic_menu_delete"/>
+</menu>
\ No newline at end of file
diff --git a/samples/SupportWearDemos/res/values/strings.xml b/samples/SupportWearDemos/res/values/strings.xml
index 7f92211..d0156bf 100644
--- a/samples/SupportWearDemos/res/values/strings.xml
+++ b/samples/SupportWearDemos/res/values/strings.xml
@@ -19,4 +19,11 @@
     <string name="cpl_click_me">Click me!</string>
     <string name="cpl_clicked">Clicked!</string>
     <string name="cpl_finished">Finished!</string>
+    <string name="lorem_ipsum">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do
+        eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis
+        nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute
+        irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.
+        Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit
+        anim id est laborum.
+    </string>
 </resources>
\ No newline at end of file
diff --git a/samples/SupportWearDemos/src/com/example/android/support/wear/app/MainDemoActivity.java b/samples/SupportWearDemos/src/com/example/android/support/wear/app/MainDemoActivity.java
index 313457b..154b14f 100644
--- a/samples/SupportWearDemos/src/com/example/android/support/wear/app/MainDemoActivity.java
+++ b/samples/SupportWearDemos/src/com/example/android/support/wear/app/MainDemoActivity.java
@@ -27,6 +27,8 @@
 import android.view.ViewGroup;
 import android.widget.Button;
 
+import com.example.android.support.wear.app.drawers.WearableDrawersDemo;
+
 import java.util.HashMap;
 import java.util.Map;
 
@@ -56,6 +58,8 @@
                 this, WearableSwitchDemo.class));
         contentMap.put("Circular Progress Layout", new Intent(
                 this, CircularProgressLayoutDemo.class));
+        contentMap.put("Wearable Drawers", new Intent(
+                this, WearableDrawersDemo.class));
 
         return contentMap;
     }
diff --git a/samples/SupportWearDemos/src/com/example/android/support/wear/app/drawers/DemoNavDrawerAdapter.java b/samples/SupportWearDemos/src/com/example/android/support/wear/app/drawers/DemoNavDrawerAdapter.java
new file mode 100644
index 0000000..f8d0955
--- /dev/null
+++ b/samples/SupportWearDemos/src/com/example/android/support/wear/app/drawers/DemoNavDrawerAdapter.java
@@ -0,0 +1,45 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.example.android.support.wear.app.drawers;
+
+import android.graphics.drawable.Drawable;
+import android.support.wear.widget.drawer.WearableNavigationDrawerView.WearableNavigationDrawerAdapter;
+
+/** Simple and declarative {@link WearableNavigationDrawerAdapter}. */
+public class DemoNavDrawerAdapter extends WearableNavigationDrawerAdapter {
+
+    private final NavItem[] mNavItems;
+
+    public DemoNavDrawerAdapter(NavItem[] navItems) {
+        mNavItems = navItems;
+    }
+
+    @Override
+    public CharSequence getItemText(int pos) {
+        return mNavItems[pos].getTitle();
+    }
+
+    @Override
+    public Drawable getItemDrawable(int pos) {
+        return mNavItems[pos].getDrawable();
+    }
+
+    @Override
+    public int getCount() {
+        return mNavItems.length;
+    }
+}
diff --git a/samples/SupportWearDemos/src/com/example/android/support/wear/app/drawers/FrameLayoutFragment.java b/samples/SupportWearDemos/src/com/example/android/support/wear/app/drawers/FrameLayoutFragment.java
new file mode 100644
index 0000000..d2be3e8
--- /dev/null
+++ b/samples/SupportWearDemos/src/com/example/android/support/wear/app/drawers/FrameLayoutFragment.java
@@ -0,0 +1,35 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.example.android.support.wear.app.drawers;
+
+import android.app.Fragment;
+import android.os.Bundle;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+
+import com.example.android.support.wear.R;
+
+/** {@link Fragment} which contains a {@link android.widget.FrameLayout} */
+public class FrameLayoutFragment extends Fragment {
+
+    @Override
+    public View onCreateView(LayoutInflater inflater, ViewGroup container,
+            Bundle savedInstanceState) {
+        return inflater.inflate(R.layout.wearable_drawers_frame_layout_demo, container, false);
+    }
+}
diff --git a/samples/SupportWearDemos/src/com/example/android/support/wear/app/drawers/NavItem.java b/samples/SupportWearDemos/src/com/example/android/support/wear/app/drawers/NavItem.java
new file mode 100644
index 0000000..8e65d2c
--- /dev/null
+++ b/samples/SupportWearDemos/src/com/example/android/support/wear/app/drawers/NavItem.java
@@ -0,0 +1,45 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.example.android.support.wear.app.drawers;
+
+import android.app.Fragment;
+import android.graphics.drawable.Drawable;
+
+/** Represents one top-level navigational item. */
+public class NavItem {
+    private final Class<? extends Fragment> mFragment;
+    private final String mTitle;
+    private final Drawable mDrawable;
+
+    public NavItem(Class<? extends Fragment> fragment, String title, Drawable drawable) {
+        mFragment = fragment;
+        mTitle = title;
+        mDrawable = drawable;
+    }
+
+    public Class<? extends Fragment> getFragment() {
+        return mFragment;
+    }
+
+    public String getTitle() {
+        return mTitle;
+    }
+
+    public Drawable getDrawable() {
+        return mDrawable;
+    }
+}
diff --git a/samples/SupportWearDemos/src/com/example/android/support/wear/app/drawers/ScrollViewFragment.java b/samples/SupportWearDemos/src/com/example/android/support/wear/app/drawers/ScrollViewFragment.java
new file mode 100644
index 0000000..2b9ac40
--- /dev/null
+++ b/samples/SupportWearDemos/src/com/example/android/support/wear/app/drawers/ScrollViewFragment.java
@@ -0,0 +1,35 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.example.android.support.wear.app.drawers;
+
+import android.app.Fragment;
+import android.os.Bundle;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+
+import com.example.android.support.wear.R;
+
+/** {@link Fragment} which contains a {@link android.widget.ScrollView} */
+public class ScrollViewFragment extends Fragment {
+
+    @Override
+    public View onCreateView(LayoutInflater inflater, ViewGroup container,
+            Bundle savedInstanceState) {
+        return inflater.inflate(R.layout.wearable_drawers_scroll_view_demo, container, false);
+    }
+}
diff --git a/samples/SupportWearDemos/src/com/example/android/support/wear/app/drawers/WearableDrawersDemo.java b/samples/SupportWearDemos/src/com/example/android/support/wear/app/drawers/WearableDrawersDemo.java
new file mode 100644
index 0000000..c7c79a3
--- /dev/null
+++ b/samples/SupportWearDemos/src/com/example/android/support/wear/app/drawers/WearableDrawersDemo.java
@@ -0,0 +1,85 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.example.android.support.wear.app.drawers;
+
+import android.app.Activity;
+import android.app.Fragment;
+import android.os.Bundle;
+import android.support.wear.widget.drawer.WearableActionDrawerView;
+import android.support.wear.widget.drawer.WearableNavigationDrawerView;
+import android.util.Log;
+import android.view.MenuItem;
+import android.widget.Toast;
+
+import com.example.android.support.wear.R;
+
+/** Main {@link Activity} for demoing the Wearable Drawers. */
+public class WearableDrawersDemo extends Activity {
+    private static final String TAG = "WearableDrawersDemo";
+
+    private WearableNavigationDrawerView mNavDrawer;
+    private WearableActionDrawerView mActionDrawer;
+    private NavItem[] mNavItems;
+
+    @Override
+    protected void onCreate(Bundle savedInstanceState) {
+        super.onCreate(savedInstanceState);
+        setContentView(R.layout.wearable_drawers_demo);
+        mNavItems = new NavItem[] {
+                new NavItem(
+                        ScrollViewFragment.class,
+                        "ScrollView",
+                        getDrawable(android.R.drawable.star_big_off)),
+                new NavItem(
+                        FrameLayoutFragment.class,
+                        "FrameLayout",
+                        getDrawable(android.R.drawable.star_big_on)),
+        };
+
+        onNavItemSelected(0);
+
+        mNavDrawer = findViewById(R.id.nav_drawer);
+        mNavDrawer.setAdapter(new DemoNavDrawerAdapter(mNavItems));
+        mNavDrawer.addOnItemSelectedListener(this::onNavItemSelected);
+        mNavDrawer.getController().peekDrawer();
+
+        mActionDrawer = findViewById(R.id.action_drawer);
+        mActionDrawer.setOnMenuItemClickListener(this::onActionClicked);
+        mActionDrawer.getController().peekDrawer();
+    }
+
+    private boolean onActionClicked(MenuItem menuItem) {
+        Toast.makeText(this, menuItem.getTitle() + " clicked", Toast.LENGTH_SHORT).show();
+        mActionDrawer.getController().peekDrawer();
+        return true;
+    }
+
+    private void onNavItemSelected(int pos) {
+        Fragment fragment;
+        try {
+            fragment = mNavItems[pos].getFragment().newInstance();
+        } catch (InstantiationException | IllegalAccessException e) {
+            Log.e(TAG, "Failed to instantiate fragment", e);
+            return;
+        }
+
+        getFragmentManager()
+                .beginTransaction()
+                .replace(R.id.fragment_container, fragment)
+                .commit();
+    }
+}