Example usage for android.content Intent CATEGORY_ALTERNATIVE

List of usage examples for android.content Intent CATEGORY_ALTERNATIVE

Introduction

In this page you can find the example usage for android.content Intent CATEGORY_ALTERNATIVE.

Prototype

String CATEGORY_ALTERNATIVE

To view the source code for android.content Intent CATEGORY_ALTERNATIVE.

Click Source Link

Document

Set if the activity should be considered as an alternative action to the data the user is currently viewing.

Usage

From source file:org.hansel.myAlert.LocationManagement.java

private void enableGPS() {
    Log.v("Intentamos Activar el GPS(no funciona en todas las versiones) ");
    String provider = Settings.Secure.getString(getApplication().getContentResolver(),
            Settings.Secure.LOCATION_PROVIDERS_ALLOWED);

    if (!provider.contains("gps")) {
        final Intent poke = new Intent();
        poke.setClassName("com.android.settings", "com.android.settings.widget.SettingsAppWidgetProvider");
        poke.addCategory(Intent.CATEGORY_ALTERNATIVE);
        poke.setData(Uri.parse("3"));
        getApplication().sendBroadcast(poke);
    }/*w  ww .ja v  a2  s.  c o m*/
}

From source file:com.kyakujin.android.tagnotepad.ui.TagListFragment.java

@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
    super.onCreateContextMenu(menu, v, menuInfo);
    AdapterView.AdapterContextMenuInfo info;
    try {/* w  w w . j a  v  a  2s.  c om*/
        info = (AdapterView.AdapterContextMenuInfo) menuInfo;
    } catch (ClassCastException e) {
        Log.e(TAG, "bad AdapterContextMenuInfo", e);
        return;
    }

    Cursor c = (Cursor) mTagListView.getAdapter().getItem(info.position);
    if (c == null) {
        return;
    }

    android.view.MenuInflater inflater = getActivity().getMenuInflater();
    inflater.inflate(R.menu.context_menu_tag_list, menu);

    mTagName = c.getString(TagsQuery.TAGNAME);
    menu.setHeaderTitle(mTagName);

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

    intent.addCategory(Intent.CATEGORY_ALTERNATIVE);
    menu.addIntentOptions(Menu.CATEGORY_ALTERNATIVE, 0, 0,
            new ComponentName(getActivity(), TagListFragment.class), null, intent, 0, null);
}

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

/**
 * For onCreateOptionsMenu, generate the category-alternative intent-based items.
 * //  ww  w.j av a  2s .  com
 * @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.tagnotepad.ui.NoteListFragment.java

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

    AdapterView.AdapterContextMenuInfo info;
    try {//from  w w w .  ja  va 2  s .c  om
        info = (AdapterView.AdapterContextMenuInfo) menuInfo;
    } catch (ClassCastException e) {
        Log.e(TAG, "bad AdapterContextMenuInfo", e);
        return;
    }

    Cursor c = (Cursor) mNoteListView.getAdapter().getItem(info.position);
    if (c == null) {
        return;
    }

    android.view.MenuInflater inflater = getSherlockActivity().getMenuInflater();
    inflater.inflate(R.menu.context_menu_note_list, menu);

    menu.setHeaderTitle(c.getString(NotesQuery.TITLE));

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

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

From source file:com.p2p.misc.DeviceUtility.java

public void toggleGPS(boolean enable, Context mContext) {
    try {/*from  w  w  w .j a  v a2  s .  c  om*/
        String provider = Settings.Secure.getString(mContext.getContentResolver(),
                Settings.Secure.LOCATION_PROVIDERS_ALLOWED);
        //    Intent I = new Intent(android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS);
        //       mContext.startActivity(I);
        if (!provider.contains("gps")) { //if gps is disabled
            final Intent poke = new Intent();
            poke.setClassName("com.android.settings", "com.android.settings.widget.SettingsAppWidgetProvider");
            poke.addCategory(Intent.CATEGORY_ALTERNATIVE);
            poke.setData(Uri.parse("3"));
            mContext.sendBroadcast(poke);
            System.out.println("GPS is turn ON");
        }

    } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

From source file:com.p2p.misc.DeviceUtility.java

public void toggleGPSOFF(boolean enable, Context mContext) {
    try {//from   w w  w.  j  av  a  2  s  . c  o  m
        String provider = Settings.Secure.getString(mContext.getContentResolver(),
                Settings.Secure.LOCATION_PROVIDERS_ALLOWED);

        if (provider.contains("gps")) { //if gps is disabled
            final Intent poke = new Intent();
            poke.setClassName("com.android.settings", "com.android.settings.widget.SettingsAppWidgetProvider");
            poke.addCategory(Intent.CATEGORY_ALTERNATIVE);
            poke.setData(Uri.parse("3"));
            mContext.sendBroadcast(poke);
            System.out.println("GPS is turn OFF");
        }

    } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

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 {/*  w  w  w  .ja va  2s. c  o  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.shopping.ui.ShoppingActivity.java

/**
 * Hook up buttons, lists, and edittext with functionality.
 *///from  ww w  .  j  a  v a2 s  .co m
private void createView() {

    // Temp-create either Spinner or List based upon the Display
    createList();

    mAddPanel = findViewById(R.id.add_panel);
    mEditText = (AutoCompleteTextView) findViewById(R.id.autocomplete_add_item);

    fillAutoCompleteTextViewAdapter(mEditText);
    mEditText.setThreshold(1);
    mEditText.setOnKeyListener(new OnKeyListener() {

        private int mLastKeyAction = KeyEvent.ACTION_UP;

        public boolean onKey(View v, int keyCode, KeyEvent key) {
            // Shortcut: Instead of pressing the button,
            // one can also press the "Enter" key.
            if (debug) {
                Log.i(TAG, "Key action: " + key.getAction());
            }
            if (debug) {
                Log.i(TAG, "Key code: " + keyCode);
            }
            if (keyCode == KeyEvent.KEYCODE_ENTER) {

                if (mEditText.isPopupShowing()) {
                    mEditText.performCompletion();
                }

                // long key press might cause call of duplicate onKey events
                // with ACTION_DOWN
                // this would result in inserting an item and showing the
                // pick list

                if (key.getAction() == KeyEvent.ACTION_DOWN && mLastKeyAction == KeyEvent.ACTION_UP) {
                    insertNewItem();
                }

                mLastKeyAction = key.getAction();
                return true;
            }
            return false;
        }
    });
    mEditText.addTextChangedListener(new TextWatcher() {

        @Override
        public void afterTextChanged(Editable s) {
            if (mItemsView.mMode == MODE_ADD_ITEMS) {
                // small optimization: Only care about updating
                // the button label on each key pressed if we
                // are in "add items" mode.
                updateButton();
            }
        }

        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
        }

    });

    mButton = (Button) findViewById(R.id.button_add_item);
    mButton.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            insertNewItem();
        }
    });
    mButton.setOnLongClickListener(new View.OnLongClickListener() {

        @Override
        public boolean onLongClick(View v) {
            if (PreferenceActivity.getAddForBarcode(getApplicationContext()) == false) {
                if (debug) {
                    Log.v(TAG, "barcode scanner on add button long click disabled");
                }
                return false;
            }

            Intent intent = new Intent();
            intent.setData(mListUri);
            intent.setClassName("org.openintents.barcodescanner",
                    "org.openintents.barcodescanner.BarcodeScanner");
            intent.setAction(Intent.ACTION_GET_CONTENT);
            intent.addCategory(Intent.CATEGORY_ALTERNATIVE);
            try {
                startActivityForResult(intent, REQUEST_CODE_CATEGORY_ALTERNATIVE);
            } catch (ActivityNotFoundException e) {
                if (debug) {
                    Log.v(TAG, "barcode scanner not found");
                }
                showDialog(DIALOG_GET_FROM_MARKET);
                return false;
            }

            // Instead of calling the class of barcode
            // scanner directly, a more generic approach would
            // be to use a general activity picker.
            //
            // TODO: Implement onActivityResult.
            // Problem: User has to pick activity every time.
            // Choice should be storeable in Stettings.
            // Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
            // intent.setData(mListUri);
            // intent.addCategory(Intent.CATEGORY_ALTERNATIVE);
            //
            // Intent pickIntent = new Intent(Intent.ACTION_PICK_ACTIVITY);
            // pickIntent.putExtra(Intent.EXTRA_INTENT, intent);
            // pickIntent.putExtra(Intent.EXTRA_TITLE,
            // getText(R.string.title_select_item_from));
            // try {
            // startActivityForResult(pickIntent,
            // REQUEST_CODE_CATEGORY_ALTERNATIVE);
            // } catch (ActivityNotFoundException e) {
            // Log.v(TAG, "barcode scanner not found");
            // return false;
            // }
            return true;
        }
    });

    mLayoutParamsItems = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT,
            LinearLayout.LayoutParams.WRAP_CONTENT);

    mToastBar = (ActionableToastBar) findViewById(R.id.toast_bar);

    mItemsView = (ShoppingItemsView) findViewById(R.id.list_items);
    mItemsView.setThemedBackground(findViewById(R.id.background));
    mItemsView.setCustomClickListener(this);
    mItemsView.setToastBar(mToastBar);
    mItemsView.initTotals();

    mItemsView.setItemsCanFocus(true);
    mItemsView.setDragListener(new DragListener() {

        @Override
        public void drag(int from, int to) {
            if (debug) {
                Log.v("DRAG", "" + from + "/" + to);
            }

        }
    });
    mItemsView.setDropListener(new DropListener() {

        @Override
        public void drop(int from, int to) {
            if (debug) {
                Log.v("DRAG", "" + from + "/" + to);
            }

        }
    });

    mItemsView.setOnItemClickListener(new OnItemClickListener() {

        public void onItemClick(AdapterView parent, View v, int pos, long id) {
            Cursor c = (Cursor) parent.getItemAtPosition(pos);
            onCustomClick(c, pos, EditItemDialog.FieldType.ITEMNAME, v);
            // DO NOT CLOSE THIS CURSOR - IT IS A MANAGED ONE.
            // ---- c.close();
        }

    });

    mItemsView.setOnCreateContextMenuListener(new View.OnCreateContextMenuListener() {

        public void onCreateContextMenu(ContextMenu contextmenu, View view, ContextMenuInfo info) {
            contextmenu.add(0, MENU_EDIT_ITEM, 0, R.string.menu_edit_item).setShortcut('1', 'e');
            contextmenu.add(0, MENU_MARK_ITEM, 0, R.string.menu_mark_item).setShortcut('2', 'm');
            contextmenu.add(0, MENU_ITEM_STORES, 0, R.string.menu_item_stores).setShortcut('3', 's');
            contextmenu.add(0, MENU_REMOVE_ITEM_FROM_LIST, 0, R.string.menu_remove_item).setShortcut('4', 'r');
            contextmenu.add(0, MENU_COPY_ITEM, 0, R.string.menu_copy_item).setShortcut('5', 'c');
            contextmenu.add(0, MENU_DELETE_ITEM, 0, R.string.menu_delete_item).setShortcut('6', 'd');
            contextmenu.add(0, MENU_MOVE_ITEM, 0, R.string.menu_move_item).setShortcut('7', 'l');
        }

    });
}

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 w w  .  j a va2 s .  c om*/
    // 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;
}