Example usage for android.view Menu CATEGORY_ALTERNATIVE

List of usage examples for android.view Menu CATEGORY_ALTERNATIVE

Introduction

In this page you can find the example usage for android.view Menu CATEGORY_ALTERNATIVE.

Prototype

int CATEGORY_ALTERNATIVE

To view the source code for android.view Menu CATEGORY_ALTERNATIVE.

Click Source Link

Document

Category code for the order integer for items/groups that are alternative actions on the data that is currently displayed -- or/add this with your base value.

Usage

From source file:net.dahanne.spring.android.ch3.restful.example.recipeapp.RecipesList.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate menu from XML resource
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.list_options_menu, menu);

    Intent intent = new Intent(null, getIntent().getData());
    intent.addCategory(Intent.CATEGORY_ALTERNATIVE);
    menu.addIntentOptions(Menu.CATEGORY_ALTERNATIVE, 0, 0, new ComponentName(this, RecipesList.class), null,
            intent, 0, null);/*  w  ww .  j a  v a2  s.  c om*/

    return super.onCreateOptionsMenu(menu);
}

From source file:com.example.android.notepad.NotesList.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    super.onCreateOptionsMenu(menu);

    // This is our one standard application action -- inserting a
    // new note into the list.
    menu.add(0, MENU_ITEM_INSERT, 0, R.string.menu_insert).setShortcut('3', 'a')
            .setIcon(android.R.drawable.ic_menu_add);

    // ilya: add refresh
    menu.add(0, MENU_ITEM_REFRESH, 0, "Refresh").setShortcut('4', 'r').setIcon(android.R.drawable.ic_menu_view);

    // Generate any additional actions that can be performed on the
    // overall list.  In a normal install, there are no additional
    // actions found here, but this allows other applications to extend
    // our menu with their own actions.
    Intent intent = new Intent(null, getIntent().getData());
    intent.addCategory(Intent.CATEGORY_ALTERNATIVE);
    menu.addIntentOptions(Menu.CATEGORY_ALTERNATIVE, 0, 0, new ComponentName(this, NotesList.class), null,
            intent, 0, null);/*from   ww w .java  2s. co m*/

    return true;
}

From source file:net.dahanne.spring.android.ch3.restful.example.recipeapp.RecipesList.java

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

    // The data from the menu item.
    AdapterView.AdapterContextMenuInfo info;

    // Tries to get the position of the item in the ListView that was long-pressed.
    try {/*from w  w w.j  a va2  s  . c o  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.e(TAG, "bad menuInfo", e);
        return;
    }
    Intent intent = new Intent(null,
            Uri.withAppendedPath(getIntent().getData(), Integer.toString((int) info.id)));
    intent.addCategory(Intent.CATEGORY_ALTERNATIVE);
    menu.addIntentOptions(Menu.CATEGORY_ALTERNATIVE, 0, 0, new ComponentName(this, RecipesList.class), null,
            intent, 0, null);
}

From source file:org.openintents.filemanager.FileManagerActivity.java

@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    // Generate any additional actions that can be performed on the
    // overall list. This allows other applications to extend
    // our menu with their own actions.
    Intent intent = new Intent(null, getIntent().getData());
    intent.addCategory(Intent.CATEGORY_ALTERNATIVE);
    // menu.addIntentOptions(Menu.CATEGORY_ALTERNATIVE, 0, 0,
    // new ComponentName(this, NoteEditor.class), null, intent, 0, null);

    // Workaround to add icons:
    MenuIntentOptionsWithIcons menu2 = new MenuIntentOptionsWithIcons(this, menu);
    menu2.addIntentOptions(Menu.CATEGORY_ALTERNATIVE, 0, 0, new ComponentName(this, FileManagerActivity.class),
            null, intent, 0, null);/*from   w  w  w  .  jav  a 2  s.c o  m*/

    return true;
}

From source file:com.example.android.notepad.NotesList.java

@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    super.onPrepareOptionsMenu(menu);
    //final boolean haveItems = getListAdapter().getCount() > 0;
    boolean haveItems = true;

    // If there are any notes in the list (which implies that one of
    // them is selected), then we need to generate the actions that
    // can be performed on the current selection.  This will be a combination
    // of our own specific actions along with any extensions that can be
    // found./*from   ww w  . j a v a  2  s. c  o  m*/
    if (haveItems) {
        // This is the selected item.
        Uri uri = ContentUris.withAppendedId(getIntent().getData(), getSelectedItemId());

        // Build menu...  always starts with the EDIT action...
        Intent[] specifics = new Intent[1];
        specifics[0] = new Intent(Intent.ACTION_EDIT, uri);
        MenuItem[] items = new MenuItem[1];

        // ... is followed by whatever other actions are available...
        Intent intent = new Intent(null, uri);
        intent.addCategory(Intent.CATEGORY_ALTERNATIVE);
        menu.addIntentOptions(Menu.CATEGORY_ALTERNATIVE, 0, 0, null, specifics, intent, 0, items);

        // Give a shortcut to the edit action.
        if (items[0] != null) {
            items[0].setShortcut('1', 'e');
        }
    } else {
        menu.removeGroup(Menu.CATEGORY_ALTERNATIVE);
    }

    return true;
}

From source file:bander.notepad.NoteListAppCompat.java

@Override
public void onCreateContextMenu(ContextMenu menu, View view, ContextMenuInfo menuInfo) {
    AdapterView.AdapterContextMenuInfo info;
    try {/*from   w w w.ja  v a  2 s  . co  m*/
        info = (AdapterView.AdapterContextMenuInfo) menuInfo;
    } catch (ClassCastException e) {
        return;
    }

    Cursor cursor = (Cursor) getListAdapter().getItem(info.position);
    if (cursor == null) {
        return;
    }

    menu.setHeaderTitle(cursor.getString(COLUMN_INDEX_TITLE));

    Uri uri = ContentUris.withAppendedId(getIntent().getData(), cursor.getInt(COLUMN_INDEX_ID));

    Intent[] specifics = new Intent[1];
    specifics[0] = new Intent(Intent.ACTION_EDIT, uri);
    MenuItem[] items = new MenuItem[1];

    Intent intent = new Intent(null, uri);
    intent.addCategory(Intent.CATEGORY_ALTERNATIVE);
    menu.addIntentOptions(Menu.CATEGORY_ALTERNATIVE, 0, 0, null, specifics, intent, 0, items);

    menu.add(0, DELETE_ID, 0, R.string.menu_delete);
    // TODO: When you click on this, it crashes. I commented it out for now.
    // menu.add(0, SEND_ID, 0, R.string.menu_send);
}

From source file:net.lp.actionbarpoirot.actions.UiActionManager.java

/**
 * For onCreateOptionsMenu, generate the category-alternative intent-based items.
 * /*w  ww . ja  va2 s.c  o  m*/
 * @param menu
 * @param context
 * @param uri
 * @param component
 * @param extraCategories
 */
public void onCreateAlternativeOptionsMenu(Menu menu, C context, Uri uri, Class<? extends C> component,
        List<String> extraCategories) {
    // Generate any additional actions that can be performed on the
    // overall list. In a normal install, there are no additional
    // actions found here, but this allows other applications to extend
    // our menu with their own actions.
    Intent intent = new Intent(null, uri);
    intent.addCategory(Intent.CATEGORY_ALTERNATIVE);
    if (extraCategories != null) {
        for (String extraCategory : extraCategories) {
            intent.addCategory(extraCategory);
        }
    }
    menu.addIntentOptions(Menu.CATEGORY_ALTERNATIVE, 0, UiAction.ORDER_SIXTH_OR_ALTERNATIVE,
            new ComponentName(context, component), null, intent, 0, null);
}

From source file:com.kyakujin.android.autoeco.ui.MainActivity.java

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

    AdapterView.AdapterContextMenuInfo info;
    try {//from  w w  w . j  a va2  s . co  m
        info = (AdapterView.AdapterContextMenuInfo) menuInfo;
    } catch (ClassCastException e) {
        Log.e(TAG, "bad AdapterContextMenuInfo", e);
        return;
    }

    android.view.MenuInflater inflater = this.getMenuInflater();
    inflater.inflate(R.menu.context_menu_schedlist, menu);

    menu.setHeaderTitle(getResources().getString(R.string.label_menu));

    Intent intent = new Intent(null, ContentUris.withAppendedId(SchedTbl.CONTENT_URI, (int) info.id));
    intent.addCategory(Intent.CATEGORY_ALTERNATIVE);

    menu.addIntentOptions(Menu.CATEGORY_ALTERNATIVE, 0, 0, new ComponentName(mActivity, MainActivity.class),
            null, intent, 0, null);
}

From source file:org.openintents.notepad.NoteEditor.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    super.onCreateOptionsMenu(menu);

    // Build the menus that are shown when editing.

    menu.add(5, MENU_SEARCH, 0, R.string.menu_search).setShortcut('3', 'f')
            .setIcon(android.R.drawable.ic_menu_search);

    // if (!mOriginalContent.equals(mText.getText().toString())) {

    menu.add(0, MENU_REVERT, 0, R.string.menu_revert).setShortcut('0', 'r')
            .setIcon(android.R.drawable.ic_menu_revert);

    menu.add(1, MENU_ENCRYPT, 0, R.string.menu_encrypt).setShortcut('1', 'e')
            .setIcon(android.R.drawable.ic_lock_lock); // TODO:
    // better/* w  ww  .  ja v a2  s  .  c o  m*/
    // icon

    menu.add(1, MENU_UNENCRYPT, 0, R.string.menu_undo_encryption).setShortcut('1', 'e')
            .setIcon(android.R.drawable.ic_lock_lock); // TODO:
    // better
    // icon

    MenuItem item = menu.add(1, MENU_DELETE, 0, R.string.menu_delete);
    item.setIcon(android.R.drawable.ic_menu_delete);

    menu.add(2, MENU_IMPORT, 0, R.string.menu_import).setShortcut('1', 'i')
            .setIcon(android.R.drawable.ic_menu_add);

    menu.add(2, MENU_SAVE, 0, R.string.menu_save).setShortcut('2', 's')
            .setIcon(android.R.drawable.ic_menu_save);

    menu.add(2, MENU_SAVE_AS, 0, R.string.menu_save_as).setShortcut('3', 'w')
            .setIcon(android.R.drawable.ic_menu_save);

    menu.add(3, MENU_THEME, 0, R.string.menu_theme).setIcon(android.R.drawable.ic_menu_manage).setShortcut('4',
            't');

    menu.add(3, MENU_SETTINGS, 0, R.string.settings).setIcon(android.R.drawable.ic_menu_preferences)
            .setShortcut('9', 'p');

    item = menu.add(4, MENU_SEND, 0, R.string.menu_share);
    item.setIcon(android.R.drawable.ic_menu_share);
    if (mActionBarAvailable) {
        WrapActionBar.showIfRoom(item);
    }

    menu.add(5, MENU_WORD_COUNT, 0, R.string.menu_word_count);

    /*
       * if (mState == STATE_EDIT) {
     *
     * menu.add(0, REVERT_ID, 0, R.string.menu_revert) .setShortcut('0',
     * 'r') .setIcon(android.R.drawable.ic_menu_revert);
     *
     * if (!mNoteOnly) { menu.add(1, DELETE_ID, 0, R.string.menu_delete)
     * .setShortcut('1', 'd') .setIcon(android.R.drawable.ic_menu_delete); }
     *
     * // Build the menus that are shown when inserting. } else {
     * menu.add(1, DISCARD_ID, 0, R.string.menu_discard) .setShortcut('0',
     * 'd') .setIcon(android.R.drawable.ic_menu_delete); }
     */

    // If we are working on a full note, then append to the
    // menu items for any other activities that can do stuff with it
    // as well. This does a query on the system for any activities that
    // implement the ALTERNATIVE_ACTION for our data, adding a menu item
    // for each one that is found.
    if (!mNoteOnly) {
        // We use mUri instead of getIntent().getData() in the
        // following line, because mUri may have changed when inserting
        // a new note.
        Intent intent = new Intent(null, mUri);
        intent.addCategory(Intent.CATEGORY_ALTERNATIVE);
        // menu.addIntentOptions(Menu.CATEGORY_ALTERNATIVE, 0, 0,
        // new ComponentName(this, NoteEditor.class), null, intent, 0,
        // null);

        // Workaround to add icons:
        MenuIntentOptionsWithIcons menu2 = new MenuIntentOptionsWithIcons(this, menu);
        menu2.addIntentOptions(Menu.CATEGORY_ALTERNATIVE, 0, 0, new ComponentName(this, NoteEditor.class), null,
                intent, 0, null);

        // Add menu items for category CATEGORY_TEXT_SELECTION_ALTERNATIVE
        intent = new Intent(); // Don't pass data for this intent
        intent.addCategory(NotepadIntents.CATEGORY_TEXT_SELECTION_ALTERNATIVE);
        intent.setType("text/plain");
        // Workaround to add icons:
        menu2.addIntentOptions(GROUP_ID_TEXT_SELECTION_ALTERNATIVE, 0, 0,
                new ComponentName(this, NoteEditor.class), null, intent, 0, null);

    }

    return true;
}

From source file:org.openintents.notepad.NoteEditor.java

@Override
public boolean onPrepareOptionsMenu(Menu menu) {

    // Show "revert" menu item only if content has changed and we have a cursor (see revertNote())

    // contentChanged used for revert and save menu
    boolean contentChanged = !mOriginalContent.equals(mText.getText().toString());

    boolean isNoteUnencrypted = isNoteUnencrypted();

    // Show comands on the URI only if the note is not encrypted
    menu.setGroupVisible(Menu.CATEGORY_ALTERNATIVE, isNoteUnencrypted);

    if (mState == STATE_EDIT_NOTE_FROM_SDCARD) {
        // Menus for editing from SD card
        menu.setGroupVisible(0, false);//from w w w. j a  v a  2s.  c o  m
        menu.setGroupVisible(1, false);
        menu.setGroupVisible(2, true);

        menu.findItem(MENU_SAVE).setEnabled(contentChanged);

    } else if (mState == STATE_EDIT_EXTERNAL_NOTE) {
        // Menus for external notes, e.g. from OI Shopping List.
        // In this case, don't show encryption/decryption.
        menu.setGroupVisible(0, contentChanged || mUndoRevert != null);
        menu.setGroupVisible(1, true);
        menu.setGroupVisible(2, false);

        menu.findItem(MENU_ENCRYPT).setVisible(false);
        menu.findItem(MENU_UNENCRYPT).setVisible(false);
    } else {
        // Menus for internal notes
        menu.setGroupVisible(0, contentChanged || mUndoRevert != null);
        menu.setGroupVisible(1, true);
        menu.setGroupVisible(2, false);

        menu.findItem(MENU_ENCRYPT).setVisible(isNoteUnencrypted);
        menu.findItem(MENU_UNENCRYPT).setVisible(!isNoteUnencrypted);
    }

    return super.onPrepareOptionsMenu(menu);
}