1 /*
2  * Copyright (C) 2016 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 package com.android.test.uibench;
17 
18 import android.os.Bundle;
19 import android.view.MenuItem;
20 
21 import androidx.appcompat.app.ActionBarDrawerToggle;
22 import androidx.appcompat.app.AppCompatActivity;
23 import androidx.appcompat.widget.Toolbar;
24 import androidx.core.view.GravityCompat;
25 import androidx.drawerlayout.widget.DrawerLayout;
26 
27 import com.google.android.material.navigation.NavigationView;
28 
29 public class NavigationDrawerActivity extends AppCompatActivity
30         implements NavigationView.OnNavigationItemSelectedListener {
31 
32     @Override
onCreate(Bundle savedInstanceState)33     protected void onCreate(Bundle savedInstanceState) {
34         super.onCreate(savedInstanceState);
35         setContentView(R.layout.activity_navigation_drawer);
36         Toolbar toolbar = findViewById(R.id.toolbar);
37         setSupportActionBar(toolbar);
38         DrawerLayout drawer = findViewById(R.id.drawer_layout);
39         ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
40                 this, drawer, toolbar, R.string.navigation_drawer_open,
41                 R.string.navigation_drawer_close);
42         drawer.setDrawerListener(toggle);
43         toggle.syncState();
44 
45         NavigationView navigationView = findViewById(R.id.nav_view);
46         navigationView.setNavigationItemSelectedListener(this);
47     }
48 
49     @Override
onNavigationItemSelected(MenuItem item)50     public boolean onNavigationItemSelected(MenuItem item) {
51         DrawerLayout drawer = findViewById(R.id.drawer_layout);
52         drawer.closeDrawer(GravityCompat.START);
53         return true;
54     }
55 }
56