androidx.appcompat.view.ActionMode Java Examples

The following examples show how to use androidx.appcompat.view.ActionMode. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: FavoriteActivityTest.java    From materialistic with Apache License 2.0 6 votes vote down vote up
@Test
public void testDelete() {
    RecyclerView.ViewHolder holder = shadowAdapter.getViewHolder(0);
    holder.itemView.performLongClick();

    ActionMode actionMode = mock(ActionMode.class);
    activity.actionModeCallback.onActionItemClicked(actionMode, new RoboMenuItem(R.id.menu_clear));
    AlertDialog dialog = ShadowAlertDialog.getLatestAlertDialog();
    dialog.getButton(DialogInterface.BUTTON_NEGATIVE).performClick();
    assertEquals(2, adapter.getItemCount());

    activity.actionModeCallback.onActionItemClicked(actionMode, new RoboMenuItem(R.id.menu_clear));
    dialog = ShadowAlertDialog.getLatestAlertDialog();
    dialog.getButton(DialogInterface.BUTTON_POSITIVE).performClick();
    verify(favoriteManager).remove(any(Context.class), selection.capture());
    assertThat(selection.getValue()).contains("1");
    verify(actionMode).finish();

    when(favoriteManager.getSize()).thenReturn(1);
    observerCaptor.getValue().onChanged();
    assertEquals(1, adapter.getItemCount());
}
 
Example #2
Source File: QiscusBaseChatActivity.java    From qiscus-sdk-android with Apache License 2.0 6 votes vote down vote up
protected void onSelectedCommentsAction(ActionMode mode, MenuItem item, List<QiscusComment> selectedComments) {
    int i = item.getItemId();
    if (i == R.id.action_copy) {
        copyComments(selectedComments);
    } else if (i == R.id.action_share) {
        if (selectedComments.size() > 0) {
            shareComment(selectedComments.get(0));
        }
    } else if (i == R.id.action_reply) {
        if (selectedComments.size() > 0) {
            replyComment(selectedComments.get(0));
        }
    } else if (i == R.id.action_forward) {
        forwardComments(selectedComments);
    } else if (i == R.id.action_info && selectedComments.size() > 0) {
        showCommentInfo(selectedComments.get(0));
    } else if (i == R.id.action_delete && selectedComments.size() > 0) {
        deleteComments(selectedComments);
    }
    mode.finish();
}
 
Example #3
Source File: FavoriteRecyclerViewAdapter.java    From materialistic with Apache License 2.0 6 votes vote down vote up
@Override
public boolean onActionItemClicked(final ActionMode actionMode, MenuItem menuItem) {
    if (menuItem.getItemId() == R.id.menu_clear) {
        mAlertDialogBuilder
                .init(mContext)
                .setMessage(R.string.confirm_clear_selected)
                .setPositiveButton(android.R.string.ok,
                        (dialog, which) -> {
                            mPendingClear = true;
                            removeSelection();
                            actionMode.finish();
                        })
                .setNegativeButton(android.R.string.cancel, null)
                .create()
                .show();
        return true;
    }
    if (menuItem.getItemId() == R.id.menu_refresh) {
        refreshSelection();
        actionMode.finish();
    }
    return false;
}
 
Example #4
Source File: ConversationListFragment.java    From deltachat-android with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onDestroyActionMode(ActionMode mode) {
  getListAdapter().initializeBatchMode(false);

  if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
    TypedArray color = getActivity().getTheme().obtainStyledAttributes(new int[] {android.R.attr.statusBarColor});
    getActivity().getWindow().setStatusBarColor(color.getColor(0, Color.BLACK));
    color.recycle();
  }

  Context context = getContext();
  if (context != null) {
    fab.setImageDrawable(ContextCompat.getDrawable(context, R.drawable.ic_add_white_24dp));
  }
  initializeFabClickListener(false);

  actionMode = null;
}
 
Example #5
Source File: ConversationFragment.java    From deltachat-android with GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean onCreateActionMode(ActionMode mode, Menu menu) {
    MenuInflater inflater = mode.getMenuInflater();
    inflater.inflate(R.menu.conversation_context, menu);

    mode.setTitle("1");

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

    setCorrectMenuVisibility(menu);
    return true;
}
 
Example #6
Source File: ChatsFragment.java    From tindroid with Apache License 2.0 6 votes vote down vote up
@Override
public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
    boolean single = mSelectionTracker.getSelection().size() <= 1;

    if (!mIsBanned) {
        menu.setGroupVisible(R.id.single_selection, single);

        if (single) {
            menu.findItem(R.id.action_mute).setVisible(!mSelectionMuted);
            menu.findItem(R.id.action_unmute).setVisible(mSelectionMuted);

            menu.findItem(R.id.action_archive).setVisible(!mIsArchive);
            menu.findItem(R.id.action_unarchive).setVisible(mIsArchive);
        }
    } else {
        menu.setGroupVisible(R.id.single_selection, false);
        menu.findItem(R.id.action_unblock).setVisible(single);
    }
    return true;
}
 
Example #7
Source File: MediaOverviewPageFragment.java    From mollyim-android with GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean onActionItemClicked(ActionMode mode, MenuItem menuItem) {
  switch (menuItem.getItemId()) {
    case R.id.save:
      MediaActions.handleSaveMedia(MediaOverviewPageFragment.this,
                                   getListAdapter().getSelectedMedia(),
                                   () -> actionMode.finish());
      return true;
    case R.id.delete:
      MediaActions.handleDeleteMedia(requireContext(), getListAdapter().getSelectedMedia());
      actionMode.finish();
      return true;
    case R.id.select_all:
      handleSelectAllMedia();
      return true;
  }
  return false;
}
 
Example #8
Source File: ActionModeHelper.java    From FlexibleAdapter with Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 * With FlexibleAdapter v5.0.0 the default mode is {@link Mode#IDLE}, if
 * you want single selection enabled change default mode with {@link #withDefaultMode(int)}.
 */
@CallSuper
@Override
public void onDestroyActionMode(ActionMode actionMode) {
    Log.d("ActionMode is about to be destroyed!");
    // Change mode and deselect everything
    mAdapter.setMode(defaultMode);
    mAdapter.clearSelection();
    mActionMode = null;
    // Re-enable Swipe and Drag capabilities if they were disabled by this helper
    enableSwipeDragCapabilities();
    // Notify the provided callback
    if (mCallback != null) {
        mCallback.onDestroyActionMode(actionMode);
    }
}
 
Example #9
Source File: PublishesFragment.java    From lbry-android with MIT License 6 votes vote down vote up
@Override
public void onDestroyActionMode(ActionMode actionMode) {
    if (adapter != null) {
        adapter.clearSelectedItems();
        adapter.setInSelectionMode(false);
        adapter.notifyDataSetChanged();
    }
    Context context = getContext();
    if (context != null) {
        MainActivity activity = (MainActivity) context;
        if (!activity.isDarkMode()) {
            activity.getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
        }
    }
    this.actionMode = null;
}
 
Example #10
Source File: ConversationListFragment.java    From mollyim-android with GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean onCreateActionMode(ActionMode mode, Menu menu) {
  MenuInflater inflater = getActivity().getMenuInflater();

  inflater.inflate(getActionModeMenuRes(), menu);
  inflater.inflate(R.menu.conversation_list_batch, menu);

  mode.setTitle("1");

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

  if (Build.VERSION.SDK_INT >= 23) {
    int current = getActivity().getWindow().getDecorView().getSystemUiVisibility();
    getActivity().getWindow().getDecorView().setSystemUiVisibility(current & ~View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
  }

  return true;
}
 
Example #11
Source File: ChatsFragment.java    From toktok-android with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onDestroyActionMode(ActionMode mode) {
    mAppLayout.setBackgroundColor(CompatUtil.getColor(getResources(), R.color.homeColorToolbar));

    mFab.setImageResource(R.drawable.ic_content_add_home);
    mFab.setBackgroundTintList(ColorStateList.valueOf(CompatUtil.getColor(getResources(), R.color.basicFABColor)));
    mFab.setImageTintList(ColorStateList.valueOf(CompatUtil.getColor(getResources(), R.color.basicFABTint)));

    mFab.setOnClickListener(v -> startActivity(new Intent(getActivity(), NewMessageActivity.class)));

    mCustomViewPager.setSwipingEnabled(true);

    mChatsRecyclerAdapter.clearSelections();
    mActionMode = null;
    mAppLayout = null;
    mFab = null;
    mCustomViewPager = null;
}
 
Example #12
Source File: MessageActivity.java    From toktok-android with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean onActionItemClicked(@NonNull ActionMode mode, @NonNull MenuItem item) {
    final int id = item.getItemId();
    if (id == R.id.action_message_delete) {
        mRecyclerAdapter.deleteSelected();
        mode.finish();
    }

    return true;
}
 
Example #13
Source File: QiscusBaseChatActivity.java    From qiscus-sdk-android with Apache License 2.0 5 votes vote down vote up
@Override
public void onDestroyActionMode(ActionMode mode) {
    actionMode = null;
    QiscusBaseChatFragment fragment = (QiscusBaseChatFragment) getSupportFragmentManager()
            .findFragmentByTag(QiscusBaseChatFragment.class.getName());
    if (fragment != null) {
        fragment.clearSelectedComments();
    }
}
 
Example #14
Source File: ProfileSettingsFragment.java    From deltachat-android with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onDestroyActionMode(ActionMode mode) {
  actionMode = null;
  adapter.clearSelection();
  if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
    getActivity().getWindow().setStatusBarColor(originalStatusBarColor);
  }
}
 
Example #15
Source File: MainActivity.java    From FlexibleAdapter with Apache License 2.0 5 votes vote down vote up
@Override
public void onDestroyActionMode(ActionMode mode) {
    if (Utils.hasMarshmallow()) {
        getWindow().setStatusBarColor(getResources().getColor(R.color.colorPrimaryDark_light, this.getTheme()));
    } else if (Utils.hasLollipop()) {
        //noinspection deprecation
        getWindow().setStatusBarColor(getResources().getColor(R.color.colorPrimaryDark_light));
    }
}
 
Example #16
Source File: ProfileDocumentsFragment.java    From deltachat-android with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean onActionItemClicked(ActionMode mode, MenuItem menuItem) {
  switch (menuItem.getItemId()) {
    case R.id.delete:
      handleDeleteMedia(getListAdapter().getSelectedMedia());
      mode.finish();
      return true;
  }
  return false;
}
 
Example #17
Source File: MainListFragment.java    From Passbook with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
    switch (item.getItemId()) {
        case R.id.action_delete:
            mRemoveCount = mAdapter.getSelected(mToBeRemoved);
            mFromMenu = true;
            reset();
            return true;
        default:
            mFromMenu = true;
            reset();
            return true;
    }
}
 
Example #18
Source File: ProfileDocumentsFragment.java    From deltachat-android with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onDestroyActionMode(ActionMode mode) {
  actionMode = null;
  getListAdapter().clearSelection();

  if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
    getActivity().getWindow().setStatusBarColor(originalStatusBarColor);
  }
}
 
Example #19
Source File: MainListFragment.java    From Passbook with Apache License 2.0 5 votes vote down vote up
@Override
public void onDestroyActionMode(ActionMode actionMode) {
    mActionMode = null;
    mIsEditing = false;
    mSelectionMode = false;
    mCategoryEditView.setVisibility(View.GONE);
    updateData(mCategoryId);
    showFab(true);
    mListener.onLockDrawer(false);
}
 
Example #20
Source File: BrowseActivity.java    From shortyz with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean onCreateActionMode(ActionMode mode, Menu menu) {
    //4
    actionMode = mode;
    MenuItem item = menu.add("Delete");
    item.setIcon(android.R.drawable.ic_menu_delete);
    utils.onActionBarWithText(item);
    item = menu.add(viewArchive ? "Un-archive" : "Archive");
    utils.onActionBarWithText(item);
    item.setIcon(R.drawable.ic_action_remove);
    download.setVisibility(View.GONE);
    return true;
}
 
Example #21
Source File: ProfileGalleryFragment.java    From deltachat-android with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean onActionItemClicked(ActionMode mode, MenuItem menuItem) {
  switch (menuItem.getItemId()) {
    case R.id.delete:
      handleDeleteMedia(getListAdapter().getSelectedMedia());
      mode.finish();
      return true;
  }
  return false;
}
 
Example #22
Source File: ProfileGalleryFragment.java    From deltachat-android with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onDestroyActionMode(ActionMode mode) {
  actionMode = null;
  getListAdapter().clearSelection();

  if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
    getActivity().getWindow().setStatusBarColor(originalStatusBarColor);
  }
}
 
Example #23
Source File: CourseOutlineFragment.java    From edx-app-android with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onCreateActionMode(ActionMode mode, Menu menu) {
    // Inflate a menu resource providing context menu items
    final MenuInflater inflater = mode.getMenuInflater();
    inflater.inflate(R.menu.delete_contextual_menu, menu);
    menu.findItem(R.id.item_delete).setIcon(
            new IconDrawable(getContext(), FontAwesomeIcons.fa_trash_o)
                    .colorRes(getContext(), R.color.white)
                    .actionBarSize(getContext())
    );
    mode.setTitle(R.string.delete_videos_title);
    return true;
}
 
Example #24
Source File: QiscusBaseChatActivity.java    From qiscus-sdk-android with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
    menu.findItem(R.id.action_reply).setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
    menu.findItem(R.id.action_copy).setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
    menu.findItem(R.id.action_share).setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
    menu.findItem(R.id.action_forward).setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
    return true;
}
 
Example #25
Source File: MessageActivity.java    From toktok-android with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean onCreateActionMode(@NonNull ActionMode mode, Menu menu) {
    MenuInflater menuInflater = mode.getMenuInflater();
    menuInflater.inflate(R.menu.message_action_mode, menu);

    mRecyclerAdapter.setActionModeActive(true);
    mRecyclerAdapter.notifyDataSetChanged();

    Animation animationOut = AnimationUtils.loadAnimation(mInputLayout.getContext(), R.anim.abc_slide_out_bottom);
    mInputLayout.startAnimation(animationOut);
    mInputLayout.setVisibility(View.GONE);

    return true;
}
 
Example #26
Source File: MainListFragment.java    From Passbook with Apache License 2.0 5 votes vote down vote up
@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;
}
 
Example #27
Source File: LibraryFragment.java    From lbry-android with MIT License 5 votes vote down vote up
@Override
public boolean onCreateActionMode(ActionMode actionMode, Menu menu) {
    this.actionMode = actionMode;
    Context context = getContext();
    if (context instanceof MainActivity) {
        MainActivity activity = (MainActivity) context;
        if (!activity.isDarkMode()) {
            activity.getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_VISIBLE);
        }
    }

    actionMode.getMenuInflater().inflate(R.menu.menu_claim_list, menu);
    return true;
}
 
Example #28
Source File: PublishesFragment.java    From lbry-android with MIT License 5 votes vote down vote up
@Override
public boolean onActionItemClicked(androidx.appcompat.view.ActionMode actionMode, MenuItem menuItem) {
    if (R.id.action_edit == menuItem.getItemId()) {
        if (adapter != null && adapter.getSelectedCount() > 0) {
            Claim claim = adapter.getSelectedItems().get(0);
            // start channel editor with the claim
            Context context = getContext();
            if (context instanceof MainActivity) {
                ((MainActivity) context).openPublishForm(claim);
            }

            actionMode.finish();
            return true;
        }
    }
    if (R.id.action_delete == menuItem.getItemId()) {
        if (adapter != null && adapter.getSelectedCount() > 0) {
            final List<Claim> selectedClaims = new ArrayList<>(adapter.getSelectedItems());
            String message = getResources().getQuantityString(R.plurals.confirm_delete_publishes, selectedClaims.size());
            AlertDialog.Builder builder = new AlertDialog.Builder(getContext()).
                    setTitle(R.string.delete_selection).
                    setMessage(message)
                    .setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialogInterface, int i) {
                            handleDeleteSelectedClaims(selectedClaims);
                        }
                    }).setNegativeButton(R.string.no, null);
            builder.show();
            return true;
        }
    }

    return false;
}
 
Example #29
Source File: PublishesFragment.java    From lbry-android with MIT License 5 votes vote down vote up
@Override
public boolean onCreateActionMode(ActionMode actionMode, Menu menu) {
    this.actionMode = actionMode;
    Context context = getContext();
    if (context instanceof MainActivity) {
        MainActivity activity = (MainActivity) context;
        if (!activity.isDarkMode()) {
            activity.getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_VISIBLE);
        }
    }

    actionMode.getMenuInflater().inflate(R.menu.menu_claim_list, menu);
    return true;
}
 
Example #30
Source File: ChannelManagerFragment.java    From lbry-android with MIT License 5 votes vote down vote up
@Override
public boolean onActionItemClicked(androidx.appcompat.view.ActionMode actionMode, MenuItem menuItem) {
    if (R.id.action_edit == menuItem.getItemId()) {
        if (adapter != null && adapter.getSelectedCount() > 0) {
            Claim claim = adapter.getSelectedItems().get(0);
            // start channel editor with the claim
            Context context = getContext();
            if (context instanceof MainActivity) {
                Map<String, Object> params = new HashMap<>();
                params.put("claim", claim);
                ((MainActivity) context).openFragment(ChannelFormFragment.class, true, NavMenuItem.ID_ITEM_CHANNELS, params);
            }

            actionMode.finish();
            return true;
        }
    }
    if (R.id.action_delete == menuItem.getItemId()) {
        if (adapter != null && adapter.getSelectedCount() > 0) {
            final List<Claim> selectedClaims = new ArrayList<>(adapter.getSelectedItems());
            String message = getResources().getQuantityString(R.plurals.confirm_delete_channels, selectedClaims.size());
            AlertDialog.Builder builder = new AlertDialog.Builder(getContext()).
                    setTitle(R.string.delete_selection).
                    setMessage(message)
                    .setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialogInterface, int i) {
                            handleDeleteSelectedClaims(selectedClaims);
                        }
                    }).setNegativeButton(R.string.no, null);
            builder.show();
            return true;
        }
    }

    return false;
}