Winson Chung | 97d85d2 | 2011-04-13 11:27:36 -0700 | [diff] [blame] | 1 | /* |
Hyunyoung Song | ee3e6a7 | 2015-02-20 14:25:27 -0800 | [diff] [blame] | 2 | * Copyright (C) 2015 The Android Open Source Project |
Winson Chung | 97d85d2 | 2011-04-13 11:27:36 -0700 | [diff] [blame] | 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 | |
Daniel Sandler | 325dc23 | 2013-06-05 22:57:57 -0400 | [diff] [blame] | 17 | package com.android.launcher3; |
Winson Chung | 97d85d2 | 2011-04-13 11:27:36 -0700 | [diff] [blame] | 18 | |
Hyunyoung Song | ee3e6a7 | 2015-02-20 14:25:27 -0800 | [diff] [blame] | 19 | import android.util.Log; |
Winson Chung | 97d85d2 | 2011-04-13 11:27:36 -0700 | [diff] [blame] | 20 | import android.view.KeyEvent; |
Sunny Goyal | b3726d9 | 2014-08-20 16:58:17 -0700 | [diff] [blame] | 21 | import android.view.SoundEffectConstants; |
Winson Chung | 97d85d2 | 2011-04-13 11:27:36 -0700 | [diff] [blame] | 22 | import android.view.View; |
| 23 | import android.view.ViewGroup; |
Winson Chung | 97d85d2 | 2011-04-13 11:27:36 -0700 | [diff] [blame] | 24 | |
Hyunyoung Song | ee3e6a7 | 2015-02-20 14:25:27 -0800 | [diff] [blame] | 25 | import com.android.launcher3.util.FocusLogic; |
Adam Cohen | 091440a | 2015-03-18 14:16:05 -0700 | [diff] [blame] | 26 | import com.android.launcher3.util.Thunk; |
Winson Chung | faa1325 | 2011-06-13 18:15:54 -0700 | [diff] [blame] | 27 | |
Winson Chung | 97d85d2 | 2011-04-13 11:27:36 -0700 | [diff] [blame] | 28 | /** |
Winson Chung | 4d279d9 | 2011-07-21 11:46:32 -0700 | [diff] [blame] | 29 | * A keyboard listener we set on all the workspace icons. |
| 30 | */ |
Adam Cohen | ac56cff | 2011-09-28 20:45:37 -0700 | [diff] [blame] | 31 | class IconKeyEventListener implements View.OnKeyListener { |
Hyunyoung Song | ee3e6a7 | 2015-02-20 14:25:27 -0800 | [diff] [blame] | 32 | @Override |
Winson Chung | 4d279d9 | 2011-07-21 11:46:32 -0700 | [diff] [blame] | 33 | public boolean onKey(View v, int keyCode, KeyEvent event) { |
Adam Cohen | ac56cff | 2011-09-28 20:45:37 -0700 | [diff] [blame] | 34 | return FocusHelper.handleIconKeyEvent(v, keyCode, event); |
| 35 | } |
| 36 | } |
| 37 | |
| 38 | /** |
Winson Chung | 3d503fb | 2011-07-13 17:25:49 -0700 | [diff] [blame] | 39 | * A keyboard listener we set on all the hotseat buttons. |
Winson Chung | 4e6a976 | 2011-05-09 11:56:34 -0700 | [diff] [blame] | 40 | */ |
Adam Cohen | ac56cff | 2011-09-28 20:45:37 -0700 | [diff] [blame] | 41 | class HotseatIconKeyEventListener implements View.OnKeyListener { |
Hyunyoung Song | ee3e6a7 | 2015-02-20 14:25:27 -0800 | [diff] [blame] | 42 | @Override |
Winson Chung | 4e6a976 | 2011-05-09 11:56:34 -0700 | [diff] [blame] | 43 | public boolean onKey(View v, int keyCode, KeyEvent event) { |
Hyunyoung Song | ee3e6a7 | 2015-02-20 14:25:27 -0800 | [diff] [blame] | 44 | return FocusHelper.handleHotseatButtonKeyEvent(v, keyCode, event); |
Winson Chung | 4e6a976 | 2011-05-09 11:56:34 -0700 | [diff] [blame] | 45 | } |
| 46 | } |
| 47 | |
Winson Chung | 97d85d2 | 2011-04-13 11:27:36 -0700 | [diff] [blame] | 48 | public class FocusHelper { |
Winson Chung | 97d85d2 | 2011-04-13 11:27:36 -0700 | [diff] [blame] | 49 | |
Hyunyoung Song | ee3e6a7 | 2015-02-20 14:25:27 -0800 | [diff] [blame] | 50 | private static final String TAG = "FocusHelper"; |
| 51 | private static final boolean DEBUG = false; |
| 52 | |
Hyunyoung Song | ee3e6a7 | 2015-02-20 14:25:27 -0800 | [diff] [blame] | 53 | /** |
Sunny Goyal | fc3c1ed | 2015-04-09 18:48:21 -0700 | [diff] [blame] | 54 | * Handles key events in paged folder. |
Sunny Goyal | 290800b | 2015-03-05 11:33:33 -0800 | [diff] [blame] | 55 | */ |
Sunny Goyal | fc3c1ed | 2015-04-09 18:48:21 -0700 | [diff] [blame] | 56 | public static class PagedFolderKeyEventListener implements View.OnKeyListener { |
Sunny Goyal | 290800b | 2015-03-05 11:33:33 -0800 | [diff] [blame] | 57 | |
| 58 | private final Folder mFolder; |
| 59 | |
| 60 | public PagedFolderKeyEventListener(Folder folder) { |
| 61 | mFolder = folder; |
| 62 | } |
| 63 | |
| 64 | @Override |
Hyunyoung Song | ada5098 | 2015-04-10 14:35:23 -0700 | [diff] [blame] | 65 | public boolean onKey(View v, int keyCode, KeyEvent e) { |
| 66 | boolean consume = FocusLogic.shouldConsume(keyCode); |
| 67 | if (e.getAction() == KeyEvent.ACTION_UP) { |
| 68 | return consume; |
Sunny Goyal | 290800b | 2015-03-05 11:33:33 -0800 | [diff] [blame] | 69 | } |
Hyunyoung Song | ada5098 | 2015-04-10 14:35:23 -0700 | [diff] [blame] | 70 | if (DEBUG) { |
Sunny Goyal | fc3c1ed | 2015-04-09 18:48:21 -0700 | [diff] [blame] | 71 | Log.v(TAG, String.format("Handle ALL Folders keyevent=[%s].", |
Hyunyoung Song | ada5098 | 2015-04-10 14:35:23 -0700 | [diff] [blame] | 72 | KeyEvent.keyCodeToString(keyCode))); |
| 73 | } |
Sunny Goyal | 290800b | 2015-03-05 11:33:33 -0800 | [diff] [blame] | 74 | |
Sunny Goyal | fc3c1ed | 2015-04-09 18:48:21 -0700 | [diff] [blame] | 75 | if (!(v.getParent() instanceof ShortcutAndWidgetContainer)) { |
Hyunyoung Song | ada5098 | 2015-04-10 14:35:23 -0700 | [diff] [blame] | 76 | if (LauncherAppState.isDogfoodBuild()) { |
| 77 | throw new IllegalStateException("Parent of the focused item is not supported."); |
| 78 | } else { |
| 79 | return false; |
| 80 | } |
| 81 | } |
Hyunyoung Song | ee3e6a7 | 2015-02-20 14:25:27 -0800 | [diff] [blame] | 82 | |
Sunny Goyal | fc3c1ed | 2015-04-09 18:48:21 -0700 | [diff] [blame] | 83 | // Initialize variables. |
| 84 | final ShortcutAndWidgetContainer itemContainer = (ShortcutAndWidgetContainer) v.getParent(); |
| 85 | final CellLayout cellLayout = (CellLayout) itemContainer.getParent(); |
| 86 | final int countX = cellLayout.getCountX(); |
| 87 | final int countY = cellLayout.getCountY(); |
Hyunyoung Song | ada5098 | 2015-04-10 14:35:23 -0700 | [diff] [blame] | 88 | |
Sunny Goyal | fc3c1ed | 2015-04-09 18:48:21 -0700 | [diff] [blame] | 89 | final int iconIndex = itemContainer.indexOfChild(v); |
| 90 | final FolderPagedView pagedView = (FolderPagedView) cellLayout.getParent(); |
| 91 | |
| 92 | final int pageIndex = pagedView.indexOfChild(cellLayout); |
| 93 | final int pageCount = pagedView.getPageCount(); |
Sunny Goyal | c620560 | 2015-05-21 20:46:33 -0700 | [diff] [blame] | 94 | final boolean isLayoutRtl = Utilities.isRtl(v.getResources()); |
Sunny Goyal | fc3c1ed | 2015-04-09 18:48:21 -0700 | [diff] [blame] | 95 | |
| 96 | int[][] matrix = FocusLogic.createSparseMatrix(cellLayout); |
Hyunyoung Song | ada5098 | 2015-04-10 14:35:23 -0700 | [diff] [blame] | 97 | // Process focus. |
Adam Cohen | 2e6da15 | 2015-05-06 11:42:25 -0700 | [diff] [blame] | 98 | int newIconIndex = FocusLogic.handleKeyEvent(keyCode, countX, |
Sunny Goyal | c620560 | 2015-05-21 20:46:33 -0700 | [diff] [blame] | 99 | countY, matrix, iconIndex, pageIndex, pageCount, isLayoutRtl); |
Hyunyoung Song | ada5098 | 2015-04-10 14:35:23 -0700 | [diff] [blame] | 100 | if (newIconIndex == FocusLogic.NOOP) { |
| 101 | handleNoopKey(keyCode, v); |
| 102 | return consume; |
| 103 | } |
Sunny Goyal | fc3c1ed | 2015-04-09 18:48:21 -0700 | [diff] [blame] | 104 | ShortcutAndWidgetContainer newParent = null; |
| 105 | View child = null; |
| 106 | |
Hyunyoung Song | ada5098 | 2015-04-10 14:35:23 -0700 | [diff] [blame] | 107 | switch (newIconIndex) { |
| 108 | case FocusLogic.PREVIOUS_PAGE_RIGHT_COLUMN: |
Sunny Goyal | fc3c1ed | 2015-04-09 18:48:21 -0700 | [diff] [blame] | 109 | case FocusLogic.PREVIOUS_PAGE_LEFT_COLUMN: |
| 110 | newParent = getCellLayoutChildrenForIndex(pagedView, pageIndex - 1); |
Hyunyoung Song | ada5098 | 2015-04-10 14:35:23 -0700 | [diff] [blame] | 111 | if (newParent != null) { |
Sunny Goyal | fc3c1ed | 2015-04-09 18:48:21 -0700 | [diff] [blame] | 112 | int row = ((CellLayout.LayoutParams) v.getLayoutParams()).cellY; |
| 113 | pagedView.snapToPage(pageIndex - 1); |
| 114 | child = newParent.getChildAt( |
| 115 | ((newIconIndex == FocusLogic.PREVIOUS_PAGE_LEFT_COLUMN) |
| 116 | ^ newParent.invertLayoutHorizontally()) ? 0 : countX - 1, row); |
Hyunyoung Song | ada5098 | 2015-04-10 14:35:23 -0700 | [diff] [blame] | 117 | } |
| 118 | break; |
| 119 | case FocusLogic.PREVIOUS_PAGE_FIRST_ITEM: |
Sunny Goyal | fc3c1ed | 2015-04-09 18:48:21 -0700 | [diff] [blame] | 120 | newParent = getCellLayoutChildrenForIndex(pagedView, pageIndex - 1); |
Hyunyoung Song | ada5098 | 2015-04-10 14:35:23 -0700 | [diff] [blame] | 121 | if (newParent != null) { |
Sunny Goyal | fc3c1ed | 2015-04-09 18:48:21 -0700 | [diff] [blame] | 122 | pagedView.snapToPage(pageIndex - 1); |
| 123 | child = newParent.getChildAt(0, 0); |
Hyunyoung Song | ada5098 | 2015-04-10 14:35:23 -0700 | [diff] [blame] | 124 | } |
| 125 | break; |
| 126 | case FocusLogic.PREVIOUS_PAGE_LAST_ITEM: |
Sunny Goyal | fc3c1ed | 2015-04-09 18:48:21 -0700 | [diff] [blame] | 127 | newParent = getCellLayoutChildrenForIndex(pagedView, pageIndex - 1); |
Hyunyoung Song | ada5098 | 2015-04-10 14:35:23 -0700 | [diff] [blame] | 128 | if (newParent != null) { |
Sunny Goyal | fc3c1ed | 2015-04-09 18:48:21 -0700 | [diff] [blame] | 129 | pagedView.snapToPage(pageIndex - 1); |
| 130 | child = newParent.getChildAt(countX - 1, countY - 1); |
Hyunyoung Song | ada5098 | 2015-04-10 14:35:23 -0700 | [diff] [blame] | 131 | } |
| 132 | break; |
| 133 | case FocusLogic.NEXT_PAGE_FIRST_ITEM: |
Sunny Goyal | fc3c1ed | 2015-04-09 18:48:21 -0700 | [diff] [blame] | 134 | newParent = getCellLayoutChildrenForIndex(pagedView, pageIndex + 1); |
Hyunyoung Song | ada5098 | 2015-04-10 14:35:23 -0700 | [diff] [blame] | 135 | if (newParent != null) { |
Sunny Goyal | fc3c1ed | 2015-04-09 18:48:21 -0700 | [diff] [blame] | 136 | pagedView.snapToPage(pageIndex + 1); |
| 137 | child = newParent.getChildAt(0, 0); |
Hyunyoung Song | ada5098 | 2015-04-10 14:35:23 -0700 | [diff] [blame] | 138 | } |
| 139 | break; |
| 140 | case FocusLogic.NEXT_PAGE_LEFT_COLUMN: |
Sunny Goyal | fc3c1ed | 2015-04-09 18:48:21 -0700 | [diff] [blame] | 141 | case FocusLogic.NEXT_PAGE_RIGHT_COLUMN: |
| 142 | newParent = getCellLayoutChildrenForIndex(pagedView, pageIndex + 1); |
Hyunyoung Song | ada5098 | 2015-04-10 14:35:23 -0700 | [diff] [blame] | 143 | if (newParent != null) { |
Sunny Goyal | fc3c1ed | 2015-04-09 18:48:21 -0700 | [diff] [blame] | 144 | pagedView.snapToPage(pageIndex + 1); |
Tony Wickham | 2518985 | 2015-11-04 17:44:32 -0800 | [diff] [blame] | 145 | child = FocusLogic.getAdjacentChildInNextFolderPage( |
| 146 | newParent, v, newIconIndex); |
Hyunyoung Song | ada5098 | 2015-04-10 14:35:23 -0700 | [diff] [blame] | 147 | } |
| 148 | break; |
| 149 | case FocusLogic.CURRENT_PAGE_FIRST_ITEM: |
Sunny Goyal | fc3c1ed | 2015-04-09 18:48:21 -0700 | [diff] [blame] | 150 | child = cellLayout.getChildAt(0, 0); |
Hyunyoung Song | ada5098 | 2015-04-10 14:35:23 -0700 | [diff] [blame] | 151 | break; |
| 152 | case FocusLogic.CURRENT_PAGE_LAST_ITEM: |
Sunny Goyal | fc3c1ed | 2015-04-09 18:48:21 -0700 | [diff] [blame] | 153 | child = pagedView.getLastItem(); |
Hyunyoung Song | ada5098 | 2015-04-10 14:35:23 -0700 | [diff] [blame] | 154 | break; |
| 155 | default: // Go to some item on the current page. |
| 156 | child = itemContainer.getChildAt(newIconIndex); |
| 157 | break; |
| 158 | } |
| 159 | if (child != null) { |
| 160 | child.requestFocus(); |
| 161 | playSoundEffect(keyCode, v); |
| 162 | } else { |
| 163 | handleNoopKey(keyCode, v); |
| 164 | } |
Hyunyoung Song | ee3e6a7 | 2015-02-20 14:25:27 -0800 | [diff] [blame] | 165 | return consume; |
| 166 | } |
Hyunyoung Song | ee3e6a7 | 2015-02-20 14:25:27 -0800 | [diff] [blame] | 167 | |
Sunny Goyal | fc3c1ed | 2015-04-09 18:48:21 -0700 | [diff] [blame] | 168 | public void handleNoopKey(int keyCode, View v) { |
| 169 | if (keyCode == KeyEvent.KEYCODE_DPAD_DOWN) { |
| 170 | mFolder.mFolderName.requestFocus(); |
| 171 | playSoundEffect(keyCode, v); |
| 172 | } |
| 173 | } |
Sunny Goyal | 290800b | 2015-03-05 11:33:33 -0800 | [diff] [blame] | 174 | } |
| 175 | |
Hyunyoung Song | ee3e6a7 | 2015-02-20 14:25:27 -0800 | [diff] [blame] | 176 | /** |
Tony Wickham | 4fc8287 | 2015-11-10 16:52:14 -0800 | [diff] [blame^] | 177 | * Handles key events in the workspace hotseat (bottom of the screen). |
Hyunyoung Song | ee3e6a7 | 2015-02-20 14:25:27 -0800 | [diff] [blame] | 178 | * <p>Currently we don't special case for the phone UI in different orientations, even though |
| 179 | * the hotseat is on the side in landscape mode. This is to ensure that accessibility |
| 180 | * consistency is maintained across rotations. |
| 181 | */ |
| 182 | static boolean handleHotseatButtonKeyEvent(View v, int keyCode, KeyEvent e) { |
| 183 | boolean consume = FocusLogic.shouldConsume(keyCode); |
| 184 | if (e.getAction() == KeyEvent.ACTION_UP || !consume) { |
| 185 | return consume; |
| 186 | } |
Hyunyoung Song | ee3e6a7 | 2015-02-20 14:25:27 -0800 | [diff] [blame] | 187 | |
Winson | c0b52fe | 2015-09-09 16:38:15 -0700 | [diff] [blame] | 188 | final Launcher launcher = (Launcher) v.getContext(); |
| 189 | final DeviceProfile profile = launcher.getDeviceProfile(); |
Adam Cohen | 2e6da15 | 2015-05-06 11:42:25 -0700 | [diff] [blame] | 190 | |
Hyunyoung Song | ee3e6a7 | 2015-02-20 14:25:27 -0800 | [diff] [blame] | 191 | if (DEBUG) { |
| 192 | Log.v(TAG, String.format( |
Hyunyoung Song | 18bfaaf | 2015-03-17 11:32:21 -0700 | [diff] [blame] | 193 | "Handle HOTSEAT BUTTONS keyevent=[%s] on hotseat buttons, isVertical=%s", |
| 194 | KeyEvent.keyCodeToString(keyCode), profile.isVerticalBarLayout())); |
Hyunyoung Song | ee3e6a7 | 2015-02-20 14:25:27 -0800 | [diff] [blame] | 195 | } |
| 196 | |
| 197 | // Initialize the variables. |
Winson | fa56b3f | 2015-09-14 12:01:13 -0700 | [diff] [blame] | 198 | final Workspace workspace = (Workspace) v.getRootView().findViewById(R.id.workspace); |
Hyunyoung Song | ee3e6a7 | 2015-02-20 14:25:27 -0800 | [diff] [blame] | 199 | final ShortcutAndWidgetContainer hotseatParent = (ShortcutAndWidgetContainer) v.getParent(); |
| 200 | final CellLayout hotseatLayout = (CellLayout) hotseatParent.getParent(); |
Hyunyoung Song | 31178b8 | 2015-02-24 14:12:51 -0800 | [diff] [blame] | 201 | |
Winson | fa56b3f | 2015-09-14 12:01:13 -0700 | [diff] [blame] | 202 | final ItemInfo itemInfo = (ItemInfo) v.getTag(); |
Hyunyoung Song | b76cd62 | 2015-04-16 14:34:09 -0700 | [diff] [blame] | 203 | int pageIndex = workspace.getNextPage(); |
Hyunyoung Song | ee3e6a7 | 2015-02-20 14:25:27 -0800 | [diff] [blame] | 204 | int pageCount = workspace.getChildCount(); |
Hyunyoung Song | 31178b8 | 2015-02-24 14:12:51 -0800 | [diff] [blame] | 205 | int countX = -1; |
| 206 | int countY = -1; |
Sunny Goyal | fc3c1ed | 2015-04-09 18:48:21 -0700 | [diff] [blame] | 207 | int iconIndex = hotseatParent.indexOfChild(v); |
Hyunyoung Song | 18bfaaf | 2015-03-17 11:32:21 -0700 | [diff] [blame] | 208 | int iconRank = ((CellLayout.LayoutParams) hotseatLayout.getShortcutsAndWidgets() |
| 209 | .getChildAt(iconIndex).getLayoutParams()).cellX; |
Hyunyoung Song | ee3e6a7 | 2015-02-20 14:25:27 -0800 | [diff] [blame] | 210 | |
| 211 | final CellLayout iconLayout = (CellLayout) workspace.getChildAt(pageIndex); |
Hyunyoung Song | b76cd62 | 2015-04-16 14:34:09 -0700 | [diff] [blame] | 212 | if (iconLayout == null) { |
| 213 | // This check is to guard against cases where key strokes rushes in when workspace |
| 214 | // child creation/deletion is still in flux. (e.g., during drop or fling |
| 215 | // animation.) |
| 216 | return consume; |
| 217 | } |
Hyunyoung Song | ee3e6a7 | 2015-02-20 14:25:27 -0800 | [diff] [blame] | 218 | final ViewGroup iconParent = iconLayout.getShortcutsAndWidgets(); |
| 219 | |
| 220 | ViewGroup parent = null; |
Hyunyoung Song | 31178b8 | 2015-02-24 14:12:51 -0800 | [diff] [blame] | 221 | int[][] matrix = null; |
Hyunyoung Song | ee3e6a7 | 2015-02-20 14:25:27 -0800 | [diff] [blame] | 222 | |
| 223 | if (keyCode == KeyEvent.KEYCODE_DPAD_UP && |
Hyunyoung Song | 18bfaaf | 2015-03-17 11:32:21 -0700 | [diff] [blame] | 224 | !profile.isVerticalBarLayout()) { |
| 225 | matrix = FocusLogic.createSparseMatrix(iconLayout, hotseatLayout, |
Sunny Goyal | 4f3e938 | 2015-06-05 00:13:25 -0700 | [diff] [blame] | 226 | true /* hotseat horizontal */, profile.inv.hotseatAllAppsRank, |
| 227 | iconRank == profile.inv.hotseatAllAppsRank /* include all apps icon */); |
Hyunyoung Song | ee3e6a7 | 2015-02-20 14:25:27 -0800 | [diff] [blame] | 228 | iconIndex += iconParent.getChildCount(); |
| 229 | countX = iconLayout.getCountX(); |
| 230 | countY = iconLayout.getCountY() + hotseatLayout.getCountY(); |
| 231 | parent = iconParent; |
| 232 | } else if (keyCode == KeyEvent.KEYCODE_DPAD_LEFT && |
Hyunyoung Song | 18bfaaf | 2015-03-17 11:32:21 -0700 | [diff] [blame] | 233 | profile.isVerticalBarLayout()) { |
| 234 | matrix = FocusLogic.createSparseMatrix(iconLayout, hotseatLayout, |
Sunny Goyal | 4f3e938 | 2015-06-05 00:13:25 -0700 | [diff] [blame] | 235 | false /* hotseat horizontal */, profile.inv.hotseatAllAppsRank, |
| 236 | iconRank == profile.inv.hotseatAllAppsRank /* include all apps icon */); |
Hyunyoung Song | ee3e6a7 | 2015-02-20 14:25:27 -0800 | [diff] [blame] | 237 | iconIndex += iconParent.getChildCount(); |
| 238 | countX = iconLayout.getCountX() + hotseatLayout.getCountX(); |
| 239 | countY = iconLayout.getCountY(); |
| 240 | parent = iconParent; |
Hyunyoung Song | 31178b8 | 2015-02-24 14:12:51 -0800 | [diff] [blame] | 241 | } else if (keyCode == KeyEvent.KEYCODE_DPAD_RIGHT && |
Hyunyoung Song | 18bfaaf | 2015-03-17 11:32:21 -0700 | [diff] [blame] | 242 | profile.isVerticalBarLayout()) { |
Hyunyoung Song | 31178b8 | 2015-02-24 14:12:51 -0800 | [diff] [blame] | 243 | keyCode = KeyEvent.KEYCODE_PAGE_DOWN; |
Winson | fa56b3f | 2015-09-14 12:01:13 -0700 | [diff] [blame] | 244 | } else if (isUninstallKeyChord(e)) { |
| 245 | matrix = FocusLogic.createSparseMatrix(iconLayout); |
| 246 | if (UninstallDropTarget.supportsDrop(launcher, itemInfo)) { |
| 247 | UninstallDropTarget.startUninstallActivity(launcher, itemInfo); |
| 248 | } |
| 249 | } else if (isDeleteKeyChord(e)) { |
| 250 | matrix = FocusLogic.createSparseMatrix(iconLayout); |
Winson | 2949fb5 | 2015-09-24 09:56:11 -0700 | [diff] [blame] | 251 | launcher.removeItem(v, itemInfo, true /* deleteFromDb */); |
Winson | c0b52fe | 2015-09-09 16:38:15 -0700 | [diff] [blame] | 252 | } else { |
Hyunyoung Song | ee3e6a7 | 2015-02-20 14:25:27 -0800 | [diff] [blame] | 253 | // For other KEYCODE_DPAD_LEFT and KEYCODE_DPAD_RIGHT navigation, do not use the |
| 254 | // matrix extended with hotseat. |
| 255 | matrix = FocusLogic.createSparseMatrix(hotseatLayout); |
Hyunyoung Song | ee3e6a7 | 2015-02-20 14:25:27 -0800 | [diff] [blame] | 256 | countX = hotseatLayout.getCountX(); |
| 257 | countY = hotseatLayout.getCountY(); |
Hyunyoung Song | 31178b8 | 2015-02-24 14:12:51 -0800 | [diff] [blame] | 258 | parent = hotseatParent; |
Hyunyoung Song | ee3e6a7 | 2015-02-20 14:25:27 -0800 | [diff] [blame] | 259 | } |
| 260 | |
| 261 | // Process the focus. |
Adam Cohen | 2e6da15 | 2015-05-06 11:42:25 -0700 | [diff] [blame] | 262 | int newIconIndex = FocusLogic.handleKeyEvent(keyCode, countX, |
Sunny Goyal | c620560 | 2015-05-21 20:46:33 -0700 | [diff] [blame] | 263 | countY, matrix, iconIndex, pageIndex, pageCount, Utilities.isRtl(v.getResources())); |
Hyunyoung Song | ee3e6a7 | 2015-02-20 14:25:27 -0800 | [diff] [blame] | 264 | |
Hyunyoung Song | 31178b8 | 2015-02-24 14:12:51 -0800 | [diff] [blame] | 265 | View newIcon = null; |
Tony Wickham | 4fc8287 | 2015-11-10 16:52:14 -0800 | [diff] [blame^] | 266 | switch (newIconIndex) { |
| 267 | case FocusLogic.NEXT_PAGE_FIRST_ITEM: |
| 268 | parent = getCellLayoutChildrenForIndex(workspace, pageIndex + 1); |
| 269 | newIcon = parent.getChildAt(0); |
| 270 | // TODO(hyunyoungs): handle cases where the child is not an icon but |
| 271 | // a folder or a widget. |
| 272 | workspace.snapToPage(pageIndex + 1); |
| 273 | break; |
| 274 | case FocusLogic.PREVIOUS_PAGE_FIRST_ITEM: |
| 275 | parent = getCellLayoutChildrenForIndex(workspace, pageIndex - 1); |
| 276 | newIcon = parent.getChildAt(0); |
| 277 | // TODO(hyunyoungs): handle cases where the child is not an icon but |
| 278 | // a folder or a widget. |
| 279 | workspace.snapToPage(pageIndex - 1); |
| 280 | break; |
| 281 | case FocusLogic.PREVIOUS_PAGE_LAST_ITEM: |
| 282 | parent = getCellLayoutChildrenForIndex(workspace, pageIndex - 1); |
| 283 | newIcon = parent.getChildAt(parent.getChildCount() - 1); |
| 284 | // TODO(hyunyoungs): handle cases where the child is not an icon but |
| 285 | // a folder or a widget. |
| 286 | workspace.snapToPage(pageIndex - 1); |
| 287 | break; |
| 288 | case FocusLogic.PREVIOUS_PAGE_LEFT_COLUMN: |
| 289 | case FocusLogic.PREVIOUS_PAGE_RIGHT_COLUMN: |
| 290 | // Go to the previous page but keep the focus on the same hotseat icon. |
| 291 | workspace.snapToPage(pageIndex - 1); |
| 292 | break; |
| 293 | case FocusLogic.NEXT_PAGE_LEFT_COLUMN: |
| 294 | case FocusLogic.NEXT_PAGE_RIGHT_COLUMN: |
| 295 | // Go to the next page but keep the focus on the same hotseat icon. |
| 296 | workspace.snapToPage(pageIndex + 1); |
| 297 | break; |
Hyunyoung Song | 31178b8 | 2015-02-24 14:12:51 -0800 | [diff] [blame] | 298 | } |
| 299 | if (parent == iconParent && newIconIndex >= iconParent.getChildCount()) { |
Hyunyoung Song | ee3e6a7 | 2015-02-20 14:25:27 -0800 | [diff] [blame] | 300 | newIconIndex -= iconParent.getChildCount(); |
| 301 | } |
| 302 | if (parent != null) { |
Hyunyoung Song | 31178b8 | 2015-02-24 14:12:51 -0800 | [diff] [blame] | 303 | if (newIcon == null && newIconIndex >=0) { |
| 304 | newIcon = parent.getChildAt(newIconIndex); |
| 305 | } |
Hyunyoung Song | ee3e6a7 | 2015-02-20 14:25:27 -0800 | [diff] [blame] | 306 | if (newIcon != null) { |
| 307 | newIcon.requestFocus(); |
| 308 | playSoundEffect(keyCode, v); |
| 309 | } |
| 310 | } |
| 311 | return consume; |
| 312 | } |
| 313 | |
| 314 | /** |
| 315 | * Handles key events in a workspace containing icons. |
| 316 | */ |
| 317 | static boolean handleIconKeyEvent(View v, int keyCode, KeyEvent e) { |
| 318 | boolean consume = FocusLogic.shouldConsume(keyCode); |
| 319 | if (e.getAction() == KeyEvent.ACTION_UP || !consume) { |
| 320 | return consume; |
| 321 | } |
Hyunyoung Song | 18bfaaf | 2015-03-17 11:32:21 -0700 | [diff] [blame] | 322 | |
Adam Cohen | 2e6da15 | 2015-05-06 11:42:25 -0700 | [diff] [blame] | 323 | Launcher launcher = (Launcher) v.getContext(); |
| 324 | DeviceProfile profile = launcher.getDeviceProfile(); |
Hyunyoung Song | 18bfaaf | 2015-03-17 11:32:21 -0700 | [diff] [blame] | 325 | |
Hyunyoung Song | ee3e6a7 | 2015-02-20 14:25:27 -0800 | [diff] [blame] | 326 | if (DEBUG) { |
Hyunyoung Song | 18bfaaf | 2015-03-17 11:32:21 -0700 | [diff] [blame] | 327 | Log.v(TAG, String.format("Handle WORKSPACE ICONS keyevent=[%s] isVerticalBar=%s", |
| 328 | KeyEvent.keyCodeToString(keyCode), profile.isVerticalBarLayout())); |
Hyunyoung Song | ee3e6a7 | 2015-02-20 14:25:27 -0800 | [diff] [blame] | 329 | } |
| 330 | |
| 331 | // Initialize the variables. |
| 332 | ShortcutAndWidgetContainer parent = (ShortcutAndWidgetContainer) v.getParent(); |
Hyunyoung Song | 3853171 | 2015-03-03 19:25:16 -0800 | [diff] [blame] | 333 | CellLayout iconLayout = (CellLayout) parent.getParent(); |
Hyunyoung Song | 31178b8 | 2015-02-24 14:12:51 -0800 | [diff] [blame] | 334 | final Workspace workspace = (Workspace) iconLayout.getParent(); |
Adam Cohen | 2e6da15 | 2015-05-06 11:42:25 -0700 | [diff] [blame] | 335 | final ViewGroup dragLayer = (ViewGroup) workspace.getParent(); |
| 336 | final ViewGroup tabs = (ViewGroup) dragLayer.findViewById(R.id.search_drop_target_bar); |
| 337 | final Hotseat hotseat = (Hotseat) dragLayer.findViewById(R.id.hotseat); |
Sunny Goyal | fc3c1ed | 2015-04-09 18:48:21 -0700 | [diff] [blame] | 338 | |
Winson | fa56b3f | 2015-09-14 12:01:13 -0700 | [diff] [blame] | 339 | final ItemInfo itemInfo = (ItemInfo) v.getTag(); |
Sunny Goyal | fc3c1ed | 2015-04-09 18:48:21 -0700 | [diff] [blame] | 340 | final int iconIndex = parent.indexOfChild(v); |
| 341 | final int pageIndex = workspace.indexOfChild(iconLayout); |
| 342 | final int pageCount = workspace.getChildCount(); |
Hyunyoung Song | 31178b8 | 2015-02-24 14:12:51 -0800 | [diff] [blame] | 343 | int countX = iconLayout.getCountX(); |
| 344 | int countY = iconLayout.getCountY(); |
Hyunyoung Song | ee3e6a7 | 2015-02-20 14:25:27 -0800 | [diff] [blame] | 345 | |
| 346 | CellLayout hotseatLayout = (CellLayout) hotseat.getChildAt(0); |
| 347 | ShortcutAndWidgetContainer hotseatParent = hotseatLayout.getShortcutsAndWidgets(); |
| 348 | int[][] matrix; |
| 349 | |
Hyunyoung Song | 31178b8 | 2015-02-24 14:12:51 -0800 | [diff] [blame] | 350 | // KEYCODE_DPAD_DOWN in portrait (KEYCODE_DPAD_RIGHT in landscape) is the only key allowed |
Hyunyoung Song | ee3e6a7 | 2015-02-20 14:25:27 -0800 | [diff] [blame] | 351 | // to take a user to the hotseat. For other dpad navigation, do not use the matrix extended |
| 352 | // with the hotseat. |
Hyunyoung Song | 18bfaaf | 2015-03-17 11:32:21 -0700 | [diff] [blame] | 353 | if (keyCode == KeyEvent.KEYCODE_DPAD_DOWN && !profile.isVerticalBarLayout()) { |
| 354 | matrix = FocusLogic.createSparseMatrix(iconLayout, hotseatLayout, true /* horizontal */, |
Sunny Goyal | 4f3e938 | 2015-06-05 00:13:25 -0700 | [diff] [blame] | 355 | profile.inv.hotseatAllAppsRank, |
Winson Chung | c393b07 | 2015-05-20 15:03:13 -0700 | [diff] [blame] | 356 | !hotseat.hasIcons() /* ignore all apps icon, unless there are no other icons */); |
Hyunyoung Song | ee3e6a7 | 2015-02-20 14:25:27 -0800 | [diff] [blame] | 357 | countY = countY + 1; |
Hyunyoung Song | 31178b8 | 2015-02-24 14:12:51 -0800 | [diff] [blame] | 358 | } else if (keyCode == KeyEvent.KEYCODE_DPAD_RIGHT && |
Hyunyoung Song | 18bfaaf | 2015-03-17 11:32:21 -0700 | [diff] [blame] | 359 | profile.isVerticalBarLayout()) { |
| 360 | matrix = FocusLogic.createSparseMatrix(iconLayout, hotseatLayout, false /* horizontal */, |
Sunny Goyal | 4f3e938 | 2015-06-05 00:13:25 -0700 | [diff] [blame] | 361 | profile.inv.hotseatAllAppsRank, |
Winson Chung | c393b07 | 2015-05-20 15:03:13 -0700 | [diff] [blame] | 362 | !hotseat.hasIcons() /* ignore all apps icon, unless there are no other icons */); |
Hyunyoung Song | 31178b8 | 2015-02-24 14:12:51 -0800 | [diff] [blame] | 363 | countX = countX + 1; |
Winson | fa56b3f | 2015-09-14 12:01:13 -0700 | [diff] [blame] | 364 | } else if (isUninstallKeyChord(e)) { |
| 365 | matrix = FocusLogic.createSparseMatrix(iconLayout); |
| 366 | if (UninstallDropTarget.supportsDrop(launcher, itemInfo)) { |
| 367 | UninstallDropTarget.startUninstallActivity(launcher, itemInfo); |
| 368 | } |
| 369 | } else if (isDeleteKeyChord(e)) { |
| 370 | matrix = FocusLogic.createSparseMatrix(iconLayout); |
Winson | 2949fb5 | 2015-09-24 09:56:11 -0700 | [diff] [blame] | 371 | launcher.removeItem(v, itemInfo, true /* deleteFromDb */); |
Hyunyoung Song | ee3e6a7 | 2015-02-20 14:25:27 -0800 | [diff] [blame] | 372 | } else { |
Hyunyoung Song | 31178b8 | 2015-02-24 14:12:51 -0800 | [diff] [blame] | 373 | matrix = FocusLogic.createSparseMatrix(iconLayout); |
Hyunyoung Song | ee3e6a7 | 2015-02-20 14:25:27 -0800 | [diff] [blame] | 374 | } |
| 375 | |
| 376 | // Process the focus. |
Adam Cohen | 2e6da15 | 2015-05-06 11:42:25 -0700 | [diff] [blame] | 377 | int newIconIndex = FocusLogic.handleKeyEvent(keyCode, countX, |
Sunny Goyal | c620560 | 2015-05-21 20:46:33 -0700 | [diff] [blame] | 378 | countY, matrix, iconIndex, pageIndex, pageCount, Utilities.isRtl(v.getResources())); |
Hyunyoung Song | ee3e6a7 | 2015-02-20 14:25:27 -0800 | [diff] [blame] | 379 | View newIcon = null; |
| 380 | switch (newIconIndex) { |
| 381 | case FocusLogic.NOOP: |
| 382 | if (keyCode == KeyEvent.KEYCODE_DPAD_UP) { |
| 383 | newIcon = tabs; |
| 384 | } |
| 385 | break; |
Hyunyoung Song | 3853171 | 2015-03-03 19:25:16 -0800 | [diff] [blame] | 386 | case FocusLogic.PREVIOUS_PAGE_RIGHT_COLUMN: |
Hyunyoung Song | ada5098 | 2015-04-10 14:35:23 -0700 | [diff] [blame] | 387 | case FocusLogic.NEXT_PAGE_RIGHT_COLUMN: |
| 388 | int newPageIndex = pageIndex - 1; |
| 389 | if (newIconIndex == FocusLogic.NEXT_PAGE_RIGHT_COLUMN) { |
| 390 | newPageIndex = pageIndex + 1; |
| 391 | } |
Sunny Goyal | fc3c1ed | 2015-04-09 18:48:21 -0700 | [diff] [blame] | 392 | int row = ((CellLayout.LayoutParams) v.getLayoutParams()).cellY; |
Hyunyoung Song | ada5098 | 2015-04-10 14:35:23 -0700 | [diff] [blame] | 393 | parent = getCellLayoutChildrenForIndex(workspace, newPageIndex); |
Hyunyoung Song | 3853171 | 2015-03-03 19:25:16 -0800 | [diff] [blame] | 394 | if (parent != null) { |
| 395 | iconLayout = (CellLayout) parent.getParent(); |
Hyunyoung Song | ac721f8 | 2015-03-04 16:33:56 -0800 | [diff] [blame] | 396 | matrix = FocusLogic.createSparseMatrix(iconLayout, |
Tony Wickham | 4fc8287 | 2015-11-10 16:52:14 -0800 | [diff] [blame^] | 397 | iconLayout.getCountX(), row); |
Adam Cohen | 2e6da15 | 2015-05-06 11:42:25 -0700 | [diff] [blame] | 398 | newIconIndex = FocusLogic.handleKeyEvent(keyCode, countX + 1, countY, |
Sunny Goyal | c620560 | 2015-05-21 20:46:33 -0700 | [diff] [blame] | 399 | matrix, FocusLogic.PIVOT, newPageIndex, pageCount, |
| 400 | Utilities.isRtl(v.getResources())); |
Hyunyoung Song | 3853171 | 2015-03-03 19:25:16 -0800 | [diff] [blame] | 401 | newIcon = parent.getChildAt(newIconIndex); |
| 402 | } |
| 403 | break; |
Hyunyoung Song | ee3e6a7 | 2015-02-20 14:25:27 -0800 | [diff] [blame] | 404 | case FocusLogic.PREVIOUS_PAGE_FIRST_ITEM: |
| 405 | parent = getCellLayoutChildrenForIndex(workspace, pageIndex - 1); |
| 406 | newIcon = parent.getChildAt(0); |
Hyunyoung Song | 3853171 | 2015-03-03 19:25:16 -0800 | [diff] [blame] | 407 | break; |
Hyunyoung Song | ee3e6a7 | 2015-02-20 14:25:27 -0800 | [diff] [blame] | 408 | case FocusLogic.PREVIOUS_PAGE_LAST_ITEM: |
| 409 | parent = getCellLayoutChildrenForIndex(workspace, pageIndex - 1); |
| 410 | newIcon = parent.getChildAt(parent.getChildCount() - 1); |
Hyunyoung Song | ee3e6a7 | 2015-02-20 14:25:27 -0800 | [diff] [blame] | 411 | break; |
| 412 | case FocusLogic.NEXT_PAGE_FIRST_ITEM: |
| 413 | parent = getCellLayoutChildrenForIndex(workspace, pageIndex + 1); |
| 414 | newIcon = parent.getChildAt(0); |
Hyunyoung Song | ee3e6a7 | 2015-02-20 14:25:27 -0800 | [diff] [blame] | 415 | break; |
Hyunyoung Song | 3853171 | 2015-03-03 19:25:16 -0800 | [diff] [blame] | 416 | case FocusLogic.NEXT_PAGE_LEFT_COLUMN: |
Hyunyoung Song | ada5098 | 2015-04-10 14:35:23 -0700 | [diff] [blame] | 417 | case FocusLogic.PREVIOUS_PAGE_LEFT_COLUMN: |
| 418 | newPageIndex = pageIndex + 1; |
| 419 | if (newIconIndex == FocusLogic.PREVIOUS_PAGE_LEFT_COLUMN) { |
| 420 | newPageIndex = pageIndex - 1; |
| 421 | } |
Sunny Goyal | fc3c1ed | 2015-04-09 18:48:21 -0700 | [diff] [blame] | 422 | row = ((CellLayout.LayoutParams) v.getLayoutParams()).cellY; |
Hyunyoung Song | ada5098 | 2015-04-10 14:35:23 -0700 | [diff] [blame] | 423 | parent = getCellLayoutChildrenForIndex(workspace, newPageIndex); |
Hyunyoung Song | 3853171 | 2015-03-03 19:25:16 -0800 | [diff] [blame] | 424 | if (parent != null) { |
| 425 | iconLayout = (CellLayout) parent.getParent(); |
Hyunyoung Song | ac721f8 | 2015-03-04 16:33:56 -0800 | [diff] [blame] | 426 | matrix = FocusLogic.createSparseMatrix(iconLayout, -1, row); |
Adam Cohen | 2e6da15 | 2015-05-06 11:42:25 -0700 | [diff] [blame] | 427 | newIconIndex = FocusLogic.handleKeyEvent(keyCode, countX + 1, countY, |
Sunny Goyal | c620560 | 2015-05-21 20:46:33 -0700 | [diff] [blame] | 428 | matrix, FocusLogic.PIVOT, newPageIndex, pageCount, |
| 429 | Utilities.isRtl(v.getResources())); |
Hyunyoung Song | 3853171 | 2015-03-03 19:25:16 -0800 | [diff] [blame] | 430 | newIcon = parent.getChildAt(newIconIndex); |
| 431 | } |
| 432 | break; |
Hyunyoung Song | ee3e6a7 | 2015-02-20 14:25:27 -0800 | [diff] [blame] | 433 | case FocusLogic.CURRENT_PAGE_FIRST_ITEM: |
| 434 | newIcon = parent.getChildAt(0); |
| 435 | break; |
| 436 | case FocusLogic.CURRENT_PAGE_LAST_ITEM: |
| 437 | newIcon = parent.getChildAt(parent.getChildCount() - 1); |
| 438 | break; |
| 439 | default: |
| 440 | // current page, some item. |
| 441 | if (0 <= newIconIndex && newIconIndex < parent.getChildCount()) { |
| 442 | newIcon = parent.getChildAt(newIconIndex); |
| 443 | } else if (parent.getChildCount() <= newIconIndex && |
| 444 | newIconIndex < parent.getChildCount() + hotseatParent.getChildCount()) { |
| 445 | newIcon = hotseatParent.getChildAt(newIconIndex - parent.getChildCount()); |
| 446 | } |
| 447 | break; |
| 448 | } |
| 449 | if (newIcon != null) { |
| 450 | newIcon.requestFocus(); |
| 451 | playSoundEffect(keyCode, v); |
| 452 | } |
| 453 | return consume; |
| 454 | } |
| 455 | |
Hyunyoung Song | ee3e6a7 | 2015-02-20 14:25:27 -0800 | [diff] [blame] | 456 | // |
| 457 | // Helper methods. |
| 458 | // |
| 459 | |
Winson Chung | 97d85d2 | 2011-04-13 11:27:36 -0700 | [diff] [blame] | 460 | /** |
Winson Chung | 97d85d2 | 2011-04-13 11:27:36 -0700 | [diff] [blame] | 461 | * Private helper method to get the CellLayoutChildren given a CellLayout index. |
| 462 | */ |
Sunny Goyal | 316490e | 2015-06-02 09:38:28 -0700 | [diff] [blame] | 463 | @Thunk static ShortcutAndWidgetContainer getCellLayoutChildrenForIndex( |
Michael Jurka | a52570f | 2012-03-20 03:18:20 -0700 | [diff] [blame] | 464 | ViewGroup container, int i) { |
Sunny Goyal | b3726d9 | 2014-08-20 16:58:17 -0700 | [diff] [blame] | 465 | CellLayout parent = (CellLayout) container.getChildAt(i); |
| 466 | return parent.getShortcutsAndWidgets(); |
Winson Chung | 97d85d2 | 2011-04-13 11:27:36 -0700 | [diff] [blame] | 467 | } |
| 468 | |
Winson Chung | 97d85d2 | 2011-04-13 11:27:36 -0700 | [diff] [blame] | 469 | /** |
Hyunyoung Song | ee3e6a7 | 2015-02-20 14:25:27 -0800 | [diff] [blame] | 470 | * Helper method to be used for playing sound effects. |
Winson Chung | 97d85d2 | 2011-04-13 11:27:36 -0700 | [diff] [blame] | 471 | */ |
Adam Cohen | 091440a | 2015-03-18 14:16:05 -0700 | [diff] [blame] | 472 | @Thunk static void playSoundEffect(int keyCode, View v) { |
Winson Chung | 97d85d2 | 2011-04-13 11:27:36 -0700 | [diff] [blame] | 473 | switch (keyCode) { |
| 474 | case KeyEvent.KEYCODE_DPAD_LEFT: |
Hyunyoung Song | ee3e6a7 | 2015-02-20 14:25:27 -0800 | [diff] [blame] | 475 | v.playSoundEffect(SoundEffectConstants.NAVIGATION_LEFT); |
Winson Chung | 97d85d2 | 2011-04-13 11:27:36 -0700 | [diff] [blame] | 476 | break; |
| 477 | case KeyEvent.KEYCODE_DPAD_RIGHT: |
Hyunyoung Song | ee3e6a7 | 2015-02-20 14:25:27 -0800 | [diff] [blame] | 478 | v.playSoundEffect(SoundEffectConstants.NAVIGATION_RIGHT); |
Winson Chung | 97d85d2 | 2011-04-13 11:27:36 -0700 | [diff] [blame] | 479 | break; |
| 480 | case KeyEvent.KEYCODE_DPAD_DOWN: |
Winson Chung | 97d85d2 | 2011-04-13 11:27:36 -0700 | [diff] [blame] | 481 | case KeyEvent.KEYCODE_PAGE_DOWN: |
Winson Chung | 97d85d2 | 2011-04-13 11:27:36 -0700 | [diff] [blame] | 482 | case KeyEvent.KEYCODE_MOVE_END: |
Hyunyoung Song | ee3e6a7 | 2015-02-20 14:25:27 -0800 | [diff] [blame] | 483 | v.playSoundEffect(SoundEffectConstants.NAVIGATION_DOWN); |
Adam Cohen | ac56cff | 2011-09-28 20:45:37 -0700 | [diff] [blame] | 484 | break; |
| 485 | case KeyEvent.KEYCODE_DPAD_UP: |
Hyunyoung Song | ee3e6a7 | 2015-02-20 14:25:27 -0800 | [diff] [blame] | 486 | case KeyEvent.KEYCODE_PAGE_UP: |
Adam Cohen | ac56cff | 2011-09-28 20:45:37 -0700 | [diff] [blame] | 487 | case KeyEvent.KEYCODE_MOVE_HOME: |
Hyunyoung Song | ee3e6a7 | 2015-02-20 14:25:27 -0800 | [diff] [blame] | 488 | v.playSoundEffect(SoundEffectConstants.NAVIGATION_UP); |
Adam Cohen | ac56cff | 2011-09-28 20:45:37 -0700 | [diff] [blame] | 489 | break; |
Hyunyoung Song | ee3e6a7 | 2015-02-20 14:25:27 -0800 | [diff] [blame] | 490 | default: |
Winson Chung | 97d85d2 | 2011-04-13 11:27:36 -0700 | [diff] [blame] | 491 | break; |
Winson Chung | 97d85d2 | 2011-04-13 11:27:36 -0700 | [diff] [blame] | 492 | } |
Winson Chung | 97d85d2 | 2011-04-13 11:27:36 -0700 | [diff] [blame] | 493 | } |
Winson | fa56b3f | 2015-09-14 12:01:13 -0700 | [diff] [blame] | 494 | |
| 495 | /** |
| 496 | * Returns whether the key event represents a valid uninstall key chord. |
| 497 | */ |
| 498 | private static boolean isUninstallKeyChord(KeyEvent event) { |
| 499 | int keyCode = event.getKeyCode(); |
| 500 | return (keyCode == KeyEvent.KEYCODE_DEL || keyCode == KeyEvent.KEYCODE_FORWARD_DEL) && |
| 501 | event.hasModifiers(KeyEvent.META_CTRL_ON | KeyEvent.META_SHIFT_ON); |
| 502 | } |
| 503 | |
| 504 | /** |
| 505 | * Returns whether the key event represents a valid delete key chord. |
| 506 | */ |
| 507 | private static boolean isDeleteKeyChord(KeyEvent event) { |
| 508 | int keyCode = event.getKeyCode(); |
| 509 | return (keyCode == KeyEvent.KEYCODE_DEL || keyCode == KeyEvent.KEYCODE_FORWARD_DEL) && |
| 510 | event.hasModifiers(KeyEvent.META_CTRL_ON); |
| 511 | } |
Winson Chung | 97d85d2 | 2011-04-13 11:27:36 -0700 | [diff] [blame] | 512 | } |