use of android.view.MenuItem in project WordPress-Android by wordpress-mobile.
the class ReferrerSpamHelper method showPopup.
public void showPopup(View anchor, final ReferrerGroupModel referrerGroup) {
if (mActivityRef.get() == null || mActivityRef.get().isFinishing()) {
return;
}
final PopupMenu popup = new PopupMenu(mActivityRef.get(), anchor);
final MenuItem menuItem;
if (referrerGroup.isRestCallInProgress) {
menuItem = popup.getMenu().add(referrerGroup.isMarkedAsSpam ? mActivityRef.get().getString(R.string.stats_referrers_marking_not_spam) : mActivityRef.get().getString(R.string.stats_referrers_marking_spam));
} else {
menuItem = popup.getMenu().add(referrerGroup.isMarkedAsSpam ? mActivityRef.get().getString(R.string.stats_referrers_unspam) : mActivityRef.get().getString(R.string.stats_referrers_spam));
}
menuItem.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
item.setTitle(referrerGroup.isMarkedAsSpam ? mActivityRef.get().getString(R.string.stats_referrers_marking_not_spam) : mActivityRef.get().getString(R.string.stats_referrers_marking_spam));
item.setOnMenuItemClickListener(null);
final RestClientUtils restClientUtils = WordPress.getRestClientUtilsV1_1();
final String restPath;
final boolean isMarkingAsSpamInProgress;
if (referrerGroup.isMarkedAsSpam) {
restPath = String.format(Locale.US, "/sites/%s/stats/referrers/spam/delete/?domain=%s", referrerGroup.getBlogId(), getDomain(referrerGroup));
isMarkingAsSpamInProgress = false;
} else {
restPath = String.format(Locale.US, "/sites/%s/stats/referrers/spam/new/?domain=%s", referrerGroup.getBlogId(), getDomain(referrerGroup));
isMarkingAsSpamInProgress = true;
}
referrerGroup.isRestCallInProgress = true;
ReferrerSpamRestListener vListener = new ReferrerSpamRestListener(mActivityRef.get(), referrerGroup, isMarkingAsSpamInProgress);
restClientUtils.post(restPath, vListener, vListener);
AppLog.d(AppLog.T.STATS, "Enqueuing the following REST request " + restPath);
return true;
}
});
popup.show();
}
use of android.view.MenuItem in project XobotOS by xamarin.
the class ActionBarView method onRestoreInstanceState.
@Override
public void onRestoreInstanceState(Parcelable p) {
SavedState state = (SavedState) p;
super.onRestoreInstanceState(state.getSuperState());
if (state.expandedMenuItemId != 0 && mExpandedMenuPresenter != null && mOptionsMenu != null) {
final MenuItem item = mOptionsMenu.findItem(state.expandedMenuItemId);
if (item != null) {
item.expandActionView();
}
}
if (state.isOverflowOpen) {
postShowOverflowMenu();
}
}
use of android.view.MenuItem in project XobotOS by xamarin.
the class MenuBuilder method restoreActionViewStates.
public void restoreActionViewStates(Bundle states) {
if (states == null) {
return;
}
SparseArray<Parcelable> viewStates = states.getSparseParcelableArray(getActionViewStatesKey());
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) {
v.restoreHierarchyState(viewStates);
}
if (item.hasSubMenu()) {
final SubMenuBuilder subMenu = (SubMenuBuilder) item.getSubMenu();
subMenu.restoreActionViewStates(states);
}
}
final int expandedId = states.getInt(EXPANDED_ACTION_VIEW_ID);
if (expandedId > 0) {
MenuItem itemToExpand = findItem(expandedId);
if (itemToExpand != null) {
itemToExpand.expandActionView();
}
}
}
use of android.view.MenuItem in project XobotOS by xamarin.
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);
}
}
use of android.view.MenuItem in project XobotOS by xamarin.
the class MenuBuilder method addIntentOptions.
public int addIntentOptions(int group, int id, int categoryOrder, ComponentName caller, Intent[] specifics, Intent intent, int flags, MenuItem[] outSpecificItems) {
PackageManager pm = mContext.getPackageManager();
final List<ResolveInfo> lri = pm.queryIntentActivityOptions(caller, specifics, intent, 0);
final int N = lri != null ? lri.size() : 0;
if ((flags & FLAG_APPEND_TO_GROUP) == 0) {
removeGroup(group);
}
for (int i = 0; i < N; i++) {
final ResolveInfo ri = lri.get(i);
Intent rintent = new Intent(ri.specificIndex < 0 ? intent : specifics[ri.specificIndex]);
rintent.setComponent(new ComponentName(ri.activityInfo.applicationInfo.packageName, ri.activityInfo.name));
final MenuItem item = add(group, id, categoryOrder, ri.loadLabel(pm)).setIcon(ri.loadIcon(pm)).setIntent(rintent);
if (outSpecificItems != null && ri.specificIndex >= 0) {
outSpecificItems[ri.specificIndex] = item;
}
}
return N;
}
Aggregations