Java Code Examples for androidx.appcompat.view.ActionMode#Callback

The following examples show how to use androidx.appcompat.view.ActionMode#Callback . 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: WeakActionModeCallback.java    From lttrs-android with Apache License 2.0 5 votes vote down vote up
@Override
public void onDestroyActionMode(final ActionMode mode) {
    final ActionMode.Callback callback = weakCallbackReference.get();
    if (callback != null) {
        callback.onDestroyActionMode(mode);
    }
}
 
Example 2
Source File: FavoriteFragment.java    From materialistic with Apache License 2.0 5 votes vote down vote up
@Override
public boolean startActionMode(ActionMode.Callback callback) {
    if (mSearchViewExpanded) {
        return false;
    }
    if (mActionMode == null) {
        mActionMode = ((AppCompatActivity) getActivity()).startSupportActionMode(callback);
    }
    return true;
}
 
Example 3
Source File: WeakActionModeCallback.java    From lttrs-android with Apache License 2.0 4 votes vote down vote up
public WeakActionModeCallback(final @NonNull ActionMode.Callback callback) {
    this.weakCallbackReference = new WeakReference<>(callback);
}
 
Example 4
Source File: WeakActionModeCallback.java    From lttrs-android with Apache License 2.0 4 votes vote down vote up
@Override
public boolean onCreateActionMode(final ActionMode mode, final Menu menu) {
    final ActionMode.Callback callback = weakCallbackReference.get();
    return callback != null && callback.onCreateActionMode(mode, menu);
}
 
Example 5
Source File: WeakActionModeCallback.java    From lttrs-android with Apache License 2.0 4 votes vote down vote up
@Override
public boolean onPrepareActionMode(final ActionMode mode, final Menu menu) {
    final ActionMode.Callback callback = weakCallbackReference.get();
    return callback != null && callback.onPrepareActionMode(mode, menu);
}
 
Example 6
Source File: WeakActionModeCallback.java    From lttrs-android with Apache License 2.0 4 votes vote down vote up
@Override
public boolean onActionItemClicked(final ActionMode mode, final MenuItem item) {
    final ActionMode.Callback callback = weakCallbackReference.get();
    return callback != null && callback.onActionItemClicked(mode, item);
}
 
Example 7
Source File: LttrsActivity.java    From lttrs-android with Apache License 2.0 4 votes vote down vote up
public ActionMode beginActionMode(final ActionMode.Callback callback) {
    this.actionMode = startSupportActionMode(new WeakActionModeCallback(callback));
    return this.actionMode;
}
 
Example 8
Source File: MessagesAdapter.java    From tindroid with Apache License 2.0 4 votes vote down vote up
MessagesAdapter(MessageActivity context, SwipeRefreshLayout refresher) {
    super();

    mActivity = context;
    setHasStableIds(true);

    mRefresher = refresher;
    mPagesToLoad = 1;

    mMessageLoaderCallback = new MessageLoaderCallbacks();

    mSelectionModeCallback = new ActionMode.Callback() {
        @Override
        public boolean onPrepareActionMode(ActionMode actionMode, Menu menu) {
            mSelectedItems = new SparseBooleanArray();
            return false;
        }

        @Override
        public void onDestroyActionMode(ActionMode actionMode) {
            SparseBooleanArray arr = mSelectedItems;
            mSelectedItems = null;
            if (arr.size() < 6) {
                for (int i = 0; i < arr.size(); i++) {
                    notifyItemChanged(arr.keyAt(i));
                }
            } else {
                notifyDataSetChanged();
            }
        }

        @Override
        public boolean onCreateActionMode(ActionMode actionMode, Menu menu) {
            mActivity.getMenuInflater().inflate(R.menu.menu_message_selected, menu);
            return true;
        }

        @Override
        public boolean onActionItemClicked(ActionMode actionMode, MenuItem menuItem) {
            switch (menuItem.getItemId()) {
                case R.id.action_delete:
                    sendDeleteMessages(getSelectedArray());
                    return true;
                case R.id.action_copy:
                    copyMessageText(getSelectedArray());
                    return true;
                case R.id.action_send_now:
                    // FIXME: implement resending now.
                    Log.d(TAG, "Try re-sending selected item");
                    return true;
                case R.id.action_view_details:
                    // FIXME: implement viewing message details.
                    Log.d(TAG, "Show message details");
                    return true;
                default:
                    break;
            }
            return false;
        }
    };

    mSpanFormatterClicker = new SpanClicker();

    verifyStoragePermissions();
}
 
Example 9
Source File: ContactSelectionListFragment.java    From deltachat-android with GNU General Public License v3.0 4 votes vote down vote up
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
  View view = inflater.inflate(R.layout.contact_selection_list_fragment, container, false);

  emptyText               = ViewUtil.findById(view, android.R.id.empty);
  recyclerView            = ViewUtil.findById(view, R.id.recycler_view);
  swipeRefresh            = ViewUtil.findById(view, R.id.swipe_refresh);
  fastScroller            = ViewUtil.findById(view, R.id.fast_scroller);
  recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
  actionModeCallback = new ActionMode.Callback() {
    @Override
    public boolean onCreateActionMode(ActionMode actionMode, Menu menu) {
      MenuInflater inflater = getActivity().getMenuInflater();
      inflater.inflate(R.menu.contact_list, menu);
      if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        getActivity().getWindow().setStatusBarColor(getResources().getColor(R.color.action_mode_status_bar));
      }
      actionMode.setTitle("1");
      return true;
    }

    @Override
    public boolean onPrepareActionMode(ActionMode actionMode, Menu menu) {
      return false;
    }

    @Override
    public boolean onActionItemClicked(ActionMode actionMode, MenuItem menuItem) {
      switch (menuItem.getItemId()) {
        case R.id.menu_select_all:
          handleSelectAll();
          return true;
        case R.id.menu_delete_selected:
          handleDeleteSelected();
          return true;
      }
      return false;
    }

    @Override
    public void onDestroyActionMode(ActionMode actionMode) {
      ContactSelectionListFragment.this.actionMode = null;
      getContactSelectionListAdapter().resetActionModeSelection();

      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();
      }
    }
  };

  // There shouldn't be the need to pull to refresh the contacts
  // swipeRefresh.setEnabled(getActivity().getIntent().getBooleanExtra(REFRESHABLE, true) && Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN);
  swipeRefresh.setEnabled(false);

  return view;
}
 
Example 10
Source File: TestFavoriteActivity.java    From materialistic with Apache License 2.0 4 votes vote down vote up
@Override
public ActionMode startSupportActionMode(ActionMode.Callback callback) {
    actionModeCallback = callback;
    return super.startSupportActionMode(callback);
}
 
Example 11
Source File: AppCompatPreferenceActivity.java    From MHViewer with Apache License 2.0 2 votes vote down vote up
/**
 * Called when a support action mode is being started for this window. Gives the
 * callback an opportunity to handle the action mode in its own unique and
 * beautiful way. If this method returns null the system can choose a way
 * to present the mode or choose not to start the mode at all.
 *
 * @param callback Callback to control the lifecycle of this action mode
 * @return The ActionMode that was started, or null if the system should present it
 */
@Nullable
@Override
public ActionMode onWindowStartingSupportActionMode(@NonNull ActionMode.Callback callback) {
    return null;
}
 
Example 12
Source File: AppCompatPreferenceActivity.java    From MHViewer with Apache License 2.0 2 votes vote down vote up
/**
 * Start an action mode.
 *
 * @param callback Callback that will manage lifecycle events for this context mode
 * @return The ContextMode that was started, or null if it was canceled
 */
@Nullable
public ActionMode startSupportActionMode(@NonNull ActionMode.Callback callback) {
    return getDelegate().startSupportActionMode(callback);
}
 
Example 13
Source File: ActionModeHelper.java    From FlexibleAdapter with Apache License 2.0 2 votes vote down vote up
/**
 * Constructor with internal callback + custom callback.
 *
 * @param adapter  the FlexibleAdapter instance
 * @param cabMenu  the Contextual Action Bar menu resourceId
 * @param callback the custom {@link androidx.appcompat.view.ActionMode.Callback}
 * @see #ActionModeHelper(FlexibleAdapter, int)
 * @since 1.0.0-b1
 */
public ActionModeHelper(@NonNull FlexibleAdapter adapter, @MenuRes int cabMenu,
                        @Nullable ActionMode.Callback callback) {
    this(adapter, cabMenu);
    this.mCallback = callback;
}
 
Example 14
Source File: AppCompatPreferenceActivity.java    From EhViewer with Apache License 2.0 2 votes vote down vote up
/**
 * Called when a support action mode is being started for this window. Gives the
 * callback an opportunity to handle the action mode in its own unique and
 * beautiful way. If this method returns null the system can choose a way
 * to present the mode or choose not to start the mode at all.
 *
 * @param callback Callback to control the lifecycle of this action mode
 * @return The ActionMode that was started, or null if the system should present it
 */
@Nullable
@Override
public ActionMode onWindowStartingSupportActionMode(@NonNull ActionMode.Callback callback) {
    return null;
}
 
Example 15
Source File: AppCompatPreferenceActivity.java    From EhViewer with Apache License 2.0 2 votes vote down vote up
/**
 * Start an action mode.
 *
 * @param callback Callback that will manage lifecycle events for this context mode
 * @return The ContextMode that was started, or null if it was canceled
 */
@Nullable
public ActionMode startSupportActionMode(@NonNull ActionMode.Callback callback) {
    return getDelegate().startSupportActionMode(callback);
}
 
Example 16
Source File: FavoriteRecyclerViewAdapter.java    From materialistic with Apache License 2.0 votes vote down vote up
boolean startActionMode(ActionMode.Callback callback);