blob: b83fcbf359601f10673330cd88c659d2999be3b8 [file] [log] [blame]
Ben Kwa74e5d412016-02-10 07:46:35 -08001/*
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 */
Steve McKayd0805062016-09-15 14:30:38 -070016package com.android.documentsui.sidebar;
Ben Kwa74e5d412016-02-10 07:46:35 -080017
18import android.content.Context;
19import android.util.AttributeSet;
20import android.view.KeyEvent;
21import android.widget.ListView;
22
Steve McKay98f8c5f2017-03-03 13:52:14 -080023import com.android.documentsui.base.Features;
Ben Lin340ab172017-01-27 11:41:26 -080024
Ben Kwa74e5d412016-02-10 07:46:35 -080025/**
26 * The list in the navigation drawer. This class exists for the purpose of overriding the key
27 * handler on ListView. Ignoring keystrokes (e.g. the tab key) cannot be properly done using
28 * View.OnKeyListener.
29 */
30public class RootsList extends ListView {
31
Steve McKay98f8c5f2017-03-03 13:52:14 -080032 private final Features mFeatures;
33
Ben Kwa74e5d412016-02-10 07:46:35 -080034 // Multiple constructors are needed to handle all the different ways this View could be
35 // constructed by the framework. Don't remove them!
36 public RootsList(Context context) {
37 super(context);
Steve McKay98f8c5f2017-03-03 13:52:14 -080038 mFeatures = Features.create(getResources());
Ben Kwa74e5d412016-02-10 07:46:35 -080039 }
40
41 public RootsList(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
42 super(context, attrs, defStyleAttr, defStyleRes);
Steve McKay98f8c5f2017-03-03 13:52:14 -080043 mFeatures = Features.create(getResources());
Ben Kwa74e5d412016-02-10 07:46:35 -080044 }
45
46 public RootsList(Context context, AttributeSet attrs, int defStyleAttr) {
47 super(context, attrs, defStyleAttr);
Steve McKay98f8c5f2017-03-03 13:52:14 -080048 mFeatures = Features.create(getResources());
Ben Kwa74e5d412016-02-10 07:46:35 -080049 }
50
51 public RootsList(Context context, AttributeSet attrs) {
52 super(context, attrs);
Steve McKay98f8c5f2017-03-03 13:52:14 -080053 mFeatures = Features.create(getResources());
Ben Kwa74e5d412016-02-10 07:46:35 -080054 }
55
56 @Override
57 public boolean onKeyDown(int keyCode, KeyEvent event) {
58 switch (keyCode) {
59 // Ignore tab key events - this causes them to bubble up to the global key handler where
60 // they are appropriately handled. See BaseActivity.onKeyDown.
61 case KeyEvent.KEYCODE_TAB:
Steve McKay98f8c5f2017-03-03 13:52:14 -080062 return mFeatures.isSystemKeyboardNavigationEnabled()
63 && super.onKeyDown(keyCode, event);
Ben Kwa74e5d412016-02-10 07:46:35 -080064 // Prevent left/right arrow keystrokes from shifting focus away from the roots list.
65 case KeyEvent.KEYCODE_DPAD_LEFT:
66 case KeyEvent.KEYCODE_DPAD_RIGHT:
67 return true;
68 default:
69 return super.onKeyDown(keyCode, event);
70 }
71 }
72}