Example usage for android.view MenuItem setOnActionExpandListener

List of usage examples for android.view MenuItem setOnActionExpandListener

Introduction

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

Prototype

public MenuItem setOnActionExpandListener(OnActionExpandListener listener);

Source Link

Document

Set an OnActionExpandListener on this menu item to be notified when the associated action view is expanded or collapsed.

Usage

From source file:com.commonsware.android.fts.QuestionsFragment.java

private void configureSearchView(Menu menu) {
    MenuItem search = menu.findItem(R.id.search);

    search.setOnActionExpandListener(this);
    sv = (SearchView) search.getActionView();
    sv.setOnQueryTextListener(this);
    sv.setSubmitButtonEnabled(true);/*from   w w w  .j a v a 2 s. c o  m*/
    sv.setIconifiedByDefault(true);

    if (initialQuery != null) {
        sv.setIconified(false);
        search.expandActionView();
        sv.setQuery(initialQuery, true);
    }
}

From source file:de.fhb.mi.paperfly.user.FriendListFragment.java

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    if (menu != null) {
        inflater.inflate(R.menu.user_friends, menu);
    }/*from   ww w  .  jav a2 s . co  m*/

    SearchManager searchManager = (SearchManager) getActivity().getSystemService(Context.SEARCH_SERVICE);
    SearchView searchView = (SearchView) menu.findItem(R.id.action_search_user).getActionView();

    // Get the menu item from the action bar
    MenuItem menuItem = menu.findItem(R.id.action_search_user);
    menuItem.setOnActionExpandListener(new MenuItem.OnActionExpandListener() {

        @Override
        public boolean onMenuItemActionCollapse(MenuItem item) {
            Log.d(TAG, "Search deactivated. Unlocking drawers.");
            drawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_UNLOCKED);
            return true;
        }

        @Override
        public boolean onMenuItemActionExpand(MenuItem item) {
            Log.d(TAG, "Search activated. Locking drawers.");
            drawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED);
            return true;
        }
    });
    // Assumes current activity is the searchable activity
    searchView.setSearchableInfo(searchManager.getSearchableInfo(getActivity().getComponentName()));
}

From source file:com.xandy.calendar.SearchActivity.java

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

    // replace the default top layer drawable of the today icon with a custom drawable
    // that shows the day of the month of today
    MenuItem menuItem = menu.findItem(R.id.action_today);
    if (Utils.isJellybeanOrLater()) {
        LayerDrawable icon = (LayerDrawable) menuItem.getIcon();
        Utils.setTodayIcon(icon, this, Utils.getTimeZone(SearchActivity.this, mTimeChangesUpdater));
    } else {//from  w ww  .j  ava 2 s .c  o m
        menuItem.setIcon(R.drawable.ic_menu_today_no_date_holo_light);
    }

    MenuItem item = menu.findItem(R.id.action_search);
    item.expandActionView();
    item.setOnActionExpandListener(this);
    mSearchView = (SearchView) item.getActionView();
    Utils.setUpSearchView(mSearchView, this);
    mSearchView.setQuery(mQuery, false);
    mSearchView.clearFocus();

    return true;
}

From source file:org.appcelerator.titanium.proxy.MenuItemProxy.java

protected MenuItemProxy(MenuItem item) {
    this.item = item;

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
        item.setOnActionExpandListener(new ActionExpandListener());
    } else {//  w  w  w.j  av a  2  s.  c  o  m
        MenuItemCompat.setOnActionExpandListener(item, new CompatActionExpandListener());
    }
}

From source file:de.spiritcroc.ownlog.ui.fragment.LogFragment.java

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    super.onCreateOptionsMenu(menu, inflater);
    inflater.inflate(R.menu.fragment_log, menu);
    MenuItem searchItem = menu.findItem(R.id.action_search);
    searchItem.setOnActionExpandListener(mSearchActionExpandListener);
    mSearchView = (SearchView) searchItem.getActionView();
    mSearchView.setOnQueryTextListener(mSearchQueryTextListener);
    mSearchView.setOnQueryTextFocusChangeListener(mSearchQueryTextFocusChangeListener);
}

From source file:li.barter.fragments.BooksAroundMeFragment.java

@Override
public void onCreateOptionsMenu(final Menu menu, final MenuInflater inflater) {
    inflater.inflate(R.menu.menu_books_around_me, menu);
    final MenuItem menuItem = menu.findItem(R.id.action_search);
    menuItem.setOnActionExpandListener(this);
    mSearchView = (SearchView) MenuItemCompat.getActionView(menuItem);
    mSearchNetworkQueryHelper = new SearchViewNetworkQueryHelper(mSearchView, this);
    mSearchNetworkQueryHelper.setSuggestCountThreshold(3);
    mSearchNetworkQueryHelper.setSuggestWaitThreshold(400);
}

From source file:com.filterdevice.ProfileScanningFragment.java

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    menu.clear();//from w w w.ja  va2s  .  c  o m
    inflater.inflate(R.menu.global, menu);
    final EditText mEditText = (EditText) menu.findItem(R.id.search).getActionView();
    mEditText.addTextChangedListener(textWatcher);

    MenuItem pairCache = menu.findItem(R.id.pairing);
    if (Utils.getBooleanSharedPreference(getActivity(), Constants.PREF_PAIR_CACHE_STATUS)) {
        pairCache.setChecked(true);
    } else {
        pairCache.setChecked(false);
    }

    MenuItem mSearch = menu.findItem(R.id.search);
    mSearch.setVisible(true);
    mSearch.setOnActionExpandListener(new MenuItem.OnActionExpandListener() {
        @Override
        public boolean onMenuItemActionCollapse(MenuItem item) {
            // Do something when collapsed
            View view = getActivity().getCurrentFocus();
            if (view != null) {
                InputMethodManager imm = (InputMethodManager) getActivity()
                        .getSystemService(Context.INPUT_METHOD_SERVICE);
                imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
            }
            Logger.e("Collapsed");
            return true; // Return true to collapse action view
        }

        @Override
        public boolean onMenuItemActionExpand(MenuItem item) {
            Logger.e("Expanded");
            mEditText.requestFocus();
            View view = getActivity().getCurrentFocus();
            if (view != null) {
                InputMethodManager inputManager = (InputMethodManager) getActivity()
                        .getSystemService(Context.INPUT_METHOD_SERVICE);
                inputManager.showSoftInput(view, InputMethodManager.SHOW_IMPLICIT);
            }
            return true; // Return true to expand action view
        }
    });

    super.onCreateOptionsMenu(menu, inflater);
}

From source file:com.example.office.ui.Office365DemoActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    try {/*ww w . jav  a2  s .c o  m*/
        getMenuInflater().inflate(R.menu.menu_inbox, menu);

        // search
        MenuItem searchItem = menu.findItem(R.id.inbox_menu_search);
        mSearchView = (SearchView) searchItem.getActionView();
        mSearchView.setOnQueryTextListener(this);

        searchItem.setOnActionExpandListener(new OnActionExpandListener() {
            @Override
            public boolean onMenuItemActionCollapse(MenuItem item) {
                return true; // Return true to collapse action view
            }

            @Override
            public boolean onMenuItemActionExpand(MenuItem item) {
                return true; // Return true to expand action view
            }
        });

        // logout
        MenuItem logoutItem = menu.findItem(R.id.menu_log_out);
        logoutItem.setOnMenuItemClickListener(new OnMenuItemClickListener() {

            @SuppressWarnings({ "unchecked", "rawtypes" })
            @Override
            public boolean onMenuItemClick(MenuItem item) {
                switch (item.getItemId()) {
                case R.id.menu_log_out:
                    // remove stored credentials
                    AuthPreferences.storeCredentials(null);
                    // remove stored mails
                    MailConfigPreferences.saveConfiguration(null);
                    // clear authentication context
                    resetToken();
                    clearCookies();
                    // reset authenticator
                    setAuthenticator(null);
                    // clear currently displayed items
                    ((ItemsFragment) getCurrentFragment()).updateList(Collections.emptyList());
                    // clear default screen
                    ((ItemsFragment) getFragmentManager()
                            .findFragmentByTag(DEFAULT_SCREEN.getName(Office365DemoActivity.this)))
                                    .updateList(Collections.emptyList());
                    // notify current fragment that user logged out
                    ((ItemsFragment) getCurrentFragment()).notifyUserLoggedOut();

                    // open authentication activity
                    tryAuthenticate();

                default:
                    return false;
                }
            }

        });

        return true;
    } catch (Exception e) {
        Logger.logApplicationException(e, getClass().getSimpleName() + ".onCreateOptionsMenu(): Error.");
        return false;
    }
}

From source file:de.kuschku.util.ui.MenuTint.java

public void apply() {
    if (forceIcons) {
        forceMenuIcons(menu);//from  ww w .  j av  a 2s . c  o m
    }

    for (int i = 0, size = menu.size(); i < size; i++) {
        MenuItem item = menu.getItem(i);
        colorMenuItem(item, menuItemIconColor, menuItemIconAlpha);
        if (reApplyOnChange) {
            View view = item.getActionView();
            if (view != null) {
                if (item instanceof MenuItemImpl) {
                    ((MenuItemImpl) item)
                            .setSupportOnActionExpandListener(new SupportActionExpandListener(this));
                } else {
                    item.setOnActionExpandListener(new NativeActionExpandListener(this));
                }
            }
        }
    }
}

From source file:com.weebly.opus1269.copyeverywhere.ui.shared.MenuTint.java

/**
 * <p>Sets a ColorFilter and/or alpha on all the {@link MenuItem}s in the menu, including the
 * OverflowMenuButton.</p>//  w  w  w. jav  a 2 s .  c om
 * <p/>
 * <p>Call this method after inflating/creating your menu in
 * {@link Activity#onCreateOptionsMenu(Menu)}.</p>
 * <p/>
 * <p>Note: This is targeted for the native ActionBar/Toolbar, not AppCompat.</p>
 *
 * @param activity the activity to apply the menu tinting on.
 */
public void apply(final Activity activity) {

    if (forceIcons) {
        forceMenuIcons(menu);
    }

    for (int i = 0, size = menu.size(); i < size; i++) {
        MenuItem item = menu.getItem(i);
        colorMenuItem(item, menuItemIconColor, menuItemIconAlpha);
        if (reApplyOnChange) {
            View view = item.getActionView();
            if (view != null) {
                if (item instanceof MenuItemImpl) {
                    ((MenuItemImpl) item)
                            .setSupportOnActionExpandListener(new SupportActionExpandListener(this));
                } else {
                    item.setOnActionExpandListener(new NativeActionExpandListener(this));
                }
            }
        }
    }

    actionBarView = findActionBar(activity);
    if (actionBarView == null) {
        Log.w(TAG, "Could not find the ActionBar");
        return;
    }

    // We must wait for the view to be created to set a color filter on the drawables.
    actionBarView.post(new Runnable() {

        @Override
        public void run() {
            for (int i = 0, size = menu.size(); i < size; i++) {
                MenuItem menuItem = menu.getItem(i);
                if (isInOverflow(menuItem)) {
                    colorMenuItem(menuItem, subMenuIconColor, subMenuIconAlpha);
                }
                if (menuItem.hasSubMenu()) {
                    SubMenu subMenu = menuItem.getSubMenu();
                    for (int j = 0; j < subMenu.size(); j++) {
                        colorMenuItem(subMenu.getItem(j), subMenuIconColor, subMenuIconAlpha);
                    }
                }
            }
            if (menuItemIconColor != null || menuItemIconAlpha != null) {
                overflowButton = findOverflowMenuButton(activity, actionBarView);
                colorOverflowMenuItem(overflowButton);
            }
        }
    });
}