static boolean handleIconKeyEvent(View v,int keyCode,KeyEvent e){
  boolean consume=FocusLogic.shouldConsume(keyCode);
  if (e.getAction() == KeyEvent.ACTION_UP || !consume) {
    return consume;
  }
  Launcher launcher=(Launcher)v.getContext();
  DeviceProfile profile=launcher.getDeviceProfile();
  if (DEBUG) {
    Log.v(TAG,String.format("Handle WORKSPACE ICONS keyevent=[%s] isVerticalBar=%s",KeyEvent.keyCodeToString(keyCode),profile.isVerticalBarLayout()));
  }
  ShortcutAndWidgetContainer parent=(ShortcutAndWidgetContainer)v.getParent();
  CellLayout iconLayout=(CellLayout)parent.getParent();
  final Workspace workspace=(Workspace)iconLayout.getParent();
  final ViewGroup dragLayer=(ViewGroup)workspace.getParent();
  final ViewGroup tabs=(ViewGroup)dragLayer.findViewById(R.id.search_drop_target_bar);
  final Hotseat hotseat=(Hotseat)dragLayer.findViewById(R.id.hotseat);
  final ItemInfo itemInfo=(ItemInfo)v.getTag();
  final int iconIndex=parent.indexOfChild(v);
  final int pageIndex=workspace.indexOfChild(iconLayout);
  final int pageCount=workspace.getChildCount();
  CellLayout hotseatLayout=(CellLayout)hotseat.getChildAt(0);
  ShortcutAndWidgetContainer hotseatParent=hotseatLayout.getShortcutsAndWidgets();
  int[][] matrix;
  if (keyCode == KeyEvent.KEYCODE_DPAD_DOWN && !profile.isVerticalBarLayout()) {
    matrix=FocusLogic.createSparseMatrixWithHotseat(iconLayout,hotseatLayout,true,profile.inv.hotseatAllAppsRank);
  }
 else   if (keyCode == KeyEvent.KEYCODE_DPAD_RIGHT && profile.isVerticalBarLayout()) {
    matrix=FocusLogic.createSparseMatrixWithHotseat(iconLayout,hotseatLayout,false,profile.inv.hotseatAllAppsRank);
  }
 else   if (isUninstallKeyChord(e)) {
    matrix=FocusLogic.createSparseMatrix(iconLayout);
    if (UninstallDropTarget.supportsDrop(launcher,itemInfo)) {
      UninstallDropTarget.startUninstallActivity(launcher,itemInfo);
    }
  }
 else   if (isDeleteKeyChord(e)) {
    matrix=FocusLogic.createSparseMatrix(iconLayout);
    launcher.removeItem(v,itemInfo,true);
  }
 else {
    matrix=FocusLogic.createSparseMatrix(iconLayout);
  }
  int newIconIndex=FocusLogic.handleKeyEvent(keyCode,matrix,iconIndex,pageIndex,pageCount,Utilities.isRtl(v.getResources()));
  boolean isRtl=Utilities.isRtl(v.getResources());
  View newIcon=null;
  CellLayout workspaceLayout=(CellLayout)workspace.getChildAt(pageIndex);
switch (newIconIndex) {
case FocusLogic.NOOP:
    if (keyCode == KeyEvent.KEYCODE_DPAD_UP) {
      newIcon=tabs;
    }
  break;
case FocusLogic.PREVIOUS_PAGE_RIGHT_COLUMN:
case FocusLogic.NEXT_PAGE_RIGHT_COLUMN:
int newPageIndex=pageIndex - 1;
if (newIconIndex == FocusLogic.NEXT_PAGE_RIGHT_COLUMN) {
newPageIndex=pageIndex + 1;
}
int row=((CellLayout.LayoutParams)v.getLayoutParams()).cellY;
parent=getCellLayoutChildrenForIndex(workspace,newPageIndex);
if (parent != null) {
iconLayout=(CellLayout)parent.getParent();
matrix=FocusLogic.createSparseMatrixWithPivotColumn(iconLayout,iconLayout.getCountX(),row);
newIconIndex=FocusLogic.handleKeyEvent(keyCode,matrix,FocusLogic.PIVOT,newPageIndex,pageCount,Utilities.isRtl(v.getResources()));
if (newIconIndex == FocusLogic.NEXT_PAGE_FIRST_ITEM) {
newIcon=handleNextPageFirstItem(workspace,hotseatLayout,pageIndex,isRtl);
}
 else if (newIconIndex == FocusLogic.PREVIOUS_PAGE_LAST_ITEM) {
newIcon=handlePreviousPageLastItem(workspace,hotseatLayout,pageIndex,isRtl);
}
 else {
newIcon=parent.getChildAt(newIconIndex);
}
}
break;
case FocusLogic.PREVIOUS_PAGE_FIRST_ITEM:
workspaceLayout=(CellLayout)workspace.getChildAt(pageIndex - 1);
newIcon=getFirstFocusableIconInReadingOrder(workspaceLayout,isRtl);
if (newIcon == null) {
newIcon=getFirstFocusableIconInReadingOrder(hotseatLayout,isRtl);
workspace.snapToPage(pageIndex - 1);
}
break;
case FocusLogic.PREVIOUS_PAGE_LAST_ITEM:
newIcon=handlePreviousPageLastItem(workspace,hotseatLayout,pageIndex,isRtl);
break;
case FocusLogic.NEXT_PAGE_FIRST_ITEM:
newIcon=handleNextPageFirstItem(workspace,hotseatLayout,pageIndex,isRtl);
break;
case FocusLogic.NEXT_PAGE_LEFT_COLUMN:
case FocusLogic.PREVIOUS_PAGE_LEFT_COLUMN:
newPageIndex=pageIndex + 1;
if (newIconIndex == FocusLogic.PREVIOUS_PAGE_LEFT_COLUMN) {
newPageIndex=pageIndex - 1;
}
row=((CellLayout.LayoutParams)v.getLayoutParams()).cellY;
parent=getCellLayoutChildrenForIndex(workspace,newPageIndex);
if (parent != null) {
iconLayout=(CellLayout)parent.getParent();
matrix=FocusLogic.createSparseMatrixWithPivotColumn(iconLayout,-1,row);
newIconIndex=FocusLogic.handleKeyEvent(keyCode,matrix,FocusLogic.PIVOT,newPageIndex,pageCount,Utilities.isRtl(v.getResources()));
if (newIconIndex == FocusLogic.NEXT_PAGE_FIRST_ITEM) {
newIcon=handleNextPageFirstItem(workspace,hotseatLayout,pageIndex,isRtl);
}
 else if (newIconIndex == FocusLogic.PREVIOUS_PAGE_LAST_ITEM) {
newIcon=handlePreviousPageLastItem(workspace,hotseatLayout,pageIndex,isRtl);
}
 else {
newIcon=parent.getChildAt(newIconIndex);
}
}
break;
case FocusLogic.CURRENT_PAGE_FIRST_ITEM:
newIcon=getFirstFocusableIconInReadingOrder(workspaceLayout,isRtl);
if (newIcon == null) {
newIcon=getFirstFocusableIconInReadingOrder(hotseatLayout,isRtl);
}
break;
case FocusLogic.CURRENT_PAGE_LAST_ITEM:
newIcon=getFirstFocusableIconInReverseReadingOrder(workspaceLayout,isRtl);
if (newIcon == null) {
newIcon=getFirstFocusableIconInReverseReadingOrder(hotseatLayout,isRtl);
}
break;
default :
if (0 <= newIconIndex && newIconIndex < parent.getChildCount()) {
newIcon=parent.getChildAt(newIconIndex);
}
 else if (parent.getChildCount() <= newIconIndex && newIconIndex < parent.getChildCount() + hotseatParent.getChildCount()) {
newIcon=hotseatParent.getChildAt(newIconIndex - parent.getChildCount());
}
break;
}
if (newIcon != null) {
newIcon.requestFocus();
playSoundEffect(keyCode,v);
}
return consume;
}

static boolean handleIconKeyEvent ( View v , int keyCode , KeyEvent e ) { boolean consume = FocusLogic . shouldConsume ( keyCode ) ; if ( e . getAction ( ) == KeyEvent . ACTION_UP || ! consume ) { return consume ; } Launcher launcher = ( Launcher ) v . getContext ( ) ; DeviceProfile profile = launcher . getDeviceProfile ( ) ; if ( DEBUG ) { Log . v ( TAG , String . format ( "Handle WORKSPACE ICONS keyevent=[%s] isVerticalBar=%s" , KeyEvent . keyCodeToString ( keyCode ) , profile . isVerticalBarLayout ( ) ) ) ; } ShortcutAndWidgetContainer parent = ( ShortcutAndWidgetContainer ) v . getParent ( ) ; CellLayout iconLayout = ( CellLayout ) parent . getParent ( ) ; final Workspace workspace = ( Workspace ) iconLayout . getParent ( ) ; final ViewGroup dragLayer = ( ViewGroup ) workspace . getParent ( ) ; final ViewGroup tabs = ( ViewGroup ) dragLayer . findViewById ( R . id . search_drop_target_bar ) ; final Hotseat hotseat = ( Hotseat ) dragLayer . findViewById ( R . id . hotseat ) ; final ItemInfo itemInfo = ( ItemInfo ) v . getTag ( ) ; final int iconIndex = parent . indexOfChild ( v ) ; final int pageIndex = workspace . indexOfChild ( iconLayout ) ; final int pageCount = workspace . getChildCount ( ) ; CellLayout hotseatLayout = ( CellLayout ) hotseat . getChildAt ( 0 ) ; ShortcutAndWidgetContainer hotseatParent = hotseatLayout . getShortcutsAndWidgets ( ) ; int [ ] [ ] matrix ; if ( keyCode == KeyEvent . KEYCODE_DPAD_DOWN && ! profile . isVerticalBarLayout ( ) ) { matrix = FocusLogic . createSparseMatrixWithHotseat ( iconLayout , hotseatLayout , true , profile . inv . hotseatAllAppsRank ) ; } else if ( keyCode == KeyEvent . KEYCODE_DPAD_RIGHT && profile . isVerticalBarLayout ( ) ) { matrix = FocusLogic . createSparseMatrixWithHotseat ( iconLayout , hotseatLayout , false , profile . inv . hotseatAllAppsRank ) ; } else if ( isUninstallKeyChord ( e ) ) { matrix = FocusLogic . createSparseMatrix ( iconLayout ) ; if ( UninstallDropTarget . supportsDrop ( launcher , itemInfo ) ) { UninstallDropTarget . startUninstallActivity ( launcher , itemInfo ) ; } } else if ( isDeleteKeyChord ( e ) ) { matrix = FocusLogic . createSparseMatrix ( iconLayout ) ; launcher . removeItem ( v , itemInfo , true ) ; } else { matrix = FocusLogic . createSparseMatrix ( iconLayout ) ; } int newIconIndex = FocusLogic . handleKeyEvent ( keyCode , matrix , iconIndex , pageIndex , pageCount , Utilities . isRtl ( v . getResources ( ) ) ) ; boolean isRtl = Utilities . isRtl ( v . getResources ( ) ) ; View newIcon = null ; CellLayout workspaceLayout = ( CellLayout ) workspace . getChildAt ( pageIndex ) ; switch ( newIconIndex ) { case FocusLogic . NOOP : if ( keyCode == KeyEvent . KEYCODE_DPAD_UP ) { newIcon = tabs ; } break ; case FocusLogic . PREVIOUS_PAGE_RIGHT_COLUMN : case FocusLogic . NEXT_PAGE_RIGHT_COLUMN : int newPageIndex = pageIndex - 1 ; if ( newIconIndex == FocusLogic . NEXT_PAGE_RIGHT_COLUMN ) { newPageIndex = pageIndex + 1 ; } int row = ( ( CellLayout . LayoutParams ) v . getLayoutParams ( ) ) . cellY ; parent = getCellLayoutChildrenForIndex ( workspace , newPageIndex ) ; if ( parent != null ) { iconLayout = ( CellLayout ) parent . getParent ( ) ; matrix = FocusLogic . createSparseMatrixWithPivotColumn ( iconLayout , iconLayout . getCountX ( ) , row ) ; newIconIndex = FocusLogic . handleKeyEvent ( keyCode , matrix , FocusLogic . PIVOT , newPageIndex , pageCount , Utilities . isRtl ( v . getResources ( ) ) ) ; if ( newIconIndex == FocusLogic . NEXT_PAGE_FIRST_ITEM ) { newIcon = handleNextPageFirstItem ( workspace , hotseatLayout , pageIndex , isRtl ) ; } else if ( newIconIndex == FocusLogic . PREVIOUS_PAGE_LAST_ITEM ) { newIcon = handlePreviousPageLastItem ( workspace , hotseatLayout , pageIndex , isRtl ) ; } else { newIcon = parent . getChildAt ( newIconIndex ) ; } } break ; case FocusLogic . PREVIOUS_PAGE_FIRST_ITEM : workspaceLayout = ( CellLayout ) workspace . getChildAt ( pageIndex - 1 ) ; newIcon = getFirstFocusableIconInReadingOrder ( workspaceLayout , isRtl ) ; if ( newIcon == null ) { newIcon = getFirstFocusableIconInReadingOrder ( hotseatLayout , isRtl ) ; workspace . snapToPage ( pageIndex - 1 ) ; } break ; case FocusLogic . PREVIOUS_PAGE_LAST_ITEM : newIcon = handlePreviousPageLastItem ( workspace , hotseatLayout , pageIndex , isRtl ) ; break ; case FocusLogic . NEXT_PAGE_FIRST_ITEM : newIcon = handleNextPageFirstItem ( workspace , hotseatLayout , pageIndex , isRtl ) ; break ; case FocusLogic . NEXT_PAGE_LEFT_COLUMN : case FocusLogic . PREVIOUS_PAGE_LEFT_COLUMN : newPageIndex = pageIndex + 1 ; if ( newIconIndex == FocusLogic . PREVIOUS_PAGE_LEFT_COLUMN ) { newPageIndex = pageIndex - 1 ; } row = ( ( CellLayout . LayoutParams ) v . getLayoutParams ( ) ) . cellY ; parent = getCellLayoutChildrenForIndex ( workspace , newPageIndex ) ; if ( parent != null ) { iconLayout = ( CellLayout ) parent . getParent ( ) ; matrix = FocusLogic . createSparseMatrixWithPivotColumn ( iconLayout , - 1 , row ) ; newIconIndex = FocusLogic . handleKeyEvent ( keyCode , matrix , FocusLogic . PIVOT , newPageIndex , pageCount , Utilities . isRtl ( v . getResources ( ) ) ) ; if ( newIconIndex == FocusLogic . NEXT_PAGE_FIRST_ITEM ) { newIcon = handleNextPageFirstItem ( workspace , hotseatLayout , pageIndex , isRtl ) ; } else if ( newIconIndex == FocusLogic . PREVIOUS_PAGE_LAST_ITEM ) { newIcon = handlePreviousPageLastItem ( workspace , hotseatLayout , pageIndex , isRtl ) ; } else { newIcon = parent . getChildAt ( newIconIndex ) ; } } break ; case FocusLogic . CURRENT_PAGE_FIRST_ITEM : newIcon = getFirstFocusableIconInReadingOrder ( workspaceLayout , isRtl ) ; if ( newIcon == null ) { newIcon = getFirstFocusableIconInReadingOrder ( hotseatLayout , isRtl ) ; } break ; case FocusLogic . CURRENT_PAGE_LAST_ITEM : newIcon = getFirstFocusableIconInReverseReadingOrder ( workspaceLayout , isRtl ) ; if ( newIcon == null ) { newIcon = getFirstFocusableIconInReverseReadingOrder ( hotseatLayout , isRtl ) ; } break ; default : if ( 0 <= newIconIndex && newIconIndex < parent . getChildCount ( ) ) { newIcon = parent . getChildAt ( newIconIndex ) ; } else if ( parent . getChildCount ( ) <= newIconIndex && newIconIndex < parent . getChildCount ( ) + hotseatParent . getChildCount ( ) ) { newIcon = hotseatParent . getChildAt ( newIconIndex - parent . getChildCount ( ) ) ; } break ; } if ( newIcon != null ) { newIcon . requestFocus ( ) ; playSoundEffect ( keyCode , v ) ; } return consume ; }
handles key events in a workspace containing icons .
