Methods Summary |
---|
public void | dismiss()Dismisses the menu's dialog.
if (mDialog != null) {
mDialog.dismiss();
}
|
public void | onClick(android.content.DialogInterface dialog, int which)
mMenu.performItemAction((MenuItemImpl) mPresenter.getAdapter().getItem(which), 0);
|
public void | onCloseMenu(MenuBuilder menu, boolean allMenusAreClosing)
if (allMenusAreClosing || menu == mMenu) {
dismiss();
}
if (mPresenterCallback != null) {
mPresenterCallback.onCloseMenu(menu, allMenusAreClosing);
}
|
public void | onDismiss(android.content.DialogInterface dialog)
mPresenter.onCloseMenu(mMenu, true);
|
public boolean | onKey(android.content.DialogInterface dialog, int keyCode, android.view.KeyEvent event)
if (keyCode == KeyEvent.KEYCODE_MENU || keyCode == KeyEvent.KEYCODE_BACK) {
if (event.getAction() == KeyEvent.ACTION_DOWN
&& event.getRepeatCount() == 0) {
Window win = mDialog.getWindow();
if (win != null) {
View decor = win.getDecorView();
if (decor != null) {
KeyEvent.DispatcherState ds = decor.getKeyDispatcherState();
if (ds != null) {
ds.startTracking(event, this);
return true;
}
}
}
} else if (event.getAction() == KeyEvent.ACTION_UP && !event.isCanceled()) {
Window win = mDialog.getWindow();
if (win != null) {
View decor = win.getDecorView();
if (decor != null) {
KeyEvent.DispatcherState ds = decor.getKeyDispatcherState();
if (ds != null && ds.isTracking(event)) {
mMenu.close(true);
dialog.dismiss();
return true;
}
}
}
}
}
// Menu shortcut matching
return mMenu.performShortcut(keyCode, event, 0);
|
public boolean | onOpenSubMenu(MenuBuilder subMenu)
if (mPresenterCallback != null) {
return mPresenterCallback.onOpenSubMenu(subMenu);
}
return false;
|
public void | setPresenterCallback(MenuPresenter.Callback cb)
mPresenterCallback = cb;
|
public void | show(android.os.IBinder windowToken)Shows menu as a dialog.
// Many references to mMenu, create local reference
final MenuBuilder menu = mMenu;
// Get the builder for the dialog
final AlertDialog.Builder builder = new AlertDialog.Builder(menu.getContext());
// Need to force Light Menu theme as list_menu_item_layout is usually against a dark bg and
// AlertDialog's bg is white
mPresenter = new ListMenuPresenter(R.layout.abc_list_menu_item_layout,
R.style.Theme_AppCompat_CompactMenu);
mPresenter.setCallback(this);
mMenu.addMenuPresenter(mPresenter);
builder.setAdapter(mPresenter.getAdapter(), this);
// Set the title
final View headerView = menu.getHeaderView();
if (headerView != null) {
// Menu's client has given a custom header view, use it
builder.setCustomTitle(headerView);
} else {
// Otherwise use the (text) title and icon
builder.setIcon(menu.getHeaderIcon()).setTitle(menu.getHeaderTitle());
}
// Set the key listener
builder.setOnKeyListener(this);
// Show the menu
mDialog = builder.create();
mDialog.setOnDismissListener(this);
WindowManager.LayoutParams lp = mDialog.getWindow().getAttributes();
lp.type = WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG;
if (windowToken != null) {
lp.token = windowToken;
}
lp.flags |= WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM;
mDialog.show();
|