use of android.view.SubMenu in project android_frameworks_base by ParanoidAndroid.
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 ParanoidAndroid.
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 ParanoidAndroid.
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));
}
use of android.view.SubMenu in project android_frameworks_base by ResurrectionRemix.
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 SR-Tracker-for-Overwatch by Rexios80.
the class InformationActivity method onCreateOptionsMenu.
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.information_actionbar, menu);
MenuItem seasonList = menu.findItem(R.id.seasons);
SubMenu subMenu = seasonList.getSubMenu();
// Get seasons list from database
DatabaseHelper mDbHelper = new DatabaseHelper(getApplicationContext());
SQLiteDatabase db = mDbHelper.getWritableDatabase();
String[] projection = { DatabaseContract.Database._ID, DatabaseContract.Database.COLUMN_NAME_SEASON };
String sortOrder = DatabaseContract.Database.COLUMN_NAME_SEASON + " ASC";
Cursor cursor = db.query(DatabaseContract.Database.SEASONS_TABLE_NAME, projection, null, null, null, null, sortOrder);
ArrayList<Integer> seasons = new ArrayList<>();
while (cursor.moveToNext()) {
seasons.add(cursor.getInt(cursor.getColumnIndexOrThrow(DatabaseContract.Database.COLUMN_NAME_SEASON)));
}
cursor.close();
// Add seasons to subMenu
if (seasons.size() <= 1) {
MenuItem item = menu.findItem(R.id.seasons);
item.setVisible(false);
}
for (int i = 0; i < seasons.size(); i++) {
subMenu.add(0, i, Menu.NONE, "Season " + seasons.get(i));
}
return true;
}
Aggregations