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 | */ |
Steve McKay | d080506 | 2016-09-15 14:30:38 -0700 | [diff] [blame] | 16 | package com.android.documentsui.sidebar; |
Ben Kwa | 74e5d41 | 2016-02-10 07:46:35 -0800 | [diff] [blame] | 17 | |
| 18 | import android.content.Context; |
| 19 | import android.util.AttributeSet; |
| 20 | import android.view.KeyEvent; |
| 21 | import android.widget.ListView; |
| 22 | |
Steve McKay | 98f8c5f | 2017-03-03 13:52:14 -0800 | [diff] [blame] | 23 | import com.android.documentsui.base.Features; |
Ben Lin | 340ab17 | 2017-01-27 11:41:26 -0800 | [diff] [blame] | 24 | |
Ben Kwa | 74e5d41 | 2016-02-10 07:46:35 -0800 | [diff] [blame] | 25 | /** |
| 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 | */ |
| 30 | public class RootsList extends ListView { |
| 31 | |
Steve McKay | 98f8c5f | 2017-03-03 13:52:14 -0800 | [diff] [blame] | 32 | private final Features mFeatures; |
| 33 | |
Ben Kwa | 74e5d41 | 2016-02-10 07:46:35 -0800 | [diff] [blame] | 34 | // 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 McKay | 98f8c5f | 2017-03-03 13:52:14 -0800 | [diff] [blame] | 38 | mFeatures = Features.create(getResources()); |
Ben Kwa | 74e5d41 | 2016-02-10 07:46:35 -0800 | [diff] [blame] | 39 | } |
| 40 | |
| 41 | public RootsList(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { |
| 42 | super(context, attrs, defStyleAttr, defStyleRes); |
Steve McKay | 98f8c5f | 2017-03-03 13:52:14 -0800 | [diff] [blame] | 43 | mFeatures = Features.create(getResources()); |
Ben Kwa | 74e5d41 | 2016-02-10 07:46:35 -0800 | [diff] [blame] | 44 | } |
| 45 | |
| 46 | public RootsList(Context context, AttributeSet attrs, int defStyleAttr) { |
| 47 | super(context, attrs, defStyleAttr); |
Steve McKay | 98f8c5f | 2017-03-03 13:52:14 -0800 | [diff] [blame] | 48 | mFeatures = Features.create(getResources()); |
Ben Kwa | 74e5d41 | 2016-02-10 07:46:35 -0800 | [diff] [blame] | 49 | } |
| 50 | |
| 51 | public RootsList(Context context, AttributeSet attrs) { |
| 52 | super(context, attrs); |
Steve McKay | 98f8c5f | 2017-03-03 13:52:14 -0800 | [diff] [blame] | 53 | mFeatures = Features.create(getResources()); |
Ben Kwa | 74e5d41 | 2016-02-10 07:46:35 -0800 | [diff] [blame] | 54 | } |
| 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 McKay | 98f8c5f | 2017-03-03 13:52:14 -0800 | [diff] [blame] | 62 | return mFeatures.isSystemKeyboardNavigationEnabled() |
| 63 | && super.onKeyDown(keyCode, event); |
Ben Kwa | 74e5d41 | 2016-02-10 07:46:35 -0800 | [diff] [blame] | 64 | // 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 | } |