Example usage for android.view MenuItem getActionView

List of usage examples for android.view MenuItem getActionView

Introduction

In this page you can find the example usage for android.view MenuItem getActionView.

Prototype

public View getActionView();

Source Link

Document

Returns the currently set action view for this menu item.

Usage

From source file:com.weebly.opus1269.copyeverywhere.ui.main.MainActivity.java

/**
 * Initialize the {@link android.support.v7.view.menu.ActionMenuItemView} for search
 */// w w w  .j a  v  a2s. co  m
private void setupSearch() {
    final SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
    final MenuItem searchItem = mMenu.findItem(R.id.action_search);
    final SearchView searchView = (SearchView) searchItem.getActionView();
    searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
    searchView.setOnQueryTextListener(this);

    if (!TextUtils.isEmpty(mQueryString)) {
        // http://stackoverflow.com/a/32397014/4468645
        searchView.post(new Runnable() {
            @Override
            public void run() {
                MenuItemCompat.expandActionView(searchItem);
                searchView.setQuery(mQueryString, true);
            }
        });
    }
}

From source file:me.acristoffers.tracker.activities.PackageListActivity.java

@Override
public boolean onCreateOptionsMenu(final Menu menu) {
    final MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.menu_package_list, menu);

    MenuItem item = menu.findItem(R.id.toggle_inactive);

    final boolean showInactive = packageListFragment.isShowInactive();

    item.setTitle(showInactive ? R.string.hide_inactive : R.string.show_inactive);
    item.setIcon(showInactive ? R.drawable.ic_visibility_off_black_48dp : R.drawable.ic_visibility_black_48dp);

    item = menu.findItem(R.id.search);//from  www  .  j  a v  a2s  .c o m
    if (item != null) {
        final SearchView searchView = (SearchView) item.getActionView();
        if (searchView != null) {
            searchView.setQueryHint(getResources().getString(R.string.filter));

            searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
                @Override
                public boolean onQueryTextSubmit(final String query) {
                    filter(query);
                    return true;
                }

                @Override
                public boolean onQueryTextChange(final String newText) {
                    // Workaround this:
                    // http://stackoverflow.com/questions/9327826/searchviews-oncloselistener-doesnt-work/12975254#12975254
                    if (newText.isEmpty()) {
                        filter(null);
                    } else {
                        filter(newText);
                    }

                    return true;
                }
            });

            searchView.setOnCloseListener(new SearchView.OnCloseListener() {
                @Override
                public boolean onClose() {
                    filter(null);
                    return true;
                }
            });
        }
    }

    return true;
}

From source file:com.cyanogenmod.eleven.ui.activities.SearchActivity.java

/**
 * {@inheritDoc}/* ww  w.  j a  v a2 s .  co m*/
 */
@Override
public boolean onCreateOptionsMenu(final Menu menu) {
    // if we are not a top level search view, we do not need to create the search fields
    if (!mTopLevelSearch) {
        return super.onCreateOptionsMenu(menu);
    }

    // Search view
    getMenuInflater().inflate(R.menu.search, menu);

    // Filter the list the user is looking it via SearchView
    MenuItem searchItem = menu.findItem(R.id.menu_search);
    mSearchView = (SearchView) searchItem.getActionView();
    mSearchView.setOnQueryTextListener(this);
    mSearchView.setQueryHint(getString(R.string.searchHint).toUpperCase());

    // The SearchView has no way for you to customize or get access to the search icon in a
    // normal fashion, so we need to manually look for the icon and change the
    // layout params to hide it
    mSearchView.setIconifiedByDefault(false);
    mSearchView.setIconified(false);
    int searchButtonId = getResources().getIdentifier("android:id/search_mag_icon", null, null);
    ImageView searchIcon = (ImageView) mSearchView.findViewById(searchButtonId);
    searchIcon.setLayoutParams(new LinearLayout.LayoutParams(0, 0));

    searchItem.setOnActionExpandListener(new MenuItem.OnActionExpandListener() {
        @Override
        public boolean onMenuItemActionExpand(MenuItem item) {
            return true;
        }

        @Override
        public boolean onMenuItemActionCollapse(MenuItem item) {
            quit();
            return false;
        }
    });

    menu.findItem(R.id.menu_search).expandActionView();

    return super.onCreateOptionsMenu(menu);
}

From source file:org.wheelmap.android.activity.MainSinglePaneActivity.java

public boolean onOptionItemClicked(int id, View v, MenuItem item) {

    switch (id) {
    case R.id.menu_search:
        if (mWorkerFragment.isSearchMode()) {
            mWorkerFragment.setSearchMode(false);
            mWorkerFragment.requestUpdate(null);
        } else {//w  w  w  .j a  va2  s .  c o m
            showSearch();
        }
        return true;
    case R.id.menu_filter_kategorie:
        showFilterCategories();
        return true;
    case R.id.menu_filter:
    case R.id.menu_wc:
        View anchor = v;
        if (anchor == null) {
            anchor = item.getActionView();
        }
        showFilterSettings(item, v, anchor);
        return true;
    case R.id.menu_about:
        showInfo();
        return true;
    case android.R.id.home:
        finish();
        return true;
    default:
        return super.onOptionsItemSelected(item);
    }
}

From source file:at.ac.tuwien.detlef.activities.MainActivity.java

private void setRefreshBtnView(int id) {
    if (menu == null) {
        return;/*from ww  w .  j  av a  2  s  .com*/
    }

    MenuItem refreshBtn = menu.findItem(R.id.refresh);

    if (refreshBtn == null) {
        return;
    }

    refreshBtn.setActionView(id);
    refreshBtn.getActionView().setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            onRefreshPressed();
        }
    });
}

From source file:com.nextgis.mobile.activity.MainActivity.java

protected void stopRefresh(final MenuItem refreshItem) {
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB)
        return;/*from  w w w .  ja  va  2s.co  m*/

    Handler handler = new Handler(Looper.getMainLooper());
    final Runnable r = new Runnable() {
        @TargetApi(Build.VERSION_CODES.HONEYCOMB)
        public void run() {
            if (refreshItem != null && refreshItem.getActionView() != null) {
                refreshItem.getActionView().clearAnimation();
                refreshItem.setActionView(null);
            }
        }
    };
    handler.post(r);
}

From source file:com.abewy.android.apps.klyph.app.MainActivity.java

public boolean onCreateOptionsMenu(Menu menu) {
    if (notificationsFragment != null && menu.findItem(R.id.menu_notifications) == null) {
        final MenuItem notificationItem = menu.add(Menu.NONE, R.id.menu_notifications, 2,
                R.string.menu_notifications);
        notificationItem.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
        notificationItem.setActionView(R.layout.actionbar_item_notifications);

        final TextView notificationTextView = (TextView) notificationItem.getActionView()
                .findViewById(R.id.textView);

        int count = notificationsFragment.getUnreadCount();

        notificationTextView.setText(String.valueOf(count));

        if (count > 0) {
            notificationTextView/*  w w  w .  j a v  a 2s  .c o m*/
                    .setBackgroundResource(AttrUtil.getResourceId(this, R.attr.notificationsItemBackground));
        } else {
            notificationTextView.setBackgroundResource(R.drawable.notifications_read_background);

        }

        notificationItem.getActionView().setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                onOptionsItemSelected(notificationItem);
            }
        });
    }

    if (!KlyphFlags.IS_PRO_VERSION && menu.findItem(R.id.menu_buy_pro) == null) {
        menu.add(Menu.NONE, R.id.menu_buy_pro, 2, R.string.menu_buy_pro)
                .setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER);
    }

    if (menu.findItem(R.id.menu_faq) == null) {
        menu.add(Menu.NONE, R.id.menu_faq, Menu.NONE, R.string.menu_faq)
                .setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER);
    }

    return super.onCreateOptionsMenu(menu);
}

From source file:de.vanita5.twittnuker.activity.support.HomeActivity.java

@Override
public boolean onCreateOptionsMenu(final Menu menu, final TwidereMenuInflater inflater) {
    inflater.inflate(R.menu.menu_home, menu);
    final MenuItem itemProgress = menu.findItem(MENU_PROGRESS);
    mSmartBarProgress = (ProgressBar) itemProgress.getActionView().findViewById(android.R.id.progress);
    updateActionsButton();/*ww  w . j a v a2  s  .  c o m*/
    return true;
}

From source file:com.irateam.vkplayer.activities.ListActivity.java

@Override
public boolean onCreateOptionsMenu(final Menu menu) {
    getMenuInflater().inflate(R.menu.menu_list, menu);

    toolbarMenu = menu;/* w  ww  . jav  a 2  s  .  c  o m*/

    MenuItem itemSort = menu.findItem(R.id.action_sort);
    MenuItem itemSortDone = menu.findItem(R.id.action_sort_done);
    MenuItem itemSearch = menu.findItem(R.id.action_search);

    audioAdapter.setSortModeListener(new AudioAdapter.SortModeListener() {
        @Override
        public void onStartSortMode() {
            itemSort.setVisible(false);
            itemSortDone.setVisible(true);
            listView.setDragEnabled(true);
            refreshLayout.setEnabled(false);
        }

        @Override
        public void onFinishSortMode() {
            itemSort.setVisible(true);
            itemSortDone.setVisible(false);
            listView.setDragEnabled(false);
            refreshLayout.setEnabled(true);
        }
    });

    searchView = (SearchView) itemSearch.getActionView();
    searchView.setIconifiedByDefault(false);
    searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
        @Override
        public boolean onQueryTextSubmit(String query) {
            return false;
        }

        @Override
        public boolean onQueryTextChange(String newText) {
            audioAdapter.getFilter().filter(newText);
            return true;
        }
    });
    return true;
}

From source file:com.freeme.filemanager.FileExplorerTabActivity.java

public void hotKnotUpdateMenu(Menu menu, int shareAction, int hotKnotAction) {
    if (menu == null) {
        Log.d(TAG, "hotKnotUpdateMenu: menu is null");
        return;/*from w  w  w.ja  va 2s.c om*/
    }
    mHotKnotItem = menu.findItem(hotKnotAction);
    MenuItem shareItem = menu.findItem(shareAction);
    boolean enable = hotKnotIsEnable();
    Log.d(TAG, "hotKnotUpdateMenu, Enable:" + enable);

    if (mHotKnotItem != null && shareItem != null) {
        mHotKnotItem.setVisible(enable);
        ((ActivityChooserView) shareItem.getActionView()).setRecentButtonEnabled(!enable);
        Log.d(TAG, "hotKnotUpdateMenu, success");
    }
}