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.conferenceengineer.android.iosched.ui.HomeActivity.java

@TargetApi(Build.VERSION_CODES.HONEYCOMB)
@Override// w w w. ja v a 2s .  c o 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);
        }
    }

    if (!getResources().getBoolean(R.bool.has_conference_feedback_enabled)) {
        menu.removeItem(R.id.menu_feedback);
    }

    return true;
}

From source file:com.jwetherell.quick_response_code.EncoderActivity.java

@SuppressLint("NewApi")
public OnClickListener onclickPopUpMenu(MenuItem item) {
    //Creating the instance of PopupMenu
    PopupMenu popup = new PopupMenu(EncoderActivity.this, item.getActionView());
    //Inflating the Popup using xml file
    popup.getMenuInflater().inflate(R.menu.menu_contextual_wps, popup.getMenu());

    //registering popup with OnMenuItemClickListener
    popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
        public boolean onMenuItemClick(MenuItem item) {
            Toast.makeText(EncoderActivity.this, "You Clicked : " + item.getTitle(), Toast.LENGTH_SHORT).show();
            return true;
        }//  ww  w.j  a  v  a 2 s.  c om
    });

    popup.show(); //showing popup menu
    return null;

}

From source file:org.namelessrom.devicecontrol.modules.appmanager.BaseAppListFragment.java

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

    // setup search
    final MenuItem searchItem = menu.findItem(R.id.action_search);
    final SearchView searchView = (searchItem != null ? (SearchView) searchItem.getActionView() : null);
    if (searchView != null) {
        searchView.setOnQueryTextListener(this);
        searchView.setOnCloseListener(this);
    }/* w  w w . j  a  v a 2 s.  c  om*/

    super.onCreateOptionsMenu(menu, inflater);
}

From source file:br.liveo.ndrawer.ui.fragment.MainFragment.java

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    // TODO Auto-generated method stub
    super.onCreateOptionsMenu(menu, inflater);
    inflater.inflate(R.menu.menu, menu);

    //Select search item
    final MenuItem menuItem = menu.findItem(R.id.menu_search);
    menuItem.setVisible(true);//from ww  w  .  j  a v  a2  s.c o  m

    SearchView searchView = (SearchView) menuItem.getActionView();
    searchView.setQueryHint(this.getString(R.string.search));

    ((EditText) searchView.findViewById(R.id.search_src_text))
            .setHintTextColor(getResources().getColor(R.color.nliveo_white));
    searchView.setOnQueryTextListener(onQuerySearchView);

    //menu.findItem(R.id.menu_add).setVisible(true);

    mSearchCheck = false;
}

From source file:ru.piter.fm.activities.RadioActivity.java

@Override
public boolean onOptionsItemSelected(com.actionbarsherlock.view.MenuItem item) {
    switch (item.getItemId()) {
    case 1:/*w ww. j a  va2s  . c  o m*/
        ((RadioFragment) mAdapter.getItem(mPager.getCurrentItem())).updateChannels();
        break;
    case 2:
        startActivity(new Intent(this, SettingsActivity.class));
        break;
    case 3:
        search = (EditText) item.getActionView();
        search.addTextChangedListener(filterTextWatcher);
        break;
    case 4:

        final AlertDialog alert;
        AlertDialog.Builder builder = new AlertDialog.Builder(RadioActivity.this)
                .setTitle(R.string.request_exit)
                .setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        App.getPlayer().stop();
                        Notifications.killNotification(Notifications.PLAY_STOP);
                        finish();
                    }
                }).setNegativeButton(R.string.no, null);
        alert = builder.create();
        alert.show();
        break;
    }
    return true;
}

From source file:com.github.chenxiaolong.dualbootpatcher.appsharing.AppListFragment.java

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

    final MenuItem item = menu.findItem(R.id.action_search);
    final SearchView searchView = (SearchView) item.getActionView();
    searchView.setOnQueryTextListener(this);

    if (mSearchQuery != null) {
        searchView.setIconified(false);/* w ww  .ja  v a  2 s.com*/
        //item.expandActionView();
        searchView.setQuery(mSearchQuery, false);
        searchView.clearFocus();
    }
}

From source file:com.digitalobstaclecourse.bluefinder.FindCar.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.activity_find_car, menu);
    MenuItem _menuItemAction = menu.findItem(R.id.menu_ammo);
    View actionView = null;/* w w w  . j av  a2s  .  co m*/
    if (_menuItemAction != null) {
        actionView = _menuItemAction.getActionView();
    } else {
        //Log.e(TAG, "getActionView()");
    }
    assert actionView != null;
    mActionView = actionView;
    actionView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            //Log.d(TAG, "onclick actionView");
            if (get_data_access().hasPurchasedInfiniteUse()) {
                Toast.makeText(getApplicationContext(),
                        "No need to purchase anything else; you already own infinite uses", Toast.LENGTH_LONG)
                        .show();
            } else {
                DialogFragment newFragment = new BuyInAppDialogFragment();
                newFragment.show(getFragmentManager(), "miss");
            }
        }
    });
    TextView uses_remaining_textview = (TextView) actionView.findViewById(R.id.uses_remaining);
    if (hasInfiniteLicense()) {
        actionView.findViewById(R.id.infinity_icon).setVisibility(View.VISIBLE);
        uses_remaining_textview.setVisibility(View.INVISIBLE);
        uses_remaining_textview.setText(String.format("\u00ec"));
    } else {
        actionView.findViewById(R.id.infinity_icon).setVisibility(View.INVISIBLE);
        uses_remaining_textview.setVisibility(View.VISIBLE);
        int remaining_locations = getUsesRemaining();
        uses_remaining_textview.setText(String.format("%d", remaining_locations));
    }
    return true;
}

From source file:com.kasungunathilaka.sarigama.ui.HomeActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.menu_home, menu);
    MenuItem item = menu.findItem(R.id.action_search);
    SearchView searchView = (SearchView) item.getActionView();
    searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
        @Override/* ww w .  j  av a 2 s .  co m*/
        public boolean onQueryTextSubmit(String query) {
            ((InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE)).hideSoftInputFromWindow(
                    (null == getCurrentFocus()) ? null : getCurrentFocus().getWindowToken(),
                    InputMethodManager.HIDE_NOT_ALWAYS);
            ContentFragment contentFragment = new ContentFragment();
            contentFragment.setContentType(ROOT_FRAGMENT_SEARCH, query);
            setFragment(contentFragment);
            return true;
        }

        @Override
        public boolean onQueryTextChange(String newText) {
            return false;
        }
    });
    return super.onCreateOptionsMenu(menu);
}

From source file:uk.ac.horizon.artcodes.activity.NavigationActivity.java

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

    final MenuItem searchItem = menu.findItem(R.id.search);
    final SearchView searchView = (SearchView) searchItem.getActionView();
    final SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
    searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
    searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
        private Runnable delayedAction = null;

        @Override//from w ww  .j av a2 s  .  c o  m
        public boolean onQueryTextSubmit(String query) {
            search(query);
            return true;
        }

        @Override
        public boolean onQueryTextChange(final String newText) {
            if (delayedAction != null) {
                searchHandler.removeCallbacks(delayedAction);
                delayedAction = null;
            }

            if (newText.trim().length() > 3) {
                delayedAction = new Runnable() {
                    @Override
                    public void run() {
                        search(newText);
                    }
                };

                searchHandler.postDelayed(delayedAction, 1000);
            }
            return true;
        }
    });
    MenuItemCompat.setOnActionExpandListener(searchItem, new MenuItemCompat.OnActionExpandListener() {
        @Override
        public boolean onMenuItemActionExpand(final MenuItem item) {
            return true;
        }

        @Override
        public boolean onMenuItemActionCollapse(final MenuItem item) {
            Log.i("a", "Closed");
            Fragment fragment = getSupportFragmentManager().findFragmentByTag(FRAGMENT_TAG);
            if (fragment instanceof ExperienceSearchFragment) {
                getSupportFragmentManager().popBackStack();
            }
            return true;
        }
    });

    return true;

}

From source file:com.akhbulatov.wordkeeper.ui.fragment.WordListFragment.java

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

    MenuItem searchItem = menu.findItem(R.id.menu_search_word);
    SearchView searchView = (SearchView) searchItem.getActionView();

    SearchManager searchManager = (SearchManager) getActivity().getSystemService(Context.SEARCH_SERVICE);
    searchView.setSearchableInfo(/*from  www . ja  v a2  s.c o m*/
            searchManager.getSearchableInfo(new ComponentName(getActivity(), MainActivity.class)));
    searchView.setImeOptions(EditorInfo.IME_ACTION_SEARCH);
    searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
        @Override
        public boolean onQueryTextSubmit(String query) {
            return false;
        }

        @Override
        public boolean onQueryTextChange(String newText) {
            final Cursor cursor = mWordDbAdapter.getAll(sSortMode);
            final int column = cursor.getColumnIndex(WordEntry.COLUMN_NAME);
            if (newText.length() > 0) {
                mWordAdapter.swapCursor(new FilterCursorWrapper(cursor, newText, column));

                mTextEmptyWordList.setVisibility(View.GONE);
                if (mWordAdapter.getItemCount() == 0) {
                    String escapedNewText = TextUtils.htmlEncode(newText);
                    String formattedNoResults = String.format(getString(R.string.no_results_word),
                            escapedNewText);
                    CharSequence styledNoResults = Html.fromHtml(formattedNoResults);

                    mTextNoResultsWord.setText(styledNoResults);
                    mTextNoResultsWord.setVisibility(View.VISIBLE);
                } else {
                    mTextNoResultsWord.setVisibility(View.GONE);
                }
            } else {
                mWordAdapter.swapCursor(cursor);

                mTextNoResultsWord.setVisibility(View.GONE);
                if (mWordAdapter.getItemCount() == 0) {
                    mTextEmptyWordList.setVisibility(View.VISIBLE);
                }
            }
            return true;
        }
    });
}