List of usage examples for android.view MenuItem expandActionView
public boolean expandActionView();
From source file:org.xbmc.kore.ui.AbstractCursorListFragment.java
private void setupSearchMenuItem(Menu menu, MenuInflater inflater) { inflater.inflate(R.menu.media_search, menu); MenuItem searchMenuItem = menu.findItem(R.id.action_search); if (searchMenuItem != null) { searchView = (SearchView) MenuItemCompat.getActionView(searchMenuItem); searchView.setOnQueryTextListener(this); searchView.setQueryHint(getString(R.string.action_search)); if ((savedSearchFilter != null) && (!TextUtils.isEmpty(savedSearchFilter))) { searchMenuItem.expandActionView(); searchView.setQuery(savedSearchFilter, false); searchView.clearFocus();/*w w w . jav a2 s . com*/ } MenuItemCompat.setOnActionExpandListener(searchMenuItem, new MenuItemCompat.OnActionExpandListener() { @Override public boolean onMenuItemActionExpand(MenuItem item) { return true; } @Override public boolean onMenuItemActionCollapse(MenuItem item) { searchFilter = savedSearchFilter = null; restartLoader(); return true; } }); } //Handle clearing search query using the close button (X button). View view = searchView.findViewById(R.id.search_close_btn); if (view != null) { view.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { EditText editText = (EditText) searchView.findViewById(R.id.search_src_text); editText.setText(""); searchView.setQuery("", false); searchFilter = savedSearchFilter = ""; restartLoader(); } }); } }
From source file:fr.cph.chicago.activity.MainActivity.java
@Override public final boolean onOptionsItemSelected(final MenuItem item) { switch (item.getItemId()) { case R.id.action_refresh: if (mCurrentPosition != POSITION_DIVVY && mCurrentPosition != POSITION_NEARBY && mCurrentPosition != POSITION_ALERTS) { MenuItem menuItem = item; menuItem.setActionView(R.layout.progressbar); menuItem.expandActionView(); SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(MainActivity.this); boolean loadTrain = sharedPref.getBoolean("cta_train", true); boolean loadBus = sharedPref.getBoolean("cta_bus", true); boolean loadBike = sharedPref.getBoolean("divvy_bike", true); boolean loadAlert = sharedPref.getBoolean("cta_alert", true); MultiMap<String, String> params = new MultiValueMap<String, String>(); List<Integer> trainFavorites = Preferences .getTrainFavorites(ChicagoTracker.PREFERENCE_FAVORITES_TRAIN); for (Integer fav : trainFavorites) { params.put("mapid", String.valueOf(fav)); }/*from w ww . ja v a2s . com*/ MultiMap<String, String> params2 = new MultiValueMap<String, String>(); List<String> busFavorites = Preferences.getBusFavorites(ChicagoTracker.PREFERENCE_FAVORITES_BUS); for (String str : busFavorites) { String[] fav = Util.decodeBusFavorite(str); params2.put("rt", fav[0]); params2.put("stpid", fav[1]); } GlobalConnectTask task; try { task = new GlobalConnectTask(mFavoritesFragment, FavoritesFragment.class, CtaRequestType.TRAIN_ARRIVALS, params, CtaRequestType.BUS_ARRIVALS, params2, loadTrain, loadBus, loadBike); task.execute((Void) null); } catch (ParserException e) { ChicagoTracker.displayError(this, e); return true; } // Google analytics if (loadTrain) { Util.trackAction(MainActivity.this, R.string.analytics_category_req, R.string.analytics_action_get_train, R.string.analytics_action_get_train_arrivals, 0); } if (loadBus) { Util.trackAction(MainActivity.this, R.string.analytics_category_req, R.string.analytics_action_get_bus, R.string.analytics_action_get_bus_arrival, 0); } if (loadBike) { Util.trackAction(MainActivity.this, R.string.analytics_category_req, R.string.analytics_action_get_divvy, R.string.analytics_action_get_divvy_all, 0); } // Check if bus/bike or alert data are not loaded. If not, load them. // Can happen when the app has been loaded without any data connection boolean loadData = false; DataHolder dataHolder = DataHolder.getInstance(); BusData busData = dataHolder.getBusData(); AlertData alertData = dataHolder.getAlertData(); Bundle bundle = getIntent().getExtras(); List<BikeStation> bikeStations = bundle.getParcelableArrayList("bikeStations"); if (loadBus && busData.getRoutes() != null && busData.getRoutes().size() == 0) { loadData = true; } if (!loadData && loadAlert && alertData.getAlerts() != null && alertData.getAlerts().size() == 0) { loadData = true; } if (!loadData && loadBike && bikeStations == null) { loadData = true; } if (loadData) { startRefreshAnimation(); new LoadData().execute(); } Util.trackAction(this, R.string.analytics_category_ui, R.string.analytics_action_press, R.string.analytics_action_refresh_fav, 0); } else if (mCurrentPosition == POSITION_NEARBY) { mNearbyFragment.reloadData(); Util.trackAction(this, R.string.analytics_category_ui, R.string.analytics_action_press, R.string.analytics_action_refresh_nearby, 0); } return false; case R.id.action_search: Util.trackAction(this, R.string.analytics_category_ui, R.string.analytics_action_press, R.string.analytics_action_search, 0); return true; } return super.onOptionsItemSelected(item); }
From source file:com.zprogrammer.tool.ui.SearchActivity.java
@Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.menu_search, menu); MenuItem searchItem = menu.findItem(R.id.action_search);//??item final SearchView searchView = (SearchView) MenuItemCompat.getActionView(searchItem); int id = searchView.getContext().getResources().getIdentifier("search_src_text", "id", BuildConfig.APPLICATION_ID); final EditText editText = (EditText) searchView.findViewById(id); editText.setTextColor(Color.WHITE); MenuItemCompat.setOnActionExpandListener(searchItem, new MenuItemCompat.OnActionExpandListener() { @Override/*from w w w.jav a2 s. com*/ public boolean onMenuItemActionExpand(MenuItem item) { return true; } @Override public boolean onMenuItemActionCollapse(MenuItem item) { ActivityCompat.finishAfterTransition(SearchActivity.this); return true; } }); searchItem.expandActionView(); searchView.setQuery(queryText, false); searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() { @Override public boolean onQueryTextSubmit(String query) { queryText = query; queryDatas(null); return true; } @Override public boolean onQueryTextChange(String newText) { return false; } }); return true; }
From source file:com.fbartnitzek.tasteemall.MainActivity.java
@Override public boolean onCreateOptionsMenu(Menu menu) { Log.v(LOG_TAG, "onCreateOptionsMenu, hashCode=" + this.hashCode() + ", " + "menu = [" + menu + "], searchPattern=" + mSearchPattern); getMenuInflater().inflate(R.menu.menu_main, menu); final MenuItem item = menu.findItem(R.id.search_all); SearchView searchView = (SearchView) MenuItemCompat.getActionView(item); searchView.setOnQueryTextListener(this); // todo: restore the right way... - still not working - should work!...? if (!TextUtils.isEmpty(mSearchPattern)) { item.expandActionView(); searchView.setQuery(mSearchPattern, true); searchView.clearFocus();/* w w w. j a va2s.c om*/ // restartCurrentFragmentLoader(); } return true; }
From source file:com.geecko.QuickLyric.fragment.LyricsViewFragment.java
@Override public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { super.onCreateOptionsMenu(menu, inflater); MainActivity mainActivity = (MainActivity) getActivity(); if (mainActivity == null) return;// w w w . j a v a2 s . co m CollapsingToolbarLayout toolbarLayout = (CollapsingToolbarLayout) mainActivity .findViewById(R.id.toolbar_layout); toolbarLayout.setTitle(getString(R.string.app_name)); if (((DrawerLayout) mainActivity.drawer) // drawer is locked .getDrawerLockMode(mainActivity.drawerView) == DrawerLayout.LOCK_MODE_LOCKED_CLOSED) return; inflater.inflate(lyrics, menu); // Get the SearchView and set the searchable configuration final MaterialSuggestionsSearchView materialSearchView = (MaterialSuggestionsSearchView) mainActivity .findViewById(R.id.material_search_view); materialSearchView.setOnQueryTextListener(new MaterialSearchView.OnQueryTextListener() { @Override public boolean onQueryTextSubmit(final String query) { materialSearchView.setSuggestions(null); materialSearchView.requestFocus(); materialSearchView.post(new Runnable() { @Override public void run() { ((InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE)) .hideSoftInputFromWindow(materialSearchView.getWindowToken(), 0); } }); materialSearchView.postDelayed(new Runnable() { @Override public void run() { ((MainActivity) getActivity()).search(query); materialSearchView.setSuggestions(null); } }, 90); mExpandedSearchView = false; return true; } @Override public boolean onQueryTextChange(String newText) { if (!materialSearchView.hasSuggestions()) materialSearchView.setSuggestions(materialSearchView.getHistory()); return true; } }); materialSearchView.setOnSearchViewListener(new MaterialSearchView.SearchViewListener() { @Override public void onSearchViewShown() { if (getActivity() == null) return; ((ControllableAppBarLayout) getActivity().findViewById(R.id.appbar)).expandToolbar(true); mExpandedSearchView = true; } @Override public void onSearchViewClosed() { mExpandedSearchView = false; } }); final Resources resources = getResources(); final int resourceId = resources.getIdentifier("status_bar_height", "dimen", "android"); int statusBarHeight; if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.LOLLIPOP) statusBarHeight = 0; else if (resourceId > 0) statusBarHeight = resources.getDimensionPixelSize(resourceId); else statusBarHeight = (int) Math.ceil((Build.VERSION.SDK_INT >= Build.VERSION_CODES.M ? 24 : 25) * resources.getDisplayMetrics().density); CoordinatorLayout.LayoutParams lp = (CoordinatorLayout.LayoutParams) materialSearchView.getLayoutParams(); lp.setMargins(lp.leftMargin, statusBarHeight, lp.rightMargin, lp.bottomMargin); materialSearchView.setLayoutParams(lp); MenuItem searchItem = menu.findItem(R.id.action_search); materialSearchView.setMenuItem(searchItem); if (!materialSearchView.isSearchOpen() && mExpandedSearchView) { materialSearchView.showSearch(); mExpandedSearchView = false; } else if (!mExpandedSearchView) materialSearchView.closeSearch(); materialSearchView.setHint(getString(R.string.search_hint)); if (mSearchQuery != null && !mSearchQuery.equals("")) { searchItem.expandActionView(); materialSearchView.setQuery(mSearchQuery, false); if (mSearchFocused) materialSearchView.requestFocus(); else materialSearchView.clearFocus(); mSearchQuery = null; } Lyrics storedLyrics = mLyrics == null ? null : DatabaseHelper.getInstance(getActivity()).get(new String[] { mLyrics.getArtist(), mLyrics.getTitle(), mLyrics.getOriginalArtist(), mLyrics.getOriginalTrack() }); MenuItem saveMenuItem = menu.findItem(R.id.save_action); if (saveMenuItem != null) { SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(getActivity()); if (mLyrics == null) saveMenuItem.setVisible(false); else if (mLyrics.getFlag() == Lyrics.POSITIVE_RESULT && sharedPref.getBoolean("pref_auto_save", true)) { if (storedLyrics == null || (mLyrics.isLRC() && !storedLyrics.isLRC())) { lyricsPresentInDB = true; new WriteToDatabaseTask().execute(this, saveMenuItem, mLyrics); } saveMenuItem.setVisible(false); } else { saveMenuItem.setIcon(lyricsPresentInDB ? R.drawable.ic_trash : R.drawable.ic_save); saveMenuItem.setTitle(lyricsPresentInDB ? R.string.remove_action : R.string.save_action); } } MenuItem resyncMenuItem = menu.findItem(R.id.resync_action); MenuItem convertMenuItem = menu.findItem(R.id.convert_action); if (resyncMenuItem != null) resyncMenuItem.setVisible(mLyrics != null && mLyrics.isLRC()); if (convertMenuItem != null) { Lyrics stored = mLyrics == null || mLyrics.isLRC() ? null : storedLyrics; convertMenuItem .setVisible((mLyrics != null && (mLyrics.isLRC())) || (stored != null && stored.isLRC())); convertMenuItem.setTitle(stored == null ? R.string.full_text_action : R.string.pref_lrc); } MenuItem shareMenuItem = menu.findItem(R.id.share_action); if (shareMenuItem != null) shareMenuItem.setVisible( mLyrics != null && mLyrics.getFlag() == Lyrics.POSITIVE_RESULT && mLyrics.getURL() != null); }
From source file:nl.mpcjanssen.simpletask.Simpletask.java
@Override public boolean onSearchRequested() { MenuItem searchMenuItem = options_menu.findItem(R.id.search); searchMenuItem.expandActionView(); return true;//from w w w .j a v a 2 s. c om }
From source file:org.sufficientlysecure.keychain.ui.ImportKeysSearchFragment.java
@Override public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { inflater.inflate(R.menu.import_keys_cloud_fragment, menu); MenuItem searchItem = menu.findItem(R.id.menu_import_keys_cloud_search); final SearchView searchView = (SearchView) MenuItemCompat.getActionView(searchItem); searchView.setSuggestionsAdapter(mSearchAdapter); searchView.setOnSuggestionListener(new OnSuggestionListener() { @Override/*from w w w .j a v a2s. co m*/ public boolean onSuggestionSelect(int position) { searchView.setQuery(mCurrentSuggestions.get(position), true); return true; } @Override public boolean onSuggestionClick(int position) { searchView.setQuery(mCurrentSuggestions.get(position), true); return true; } }); searchView.setOnQueryTextListener(new OnQueryTextListener() { @Override public boolean onQueryTextSubmit(String query) { searchView.clearFocus(); search(searchView.getQuery().toString().trim()); return true; } @Override public boolean onQueryTextChange(String newText) { updateAdapter(newText); return false; } }); MenuItemCompat.setOnActionExpandListener(searchItem, new OnActionExpandListener() { @Override public boolean onMenuItemActionExpand(MenuItem item) { return true; } @Override public boolean onMenuItemActionCollapse(MenuItem item) { mActivity.finish(); return true; } }); searchItem.expandActionView(); String query = getArguments().getString(ARG_QUERY); if (query != null) { searchView.setQuery(query, false); } super.onCreateOptionsMenu(menu, inflater); }
From source file:in.andres.kandroid.ui.TaskEditActivity.java
@Override public boolean onOptionsItemSelected(MenuItem item) { int id = item.getItemId(); switch (id) { case android.R.id.home: onBackPressed();// ww w . ja v a 2 s. c o m return true; case R.id.action_save: ownerId = spinnerProjectUsers.getSelectedItemPosition(); if (spinnerProjectUsers.getSelectedItemPosition() != 0) { for (Enumeration<Integer> iter = projectUsers.keys(); iter.hasMoreElements();) { Integer key = iter.nextElement(); if (projectUsers.get(key).contentEquals((String) spinnerProjectUsers.getSelectedItem())) { ownerId = key; break; } } } if (isNewTask) { kanboardAPI.createTask(editTextTitle.getText().toString(), projectid, colorId != null ? colorId : defaultColor, columnId, ownerId, null, dueDate, editTextDescription.getText().toString(), null, null, swimlaneId, null, null, null, null, null, null, null, startDate); } else { kanboardAPI.updateTask(task.getId(), editTextTitle.getText().toString(), colorId != null ? colorId : defaultColor, ownerId, dueDate, editTextDescription.getText().toString(), null, null, null, null, null, null, null, null, null, startDate); } ProgressBar prog = new ProgressBar(TaskEditActivity.this); prog.getIndeterminateDrawable().setColorFilter(Color.WHITE, android.graphics.PorterDuff.Mode.MULTIPLY); item.setActionView(prog); item.expandActionView(); return true; default: return super.onOptionsItemSelected(item); } }
From source file:cn.edu.wyu.documentviewer.DocumentsActivity.java
@Override public boolean onPrepareOptionsMenu(Menu menu) { super.onPrepareOptionsMenu(menu); final FragmentManager fm = getFragmentManager(); final RootInfo root = getCurrentRoot(); final DocumentInfo cwd = getCurrentDirectory(); final MenuItem createDir = menu.findItem(R.id.menu_create_dir); final MenuItem search = menu.findItem(R.id.menu_search); final MenuItem sort = menu.findItem(R.id.menu_sort); final MenuItem sortSize = menu.findItem(R.id.menu_sort_size); final MenuItem grid = menu.findItem(R.id.menu_grid); final MenuItem list = menu.findItem(R.id.menu_list); final MenuItem settings = menu.findItem(R.id.menu_settings); // Open drawer means we hide most actions if (isRootsDrawerOpen()) { createDir.setVisible(false);//from w w w. ja v a2 s.co m search.setVisible(false); sort.setVisible(false); grid.setVisible(false); list.setVisible(false); mIgnoreNextCollapse = true; search.collapseActionView(); return true; } sort.setVisible(cwd != null); grid.setVisible(mState.derivedMode != MODE_GRID); list.setVisible(mState.derivedMode != MODE_LIST); if (mState.currentSearch != null) { // Search uses backend ranking; no sorting sort.setVisible(false); search.expandActionView(); mSearchView.setIconified(false); mSearchView.clearFocus(); mSearchView.setQuery(mState.currentSearch, false); } else { mIgnoreNextClose = true; mSearchView.setIconified(true); mSearchView.clearFocus(); mIgnoreNextCollapse = true; search.collapseActionView(); } // Only sort by size when visible sortSize.setVisible(mState.showSize); final boolean searchVisible; if (mState.action == ACTION_CREATE) { createDir.setVisible(cwd != null && cwd.isCreateSupported()); searchVisible = false; // No display options in recent directories if (cwd == null) { grid.setVisible(false); list.setVisible(false); } SaveFragment.get(fm).setSaveEnabled(cwd != null && cwd.isCreateSupported()); } else { createDir.setVisible(false); searchVisible = root != null && ((root.flags & Root.FLAG_SUPPORTS_SEARCH) != 0); } // TODO: close any search in-progress when hiding search.setVisible(searchVisible); settings.setVisible(mState.action != ACTION_MANAGE); return true; }
From source file:dev.dworks.apps.anexplorer.DocumentsActivity.java
@Override public boolean onPrepareOptionsMenu(Menu menu) { super.onPrepareOptionsMenu(menu); final FragmentManager fm = getFragmentManager(); final RootInfo root = getCurrentRoot(); final DocumentInfo cwd = getCurrentDirectory(); final MenuItem createDir = menu.findItem(R.id.menu_create_dir); //final MenuItem createFile = menu.findItem(R.id.menu_create_file); final MenuItem search = menu.findItem(R.id.menu_search); final MenuItem sort = menu.findItem(R.id.menu_sort); final MenuItem sortSize = menu.findItem(R.id.menu_sort_size); final MenuItem grid = menu.findItem(R.id.menu_grid); final MenuItem list = menu.findItem(R.id.menu_list); final MenuItem settings = menu.findItem(R.id.menu_settings); // Open drawer means we hide most actions if (isRootsDrawerOpen()) { createDir.setVisible(false);// w w w . ja v a 2s. c o m //createFile.setVisible(false); search.setVisible(false); sort.setVisible(false); grid.setVisible(false); list.setVisible(false); mIgnoreNextCollapse = true; search.collapseActionView(); return true; } sort.setVisible(cwd != null); grid.setVisible(mState.derivedMode != MODE_GRID); list.setVisible(mState.derivedMode != MODE_LIST); if (mState.currentSearch != null) { // Search uses backend ranking; no sorting sort.setVisible(false); search.expandActionView(); mSearchView.setIconified(false); mSearchView.clearFocus(); mSearchView.setQuery(mState.currentSearch, false); } else { mIgnoreNextClose = true; mSearchView.setIconified(true); mSearchView.clearFocus(); mIgnoreNextCollapse = true; search.collapseActionView(); } // Only sort by size when visible sortSize.setVisible(mState.showSize); final boolean searchVisible; if (mState.action == ACTION_CREATE) { createDir.setVisible(cwd != null && cwd.isCreateSupported()); //createFile.setVisible(cwd != null && cwd.isCreateSupported()); searchVisible = false; // No display options in recent directories if (cwd == null) { grid.setVisible(false); list.setVisible(false); } if (null != SaveFragment.get(fm)) SaveFragment.get(fm).setSaveEnabled(cwd != null && cwd.isCreateSupported()); } else if (mState.action == ACTION_GET_CONTENT) { createDir.setVisible(false); searchVisible = root != null && ((root.flags & Root.FLAG_SUPPORTS_SEARCH) != 0); } else { createDir.setVisible(cwd != null && cwd.isCreateSupported()); //createFile.setVisible(cwd != null && cwd.isCreateSupported()); //createDir.setVisible(false); searchVisible = root != null && ((root.flags & Root.FLAG_SUPPORTS_SEARCH) != 0); if (null != SaveFragment.get(fm)) SaveFragment.get(fm).setSaveEnabled(cwd != null && cwd.isCreateSupported()); if (null != MoveFragment.get(fm)) MoveFragment.get(fm).setSaveEnabled(cwd != null && cwd.isEditSupported()); } // TODO: close any search in-progress when hiding search.setVisible(searchVisible); settings.setVisible(mState.action != ACTION_MANAGE); return true; }