use of android.view.SubMenu in project android_frameworks_base by crdroidandroid.
the class Editor method onCreateContextMenu.
void onCreateContextMenu(ContextMenu menu) {
if (mIsBeingLongClicked || Float.isNaN(mContextMenuAnchorX) || Float.isNaN(mContextMenuAnchorY)) {
return;
}
final int offset = mTextView.getOffsetForPosition(mContextMenuAnchorX, mContextMenuAnchorY);
if (offset == -1) {
return;
}
stopTextActionModeWithPreservingSelection();
final boolean isOnSelection = mTextView.hasSelection() && offset >= mTextView.getSelectionStart() && offset <= mTextView.getSelectionEnd();
if (!isOnSelection) {
// Right clicked position is not on the selection. Remove the selection and move the
// cursor to the right clicked position.
Selection.setSelection((Spannable) mTextView.getText(), offset);
stopTextActionMode();
}
if (shouldOfferToShowSuggestions()) {
final SuggestionInfo[] suggestionInfoArray = new SuggestionInfo[SuggestionSpan.SUGGESTIONS_MAX_SIZE];
for (int i = 0; i < suggestionInfoArray.length; i++) {
suggestionInfoArray[i] = new SuggestionInfo();
}
final SubMenu subMenu = menu.addSubMenu(Menu.NONE, Menu.NONE, MENU_ITEM_ORDER_REPLACE, com.android.internal.R.string.replace);
final int numItems = mSuggestionHelper.getSuggestionInfo(suggestionInfoArray, null);
for (int i = 0; i < numItems; i++) {
final SuggestionInfo info = suggestionInfoArray[i];
subMenu.add(Menu.NONE, Menu.NONE, i, info.mText).setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
replaceWithSuggestion(info);
return true;
}
});
}
}
menu.add(Menu.NONE, TextView.ID_UNDO, MENU_ITEM_ORDER_UNDO, com.android.internal.R.string.undo).setAlphabeticShortcut('z').setOnMenuItemClickListener(mOnContextMenuItemClickListener).setEnabled(mTextView.canUndo());
menu.add(Menu.NONE, TextView.ID_REDO, MENU_ITEM_ORDER_REDO, com.android.internal.R.string.redo).setOnMenuItemClickListener(mOnContextMenuItemClickListener).setEnabled(mTextView.canRedo());
menu.add(Menu.NONE, TextView.ID_CUT, MENU_ITEM_ORDER_CUT, com.android.internal.R.string.cut).setAlphabeticShortcut('x').setOnMenuItemClickListener(mOnContextMenuItemClickListener).setEnabled(mTextView.canCut());
menu.add(Menu.NONE, TextView.ID_COPY, MENU_ITEM_ORDER_COPY, com.android.internal.R.string.copy).setAlphabeticShortcut('c').setOnMenuItemClickListener(mOnContextMenuItemClickListener).setEnabled(mTextView.canCopy());
menu.add(Menu.NONE, TextView.ID_PASTE, MENU_ITEM_ORDER_PASTE, com.android.internal.R.string.paste).setAlphabeticShortcut('v').setEnabled(mTextView.canPaste()).setOnMenuItemClickListener(mOnContextMenuItemClickListener);
menu.add(Menu.NONE, TextView.ID_PASTE, MENU_ITEM_ORDER_PASTE_AS_PLAIN_TEXT, com.android.internal.R.string.paste_as_plain_text).setEnabled(mTextView.canPaste()).setOnMenuItemClickListener(mOnContextMenuItemClickListener);
menu.add(Menu.NONE, TextView.ID_SHARE, MENU_ITEM_ORDER_SHARE, com.android.internal.R.string.share).setEnabled(mTextView.canShare()).setOnMenuItemClickListener(mOnContextMenuItemClickListener);
menu.add(Menu.NONE, TextView.ID_SELECT_ALL, MENU_ITEM_ORDER_SELECT_ALL, com.android.internal.R.string.selectAll).setAlphabeticShortcut('a').setEnabled(mTextView.canSelectAllText()).setOnMenuItemClickListener(mOnContextMenuItemClickListener);
mPreserveSelection = true;
}
use of android.view.SubMenu in project bottomsheet by Flipboard.
the class MenuSheetView method prepareMenuItems.
/**
* Flattens the visible menu items of {@link #menu} into {@link #items},
* while inserting separators between items when necessary.
*
* Adapted from the Design support library's NavigationMenuPresenter implementation
*/
private void prepareMenuItems() {
items.clear();
int currentGroupId = 0;
// Iterate over the menu items
for (int i = 0; i < menu.size(); i++) {
MenuItem item = menu.getItem(i);
if (item.isVisible()) {
if (item.hasSubMenu()) {
// Flatten the submenu
SubMenu subMenu = item.getSubMenu();
if (subMenu.hasVisibleItems()) {
if (menuType == LIST) {
items.add(SheetMenuItem.SEPARATOR);
// Add a header item if it has text
if (!TextUtils.isEmpty(item.getTitle())) {
items.add(SheetMenuItem.of(item));
}
}
// Add the sub-items
for (int subI = 0, size = subMenu.size(); subI < size; subI++) {
MenuItem subMenuItem = subMenu.getItem(subI);
if (subMenuItem.isVisible()) {
items.add(SheetMenuItem.of(subMenuItem));
}
}
// Add one more separator to the end to close it off if we have more items
if (menuType == LIST && i != menu.size() - 1) {
items.add(SheetMenuItem.SEPARATOR);
}
}
} else {
int groupId = item.getGroupId();
if (groupId != currentGroupId && menuType == LIST) {
items.add(SheetMenuItem.SEPARATOR);
}
items.add(SheetMenuItem.of(item));
currentGroupId = groupId;
}
}
}
}
use of android.view.SubMenu in project android_frameworks_base by AOSPA.
the class ListContextMenu method onCreateContextMenu.
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuInfo;
String text = ((TextView) info.targetView).getText().toString();
if (text.contains("[0]")) {
menu.setHeaderTitle("This is a test of the title and the icon").setHeaderIcon(android.R.drawable.sym_def_app_icon);
} else if (text.contains("[1]")) {
menu.setHeaderTitle("This is a test of just the title");
} else {
TextView textView = new TextView(this);
textView.setText("This is a test of a custom View");
menu.setHeaderView(textView);
}
menu.add(0, 0, 0, "Test 1");
SubMenu sm = menu.addSubMenu(0, 0, 0, "Test 1.5 SM");
sm.add(0, 0, 0, "CM Subitem 1");
sm.add(0, 0, 0, "CM Subitem 2");
sm.add(0, 0, 0, "CM Subitem 3");
menu.add(0, 0, 0, "Test 2");
menu.add(0, 0, 0, "Test 3");
menu.add(0, 0, 0, "Test 4");
menu.add(0, 0, 0, "Test 5");
menu.add(0, 0, 0, "Test 6");
menu.add(0, 0, 0, "Test 7");
menu.add(0, 0, 0, "Test 8");
menu.add(0, 0, 0, "Test 9");
menu.add(0, 0, 0, "Test 10");
menu.add(0, 0, 0, "Test 11");
menu.add(0, 0, 0, "Test 12");
menu.add(0, 0, 0, "Test 13");
menu.add(0, 0, 0, "Test 14");
menu.add(0, 0, 0, "Test 15");
menu.add(0, 0, 0, "Test 16");
menu.add(0, 0, 0, "Test 17");
menu.add(0, 0, 0, "Test 18");
menu.add(0, 0, 0, "Test 19");
menu.add(0, 0, 0, "Test 20");
menu.add(0, 0, 0, "Test 21");
menu.add(0, 0, 0, "Test 22");
menu.add(0, 0, 0, "Test 23");
menu.add(0, 0, 0, "Test 24");
}
use of android.view.SubMenu in project android_frameworks_base by AOSPA.
the class ListContextMenu method onCreateOptionsMenu.
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuItem item = menu.add(0, 0, 0, "Really long menu item name");
item.setTitleCondensed("Long name");
item.setIcon(R.drawable.black_square);
SubMenu sm = menu.addSubMenu(0, 0, 0, "The 2nd item, a sub menu").setIcon(R.drawable.black_square_stretchable);
item = sm.getItem();
item.setTitleCondensed("Sub menu");
sm.add(1, 0, 0, "Subitem 1");
sm.add(1, 0, 0, "Subitem 2");
sm.add(1, 0, 0, "Subitem 3");
sm.setGroupCheckable(1, true, true);
menu.add(0, 0, 0, "Item 3");
menu.add(0, 0, 0, "Item 4");
menu.add(0, 0, 0, "Item 5");
menu.add(0, 0, 0, "Item 6");
menu.add(0, 0, 0, "Item 7");
menu.add(0, 0, 0, "Item 8");
menu.add(0, 0, 0, "Item 9");
sm = menu.addSubMenu(0, 0, 0, "Item 10 SM");
sm.add(0, 0, 0, "Subitem 1");
sm.add(0, 0, 0, "Subitem 2");
sm.add(0, 0, 0, "Subitem 3");
sm.add(0, 0, 0, "Subitem 4");
sm.add(0, 0, 0, "Subitem 5");
sm.add(0, 0, 0, "Subitem 6");
sm.add(0, 0, 0, "Subitem 7");
sm.add(0, 0, 0, "Subitem 8");
return true;
}
use of android.view.SubMenu in project android_frameworks_base by AOSPA.
the class MenuTest method testSubMenu.
@SmallTest
public void testSubMenu() {
final SubMenu subMenu = mMenu.addSubMenu(0, 0, 0, "submenu");
final MenuItem subMenuItem = subMenu.getItem();
final MenuItem item1 = subMenu.add(0, 1, 0, "item1");
final MenuItem item2 = subMenu.add(0, 2, 0, "item2");
// findItem should recurse into submenus
Assert.assertEquals(item1, mMenu.findItem(1));
Assert.assertEquals(item2, mMenu.findItem(2));
}
Aggregations