Search in sources :

Example 61 with MenuItem

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();
}
Also used : RestClientUtils(org.wordpress.android.networking.RestClientUtils) MenuItem(android.view.MenuItem) PopupMenu(android.widget.PopupMenu)

Example 62 with MenuItem

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();
    }
}
Also used : ActionMenuItem(com.android.internal.view.menu.ActionMenuItem) MenuItem(android.view.MenuItem)

Example 63 with MenuItem

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();
        }
    }
}
Also used : Parcelable(android.os.Parcelable) MenuItem(android.view.MenuItem) View(android.view.View)

Example 64 with MenuItem

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);
    }
}
Also used : Parcelable(android.os.Parcelable) MenuItem(android.view.MenuItem) View(android.view.View)

Example 65 with MenuItem

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;
}
Also used : ResolveInfo(android.content.pm.ResolveInfo) PackageManager(android.content.pm.PackageManager) Intent(android.content.Intent) ComponentName(android.content.ComponentName) MenuItem(android.view.MenuItem)

Aggregations

MenuItem (android.view.MenuItem)761 View (android.view.View)140 Intent (android.content.Intent)86 TextView (android.widget.TextView)78 PopupMenu (android.widget.PopupMenu)62 ImageView (android.widget.ImageView)58 Menu (android.view.Menu)52 SearchView (android.support.v7.widget.SearchView)46 SmallTest (android.test.suitebuilder.annotation.SmallTest)42 RecyclerView (android.support.v7.widget.RecyclerView)36 MenuInflater (android.view.MenuInflater)35 AdapterView (android.widget.AdapterView)33 ListView (android.widget.ListView)32 SubMenu (android.view.SubMenu)30 ComponentName (android.content.ComponentName)25 PackageManager (android.content.pm.PackageManager)25 Parcelable (android.os.Parcelable)24 Toolbar (android.support.v7.widget.Toolbar)24 Bundle (android.os.Bundle)19 PopupMenu (android.support.v7.widget.PopupMenu)19