blob: 3ca16d476da3a85a517317f742c3d68a1a4acd54 [file] [log] [blame]
Winson Chung97d85d22011-04-13 11:27:36 -07001/*
Hyunyoung Songee3e6a72015-02-20 14:25:27 -08002 * Copyright (C) 2015 The Android Open Source Project
Winson Chung97d85d22011-04-13 11:27:36 -07003 *
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 Sandler325dc232013-06-05 22:57:57 -040017package com.android.launcher3;
Winson Chung97d85d22011-04-13 11:27:36 -070018
Winson Chung4e6a9762011-05-09 11:56:34 -070019import android.content.res.Configuration;
Hyunyoung Songee3e6a72015-02-20 14:25:27 -080020import android.util.Log;
Winson Chung97d85d22011-04-13 11:27:36 -070021import android.view.KeyEvent;
Sunny Goyalb3726d92014-08-20 16:58:17 -070022import android.view.SoundEffectConstants;
Winson Chung97d85d22011-04-13 11:27:36 -070023import android.view.View;
24import android.view.ViewGroup;
Winson Chung97d85d22011-04-13 11:27:36 -070025
Hyunyoung Songee3e6a72015-02-20 14:25:27 -080026import com.android.launcher3.util.FocusLogic;
Winson Chungfaa13252011-06-13 18:15:54 -070027
Winson Chung97d85d22011-04-13 11:27:36 -070028/**
Winson Chung4d279d92011-07-21 11:46:32 -070029 * A keyboard listener we set on all the workspace icons.
30 */
Adam Cohenac56cff2011-09-28 20:45:37 -070031class IconKeyEventListener implements View.OnKeyListener {
Hyunyoung Songee3e6a72015-02-20 14:25:27 -080032 @Override
Winson Chung4d279d92011-07-21 11:46:32 -070033 public boolean onKey(View v, int keyCode, KeyEvent event) {
Adam Cohenac56cff2011-09-28 20:45:37 -070034 return FocusHelper.handleIconKeyEvent(v, keyCode, event);
35 }
36}
37
38/**
39 * A keyboard listener we set on all the workspace icons.
40 */
41class FolderKeyEventListener implements View.OnKeyListener {
Hyunyoung Songee3e6a72015-02-20 14:25:27 -080042 @Override
Adam Cohenac56cff2011-09-28 20:45:37 -070043 public boolean onKey(View v, int keyCode, KeyEvent event) {
44 return FocusHelper.handleFolderKeyEvent(v, keyCode, event);
Winson Chung4d279d92011-07-21 11:46:32 -070045 }
46}
47
48/**
Winson Chung3d503fb2011-07-13 17:25:49 -070049 * A keyboard listener we set on all the hotseat buttons.
Winson Chung4e6a9762011-05-09 11:56:34 -070050 */
Adam Cohenac56cff2011-09-28 20:45:37 -070051class HotseatIconKeyEventListener implements View.OnKeyListener {
Hyunyoung Songee3e6a72015-02-20 14:25:27 -080052 @Override
Winson Chung4e6a9762011-05-09 11:56:34 -070053 public boolean onKey(View v, int keyCode, KeyEvent event) {
Hyunyoung Songee3e6a72015-02-20 14:25:27 -080054 return FocusHelper.handleHotseatButtonKeyEvent(v, keyCode, event);
Winson Chung4e6a9762011-05-09 11:56:34 -070055 }
56}
57
Winson Chung97d85d22011-04-13 11:27:36 -070058public class FocusHelper {
Winson Chung97d85d22011-04-13 11:27:36 -070059
Hyunyoung Songee3e6a72015-02-20 14:25:27 -080060 private static final String TAG = "FocusHelper";
61 private static final boolean DEBUG = false;
62
63 //
64 // Key code handling methods.
65 //
66
67 /**
68 * Handles key events in the all apps screen.
69 */
70 static boolean handleAppsCustomizeKeyEvent(View v, int keyCode, KeyEvent e) {
71 boolean consume = FocusLogic.shouldConsume(keyCode);
72 if (e.getAction() == KeyEvent.ACTION_UP) {
73 return consume;
74 }
75 if (DEBUG) {
76 Log.v(TAG, String.format("Handle ALL APPS keyevent=[%s].",
77 KeyEvent.keyCodeToString(keyCode)));
78 }
79
80 // Initialize variables.
81 ViewGroup parentLayout;
82 ViewGroup itemContainer;
83 int countX;
84 int countY;
85 if (v.getParent() instanceof ShortcutAndWidgetContainer) {
86 itemContainer = (ViewGroup) v.getParent();
87 parentLayout = (ViewGroup) itemContainer.getParent();
88 countX = ((CellLayout) parentLayout).getCountX();
89 countY = ((CellLayout) parentLayout).getCountY();
90 } else if (v.getParent() instanceof ViewGroup) {
91 itemContainer = parentLayout = (ViewGroup) v.getParent();
92 countX = ((PagedViewGridLayout) parentLayout).getCellCountX();
93 countY = ((PagedViewGridLayout) parentLayout).getCellCountY();
94 } else {
95 throw new IllegalStateException(
96 "Parent of the focused item inside all apps screen is not a supported type.");
97 }
98 final int iconIndex = itemContainer.indexOfChild(v);
99 final PagedView container = (PagedView) parentLayout.getParent();
100 final int pageIndex = container.indexToPage(container.indexOfChild(parentLayout));
101 final int pageCount = container.getChildCount();
102 ViewGroup newParent = null;
103 View child = null;
104 int[][] matrix = FocusLogic.createFullMatrix(countX, countY, true);
105
106 // Process focus.
107 int newIconIndex = FocusLogic.handleKeyEvent(keyCode, countX, countY, matrix,
108 iconIndex, pageIndex, pageCount);
109 if (newIconIndex == FocusLogic.NOOP) {
110 return consume;
111 }
112 switch (newIconIndex) {
113 case FocusLogic.PREVIOUS_PAGE_FIRST_ITEM:
114 newParent = getAppsCustomizePage(container, pageIndex - 1);
115 if (newParent != null) {
116 container.snapToPage(pageIndex - 1);
117 child = newParent.getChildAt(0);
118 }
119 case FocusLogic.PREVIOUS_PAGE_LAST_ITEM:
120 newParent = getAppsCustomizePage(container, pageIndex - 1);
121 if (newParent != null) {
122 container.snapToPage(pageIndex - 1);
123 child = newParent.getChildAt(newParent.getChildCount() - 1);
124 }
125 break;
126 case FocusLogic.NEXT_PAGE_FIRST_ITEM:
127 newParent = getAppsCustomizePage(container, pageIndex + 1);
128 if (newParent != null) {
129 container.snapToPage(pageIndex + 1);
130 child = newParent.getChildAt(0);
131 }
132 break;
133 case FocusLogic.CURRENT_PAGE_FIRST_ITEM:
134 child = container.getChildAt(0);
135 break;
136 case FocusLogic.CURRENT_PAGE_LAST_ITEM:
137 child = itemContainer.getChildAt(itemContainer.getChildCount() - 1);
138 break;
139 default: // Go to some item on the current page.
140 child = itemContainer.getChildAt(newIconIndex);
141 break;
142 }
143 if (child != null) {
144 child.requestFocus();
145 playSoundEffect(keyCode, v);
146 }
147 return consume;
148 }
149
150 /**
151 * Handles key events in the workspace hot seat (bottom of the screen).
152 * <p>Currently we don't special case for the phone UI in different orientations, even though
153 * the hotseat is on the side in landscape mode. This is to ensure that accessibility
154 * consistency is maintained across rotations.
155 */
156 static boolean handleHotseatButtonKeyEvent(View v, int keyCode, KeyEvent e) {
157 boolean consume = FocusLogic.shouldConsume(keyCode);
158 if (e.getAction() == KeyEvent.ACTION_UP || !consume) {
159 return consume;
160 }
161 int orientation = v.getResources().getConfiguration().orientation;
162
163 if (DEBUG) {
164 Log.v(TAG, String.format(
165 "Handle HOTSEAT BUTTONS keyevent=[%s] on hotseat buttons, orientation=%d",
166 KeyEvent.keyCodeToString(keyCode), orientation));
167 }
168
169 // Initialize the variables.
170 final ShortcutAndWidgetContainer hotseatParent = (ShortcutAndWidgetContainer) v.getParent();
171 final CellLayout hotseatLayout = (CellLayout) hotseatParent.getParent();
Hyunyoung Song31178b82015-02-24 14:12:51 -0800172 Hotseat hotseat = (Hotseat) hotseatLayout.getParent();
173
Hyunyoung Songee3e6a72015-02-20 14:25:27 -0800174 Workspace workspace = (Workspace) v.getRootView().findViewById(R.id.workspace);
175 int pageIndex = workspace.getCurrentPage();
176 int pageCount = workspace.getChildCount();
Hyunyoung Song31178b82015-02-24 14:12:51 -0800177 int countX = -1;
178 int countY = -1;
Hyunyoung Songee3e6a72015-02-20 14:25:27 -0800179 int iconIndex = findIndexOfView(hotseatParent, v);
180
181 final CellLayout iconLayout = (CellLayout) workspace.getChildAt(pageIndex);
182 final ViewGroup iconParent = iconLayout.getShortcutsAndWidgets();
183
184 ViewGroup parent = null;
Hyunyoung Song31178b82015-02-24 14:12:51 -0800185 int[][] matrix = null;
Hyunyoung Songee3e6a72015-02-20 14:25:27 -0800186
187 if (keyCode == KeyEvent.KEYCODE_DPAD_UP &&
188 orientation == Configuration.ORIENTATION_PORTRAIT) {
Hyunyoung Song31178b82015-02-24 14:12:51 -0800189 matrix = FocusLogic.createSparseMatrix(iconLayout, hotseatLayout, orientation,
190 hotseat.getAllAppsButtonRank(), true /* include all apps icon */);
Hyunyoung Songee3e6a72015-02-20 14:25:27 -0800191 iconIndex += iconParent.getChildCount();
192 countX = iconLayout.getCountX();
193 countY = iconLayout.getCountY() + hotseatLayout.getCountY();
194 parent = iconParent;
195 } else if (keyCode == KeyEvent.KEYCODE_DPAD_LEFT &&
196 orientation == Configuration.ORIENTATION_LANDSCAPE) {
Hyunyoung Song31178b82015-02-24 14:12:51 -0800197 matrix = FocusLogic.createSparseMatrix(iconLayout, hotseatLayout, orientation,
198 hotseat.getAllAppsButtonRank(), true /* include all apps icon */);
Hyunyoung Songee3e6a72015-02-20 14:25:27 -0800199 iconIndex += iconParent.getChildCount();
200 countX = iconLayout.getCountX() + hotseatLayout.getCountX();
201 countY = iconLayout.getCountY();
202 parent = iconParent;
Hyunyoung Song31178b82015-02-24 14:12:51 -0800203 } else if (keyCode == KeyEvent.KEYCODE_DPAD_RIGHT &&
204 orientation == Configuration.ORIENTATION_LANDSCAPE) {
205 keyCode = KeyEvent.KEYCODE_PAGE_DOWN;
206 }else {
Hyunyoung Songee3e6a72015-02-20 14:25:27 -0800207 // For other KEYCODE_DPAD_LEFT and KEYCODE_DPAD_RIGHT navigation, do not use the
208 // matrix extended with hotseat.
209 matrix = FocusLogic.createSparseMatrix(hotseatLayout);
Hyunyoung Songee3e6a72015-02-20 14:25:27 -0800210 countX = hotseatLayout.getCountX();
211 countY = hotseatLayout.getCountY();
Hyunyoung Song31178b82015-02-24 14:12:51 -0800212 parent = hotseatParent;
Hyunyoung Songee3e6a72015-02-20 14:25:27 -0800213 }
214
215 // Process the focus.
216 int newIconIndex = FocusLogic.handleKeyEvent(keyCode, countX, countY, matrix,
217 iconIndex, pageIndex, pageCount);
218
Hyunyoung Song31178b82015-02-24 14:12:51 -0800219 View newIcon = null;
220 if (newIconIndex == FocusLogic.NEXT_PAGE_FIRST_ITEM) {
221 parent = getCellLayoutChildrenForIndex(workspace, pageIndex + 1);
222 newIcon = parent.getChildAt(0);
223 // TODO(hyunyoungs): handle cases where the child is not an icon but
224 // a folder or a widget.
225 workspace.snapToPage(pageIndex + 1);
226 }
227 if (parent == iconParent && newIconIndex >= iconParent.getChildCount()) {
Hyunyoung Songee3e6a72015-02-20 14:25:27 -0800228 newIconIndex -= iconParent.getChildCount();
229 }
230 if (parent != null) {
Hyunyoung Song31178b82015-02-24 14:12:51 -0800231 if (newIcon == null && newIconIndex >=0) {
232 newIcon = parent.getChildAt(newIconIndex);
233 }
Hyunyoung Songee3e6a72015-02-20 14:25:27 -0800234 if (newIcon != null) {
235 newIcon.requestFocus();
236 playSoundEffect(keyCode, v);
237 }
238 }
239 return consume;
240 }
241
242 /**
243 * Handles key events in a workspace containing icons.
244 */
245 static boolean handleIconKeyEvent(View v, int keyCode, KeyEvent e) {
246 boolean consume = FocusLogic.shouldConsume(keyCode);
247 if (e.getAction() == KeyEvent.ACTION_UP || !consume) {
248 return consume;
249 }
250 int orientation = v.getResources().getConfiguration().orientation;
251 if (DEBUG) {
252 Log.v(TAG, String.format("Handle WORKSPACE ICONS keyevent=[%s] orientation=%d",
253 KeyEvent.keyCodeToString(keyCode), orientation));
254 }
255
256 // Initialize the variables.
257 ShortcutAndWidgetContainer parent = (ShortcutAndWidgetContainer) v.getParent();
Hyunyoung Song31178b82015-02-24 14:12:51 -0800258 final CellLayout iconLayout = (CellLayout) parent.getParent();
259 final Workspace workspace = (Workspace) iconLayout.getParent();
Hyunyoung Songee3e6a72015-02-20 14:25:27 -0800260 final ViewGroup launcher = (ViewGroup) workspace.getParent();
261 final ViewGroup tabs = (ViewGroup) launcher.findViewById(R.id.search_drop_target_bar);
Hyunyoung Song31178b82015-02-24 14:12:51 -0800262 final Hotseat hotseat = (Hotseat) launcher.findViewById(R.id.hotseat);
263 int pageIndex = workspace.indexOfChild(iconLayout);
Hyunyoung Songee3e6a72015-02-20 14:25:27 -0800264 int pageCount = workspace.getChildCount();
Hyunyoung Song31178b82015-02-24 14:12:51 -0800265 int countX = iconLayout.getCountX();
266 int countY = iconLayout.getCountY();
Hyunyoung Songee3e6a72015-02-20 14:25:27 -0800267 final int iconIndex = findIndexOfView(parent, v);
268
269 CellLayout hotseatLayout = (CellLayout) hotseat.getChildAt(0);
270 ShortcutAndWidgetContainer hotseatParent = hotseatLayout.getShortcutsAndWidgets();
271 int[][] matrix;
272
Hyunyoung Song31178b82015-02-24 14:12:51 -0800273 // KEYCODE_DPAD_DOWN in portrait (KEYCODE_DPAD_RIGHT in landscape) is the only key allowed
Hyunyoung Songee3e6a72015-02-20 14:25:27 -0800274 // to take a user to the hotseat. For other dpad navigation, do not use the matrix extended
275 // with the hotseat.
276 if (keyCode == KeyEvent.KEYCODE_DPAD_DOWN &&
277 orientation == Configuration.ORIENTATION_PORTRAIT) {
Hyunyoung Song31178b82015-02-24 14:12:51 -0800278 matrix = FocusLogic.createSparseMatrix(iconLayout, hotseatLayout, orientation,
279 hotseat.getAllAppsButtonRank(), false /* all apps icon is ignored */);
Hyunyoung Songee3e6a72015-02-20 14:25:27 -0800280 countY = countY + 1;
Hyunyoung Song31178b82015-02-24 14:12:51 -0800281 } else if (keyCode == KeyEvent.KEYCODE_DPAD_RIGHT &&
Hyunyoung Songee3e6a72015-02-20 14:25:27 -0800282 orientation == Configuration.ORIENTATION_LANDSCAPE) {
Hyunyoung Song31178b82015-02-24 14:12:51 -0800283 matrix = FocusLogic.createSparseMatrix(iconLayout, hotseatLayout, orientation,
284 hotseat.getAllAppsButtonRank(), false /* all apps icon is ignored */);
285 countX = countX + 1;
286 } else if (keyCode == KeyEvent.KEYCODE_DEL || keyCode == KeyEvent.KEYCODE_FORWARD_DEL) {
287 workspace.removeWorkspaceItem(v);
288 return consume;
Hyunyoung Songee3e6a72015-02-20 14:25:27 -0800289 } else {
Hyunyoung Song31178b82015-02-24 14:12:51 -0800290 matrix = FocusLogic.createSparseMatrix(iconLayout);
Hyunyoung Songee3e6a72015-02-20 14:25:27 -0800291 }
292
293 // Process the focus.
294 int newIconIndex = FocusLogic.handleKeyEvent(keyCode, countX, countY, matrix,
295 iconIndex, pageIndex, pageCount);
296 View newIcon = null;
297 switch (newIconIndex) {
298 case FocusLogic.NOOP:
299 if (keyCode == KeyEvent.KEYCODE_DPAD_UP) {
300 newIcon = tabs;
301 }
302 break;
303 case FocusLogic.PREVIOUS_PAGE_FIRST_ITEM:
304 parent = getCellLayoutChildrenForIndex(workspace, pageIndex - 1);
305 newIcon = parent.getChildAt(0);
306 workspace.snapToPage(pageIndex - 1);
307 case FocusLogic.PREVIOUS_PAGE_LAST_ITEM:
308 parent = getCellLayoutChildrenForIndex(workspace, pageIndex - 1);
309 newIcon = parent.getChildAt(parent.getChildCount() - 1);
310 workspace.snapToPage(pageIndex - 1);
311 break;
312 case FocusLogic.NEXT_PAGE_FIRST_ITEM:
313 parent = getCellLayoutChildrenForIndex(workspace, pageIndex + 1);
314 newIcon = parent.getChildAt(0);
Hyunyoung Song31178b82015-02-24 14:12:51 -0800315 workspace.snapToPage(pageIndex + 1);
Hyunyoung Songee3e6a72015-02-20 14:25:27 -0800316 break;
317 case FocusLogic.CURRENT_PAGE_FIRST_ITEM:
318 newIcon = parent.getChildAt(0);
319 break;
320 case FocusLogic.CURRENT_PAGE_LAST_ITEM:
321 newIcon = parent.getChildAt(parent.getChildCount() - 1);
322 break;
323 default:
324 // current page, some item.
325 if (0 <= newIconIndex && newIconIndex < parent.getChildCount()) {
326 newIcon = parent.getChildAt(newIconIndex);
327 } else if (parent.getChildCount() <= newIconIndex &&
328 newIconIndex < parent.getChildCount() + hotseatParent.getChildCount()) {
329 newIcon = hotseatParent.getChildAt(newIconIndex - parent.getChildCount());
330 }
331 break;
332 }
333 if (newIcon != null) {
334 newIcon.requestFocus();
335 playSoundEffect(keyCode, v);
336 }
337 return consume;
338 }
339
340 /**
341 * Handles key events for items in a Folder.
342 */
343 static boolean handleFolderKeyEvent(View v, int keyCode, KeyEvent e) {
344 boolean consume = FocusLogic.shouldConsume(keyCode);
345 if (e.getAction() == KeyEvent.ACTION_UP || !consume) {
346 return consume;
347 }
348 if (DEBUG) {
349 Log.v(TAG, String.format("Handle FOLDER keyevent=[%s].",
350 KeyEvent.keyCodeToString(keyCode)));
351 }
352
353 // Initialize the variables.
354 ShortcutAndWidgetContainer parent = (ShortcutAndWidgetContainer) v.getParent();
355 final CellLayout layout = (CellLayout) parent.getParent();
Sunny Goyalc3a609f2015-02-26 17:43:50 -0800356 final Folder folder = (Folder) layout.getParent().getParent();
Hyunyoung Songee3e6a72015-02-20 14:25:27 -0800357 View title = folder.mFolderName;
358 Workspace workspace = (Workspace) v.getRootView().findViewById(R.id.workspace);
359 final int countX = layout.getCountX();
360 final int countY = layout.getCountY();
361 final int iconIndex = findIndexOfView(parent, v);
362 int pageIndex = workspace.indexOfChild(layout);
363 int pageCount = workspace.getChildCount();
Hyunyoung Song31178b82015-02-24 14:12:51 -0800364 int[][] map = FocusLogic.createFullMatrix(countX, countY, true /* incremental order */);
Hyunyoung Songee3e6a72015-02-20 14:25:27 -0800365
366 // Process the focus.
367 int newIconIndex = FocusLogic.handleKeyEvent(keyCode, countX, countY, map, iconIndex,
368 pageIndex, pageCount);
369 View newIcon = null;
370 switch (newIconIndex) {
371 case FocusLogic.NOOP:
372 if (keyCode == KeyEvent.KEYCODE_DPAD_DOWN) {
373 newIcon = title;
374 }
375 break;
376 case FocusLogic.PREVIOUS_PAGE_FIRST_ITEM:
377 case FocusLogic.PREVIOUS_PAGE_LAST_ITEM:
378 case FocusLogic.NEXT_PAGE_FIRST_ITEM:
379 case FocusLogic.CURRENT_PAGE_FIRST_ITEM:
380 case FocusLogic.CURRENT_PAGE_LAST_ITEM:
381 if (DEBUG) {
382 Log.v(TAG, "Page advance handling not supported on folder icons.");
383 }
384 break;
385 default: // current page some item.
386 newIcon = parent.getChildAt(newIconIndex);
387 break;
388 }
389 if (newIcon != null) {
390 newIcon.requestFocus();
391 playSoundEffect(keyCode, v);
392 }
393 return consume;
394 }
395
396 //
397 // Helper methods.
398 //
399
Winson Chung97d85d22011-04-13 11:27:36 -0700400 /**
Adam Cohenae4f1552011-10-20 00:15:42 -0700401 * Returns the Viewgroup containing page contents for the page at the index specified.
402 */
403 private static ViewGroup getAppsCustomizePage(ViewGroup container, int index) {
404 ViewGroup page = (ViewGroup) ((PagedView) container).getPageAt(index);
Winson Chungc58497e2013-09-03 17:48:37 -0700405 if (page instanceof CellLayout) {
Adam Cohenae4f1552011-10-20 00:15:42 -0700406 // There are two layers, a PagedViewCellLayout and PagedViewCellLayoutChildren
Winson Chungc58497e2013-09-03 17:48:37 -0700407 page = ((CellLayout) page).getShortcutsAndWidgets();
Adam Cohenae4f1552011-10-20 00:15:42 -0700408 }
409 return page;
410 }
411
412 /**
Winson Chung97d85d22011-04-13 11:27:36 -0700413 * Private helper method to get the CellLayoutChildren given a CellLayout index.
414 */
Michael Jurkaa52570f2012-03-20 03:18:20 -0700415 private static ShortcutAndWidgetContainer getCellLayoutChildrenForIndex(
416 ViewGroup container, int i) {
Sunny Goyalb3726d92014-08-20 16:58:17 -0700417 CellLayout parent = (CellLayout) container.getChildAt(i);
418 return parent.getShortcutsAndWidgets();
Winson Chung97d85d22011-04-13 11:27:36 -0700419 }
420
Hyunyoung Songee3e6a72015-02-20 14:25:27 -0800421 private static int findIndexOfView(ViewGroup parent, View v) {
422 for (int i = 0; i < parent.getChildCount(); i++) {
423 if (v != null && v.equals(parent.getChildAt(i))) {
424 return i;
Winson Chung97d85d22011-04-13 11:27:36 -0700425 }
426 }
Hyunyoung Songee3e6a72015-02-20 14:25:27 -0800427 return -1;
Winson Chung97d85d22011-04-13 11:27:36 -0700428 }
429
430 /**
Hyunyoung Songee3e6a72015-02-20 14:25:27 -0800431 * Helper method to be used for playing sound effects.
Winson Chung97d85d22011-04-13 11:27:36 -0700432 */
Hyunyoung Songee3e6a72015-02-20 14:25:27 -0800433 private static void playSoundEffect(int keyCode, View v) {
Winson Chung97d85d22011-04-13 11:27:36 -0700434 switch (keyCode) {
435 case KeyEvent.KEYCODE_DPAD_LEFT:
Hyunyoung Songee3e6a72015-02-20 14:25:27 -0800436 v.playSoundEffect(SoundEffectConstants.NAVIGATION_LEFT);
Winson Chung97d85d22011-04-13 11:27:36 -0700437 break;
438 case KeyEvent.KEYCODE_DPAD_RIGHT:
Hyunyoung Songee3e6a72015-02-20 14:25:27 -0800439 v.playSoundEffect(SoundEffectConstants.NAVIGATION_RIGHT);
Winson Chung97d85d22011-04-13 11:27:36 -0700440 break;
441 case KeyEvent.KEYCODE_DPAD_DOWN:
Winson Chung97d85d22011-04-13 11:27:36 -0700442 case KeyEvent.KEYCODE_PAGE_DOWN:
Winson Chung97d85d22011-04-13 11:27:36 -0700443 case KeyEvent.KEYCODE_MOVE_END:
Hyunyoung Songee3e6a72015-02-20 14:25:27 -0800444 v.playSoundEffect(SoundEffectConstants.NAVIGATION_DOWN);
Adam Cohenac56cff2011-09-28 20:45:37 -0700445 break;
446 case KeyEvent.KEYCODE_DPAD_UP:
Hyunyoung Songee3e6a72015-02-20 14:25:27 -0800447 case KeyEvent.KEYCODE_PAGE_UP:
Adam Cohenac56cff2011-09-28 20:45:37 -0700448 case KeyEvent.KEYCODE_MOVE_HOME:
Hyunyoung Songee3e6a72015-02-20 14:25:27 -0800449 v.playSoundEffect(SoundEffectConstants.NAVIGATION_UP);
Adam Cohenac56cff2011-09-28 20:45:37 -0700450 break;
Hyunyoung Songee3e6a72015-02-20 14:25:27 -0800451 default:
Winson Chung97d85d22011-04-13 11:27:36 -0700452 break;
Winson Chung97d85d22011-04-13 11:27:36 -0700453 }
Winson Chung97d85d22011-04-13 11:27:36 -0700454 }
455}