@Override
 public void onDestroyActionMode(ActionMode mode) {
   mWrapped.onDestroyActionMode(mode);
   if (mActionModePopup != null) {
     mWindow.getDecorView().removeCallbacks(mShowActionModePopup);
     mActionModePopup.dismiss();
   } else if (mActionModeView != null) {
     mActionModeView.setVisibility(View.GONE);
     if (mActionModeView.getParent() != null) {
       ViewCompat.requestApplyInsets((View) mActionModeView.getParent());
     }
   }
   if (mActionModeView != null) {
     mActionModeView.removeAllViews();
   }
   if (mAppCompatCallback != null) {
     mAppCompatCallback.onSupportActionModeFinished(mActionMode);
   }
   mActionMode = null;
 }
 @Override
 public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
   return mWrapped.onActionItemClicked(mode, item);
 }
 @Override
 public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
   return mWrapped.onPrepareActionMode(mode, menu);
 }
  ActionMode startSupportActionModeFromWindow(ActionMode.Callback callback) {
    if (mActionMode != null) {
      mActionMode.finish();
    }

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

    if (mActionModeView == null) {
      // Use the action bar theme.
      final Context actionBarContext;
      actionBarContext =
          ThemeUtils.getActionBarThemedContext(
              mActivity, mThemed.getCurrentThemeResourceId(), mThemed.getCurrentThemeColor());

      mActionModeView = new ActionBarContextView(actionBarContext);
      mActionModePopup =
          new PopupWindow(
              actionBarContext,
              null,
              android.support.v7.appcompat.R.attr.actionModePopupWindowStyle);
      mActionModePopup.setContentView(mActionModeView);

      final TypedValue outValue = new TypedValue();
      actionBarContext
          .getTheme()
          .resolveAttribute(android.support.v7.appcompat.R.attr.actionBarSize, outValue, true);
      final int height =
          TypedValue.complexToDimensionPixelSize(
              outValue.data, actionBarContext.getResources().getDisplayMetrics());
      mActionModeView.setContentHeight(height);
      ThemeUtils.setActionBarContextViewBackground(
          mActionModeView,
          mThemed.getCurrentThemeResourceId(),
          mThemed.getCurrentThemeColor(),
          mThemed.getCurrentThemeBackgroundOption(),
          false);
      mActionModePopup.setHeight(ViewGroup.LayoutParams.WRAP_CONTENT);
      final Rect actionModeBounds = getActionModeBounds();
      if (actionModeBounds != null) {
        mActionModePopup.setWidth(actionModeBounds.width());
      } else {
        mActionModePopup.setWidth(ViewGroup.LayoutParams.MATCH_PARENT);
      }
      mShowActionModePopup =
          new Runnable() {
            @Override
            public void run() {
              if (actionModeBounds != null) {
                mActionModePopup.showAtLocation(
                    mWindow.getDecorView(),
                    Gravity.TOP | Gravity.LEFT,
                    actionModeBounds.left,
                    actionModeBounds.top);
              } else {
                mActionModePopup.showAtLocation(
                    mWindow.getDecorView(), Gravity.TOP | Gravity.LEFT, 0, 0);
              }
            }
          };
    }

    if (mActionModeView != null) {
      mActionModeView.killMode();
      ActionMode mode =
          new StandaloneActionMode(
              mActionModeView.getContext(),
              mActionModeView,
              wrappedCallback,
              mActionModePopup == null);
      if (callback.onCreateActionMode(mode, mode.getMenu())) {
        mode.invalidate();
        mActionModeView.initForMode(mode);
        mActionModeView.setVisibility(View.VISIBLE);
        mActionMode = mode;
        if (mActionModePopup != null) {
          mWindow.getDecorView().post(mShowActionModePopup);
        }
        mActionModeView.sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);

        if (mActionModeView.getParent() != null) {
          ViewCompat.requestApplyInsets((View) mActionModeView.getParent());
        }
      } else {
        mActionMode = null;
      }
    }
    if (mActionMode != null && mAppCompatCallback != null) {
      mAppCompatCallback.onSupportActionModeStarted(mActionMode);
    }
    return mActionMode;
  }
 public boolean onPrepareActionMode(android.view.ActionMode actionmode, Menu menu) {
   return mWrappedCallback.onPrepareActionMode(
       getActionModeWrapper(actionmode), MenuWrapperFactory.createMenuWrapper(menu));
 }
 public void onDestroyActionMode(android.view.ActionMode actionmode) {
   mWrappedCallback.onDestroyActionMode(getActionModeWrapper(actionmode));
 }
 public boolean onActionItemClicked(android.view.ActionMode actionmode, MenuItem menuitem) {
   return mWrappedCallback.onActionItemClicked(
       getActionModeWrapper(actionmode), MenuWrapperFactory.createMenuItemWrapper(menuitem));
 }