Example usage for android.view MenuItem getSubMenu

List of usage examples for android.view MenuItem getSubMenu

Introduction

In this page you can find the example usage for android.view MenuItem getSubMenu.

Prototype

public SubMenu getSubMenu();

Source Link

Document

Get the sub-menu to be invoked when this item is selected, if it has one.

Usage

From source file:android.support.v7.internal.view.menu.MenuBuilder.java

public void restoreActionViewStates(Bundle states) {
    if (states == null) {
        return;//  ww  w.j  a v  a  2  s .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:com.tweetlanes.android.view.TweetFeedFragment.java

@Override
public boolean configureOptionsMenu(MenuInflater inflater, Menu menu) {

    if (inflater != null && mContentHandle != null
            && (mContentHandle.getStatusesType() == StatusesType.USER_TIMELINE
                    || mContentHandle.getStatusesType() == StatusesType.USER_HOME_TIMELINE
                    || mContentHandle.getStatusesType() == StatusesType.USER_LIST_TIMELINE)) {

        if (getBaseLaneActivity() instanceof HomeActivity) {
            inflater.inflate(R.menu.home_tweet_feed_action_bar, menu);
        } else {/*  ww  w  . ja v a2s . c o m*/
            inflater.inflate(R.menu.tweet_feed_action_bar, menu);
        }

        for (int i = 0; i < menu.size(); i++) {
            MenuItem menuItem = menu.getItem(i);
            if (menuItem.getItemId() == R.id.action_feed_filter) {
                SubMenu subMenu = menuItem.getSubMenu();
                if (subMenu != null) {
                    SocialNetConstant.Type socialNetType = getApp().getCurrentAccount().getSocialNetType();
                    int subMenuSize = subMenu.size();
                    for (int j = 0; j < subMenuSize; j++) {
                        MenuItem subMenuItem = subMenu.getItem(j);
                        switch (subMenuItem.getItemId()) {
                        case R.id.action_replies_visibility:

                            subMenuItem
                                    .setTitle(getString(getBaseLaneActivity().mStatusesFilter.getShowReplies()
                                            ? R.string.action_hide_replies
                                            : R.string.action_show_replies));
                            break;

                        case R.id.action_retweets_visibility:
                            subMenuItem
                                    .setTitle(getString(getBaseLaneActivity().mStatusesFilter.getShowRetweets()
                                            ? socialNetType == SocialNetConstant.Type.Twitter
                                                    ? R.string.action_hide_retweets
                                                    : R.string.action_hide_retweets_adn
                                            : socialNetType == SocialNetConstant.Type.Twitter
                                                    ? R.string.action_show_retweets
                                                    : R.string.action_show_retweets_adn));
                            break;

                        default:
                            break;
                        }

                    }
                }
            }
        }

        return true;
    }

    return false;
}

From source file:org.totschnig.myexpenses.activity.MyExpenses.java

@Override
public void onCreate(Bundle savedInstanceState) {
    setTheme(MyApplication.getThemeId());
    Resources.Theme theme = getTheme();
    TypedValue value = new TypedValue();
    theme.resolveAttribute(R.attr.colorAggregate, value, true);
    colorAggregate = value.data;//from ww  w .  j  a v  a 2s . co  m
    int prev_version = PrefKey.CURRENT_VERSION.getInt(-1);
    if (prev_version == -1) {
        //prevent preference change listener from firing when preference file is created
        if (MyApplication.getInstance().isInstrumentationTest()) {
            PreferenceManager.setDefaultValues(this, MyApplication.getTestId(), Context.MODE_PRIVATE,
                    R.xml.preferences, true);
        } else {
            PreferenceManager.setDefaultValues(this, R.xml.preferences, false);
        }
    }

    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    adHandler = new AdHandler(this);
    adHandler.init();

    mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    mDrawerList = (StickyListHeadersListView) findViewById(R.id.left_drawer);
    mToolbar = setupToolbar(false);
    mToolbar.addView(getLayoutInflater().inflate(R.layout.custom_title, mToolbar, false));
    if (mDrawerLayout != null) {
        mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, mToolbar, R.string.drawer_open,
                R.string.drawer_close) {

            /**
             * Called when a drawer has settled in a completely closed state.
             */
            public void onDrawerClosed(View view) {
                super.onDrawerClosed(view);
                TransactionList tl = getCurrentFragment();
                if (tl != null)
                    tl.onDrawerClosed();
                //ActivityCompat.invalidateOptionsMenu(MyExpenses.this); // creates call to onPrepareOptionsMenu()
            }

            /**
             * Called when a drawer has settled in a completely open state.
             */
            public void onDrawerOpened(View drawerView) {
                super.onDrawerOpened(drawerView);
                TransactionList tl = getCurrentFragment();
                if (tl != null)
                    tl.onDrawerOpened();
                //ActivityCompat.invalidateOptionsMenu(MyExpenses.this); // creates call to onPrepareOptionsMenu()
            }

            @Override
            public void onDrawerSlide(View drawerView, float slideOffset) {
                super.onDrawerSlide(drawerView, 0); // this disables the animation
            }
        };

        // Set the drawer toggle as the DrawerListener
        mDrawerLayout.addDrawerListener(mDrawerToggle);
    }
    String[] from = new String[] { KEY_DESCRIPTION, KEY_LABEL, KEY_OPENING_BALANCE, KEY_SUM_INCOME,
            KEY_SUM_EXPENSES, KEY_SUM_TRANSFERS, KEY_CURRENT_BALANCE, KEY_TOTAL, KEY_CLEARED_TOTAL,
            KEY_RECONCILED_TOTAL };
    // and an array of the fields we want to bind those fields to
    int[] to = new int[] { R.id.description, R.id.label, R.id.opening_balance, R.id.sum_income,
            R.id.sum_expenses, R.id.sum_transfer, R.id.current_balance, R.id.total, R.id.cleared_total,
            R.id.reconciled_total };
    mDrawerListAdapter = new MyGroupedAdapter(this, R.layout.account_row, null, from, to, 0);

    Toolbar accountsMenu = (Toolbar) findViewById(R.id.accounts_menu);
    accountsMenu.setTitle(R.string.pref_manage_accounts_title);
    accountsMenu.inflateMenu(R.menu.accounts);
    accountsMenu.inflateMenu(R.menu.sort);

    //Sort submenu
    MenuItem menuItem = accountsMenu.getMenu().findItem(R.id.SORT_COMMAND);
    MenuItemCompat.setShowAsAction(menuItem, MenuItemCompat.SHOW_AS_ACTION_NEVER);
    sortMenu = menuItem.getSubMenu();
    sortMenu.findItem(R.id.SORT_CUSTOM_COMMAND).setVisible(true);

    //Grouping submenu
    SubMenu groupingMenu = accountsMenu.getMenu().findItem(R.id.GROUPING_ACCOUNTS_COMMAND).getSubMenu();
    AccountGrouping accountGrouping;
    try {
        accountGrouping = AccountGrouping.valueOf(PrefKey.ACCOUNT_GROUPING.getString("TYPE"));
    } catch (IllegalArgumentException e) {
        accountGrouping = AccountGrouping.TYPE;
    }
    MenuItem activeItem;
    switch (accountGrouping) {
    case CURRENCY:
        activeItem = groupingMenu.findItem(R.id.GROUPING_ACCOUNTS_CURRENCY_COMMAND);
        break;
    case NONE:
        activeItem = groupingMenu.findItem(R.id.GROUPING_ACCOUNTS_NONE_COMMAND);
        break;
    default:
        activeItem = groupingMenu.findItem(R.id.GROUPING_ACCOUNTS_TYPE_COMMAND);
        break;
    }
    activeItem.setChecked(true);

    accountsMenu.setOnMenuItemClickListener(new Toolbar.OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(MenuItem item) {
            return handleSortOption(item) || handleAccountsGrouping(item)
                    || dispatchCommand(item.getItemId(), null);
        }
    });

    mDrawerList.setAdapter(mDrawerListAdapter);
    mDrawerList.setAreHeadersSticky(false);
    mDrawerList.setOnItemClickListener(new OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            if (mAccountId != id) {
                moveToPosition(position);
                ((SimpleCursorAdapter) mDrawerListAdapter).notifyDataSetChanged();
                closeDrawer();
            }
        }
    });

    requireFloatingActionButtonWithContentDescription(Utils.concatResStrings(this, ". ",
            R.string.menu_create_transaction, R.string.menu_create_transfer, R.string.menu_create_split));
    if (prev_version == -1) {
        getSupportActionBar().hide();
        initialSetup();
        return;
    }
    if (savedInstanceState != null) {
        mExportFormat = savedInstanceState.getString("exportFormat");
        mAccountId = savedInstanceState.getLong(KEY_ACCOUNTID, 0L);
    } else {
        Bundle extras = getIntent().getExtras();
        if (extras != null) {
            mAccountId = Utils.getFromExtra(extras, KEY_ROWID, 0);
            idFromNotification = extras.getLong(KEY_TRANSACTIONID, 0);
            //detail fragment from notification should only be shown upon first instantiation from notification
            if (idFromNotification != 0) {
                FragmentManager fm = getSupportFragmentManager();
                if (fm.findFragmentByTag(TransactionDetailFragment.class.getName()) == null) {
                    TransactionDetailFragment.newInstance(idFromNotification).show(fm,
                            TransactionDetailFragment.class.getName());
                    getIntent().removeExtra(KEY_TRANSACTIONID);
                }
            }
        }
    }
    if (mAccountId == 0)
        mAccountId = PrefKey.CURRENT_ACCOUNT.getLong(0L);
    setup();
}

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();/*  ww w. j av a2 s.  c  om*/
    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>();
            }/* w  w w. j a v a 2 s .  com*/
            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.ComposeActivity.java

@Override
public void onCreate(final Bundle savedInstanceState) {
    mLocationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
    mPreferences = getSharedPreferences(SHARED_PREFERENCES_NAME, Context.MODE_PRIVATE);
    mTwitterWrapper = getTwidereApplication().getTwitterWrapper();
    mResolver = getContentResolver();/*from   w ww. j  a v a2 s. co m*/
    super.onCreate(savedInstanceState);
    final long[] account_ids = getAccountIds(this);
    if (account_ids.length <= 0) {
        final Intent intent = new Intent(INTENT_ACTION_TWITTER_LOGIN);
        intent.setClass(this, SignInActivity.class);
        startActivity(intent);
        finish();
        return;
    }
    setContentView(R.layout.compose);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);

    final Bundle bundle = savedInstanceState != null ? savedInstanceState : getIntent().getExtras();
    final long account_id = bundle != null ? bundle.getLong(INTENT_KEY_ACCOUNT_ID) : -1;
    mAccountIds = bundle != null ? bundle.getLongArray(INTENT_KEY_IDS) : null;
    mInReplyToStatusId = bundle != null ? bundle.getLong(INTENT_KEY_IN_REPLY_TO_ID) : -1;
    mInReplyToScreenName = bundle != null ? bundle.getString(INTENT_KEY_IN_REPLY_TO_SCREEN_NAME) : null;
    mInReplyToName = bundle != null ? bundle.getString(INTENT_KEY_IN_REPLY_TO_NAME) : null;
    mIsImageAttached = bundle != null ? bundle.getBoolean(INTENT_KEY_IS_IMAGE_ATTACHED) : false;
    mIsPhotoAttached = bundle != null ? bundle.getBoolean(INTENT_KEY_IS_PHOTO_ATTACHED) : false;
    mImageUri = bundle != null ? (Uri) bundle.getParcelable(INTENT_KEY_IMAGE_URI) : null;
    final String[] mentions = bundle != null ? bundle.getStringArray(INTENT_KEY_MENTIONS) : null;
    final int notification_id = bundle != null ? bundle.getInt(INTENT_KEY_NOTIFICATION_ID, -1) : -1;
    if (notification_id != -1) {
        mTwitterWrapper.clearNotification(notification_id);
    }
    final String account_screen_name = getAccountScreenName(this, account_id);
    int text_selection_start = -1;
    if (mInReplyToStatusId > 0) {
        if (bundle != null && bundle.getString(INTENT_KEY_TEXT) != null
                && (mentions == null || mentions.length < 1)) {
            mText = bundle.getString(INTENT_KEY_TEXT);
        } else if (mentions != null) {
            final StringBuilder builder = new StringBuilder();
            for (final String mention : mentions) {
                if (mentions.length == 1 && mentions[0].equalsIgnoreCase(account_screen_name)) {
                    builder.append('@' + account_screen_name + ' ');
                } else if (!mention.equalsIgnoreCase(account_screen_name)) {
                    builder.append('@' + mention + ' ');
                }
            }
            mText = builder.toString();
            text_selection_start = mText.indexOf(' ') + 1;
        }

        mIsQuote = bundle != null ? bundle.getBoolean(INTENT_KEY_IS_QUOTE, false) : false;

        final boolean display_screen_name = NAME_DISPLAY_OPTION_SCREEN_NAME
                .equals(mPreferences.getString(PREFERENCE_KEY_NAME_DISPLAY_OPTION, NAME_DISPLAY_OPTION_BOTH));
        if (mInReplyToScreenName != null && mInReplyToName != null) {
            setTitle(getString(mIsQuote ? R.string.quote_user : R.string.reply_to,
                    display_screen_name ? mInReplyToScreenName : mInReplyToName));
        }
        if (mAccountIds == null || mAccountIds.length == 0) {
            mAccountIds = new long[] { account_id };
        }
    } else {
        if (mentions != null) {
            final StringBuilder builder = new StringBuilder();
            for (final String mention : mentions) {
                if (mentions.length == 1 && mentions[0].equalsIgnoreCase(account_screen_name)) {
                    builder.append('@' + account_screen_name + ' ');
                } else if (!mention.equalsIgnoreCase(account_screen_name)) {
                    builder.append('@' + mention + ' ');
                }
            }
            mText = builder.toString();
        }
        if (mAccountIds == null || mAccountIds.length == 0) {
            final long[] ids_in_prefs = ArrayUtils
                    .fromString(mPreferences.getString(PREFERENCE_KEY_COMPOSE_ACCOUNTS, null), ',');
            final long[] intersection = ArrayUtils.intersection(ids_in_prefs, account_ids);
            mAccountIds = intersection.length > 0 ? intersection : account_ids;
        }
        final String action = getIntent().getAction();
        if (Intent.ACTION_SEND.equals(action) || Intent.ACTION_SEND_MULTIPLE.equals(action)) {
            setTitle(R.string.share);
            final Bundle extras = getIntent().getExtras();
            if (extras != null) {
                if (mText == null) {
                    final CharSequence extra_subject = extras.getCharSequence(Intent.EXTRA_SUBJECT);
                    final CharSequence extra_text = extras.getCharSequence(Intent.EXTRA_TEXT);
                    mText = getShareStatus(this, parseString(extra_subject), parseString(extra_text));
                } else {
                    mText = bundle.getString(INTENT_KEY_TEXT);
                }
                if (mImageUri == null) {
                    final Uri extra_stream = extras.getParcelable(Intent.EXTRA_STREAM);
                    final String content_type = getIntent().getType();
                    if (extra_stream != null && content_type != null && content_type.startsWith("image/")) {
                        final String real_path = getImagePathFromUri(this, extra_stream);
                        final File file = real_path != null ? new File(real_path) : null;
                        if (file != null && file.exists()) {
                            mImageUri = Uri.fromFile(file);
                            mIsImageAttached = true;
                            mIsPhotoAttached = false;
                        } else {
                            mImageUri = null;
                            mIsImageAttached = false;
                        }
                    }
                }
            }
        } else if (bundle != null) {
            if (bundle.getString(INTENT_KEY_TEXT) != null) {
                mText = bundle.getString(INTENT_KEY_TEXT);
            }
        }
    }

    final File image_file = mImageUri != null && "file".equals(mImageUri.getScheme())
            ? new File(mImageUri.getPath())
            : null;
    final boolean image_file_valid = image_file != null && image_file.exists();
    mImageThumbnailPreview.setVisibility(image_file_valid ? View.VISIBLE : View.GONE);
    if (image_file_valid) {
        reloadAttachedImageThumbnail(image_file);
    }

    mImageThumbnailPreview.setOnClickListener(this);
    mImageThumbnailPreview.setOnLongClickListener(this);
    mMenuBar.setOnMenuItemClickListener(this);
    mMenuBar.inflate(R.menu.menu_compose);
    final Menu menu = mMenuBar.getMenu();
    final MenuItem extensions = menu.findItem(MENU_EXTENSIONS_SUBMENU);
    if (extensions != null) {
        final Intent intent = new Intent(INTENT_ACTION_EXTENSION_COMPOSE);
        final Bundle extras = new Bundle();
        final String screen_name = mAccountIds != null && mAccountIds.length > 0
                ? getAccountScreenName(this, mAccountIds[0])
                : null;
        extras.putString(INTENT_KEY_TEXT, parseString(mEditText.getText()));
        extras.putString(INTENT_KEY_IN_REPLY_TO_SCREEN_NAME, mInReplyToScreenName);
        extras.putString(INTENT_KEY_IN_REPLY_TO_NAME, mInReplyToName);
        extras.putString(INTENT_KEY_SCREEN_NAME, screen_name);
        extras.putLong(INTENT_KEY_IN_REPLY_TO_ID, mInReplyToStatusId);
        intent.putExtras(extras);
        addIntentToSubMenu(this, extensions.getSubMenu(), intent);
    }
    mMenuBar.show();
    if (mPreferences.getBoolean(PREFERENCE_KEY_QUICK_SEND, false)) {
        mEditText.setOnEditorActionListener(this);
    }
    mEditText.addTextChangedListener(this);
    if (mText != null) {
        mEditText.setText(mText);
        if (mIsQuote) {
            mEditText.setSelection(0);
        } else if (text_selection_start != -1 && text_selection_start < mEditText.length()
                && mEditText.length() > 0) {
            mEditText.setSelection(text_selection_start, mEditText.length() - 1);
        } else if (mEditText.length() > 0) {
            mEditText.setSelection(mEditText.length());
        }
    }
    setMenu();
    mColorIndicator.setColors(getAccountColors(this, mAccountIds));
    mContentModified = savedInstanceState != null ? savedInstanceState.getBoolean(INTENT_KEY_CONTENT_MODIFIED)
            : false;
    mIsPossiblySensitive = savedInstanceState != null
            ? savedInstanceState.getBoolean(INTENT_KEY_IS_POSSIBLY_SENSITIVE)
            : false;
}

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 ava2 s  .c  om
    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.totschnig.myexpenses.fragment.TransactionList.java

@Override
public void onPrepareOptionsMenu(Menu menu) {
    super.onPrepareOptionsMenu(menu);
    if (mAccount == null || getActivity() == null) {
        //mAccount seen in report 3331195c529454ca6b25a4c5d403beda
        //getActivity seen in report 68a501c984bdfcc95b40050af4f815bf
        return;/*from   www.  j  av a2  s  . c o  m*/
    }
    MenuItem searchMenu = menu.findItem(R.id.SEARCH_COMMAND);
    if (searchMenu != null) {
        String title;
        Drawable searchMenuIcon = searchMenu.getIcon();
        if (!mFilter.isEmpty()) {
            if (searchMenuIcon != null) {
                searchMenuIcon.setColorFilter(Color.GREEN, PorterDuff.Mode.MULTIPLY);
            } else {
                AcraHelper.report(new Exception("Search menu icon not found"));
            }
            searchMenu.setChecked(true);
            title = mAccount.label + " ( " + mFilter.prettyPrint() + " )";
        } else {
            if (searchMenuIcon != null) {
                searchMenuIcon.setColorFilter(null);
            } else {
                AcraHelper.report(new Exception("Search menu icon not found"));
            }
            searchMenu.setChecked(false);
            title = mAccount.label;
        }
        ((MyExpenses) getActivity()).setTitle(title);
        SubMenu filterMenu = searchMenu.getSubMenu();
        for (int i = 0; i < filterMenu.size(); i++) {
            MenuItem filterItem = filterMenu.getItem(i);
            boolean enabled = true;
            switch (filterItem.getItemId()) {
            case R.id.FILTER_CATEGORY_COMMAND:
                enabled = mappedCategories;
                break;
            case R.id.FILTER_STATUS_COMMAND:
                enabled = !mAccount.type.equals(AccountType.CASH);
                break;
            case R.id.FILTER_PAYEE_COMMAND:
                enabled = mappedPayees;
                break;
            case R.id.FILTER_METHOD_COMMAND:
                enabled = mappedMethods;
                break;
            case R.id.FILTER_TRANSFER_COMMAND:
                enabled = hasTransfers;
                break;
            }
            Criteria c = mFilter.get(filterItem.getItemId());
            Utils.menuItemSetEnabledAndVisible(filterItem, enabled || c != null);
            if (c != null) {
                filterItem.setChecked(true);
                filterItem.setTitle(c.prettyPrint());
            }
        }
    } else {
        AcraHelper.report(new Exception("Search menu not found"));
    }
}

From source file:com.android.app.MediaPlaybackActivity.java

@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    if (mService == null)
        return false;
    MenuItem item = menu.findItem(PARTY_SHUFFLE);
    if (item != null) {
        int shuffle = MusicUtils.getCurrentShuffleMode();
        if (shuffle == MediaPlaybackService.SHUFFLE_AUTO) {
            item.setIcon(R.drawable.ic_menu_party_shuffle);
            item.setTitle(R.string.party_shuffle_off);
        } else {//  ww w . j a v  a2s  .c o m
            item.setIcon(R.drawable.ic_menu_party_shuffle);
            item.setTitle(R.string.party_shuffle);
        }
    }

    item = menu.findItem(ADD_TO_PLAYLIST);
    if (item != null) {
        SubMenu sub = item.getSubMenu();
        MusicUtils.makePlaylistMenu(this, sub);
    }

    KeyguardManager km = (KeyguardManager) getSystemService(Context.KEYGUARD_SERVICE);
    menu.setGroupVisible(1, !km.inKeyguardRestrictedInputMode());

    return true;
}

From source file:com.tweetlanes.android.core.view.TweetFeedFragment.java

@Override
public boolean configureOptionsMenu(MenuInflater inflater, Menu menu) {

    if (inflater != null && mContentHandle != null
            && (mContentHandle.getStatusesType() == StatusesType.USER_TIMELINE
                    || mContentHandle.getStatusesType() == StatusesType.USER_HOME_TIMELINE
                    || mContentHandle.getStatusesType() == StatusesType.USER_LIST_TIMELINE)) {

        if (getBaseLaneActivity() instanceof HomeActivity) {
            inflater.inflate(R.menu.home_tweet_feed_action_bar, menu);
        } else {/*from   ww  w.  jav  a2 s .  c om*/
            inflater.inflate(R.menu.tweet_feed_action_bar, menu);
        }

        for (int i = 0; i < menu.size(); i++) {
            MenuItem menuItem = menu.getItem(i);
            if (menuItem.getItemId() == R.id.action_feed_filter) {
                SubMenu subMenu = menuItem.getSubMenu();
                if (subMenu != null) {
                    SocialNetConstant.Type socialNetType = getApp().getCurrentAccount().getSocialNetType();
                    int subMenuSize = subMenu.size();
                    for (int j = 0; j < subMenuSize; j++) {
                        MenuItem subMenuItem = subMenu.getItem(j);
                        int i1 = subMenuItem.getItemId();
                        if (i1 == R.id.action_replies_visibility) {
                            subMenuItem
                                    .setTitle(getString(getBaseLaneActivity().mStatusesFilter.getShowReplies()
                                            ? R.string.action_hide_replies
                                            : R.string.action_show_replies));

                        } else if (i1 == R.id.action_retweets_visibility) {
                            subMenuItem
                                    .setTitle(getString(getBaseLaneActivity().mStatusesFilter.getShowRetweets()
                                            ? socialNetType == SocialNetConstant.Type.Twitter
                                                    ? R.string.action_hide_retweets
                                                    : R.string.action_hide_retweets_adn
                                            : socialNetType == SocialNetConstant.Type.Twitter
                                                    ? R.string.action_show_retweets
                                                    : R.string.action_show_retweets_adn));

                        } else {
                        }

                    }
                }
            }
        }

        return true;
    }

    return false;
}