Ben Kwa | 74e5d41 | 2016-02-10 07:46:35 -0800 | [diff] [blame] | 1 | /* |
| 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 | */ |
| 16 | package com.android.documentsui; |
| 17 | |
| 18 | import android.content.Context; |
| 19 | import android.util.AttributeSet; |
| 20 | import android.view.KeyEvent; |
| 21 | import android.widget.ListView; |
| 22 | |
| 23 | /** |
| 24 | * The list in the navigation drawer. This class exists for the purpose of overriding the key |
| 25 | * handler on ListView. Ignoring keystrokes (e.g. the tab key) cannot be properly done using |
| 26 | * View.OnKeyListener. |
| 27 | */ |
| 28 | public class RootsList extends ListView { |
| 29 | |
| 30 | // Multiple constructors are needed to handle all the different ways this View could be |
| 31 | // constructed by the framework. Don't remove them! |
| 32 | public RootsList(Context context) { |
| 33 | super(context); |
| 34 | } |
| 35 | |
| 36 | public RootsList(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { |
| 37 | super(context, attrs, defStyleAttr, defStyleRes); |
| 38 | } |
| 39 | |
| 40 | public RootsList(Context context, AttributeSet attrs, int defStyleAttr) { |
| 41 | super(context, attrs, defStyleAttr); |
| 42 | } |
| 43 | |
| 44 | public RootsList(Context context, AttributeSet attrs) { |
| 45 | super(context, attrs); |
| 46 | } |
| 47 | |
| 48 | @Override |
| 49 | public boolean onKeyDown(int keyCode, KeyEvent event) { |
| 50 | switch (keyCode) { |
| 51 | // Ignore tab key events - this causes them to bubble up to the global key handler where |
| 52 | // they are appropriately handled. See BaseActivity.onKeyDown. |
| 53 | case KeyEvent.KEYCODE_TAB: |
| 54 | return false; |
| 55 | // Prevent left/right arrow keystrokes from shifting focus away from the roots list. |
| 56 | case KeyEvent.KEYCODE_DPAD_LEFT: |
| 57 | case KeyEvent.KEYCODE_DPAD_RIGHT: |
| 58 | return true; |
| 59 | default: |
| 60 | return super.onKeyDown(keyCode, event); |
| 61 | } |
| 62 | } |
| 63 | } |