blob: 2bf6040351b85408d21971077b2a45e7aa2fd2c2 [file] [log] [blame]
Stan Ilievbf256272017-01-26 13:26:08 -05001/*
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 */
16package com.android.test.uibench;
17
18import android.os.Bundle;
Stan Ilievbf256272017-01-26 13:26:08 -050019import android.view.MenuItem;
20import android.widget.ArrayAdapter;
21import android.widget.ListAdapter;
22
Aurimas Liutikasd113f942019-01-30 22:08:37 -080023import androidx.appcompat.app.ActionBarDrawerToggle;
24import androidx.appcompat.app.AppCompatActivity;
25import androidx.appcompat.widget.Toolbar;
26import androidx.core.view.GravityCompat;
27import androidx.drawerlayout.widget.DrawerLayout;
28import androidx.fragment.app.FragmentManager;
29import androidx.fragment.app.ListFragment;
30
31import com.google.android.material.navigation.NavigationView;
32
Stan Ilievbf256272017-01-26 13:26:08 -050033public 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 Viverette51efddb2017-04-05 10:00:01 -040040 Toolbar toolbar = findViewById(R.id.toolbar);
Stan Ilievbf256272017-01-26 13:26:08 -050041 setSupportActionBar(toolbar);
Alan Viverette51efddb2017-04-05 10:00:01 -040042 DrawerLayout drawer = findViewById(R.id.drawer_layout);
Stan Ilievbf256272017-01-26 13:26:08 -050043 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 Viverette51efddb2017-04-05 10:00:01 -040049 NavigationView navigationView = findViewById(R.id.nav_view);
Stan Ilievbf256272017-01-26 13:26:08 -050050 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 Viverette51efddb2017-04-05 10:00:01 -040064 DrawerLayout drawer = findViewById(R.id.drawer_layout);
Stan Ilievbf256272017-01-26 13:26:08 -050065 drawer.closeDrawer(GravityCompat.START);
66 return true;
67 }
68}