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;
}
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;
}
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;
}
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;
}
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);
}
}
Aggregations