Search in sources :

Example 71 with MenuItem

use of com.actionbarsherlock.view.MenuItem in project MDM-Android-Agent by wso2-attic.

the class MenuBuilder method saveActionViewStates.

public void saveActionViewStates(Bundle outStates) {
    SparseArray<Parcelable> viewStates = null;
    final int itemCount = size();
    for (int i = 0; i < itemCount; i++) {
        final MenuItem item = getItem(i);
        final View v = item.getActionView();
        if (v != null && v.getId() != View.NO_ID) {
            if (viewStates == null) {
                viewStates = new SparseArray<Parcelable>();
            }
            v.saveHierarchyState(viewStates);
            if (item.isActionViewExpanded()) {
                outStates.putInt(EXPANDED_ACTION_VIEW_ID, item.getItemId());
            }
        }
        if (item.hasSubMenu()) {
            final SubMenuBuilder subMenu = (SubMenuBuilder) item.getSubMenu();
            subMenu.saveActionViewStates(outStates);
        }
    }
    if (viewStates != null) {
        outStates.putSparseParcelableArray(getActionViewStatesKey(), viewStates);
    }
}
Also used : Parcelable(android.os.Parcelable) MenuItem(com.actionbarsherlock.view.MenuItem) View(android.view.View)

Example 72 with MenuItem

use of com.actionbarsherlock.view.MenuItem in project KeepScore by nolanlawson.

the class MainActivity method onPrepareOptionsMenu.

@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    MenuItem deleteSelectedMenuItem = menu.findItem(R.id.menu_delete_selected);
    MenuItem shareSelectedMenuItem = menu.findItem(R.id.menu_share_selected);
    MenuItem loadBackupMenuItem = menu.findItem(R.id.menu_load_backup);
    MenuItem saveBackupMenuItem = menu.findItem(R.id.menu_save_backup);
    MenuItem shareMenuItem = menu.findItem(R.id.menu_share);
    MenuItem exportToSpreadsheetMenuItem = menu.findItem(R.id.menu_export_to_spreadsheet);
    MenuItem settingsMenuItem = menu.findItem(R.id.menu_settings);
    MenuItem aboutMenuItem = menu.findItem(R.id.menu_about);
    // 
    // if the row of buttons at the bottom (select all, deselect all) is showing, offer
    // specific actions up at the top.
    // 
    MenuItem[] selectedModeMenuItems = new MenuItem[] { deleteSelectedMenuItem, shareSelectedMenuItem };
    MenuItem[] normalModeMenuItems = new MenuItem[] { loadBackupMenuItem, saveBackupMenuItem, shareMenuItem, exportToSpreadsheetMenuItem, settingsMenuItem, aboutMenuItem };
    for (MenuItem menuItem : selectedModeMenuItems) {
        menuItem.setEnabled(selectedMode);
        menuItem.setVisible(selectedMode);
    }
    for (MenuItem menuItem : normalModeMenuItems) {
        menuItem.setEnabled(!selectedMode);
        menuItem.setVisible(!selectedMode);
    }
    if (!selectedMode) {
        // normal mode
        // 
        // hide certain menu items if we're in less than Froyo, because
        // the XML Transformer stuff is only available in Froyo and above
        // 
        MenuItem[] eclairIncompatibleMenuItems = new MenuItem[] { loadBackupMenuItem, saveBackupMenuItem, shareMenuItem };
        boolean postFroyo = VersionHelper.getVersionSdkIntCompat() >= VersionHelper.VERSION_FROYO;
        for (MenuItem menuItem : eclairIncompatibleMenuItems) {
            menuItem.setVisible(postFroyo);
            menuItem.setEnabled(postFroyo);
        }
    }
    return true;
}
Also used : MenuItem(com.actionbarsherlock.view.MenuItem)

Example 73 with MenuItem

use of com.actionbarsherlock.view.MenuItem in project KeepScore by nolanlawson.

the class AbstractHistoryChartFragment method onPrepareOptionsMenu.

@Override
public void onPrepareOptionsMenu(Menu menu) {
    super.onPrepareOptionsMenu(menu);
    MenuItem zoomInMenuItem = menu.findItem(R.id.menu_zoom_in);
    MenuItem zoomOutMenuItem = menu.findItem(R.id.menu_zoom_out);
    boolean atMin = currentZoomIdx.get() == 0;
    boolean atMax = currentZoomIdx.get() == ZOOM_VALUES.size() - 1;
    zoomInMenuItem.setEnabled(!atMax);
    zoomInMenuItem.setVisible(true);
    zoomOutMenuItem.setEnabled(!atMin);
    zoomOutMenuItem.setVisible(true);
    // 
    // set the icons to be grayed out if disabled.  It looks prettier that way.  See
    // http://stackoverflow.com/questions/9642990/is-it-possible-to-grey-out-not-just-disable-a-menuitem-in-android
    // for details.
    // 
    Drawable zoomInIcon = getResources().getDrawable(R.drawable.action_zoom_in);
    Drawable zoomOutIcon = getResources().getDrawable(R.drawable.action_zoom_out);
    if (atMin) {
        zoomOutIcon.mutate().setColorFilter(Color.GRAY, PorterDuff.Mode.SRC_IN);
    } else if (atMax) {
        zoomInIcon.mutate().setColorFilter(Color.GRAY, PorterDuff.Mode.SRC_IN);
    }
    zoomInMenuItem.setIcon(zoomInIcon);
    zoomOutMenuItem.setIcon(zoomOutIcon);
}
Also used : Drawable(android.graphics.drawable.Drawable) MenuItem(com.actionbarsherlock.view.MenuItem)

Example 74 with MenuItem

use of com.actionbarsherlock.view.MenuItem in project Android-CollapsibleSearchMenu by johnkil.

the class CollapsibleMenuUtils method addSearchMenuItem.

/**
 * Adding collapsible search menu item to the menu.
 * @param menu
 * @param isLightTheme - true if use light them for ActionBar, else false
 * @return
 */
public static MenuItem addSearchMenuItem(Menu menu, boolean isLightTheme, final TextWatcher textWatcher) {
    final MenuItem menuItem = menu.add(Menu.NONE, R.id.collapsible_search_menu_item, Menu.NONE, R.string.search_go);
    menuItem.setIcon(isLightTheme ? R.drawable.ic_action_search_holo_light : R.drawable.ic_action_search_holo_dark).setActionView(isLightTheme ? R.layout.search_view_holo_light : R.layout.search_view_holo_dark).setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS | MenuItem.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW);
    final View searchView = menuItem.getActionView();
    final AutoCompleteTextView editText = (AutoCompleteTextView) searchView.findViewById(R.id.search_src_text);
    menuItem.setOnActionExpandListener(new OnActionExpandListener() {

        @Override
        public boolean onMenuItemActionExpand(MenuItem item) {
            editText.addTextChangedListener(textWatcher);
            editText.requestFocus();
            showKeyboard(editText);
            return true;
        }

        @Override
        public boolean onMenuItemActionCollapse(MenuItem item) {
            editText.setText(null);
            editText.removeTextChangedListener(textWatcher);
            // editText.clearFocus();
            hideKeyboard(editText);
            return true;
        }
    });
    final View searchPlate = searchView.findViewById(R.id.search_plate);
    editText.setOnFocusChangeListener(new OnFocusChangeListener() {

        @Override
        public void onFocusChange(View v, final boolean hasFocus) {
            searchView.post(new Runnable() {

                public void run() {
                    searchPlate.getBackground().setState(hasFocus ? new int[] { android.R.attr.state_focused } : new int[] { android.R.attr.state_empty });
                    searchView.invalidate();
                }
            });
        }
    });
    final ImageView closeBtn = (ImageView) menuItem.getActionView().findViewById(R.id.search_close_btn);
    closeBtn.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            if (!TextUtils.isEmpty(editText.getText())) {
                editText.setText(null);
            } else {
                menuItem.collapseActionView();
            }
        }
    });
    return menuItem;
}
Also used : OnFocusChangeListener(android.view.View.OnFocusChangeListener) OnActionExpandListener(com.actionbarsherlock.view.MenuItem.OnActionExpandListener) OnClickListener(android.view.View.OnClickListener) MenuItem(com.actionbarsherlock.view.MenuItem) ImageView(android.widget.ImageView) ImageView(android.widget.ImageView) View(android.view.View) AutoCompleteTextView(android.widget.AutoCompleteTextView) AutoCompleteTextView(android.widget.AutoCompleteTextView)

Example 75 with MenuItem

use of com.actionbarsherlock.view.MenuItem in project Ushahidi_Android by ushahidi.

the class MenuBuilder method addIntentOptions.

public int addIntentOptions(int group, int id, int categoryOrder, 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(group);
    }
    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(group, id, categoryOrder, 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)

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