@Override
  public boolean onContextItemSelected(MenuItem menuItem) {
    ExpandableListContextMenuInfo info = (ExpandableListContextMenuInfo) menuItem.getMenuInfo();

    int type = ExpandableListView.getPackedPositionType(info.packedPosition);

    if (type == ExpandableListView.PACKED_POSITION_TYPE_CHILD) {
      int group = ExpandableListView.getPackedPositionGroup(info.packedPosition);
      int child = ExpandableListView.getPackedPositionChild(info.packedPosition);

      HistoryItem item = (HistoryItem) getExpandableListAdapter().getChild(group, child);

      switch (menuItem.getItemId()) {
        case MENU_OPEN_IN_TAB:
          doNavigateToUrl(item.getUrl(), true);
          break;
        case MENU_COPY_URL:
          ApplicationUtils.copyTextToClipboard(
              this, item.getUrl(), getString(R.string.Commons_UrlCopyToastMessage));
          break;
        case MENU_SHARE:
          ApplicationUtils.sharePage(this, item.getTitle(), item.getUrl());
          break;
        case MENU_DELETE_FROM_HISTORY:
          BookmarksProviderWrapper.deleteHistoryRecord(getContentResolver(), item.getId());
          fillData();
          break;
        default:
          break;
      }
    }

    return super.onContextItemSelected(menuItem);
  }
 /** Display confirmation and clear history. */
 private void clearHistory() {
   ApplicationUtils.showYesNoDialog(
       this,
       android.R.drawable.ic_dialog_alert,
       R.string.Commons_ClearHistory,
       R.string.Commons_NoUndoMessage,
       new DialogInterface.OnClickListener() {
         @Override
         public void onClick(DialogInterface dialog, int which) {
           dialog.dismiss();
           doClearHistory();
         }
       });
 }
  /** Fill the history list. */
  private void fillData() {
    Cursor c = BookmarksProviderWrapper.getStockHistory(getContentResolver());

    if (c == null) return;

    mAdapter =
        new HistoryExpandableListAdapter(
            this,
            c,
            Browser.HISTORY_PROJECTION_DATE_INDEX,
            ApplicationUtils.getFaviconSizeForBookmarks(this));

    setListAdapter(mAdapter);

    if (getExpandableListAdapter().getGroupCount() > 0) {
      getExpandableListView().expandGroup(0);
    }
  }