Example usage for android.view ContextMenu setHeaderTitle

List of usage examples for android.view ContextMenu setHeaderTitle

Introduction

In this page you can find the example usage for android.view ContextMenu setHeaderTitle.

Prototype

public ContextMenu setHeaderTitle(CharSequence title);

Source Link

Document

Sets the context menu header's title to the title given in title.

Usage

From source file:com.money.manager.ex.home.HomeFragment.java

/**
 * Context menu for account entries.//  w w  w.java  2 s.  c  om
 */
@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) {
    super.onCreateContextMenu(menu, v, menuInfo);

    if (!(v instanceof ExpandableListView))
        return;

    ExpandableListView.ExpandableListContextMenuInfo info = (ExpandableListView.ExpandableListContextMenuInfo) menuInfo;
    int type = ExpandableListView.getPackedPositionType(info.packedPosition);
    int groupPosition = ExpandableListView.getPackedPositionGroup(info.packedPosition);
    int childPosition = ExpandableListView.getPackedPositionChild(info.packedPosition);

    // ignore long-press on group items.
    if (type != ExpandableListView.PACKED_POSITION_TYPE_CHILD)
        return;

    // get adapter.
    HomeAccountsExpandableAdapter accountsAdapter = (HomeAccountsExpandableAdapter) mExpandableListView
            .getExpandableListAdapter();
    Object childItem = accountsAdapter.getChild(groupPosition, childPosition);
    QueryAccountBills account = (QueryAccountBills) childItem;

    //        menu.setHeaderIcon(android.R.drawable.ic_menu_manage);
    menu.setHeaderTitle(account.getAccountName());
    String[] menuItems = getResources().getStringArray(R.array.context_menu_account_dashboard);
    for (String menuItem : menuItems) {
        menu.add(menuItem);
    }

    // balance account should work only for transaction accounts.
    AccountService service = new AccountService(getActivity());
    List<String> accountTypes = service.getTransactionAccountTypeNames();
    String accountType = account.getAccountType();
    if (accountTypes.contains(accountType)) {
        menu.add(R.string.balance_account);
    }

    // Investment menu items.
    if (accountType.equals(AccountTypes.INVESTMENT.toString())) {
        menu.add(Menu.NONE, ContextMenuIds.Portfolio.getId(), 0, getString(R.string.portfolio));
    }
}

From source file:org.uguess.android.sysinfo.ProcessManager.java

@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
    super.onCreateContextMenu(menu, v, menuInfo);

    int pos = ((AdapterContextMenuInfo) menuInfo).position;
    ProcessItem rap = (ProcessItem) getListView().getItemAtPosition(pos);

    menu.setHeaderTitle(R.string.actions);
    menu.add(Menu.NONE, MI_DISPLAY, Menu.NONE, R.string.switch_to);

    boolean protect = ignoreList.contains(rap.procInfo.processName) || rap.sys;

    if (protect) {
        menu.add(Menu.NONE, MI_ENDTASK, Menu.NONE, R.string.end_task).setEnabled(false);
    } else {//from   w ww. ja  v a2 s.  c o  m
        menu.add(Menu.NONE, MI_ENDTASK, Menu.NONE, R.string.end_task);
    }

    menu.add(Menu.NONE, MI_END_OTHERS, Menu.NONE, R.string.end_others);

    if (protect) {
        menu.add(Menu.NONE, MI_IGNORE, Menu.NONE, R.string.ignore).setEnabled(false);
    } else {
        menu.add(Menu.NONE, MI_IGNORE, Menu.NONE, R.string.ignore);
    }

    menu.add(Menu.NONE, MI_DETAILS, Menu.NONE, R.string.details);
}

From source file:com.xorcode.andtweet.TweetListActivity.java

@Override
public void onCreateContextMenu(ContextMenu menu, View view, ContextMenuInfo menuInfo) {
    super.onCreateContextMenu(menu, view, menuInfo);

    // Get the adapter context menu information
    AdapterView.AdapterContextMenuInfo info;
    try {//from  ww w  .  jav a 2 s .co m
        info = (AdapterView.AdapterContextMenuInfo) menuInfo;
    } catch (ClassCastException e) {
        Log.e(TAG, "bad menuInfo", e);
        return;
    }

    int m = 0;

    // Add menu items
    menu.add(0, CONTEXT_MENU_ITEM_REPLY, m++, R.string.menu_item_reply);
    menu.add(0, CONTEXT_MENU_ITEM_RETWEET, m++, R.string.menu_item_retweet);
    menu.add(0, CONTEXT_MENU_ITEM_SHARE, m++, R.string.menu_item_share);
    // menu.add(0, CONTEXT_MENU_ITEM_DIRECT_MESSAGE, m++,
    // R.string.menu_item_direct_message);
    // menu.add(0, CONTEXT_MENU_ITEM_UNFOLLOW, m++,
    // R.string.menu_item_unfollow);
    // menu.add(0, CONTEXT_MENU_ITEM_BLOCK, m++, R.string.menu_item_block);
    // menu.add(0, CONTEXT_MENU_ITEM_PROFILE, m++,
    // R.string.menu_item_view_profile);

    // Get the record for the currently selected item
    Uri uri = ContentUris.withAppendedId(Tweets.CONTENT_URI, info.id);
    Cursor c = getContentResolver().query(uri,
            new String[] { Tweets._ID, Tweets.MESSAGE, Tweets.AUTHOR_ID, Tweets.FAVORITED }, null, null, null);
    try {
        c.moveToFirst();
        menu.setHeaderTitle(c.getString(c.getColumnIndex(Tweets.MESSAGE)));
        if (c.getInt(c.getColumnIndex(Tweets.FAVORITED)) == 1) {
            menu.add(0, CONTEXT_MENU_ITEM_DESTROY_FAVORITE, m++, R.string.menu_item_destroy_favorite);
        } else {
            menu.add(0, CONTEXT_MENU_ITEM_FAVORITE, m++, R.string.menu_item_favorite);
        }
        if (MyPreferences.getDefaultSharedPreferences().getString(MyPreferences.KEY_TWITTER_USERNAME, null)
                .equals(c.getString(c.getColumnIndex(Tweets.AUTHOR_ID)))) {
            menu.add(0, CONTEXT_MENU_ITEM_DESTROY_STATUS, m++, R.string.menu_item_destroy_status);
        }
    } catch (Exception e) {
        Log.e(TAG, "onCreateContextMenu: " + e.toString());
    } finally {
        if (c != null && !c.isClosed())
            c.close();
    }
}

From source file:info.guardianproject.otr.app.im.app.ContactListActivity.java

@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
    boolean chatSelected = false;
    boolean contactSelected = false;
    Cursor contactCursor;/*from  w w w  .  j a va 2  s . co m*/
    if (mIsFiltering) {
        AdapterView.AdapterContextMenuInfo info = (AdapterContextMenuInfo) menuInfo;
        mContextMenuHandler.mPosition = info.position;
        contactSelected = true;
        contactCursor = mFilterView.getContactAtPosition(info.position);
    } else {
        ExpandableListContextMenuInfo info = (ExpandableListContextMenuInfo) menuInfo;
        mContextMenuHandler.mPosition = info.packedPosition;
        contactSelected = mContactListView.isContactAtPosition(info.packedPosition);
        contactCursor = mContactListView.getContactAtPosition(info.packedPosition);
    }

    boolean allowBlock = true;
    if (contactCursor != null) {
        //XXX HACK: Yahoo! doesn't allow to block a friend. We can only block a temporary contact.
        ProviderDef provider = mApp.getProvider(mProviderId);
        if (Imps.ProviderNames.YAHOO.equals(provider.mName)) {
            int type = contactCursor.getInt(contactCursor.getColumnIndexOrThrow(Imps.Contacts.TYPE));
            allowBlock = (type == Imps.Contacts.TYPE_TEMPORARY);
        }

        int nickNameIndex = contactCursor.getColumnIndexOrThrow(Imps.Contacts.NICKNAME);

        menu.setHeaderTitle(contactCursor.getString(nickNameIndex));
    }

    BrandingResources brandingRes = mApp.getBrandingResource(mProviderId);
    String menu_end_conversation = brandingRes.getString(BrandingResourceIDs.STRING_MENU_END_CHAT);
    String menu_view_profile = brandingRes.getString(BrandingResourceIDs.STRING_MENU_VIEW_PROFILE);
    String menu_block_contact = brandingRes.getString(BrandingResourceIDs.STRING_MENU_BLOCK_CONTACT);
    String menu_start_conversation = brandingRes.getString(BrandingResourceIDs.STRING_MENU_START_CHAT);
    String menu_delete_contact = brandingRes.getString(BrandingResourceIDs.STRING_MENU_DELETE_CONTACT);

    if (chatSelected) {
        menu.add(0, MENU_END_CONVERSATION, 0, menu_end_conversation)
                .setOnMenuItemClickListener(mContextMenuHandler);
        menu.add(0, MENU_VIEW_PROFILE, 0, menu_view_profile).setIcon(R.drawable.ic_menu_my_profile)
                .setOnMenuItemClickListener(mContextMenuHandler);
        if (allowBlock) {
            menu.add(0, MENU_BLOCK_CONTACT, 0, menu_block_contact)
                    .setOnMenuItemClickListener(mContextMenuHandler);
        }
    } else if (contactSelected) {
        menu.add(0, MENU_START_CONVERSATION, 0, menu_start_conversation)
                .setOnMenuItemClickListener(mContextMenuHandler);
        menu.add(0, MENU_VIEW_PROFILE, 0, menu_view_profile).setIcon(R.drawable.ic_menu_view_profile)
                .setOnMenuItemClickListener(mContextMenuHandler);
        if (allowBlock) {
            menu.add(0, MENU_BLOCK_CONTACT, 0, menu_block_contact)
                    .setOnMenuItemClickListener(mContextMenuHandler);
        }
        menu.add(0, MENU_DELETE_CONTACT, 0, menu_delete_contact).setIcon(android.R.drawable.ic_menu_delete)
                .setOnMenuItemClickListener(mContextMenuHandler);
    }
}

From source file:com.fsck.k9.activity.Accounts.java

@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
    super.onCreateContextMenu(menu, v, menuInfo);
    menu.setHeaderTitle(R.string.accounts_context_menu_title);

    AdapterContextMenuInfo info = (AdapterContextMenuInfo) menuInfo;
    BaseAccount account = mAdapter.getItem(info.position);

    if ((account instanceof Account) && !((Account) account).isEnabled()) {
        getMenuInflater().inflate(R.menu.disabled_accounts_context, menu);
    } else {/*  ww w  .  j  a  v  a  2  s  . c  o  m*/
        getMenuInflater().inflate(R.menu.accounts_context, menu);
    }

    if (account instanceof SearchAccount) {
        for (int i = 0; i < menu.size(); i++) {
            android.view.MenuItem item = menu.getItem(i);
            item.setVisible(false);
        }
    } else {
        EnumSet<ACCOUNT_LOCATION> accountLocation = accountLocation(account);
        if (accountLocation.contains(ACCOUNT_LOCATION.TOP)) {
            menu.findItem(R.id.move_up).setEnabled(false);
        } else {
            menu.findItem(R.id.move_up).setEnabled(true);
        }
        if (accountLocation.contains(ACCOUNT_LOCATION.BOTTOM)) {
            menu.findItem(R.id.move_down).setEnabled(false);
        } else {
            menu.findItem(R.id.move_down).setEnabled(true);
        }
    }
}

From source file:org.uguess.android.sysinfo.ApplicationManager.java

@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
    menu.setHeaderTitle(R.string.actions);
    menu.add(Menu.NONE, MI_MANAGE, Menu.NONE, R.string.manage);
    menu.add(Menu.NONE, MI_LAUNCH, Menu.NONE, R.string.run);
    menu.add(Menu.NONE, MI_SEARCH, Menu.NONE, R.string.search_market);
    menu.add(Menu.NONE, MI_DETAILS, Menu.NONE, R.string.details);
}

From source file:cgeo.geocaching.cgeocaches.java

@Override
public void onCreateContextMenu(final ContextMenu menu, final View view,
        final ContextMenu.ContextMenuInfo info) {
    super.onCreateContextMenu(menu, view, info);

    AdapterContextMenuInfo adapterInfo = null;
    try {/*from   w  ww .j a v a 2  s .  c  om*/
        adapterInfo = (AdapterContextMenuInfo) info;
    } catch (Exception e) {
        Log.w("cgeocaches.onCreateContextMenu", e);
    }

    if (adapterInfo == null || adapterInfo.position >= adapter.getCount()) {
        return;
    }
    final Geocache cache = adapter.getItem(adapterInfo.position);

    menu.setHeaderTitle(StringUtils.defaultIfBlank(cache.getName(), cache.getGeocode()));

    contextMenuGeocode = cache.getGeocode();

    if (cache.getCoords() != null) {
        menu.add(0, MENU_DEFAULT_NAVIGATION, 0,
                NavigationAppFactory.getDefaultNavigationApplication().getName());
        menu.add(1, MENU_NAVIGATION, 0, res.getString(R.string.cache_menu_navigate))
                .setIcon(R.drawable.ic_menu_mapmode);
        LoggingUI.addMenuItems(this, menu, cache);
        menu.add(0, MENU_CACHE_DETAILS, 0, res.getString(R.string.cache_menu_details));
    }
    if (cache.isOffline()) {
        menu.add(0, MENU_DROP_CACHE, 0, res.getString(R.string.cache_offline_drop));
        menu.add(0, MENU_MOVE_TO_LIST, 0, res.getString(R.string.cache_menu_move_list));
        menu.add(0, MENU_EXPORT, 0, res.getString(R.string.export));
        menu.add(0, MENU_REFRESH, 0, res.getString(R.string.cache_menu_refresh));
    } else {
        menu.add(0, MENU_STORE_CACHE, 0, res.getString(R.string.cache_offline_store));
    }
}

From source file:it.geosolutions.geocollect.android.core.mission.PendingMissionListFragment.java

/**
 * Create the Menu visible on longpress on items
 *//* w ww.  j a va 2s .co m*/
@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {

    // if this item is editable or uploadable, offer the possibility to "reset" the state -> delete its "sop" entry
    if (v.getId() == getListView().getId()) {
        ListView lv = (ListView) v;

        final MissionTemplate template = MissionUtils.getDefaultTemplate(getActivity());
        AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuInfo;
        MissionFeature feature = (MissionFeature) lv.getItemAtPosition(info.position);

        // identify edited/uploadable
        if (feature.editing
                || (feature.typeName != null && feature.typeName.endsWith(MissionTemplate.NEW_NOTICE_SUFFIX))) {
            // create a dialog to let the user clear this surveys data
            String title = getString(R.string.survey);
            if (feature.properties != null && feature.properties.get(template.nameField) != null) {
                title = (String) feature.properties.get(template.nameField);
            }
            if (title != null) {
                menu.setHeaderTitle(title);
            }

            menu.add(0, RESET_MISSION_FEATURE_ID, 0, getString(R.string.menu_clear_survey));

        }
    }
}

From source file:com.oakesville.mythling.MediaActivity.java

@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
    if (v == getListView()) {
        AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuInfo;
        Listable listable = (Listable) getListView().getItemAtPosition(info.position);
        if (listable instanceof Item) {
            Item item = (Item) listable;
            menu.setHeaderTitle(item.getDialogTitle());
            if (isSplitView()) {
                getListView().performItemClick(getListView().getChildAt(info.position), info.position,
                        getListView().getAdapter().getItemId(info.position));
            } else {
                getListView().setItemChecked(info.position, true);
            }/*from www  .j av  a  2s . c  o  m*/
            SparseArray<String> menuItems = getLongClickMenuItems(item);
            for (int i = 0; i < menuItems.size(); i++) {
                int id = menuItems.keyAt(i);
                menu.add(MEDIA_ACTIVITY_CONTEXT_MENU_GROUP_ID, id, id, menuItems.get(id));
            }
        }
    }
}

From source file:cgeo.geocaching.CacheListActivity.java

@Override
public void onCreateContextMenu(final ContextMenu menu, final View view,
        final ContextMenu.ContextMenuInfo info) {
    super.onCreateContextMenu(menu, view, info);

    AdapterContextMenuInfo adapterInfo = null;
    try {//from w  w  w.j a  v  a  2  s. c om
        adapterInfo = (AdapterContextMenuInfo) info;
    } catch (final Exception e) {
        Log.w("CacheListActivity.onCreateContextMenu", e);
    }

    if (adapterInfo == null || adapterInfo.position >= adapter.getCount()) {
        return;
    }
    final Geocache cache = adapter.getItem(adapterInfo.position);

    menu.setHeaderTitle(StringUtils.defaultIfBlank(cache.getName(), cache.getGeocode()));

    contextMenuGeocode = cache.getGeocode();

    getMenuInflater().inflate(R.menu.cache_list_context, menu);

    menu.findItem(R.id.menu_default_navigation)
            .setTitle(NavigationAppFactory.getDefaultNavigationApplication().getName());
    final boolean hasCoords = cache.getCoords() != null;
    menu.findItem(R.id.menu_default_navigation).setVisible(hasCoords);
    menu.findItem(R.id.menu_navigate).setVisible(hasCoords);
    menu.findItem(R.id.menu_cache_details).setVisible(hasCoords);
    final boolean isOffline = cache.isOffline();
    menu.findItem(R.id.menu_drop_cache).setVisible(isOffline);
    menu.findItem(R.id.menu_move_to_list).setVisible(isOffline);
    menu.findItem(R.id.menu_copy_to_list).setVisible(isOffline);
    menu.findItem(R.id.menu_refresh).setVisible(isOffline);
    menu.findItem(R.id.menu_store_cache).setVisible(!isOffline);

    LoggingUI.onPrepareOptionsMenu(menu, cache);
}