Esempio n. 1
0
  /** Handles key events for items in a Folder. */
  static boolean handleFolderKeyEvent(View v, int keyCode, KeyEvent e) {
    ShortcutAndWidgetContainer parent = (ShortcutAndWidgetContainer) v.getParent();
    final CellLayout layout = (CellLayout) parent.getParent();
    final Folder folder = (Folder) layout.getParent();
    View title = folder.mFolderName;

    final int action = e.getAction();
    final boolean handleKeyEvent = (action != KeyEvent.ACTION_UP);
    boolean wasHandled = false;
    switch (keyCode) {
      case KeyEvent.KEYCODE_DPAD_LEFT:
        if (handleKeyEvent) {
          // Select the previous icon
          View newIcon = getIconInDirection(layout, parent, v, -1);
          if (newIcon != null) {
            newIcon.requestFocus();
          }
        }
        wasHandled = true;
        break;
      case KeyEvent.KEYCODE_DPAD_RIGHT:
        if (handleKeyEvent) {
          // Select the next icon
          View newIcon = getIconInDirection(layout, parent, v, 1);
          if (newIcon != null) {
            newIcon.requestFocus();
          } else {
            title.requestFocus();
          }
        }
        wasHandled = true;
        break;
      case KeyEvent.KEYCODE_DPAD_UP:
        if (handleKeyEvent) {
          // Select the closest icon in the previous line
          View newIcon = getClosestIconOnLine(layout, parent, v, -1);
          if (newIcon != null) {
            newIcon.requestFocus();
          }
        }
        wasHandled = true;
        break;
      case KeyEvent.KEYCODE_DPAD_DOWN:
        if (handleKeyEvent) {
          // Select the closest icon in the next line
          View newIcon = getClosestIconOnLine(layout, parent, v, 1);
          if (newIcon != null) {
            newIcon.requestFocus();
          } else {
            title.requestFocus();
          }
        }
        wasHandled = true;
        break;
      case KeyEvent.KEYCODE_MOVE_HOME:
        if (handleKeyEvent) {
          // Select the first icon on this page
          View newIcon = getIconInDirection(layout, parent, -1, 1);
          if (newIcon != null) {
            newIcon.requestFocus();
          }
        }
        wasHandled = true;
        break;
      case KeyEvent.KEYCODE_MOVE_END:
        if (handleKeyEvent) {
          // Select the last icon on this page
          View newIcon = getIconInDirection(layout, parent, parent.getChildCount(), -1);
          if (newIcon != null) {
            newIcon.requestFocus();
          }
        }
        wasHandled = true;
        break;
      default:
        break;
    }
    return wasHandled;
  }
Esempio n. 2
0
  /** Handles key events in a Workspace containing. */
  static boolean handleIconKeyEvent(View v, int keyCode, KeyEvent e) {
    ShortcutAndWidgetContainer parent = (ShortcutAndWidgetContainer) v.getParent();
    final CellLayout layout = (CellLayout) parent.getParent();
    if (!(layout.getParent() instanceof Workspace)) return false;
    final Workspace workspace = (Workspace) layout.getParent();
    final ViewGroup launcher = (ViewGroup) workspace.getParent();
    final ViewGroup tabs = null;
    final ViewGroup hotseat = null;
    int pageIndex = workspace.indexOfChild(layout);
    int pageCount = workspace.getChildCount();

    final int action = e.getAction();
    final boolean handleKeyEvent = (action != KeyEvent.ACTION_UP);
    boolean wasHandled = false;
    switch (keyCode) {
      case KeyEvent.KEYCODE_DPAD_LEFT:
        if (handleKeyEvent) {
          // Select the previous icon or the last icon on the previous page if possible
          View newIcon = getIconInDirection(layout, parent, v, -1);
          if (newIcon != null) {
            newIcon.requestFocus();
          } else {
            if (pageIndex > 0) {
              parent = getCellLayoutChildrenForIndex(workspace, pageIndex - 1);
              newIcon = getIconInDirection(layout, parent, parent.getChildCount(), -1);
              if (newIcon != null) {
                newIcon.requestFocus();
              } else {
                // Snap to the previous page
                workspace.snapToPage(pageIndex - 1);
              }
            }
          }
        }
        wasHandled = true;
        break;
      case KeyEvent.KEYCODE_DPAD_RIGHT:
        if (handleKeyEvent) {
          // Select the next icon or the first icon on the next page if possible
          View newIcon = getIconInDirection(layout, parent, v, 1);
          if (newIcon != null) {
            newIcon.requestFocus();
          } else {
            if (pageIndex < (pageCount - 1)) {
              parent = getCellLayoutChildrenForIndex(workspace, pageIndex + 1);
              newIcon = getIconInDirection(layout, parent, -1, 1);
              if (newIcon != null) {
                newIcon.requestFocus();
              } else {
                // Snap to the next page
                workspace.snapToPage(pageIndex + 1);
              }
            }
          }
        }
        wasHandled = true;
        break;
      case KeyEvent.KEYCODE_DPAD_UP:
        if (handleKeyEvent) {
          // Select the closest icon in the previous line, otherwise select the tab bar
          View newIcon = getClosestIconOnLine(layout, parent, v, -1);
          if (newIcon != null) {
            newIcon.requestFocus();
            wasHandled = true;
          } else {
            if (tabs != null) tabs.requestFocus();
          }
        }
        break;
      case KeyEvent.KEYCODE_DPAD_DOWN:
        if (handleKeyEvent) {
          // Select the closest icon in the next line, otherwise select the button bar
          View newIcon = getClosestIconOnLine(layout, parent, v, 1);
          if (newIcon != null) {
            newIcon.requestFocus();
            wasHandled = true;
          } else if (hotseat != null) {
            hotseat.requestFocus();
          }
        }
        break;
      case KeyEvent.KEYCODE_PAGE_UP:
        if (handleKeyEvent) {
          // Select the first icon on the previous page or the first icon on this page
          // if there is no previous page
          if (pageIndex > 0) {
            parent = getCellLayoutChildrenForIndex(workspace, pageIndex - 1);
            View newIcon = getIconInDirection(layout, parent, -1, 1);
            if (newIcon != null) {
              newIcon.requestFocus();
            } else {
              // Snap to the previous page
              workspace.snapToPage(pageIndex - 1);
            }
          } else {
            View newIcon = getIconInDirection(layout, parent, -1, 1);
            if (newIcon != null) {
              newIcon.requestFocus();
            }
          }
        }
        wasHandled = true;
        break;
      case KeyEvent.KEYCODE_PAGE_DOWN:
        if (handleKeyEvent) {
          // Select the first icon on the next page or the last icon on this page
          // if there is no previous page
          if (pageIndex < (pageCount - 1)) {
            parent = getCellLayoutChildrenForIndex(workspace, pageIndex + 1);
            View newIcon = getIconInDirection(layout, parent, -1, 1);
            if (newIcon != null) {
              newIcon.requestFocus();
            } else {
              // Snap to the next page
              workspace.snapToPage(pageIndex + 1);
            }
          } else {
            View newIcon = getIconInDirection(layout, parent, parent.getChildCount(), -1);
            if (newIcon != null) {
              newIcon.requestFocus();
            }
          }
        }
        wasHandled = true;
        break;
      case KeyEvent.KEYCODE_MOVE_HOME:
        if (handleKeyEvent) {
          // Select the first icon on this page
          View newIcon = getIconInDirection(layout, parent, -1, 1);
          if (newIcon != null) {
            newIcon.requestFocus();
          }
        }
        wasHandled = true;
        break;
      case KeyEvent.KEYCODE_MOVE_END:
        if (handleKeyEvent) {
          // Select the last icon on this page
          View newIcon = getIconInDirection(layout, parent, parent.getChildCount(), -1);
          if (newIcon != null) {
            newIcon.requestFocus();
          }
        }
        wasHandled = true;
        break;
      default:
        break;
    }
    return wasHandled;
  }