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.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  ww  w. j  a  va 2s  .c  om*/
    sv.setIconifiedByDefault(true);

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

From source file:com.anadoluuniversity.tinyreader.OcrCaptureActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {

    if (getSupportFragmentManager().findFragmentByTag("FragmentCamera") != null
            && getSupportFragmentManager().findFragmentByTag("FragmentCamera").isVisible()) {
        MenuInflater inflater = getMenuInflater();
        inflater.inflate(R.menu.menu_search, menu);
        MenuItem item = menu.findItem(R.id.menuSearch);

        SearchView searchView = (SearchView) item.getActionView();

        searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
            @Override/*from  ww  w.j  a v  a  2s. c o m*/
            public boolean onQueryTextSubmit(String query) {
                Log.d("searchbar_submit", query);
                wordToSearch = query;
                return false;
            }

            @Override
            public boolean onQueryTextChange(String newText) {
                return false;
            }
        });
    }

    return super.onCreateOptionsMenu(menu);
}

From source file:com.demo.android.smsapp.activities.SMSChatActivity.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_chat, menu);

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

    SearchView searchView = (SearchView) item.getActionView();
    searchView.setQueryHint(getResources().getString(R.string.hint_search));
    searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
        @Override/* w  w  w  . j  av a  2  s. c om*/
        public boolean onQueryTextSubmit(String query) {
            return false;
        }

        @Override
        public boolean onQueryTextChange(String newText) {
            smsModelsSearch = new ArrayList<SMSModel>();
            for (int i = 0; i < smsModels.size(); i++) {
                if (smsModels.get(i).getBody().toLowerCase().contains(newText.toLowerCase())) {
                    smsModelsSearch.add(smsModels.get(i));
                }
            }
            smsChatsAdapter = new SMSChatsAdapter(SMSChatActivity.this, smsModelsSearch);
            recyclerView.setAdapter(smsChatsAdapter);
            smsChatsAdapter.notifyDataSetChanged();
            return false;
        }
    });
    return true;
}

From source file:org.openmrs.mobile.activities.lastviewedpatients.LastViewedPatientsActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    super.onCreateOptionsMenu(menu);
    getMenuInflater().inflate(R.menu.find_patients_remote_menu, menu);
    MenuItem mFindPatientMenuItem = menu.findItem(R.id.actionSearchRemote);
    if (OpenMRS.getInstance().isRunningHoneycombVersionOrHigher()) {
        findPatientView = (SearchView) mFindPatientMenuItem.getActionView();
    } else {// ww  w.j av  a  2  s .  com
        findPatientView = (SearchView) MenuItemCompat.getActionView(mFindPatientMenuItem);
    }

    if (StringUtils.notEmpty(query)) {
        mFindPatientMenuItem.expandActionView();
        findPatientView.setQuery(query, true);
        findPatientView.clearFocus();
    }

    // Search function
    findPatientView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
        @Override
        public boolean onQueryTextSubmit(String query) {
            mPresenter.findPatients(query);
            return true;
        }

        // This listener restores last viewed list to initial state when query is empty or SearchView is closed.
        @Override
        public boolean onQueryTextChange(String query) {
            mPresenter.updateLastViewedList(query);
            return true;
        }
    });

    findPatientView.addOnAttachStateChangeListener(new View.OnAttachStateChangeListener() {
        @Override
        public void onViewAttachedToWindow(View view) {
            // nothing to do
        }

        @Override
        public void onViewDetachedFromWindow(View view) {
            ((LastViewedPatientsPresenter) mPresenter).setLastQueryEmpty();
        }
    });

    return true;
}

From source file:ru.lizaalert.common.ui.MainActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the options menu from XML
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.yp_menu, menu);

    // Get the SearchView and set the searchable configuration
    SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
    MenuItem item = menu.findItem(R.id.action_search);
    SearchView searchView = (SearchView) item.getActionView();

    // Assumes current activity is the searchable activity
    assert searchView != null;
    assert searchManager != null;
    searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
    //        searchView.setIconifiedByDefault(false);

    return true;/*from w  w w .j  a  v  a 2  s  . c  o  m*/
}

From source file:org.schabi.newpipe.search_fragment.SearchInfoItemFragment.java

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    super.onCreateOptionsMenu(menu, inflater);
    inflater.inflate(R.menu.search_menu, menu);

    MenuItem searchItem = menu.findItem(R.id.action_search);
    searchView = (SearchView) searchItem.getActionView();
    setupSearchView(searchView);//from  w  ww.j  av  a  2s  .  co  m
}

From source file:rus.cpuinfo.Ui.Fragments.Base.CpuInfoBaseTabFragment.java

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    super.onCreateOptionsMenu(menu, inflater);

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

    MenuItem menuItem = menu.getItem(0);
    menuItem.setActionView(R.layout.include_app_comat_spinner);

    mSpinner = (AppCompatSpinner) menuItem.getActionView();
    mSpinner.setOnItemSelectedListener(this);
    mTabLayout.setOnTabSelectedListener(this);

    mSpinner.setSelection(mCurrentItem);

    if (getResources().getConfiguration().orientation == ORIENTATION_PORTRAIT) {
        menuItem.setVisible(false);//  w w w. j  a va  2  s  .  c o  m
    }
}

From source file:com.androguide.honamicontrol.kernel.KernelFragment.java

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    inflater.inflate(R.menu.profiles, menu);
    MenuItem item = menu.findItem(R.id.profile_spinner);
    View spinner = item != null ? item.getActionView() : null;
    if (spinner instanceof android.widget.Spinner) {
        final SharedPreferences profilePrefs = super.getActivity().getSharedPreferences("PROFILES", 0);
        Spinner profiles = (Spinner) spinner;
        profiles.setAdapter(ArrayAdapter.createFromResource(super.getActivity(), R.array.profiles_array,
                R.layout.spinner_action_row));
        profiles.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {

            @Override//from w  ww.j av  a 2  s . c o m
            public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
                final int currProfile = profilePrefs.getInt("CURR_PROFILE", 5);
                ActionBarActivity context = (ActionBarActivity) getActivity();
                switch (i) {
                case 0:
                    if (profileCounter > 0 && i != currProfile)
                        ProfileEnabler.enableProfile(new BatteryMaxProfile(), context);
                    profileCounter++;
                    break;
                case 1:
                    if (profileCounter > 0 && i != currProfile)
                        ProfileEnabler.enableProfile(new BatteryProfile(), context);
                    profileCounter++;
                    break;
                case 2:
                    if (profileCounter > 0 && i != currProfile)
                        ProfileEnabler.enableProfile(new BalancedProfile(), context);
                    profileCounter++;
                    break;
                case 3:
                    if (profileCounter > 0 && i != currProfile)
                        ProfileEnabler.enableProfile(new PerformanceProfile(), context);
                    profileCounter++;
                    break;
                case 4:
                    if (profileCounter > 0 && i != currProfile)
                        ProfileEnabler.enableProfile(new BenchmarkProfile(), context);
                    profileCounter++;
                    break;
                }
                profilePrefs.edit().putInt("CURR_PROFILE", i).commit();
            }

            @Override
            public void onNothingSelected(AdapterView<?> adapterView) {

            }
        });

        profiles.setSelection(profilePrefs.getInt("CURR_PROFILE", 5));
    }
}

From source file:com.hbm.devices.scan.ui.android.ScanActivity.java

@Override
public boolean onCreateOptionsMenu(@NonNull Menu menu) {
    final MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.device_list_actions, menu);
    final MenuItem searchItem = menu.findItem(R.id.action_search);
    final SearchView searchView = (SearchView) searchItem.getActionView();
    searchView.setQueryHint(getString(R.string.search_hint));
    searchView.setImeOptions(EditorInfo.IME_ACTION_DONE);
    searchView.setOnQueryTextListener(new OnQueryTextListener() {
        @Override//w w  w . jav a  2 s.  co  m
        public boolean onQueryTextSubmit(final String query) {
            searchView.clearFocus();
            adapter.setFilterString(query);
            return true;
        }

        @Override
        public boolean onQueryTextChange(final String newText) {
            adapter.setFilterString(newText);
            return true;
        }
    });
    adapter.setFilterString(null);

    final MenuItem pauseItem = menu.findItem(R.id.action_pause_control);
    if (adapter.isPaused()) {
        pauseItem.setIcon(R.drawable.ic_action_play);
    } else {
        pauseItem.setIcon(R.drawable.ic_action_pause);
    }
    return true;
}

From source file:com.conferenceengineer.android.iosched.ui.SearchActivity.java

@Override
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
public boolean onCreateOptionsMenu(Menu menu) {
    super.onCreateOptionsMenu(menu);
    getMenuInflater().inflate(R.menu.search, menu);
    final 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);
            searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
                @Override/*from w  ww.  j a  v  a 2  s  . c om*/
                public boolean onQueryTextSubmit(String s) {
                    ReflectionUtils.tryInvoke(searchItem, "collapseActionView");
                    return false;
                }

                @Override
                public boolean onQueryTextChange(String s) {
                    return false;
                }
            });
            searchView.setOnSuggestionListener(new SearchView.OnSuggestionListener() {
                @Override
                public boolean onSuggestionSelect(int i) {
                    return false;
                }

                @Override
                public boolean onSuggestionClick(int i) {
                    ReflectionUtils.tryInvoke(searchItem, "collapseActionView");
                    return false;
                }
            });
        }
    }
    return true;
}