1431713be0958fd0f4d878f5f25755575191fb8baKirill Grouchnikov/* 2431713be0958fd0f4d878f5f25755575191fb8baKirill Grouchnikov * Copyright (C) 2016 The Android Open Source Project 3431713be0958fd0f4d878f5f25755575191fb8baKirill Grouchnikov * 4431713be0958fd0f4d878f5f25755575191fb8baKirill Grouchnikov * Licensed under the Apache License, Version 2.0 (the "License"); 5431713be0958fd0f4d878f5f25755575191fb8baKirill Grouchnikov * you may not use this file except in compliance with the License. 6431713be0958fd0f4d878f5f25755575191fb8baKirill Grouchnikov * You may obtain a copy of the License at 7431713be0958fd0f4d878f5f25755575191fb8baKirill Grouchnikov * 8431713be0958fd0f4d878f5f25755575191fb8baKirill Grouchnikov * http://www.apache.org/licenses/LICENSE-2.0 9431713be0958fd0f4d878f5f25755575191fb8baKirill Grouchnikov * 10431713be0958fd0f4d878f5f25755575191fb8baKirill Grouchnikov * Unless required by applicable law or agreed to in writing, software 11431713be0958fd0f4d878f5f25755575191fb8baKirill Grouchnikov * distributed under the License is distributed on an "AS IS" BASIS, 12431713be0958fd0f4d878f5f25755575191fb8baKirill Grouchnikov * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13431713be0958fd0f4d878f5f25755575191fb8baKirill Grouchnikov * See the License for the specific language governing permissions and 14431713be0958fd0f4d878f5f25755575191fb8baKirill Grouchnikov * limitations under the License. 15431713be0958fd0f4d878f5f25755575191fb8baKirill Grouchnikov */ 16431713be0958fd0f4d878f5f25755575191fb8baKirill Grouchnikov 17431713be0958fd0f4d878f5f25755575191fb8baKirill Grouchnikovpackage android.support.v7.app; 18431713be0958fd0f4d878f5f25755575191fb8baKirill Grouchnikov 19431713be0958fd0f4d878f5f25755575191fb8baKirill Grouchnikovimport android.content.res.Configuration; 20431713be0958fd0f4d878f5f25755575191fb8baKirill Grouchnikovimport android.os.Bundle; 21431713be0958fd0f4d878f5f25755575191fb8baKirill Grouchnikovimport android.support.v4.view.GravityCompat; 22431713be0958fd0f4d878f5f25755575191fb8baKirill Grouchnikovimport android.support.v4.widget.DrawerLayout; 23431713be0958fd0f4d878f5f25755575191fb8baKirill Grouchnikovimport android.support.v7.appcompat.test.R; 24431713be0958fd0f4d878f5f25755575191fb8baKirill Grouchnikovimport android.support.v7.testutils.BaseTestActivity; 25431713be0958fd0f4d878f5f25755575191fb8baKirill Grouchnikovimport android.support.v7.testutils.Shakespeare; 26431713be0958fd0f4d878f5f25755575191fb8baKirill Grouchnikovimport android.support.v7.widget.Toolbar; 27431713be0958fd0f4d878f5f25755575191fb8baKirill Grouchnikovimport android.view.MenuItem; 28431713be0958fd0f4d878f5f25755575191fb8baKirill Grouchnikovimport android.view.View; 29431713be0958fd0f4d878f5f25755575191fb8baKirill Grouchnikovimport android.widget.AdapterView; 30431713be0958fd0f4d878f5f25755575191fb8baKirill Grouchnikovimport android.widget.ArrayAdapter; 31431713be0958fd0f4d878f5f25755575191fb8baKirill Grouchnikovimport android.widget.ListView; 32431713be0958fd0f4d878f5f25755575191fb8baKirill Grouchnikovimport android.widget.TextView; 33431713be0958fd0f4d878f5f25755575191fb8baKirill Grouchnikov 34431713be0958fd0f4d878f5f25755575191fb8baKirill Grouchnikov/** 35431713be0958fd0f4d878f5f25755575191fb8baKirill Grouchnikov * Test activity for testing various APIs and interactions for DrawerLayout with start and end 36431713be0958fd0f4d878f5f25755575191fb8baKirill Grouchnikov * drawers. 37431713be0958fd0f4d878f5f25755575191fb8baKirill Grouchnikov */ 38431713be0958fd0f4d878f5f25755575191fb8baKirill Grouchnikovpublic class DrawerLayoutDoubleActivity extends BaseTestActivity { 39431713be0958fd0f4d878f5f25755575191fb8baKirill Grouchnikov private DrawerLayout mDrawerLayout; 40431713be0958fd0f4d878f5f25755575191fb8baKirill Grouchnikov private ListView mStartDrawer; 41431713be0958fd0f4d878f5f25755575191fb8baKirill Grouchnikov private View mEndDrawer; 42431713be0958fd0f4d878f5f25755575191fb8baKirill Grouchnikov private TextView mContent; 43431713be0958fd0f4d878f5f25755575191fb8baKirill Grouchnikov 44431713be0958fd0f4d878f5f25755575191fb8baKirill Grouchnikov private Toolbar mToolbar; 45431713be0958fd0f4d878f5f25755575191fb8baKirill Grouchnikov 46431713be0958fd0f4d878f5f25755575191fb8baKirill Grouchnikov @Override 47431713be0958fd0f4d878f5f25755575191fb8baKirill Grouchnikov protected int getContentViewLayoutResId() { 48431713be0958fd0f4d878f5f25755575191fb8baKirill Grouchnikov return R.layout.drawer_double_layout; 49431713be0958fd0f4d878f5f25755575191fb8baKirill Grouchnikov } 50431713be0958fd0f4d878f5f25755575191fb8baKirill Grouchnikov 51431713be0958fd0f4d878f5f25755575191fb8baKirill Grouchnikov @Override 52431713be0958fd0f4d878f5f25755575191fb8baKirill Grouchnikov protected void onContentViewSet() { 53431713be0958fd0f4d878f5f25755575191fb8baKirill Grouchnikov super.onContentViewSet(); 54431713be0958fd0f4d878f5f25755575191fb8baKirill Grouchnikov 55431713be0958fd0f4d878f5f25755575191fb8baKirill Grouchnikov mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); 56431713be0958fd0f4d878f5f25755575191fb8baKirill Grouchnikov mStartDrawer = (ListView) findViewById(R.id.start_drawer); 57431713be0958fd0f4d878f5f25755575191fb8baKirill Grouchnikov mEndDrawer = findViewById(R.id.end_drawer); 58431713be0958fd0f4d878f5f25755575191fb8baKirill Grouchnikov mContent = (TextView) findViewById(R.id.content_text); 59431713be0958fd0f4d878f5f25755575191fb8baKirill Grouchnikov 60431713be0958fd0f4d878f5f25755575191fb8baKirill Grouchnikov mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START); 61431713be0958fd0f4d878f5f25755575191fb8baKirill Grouchnikov 62431713be0958fd0f4d878f5f25755575191fb8baKirill Grouchnikov // The drawer title must be set in order to announce state changes when 63431713be0958fd0f4d878f5f25755575191fb8baKirill Grouchnikov // accessibility is turned on. This is typically a simple description, 64431713be0958fd0f4d878f5f25755575191fb8baKirill Grouchnikov // e.g. "Navigation". 65431713be0958fd0f4d878f5f25755575191fb8baKirill Grouchnikov mDrawerLayout.setDrawerTitle(GravityCompat.START, getString(R.string.drawer_title)); 66431713be0958fd0f4d878f5f25755575191fb8baKirill Grouchnikov 67431713be0958fd0f4d878f5f25755575191fb8baKirill Grouchnikov mStartDrawer.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, 68431713be0958fd0f4d878f5f25755575191fb8baKirill Grouchnikov Shakespeare.TITLES)); 69431713be0958fd0f4d878f5f25755575191fb8baKirill Grouchnikov mStartDrawer.setOnItemClickListener(new DrawerItemClickListener()); 70431713be0958fd0f4d878f5f25755575191fb8baKirill Grouchnikov 71431713be0958fd0f4d878f5f25755575191fb8baKirill Grouchnikov // Find the toolbar in our layout and set it as the support action bar on the activity. 72431713be0958fd0f4d878f5f25755575191fb8baKirill Grouchnikov // This is required to have the drawer slide "over" the toolbar. 73431713be0958fd0f4d878f5f25755575191fb8baKirill Grouchnikov mToolbar = (Toolbar) findViewById(R.id.toolbar); 74431713be0958fd0f4d878f5f25755575191fb8baKirill Grouchnikov mToolbar.setTitle(R.string.drawer_title); 75431713be0958fd0f4d878f5f25755575191fb8baKirill Grouchnikov setSupportActionBar(mToolbar); 76431713be0958fd0f4d878f5f25755575191fb8baKirill Grouchnikov 77431713be0958fd0f4d878f5f25755575191fb8baKirill Grouchnikov getSupportActionBar().setDisplayHomeAsUpEnabled(true); 78431713be0958fd0f4d878f5f25755575191fb8baKirill Grouchnikov getSupportActionBar().setDisplayShowHomeEnabled(false); 79431713be0958fd0f4d878f5f25755575191fb8baKirill Grouchnikov 80431713be0958fd0f4d878f5f25755575191fb8baKirill Grouchnikov // Configure the background color fill of the system status bar (on supported platform 81431713be0958fd0f4d878f5f25755575191fb8baKirill Grouchnikov // versions) and the toolbar itself. We're using the same color, and android:statusBar 82431713be0958fd0f4d878f5f25755575191fb8baKirill Grouchnikov // from the theme makes the status bar slightly darker. 83431713be0958fd0f4d878f5f25755575191fb8baKirill Grouchnikov final int metalBlueColor = getResources().getColor(R.color.drawer_sample_metal_blue); 84431713be0958fd0f4d878f5f25755575191fb8baKirill Grouchnikov mDrawerLayout.setStatusBarBackgroundColor(metalBlueColor); 85431713be0958fd0f4d878f5f25755575191fb8baKirill Grouchnikov mToolbar.setBackgroundColor(metalBlueColor); 86431713be0958fd0f4d878f5f25755575191fb8baKirill Grouchnikov } 87431713be0958fd0f4d878f5f25755575191fb8baKirill Grouchnikov 88431713be0958fd0f4d878f5f25755575191fb8baKirill Grouchnikov @Override 89431713be0958fd0f4d878f5f25755575191fb8baKirill Grouchnikov public void onBackPressed() { 90431713be0958fd0f4d878f5f25755575191fb8baKirill Grouchnikov // Is the start drawer open? 91431713be0958fd0f4d878f5f25755575191fb8baKirill Grouchnikov if (mDrawerLayout.isDrawerOpen(mStartDrawer)) { 92431713be0958fd0f4d878f5f25755575191fb8baKirill Grouchnikov // Close the drawer and return. 93431713be0958fd0f4d878f5f25755575191fb8baKirill Grouchnikov mDrawerLayout.closeDrawer(mStartDrawer); 94431713be0958fd0f4d878f5f25755575191fb8baKirill Grouchnikov return; 95431713be0958fd0f4d878f5f25755575191fb8baKirill Grouchnikov } 96431713be0958fd0f4d878f5f25755575191fb8baKirill Grouchnikov 97431713be0958fd0f4d878f5f25755575191fb8baKirill Grouchnikov // Is the end drawer open? 98431713be0958fd0f4d878f5f25755575191fb8baKirill Grouchnikov if (mDrawerLayout.isDrawerOpen(mEndDrawer)) { 99431713be0958fd0f4d878f5f25755575191fb8baKirill Grouchnikov // Close the drawer and return. 100431713be0958fd0f4d878f5f25755575191fb8baKirill Grouchnikov mDrawerLayout.closeDrawer(mEndDrawer); 101431713be0958fd0f4d878f5f25755575191fb8baKirill Grouchnikov return; 102431713be0958fd0f4d878f5f25755575191fb8baKirill Grouchnikov } 103431713be0958fd0f4d878f5f25755575191fb8baKirill Grouchnikov 104431713be0958fd0f4d878f5f25755575191fb8baKirill Grouchnikov super.onBackPressed(); 105431713be0958fd0f4d878f5f25755575191fb8baKirill Grouchnikov } 106431713be0958fd0f4d878f5f25755575191fb8baKirill Grouchnikov 107431713be0958fd0f4d878f5f25755575191fb8baKirill Grouchnikov /** 108431713be0958fd0f4d878f5f25755575191fb8baKirill Grouchnikov * This list item click listener implements very simple view switching by changing 109431713be0958fd0f4d878f5f25755575191fb8baKirill Grouchnikov * the primary content text. The drawer is closed when a selection is made. 110431713be0958fd0f4d878f5f25755575191fb8baKirill Grouchnikov */ 111431713be0958fd0f4d878f5f25755575191fb8baKirill Grouchnikov private class DrawerItemClickListener implements ListView.OnItemClickListener { 112431713be0958fd0f4d878f5f25755575191fb8baKirill Grouchnikov @Override 113431713be0958fd0f4d878f5f25755575191fb8baKirill Grouchnikov public void onItemClick(AdapterView<?> parent, View view, int position, long id) { 114431713be0958fd0f4d878f5f25755575191fb8baKirill Grouchnikov mContent.setText(Shakespeare.DIALOGUE[position]); 115431713be0958fd0f4d878f5f25755575191fb8baKirill Grouchnikov mToolbar.setTitle(Shakespeare.TITLES[position]); 116431713be0958fd0f4d878f5f25755575191fb8baKirill Grouchnikov mDrawerLayout.closeDrawer(mStartDrawer); 117431713be0958fd0f4d878f5f25755575191fb8baKirill Grouchnikov } 118431713be0958fd0f4d878f5f25755575191fb8baKirill Grouchnikov } 119431713be0958fd0f4d878f5f25755575191fb8baKirill Grouchnikov} 120