Пример #1
0
 @Override
 public ActionMode startSupportActionMode(final ActionMode.Callback callback) {
   // Fix for bug https://code.google.com/p/android/issues/detail?id=159527
   final ActionMode mode = super.startSupportActionMode(callback);
   if (mode != null) {
     mode.invalidate();
   }
   return mode;
 }
Пример #2
0
  /**
   * Toggle the selection state of an item.
   *
   * <p>If the item was the last one in the selection and is unselected, the selection is stopped.
   * Note that the selection must already be started (actionMode must not be null).
   *
   * @param position Position of the item to toggle the selection state
   */
  private void toggleSelection(int position) {
    chatAdapter.toggleSelection(position);
    int count = chatAdapter.getSelectedItemCount();

    if (count == 0) {
      actionMode.finish();
    } else {
      actionMode.setTitle(String.valueOf(count));
      actionMode.invalidate();
    }
  }
  /**
   * Select items on view when opened action-mode.
   *
   * @param position The select position.
   */
  private void toggleSelection(int position) {
    mAdp.toggleSelection(position);
    int count = mAdp.getSelectedItemCount();

    if (count == 0) {
      mActionMode.finish();
    } else {
      mActionMode.setTitle(String.valueOf(count));
      mActionMode.invalidate();
    }
  }
  public void initForMode(final ActionMode mode) {
    if (mClose == null) {
      LayoutInflater inflater = LayoutInflater.from(getContext());
      mClose = inflater.inflate(mCloseItemLayout, this, false);
      addView(mClose);
    } else if (mClose.getParent() == null) {
      addView(mClose);
    }

    View closeButton = mClose.findViewById(R.id.action_mode_close_button);
    closeButton.setOnClickListener(
        new OnClickListener() {
          public void onClick(View v) {
            mode.finish();
          }
        });

    final MenuBuilder menu = (MenuBuilder) mode.getMenu();
    if (mActionMenuPresenter != null) {
      mActionMenuPresenter.dismissPopupMenus();
    }
    mActionMenuPresenter = new ActionMenuPresenter(getContext());
    mActionMenuPresenter.setReserveOverflow(true);

    final LayoutParams layoutParams =
        new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT);
    menu.addMenuPresenter(mActionMenuPresenter, mPopupContext);
    mMenuView = (ActionMenuView) mActionMenuPresenter.getMenuView(this);
    mMenuView.setBackgroundDrawable(null);
    addView(mMenuView, layoutParams);
  }
 @Override
 public boolean onCreateActionMode(ActionMode actionMode, Menu menu) {
   // Inflate the menu resource (res/menu/context_cheeses.xml) which will be displayed
   // in the action mode
   actionMode.getMenuInflater().inflate(R.menu.context_cheeses, menu);
   return true;
 }
  @Override
  public boolean onCreateActionMode(ActionMode mode, Menu menu) {
    MenuInflater inflater = getActivity().getMenuInflater();
    inflater.inflate(R.menu.conversation_list_batch, menu);

    mode.setTitle(R.string.conversation_fragment_cab__batch_selection_mode);
    mode.setSubtitle(null);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
      getActivity()
          .getWindow()
          .setStatusBarColor(getResources().getColor(R.color.action_mode_status_bar));
    }

    return true;
  }
 @Override
 public void onBackPressed() {
   if (mActionMode != null) {
     mActionMode.finish();
     closeActionMode();
   } else super.onBackPressed();
 }
 private void handleSelectAllThreads() {
   getListAdapter().selectAllThreads();
   actionMode.setSubtitle(
       getString(
           R.string.conversation_fragment_cab__batch_selection_amount,
           ((ConversationListAdapter) this.getListAdapter()).getBatchSelections().size()));
 }
Пример #9
0
 private void reset() {
   int begin = mListView.getFirstVisiblePosition();
   int end = mListView.getLastVisiblePosition();
   if (mAdapter.cancelSelection(mListView, begin, end) < 1 && mFromMenu) {
     mActionMode.finish();
   }
 }
 public boolean finishExisting() {
   if (mActionMode != null) {
     mActionMode.finish();
     return true;
   }
   return false;
 }
Пример #11
0
 @Override
 public void onStop() {
   super.onStop();
   EventBus.getDefault().unregister(this);
   // Finish action mode so that it doesn't leak.
   if (actionMode != null) actionMode.finish();
 }
Пример #12
0
  @Override
  public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
    // TODO Auto-generated method stub

    mode.setTitle("CheckBox is Checked");
    return false;
  }
Пример #13
0
  private void updateView() {
    sendConfirmButton.setEnabled(everythingValid());

    if (address == null) {
      setVisible(sendToAddressView);
      setGone(sendToStaticAddressView);
      setVisible(scanQrCodeButton);
      setGone(eraseAddressButton);

      if (actionMode != null) {
        actionMode.finish();
        actionMode = null;
      }
    } else {
      setGone(sendToAddressView);
      setVisible(sendToStaticAddressView);
      sendToStaticAddressView.setAddressAndLabel(address);
      setGone(scanQrCodeButton);
      setVisible(eraseAddressButton);
    }

    if (sendCoinAmountView.resetType(sendAmountType)) {
      amountCalculatorLink.setExchangeRate(getCurrentRate());
    }

    startOrStopMarketRatePolling();

    // enable actions
    scanQrCodeButton.setEnabled(state == State.INPUT);
    eraseAddressButton.setEnabled(state == State.INPUT);
  }
Пример #14
0
 @Override
 public boolean onActionItemClicked(ActionMode actionMode, MenuItem menuItem) {
   if (menuItem.getItemId() == R.id.action_save) {
     saveCategory();
   }
   mActionMode.finish();
   return true;
 }
Пример #15
0
 @Override
 public boolean onCreateActionMode(ActionMode actionMode, Menu menu) {
   showFab(false);
   MenuInflater inflater = actionMode.getMenuInflater();
   inflater.inflate(R.menu.menu_edit, menu);
   mListener.onLockDrawer(true);
   return true;
 }
Пример #16
0
 // Called when the user selects a
 // contextual menu item
 @Override
 public boolean onActionItemClicked(final ActionMode mode, final MenuItem item) {
   final boolean b = handleActionBarClick(item);
   if (!b) {
     mode.finish();
   }
   return b;
 }
 @Override
 public boolean onActionItemClicked(ActionMode actionMode, MenuItem menuItem) {
   if (menuItem.getItemId() == R.id.acao_delete) {
     remover();
     actionMode.finish();
     return true;
   }
   return false;
 }
Пример #18
0
 @Override
 public boolean onCreateActionMode(ActionMode mode, Menu menu) {
   MenuInflater inflater = mode.getMenuInflater();
   inflater.inflate(R.menu.menu_remove, menu);
   showFab(false);
   mActionModeDestroyed = false;
   mFromMenu = false;
   mListener.onLockDrawer(true);
   return true;
 }
Пример #19
0
 private void deleteSelected() {
   ListView list = getListView();
   SparseBooleanArray checked = list.getCheckedItemPositions();
   ArrayList<String> deleted = new ArrayList<String>();
   for (int i = 0, lim = list.getAdapter().getCount(); i < lim; ++i)
     if (checked.get(i)) deleted.add((String) mAdapter.getItem(i));
   for (String s : deleted) mAdapter.remove(s);
   mAdapter.notifyDataSetChanged();
   mMode.finish();
 }
Пример #20
0
  @Override
  public void onColorChanged(int color) {
    MathElement begin = textSelector.getBeginObject();
    while (begin != null) {
      begin.setColor(color);

      if (begin == textSelector.getEndObject()) break;
      begin = begin.getNext();
    }
    if (mode != null) mode.finish();
  }
Пример #21
0
 @Override
 public boolean onCreateActionMode(ActionMode mode, Menu menu) {
   mode.getMenuInflater().inflate(R.menu.recent_action_mode, menu);
   recyclerView.setSwipe(false);
   adapter.setSelectionMode(true);
   // Change status bar color to be dark to correspond to dark toolbar color.
   getActivity()
       .getWindow()
       .setStatusBarColor(ContextCompat.getColor(getActivity(), R.color.grey900));
   return true;
 }
  @Override
  public void onItemClick(ConversationListItem item) {
    if (actionMode == null) {
      handleCreateConversation(
          item.getThreadId(), item.getRecipients(), item.getDistributionType());
    } else {
      ConversationListAdapter adapter = (ConversationListAdapter) list.getAdapter();
      adapter.toggleThreadInBatchSet(item.getThreadId());

      if (adapter.getBatchSelections().size() == 0) {
        actionMode.finish();
      } else {
        actionMode.setSubtitle(
            getString(
                R.string.conversation_fragment_cab__batch_selection_amount,
                adapter.getBatchSelections().size()));
      }

      adapter.notifyDataSetChanged();
    }
  }
Пример #23
0
 @Override
 public void onActivityResult(int requestCode, int resultCode, Intent data) {
   switch (requestCode) {
     case C.RC_TAG_ACTIVITY:
       // Came back from TaggingActivity.
       if (resultCode == Activity.RESULT_OK) {
         // We've changed the tags on some books.
         if (actionMode != null) actionMode.finish();
       }
       break;
   }
 }
Пример #24
0
 @Override
 public void onDestroy() {
   super.onDestroy();
   // Close adapter.
   if (adapter != null) adapter.close();
   // Close Realm.
   if (realm != null) {
     realm.close();
     realm = null;
   }
   if (actionMode != null) actionMode.finish();
 }
Пример #25
0
 // Called when the action mode is
 // created; startActionMode() was
 // called
 @Override
 public boolean onCreateActionMode(final ActionMode mode, final Menu menu) {
   // Inflate a menu resource
   // providing context menu items
   final MenuInflater inflater = mode.getMenuInflater();
   final boolean b = handleCabCreateMenu(inflater, menu);
   if (b) {
     TaskFragmentV8.this.mActionMode = mode;
     TaskFragmentV8.this.mMenu = menu;
   }
   return b;
 }
Пример #26
0
 @Override
 public void onItemCheckedStateChanged(
     ActionMode actionMode, int position, long id, boolean checked) {
   Log.d(ExampleListFragment.class.getSimpleName(), "onItemCheckedStateChanged");
   if (checked) mCnt++;
   else mCnt--;
   switch (mCnt) {
     case 1:
     case 2:
       actionMode.invalidate();
       break;
   }
 }
  /**
   * Called when an action mode item is clicked.
   *
   * @param mode The action mode containing the item that is clicked.
   * @param item The item that is clicked.
   * @return Returns true if the method handles the item clicked.
   */
  @Override
  public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
    switch (item.getItemId()) {
      case R.id.mark_read_unread_button:
        for (int i = 0; i < adapter.getItemCount(); i++) {
          if (adapter.isItemChecked(i)) {
            Message[] smses = adapter.getItem(i).getMessages();
            for (Message message : smses) {
              message.setUnread(
                  item.getTitle()
                      .equals(getResources().getString(R.string.conversations_action_mark_unread)));
              database.insertMessage(message);
            }
          }
        }
        adapter.refresh();
        mode.finish();
        return true;
      case R.id.delete_button:
        List<Long> databaseIds = new ArrayList<>();
        for (int i = 0; i < adapter.getItemCount(); i++) {
          if (adapter.isItemChecked(i)) {
            for (Message message : adapter.getItem(i).getMessages()) {
              if (message.getDatabaseId() != null) {
                databaseIds.add(message.getDatabaseId());
              }
            }
          }
        }

        Long[] databaseIdsArray = new Long[databaseIds.size()];
        databaseIds.toArray(databaseIdsArray);
        deleteMessages(databaseIdsArray);
        mode.finish();
        return true;
      default:
        return false;
    }
  }
Пример #28
0
    @Override
    public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
      switch (item.getItemId()) {
        case R.id.menu_remove:
          chatAdapter.removeItems(chatAdapter.getSelectedItems());
          Log.d(TAG, "menu_remove");
          mode.finish();
          return true;

        default:
          return false;
      }
    }
Пример #29
0
  /**
   * Called when we wish to take some action.
   *
   * @param event {@link ActionEvent}.
   */
  @Subscribe
  public void onActionEvent(ActionEvent event) {
    //noinspection unchecked
    List<RBook> selectedItems = adapter.getSelectedRealmObjects();

    switch (event.getActionId()) {
      case R.id.action_clear:
        realm.executeTransaction(
            tRealm -> {
              // Set isInRecents to false for all RBooks which currently have it set to true.
              RealmResults<RBook> recentBooks =
                  tRealm.where(RBook.class).equalTo("isInRecents", true).findAll();
              for (int i = recentBooks.size() - 1; i >= 0; i--)
                recentBooks.get(i).isInRecents = false;
            });
        break;
      case R.id.action_rate:
        ActionHelper.rateBooks(realm, selectedItems, (Integer) event.getData());
        break;
      case R.id.action_read:
        // Save the position to update so we can refresh the list correctly when resuming.
        this.moveToTop = event.getPosToUpdate();
        break;
      case R.id.action_mark_as:
        int whichMark = (int) event.getData();
        ActionHelper.markBooks(
            realm,
            selectedItems,
            whichMark < 2 ? MarkType.NEW : MarkType.UPDATED,
            whichMark % 2 == 0);
        break;
      case R.id.action_add_to_list:
        ActionHelper.addBooksToList(realm, selectedItems, (String) event.getData());
        break;
      case R.id.action_re_import:
        ActionHelper.reImportBooks(selectedItems);
        break;
      case R.id.action_remove:
        realm.executeTransaction(
            tRealm -> {
              // Set isInRecents to false for all selected RBooks.
              for (RBook book : selectedItems) book.isInRecents = false;
            });
        break;
      case R.id.action_delete:
        ActionHelper.deleteBooks(realm, selectedItems, (boolean) event.getData());
        break;
    }
    if (actionMode != null) actionMode.finish();
  }
 @Override
 public void onBackPressed() {
   if (actionModeEnabled) {
     actionMode.finish();
   } else if (menu != null) {
     MenuItem searchItem = menu.findItem(R.id.search_button);
     SearchView searchView = (SearchView) searchItem.getActionView();
     if (!searchView.isIconified()) {
       searchItem.collapseActionView();
     } else {
       super.onBackPressed();
     }
   }
 }