Search in sources :

Example 36 with MenuItem

use of com.actionbarsherlock.view.MenuItem in project ActionBarSherlock by JakeWharton.

the class ActionMenu method addIntentOptions.

public int addIntentOptions(int groupId, int itemId, int order, ComponentName caller, Intent[] specifics, Intent intent, int flags, MenuItem[] outSpecificItems) {
    PackageManager pm = mContext.getPackageManager();
    final List<ResolveInfo> lri = pm.queryIntentActivityOptions(caller, specifics, intent, 0);
    final int N = lri != null ? lri.size() : 0;
    if ((flags & FLAG_APPEND_TO_GROUP) == 0) {
        removeGroup(groupId);
    }
    for (int i = 0; i < N; i++) {
        final ResolveInfo ri = lri.get(i);
        Intent rintent = new Intent(ri.specificIndex < 0 ? intent : specifics[ri.specificIndex]);
        rintent.setComponent(new ComponentName(ri.activityInfo.applicationInfo.packageName, ri.activityInfo.name));
        final MenuItem item = add(groupId, itemId, order, ri.loadLabel(pm)).setIcon(ri.loadIcon(pm)).setIntent(rintent);
        if (outSpecificItems != null && ri.specificIndex >= 0) {
            outSpecificItems[ri.specificIndex] = item;
        }
    }
    return N;
}
Also used : ResolveInfo(android.content.pm.ResolveInfo) PackageManager(android.content.pm.PackageManager) Intent(android.content.Intent) ComponentName(android.content.ComponentName) MenuItem(com.actionbarsherlock.view.MenuItem)

Example 37 with MenuItem

use of com.actionbarsherlock.view.MenuItem in project ActionBarSherlock by JakeWharton.

the class ActionBarSherlockNative method dispatchOptionsItemSelected.

@Override
public boolean dispatchOptionsItemSelected(android.view.MenuItem item) {
    if (ActionBarSherlock.DEBUG)
        Log.d(TAG, "[dispatchOptionsItemSelected] item: " + item.getTitleCondensed());
    MenuItem wrapped;
    if (mMenu == null) {
        if (item.getItemId() != android.R.id.home) {
            throw new IllegalStateException("Non-home action item clicked before onCreateOptionsMenu with ID " + item.getItemId());
        }
        // Create a throw-away wrapper for now.
        wrapped = new MenuItemWrapper(item);
    } else {
        wrapped = mMenu.findItem(item);
    }
    final boolean result = callbackOptionsItemSelected(wrapped);
    if (ActionBarSherlock.DEBUG)
        Log.d(TAG, "[dispatchOptionsItemSelected] returning " + result);
    return result;
}
Also used : MenuItem(com.actionbarsherlock.view.MenuItem) MenuItemWrapper(com.actionbarsherlock.internal.view.menu.MenuItemWrapper)

Example 38 with MenuItem

use of com.actionbarsherlock.view.MenuItem in project ActionBarSherlock by JakeWharton.

the class MainActivity method onCreateOptionsMenu.

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getSupportMenuInflater().inflate(R.menu.main_menu, menu);
    // set up a listener for the refresh item
    final MenuItem refresh = (MenuItem) menu.findItem(R.id.menu_refresh);
    refresh.setOnMenuItemClickListener(new OnMenuItemClickListener() {

        // on selecting show progress spinner for 1s
        public boolean onMenuItemClick(MenuItem item) {
            // item.setActionView(R.layout.progress_action);
            handler.postDelayed(new Runnable() {

                public void run() {
                    refresh.setActionView(null);
                }
            }, 1000);
            return false;
        }
    });
    return super.onCreateOptionsMenu(menu);
}
Also used : OnMenuItemClickListener(com.actionbarsherlock.view.MenuItem.OnMenuItemClickListener) MenuItem(com.actionbarsherlock.view.MenuItem)

Example 39 with MenuItem

use of com.actionbarsherlock.view.MenuItem in project ActionBarSherlock by JakeWharton.

the class ShareActionProviders method onCreateOptionsMenu.

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate your menu.
    getSupportMenuInflater().inflate(R.menu.share_action_provider, menu);
    // Set file with share history to the provider and set the share intent.
    MenuItem actionItem = menu.findItem(R.id.menu_item_share_action_provider_action_bar);
    ShareActionProvider actionProvider = (ShareActionProvider) actionItem.getActionProvider();
    actionProvider.setShareHistoryFileName(ShareActionProvider.DEFAULT_SHARE_HISTORY_FILE_NAME);
    // Note that you can set/change the intent any time,
    // say when the user has selected an image.
    actionProvider.setShareIntent(createShareIntent());
    return true;
}
Also used : MenuItem(com.actionbarsherlock.view.MenuItem) ShareActionProvider(com.actionbarsherlock.widget.ShareActionProvider)

Example 40 with MenuItem

use of com.actionbarsherlock.view.MenuItem in project mobile-android by photo.

the class CommonRefreshableFragment method reinitMenu.

protected void reinitMenu(Menu menu) {
    try {
        MenuItem refreshItem = menu.findItem(R.id.menu_refresh);
        refreshItem.setVisible(isRefreshMenuVisible());
    } catch (Exception ex) {
        GuiUtils.noAlertError(TAG, ex);
        try {
            TrackerUtils.trackErrorEvent("#409 situation", CommonUtils.format("isAdded: %1$b; isDetached: %2$b; " + "isHidden: %3$b; isRemoving: %4$b; " + "isVisible: %1$b", isAdded(), isDetached(), isHidden(), isRemoving(), isVisible()));
        } catch (Exception ex2) {
            GuiUtils.noAlertError(TAG, ex2);
            TrackerUtils.trackErrorEvent("#409 situation", "additinal details error");
        }
    }
}
Also used : MenuItem(com.actionbarsherlock.view.MenuItem)

Aggregations

MenuItem (com.actionbarsherlock.view.MenuItem)93 View (android.view.View)18 ComponentName (android.content.ComponentName)16 Intent (android.content.Intent)16 PackageManager (android.content.pm.PackageManager)16 ResolveInfo (android.content.pm.ResolveInfo)16 Parcelable (android.os.Parcelable)16 SubMenu (com.actionbarsherlock.view.SubMenu)10 ActionMenuItem (com.actionbarsherlock.internal.view.menu.ActionMenuItem)8 MenuItemWrapper (com.actionbarsherlock.internal.view.menu.MenuItemWrapper)5 OnClickListener (android.view.View.OnClickListener)2 OnFocusChangeListener (android.view.View.OnFocusChangeListener)2 AutoCompleteTextView (android.widget.AutoCompleteTextView)2 ImageView (android.widget.ImageView)2 OnActionExpandListener (com.actionbarsherlock.view.MenuItem.OnActionExpandListener)2 OnMenuItemClickListener (com.actionbarsherlock.view.MenuItem.OnMenuItemClickListener)2 ShareActionProvider (com.actionbarsherlock.widget.ShareActionProvider)2 Drawable (android.graphics.drawable.Drawable)1 Editable (android.text.Editable)1 TextWatcher (android.text.TextWatcher)1