List of usage examples for android.view MenuItem hasSubMenu
public boolean hasSubMenu();
From source file:net.gsantner.opoc.util.ContextUtils.java
/** * Try to tint all {@link Menu}s {@link MenuItem}s with given color *//*from w w w . j ava 2s . co m*/ @SuppressWarnings("ConstantConditions") public void tintMenuItems(Menu menu, boolean recurse, @ColorInt int iconColor) { for (int i = 0; i < menu.size(); i++) { MenuItem item = menu.getItem(i); try { tintDrawable(item.getIcon(), iconColor); if (item.hasSubMenu() && recurse) { tintMenuItems(item.getSubMenu(), recurse, iconColor); } } catch (Exception ignored) { // This should not happen at all, but may in bad menu.xml configuration } } }
From source file:android.support.v7.internal.view.menu.MenuBuilder.java
public void restoreActionViewStates(Bundle states) { if (states == null) { return;/*from w w w. j av a2s. c om*/ } SparseArray<Parcelable> viewStates = states.getSparseParcelableArray(getActionViewStatesKey()); final int itemCount = size(); for (int i = 0; i < itemCount; i++) { final MenuItem item = getItem(i); final View v = MenuItemCompat.getActionView(item); if (v != null && v.getId() != View.NO_ID) { v.restoreHierarchyState(viewStates); } if (item.hasSubMenu()) { final SubMenuBuilder subMenu = (SubMenuBuilder) item.getSubMenu(); subMenu.restoreActionViewStates(states); } } final int expandedId = states.getInt(EXPANDED_ACTION_VIEW_ID); if (expandedId > 0) { MenuItem itemToExpand = findItem(expandedId); if (itemToExpand != null) { MenuItemCompat.expandActionView(itemToExpand); } } }
From source file:org.getlantern.firetweet.activity.support.ComposeActivity.java
@Override protected void onCreate(final Bundle savedInstanceState) { // requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS); super.onCreate(savedInstanceState); mLocationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); mPreferences = SharedPreferencesWrapper.getInstance(this, SHARED_PREFERENCES_NAME, Context.MODE_PRIVATE); final FiretweetApplication app = FiretweetApplication.getInstance(this); mTwitterWrapper = app.getTwitterWrapper(); mResolver = getContentResolver();// www .j a v a 2 s . c o m mValidator = new FiretweetValidator(this); mImageLoader = app.getMediaLoaderWrapper(); setContentView(R.layout.activity_compose); // setSupportProgressBarIndeterminateVisibility(false); setFinishOnTouchOutside(false); final long[] defaultAccountIds = getAccountIds(this); if (defaultAccountIds.length <= 0) { final Intent intent = new Intent(INTENT_ACTION_TWITTER_LOGIN); intent.setClass(this, SignInActivity.class); startActivity(intent); finish(); return; } // mMenuBar.setIsBottomBar(true); mMenuBar.setOnMenuItemClickListener(this); mEditText.setOnEditorActionListener(mPreferences.getBoolean(KEY_QUICK_SEND, false) ? this : null); mEditText.addTextChangedListener(this); mEditText.setCustomSelectionActionModeCallback(this); mAccountSelectorContainer.setOnClickListener(this); mAccountSelectorButton.setOnClickListener(this); mLocationContainer.setOnClickListener(this); final LinearLayoutManager linearLayoutManager = new FixedLinearLayoutManager(this); linearLayoutManager.setOrientation(LinearLayoutManager.VERTICAL); linearLayoutManager.setStackFromEnd(true); mAccountSelector.setLayoutManager(linearLayoutManager); mAccountSelector.addItemDecoration(new SpacingItemDecoration(this)); mAccountsAdapter = new AccountIconsAdapter(this); mAccountSelector.setAdapter(mAccountsAdapter); mAccountsAdapter.setAccounts(ParcelableAccount.getAccounts(this, false, false)); mMediaPreviewAdapter = new MediaPreviewAdapter(this); mMediaPreviewGrid.setAdapter(mMediaPreviewAdapter); final Intent intent = getIntent(); if (savedInstanceState != null) { // Restore from previous saved state mAccountsAdapter.setSelectedAccountIds(savedInstanceState.getLongArray(EXTRA_ACCOUNT_IDS)); mIsPossiblySensitive = savedInstanceState.getBoolean(EXTRA_IS_POSSIBLY_SENSITIVE); final ArrayList<ParcelableMediaUpdate> mediaList = savedInstanceState .getParcelableArrayList(EXTRA_MEDIA); if (mediaList != null) { addMedia(mediaList); } mInReplyToStatus = savedInstanceState.getParcelable(EXTRA_STATUS); mInReplyToStatusId = savedInstanceState.getLong(EXTRA_STATUS_ID); mMentionUser = savedInstanceState.getParcelable(EXTRA_USER); mDraftItem = savedInstanceState.getParcelable(EXTRA_DRAFT); mShouldSaveAccounts = savedInstanceState.getBoolean(EXTRA_SHOULD_SAVE_ACCOUNTS); mOriginalText = savedInstanceState.getString(EXTRA_ORIGINAL_TEXT); mTempPhotoUri = savedInstanceState.getParcelable(EXTRA_TEMP_URI); } else { // The context was first created final int notificationId = intent.getIntExtra(EXTRA_NOTIFICATION_ID, -1); final long notificationAccount = intent.getLongExtra(EXTRA_NOTIFICATION_ACCOUNT, -1); if (notificationId != -1) { mTwitterWrapper.clearNotificationAsync(notificationId, notificationAccount); } if (!handleIntent(intent)) { handleDefaultIntent(intent); } final long[] accountIds = mAccountsAdapter.getSelectedAccountIds(); if (accountIds.length == 0) { final long[] idsInPrefs = FiretweetArrayUtils .parseLongArray(mPreferences.getString(KEY_COMPOSE_ACCOUNTS, null), ','); final long[] intersection = FiretweetArrayUtils.intersection(idsInPrefs, defaultAccountIds); mAccountsAdapter.setSelectedAccountIds(intersection.length > 0 ? intersection : defaultAccountIds); } mOriginalText = ParseUtils.parseString(mEditText.getText()); } if (!setComposeTitle(intent)) { setTitle(R.string.compose); } final Menu menu = mMenuBar.getMenu(); getMenuInflater().inflate(R.menu.menu_compose, menu); ThemeUtils.wrapMenuIcon(mMenuBar); mSendView.setOnClickListener(this); mSendView.setOnLongClickListener(this); final Intent composeExtensionsIntent = new Intent(INTENT_ACTION_EXTENSION_COMPOSE); addIntentToMenu(this, menu, composeExtensionsIntent, MENU_GROUP_COMPOSE_EXTENSION); final Intent imageExtensionsIntent = new Intent(INTENT_ACTION_EXTENSION_EDIT_IMAGE); final MenuItem mediaMenuItem = menu.findItem(R.id.media_menu); if (mediaMenuItem != null && mediaMenuItem.hasSubMenu()) { addIntentToMenu(this, mediaMenuItem.getSubMenu(), imageExtensionsIntent, MENU_GROUP_IMAGE_EXTENSION); } setMenu(); updateLocationState(); updateMediaPreview(); notifyAccountSelectionChanged(); }
From source file:android.support.v7.internal.view.menu.MenuBuilder.java
public void saveActionViewStates(Bundle outStates) { SparseArray<Parcelable> viewStates = null; final int itemCount = size(); for (int i = 0; i < itemCount; i++) { final MenuItem item = getItem(i); final View v = MenuItemCompat.getActionView(item); if (v != null && v.getId() != View.NO_ID) { if (viewStates == null) { viewStates = new SparseArray<Parcelable>(); }/*from w w w . j av a 2s .c om*/ v.saveHierarchyState(viewStates); if (MenuItemCompat.isActionViewExpanded(item)) { outStates.putInt(EXPANDED_ACTION_VIEW_ID, item.getItemId()); } } if (item.hasSubMenu()) { final SubMenuBuilder subMenu = (SubMenuBuilder) item.getSubMenu(); subMenu.saveActionViewStates(outStates); } } if (viewStates != null) { outStates.putSparseParcelableArray(getActionViewStatesKey(), viewStates); } }
From source file:org.mariotaku.twidere.activity.support.ComposeActivity.java
@Override protected void onCreate(final Bundle savedInstanceState) { super.onCreate(savedInstanceState); mLocationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); mPreferences = SharedPreferencesWrapper.getInstance(this, SHARED_PREFERENCES_NAME, Context.MODE_PRIVATE, SharedPreferenceConstants.class); final TwidereApplication app = TwidereApplication.getInstance(this); mTwitterWrapper = app.getTwitterWrapper(); mResolver = getContentResolver();/*w ww .j a v a2 s . co m*/ mValidator = new TwidereValidator(this); mImageLoader = app.getMediaLoaderWrapper(); setContentView(R.layout.activity_compose); setFinishOnTouchOutside(false); final long[] defaultAccountIds = Utils.getAccountIds(this); if (defaultAccountIds.length <= 0) { final Intent intent = new Intent(INTENT_ACTION_TWITTER_LOGIN); intent.setClass(this, SignInActivity.class); startActivity(intent); finish(); return; } mMenuBar.setOnMenuItemClickListener(this); setupEditText(); mAccountSelectorContainer.setOnClickListener(this); mAccountSelectorButton.setOnClickListener(this); mLocationContainer.setOnClickListener(this); final LinearLayoutManager linearLayoutManager = new FixedLinearLayoutManager(this); linearLayoutManager.setOrientation(LinearLayoutManager.VERTICAL); linearLayoutManager.setStackFromEnd(true); mAccountSelector.setLayoutManager(linearLayoutManager); mAccountSelector.addItemDecoration(new SpacingItemDecoration(this)); mAccountSelector.setItemAnimator(new RecyclerView.ItemAnimator() { @Override public void runPendingAnimations() { } @Override public boolean animateRemove(ViewHolder holder) { return false; } @Override public boolean animateAdd(ViewHolder holder) { return false; } @Override public boolean animateMove(ViewHolder holder, int fromX, int fromY, int toX, int toY) { Log.d(LOGTAG, String.format("animateMove")); return false; } @Override public boolean animateChange(ViewHolder oldHolder, ViewHolder newHolder, int fromLeft, int fromTop, int toLeft, int toTop) { Log.d(LOGTAG, String.format("animateChange")); return false; } @Override public void endAnimation(ViewHolder item) { Log.d(LOGTAG, String.format("endAnimation")); } @Override public void endAnimations() { } @Override public boolean isRunning() { return false; } }); mAccountsAdapter = new AccountIconsAdapter(this); mAccountSelector.setAdapter(mAccountsAdapter); mAccountsAdapter.setAccounts(ParcelableAccount.getAccounts(this, false, false)); mMediaPreviewAdapter = new MediaPreviewAdapter(this); mMediaPreviewGrid.setAdapter(mMediaPreviewAdapter); final Intent intent = getIntent(); if (savedInstanceState != null) { // Restore from previous saved state mAccountsAdapter.setSelectedAccountIds(savedInstanceState.getLongArray(EXTRA_ACCOUNT_IDS)); mIsPossiblySensitive = savedInstanceState.getBoolean(EXTRA_IS_POSSIBLY_SENSITIVE); final ArrayList<ParcelableMediaUpdate> mediaList = savedInstanceState .getParcelableArrayList(EXTRA_MEDIA); if (mediaList != null) { addMedia(mediaList); } mInReplyToStatus = savedInstanceState.getParcelable(EXTRA_STATUS); mInReplyToStatusId = savedInstanceState.getLong(EXTRA_STATUS_ID); mMentionUser = savedInstanceState.getParcelable(EXTRA_USER); mDraftItem = savedInstanceState.getParcelable(EXTRA_DRAFT); mShouldSaveAccounts = savedInstanceState.getBoolean(EXTRA_SHOULD_SAVE_ACCOUNTS); mOriginalText = savedInstanceState.getString(EXTRA_ORIGINAL_TEXT); } else { // The context was first created final int notificationId = intent.getIntExtra(EXTRA_NOTIFICATION_ID, -1); final long notificationAccount = intent.getLongExtra(EXTRA_NOTIFICATION_ACCOUNT, -1); if (notificationId != -1) { mTwitterWrapper.clearNotificationAsync(notificationId, notificationAccount); } if (!handleIntent(intent)) { handleDefaultIntent(intent); } final long[] accountIds = mAccountsAdapter.getSelectedAccountIds(); if (accountIds.length == 0) { final long[] idsInPrefs = TwidereArrayUtils .parseLongArray(mPreferences.getString(KEY_COMPOSE_ACCOUNTS, null), ','); final long[] intersection = TwidereArrayUtils.intersection(idsInPrefs, defaultAccountIds); mAccountsAdapter.setSelectedAccountIds(intersection.length > 0 ? intersection : defaultAccountIds); } mOriginalText = ParseUtils.parseString(mEditText.getText()); } if (!setComposeTitle(intent)) { setTitle(R.string.compose); } final Menu menu = mMenuBar.getMenu(); getMenuInflater().inflate(R.menu.menu_compose, menu); ThemeUtils.wrapMenuIcon(mMenuBar); mSendView.setOnClickListener(this); mSendView.setOnLongClickListener(this); final Intent composeExtensionsIntent = new Intent(INTENT_ACTION_EXTENSION_COMPOSE); Utils.addIntentToMenu(this, menu, composeExtensionsIntent, MENU_GROUP_COMPOSE_EXTENSION); final Intent imageExtensionsIntent = new Intent(INTENT_ACTION_EXTENSION_EDIT_IMAGE); final MenuItem mediaMenuItem = menu.findItem(R.id.media_menu); if (mediaMenuItem != null && mediaMenuItem.hasSubMenu()) { Utils.addIntentToMenu(this, mediaMenuItem.getSubMenu(), imageExtensionsIntent, MENU_GROUP_IMAGE_EXTENSION); } setMenu(); updateLocationState(); updateMediaPreview(); notifyAccountSelectionChanged(); mTextChanged = false; }
From source file:org.mozilla.gecko.BrowserApp.java
private static Menu findParentMenu(Menu menu, MenuItem item) { final int itemId = item.getItemId(); final int count = (menu != null) ? menu.size() : 0; for (int i = 0; i < count; i++) { MenuItem menuItem = menu.getItem(i); if (menuItem.getItemId() == itemId) { return menu; }/* w w w . ja va 2 s .c o m*/ if (menuItem.hasSubMenu()) { Menu parent = findParentMenu(menuItem.getSubMenu(), item); if (parent != null) { return parent; } } } return null; }
From source file:de.vanita5.twittnuker.util.Utils.java
public static void setMenuForStatus(final Context context, final Menu menu, final ParcelableStatus status) { if (context == null || menu == null || status == null) return;//from w ww. ja v a 2 s . c o m final int activatedColor = ThemeUtils.getUserThemeColor(context); final boolean isMyRetweet = isMyRetweet(status); final MenuItem delete = menu.findItem(MENU_DELETE); if (delete != null) { delete.setVisible(status.account_id == status.user_id && !isMyRetweet); } final MenuItem retweet = menu.findItem(MENU_RETWEET); if (retweet != null) { final Drawable icon = retweet.getIcon().mutate(); retweet.setVisible(!status.user_is_protected || isMyRetweet); if (isMyRetweet) { icon.setColorFilter(activatedColor, Mode.SRC_ATOP); retweet.setTitle(R.string.cancel_retweet); } else { icon.clearColorFilter(); retweet.setTitle(R.string.retweet); } } final MenuItem itemRetweetSubmenu = menu.findItem(R.id.retweet_submenu); if (itemRetweetSubmenu != null) { final Drawable icon = itemRetweetSubmenu.getIcon().mutate(); if (isMyRetweet) { icon.setColorFilter(activatedColor, Mode.SRC_ATOP); } else { icon.clearColorFilter(); } } final MenuItem favorite = menu.findItem(MENU_FAVORITE); if (favorite != null) { final Drawable icon = favorite.getIcon().mutate(); if (status.is_favorite) { icon.setColorFilter(activatedColor, Mode.SRC_ATOP); favorite.setTitle(R.string.unfavorite); } else { icon.clearColorFilter(); favorite.setTitle(R.string.favorite); } } final MenuItem love = menu.findItem(MENU_LOVE); if (love != null) { final Drawable icon = love.getIcon().mutate(); love.setVisible(!status.user_is_protected || isMyRetweet); if (isMyRetweet && status.is_favorite) { icon.setColorFilter(activatedColor, Mode.SRC_ATOP); } else { icon.clearColorFilter(); } } final MenuItem translate = menu.findItem(MENU_TRANSLATE); if (translate != null) { final AccountWithCredentials account = Account.getAccountWithCredentials(context, status.account_id); final boolean isOfficialKey = AccountWithCredentials.isOfficialCredentials(context, account); setMenuItemAvailability(menu, MENU_TRANSLATE, isOfficialKey); } final MenuItem shareItem = menu.findItem(R.id.share_submenu); final Menu shareSubmenu = shareItem != null && shareItem.hasSubMenu() ? shareItem.getSubMenu() : null; if (shareSubmenu != null) { final Intent shareIntent = createStatusShareIntent(context, status); shareSubmenu.removeGroup(MENU_GROUP_STATUS_SHARE); addIntentToMenu(context, shareSubmenu, shareIntent, MENU_GROUP_STATUS_SHARE); } }
From source file:org.mozilla.gecko.BrowserApp.java
/** * Add the provided item to the provided menu, which should be * the root (mMenu).//from w w w. j a va2s .co m */ private void addAddonMenuItemToMenu(final Menu menu, final MenuItemInfo info) { info.added = true; final Menu destination; if (info.parent == 0) { destination = menu; } else if (info.parent == GECKO_TOOLS_MENU) { // The tools menu only exists in our -v11 resources. if (Versions.feature11Plus) { final MenuItem tools = menu.findItem(R.id.tools); destination = tools != null ? tools.getSubMenu() : menu; } else { destination = menu; } } else { final MenuItem parent = menu.findItem(info.parent); if (parent == null) { return; } Menu parentMenu = findParentMenu(menu, parent); if (!parent.hasSubMenu()) { parentMenu.removeItem(parent.getItemId()); destination = parentMenu.addSubMenu(Menu.NONE, parent.getItemId(), Menu.NONE, parent.getTitle()); if (parent.getIcon() != null) { ((SubMenu) destination).getItem().setIcon(parent.getIcon()); } } else { destination = parent.getSubMenu(); } } final MenuItem item = destination.add(Menu.NONE, info.id, Menu.NONE, info.label); item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() { @Override public boolean onMenuItemClick(MenuItem item) { GeckoAppShell.sendEventToGecko(GeckoEvent.createBroadcastEvent("Menu:Clicked", Integer.toString(info.id - ADDON_MENU_OFFSET))); return true; } }); if (info.icon == null) { item.setIcon(R.drawable.ic_menu_addons_filler); } else { final int id = info.id; BitmapUtils.getDrawable(this, info.icon, new BitmapUtils.BitmapLoader() { @Override public void onBitmapFound(Drawable d) { // TODO: why do we re-find the item? final MenuItem item = destination.findItem(id); if (item == null) { return; } if (d == null) { item.setIcon(R.drawable.ic_menu_addons_filler); return; } item.setIcon(d); } }); } item.setCheckable(info.checkable); item.setChecked(info.checked); item.setEnabled(info.enabled); item.setVisible(info.visible); }