android.view.ActionMode Java Examples

The following examples show how to use android.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: ServerListActivity.java    From padland with Apache License 2.0 6 votes vote down vote up
/**
     * Called when the user selects a contextual menu item
     *
     * @param mode
     * @param item
     * @return
     */
    @Override
    public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
        switch (item.getItemId()) {
            case R.id.menuitem_delete:
                AskDelete(getCheckedItemIds());
                // Action picked, so close the CAB
                mode.finish();
                return true;
//            case R.id.menuitem_share:
//                menu_share(getCheckedItemIds());
                // Action picked, so close the CAB
//                mode.finish();
//                return true;
            default:
                return false;
        }
    }
 
Example #2
Source File: MessageAdapter.java    From Pix-Art-Messenger with GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
    if (item.getItemId() == android.R.id.button1) {
        int start = messageBody.getSelectionStart();
        int end = messageBody.getSelectionEnd();
        if (end > start) {
            String text = transformText(messageBody.getText(), start, end, false);
            String user = multiuser ? messageUser.getText().toString() : null;
            if (onQuoteListener != null) {
                onQuoteListener.onQuote(text, user);
            }
            mode.finish();
        }
        return true;
    }
    return false;
}
 
Example #3
Source File: FloatingPastePopupMenu.java    From 365browser with Apache License 2.0 6 votes vote down vote up
@Override
public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
    int id = item.getItemId();
    if (id == R.id.select_action_menu_paste) {
        mDelegate.paste();
        mode.finish();
    }
    if (id == R.id.select_action_menu_paste_as_plain_text) {
        mDelegate.pasteAsPlainText();
        mode.finish();
    }
    if (id == R.id.select_action_menu_select_all) {
        mDelegate.selectAll();
        mode.finish();
    }
    return true;
}
 
Example #4
Source File: DirectoryFragment.java    From FireFiles with Apache License 2.0 6 votes vote down vote up
@Override
public void onItemCheckedStateChanged(ActionMode mode, int position, long id, boolean checked) {
	if (checked) {
		// Directories and footer items cannot be checked
		boolean valid = false;

		final Cursor cursor = mAdapter.getItem(position);
		if (cursor != null) {
			final String docMimeType = getCursorString(cursor, Document.COLUMN_MIME_TYPE);
			final int docFlags = getCursorInt(cursor, Document.COLUMN_FLAGS);
			// if (!Document.MIME_TYPE_DIR.equals(docMimeType)) {
			valid = isDocumentEnabled(docMimeType, docFlags);
			// }
		}

		if (!valid) {
			mCurrentView.setItemChecked(position, false);
		}
	}

	int count = mCurrentView.getCheckedItemCount();
	mode.setTitle(getResources().getString(R.string.mode_selected_count, count));
	if (count == 1 || count == 2) {
		mode.invalidate();
	}
}
 
Example #5
Source File: BrowseDrawerListener.java    From android-vlc-remote with GNU General Public License v3.0 5 votes vote down vote up
/** {@inheritDoc} */
public void onDestroyActionMode(ActionMode mode) {
    if (mode == mActionMode) {
        if (mDrawer.isOpened()) {
            mDrawer.animateClose();
        }
        mActionMode = null;
    }
}
 
Example #6
Source File: MultiChoiceAdapterHelper.java    From MultiChoiceAdapter with Apache License 2.0 5 votes vote down vote up
@Override
protected void startActionMode() {
    try {
        Activity activity = (Activity) adapterView.getContext();
        Method method = activity.getClass().getMethod("startActionMode", ActionMode.Callback.class);
        actionMode = (ActionMode) method.invoke(activity, owner);
    } catch (Exception e) {
        e.printStackTrace();
        throw new RuntimeException(e);
    }
}
 
Example #7
Source File: DownloadHistoryPhotoFragment.java    From Instagram-Profile-Downloader with MIT License 5 votes vote down vote up
@Override
public boolean onCreateActionMode(ActionMode mode, Menu menu) {
    // Inflate a menu resource providing context menu items
    MenuInflater inflater = mode.getMenuInflater();
    inflater.inflate(R.menu.menu_delete, menu);
    return true;
}
 
Example #8
Source File: ListUnit.java    From Dashchan with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onCreateActionMode(ActionMode mode, Menu menu) {
	gridView.setChoiceMode(GridView.CHOICE_MODE_MULTIPLE);
	gridView.clearChoices();
	mode.setTitle(instance.context.getString(R.string.text_selected_format, 0));
	int selectAllResId = ResourceUtils.getSystemSelectionIcon(instance.context, "actionModeSelectAllDrawable",
			"ic_menu_selectall_holo_dark");
	int flags = MenuItem.SHOW_AS_ACTION_ALWAYS | MenuItem.SHOW_AS_ACTION_WITH_TEXT;
	ActionIconSet set = new ActionIconSet(instance.context);
	menu.add(0, ACTION_MENU_SELECT_ALL, 0, R.string.action_select_all)
			.setIcon(selectAllResId).setShowAsAction(flags);
	menu.add(0, ACTION_MENU_DOWNLOAD_FILES, 0, R.string.action_download_files)
			.setIcon(set.getId(R.attr.actionDownload)).setShowAsAction(flags);
	return true;
}
 
Example #9
Source File: WidgetTimezones.java    From SuntimesWidget with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean onCreateActionMode(ActionMode mode, Menu menu)
{
    MenuInflater inflater = mode.getMenuInflater();
    inflater.inflate(R.menu.timezonesort, menu);
    return true;
}
 
Example #10
Source File: FindActionModeCallback.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
@Override
public void onDestroyActionMode(ActionMode mode) {
    mActionMode = null;
    mWebView.notifyFindDialogDismissed();
    mWebView.setFindDialogFindListener(null);
    mInput.hideSoftInputFromWindow(mWebView.getWindowToken(), 0);
}
 
Example #11
Source File: SelectionPopupController.java    From 365browser with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
    if (!isActionModeValid()) return true;

    int id = item.getItemId();
    int groupId = item.getGroupId();

    if (id == mAssistMenuItemId) {
        doAssistAction();
        mode.finish();
    } else if (id == R.id.select_action_menu_select_all) {
        selectAll();
    } else if (id == R.id.select_action_menu_cut) {
        cut();
        mode.finish();
    } else if (id == R.id.select_action_menu_copy) {
        copy();
        mode.finish();
    } else if (id == R.id.select_action_menu_paste) {
        paste();
        mode.finish();
    } else if (id == R.id.select_action_menu_share) {
        share();
        mode.finish();
    } else if (id == R.id.select_action_menu_web_search) {
        search();
        mode.finish();
    } else if (groupId == R.id.select_action_menu_text_processing_menus) {
        processText(item.getIntent());
        // The ActionMode is not dismissed to match the behavior with
        // TextView in Android M.
    } else {
        return false;
    }
    return true;
}
 
Example #12
Source File: FreeFlowContainer.java    From FreeFlow with Apache License 2.0 5 votes vote down vote up
@Override
public void onDestroyActionMode(ActionMode mode) {
	mWrapped.onDestroyActionMode(mode);
	mChoiceActionMode = null;

	// Ending selection mode means deselecting everything.
	clearChoices();
	updateOnScreenCheckedViews();

	// rememberSyncState();
	requestLayout();

	setLongClickable(true);
}
 
Example #13
Source File: DirectoryFragment.java    From FireFiles with Apache License 2.0 5 votes vote down vote up
@Override
public void onClick(final View v) {

	final int position = mCurrentView.getPositionForView(v);
	if (position != ListView.INVALID_POSITION) {
		int count = mCurrentView.getCheckedItemCount();
		switch (v.getId()) {
		case android.R.id.icon:
			if (count == 0) {
				ActionMode mChoiceActionMode = null;
				if (mChoiceActionMode == null && (mChoiceActionMode = mCurrentView.startActionMode(mMultiListener)) != null) {
					mCurrentView.setItemChecked(position, true);
					mCurrentView.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS);
				}
			} else {
				mCurrentView.setItemChecked(position, !mCurrentView.isItemChecked(position));
				mCurrentView.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS);
			}
			break;

		case R.id.button_popup:
			v.post(new Runnable() {
				@Override
				public void run() {
					showPopupMenu(v, position);
				}
			});
			break;
		}
	}

}
 
Example #14
Source File: ListSelectionManager.java    From Pix-Art-Messenger with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean onCreateActionMode(ActionMode mode, Menu menu) {
    selectionActionMode = mode;
    selectionIdentifier = identifier;
    selectionTextView = textView;
    if (additionalCallback != null) {
        additionalCallback.onCreateActionMode(mode, menu);
    }
    return true;
}
 
Example #15
Source File: DownloadHistoryPhotoFragment.java    From Instagram-Profile-Downloader with MIT License 5 votes vote down vote up
@Override
public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
    switch (item.getItemId()) {
        case R.id.action_delete:
            showAlertDialog();
            return true;
        default:
            if (eventListener != null)
                eventListener.updateActionBar(false, -1);
            return false;
    }
}
 
Example #16
Source File: AuthenticatorActivityTest.java    From google-authenticator-android with Apache License 2.0 5 votes vote down vote up
@TargetApi(11)
// The return value is of type android.view.ActionMode. However, since the ActionMode class is
// only available in API Level 11+, we have to declare the return type as Object in order to
// for this test class to load fine on Gingerbread and below.
private static Object openListViewContextualActionBar(
    AuthenticatorActivity activity, ListView listView, int position) {
  View listEntry = listView.getChildAt(position);
  onView(is(listEntry)).perform(longClick());
  ActionMode actionMode = activity.actionMode;
  if (actionMode == null) {
    throw new RuntimeException(
        "Failed to open list entry contextual action bar: got ActionMode == null");
  }
  return actionMode;
}
 
Example #17
Source File: ChooseContactActivity.java    From Pix-Art-Messenger with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onItemCheckedStateChanged(ActionMode mode, int position, long id, boolean checked) {
    if (selected.size() != 0) {
        getListView().playSoundEffect(0);
    }
    Contact item = (Contact) getListItems().get(position);
    if (checked) {
        selected.add(item.getJid().toString());
    } else {
        selected.remove(item.getJid().toString());
    }
}
 
Example #18
Source File: ContentFragment.java    From androidtestdebug with MIT License 5 votes vote down vote up
public boolean onCreateActionMode(ActionMode actionMode, Menu menu) {
    actionMode.setTitle(R.string.photo_selection_cab_title);

    MenuInflater inflater = getActivity().getMenuInflater();
    inflater.inflate(R.menu.photo_context_menu, menu);
    return true;
}
 
Example #19
Source File: ListSelectionManager.java    From Pix-Art-Messenger with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
    if (additionalCallback != null) {
        additionalCallback.onPrepareActionMode(mode, menu);
    }
    return true;
}
 
Example #20
Source File: PadListActivity.java    From padland with Apache License 2.0 5 votes vote down vote up
/**
 * Called when the action mode is created; startActionMode() was called
 *
 * @param mode
 * @param menu
 * @return boolean
 */
@Override
public boolean onCreateActionMode(ActionMode mode, Menu menu) {
    // Inflate a menu resource providing context menu items
    MenuInflater inflater = mode.getMenuInflater();
    inflater.inflate(R.menu.rowselection, menu);

    mActionMode = mode;

    return true;
}
 
Example #21
Source File: DirectoryFragment.java    From FireFiles with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onCreateActionMode(ActionMode mode, Menu menu) {
	editMode = root != null && root.isEditSupported();
	int menuId = R.menu.mode_simple_directory;
	if (null != root && root.isApp()) {
		menuId = R.menu.mode_apps;
	} else {
		menuId = R.menu.mode_directory;
	}

	mode.getMenuInflater().inflate(menuId, menu);
	int count = mCurrentView.getCheckedItemCount();
	mode.setTitle(count+"");
	return true;
}
 
Example #22
Source File: EditTextBoldCursor.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
@Override
public ActionMode startActionMode(ActionMode.Callback callback, int type) {
    if (Build.VERSION.SDK_INT >= 23 && (windowView != null || attachedToWindow != null)) {
        return startActionMode(callback);
    } else {
        return super.startActionMode(callback, type);
    }
}
 
Example #23
Source File: FriendPickerActivity.java    From Klyph with MIT License 5 votes vote down vote up
@Override
public boolean  onActionItemClicked(ActionMode mode, MenuItem item)
{
	deselectAll();

	return true;
}
 
Example #24
Source File: WidgetTimezones.java    From SuntimesWidget with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean onCreateActionMode(android.support.v7.view.ActionMode mode, Menu menu)
{
    MenuInflater inflater = mode.getMenuInflater();
    inflater.inflate(R.menu.timezonesort, menu);
    return true;
}
 
Example #25
Source File: DataList.java    From trekarta with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onItemCheckedStateChanged(ActionMode mode, int position, long id, boolean checked) {
    ListView listView = getListView();
    int count = listView.getCheckedItemCount();
    mode.setTitle(getResources().getQuantityString(R.plurals.itemsSelected, count, count));
    // Update (redraw) list item view
    int start = listView.getFirstVisiblePosition();
    for (int i = start, j = listView.getLastVisiblePosition(); i <= j; i++) {
        if (position == i) {
            View view = listView.getChildAt(i - start);
            listView.getAdapter().getView(i, view, listView);
            break;
        }
    }
}
 
Example #26
Source File: ChatSelectTouchListener.java    From revolution-irc with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onGetContentRect(ActionMode mode, View view, Rect outRect) {
    view.getLocationOnScreen(mTmpLocation);

    TextView textViewStart = findTextViewByItemId(mSelectionStartId);
    TextView textViewEnd = findTextViewByItemId(mSelectionEndId);
    int lineStart = textViewStart != null ?
            textViewStart.getLayout().getLineForOffset(mSelectionStartOffset) : -1;
    int lineEnd = textViewStart != null ?
            textViewStart.getLayout().getLineForOffset(mSelectionEndOffset) : -1;

    outRect.top = 0;
    if (textViewStart != null) {
        textViewStart.getLocationOnScreen(mTmpLocation2);
        outRect.top = mTmpLocation2[1] - mTmpLocation[1];
        outRect.top += textViewStart.getLayout().getLineTop(lineStart);
    }
    outRect.bottom = view.getHeight();
    if (textViewEnd != null) {
        textViewEnd.getLocationOnScreen(mTmpLocation2);
        outRect.bottom = mTmpLocation2[1] - mTmpLocation[1];
        outRect.bottom += textViewEnd.getLayout().getLineBottom(lineEnd);
    }
    outRect.left = 0;
    outRect.right = view.getWidth();
    if (textViewStart != null && textViewStart == textViewEnd && lineStart == lineEnd) {
        textViewStart.getLocationOnScreen(mTmpLocation2);
        outRect.left = mTmpLocation2[0] - mTmpLocation[0];
        outRect.left += textViewStart.getLayout().getPrimaryHorizontal(mSelectionStartOffset);
        outRect.right = mTmpLocation2[0] - mTmpLocation[0];
        outRect.right += textViewStart.getLayout().getPrimaryHorizontal(mSelectionEndOffset);
    }
}
 
Example #27
Source File: CustomActionModeTitleAdapter.java    From MultiChoiceAdapter with Apache License 2.0 4 votes vote down vote up
@Override
public boolean onCreateActionMode(ActionMode mode, Menu menu) {
    MenuInflater inflater = mode.getMenuInflater();
    inflater.inflate(R.menu.my_action_mode, menu);
    return true;
}
 
Example #28
Source File: TwoLinesArrayAdapter.java    From MultiChoiceAdapter with Apache License 2.0 4 votes vote down vote up
@Override
public boolean onCreateActionMode(ActionMode mode, Menu menu) {
    MenuInflater inflater = mode.getMenuInflater();
    inflater.inflate(R.menu.my_action_mode, menu);
    return true;
}
 
Example #29
Source File: CardArrayMultiChoiceAdapter.java    From example with Apache License 2.0 4 votes vote down vote up
@Override
public void onDestroyActionMode(ActionMode mode) {
    actionMode = null;
}
 
Example #30
Source File: ObservableWebView.java    From BookReader with Apache License 2.0 4 votes vote down vote up
@Override
public ActionMode startActionMode(ActionMode.Callback callback, int type) {
    return this.dummyActionMode();
}