Search in sources :

Example 26 with MenuItem

use of com.actionbarsherlock.view.MenuItem in project Libraries-for-Android-Developers by eoecn.

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 27 with MenuItem

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

the class GameActivity method onPrepareOptionsMenu.

@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    // show/hide undo/redo menu items
    MenuItem undoMenuItem = menu.findItem(R.id.menu_undo);
    MenuItem redoMenuItem = menu.findItem(R.id.menu_redo);
    boolean showUndo = !undoStack.isEmpty();
    boolean showRedo = !redoStack.isEmpty();
    undoMenuItem.setEnabled(showUndo);
    redoMenuItem.setEnabled(showRedo);
    return true;
}
Also used : MenuItem(com.actionbarsherlock.view.MenuItem)

Example 28 with MenuItem

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

the class OrganizePlayersActivity method onPrepareOptionsMenu.

@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    super.onPrepareOptionsMenu(menu);
    MenuItem addPlayerItem = menu.findItem(R.id.menu_add_player);
    boolean enabled = adapter.getCount() < MAX_NUM_PLAYERS;
    addPlayerItem.setEnabled(enabled);
    addPlayerItem.setVisible(enabled);
    return true;
}
Also used : MenuItem(com.actionbarsherlock.view.MenuItem)

Example 29 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 menu item
 */
public static MenuItem addSearchMenuItem(Menu menu, boolean isLightTheme, final OnQueryTextListener onQueryChangeListener) {
    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);
    final TextWatcher textWatcher = new TextWatcher() {

        @Override
        public void onTextChanged(CharSequence charSequence, int i, int i2, int i3) {
            onQueryChangeListener.onQueryTextChange(charSequence.toString());
        }

        @Override
        public void beforeTextChanged(CharSequence charSequence, int i, int i2, int i3) {
        }

        @Override
        public void afterTextChanged(Editable editable) {
        }
    };
    final TextView.OnEditorActionListener onEditorActionListener = new TextView.OnEditorActionListener() {

        @Override
        public boolean onEditorAction(TextView textView, int i, KeyEvent keyEvent) {
            if (i == EditorInfo.IME_ACTION_SEARCH || keyEvent.getKeyCode() == KeyEvent.KEYCODE_ENTER) {
                onQueryChangeListener.onQueryTextSubmit(textView.getText().toString());
                return true;
            }
            return false;
        }
    };
    menuItem.setOnActionExpandListener(new OnActionExpandListener() {

        @Override
        public boolean onMenuItemActionExpand(MenuItem item) {
            editText.addTextChangedListener(textWatcher);
            editText.setOnEditorActionListener(onEditorActionListener);
            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) MenuItem(com.actionbarsherlock.view.MenuItem) ImageView(android.widget.ImageView) AutoCompleteTextView(android.widget.AutoCompleteTextView) TextView(android.widget.TextView) View(android.view.View) KeyEvent(android.view.KeyEvent) TextWatcher(android.text.TextWatcher) Editable(android.text.Editable) OnActionExpandListener(com.actionbarsherlock.view.MenuItem.OnActionExpandListener) OnClickListener(android.view.View.OnClickListener) AutoCompleteTextView(android.widget.AutoCompleteTextView) TextView(android.widget.TextView) ImageView(android.widget.ImageView) AutoCompleteTextView(android.widget.AutoCompleteTextView)

Example 30 with MenuItem

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

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)

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