Merge "Add NavigationView usage to SupportDesignDemos" into lmp-mr1-ub-dev
diff --git a/samples/SupportDesignDemos/AndroidManifest.xml b/samples/SupportDesignDemos/AndroidManifest.xml
index f998dcc..8fcdf38 100644
--- a/samples/SupportDesignDemos/AndroidManifest.xml
+++ b/samples/SupportDesignDemos/AndroidManifest.xml
@@ -45,6 +45,15 @@
             </intent-filter>
         </activity>
 
+        <activity android:name=".widget.NavigationViewUsage"
+                  android:label="@string/design_navigation"
+                  android:theme="@style/Theme.Navigation">
+            <intent-filter>
+                <action android:name="android.intent.action.MAIN" />
+                <category android:name="com.example.android.support.design.SAMPLE_CODE" />
+            </intent-filter>
+        </activity>
+
         <activity android:name=".widget.TabLayoutUsage"
                   android:label="@string/design_tabs_basic"
                   android:theme="@style/Theme.Design">
diff --git a/samples/SupportDesignDemos/res/drawable-hdpi/ic_action_navigation_menu.png b/samples/SupportDesignDemos/res/drawable-hdpi/ic_action_navigation_menu.png
new file mode 100644
index 0000000..743fd7d
--- /dev/null
+++ b/samples/SupportDesignDemos/res/drawable-hdpi/ic_action_navigation_menu.png
Binary files differ
diff --git a/samples/SupportDesignDemos/res/drawable-hdpi/ic_android.png b/samples/SupportDesignDemos/res/drawable-hdpi/ic_android.png
new file mode 100644
index 0000000..94b8fb1
--- /dev/null
+++ b/samples/SupportDesignDemos/res/drawable-hdpi/ic_android.png
Binary files differ
diff --git a/samples/SupportDesignDemos/res/drawable-mdpi/ic_action_navigation_menu.png b/samples/SupportDesignDemos/res/drawable-mdpi/ic_action_navigation_menu.png
new file mode 100644
index 0000000..4fa2c22
--- /dev/null
+++ b/samples/SupportDesignDemos/res/drawable-mdpi/ic_action_navigation_menu.png
Binary files differ
diff --git a/samples/SupportDesignDemos/res/drawable-mdpi/ic_android.png b/samples/SupportDesignDemos/res/drawable-mdpi/ic_android.png
new file mode 100644
index 0000000..afc43db
--- /dev/null
+++ b/samples/SupportDesignDemos/res/drawable-mdpi/ic_android.png
Binary files differ
diff --git a/samples/SupportDesignDemos/res/drawable-xhdpi/ic_action_navigation_menu.png b/samples/SupportDesignDemos/res/drawable-xhdpi/ic_action_navigation_menu.png
new file mode 100644
index 0000000..595da84
--- /dev/null
+++ b/samples/SupportDesignDemos/res/drawable-xhdpi/ic_action_navigation_menu.png
Binary files differ
diff --git a/samples/SupportDesignDemos/res/drawable-xhdpi/ic_android.png b/samples/SupportDesignDemos/res/drawable-xhdpi/ic_android.png
new file mode 100644
index 0000000..74c6f68
--- /dev/null
+++ b/samples/SupportDesignDemos/res/drawable-xhdpi/ic_android.png
Binary files differ
diff --git a/samples/SupportDesignDemos/res/drawable-xxhdpi/ic_action_navigation_menu.png b/samples/SupportDesignDemos/res/drawable-xxhdpi/ic_action_navigation_menu.png
new file mode 100644
index 0000000..3ebee24
--- /dev/null
+++ b/samples/SupportDesignDemos/res/drawable-xxhdpi/ic_action_navigation_menu.png
Binary files differ
diff --git a/samples/SupportDesignDemos/res/drawable-xxhdpi/ic_android.png b/samples/SupportDesignDemos/res/drawable-xxhdpi/ic_android.png
new file mode 100644
index 0000000..5cb6acd
--- /dev/null
+++ b/samples/SupportDesignDemos/res/drawable-xxhdpi/ic_android.png
Binary files differ
diff --git a/samples/SupportDesignDemos/res/drawable-xxxhdpi/ic_android.png b/samples/SupportDesignDemos/res/drawable-xxxhdpi/ic_android.png
new file mode 100644
index 0000000..e302a07
--- /dev/null
+++ b/samples/SupportDesignDemos/res/drawable-xxxhdpi/ic_android.png
Binary files differ
diff --git a/samples/SupportDesignDemos/res/layout/design_navigation.xml b/samples/SupportDesignDemos/res/layout/design_navigation.xml
new file mode 100644
index 0000000..22e900a
--- /dev/null
+++ b/samples/SupportDesignDemos/res/layout/design_navigation.xml
@@ -0,0 +1,55 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+     Copyright (C) 2015 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.v4.widget.DrawerLayout
+        xmlns:android="http://schemas.android.com/apk/res/android"
+        xmlns:app="http://schemas.android.com/apk/res-auto"
+        android:id="@+id/drawer_layout"
+        android:layout_width="match_parent"
+        android:layout_height="match_parent"
+        android:fitsSystemWindows="true">
+
+    <LinearLayout
+            android:layout_width="match_parent"
+            android:layout_height="match_parent"
+            android:orientation="vertical">
+
+        <android.support.v7.widget.Toolbar
+                android:id="@+id/toolbar"
+                android:layout_height="wrap_content"
+                android:layout_width="match_parent"
+                android:minHeight="?attr/actionBarSize"
+                android:background="?attr/colorPrimary"
+                android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
+                app:popupTheme="@style/ThemeOverlay.AppCompat.Light"/>
+
+        <TextView
+                android:id="@+id/message"
+                android:layout_width="match_parent"
+                android:layout_height="match_parent"
+                android:gravity="center"
+                android:text="@string/navigation_1"
+                android:textAppearance="?android:attr/textAppearanceLarge"/>
+
+    </LinearLayout>
+
+    <android.support.design.widget.NavigationView
+            android:id="@+id/navigation"
+            android:layout_width="wrap_content"
+            android:layout_height="match_parent"
+            android:layout_gravity="start"/>
+
+</android.support.v4.widget.DrawerLayout>
diff --git a/samples/SupportDesignDemos/res/layout/design_navigation_header.xml b/samples/SupportDesignDemos/res/layout/design_navigation_header.xml
new file mode 100644
index 0000000..a03f0bb
--- /dev/null
+++ b/samples/SupportDesignDemos/res/layout/design_navigation_header.xml
@@ -0,0 +1,26 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+     Copyright (C) 2015 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.
+-->
+
+<TextView xmlns:android="http://schemas.android.com/apk/res/android"
+          android:layout_width="match_parent"
+          android:layout_height="wrap_content"
+          android:minHeight="180dp"
+          android:padding="16dp"
+          android:background="?attr/colorPrimary"
+          android:gravity="bottom|start"
+          android:text="@string/navigation_header"
+          android:textAppearance="?android:attr/textAppearanceLargeInverse"/>
diff --git a/samples/SupportDesignDemos/res/menu/navigation.xml b/samples/SupportDesignDemos/res/menu/navigation.xml
new file mode 100644
index 0000000..b399ef3
--- /dev/null
+++ b/samples/SupportDesignDemos/res/menu/navigation.xml
@@ -0,0 +1,71 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+     Copyright (C) 2015 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.
+-->
+<menu xmlns:android="http://schemas.android.com/apk/res/android">
+
+    <!-- Main items -->
+    <group android:checkableBehavior="single">
+        <item
+                android:id="@+id/navigation_item_1"
+                android:checked="true"
+                android:icon="@drawable/ic_android"
+                android:title="@string/navigation_item_1"/>
+        <item
+                android:id="@+id/navigation_item_2"
+                android:icon="@drawable/ic_android"
+                android:title="@string/navigation_item_2"/>
+        <item
+                android:id="@+id/navigation_item_3"
+                android:icon="@drawable/ic_android"
+                android:title="@string/navigation_item_3"/>
+        <item
+                android:id="@+id/navigation_item_disabled"
+                android:icon="@drawable/ic_android"
+                android:title="@string/navigation_item_4"
+                android:enabled="false"/>
+        <item
+                android:id="@+id/navigation_invisible"
+                android:icon="@drawable/ic_android"
+                android:title="@string/navigation_invisible"
+                android:visible="false"/>
+    </group>
+
+    <item
+            android:id="@+id/navigation_subheader"
+            android:title="@string/navigation_subheader">
+        <menu>
+            <item
+                    android:id="@+id/navigation_sub_item_1"
+                    android:icon="@drawable/ic_android"
+                    android:title="@string/navigation_sub_item_1"/>
+            <item
+                    android:id="@+id/navigation_sub_item_2"
+                    android:icon="@drawable/ic_android"
+                    android:title="@string/navigation_sub_item_2"/>
+        </menu>
+    </item>
+
+    <group android:id="@+id/aligned_items">
+        <item
+                android:id="@+id/navigation_with_icon"
+                android:icon="@drawable/ic_android"
+                android:title="@string/navigation_item_with_icon"/>
+        <item
+                android:id="@+id/navigation_without_icon"
+                android:title="@string/navigation_item_without_icon"/>
+    </group>
+
+</menu>
diff --git a/samples/SupportDesignDemos/res/values-v21/styles.xml b/samples/SupportDesignDemos/res/values-v21/styles.xml
new file mode 100644
index 0000000..8faf5e6
--- /dev/null
+++ b/samples/SupportDesignDemos/res/values-v21/styles.xml
@@ -0,0 +1,25 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+     Copyright (C) 2015 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.
+-->
+
+<resources>
+
+    <style name="Theme.Navigation" parent="Theme.Navigation.Base">
+        <item name="android:statusBarColor">@android:color/transparent</item>
+        <item name="android:windowDrawsSystemBarBackgrounds">true</item>
+    </style>
+
+</resources>
diff --git a/samples/SupportDesignDemos/res/values/strings.xml b/samples/SupportDesignDemos/res/values/strings.xml
index 7bcfb81..b2cb6d7 100644
--- a/samples/SupportDesignDemos/res/values/strings.xml
+++ b/samples/SupportDesignDemos/res/values/strings.xml
@@ -18,12 +18,29 @@
     <string name="activity_sample_code">Support Design Demos</string>
 
     <string name="design_fab">Floating Action Button/Basic</string>
+    <string name="design_navigation">NavigationView/Usage</string>
     <string name="design_tabs_basic">TabLayout/Usage</string>
     <string name="design_text_input">Text Input</string>
 
     <string name="fab_size_normal">Normal size</string>
     <string name="fab_size_mini">Mini size</string>
 
+    <string name="navigation_open">Open</string>
+    <string name="navigation_close">Close</string>
+    <string name="navigation_item_with_icon">Item with icon</string>
+    <string name="navigation_item_without_icon">Item without icon</string>
+    <string name="navigation_message">Clicked: \"%s\"</string>
+    <string name="navigation_header">Header</string>
+    <string name="navigation_item_1">Item 1</string>
+    <string name="navigation_item_2">Item 2</string>
+    <string name="navigation_item_3">Item 3</string>
+    <string name="navigation_item_4">Item 4 (disabled)</string>
+    <string name="navigation_1">1</string>
+    <string name="navigation_invisible">Invisible</string>
+    <string name="navigation_subheader">Subheader</string>
+    <string name="navigation_sub_item_1">Subitem 1</string>
+    <string name="navigation_sub_item_2">Subitem 2</string>
+
     <string name="tabs_fixed">Fixed</string>
     <string name="tabs_scrollable">Scrollable</string>
     <string name="tabs_gravity_center">Center</string>
diff --git a/samples/SupportDesignDemos/res/values/styles.xml b/samples/SupportDesignDemos/res/values/styles.xml
index ec05888..a63f93f 100644
--- a/samples/SupportDesignDemos/res/values/styles.xml
+++ b/samples/SupportDesignDemos/res/values/styles.xml
@@ -30,4 +30,17 @@
         <item name="colorAccent">#ff0000</item>
     </style>
 
+    <style name="Theme.Navigation.Base" parent="Theme.AppCompat.Light.NoActionBar">
+        <item name="colorPrimary">#607D8B</item>
+        <item name="colorPrimaryDark">#455A64</item>
+        <item name="colorAccent">#FFAB40</item>
+        <item name="drawerArrowStyle">@style/DrawerArrowStyle</item>
+    </style>
+
+    <style name="DrawerArrowStyle" parent="Widget.AppCompat.DrawerArrowToggle">
+        <item name="spinBars">false</item>
+    </style>
+
+    <style name="Theme.Navigation" parent="Theme.Navigation.Base"/>
+
 </resources>
\ No newline at end of file
diff --git a/samples/SupportDesignDemos/src/com/example/android/support/design/widget/NavigationViewUsage.java b/samples/SupportDesignDemos/src/com/example/android/support/design/widget/NavigationViewUsage.java
new file mode 100644
index 0000000..46a57b5
--- /dev/null
+++ b/samples/SupportDesignDemos/src/com/example/android/support/design/widget/NavigationViewUsage.java
@@ -0,0 +1,132 @@
+/*
+ * Copyright (C) 2015 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.design.widget;
+
+import com.example.android.support.design.R;
+
+import android.os.Bundle;
+import android.support.design.widget.NavigationView;
+import android.support.v4.view.GravityCompat;
+import android.support.v4.widget.DrawerLayout;
+import android.support.v7.app.AppCompatActivity;
+import android.support.v7.widget.Toolbar;
+import android.util.TypedValue;
+import android.view.MenuItem;
+import android.view.View;
+import android.widget.TextView;
+import android.widget.Toast;
+
+/**
+ * This demonstrates basic usage of NavigationView
+ */
+public class NavigationViewUsage extends AppCompatActivity {
+
+    private DrawerLayout mDrawerLayout;
+
+    private TextView mTextMessage;
+
+    @Override
+    protected void onCreate(Bundle savedInstanceState) {
+        super.onCreate(savedInstanceState);
+        setContentView(R.layout.design_navigation);
+
+        mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
+        mTextMessage = (TextView) findViewById(R.id.message);
+
+        // Set the color of status bar
+        TypedValue value = new TypedValue();
+        getTheme().resolveAttribute(R.attr.colorPrimaryDark, value, true);
+        mDrawerLayout.setStatusBarBackgroundColor(value.data);
+
+        // Retrieve the Toolbar from our content view, and set it as the action bar
+        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
+        setSupportActionBar(toolbar);
+
+        // Toggle icon
+        toolbar.setNavigationIcon(R.drawable.ic_action_navigation_menu);
+        toolbar.setNavigationOnClickListener(new View.OnClickListener() {
+            @Override
+            public void onClick(View view) {
+                mDrawerLayout.openDrawer(GravityCompat.START);
+            }
+        });
+
+        // Menu
+        NavigationView navigation = (NavigationView) findViewById(R.id.navigation);
+        getMenuInflater().inflate(R.menu.navigation, navigation.getMenu());
+        navigation.setNavigationItemSelectedListener(mNavigationItemSelectedListener);
+        navigation.inflateHeaderView(R.layout.design_navigation_header);
+    }
+
+    private NavigationView.OnNavigationItemSelectedListener mNavigationItemSelectedListener
+            = new NavigationView.OnNavigationItemSelectedListener() {
+        @Override
+        public boolean onNavigationItemSelected(MenuItem item) {
+            if (handleNavigationItemSelected(item)) {
+                mDrawerLayout.closeDrawers();
+                return true;
+            }
+            return false;
+        }
+    };
+
+    private boolean handleNavigationItemSelected(MenuItem item) {
+        switch (item.getItemId()) {
+            case R.id.navigation_item_1:
+                mTextMessage.setText("1");
+                item.setChecked(true);
+                return true;
+            case R.id.navigation_item_2:
+                mTextMessage.setText("2");
+                item.setChecked(true);
+                return true;
+            case R.id.navigation_item_3:
+                mTextMessage.setText("3");
+                item.setChecked(true);
+                return true;
+            case R.id.navigation_sub_item_1:
+                showToast(R.string.navigation_sub_item_1);
+                return true;
+            case R.id.navigation_sub_item_2:
+                showToast(R.string.navigation_sub_item_2);
+                return true;
+            case R.id.navigation_with_icon:
+                showToast(R.string.navigation_item_with_icon);
+                return true;
+            case R.id.navigation_without_icon:
+                showToast(R.string.navigation_item_without_icon);
+                return true;
+            default:
+                return false;
+        }
+    }
+
+    private void showToast(int res) {
+        Toast.makeText(this, getString(R.string.navigation_message, getString(res)),
+                Toast.LENGTH_SHORT).show();
+    }
+
+    @Override
+    public void onBackPressed() {
+        if (mDrawerLayout.isDrawerOpen(GravityCompat.START)) {
+            mDrawerLayout.closeDrawer(GravityCompat.START);
+        } else {
+            super.onBackPressed();
+        }
+    }
+
+}