Stan Iliev | bf25627 | 2017-01-26 13:26:08 -0500 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2017 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; |
Stan Iliev | bf25627 | 2017-01-26 13:26:08 -0500 | [diff] [blame] | 19 | import android.view.MenuItem; |
| 20 | import android.widget.ArrayAdapter; |
| 21 | import android.widget.ListAdapter; |
| 22 | |
Aurimas Liutikas | d113f94 | 2019-01-30 22:08:37 -0800 | [diff] [blame] | 23 | import androidx.appcompat.app.ActionBarDrawerToggle; |
| 24 | import androidx.appcompat.app.AppCompatActivity; |
| 25 | import androidx.appcompat.widget.Toolbar; |
| 26 | import androidx.core.view.GravityCompat; |
| 27 | import androidx.drawerlayout.widget.DrawerLayout; |
| 28 | import androidx.fragment.app.FragmentManager; |
| 29 | import androidx.fragment.app.ListFragment; |
| 30 | |
| 31 | import com.google.android.material.navigation.NavigationView; |
| 32 | |
Stan Iliev | bf25627 | 2017-01-26 13:26:08 -0500 | [diff] [blame] | 33 | public class ClippedListActivity extends AppCompatActivity |
| 34 | implements NavigationView.OnNavigationItemSelectedListener { |
| 35 | |
| 36 | @Override |
| 37 | protected void onCreate(Bundle savedInstanceState) { |
| 38 | super.onCreate(savedInstanceState); |
| 39 | setContentView(R.layout.activity_navigation_drawer); |
Alan Viverette | 51efddb | 2017-04-05 10:00:01 -0400 | [diff] [blame] | 40 | Toolbar toolbar = findViewById(R.id.toolbar); |
Stan Iliev | bf25627 | 2017-01-26 13:26:08 -0500 | [diff] [blame] | 41 | setSupportActionBar(toolbar); |
Alan Viverette | 51efddb | 2017-04-05 10:00:01 -0400 | [diff] [blame] | 42 | DrawerLayout drawer = findViewById(R.id.drawer_layout); |
Stan Iliev | bf25627 | 2017-01-26 13:26:08 -0500 | [diff] [blame] | 43 | ActionBarDrawerToggle toggle = new ActionBarDrawerToggle( |
| 44 | this, drawer, toolbar, R.string.navigation_drawer_open, |
| 45 | R.string.navigation_drawer_close); |
| 46 | drawer.setDrawerListener(toggle); |
| 47 | toggle.syncState(); |
| 48 | |
Alan Viverette | 51efddb | 2017-04-05 10:00:01 -0400 | [diff] [blame] | 49 | NavigationView navigationView = findViewById(R.id.nav_view); |
Stan Iliev | bf25627 | 2017-01-26 13:26:08 -0500 | [diff] [blame] | 50 | navigationView.setNavigationItemSelectedListener(this); |
| 51 | |
| 52 | FragmentManager fm = getSupportFragmentManager(); |
| 53 | if (fm.findFragmentById(android.R.id.content) == null) { |
| 54 | ListFragment listFragment = new ListFragment(); |
| 55 | ListAdapter adapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, |
| 56 | TextUtils.buildSimpleStringList(40)); |
| 57 | listFragment.setListAdapter(adapter); |
| 58 | fm.beginTransaction().add(R.id.app_bar_layout, listFragment).commit(); |
| 59 | } |
| 60 | } |
| 61 | |
| 62 | @Override |
| 63 | public boolean onNavigationItemSelected(MenuItem item) { |
Alan Viverette | 51efddb | 2017-04-05 10:00:01 -0400 | [diff] [blame] | 64 | DrawerLayout drawer = findViewById(R.id.drawer_layout); |
Stan Iliev | bf25627 | 2017-01-26 13:26:08 -0500 | [diff] [blame] | 65 | drawer.closeDrawer(GravityCompat.START); |
| 66 | return true; |
| 67 | } |
| 68 | } |