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.github.jvanhie.discogsscrobbler.SearchActivity.java

@Override
public boolean onCreateOptionsMenu(final Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.discogs_search, menu);
    //configure search box
    final MenuItem search = menu.findItem(R.id.search_field);
    mSearchView = (SearchView) search.getActionView();
    mSearchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
        @Override/*from  w  ww.java2 s.  c  o m*/
        public boolean onQueryTextSubmit(String s) {
            menu.findItem(R.id.search_field).collapseActionView();
            mLastSearch = s;
            //pass query to search fragment
            if (mSearchType > 0) {
                mSearchFragment.search(s, mSearchTypes[mSearchType]);
            } else {
                mSearchFragment.search(s);
            }
            return false;
        }

        @Override
        public boolean onQueryTextChange(String s) {
            return false;
        }
    });
    mSearchView.setOnSearchClickListener(new SearchView.OnClickListener() {
        @Override
        public void onClick(View view) {
            //restore last search
            if (mLastSearch != null) {
                mSearchView.setQuery(mLastSearch, false);
            }
        }
    });
    if (mSearchType > 0) {
        mSearchView.setQueryHint("Search Discogs (" + mSearchTypes[mSearchType] + ")");
    } else {
        mSearchView.setQueryHint("Search Discogs");
    }
    //config filter spinner
    final MenuItem filter = menu.findItem(R.id.search_filter);
    Spinner s = (Spinner) filter.getActionView(); // find the spinner
    ArrayAdapter mSpinnerAdapter = ArrayAdapter.createFromResource(getSupportActionBar().getThemedContext(),
            R.array.search_filter_items, android.R.layout.simple_spinner_dropdown_item); //  create the adapter from a StringArray
    mSpinnerAdapter.setDropDownViewResource(R.layout.spinner_dropdown_item);
    s.setAdapter(mSpinnerAdapter); // set the adapter
    s.setSelection(mSearchType, false);

    s.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
            mSearchType = i;
            PreferenceManager.getDefaultSharedPreferences(SearchActivity.this).edit()
                    .putInt(SEARCH_TYPE, mSearchType).apply();
            if (i > 0) {
                mSearchView.setQueryHint("Search Discogs (" + mSearchTypes[i] + ")");
            } else {
                mSearchView.setQueryHint("Search Discogs");
            }
            filter.collapseActionView();
            search.expandActionView();
        }

        @Override
        public void onNothingSelected(AdapterView<?> adapterView) {
            //filter.collapseActionView();
        }
    });
    //make sure only one actionview is expanded
    MenuItemCompat.setOnActionExpandListener(filter, new MenuItemCompat.OnActionExpandListener() {
        @Override
        public boolean onMenuItemActionExpand(MenuItem menuItem) {
            //collapse search
            search.collapseActionView();
            return true;
        }

        @Override
        public boolean onMenuItemActionCollapse(MenuItem menuItem) {
            return true;
        }
    });
    MenuItemCompat.setOnActionExpandListener(search, new MenuItemCompat.OnActionExpandListener() {
        @Override
        public boolean onMenuItemActionExpand(MenuItem menuItem) {
            //collapse filter
            filter.collapseActionView();
            return true;
        }

        @Override
        public boolean onMenuItemActionCollapse(MenuItem menuItem) {
            return true;
        }
    });

    //only expand when the drawer is closed and initial page load
    if (!((DrawerLayout) findViewById(R.id.search_drawer_layout)).isDrawerOpen(findViewById(R.id.search_drawer))
            && !mDetailVisible) {
        search.expandActionView();
    }

    if (mSelected > 0) {

        inflater.inflate(R.menu.release_detail_search, menu);
        if (PreferenceManager.getDefaultSharedPreferences(this).getBoolean("enable_lastfm", true)) {
            inflater.inflate(R.menu.release_detail_scrobble, menu);
        }
    }

    return true;
}

From source file:com.conferenceengineer.android.iosched.ui.tablet.SessionsSandboxMultiPaneActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    super.onCreateOptionsMenu(menu);
    getMenuInflater().inflate(R.menu.search, menu);
    MenuItem searchItem = menu.findItem(R.id.menu_search);
    if (searchItem != null && UIUtils.hasHoneycomb()) {
        SearchView searchView = (SearchView) searchItem.getActionView();
        if (searchView != null) {
            SearchManager searchManager = (SearchManager) getSystemService(SEARCH_SERVICE);
            searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
            searchView.setQueryRefinementEnabled(true);
        }/*from  www  . j  a v a2s . co  m*/
    }
    return true;
}

From source file:com.vaquerosisd.projectmanager.TaskList.java

@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    if (taskSelected)
        menu.findItem(R.id.actionBar_DeleteTaskIcon).setVisible(true);
    else//from   w  w  w. java2s.  c o m
        menu.findItem(R.id.actionBar_DeleteTaskIcon).setVisible(false);

    if (searching) {
        getActionBar().setDisplayShowTitleEnabled(false);
        menu.findItem(R.id.actionBar_SearchTaskIcon).setVisible(false);
        menu.findItem(R.id.actionBar_SearchTaskItem).setVisible(true);
        InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
        imm.toggleSoftInput(InputMethodManager.SHOW_IMPLICIT, 0);
    } else {
        getActionBar().setDisplayShowTitleEnabled(true);
        MenuItem searchItem = menu.findItem(R.id.actionBar_SearchTaskItem);
        final EditText searchProject = (EditText) searchItem.getActionView()
                .findViewById(R.id.actionBar_SearchItemEditText);
        searchProject.setText("");
        menu.findItem(R.id.actionBar_SearchTaskIcon).setVisible(true);
        menu.findItem(R.id.actionBar_SearchTaskItem).setVisible(false);
    }

    MenuItem logMenuItem = menu.findItem(R.id.actionBar_Menu_user);
    if (currentUser != null) {
        logMenuItem.setTitle("Log Out from " + currentUser.getUsername());
    } else {
        checkUser();
    }

    return true;
}

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 {/*  ww  w  .j av  a  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:com.hybris.mobile.activity.StoreLocatorActivity.java

/**
 * Menu methods//from w w w.  j a v a  2  s.  c o m
 */
@Override
public boolean onCreateOptionsMenu(final Menu menu) {
    MenuInflater inflater = this.getMenuInflater();
    inflater.inflate(R.menu.store_finder, menu);

    SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
    MenuItem searchViewMenuItem = menu.findItem(R.id.store_search);
    this.mSearchView = searchViewMenuItem;
    SearchView searchView = ((SearchView) searchViewMenuItem.getActionView());

    searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
    searchView.setIconifiedByDefault(true);
    searchView.setQueryHint(getResources().getString(R.string.store_search_hint));
    searchView.setOnQueryTextListener(this);

    return true;
}

From source file:com.kccomy.orgar.ui.files.FileListFragment.java

@Override
public void onPrepareOptionsMenu(Menu menu) {
    MenuItem search = menu.findItem(R.id.action_search_file);
    search.collapseActionView();//from w  w w  . j a  v  a2 s. co  m

    searchView = (SearchView) search.getActionView();
    // Don't cover App Label
    searchView.setMaxWidth(600);
    searchView.setIconified(true);
    searchView.setIconifiedByDefault(true);
    // set input text color
    SearchView.SearchAutoComplete textView = (SearchView.SearchAutoComplete) searchView
            .findViewById(R.id.search_src_text);
    textView.setTextColor(getResources().getColor(R.color.colorPrimaryDark));

    searchView.setOnSearchClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            showRecentSearchView();
            fab.hide();
        }
    });

    searchView.setOnCloseListener(new SearchView.OnCloseListener() {
        @Override
        public boolean onClose() {
            showFileListView();
            fab.show();
            return false;
        }
    });

    searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
        @Override
        public boolean onQueryTextSubmit(String query) {
            recentAdapter.addItem(query);
            return false;
        }

        @Override
        public boolean onQueryTextChange(String newText) {
            if (!TextUtils.isEmpty(newText)) {
                showSearchResultView();
                presenter.processQuery(fileAdapter.getFiles(), newText);
            } else {
                showRecentSearchView();
            }
            return false;
        }
    });

    super.onPrepareOptionsMenu(menu);
}

From source file:ua.org.gdg.devfest.iosched.ui.HomeActivity.java

@TargetApi(Build.VERSION_CODES.HONEYCOMB)
@Override/*from   w  ww  .j a va  2 s. co  m*/
public boolean onCreateOptionsMenu(Menu menu) {
    super.onCreateOptionsMenu(menu);
    mOptionsMenu = menu;
    getMenuInflater().inflate(R.menu.home, menu);
    MenuItem searchItem = menu.findItem(R.id.menu_search);
    if (searchItem != null && UIUtils.hasHoneycomb()) {
        SearchView searchView = (SearchView) searchItem.getActionView();
        if (searchView != null) {
            SearchManager searchManager = (SearchManager) getSystemService(SEARCH_SERVICE);
            searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
            searchView.setQueryRefinementEnabled(true);
        }
    }
    return true;
}

From source file:com.foodie.app.Activity.MainActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.home_actions, menu);
    SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
    MenuItem searchMenuItem = menu.findItem(R.id.id_action_search);
    SearchView searchView = null;/*from  w  w  w .j a  v a  2s . co  m*/
    if (searchMenuItem != null) {
        searchView = (SearchView) searchMenuItem.getActionView();
    }
    if (searchView != null) {
        searchView.setSearchableInfo(searchManager.getSearchableInfo(MainActivity.this.getComponentName()));
    }
    SearchView.SearchAutoComplete searchAutoComplete = (SearchView.SearchAutoComplete) searchView
            .findViewById(android.support.v7.appcompat.R.id.search_src_text);
    searchAutoComplete.setHintTextColor(Color.WHITE);
    searchAutoComplete.setTextColor(Color.WHITE);
    searchAutoComplete.setHint("?,,");
    //?
    searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
        @Override
        public boolean onQueryTextSubmit(String query) {
            //Toast.makeText(MainActivity.this,""+query,Toast.LENGTH_SHORT).show();
            Intent intent = new Intent(MainActivity.this, SearchResultsActivity.class);
            intent.putExtra("query", query);
            startActivity(intent);
            return true;
        }

        @Override
        public boolean onQueryTextChange(String newText) {
            //Toast.makeText(MainActivity.this,""+newText,Toast.LENGTH_SHORT).show();
            return false;
        }
    });
    //??
    View searchplate = (View) searchView.findViewById(android.support.v7.appcompat.R.id.search_plate);
    //searchplate.setBackgroundResource(R.drawable.ic_search_white_24dp);

    ImageView searchCloseIcon = (ImageView) searchView
            .findViewById(android.support.v7.appcompat.R.id.search_close_btn);
    searchCloseIcon.setImageResource(R.drawable.ic_close_white_24dp);

    ImageView voiceIcon = (ImageView) searchView
            .findViewById(android.support.v7.appcompat.R.id.search_voice_btn);
    voiceIcon.setImageResource(R.drawable.ic_settings_voice_white_24dp);

    //searchView.setSubmitButtonEnabled(true); // to enable submit button

    ImageView b = (ImageView) searchView.findViewById(android.support.v7.appcompat.R.id.search_button);
    b.setImageResource(R.drawable.ic_search_white_24dp); //to change submit button icon

    ImageView searchIcon = (ImageView) searchView
            .findViewById(android.support.v7.appcompat.R.id.search_mag_icon);
    searchIcon.setImageResource(R.drawable.ic_search_white_24dp);

    switch (currentTab) {
    case 0:
        MenuItem miMap = menu.findItem(R.id.id_action_map);
        miMap.setVisible(false);
        break;
    case 1:
        MenuItem miSearch = menu.findItem(R.id.id_action_search);
        miSearch.setVisible(false);
        break;
    case 2:
        MenuItem mi1 = menu.findItem(R.id.id_action_map);
        mi1.setVisible(false);
        MenuItem mi2 = menu.findItem(R.id.id_action_search);
        mi2.setVisible(false);
    case 3:
        MenuItem mi3 = menu.findItem(R.id.id_action_map);
        mi3.setVisible(false);
        MenuItem mi4 = menu.findItem(R.id.id_action_search);
        mi4.setVisible(false);
        break;
    default:
        break;
    }

    return true;
}

From source file:com.vaquerosisd.projectmanager.TaskList.java

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

    MenuItem searchItem = menu.findItem(R.id.actionBar_SearchTaskItem);
    Button clearSearchTask = (Button) searchItem.getActionView().findViewById(R.id.actionBar_ClearSearch);
    final AutoCompleteTextView searchTask = (AutoCompleteTextView) searchItem.getActionView()
            .findViewById(R.id.actionBar_SearchItemEditText);

    //Get all tasks names and add them to an adapter for the AutoCompleteTextView
    List<Task> allTasks = db.getAllTasks(projectId);
    String[] tasksNames = new String[allTasks.size()];
    for (int i = 0; i < allTasks.size(); i++)
        tasksNames[i] = allTasks.get(i).getTaskName();

    ArrayAdapter<String> tasksAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1,
            tasksNames);/*from   w  w  w.j  a  va  2  s.  c o  m*/
    searchTask.setAdapter(tasksAdapter);
    searchTask.setThreshold(1);

    //Clear text of search AutoCompleteTextView
    clearSearchTask.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            searchTask.setText("");
        }
    });

    searchTask.setOnFocusChangeListener(new OnFocusChangeListener() {

        @Override
        public void onFocusChange(View v, boolean hasFocus) {
            if (hasFocus) {
                InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
                imm.toggleSoftInput(InputMethodManager.SHOW_IMPLICIT, 0);
            } else {
                InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
                imm.toggleSoftInput(InputMethodManager.HIDE_IMPLICIT_ONLY, 0);
            }
        }
    });

    //Search task
    searchTask.setOnEditorActionListener(new OnEditorActionListener() {
        @Override
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            //When the user press "DONE" key, select the task
            if (actionId == EditorInfo.IME_ACTION_DONE) {
                String project = searchTask.getText().toString();
                searchTask(project);
                //Hide keyboard
                InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
                imm.hideSoftInputFromWindow(searchTask.getWindowToken(), InputMethodManager.HIDE_IMPLICIT_ONLY);
                return true;
            }
            return false;
        }
    });
    return true;
}

From source file:de.qspool.clementineremote.ui.fragments.GlobalSearchFragment.java

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    menu.clear();//from  ww  w. jav  a2 s  .  co  m

    inflater.inflate(R.menu.global_search_menu, menu);

    // Create a listener for search change
    final MenuItem search = menu.findItem(R.id.global_search_menu_search);
    final SearchView searchView = (SearchView) search.getActionView();
    searchView.setIconifiedByDefault(true);
    searchView.setIconified(false);

    final SearchView.OnQueryTextListener queryTextListener = new SearchView.OnQueryTextListener() {
        @Override
        public boolean onQueryTextChange(String newText) {
            return false;
        }

        @Override
        public boolean onQueryTextSubmit(String query) {
            mSwipeRefreshLayout.setRefreshing(true);
            mEmptyView.setRefreshing(true);

            Message msg = Message.obtain();

            msg.obj = ClementineMessageFactory.buildGlobalSearch(query);
            App.ClementineConnection.mHandler.sendMessage(msg);

            hideSoftInput();

            // Set the actionbar title
            mActionBar.setTitle(getResources().getString(R.string.global_search_query, query));
            mActionBar.setSubtitle("/");

            // Query must be empty in order to collapse the search view.
            searchView.setQuery("", false);
            searchView.setIconified(true);

            // Remove currently present adapters
            mAdapters.clear();
            showList();

            return true;
        }
    };
    searchView.setOnQueryTextListener(queryTextListener);
    searchView.setQueryHint(getString(R.string.global_search_search));

    EditText searchText = (EditText) searchView.findViewById(android.support.v7.appcompat.R.id.search_src_text);
    searchText.setHintTextColor(ContextCompat.getColor(getActivity(), R.color.searchview_edittext_hint));

    super.onCreateOptionsMenu(menu, inflater);
}