use of android.support.v7.view.menu.MenuBuilder in project HoloEverywhere by Prototik.
the class ActionBarActivityDelegateBase method createMenu.
private MenuBuilder createMenu() {
MenuBuilder menu = new MenuBuilder(getActionBarThemedContext());
menu.setCallback(this);
return menu;
}
use of android.support.v7.view.menu.MenuBuilder in project HoloEverywhere by Prototik.
the class ActionMenuPresenter method initForMenu.
@Override
public void initForMenu(Context context, MenuBuilder menu) {
super.initForMenu(context, menu);
final Resources res = context.getResources();
final ActionBarPolicy abp = ActionBarPolicy.get(context);
if (!mReserveOverflowSet) {
mReserveOverflow = abp.showsOverflowMenuButton();
}
if (!mWidthLimitSet) {
mWidthLimit = abp.getEmbeddedMenuWidthLimit();
}
// Measure for initial configuration
if (!mMaxItemsSet) {
mMaxItems = abp.getMaxActionButtons();
}
int width = mWidthLimit;
if (mReserveOverflow) {
if (mOverflowButton == null) {
mOverflowButton = new OverflowMenuButton(mSystemContext);
final int spec = MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED);
mOverflowButton.measure(spec, spec);
}
width -= mOverflowButton.getMeasuredWidth();
} else {
mOverflowButton = null;
}
mActionItemWidthLimit = width;
mMinCellSize = (int) (ActionMenuView.MIN_CELL_SIZE * res.getDisplayMetrics().density);
// Drop a scrap view as it may no longer reflect the proper context/config.
mScrapActionButtonView = null;
}
use of android.support.v7.view.menu.MenuBuilder in project HoloEverywhere by Prototik.
the class ActionBarContextView method initForMode.
public void initForMode(final ActionMode mode) {
if (mClose == null) {
LayoutInflater inflater = LayoutInflater.from(getContext());
mClose = inflater.inflate(R.layout.abc_action_mode_close_item, this, false);
addView(mClose);
} else if (mClose.getParent() == null) {
addView(mClose);
}
View closeButton = mClose.findViewById(R.id.action_mode_close_button);
closeButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
mode.finish();
}
});
final MenuBuilder menu = (MenuBuilder) mode.getMenu();
if (mActionMenuPresenter != null) {
mActionMenuPresenter.dismissPopupMenus();
}
mActionMenuPresenter = new ActionMenuPresenter(getContext());
mActionMenuPresenter.setReserveOverflow(true);
final ViewGroup.LayoutParams layoutParams = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.FILL_PARENT);
if (!mSplitActionBar) {
menu.addMenuPresenter(mActionMenuPresenter);
mMenuView = (ActionMenuView) mActionMenuPresenter.getMenuView(this);
mMenuView.setBackgroundDrawable(null);
addView(mMenuView, layoutParams);
} else {
// Allow full screen width in split mode.
mActionMenuPresenter.setWidthLimit(getContext().getResources().getDisplayMetrics().widthPixels, true);
// No limit to the item count; use whatever will fit.
mActionMenuPresenter.setItemLimit(Integer.MAX_VALUE);
// Span the whole width
layoutParams.width = ViewGroup.LayoutParams.FILL_PARENT;
layoutParams.height = mContentHeight;
menu.addMenuPresenter(mActionMenuPresenter);
mMenuView = (ActionMenuView) mActionMenuPresenter.getMenuView(this);
mMenuView.setBackgroundDrawable(mSplitBackground);
mSplitView.addView(mMenuView, layoutParams);
}
}
use of android.support.v7.view.menu.MenuBuilder in project floatingsearchview by arimorty.
the class FloatingSearchView method setupQueryBar.
private void setupQueryBar() {
mSearchInput.setTextColor(mSearchInputTextColor);
mSearchInput.setHintTextColor(mSearchInputHintColor);
if (!isInEditMode() && mHostActivity != null) {
mHostActivity.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);
}
ViewTreeObserver vto = mQuerySection.getViewTreeObserver();
vto.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
Util.removeGlobalLayoutObserver(mQuerySection, this);
inflateOverflowMenu(mMenuId);
}
});
mMenuView.setMenuCallback(new MenuBuilder.Callback() {
@Override
public boolean onMenuItemSelected(MenuBuilder menu, MenuItem item) {
if (mActionMenuItemListener != null) {
mActionMenuItemListener.onActionMenuItemSelected(item);
}
// todo check if we should care about this return or not
return false;
}
@Override
public void onMenuModeChange(MenuBuilder menu) {
}
});
mMenuView.setOnVisibleWidthChanged(new MenuView.OnVisibleWidthChangedListener() {
@Override
public void onItemsMenuVisibleWidthChanged(int newVisibleWidth) {
handleOnVisibleMenuItemsWidthChanged(newVisibleWidth);
}
});
mMenuView.setActionIconColor(mActionMenuItemColor);
mMenuView.setOverflowColor(mOverflowIconColor);
mClearButton.setVisibility(View.INVISIBLE);
mClearButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
mSearchInput.setText("");
if (mOnClearSearchActionListener != null) {
mOnClearSearchActionListener.onClearSearchClicked();
}
}
});
mSearchInput.addTextChangedListener(new TextWatcherAdapter() {
public void onTextChanged(final CharSequence s, int start, int before, int count) {
if (mSkipTextChangeEvent || !mIsFocused) {
mSkipTextChangeEvent = false;
} else {
if (mSearchInput.getText().toString().length() != 0 && mClearButton.getVisibility() == View.INVISIBLE) {
mClearButton.setAlpha(0.0f);
mClearButton.setVisibility(View.VISIBLE);
ViewCompat.animate(mClearButton).alpha(1.0f).setDuration(CLEAR_BTN_FADE_ANIM_DURATION).start();
} else if (mSearchInput.getText().toString().length() == 0) {
mClearButton.setVisibility(View.INVISIBLE);
}
if (mQueryListener != null && mIsFocused && !mOldQuery.equals(mSearchInput.getText().toString())) {
mQueryListener.onSearchTextChanged(mOldQuery, mSearchInput.getText().toString());
}
}
mOldQuery = mSearchInput.getText().toString();
}
});
mSearchInput.setOnFocusChangeListener(new TextView.OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
if (mSkipQueryFocusChangeEvent) {
mSkipQueryFocusChangeEvent = false;
} else if (hasFocus != mIsFocused) {
setSearchFocusedInternal(hasFocus);
}
}
});
mSearchInput.setOnKeyboardDismissedListener(new SearchInputView.OnKeyboardDismissedListener() {
@Override
public void onKeyboardDismissed() {
if (mCloseSearchOnSofteKeyboardDismiss) {
setSearchFocusedInternal(false);
}
}
});
mSearchInput.setOnSearchKeyListener(new SearchInputView.OnKeyboardSearchKeyClickListener() {
@Override
public void onSearchKeyClicked() {
if (mSearchListener != null) {
mSearchListener.onSearchAction(getQuery());
}
mSkipTextChangeEvent = true;
mSkipTextChangeEvent = true;
if (mIsTitleSet) {
setSearchBarTitle(getQuery());
} else {
setSearchText(getQuery());
}
setSearchFocusedInternal(false);
}
});
mLeftAction.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if (isSearchBarFocused()) {
setSearchFocusedInternal(false);
} else {
switch(mLeftActionMode) {
case LEFT_ACTION_MODE_SHOW_HAMBURGER:
if (mLeftMenuClickListener != null) {
mLeftMenuClickListener.onClick(mLeftAction);
} else {
toggleLeftMenu();
}
break;
case LEFT_ACTION_MODE_SHOW_SEARCH:
setSearchFocusedInternal(true);
break;
case LEFT_ACTION_MODE_SHOW_HOME:
if (mOnHomeActionClickListener != null) {
mOnHomeActionClickListener.onHomeClicked();
}
break;
case LEFT_ACTION_MODE_NO_LEFT_ACTION:
// do nothing
break;
}
}
}
});
refreshLeftIcon();
}
use of android.support.v7.view.menu.MenuBuilder in project floatingsearchview by arimorty.
the class MenuView method reset.
/**
* Resets the the view to fit into a new
* available width.
* <p/>
* <p>This clears and then re-inflates the menu items
* , removes all of its associated action views, and re-creates
* the menu and action items to fit in the new width.</p>
*
* @param availWidth the width available for the menu to use. If
* there is room, menu items that are flagged with
* android:showAsAction="ifRoom" or android:showAsAction="always"
* will show as actions.
*/
public void reset(int menu, int availWidth) {
mMenu = menu;
if (mMenu == -1) {
return;
}
mActionShowAlwaysItems = new ArrayList<>();
mActionItems = new ArrayList<>();
mMenuItems = new ArrayList<>();
mMenuBuilder = new MenuBuilder(getContext());
mMenuPopupHelper = new MenuPopupHelper(getContext(), mMenuBuilder, this);
// clean view and re-inflate
removeAllViews();
getMenuInflater().inflate(mMenu, mMenuBuilder);
mMenuItems = mMenuBuilder.getActionItems();
mMenuItems.addAll(mMenuBuilder.getNonActionItems());
Collections.sort(mMenuItems, new Comparator<MenuItemImpl>() {
@Override
public int compare(MenuItemImpl lhs, MenuItemImpl rhs) {
return ((Integer) lhs.getOrder()).compareTo(rhs.getOrder());
}
});
List<MenuItemImpl> localActionItems = filter(mMenuItems, new MenuItemImplPredicate() {
@Override
public boolean apply(MenuItemImpl menuItem) {
return menuItem.getIcon() != null && (menuItem.requiresActionButton() || menuItem.requestsActionButton());
}
});
int availItemRoom = availWidth / (int) ACTION_DIMENSION_PX;
// determine if to show overflow menu
boolean addOverflowAtTheEnd = false;
if (((localActionItems.size() < mMenuItems.size()) || availItemRoom < localActionItems.size())) {
addOverflowAtTheEnd = true;
availItemRoom--;
}
ArrayList<Integer> actionItemsIds = new ArrayList<>();
if (availItemRoom > 0) {
for (int i = 0; i < localActionItems.size(); i++) {
final MenuItemImpl menuItem = localActionItems.get(i);
if (menuItem.getIcon() != null) {
ImageView action = createActionView();
action.setContentDescription(menuItem.getTitle());
action.setImageDrawable(menuItem.getIcon());
Util.setIconColor(action, mActionIconColor);
addView(action);
mActionItems.add(menuItem);
actionItemsIds.add(menuItem.getItemId());
action.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if (mMenuCallback != null) {
mMenuCallback.onMenuItemSelected(mMenuBuilder, menuItem);
}
}
});
availItemRoom--;
if (availItemRoom == 0) {
break;
}
}
}
}
mHasOverflow = addOverflowAtTheEnd;
if (addOverflowAtTheEnd) {
ImageView overflowAction = getOverflowActionView();
overflowAction.setImageResource(R.drawable.ic_more_vert_black_24dp);
Util.setIconColor(overflowAction, mOverflowIconColor);
addView(overflowAction);
overflowAction.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
mMenuPopupHelper.show();
}
});
mMenuBuilder.setCallback(mMenuCallback);
}
// remove all menu items that will be shown as icons (the action items) from the overflow menu
for (int id : actionItemsIds) {
mMenuBuilder.removeItem(id);
}
actionItemsIds = null;
if (mOnVisibleWidthChangedListener != null) {
mVisibleWidth = ((int) ACTION_DIMENSION_PX * getChildCount()) - (mHasOverflow ? Util.dpToPx(8) : 0);
mOnVisibleWidthChangedListener.onItemsMenuVisibleWidthChanged(mVisibleWidth);
}
}
Aggregations