コード例 #1
0
  private void initCustomContextMenu() {
    Resources resources = getResources();
    iconContextMenu = new CustomIconContextMenu(this, DIALOG_CONTEXT_MENU);
    iconContextMenu.addItem(
        resources,
        this.getString(R.string.rename),
        R.drawable.ic_context_rename,
        CONTEXT_MENU_ITEM_RENAME);
    iconContextMenu.addItem(
        resources,
        this.getString(R.string.delete),
        R.drawable.ic_context_delete,
        CONTEXT_MENU_ITEM_DELETE);

    iconContextMenu.setOnClickListener(
        new CustomIconContextMenu.IconContextMenuOnClickListener() {
          public void onClick(int menuId) {
            switch (menuId) {
              case CONTEXT_MENU_ITEM_RENAME:
                showDialog(DIALOG_RENAME_SPRITE);
                break;
              case CONTEXT_MENU_ITEM_DELETE:
                ProjectManager projectManager = ProjectManager.getInstance();
                projectManager.getCurrentProject().getSpriteList().remove(spriteToEdit);
                if (projectManager.getCurrentSprite() != null
                    && projectManager.getCurrentSprite().equals(spriteToEdit)) {
                  projectManager.setCurrentSprite(null);
                }
                break;
            }
          }
        });
  }
コード例 #2
0
  @Override
  protected Dialog onCreateDialog(int id) {
    final Dialog dialog;
    switch (id) {
      case DIALOG_NEW_SPRITE:
        newSpriteDialog = new NewSpriteDialog(this);
        dialog = newSpriteDialog.dialog;
        break;
      case DIALOG_RENAME_SPRITE:
        if (spriteToEdit == null) {
          dialog = null;
        } else {
          renameDialog = new RenameSpriteDialog(this);
          dialog = renameDialog.dialog;
        }
        break;
      case DIALOG_CONTEXT_MENU:
        if (iconContextMenu == null || spriteToEdit == null) {
          dialog = null;
        } else {
          dialog = iconContextMenu.createMenu(spriteToEdit.getName());
        }
        break;
      default:
        dialog = null;
        break;
    }

    return dialog;
  }