コード例 #1
0
  @Override
  public ActionMode startActionMode(ActionMode.Callback callback) {
    if (DEBUG) Log.d(TAG, "[startActionMode] callback: " + callback);

    if (mActionMode != null) {
      mActionMode.finish();
    }

    final ActionMode.Callback wrappedCallback = new ActionModeCallbackWrapper(callback);
    ActionMode mode = null;

    // Emulate Activity's onWindowStartingActionMode:
    initActionBar();
    if (aActionBar != null) {
      mode = aActionBar.startActionMode(wrappedCallback);
    }

    if (mode != null) {
      mActionMode = mode;
    } else {
      if (mActionModeView == null) {
        ViewStub stub = (ViewStub) mDecor.findViewById(R.id.abs__action_mode_bar_stub);
        if (stub != null) {
          mActionModeView = (ActionBarContextView) stub.inflate();
        }
      }
      if (mActionModeView != null) {
        mActionModeView.killMode();
        mode = new StandaloneActionMode(mActivity, mActionModeView, wrappedCallback, true);
        if (callback.onCreateActionMode(mode, mode.getMenu())) {
          mode.invalidate();
          mActionModeView.initForMode(mode);
          mActionModeView.setVisibility(View.VISIBLE);
          mActionMode = mode;
          mActionModeView.sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
        } else {
          mActionMode = null;
        }
      }
    }
    if (mActionMode != null && mActivity instanceof OnActionModeStartedListener) {
      ((OnActionModeStartedListener) mActivity).onActionModeStarted(mActionMode);
    }
    return mActionMode;
  }
コード例 #2
0
  /**
   * Update the contextual action bar for the number of item selected
   *
   * @param numSelected
   */
  private void updateCAB(int numSelected) {
    if (actionMode == null) return;

    Menu menu = actionMode.getMenu();
    if (numSelected == 1) {
      if (selected.get(0).canEdit()) {
        menu.findItem(R.id.edit).setVisible(true);
      } else {
        menu.findItem(R.id.edit).setVisible(false);
      }
    } else {
      menu.findItem(R.id.edit).setVisible(false);
    }
    String title =
        getResources()
            .getQuantityString(R.plurals.quantity_sources_selected, numSelected, numSelected);
    actionMode.setTitle(title);
  }