예제 #1
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);
  }
예제 #2
0
 private void reset() {
   int begin = mListView.getFirstVisiblePosition();
   int end = mListView.getLastVisiblePosition();
   if (mAdapter.cancelSelection(mListView, begin, end) < 1 && mFromMenu) {
     mActionMode.finish();
   }
 }
예제 #3
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();
 }
 public boolean finishExisting() {
   if (mActionMode != null) {
     mActionMode.finish();
     return true;
   }
   return false;
 }
 @Override
 public void onBackPressed() {
   if (mActionMode != null) {
     mActionMode.finish();
     closeActionMode();
   } else super.onBackPressed();
 }
예제 #6
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;
 }
예제 #7
0
 @Override
 public boolean onActionItemClicked(ActionMode actionMode, MenuItem menuItem) {
   if (menuItem.getItemId() == R.id.action_save) {
     saveCategory();
   }
   mActionMode.finish();
   return true;
 }
 @Override
 public boolean onActionItemClicked(ActionMode actionMode, MenuItem menuItem) {
   if (menuItem.getItemId() == R.id.acao_delete) {
     remover();
     actionMode.finish();
     return true;
   }
   return false;
 }
예제 #9
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();
 }
  /**
   * 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();
    }
  }
예제 #11
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();
  }
예제 #12
0
파일: Chat.java 프로젝트: acruche/DobleFC
  /**
   * 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();
    }
  }
예제 #13
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();
 }
예제 #14
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;
   }
 }
  /**
   * 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;
    }
  }
예제 #16
0
파일: Chat.java 프로젝트: acruche/DobleFC
    @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;
      }
    }
 @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();
     }
   }
 }
예제 #18
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 boolean onActionItemClicked(ActionMode actionMode, MenuItem menuItem) {
      // We switch on the menu item's id, so we know which is clicked
      switch (menuItem.getItemId()) {

          // Our item with the menu_remove ID is used to remove the item(s) from the list.
          // Here we retrieve which positions are currently checked, then iterate through the
          // list and remove the checked items. Once finished we notify the adapter to update
          // the ListView contents and finish the action mode.
        case R.id.menu_remove:
          // Retrieve which positions are currently checked
          final ListView listView = getListView();
          SparseBooleanArray checkedPositions = listView.getCheckedItemPositions();

          // Check to see if there are any checked items
          if (checkedPositions.size() == 0) {
            return false;
          }

          // Iterate through the items and remove any which are checked
          final Iterator<String> iterator = mItems.iterator();
          int i = 0;
          while (iterator.hasNext()) {
            // Call next() so that the iterator index moves
            iterator.next();

            // Remove the item if it is checked (and increment position)
            if (checkedPositions.get(i++)) {
              iterator.remove();
            }
          }

          // Clear the ListView's checked items
          listView.clearChoices();

          // Finally, notify the adapter so that it updates the ListView
          ((BaseAdapter) getListAdapter()).notifyDataSetChanged();

          // As we're removing all of checked items, we'll close the action mode
          actionMode.finish();

          // We return true to signify that we have handled the action item click
          return true;
      }

      return false;
    }
  /**
   * Toggles the item associated with the specified view. Activates and deactivates the action mode
   * depending on the checked item count.
   *
   * @param view The specified view.
   */
  private void toggleItem(View view) {
    adapter.toggleItemChecked(recyclerView.getChildAdapterPosition(view));

    if (adapter.getCheckedItemCount() == 0) {
      if (actionMode != null) {
        actionMode.finish();
      }
      actionModeEnabled = false;
      return;
    }

    if (!actionModeEnabled) {
      actionMode = startSupportActionMode(this);
      actionModeEnabled = true;
    }
    updateButtons();
  }
예제 #21
0
 @Override
 public void onCheck(int count, int position, boolean isChecked) {
   if (count == 0) {
     mSelectionMode = false;
   } else if (count == 1) {
     mSelectionMode = true;
   }
   if (!mActionModeDestroyed && !mIsEditing) {
     if (count > 0) {
       if (mActionMode == null) {
         mActionMode = ((MainActivity) getActivity()).startSupportActionMode(mActionModeCallback);
       }
     } else if (mActionMode != null) {
       mActionMode.finish();
     }
   }
 }
  public ActionMode startSupportActionMode(ActionMode.Callback callback) {
    if (callback == null) {
      throw new IllegalArgumentException("ActionMode callback can not be null.");
    }

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

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

    if (mActionMode == null) {
      // If the action bar didn't provide an action mode, start the emulated window one
      mActionMode = startSupportActionModeFromWindow(wrappedCallback);
    }

    return mActionMode;
  }
  @Override
  public void onListItemClick(ListView l, View v, int position, long id) {
    super.onListItemClick(l, v, position, id);
    if (mActionMode == null) {
      Activity activity = getActivity();
      if (activity instanceof AoClicarNoHotel) {
        Cursor cursor = (Cursor) l.getItemAtPosition(position);
        Hotel hotel = HotelRepositorio.hotelFromCursor(cursor);

        AoClicarNoHotel listener = (AoClicarNoHotel) activity;
        listener.clicouNoHotel(hotel);
      }
    } else {
      atualizarItensMarcados(mListView, position);
      if (qtdeItensMarcados() == 0) {
        mActionMode.finish();
      }
    }
  }
예제 #24
0
 /**
  * This method deletes all reference to a {@link Context} so {@link Activity} could be properly
  * recreated
  */
 @Override
 public void onDestroyView() {
   selectorBegin = textSelector.getBeginObject();
   selectorEnd = textSelector.getEndObject();
   selectorNoBegin = textSelector.isNoBegin();
   selectorNoEnd = textSelector.isNoEnd();
   if (mode != null) {
     mode.finish();
     mode = null;
   }
   super.onDestroyView();
   menu.destroyViews();
   editorScrollX = board.getEditorScrollX();
   editorScrollY = board.getEditorScrollY();
   lines = board.getLines();
   board.destroyViews();
   board = null;
   textSelector.destroy();
   textSelector = null;
 }
  @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();
    }
  }
        @Override
        public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
          if (item.getItemId() == R.id.action_delete) {
            mAdapter.delete();
            mActionMode.finish();

            Snackbar.make(
                    mRecyclerView,
                    getString(R.string.message_deleted, mAdapter.totalItemChecked()),
                    Snackbar.LENGTH_LONG)
                .setAction(
                    R.string.message_undo,
                    new View.OnClickListener() {
                      @Override
                      public void onClick(View v) {
                        mAdapter.undoDelete();
                      }
                    })
                .setActionTextColor(ContextCompat.getColor(MainActivity.this, R.color.colorPrimary))
                .show();
          }

          return false;
        }
  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;
  }
예제 #28
0
 private void finishActionMode() {
   if (currentActionMode != null) {
     currentActionMode.finish();
   }
 }
예제 #29
0
 public void destroyActionModeIfNeeded() {
   if (actionMode != null) {
     actionMode.finish();
   }
 }
예제 #30
0
 public void finish() {
   if (mActionMode != null) {
     mActionMode.finish();
   }
   mActionMode = null;
 }