package sk.m217.actionbarcompat;
import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.concurrent.CopyOnWriteArrayList;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.res.Resources;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.MenuItem;
import android.view.SubMenu;
public class implements Menu {
private Context mContext;
private Resources mResources;
private ArrayList<SimpleMenuItem> mItems;
private CopyOnWriteArrayList<WeakReference<SimpleMenuPresenter>> mPresenters =
new CopyOnWriteArrayList<WeakReference<SimpleMenuPresenter>>();
private SimpleMenuItem mExpandedItem;
private Callback mCallback;
static final int ITEM_CHANGED_NEW = 0;
static final int ITEM_CHANGED_TITLE = 1;
static final int ITEM_CHANGED_ICON = 2;
static final int ITEM_CHANGED_ACTION = 3;
static final int ITEM_CHANGED_ACTION_VIEW = 4;
static final int ITEM_CHANGED_VISIBILITY = 5;
public boolean (SimpleMenu menu, MenuItem item);
}
public (Context context) {
mContext = context;
mResources = context.getResources();
mItems = new ArrayList<SimpleMenuItem>();
}
return mContext;
}
return mResources;
}
public void (SimpleMenuPresenter presenter) {
mPresenters.add(new WeakReference<SimpleMenuPresenter>(presenter));
presenter.initForMenu(mContext, this);
}
public void (SimpleMenuPresenter presenter) {
for (WeakReference<SimpleMenuPresenter> ref : mPresenters) {
final SimpleMenuPresenter item = ref.get();
if (item == null || item == presenter) {
mPresenters.remove(ref);
}
}
}
private void (SimpleMenuItem item, int change) {
if (mPresenters.isEmpty()) {
return;
}
for (WeakReference<SimpleMenuPresenter> ref : mPresenters) {
final SimpleMenuPresenter presenter = ref.get();
if (presenter == null) {
mPresenters.remove(ref);
} else {
presenter.updateMenuView(this, item, change);
}
}
}
mCallback = cb;
}
boolean (SimpleMenu menu, MenuItem item) {
return mCallback != null && mCallback.onMenuItemSelected(menu, item);
}
public MenuItem
add(CharSequence title) {
return addInternal(0, 0, title);
}
public MenuItem
add(
int titleRes) {
return addInternal(0, 0, mResources.getString(titleRes));
}
public MenuItem
add(
int groupId,
int itemId,
int order, CharSequence title) {
return addInternal(itemId, order, title);
}
public MenuItem
add(
int groupId,
int itemId,
int order,
int titleRes) {
return addInternal(itemId, order, mResources.getString(titleRes));
}
private MenuItem
addInternal(
int itemId,
int order, CharSequence title) {
final SimpleMenuItem item = new SimpleMenuItem(this, itemId, order, title);
mItems.add(findInsertIndex(mItems, order), item);
onItemChanged(item, ITEM_CHANGED_NEW);
return item;
}
private static int (ArrayList<? extends MenuItem> items, int order) {
for (int i = items.size() - 1; i >= 0; i--) {
MenuItem item = items.get(i);
if (item.getOrder() <= order) {
return i + 1;
}
}
return 0;
}
final int size = size();
for (int i = 0; i < size; i++) {
SimpleMenuItem item = mItems.get(i);
if (item.getItemId() == id) {
return i;
}
}
return -1;
}
removeItemAtInt(findItemIndex(itemId));
}
if ((index < 0) || (index >= mItems.size())) {
return;
}
mItems.remove(index);
}
mItems.clear();
}
final int size = size();
for (int i = 0; i < size; i++) {
SimpleMenuItem item = mItems.get(i);
if (item.getItemId() == id) {
return item;
}
}
return null;
}
return mItems.size();
}
public MenuItem
getItem(
int index) {
return mItems.get(index);
}
if (mPresenters.isEmpty()) {
return false;
}
boolean expanded = false;
for (WeakReference<SimpleMenuPresenter> ref : mPresenters) {
final SimpleMenuPresenter presenter = ref.get();
if (presenter == null) {
mPresenters.remove(ref);
} else {
if ((expanded = presenter.expandItemActionView(this, item))) {
break;
}
}
}
if (expanded) {
mExpandedItem = item;
}
return expanded;
}
public boolean (SimpleMenuItem item) {
if (mPresenters.isEmpty() || mExpandedItem != item) {
return false;
}
boolean collapsed = false;
for (WeakReference<SimpleMenuPresenter> ref : mPresenters) {
final SimpleMenuPresenter presenter = ref.get();
if (presenter == null) {
mPresenters.remove(ref);
} else {
if ((collapsed = presenter.collapseItemActionView(this, item))) {
break;
}
}
}
if (collapsed) {
mExpandedItem = null;
}
return collapsed;
}
return mExpandedItem;
}
void (SimpleMenuItem item, int change) {
dispatchPresenterUpdate(item, change);
}
public SubMenu (CharSequence charSequence) {
throw new UnsupportedOperationException("This operation is not supported for SimpleMenu");
}
public SubMenu (int titleRes) {
throw new UnsupportedOperationException("This operation is not supported for SimpleMenu");
}
public SubMenu (int groupId, int itemId, int order, CharSequence title) {
throw new UnsupportedOperationException("This operation is not supported for SimpleMenu");
}
public SubMenu (int groupId, int itemId, int order, int titleRes) {
throw new UnsupportedOperationException("This operation is not supported for SimpleMenu");
}
public int (int i, int i1, int i2, ComponentName componentName,
Intent[] intents, Intent intent, int i3, MenuItem[] menuItems) {
throw new UnsupportedOperationException("This operation is not supported for SimpleMenu");
}
throw new UnsupportedOperationException("This operation is not supported for SimpleMenu");
}
throw new UnsupportedOperationException("This operation is not supported for SimpleMenu");
}
throw new UnsupportedOperationException("This operation is not supported for SimpleMenu");
}
throw new UnsupportedOperationException("This operation is not supported for SimpleMenu");
}
throw new UnsupportedOperationException("This operation is not supported for SimpleMenu");
}
throw new UnsupportedOperationException("This operation is not supported for SimpleMenu");
}
throw new UnsupportedOperationException("This operation is not supported for SimpleMenu");
}
throw new UnsupportedOperationException("This operation is not supported for SimpleMenu");
}
throw new UnsupportedOperationException("This operation is not supported for SimpleMenu");
}
throw new UnsupportedOperationException("This operation is not supported for SimpleMenu");
}
}