Ejemplo n.º 1
0
  @Override
  public boolean dispatchKeyEvent(KeyEvent event) {
    // Dismiss ActionMode without effecting checked items

    FormulaEditorVariableListFragment formulaEditorVariableListFragment =
        (FormulaEditorVariableListFragment)
            getSupportFragmentManager()
                .findFragmentByTag(FormulaEditorVariableListFragment.VARIABLE_TAG);

    if (formulaEditorVariableListFragment != null
        && formulaEditorVariableListFragment.isVisible()) {
      ListAdapter adapter = formulaEditorVariableListFragment.getListAdapter();
      ((ScriptActivityAdapterInterface) adapter).clearCheckedItems();
      return super.dispatchKeyEvent(event);
    }

    if (currentFragment != null
        && currentFragment.getActionModeActive()
        && event.getKeyCode() == KeyEvent.KEYCODE_BACK
        && event.getAction() == KeyEvent.ACTION_UP) {
      ListAdapter adapter = null;
      if (currentFragment instanceof ScriptFragment) {
        adapter = ((ScriptFragment) currentFragment).getAdapter();
      } else {
        adapter = currentFragment.getListAdapter();
      }
      ((ScriptActivityAdapterInterface) adapter).clearCheckedItems();
    }

    return super.dispatchKeyEvent(event);
  }
Ejemplo n.º 2
0
  @Override
  public boolean onOptionsItemSelected(MenuItem item) {

    if (isHoveringActive()) {
      scriptFragment.getListView().animateHoveringBrick();
      return super.onOptionsItemSelected(item);
    }

    FormulaEditorVariableListFragment formulaEditorVariableListFragment =
        (FormulaEditorVariableListFragment)
            getSupportFragmentManager()
                .findFragmentByTag(FormulaEditorVariableListFragment.VARIABLE_TAG);

    if (formulaEditorVariableListFragment != null
        && formulaEditorVariableListFragment.isVisible()) {
      return super.onOptionsItemSelected(item);
    }

    switch (item.getItemId()) {
      case R.id.backpack:
        currentFragment.startBackPackActionMode();
        break;

      case R.id.show_details:
        handleShowDetails(!currentFragment.getShowDetails(), item);
        break;

      case R.id.copy:
        currentFragment.startCopyActionMode();
        break;

      case R.id.cut:
        break;

      case R.id.unpacking:
        Intent intent = new Intent(currentFragment.getActivity(), BackPackActivity.class);
        intent.putExtra(BackPackActivity.EXTRA_FRAGMENT_POSITION, FRAGMENT_SOUNDS);
        startActivity(intent);
        break;

      case R.id.insert_below:
        break;

      case R.id.move:
        break;

      case R.id.rename:
        if (currentFragmentPosition != FRAGMENT_SCRIPTS) {
          currentFragment.startRenameActionMode();
        }
        break;

      case R.id.delete:
        currentFragment.startDeleteActionMode();
        break;
    }
    return super.onOptionsItemSelected(item);
  }
Ejemplo n.º 3
0
  @Override
  public boolean onKeyDown(int keyCode, KeyEvent event) {
    FragmentManager fragmentManager = getSupportFragmentManager();

    for (String tag : FormulaEditorListFragment.TAGS) {
      FormulaEditorListFragment fragment =
          (FormulaEditorListFragment) fragmentManager.findFragmentByTag(tag);
      if (fragment != null && fragment.isVisible()) {
        return fragment.onKey(null, keyCode, event);
      }
    }

    FormulaEditorVariableListFragment formulaEditorVariableListFragment =
        (FormulaEditorVariableListFragment)
            getSupportFragmentManager()
                .findFragmentByTag(FormulaEditorVariableListFragment.VARIABLE_TAG);

    if (formulaEditorVariableListFragment != null
        && formulaEditorVariableListFragment.isVisible()) {
      return formulaEditorVariableListFragment.onKey(null, keyCode, event);
    }

    FormulaEditorFragment formulaEditor =
        (FormulaEditorFragment)
            getSupportFragmentManager()
                .findFragmentByTag(FormulaEditorFragment.FORMULA_EDITOR_FRAGMENT_TAG);

    if (formulaEditor != null && formulaEditor.isVisible()) {
      scriptFragment.getAdapter().updateProjectBrickList();
      return formulaEditor.onKey(null, keyCode, event);
    }

    if (soundFragment != null
        && soundFragment.isVisible()
        && soundFragment.onKey(null, keyCode, event)) {
      return true;
    }

    if (lookFragment != null
        && lookFragment.isVisible()
        && lookFragment.onKey(null, keyCode, event)) {
      return true;
    }

    int backStackEntryCount = fragmentManager.getBackStackEntryCount();
    for (int i = backStackEntryCount; i > 0; --i) {
      String backStackEntryName = fragmentManager.getBackStackEntryAt(i - 1).getName();
      if (backStackEntryName != null
          && (backStackEntryName.equals(LookFragment.TAG)
              || backStackEntryName.equals(SoundFragment.TAG))) {
        fragmentManager.popBackStack();
      } else {
        break;
      }
    }

    if (keyCode == KeyEvent.KEYCODE_BACK && currentFragmentPosition == FRAGMENT_SCRIPTS) {
      DragAndDropListView listView = scriptFragment.getListView();
      if (listView.isCurrentlyDragging()) {
        listView.resetDraggingScreen();

        BrickAdapter adapter = scriptFragment.getAdapter();
        adapter.removeDraggedBrick();
        return true;
      }
    }

    return super.onKeyDown(keyCode, event);
  }