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:cm.aptoide.pt.ManageRepos.java

@Override
public void onCreateContextMenu(ContextMenu menu, View view, ContextMenuInfo menuInfo) {
    Log.d("Aptoide-ManageRepos", "oncreateContext view: " + view.toString());
    final int repoHashid = Integer.parseInt(view.findViewById(R.id.repo_hashid).getTag().toString());
    if (!reposInserting.containsKey(repoHashid)) {
        super.onCreateContextMenu(menu, view, menuInfo);

        menu.setHeaderTitle(getString(R.string.options));
        menu.add(0, popupOptions.EDIT_REPO.ordinal(), 0, getString(R.string.edit));
        menu.add(0, popupOptions.REMOVE_REPO.ordinal(), 0, getString(R.string.remove));
    }/*from  ww  w  .ja va  2 s .  c om*/
}

From source file:de.enlightened.peris.CategoriesFragment.java

public final void onCreateContextMenu(final ContextMenu menu, final View v, final ContextMenuInfo menuInfo) {
    final String serverUserId = this.application.getSession().getServer().serverUserId;
    final AdapterContextMenuInfo info = (AdapterContextMenuInfo) menuInfo;

    this.clickedTopicItem = (TopicItem) CategoriesFragment.this.getListView().getItemAtPosition(info.position);

    if (serverUserId == null) {
        return;//  w ww  . j  av  a2  s.  c o m
    }
    super.onCreateContextMenu(menu, v, menuInfo);
    menu.setHeaderTitle(this.clickedTopicItem.getHeading());
    final MenuInflater inflater = this.activity.getMenuInflater();

    inflater.inflate(R.menu.categories_context, menu);

    final MenuItem ubsubItem = menu.findItem(R.id.categories_unsubscribe);
    final MenuItem subItem = menu.findItem(R.id.categories_subscribe);
    final MenuItem stickyItem = menu.findItem(R.id.categories_context_sticky);
    final MenuItem lockItem = menu.findItem(R.id.categories_context_lock);
    final MenuItem deleteItem = menu.findItem(R.id.categories_context_delete);

    final MenuItem subscribeItem = menu.findItem(R.id.categories_add_favorite);
    final MenuItem unsubscribeItem = menu.findItem(R.id.categories_remove_favorite);

    if (this.clickedTopicItem instanceof Category) {
        final Category category = (Category) this.clickedTopicItem;
        ubsubItem.setVisible(false);
        subItem.setVisible(false);
        stickyItem.setVisible(false);
        lockItem.setVisible(false);
        deleteItem.setVisible(false);

        if (category.isCanSubscribe()) {
            subscribeItem.setVisible(true);
        } else {
            subscribeItem.setVisible(false);
        }

        if (category.isSubscribed()) {
            unsubscribeItem.setVisible(true);
            subscribeItem.setVisible(false);
        } else {
            unsubscribeItem.setVisible(false);
        }
    } else {
        final Topic topic = (Topic) this.clickedTopicItem;

        unsubscribeItem.setVisible(false);
        subscribeItem.setVisible(false);

        if (topic.isCanStick()) {
            stickyItem.setVisible(true);

            if (Topic.Type.Sticky == topic.getType()) {
                stickyItem.setTitle("Unstick Topic");
            } else {
                stickyItem.setTitle("Stick Topic");
            }
        } else {
            stickyItem.setVisible(false);
        }

        if (topic.isCanDelete()) {
            deleteItem.setVisible(true);
        } else {
            deleteItem.setVisible(false);
        }

        if (topic.isCanClose()) {
            lockItem.setVisible(true);

            if (topic.isClosed()) {
                lockItem.setTitle("Unlock Topic");
            } else {
                lockItem.setTitle("Lock Topic");
            }
        } else {
            lockItem.setVisible(false);
        }

        if (this.subforumId.contentEquals("favs")) {
            ubsubItem.setVisible(true);
            subItem.setVisible(false);
        } else {
            ubsubItem.setVisible(false);
            subItem.setVisible(true);
        }
    }
}

From source file:br.liveo.ndrawer.ui.fragment.FragmentNotificationsfacebook.java

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

    Log.i("item long click", "click2");

    //        if (v.getId()==R.id.listview) {
    //            AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo)menuInfo;
    //           /// menu.setHeaderTitle(Countries[info.position]);
    //            String[] menuItems ={"item 1", "item 2", "item 3"};
    //                    //getResources().getStringArray(R.array.menu);
    //            for (int i = 0; i<menuItems.length; i++) {
    //                menu.add(Menu.NONE, i, i, menuItems[i]);
    //            }
    //        }//from  ww w  .jav a  2 s .  c o  m

    // super.onCreateContextMenu(menu, v, menuInfo);
    menu.setHeaderTitle(" Delete this post ?");

    //  String[] menuItems ={"Yes", "item 2", "item 3"};
    //getResources().getStringArray(R.array.menu);
    //            for (int i = 0; i<menuItems.length; i++) {
    //     menu.add(Menu.NONE, 0, 0, "Yes");

    // menu.add(0, v.getId(), 0, "Yes");
    //  menu.add(0, v.getId(), 0, "Action 2");

}

From source file:uk.co.droidinactu.ebooklauncher.EBookLauncherActivity.java

private void setupList(final HorizontialListView listview, final SimpleCursorAdapter listAdapter,
        final Cursor cursr) {
    if (cursr == null || cursr != null && cursr.getCount() == 0) {
        Toast.makeText(getApplication(), "No books available", Toast.LENGTH_LONG);
    } else {/* w w  w  . ja v  a  2 s  .  com*/
        listview.setOnCreateContextMenuListener(new View.OnCreateContextMenuListener() {
            @Override
            public void onCreateContextMenu(final ContextMenu conMenu, final View v,
                    final ContextMenuInfo menuInfo) {
                final LinearLayout ll = (LinearLayout) ((HorizontialListView) v)
                        .getChildAt(((AdapterContextMenuInfo) menuInfo).position);
                final Drawable bookCover = ((ImageView) ll.getChildAt(0)).getDrawable();
                final String bookTitle = ((TextView) ll.getChildAt(1)).getText().toString();
                conMenu.setHeaderIcon(bookCover); // set to book cover
                conMenu.setHeaderTitle(bookTitle); // set to book title
                conMenu.add(0, EBookLauncherActivity.CONTEXTMENU_VIEW_DETAILS, 0,
                        R.string.book_grid_context_item_view_book_details);
                conMenu.add(0, EBookLauncherActivity.CONTEXTMENU_OPEN_BOOK, 1,
                        R.string.book_grid_context_item_open_book);
                conMenu.add(0, EBookLauncherActivity.CONTEXTMENU_DELETE_BOOK, 2,
                        R.string.book_grid_context_item_delete_book);
            }
        });
        listview.setOnItemSelectedListener(new OnItemSelectedListener() {
            @Override
            public void onItemSelected(final AdapterView<?> av, final View v, final int pos, final long id) {
                myApp.dataMdl.launchBook(EBookLauncherActivity.this, id);
            }

            @Override
            public void onNothingSelected(final AdapterView<?> arg0) {
            }
        });
        listAdapter.setViewBinder(new SimpleCursorAdapter.ViewBinder() {
            @Override
            public boolean setViewValue(final View view, final Cursor cursor, final int columnIndex) {
                boolean retval = false;
                final int idColIndex = cursor.getColumnIndexOrThrow(BaseColumns._ID);
                final int thumbColIndex = cursor.getColumnIndexOrThrow(DeviceFactory.getCoverImgColumnName());

                if (columnIndex == idColIndex) {
                    try {
                        final ImageView coverImg = (ImageView) view;
                        final String thumbnailFilename = cursor.getString(thumbColIndex);
                        final Bitmap bitmap = myApp.dataMdl.getBookCoverImg(EBookLauncherActivity.this,
                                thumbnailFilename);
                        coverImg.setImageDrawable(new BitmapDrawable(bitmap));
                        retval = true;
                    } catch (final Exception e) {
                        Log.e(EBookLauncherApplication.LOG_TAG, EBookLauncherActivity.LOG_TAG + "Exception ",
                                e);
                    }
                    retval = true;
                }
                return retval;
            }
        });
        listview.setAdapter(listAdapter);
        registerForContextMenu(listview);
        startManagingCursor(cursr);
    }
}

From source file:org.zirco.ui.components.CustomPagerAdapter.java

private CustomWebView initializeWebView(CustomWebView webView) {

    webView.setOnTouchListener(mParentActivity);

    webView.setWebViewClient(new CustomWebViewClient(mParentActivity));
    webView.setWebChromeClient(new CustomWebChromeClient(mParentActivity, webView));

    webView.setOnCreateContextMenuListener(new View.OnCreateContextMenuListener() {
        @Override//w  ww  .java  2  s .  c  o  m
        public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
            HitTestResult result = ((WebView) v).getHitTestResult();

            int resultType = result.getType();
            if ((resultType == HitTestResult.ANCHOR_TYPE) || (resultType == HitTestResult.IMAGE_ANCHOR_TYPE)
                    || (resultType == HitTestResult.SRC_ANCHOR_TYPE)
                    || (resultType == HitTestResult.SRC_IMAGE_ANCHOR_TYPE)) {

                Intent i = new Intent();
                i.putExtra(Constants.EXTRA_ID_URL, result.getExtra());

                MenuItem item = menu.add(0, MainActivity.CONTEXT_MENU_OPEN, 0, R.string.Main_MenuOpen);
                item.setIntent(i);

                item = menu.add(0, MainActivity.CONTEXT_MENU_OPEN_IN_NEW_TAB, 0, R.string.Main_MenuOpenNewTab);
                item.setIntent(i);

                item = menu.add(0, MainActivity.CONTEXT_MENU_COPY, 0, R.string.Main_MenuCopyLinkUrl);
                item.setIntent(i);

                item = menu.add(0, MainActivity.CONTEXT_MENU_DOWNLOAD, 0, R.string.Main_MenuDownload);
                item.setIntent(i);

                item = menu.add(0, MainActivity.CONTEXT_MENU_SHARE, 0, R.string.Main_MenuShareLinkUrl);
                item.setIntent(i);

                menu.setHeaderTitle(result.getExtra());
            } else if (resultType == HitTestResult.IMAGE_TYPE) {
                Intent i = new Intent();
                i.putExtra(Constants.EXTRA_ID_URL, result.getExtra());

                MenuItem item = menu.add(0, MainActivity.CONTEXT_MENU_OPEN, 0, R.string.Main_MenuViewImage);
                item.setIntent(i);

                item = menu.add(0, MainActivity.CONTEXT_MENU_COPY, 0, R.string.Main_MenuCopyImageUrl);
                item.setIntent(i);

                item = menu.add(0, MainActivity.CONTEXT_MENU_DOWNLOAD, 0, R.string.Main_MenuDownloadImage);
                item.setIntent(i);

                item = menu.add(0, MainActivity.CONTEXT_MENU_SHARE, 0, R.string.Main_MenuShareImageUrl);
                item.setIntent(i);

                menu.setHeaderTitle(result.getExtra());

            } else if (resultType == HitTestResult.EMAIL_TYPE) {

                Intent sendMail = new Intent(Intent.ACTION_VIEW,
                        Uri.parse(WebView.SCHEME_MAILTO + result.getExtra()));

                MenuItem item = menu.add(0, MainActivity.CONTEXT_MENU_SEND_MAIL, 0,
                        R.string.Main_MenuSendEmail);
                item.setIntent(sendMail);

                Intent i = new Intent();
                i.putExtra(Constants.EXTRA_ID_URL, result.getExtra());

                item = menu.add(0, MainActivity.CONTEXT_MENU_COPY, 0, R.string.Main_MenuCopyEmailUrl);
                item.setIntent(i);

                item = menu.add(0, MainActivity.CONTEXT_MENU_SHARE, 0, R.string.Main_MenuShareEmailUrl);
                item.setIntent(i);

                menu.setHeaderTitle(result.getExtra());
            }
        }
    });

    webView.setDownloadListener(new DownloadListener() {

        @Override
        public void onDownloadStart(String url, String userAgent, String contentDisposition, String mimetype,
                long contentLength) {
            mParentActivity.doDownloadStart(url, userAgent, contentDisposition, mimetype, contentLength);
        }

    });

    return webView;
}

From source file:com.money.manager.ex.fragment.AllDataFragment.java

@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
    // take info and cursor from listview adapter
    AdapterContextMenuInfo info = (AdapterContextMenuInfo) menuInfo;
    Cursor cursor = (Cursor) getListAdapter().getItem(info.position);
    // check if cursor is valid
    if (cursor == null)
        return;//w  w w .  j  a va  2 s.c o m
    /* getActivity().getMenuInflater().inflate(R.menu.contextmenu_accountfragment, menu);
    // add manually
    int[] menuItem = new int[] { R.id.menu_edit, R.id.menu_delete, R.id.menu_reconciled, R.id.menu_none, R.id.menu_follow_up, R.id.menu_duplicate,
    R.id.menu_void };
    int[] menuText = new int[] { R.string.edit, R.string.delete, R.string.status_reconciled, R.string.status_none, R.string.status_follow_up,
    R.string.status_duplicate, R.string.status_void };
    for (int i = 0; i < menuItem.length; i++) {
       menu.add(getContextMenuGroupId(), menuItem[i], i, menuText[i]);
    } */
    // create a context menu
    getSherlockActivity().getMenuInflater().inflate(R.menu.menu_all_data_adapter, menu);
    menu.setHeaderTitle(cursor.getString(cursor.getColumnIndex(QueryAllData.AccountName)));
    // hide current status
    if (menu.findItem(R.id.menu_reconciled) != null)
        menu.findItem(R.id.menu_reconciled).setVisible(!Constants.TRANSACTION_STATUS_RECONCILED
                .equalsIgnoreCase(cursor.getString(cursor.getColumnIndex(QueryAllData.Status))));
    if (menu.findItem(R.id.menu_none) != null)
        menu.findItem(R.id.menu_none).setVisible(!Constants.TRANSACTION_STATUS_UNRECONCILED
                .equalsIgnoreCase(cursor.getString(cursor.getColumnIndex(QueryAllData.Status))));
    if (menu.findItem(R.id.menu_duplicate) != null)
        menu.findItem(R.id.menu_duplicate).setVisible(!Constants.TRANSACTION_STATUS_DUPLICATE
                .equalsIgnoreCase(cursor.getString(cursor.getColumnIndex(QueryAllData.Status))));
    if (menu.findItem(R.id.menu_follow_up) != null)
        menu.findItem(R.id.menu_follow_up).setVisible(!Constants.TRANSACTION_STATUS_FOLLOWUP
                .equalsIgnoreCase(cursor.getString(cursor.getColumnIndex(QueryAllData.Status))));
    if (menu.findItem(R.id.menu_void) != null)
        menu.findItem(R.id.menu_void).setVisible(!Constants.TRANSACTION_STATUS_VOID
                .equalsIgnoreCase(cursor.getString(cursor.getColumnIndex(QueryAllData.Status))));

}

From source file:org.yammp.app.ArtistFragment.java

@Override
public void onCreateContextMenu(ContextMenu menu, View view, ContextMenuInfo info) {

    ExpandableListContextMenuInfo mi = (ExpandableListContextMenuInfo) info;

    int itemtype = ExpandableListView.getPackedPositionType(mi.packedPosition);
    mSelectedGroupPosition = ExpandableListView.getPackedPositionGroup(mi.packedPosition);
    int gpos = mSelectedGroupPosition;
    mSelectedGroupId = mGroupCursor.getLong(mGroupArtistIdIdx);
    if (itemtype == ExpandableListView.PACKED_POSITION_TYPE_GROUP) {
        mGroupSelected = true;/*from  w ww .  ja  v  a  2 s. c  o  m*/
        mChildSelected = false;
        getSherlockActivity().getMenuInflater().inflate(R.menu.music_browser_item, menu);
        if (gpos == -1) {
            // this shouldn't happen
            Log.d("Artist/Album", "no group");
            return;
        }
        gpos = gpos - mListView.getHeaderViewsCount();
        mGroupCursor.moveToPosition(gpos);
        mCurrentGroupArtistName = mGroupCursor.getString(mGroupArtistIdx);
        if (mCurrentGroupArtistName == null || MediaStore.UNKNOWN_STRING.equals(mCurrentGroupArtistName)) {
            menu.setHeaderTitle(getString(R.string.unknown_artist));
            menu.findItem(R.id.search).setEnabled(false);
            menu.findItem(R.id.search).setVisible(false);
        } else {
            menu.setHeaderTitle(mCurrentGroupArtistName);
        }
    }
}

From source file:org.smap.smapTask.android.activities.MainMapsActivity.java

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

    if (currentPlace != null) {
        int taskId = currentPlace.getId(); // Use currentPlace to get task Id
        Cursor c = null;/*from  www .j a  v  a2s  .co m*/
        fda = new FileDbAdapter();
        try {
            fda.open();
            c = fda.fetchTaskForId((long) taskId);
            String taskStatus = c.getString(c.getColumnIndex(FileDbAdapter.KEY_T_STATUS));
            String taskTitle = c.getString(c.getColumnIndex(FileDbAdapter.KEY_T_TITLE));
            menu.setHeaderTitle(taskTitle);
            if (fda.canReject(taskStatus)) {
                menu.add(0, R.id.reject, 0, R.string.smap_reject_task);
            }
            if (fda.canComplete(c.getString(c.getColumnIndex(FileDbAdapter.KEY_T_STATUS)))) {
                menu.add(0, R.id.complete_task, 0, R.string.smap_complete_task);
            }
            if (fda.canAccept(taskStatus)) {
                menu.add(0, R.id.accept_task, 0, R.string.smap_accept_task);
            }
            menu.add(0, R.id.cancel_task, 0, R.string.cancel);
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            if (fda != null) {
                fda.close();
            }
            if (c != null) {
                c.close();
            }
        }
    } else {

    }
}

From source file:com.binoy.vibhinna.VibhinnaFragment.java

@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) {
    super.onCreateContextMenu(menu, v, menuInfo);
    AdapterView.AdapterContextMenuInfo info;
    PropManager propmanager = new PropManager(getActivity().getApplicationContext());
    try {//from   www  . jav a  2s .  co  m
        // Casts the incoming data object into the type for AdapterView
        // objects.
        info = (AdapterView.AdapterContextMenuInfo) menuInfo;
    } catch (ClassCastException e) {
        // If the menu object can't be cast, logs an error.
        Log.w("Exception", "exception in getting menuinfo");
        return;
    }
    Cursor cursor = (Cursor) getListAdapter().getItem(info.position);
    String s1 = Constants.SD_PATH + propmanager.mbActivePath();
    String s2 = cursor.getString(7);
    if (cursor.equals(null) || s1.equals(s2))
        return;
    if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.HONEYCOMB) {
        LayoutInflater headerInflater = (LayoutInflater) getSherlockActivity()
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        ViewGroup header = (ViewGroup) headerInflater.inflate(R.layout.context_menu_header, null);
        TextView title = (TextView) header.findViewById(R.id.context_menu_title);
        title.setText(cursor.getString(1));
        menu.setHeaderView(header);
    } else
        menu.setHeaderTitle(cursor.getString(1));
    android.view.MenuInflater inflater = getActivity().getMenuInflater();
    inflater.inflate(R.menu.context_menu, menu);
}

From source file:org.mozilla.gecko.home.TopSitesPanel.java

@Override
public void onCreateContextMenu(ContextMenu menu, View view, ContextMenuInfo menuInfo) {
    if (menuInfo == null) {
        return;/*  www.  j  a  va2  s.  c o m*/
    }

    if (!(menuInfo instanceof TopSitesGridContextMenuInfo)) {
        // Long pressed item was not a Top Sites GridView item. Superclass
        // can handle this.
        super.onCreateContextMenu(menu, view, menuInfo);
        return;
    }

    // Long pressed item was a Top Sites GridView item, handle it.
    MenuInflater inflater = new MenuInflater(view.getContext());
    inflater.inflate(R.menu.home_contextmenu, menu);

    // Hide unused menu items.
    menu.findItem(R.id.home_edit_bookmark).setVisible(false);

    TopSitesGridContextMenuInfo info = (TopSitesGridContextMenuInfo) menuInfo;
    menu.setHeaderTitle(info.getDisplayTitle());

    if (info.type != TopSites.TYPE_BLANK) {
        if (info.type == TopSites.TYPE_PINNED) {
            menu.findItem(R.id.top_sites_pin).setVisible(false);
        } else {
            menu.findItem(R.id.top_sites_unpin).setVisible(false);
        }
    } else {
        menu.findItem(R.id.home_open_new_tab).setVisible(false);
        menu.findItem(R.id.home_open_private_tab).setVisible(false);
        menu.findItem(R.id.top_sites_pin).setVisible(false);
        menu.findItem(R.id.top_sites_unpin).setVisible(false);
    }

    if (!StringUtils.isShareableUrl(info.url) || GeckoProfile.get(getActivity()).inGuestMode()) {
        menu.findItem(R.id.home_share).setVisible(false);
    }

    if (!RestrictedProfiles.isAllowed(view.getContext(), Restriction.DISALLOW_PRIVATE_BROWSING)) {
        menu.findItem(R.id.home_open_private_tab).setVisible(false);
    }
}