Home | History | Annotate | Download | only in uibench
      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;
     19 import android.support.design.widget.NavigationView;
     20 import android.support.v4.app.FragmentManager;
     21 import android.support.v4.app.ListFragment;
     22 import android.support.v4.view.GravityCompat;
     23 import android.support.v4.widget.DrawerLayout;
     24 import android.support.v7.app.ActionBarDrawerToggle;
     25 import android.support.v7.app.AppCompatActivity;
     26 import android.support.v7.widget.Toolbar;
     27 import android.view.MenuItem;
     28 import android.widget.ArrayAdapter;
     29 import android.widget.ListAdapter;
     30 
     31 public class ClippedListActivity extends AppCompatActivity
     32         implements NavigationView.OnNavigationItemSelectedListener {
     33 
     34     @Override
     35     protected void onCreate(Bundle savedInstanceState) {
     36         super.onCreate(savedInstanceState);
     37         setContentView(R.layout.activity_navigation_drawer);
     38         Toolbar toolbar = findViewById(R.id.toolbar);
     39         setSupportActionBar(toolbar);
     40         DrawerLayout drawer = findViewById(R.id.drawer_layout);
     41         ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
     42                 this, drawer, toolbar, R.string.navigation_drawer_open,
     43                 R.string.navigation_drawer_close);
     44         drawer.setDrawerListener(toggle);
     45         toggle.syncState();
     46 
     47         NavigationView navigationView = findViewById(R.id.nav_view);
     48         navigationView.setNavigationItemSelectedListener(this);
     49 
     50         FragmentManager fm = getSupportFragmentManager();
     51         if (fm.findFragmentById(android.R.id.content) == null) {
     52             ListFragment listFragment = new ListFragment();
     53             ListAdapter adapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1,
     54                     TextUtils.buildSimpleStringList(40));
     55             listFragment.setListAdapter(adapter);
     56             fm.beginTransaction().add(R.id.app_bar_layout, listFragment).commit();
     57         }
     58     }
     59 
     60     @Override
     61     public boolean onNavigationItemSelected(MenuItem item) {
     62         DrawerLayout drawer = findViewById(R.id.drawer_layout);
     63         drawer.closeDrawer(GravityCompat.START);
     64         return true;
     65     }
     66 }
     67