Example usage for android.view MenuItem expandActionView

List of usage examples for android.view MenuItem expandActionView

Introduction

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

Prototype

public boolean expandActionView();

Source Link

Document

Expand the action view associated with this menu item.

Usage

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 {/*  w w w.  ja  v a2s.  co  m*/
        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:fr.cph.chicago.activity.BusActivity.java

@Override
public final boolean onOptionsItemSelected(final MenuItem item) {
    switch (item.getItemId()) {
    case android.R.id.home:
        finish();/*from w  w w .  ja  v  a2  s .co m*/
        // overridePendingTransition(R.anim.slide_in, R.anim.slide_out);
        return true;
    case R.id.action_refresh:

        // Load top bar animation
        MenuItem menuItem = item;
        menuItem.setActionView(R.layout.progressbar);
        menuItem.expandActionView();

        // Load data
        new LoadData().execute();
        return true;
    }
    return super.onOptionsItemSelected(item);

}

From source file:fr.cph.chicago.activity.BusActivity.java

@Override
public final boolean onCreateOptionsMenu(final Menu menu) {
    super.onCreateOptionsMenu(menu);
    this.mMenu = menu;

    // Inflate menu with no search
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.main_no_search, menu);

    // Modify action bar title
    ActionBar actionBar = getActionBar();
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD);
    actionBar.setDisplayShowTitleEnabled(true);
    actionBar.setTitle("Bus");

    // Load top bar animation
    MenuItem refreshMenuItem = menu.findItem(R.id.action_refresh);
    refreshMenuItem.setActionView(R.layout.progressbar);
    refreshMenuItem.expandActionView();

    return true;//from   w w  w  .jav  a 2  s  .c o m
}

From source file:fr.cph.chicago.activity.StationActivity.java

@SuppressWarnings("unchecked")
@Override// ww  w. j  a  v  a2  s  .com
public final boolean onOptionsItemSelected(final MenuItem item) {
    switch (item.getItemId()) {
    case android.R.id.home:
        finish();
        return true;
    case R.id.action_refresh:
        MenuItem menuItem = item;
        menuItem.setActionView(R.layout.progressbar);
        menuItem.expandActionView();

        MultiMap<String, String> params = new MultiValueMap<String, String>();
        List<Integer> favorites = Preferences.getTrainFavorites(ChicagoTracker.PREFERENCE_FAVORITES_TRAIN);
        for (Integer fav : favorites) {
            params.put("mapid", String.valueOf(fav));
        }
        MultiMap<String, String> reqParams = new MultiValueMap<String, String>();
        reqParams.put("mapid", String.valueOf(mStation.getId()));
        new LoadData().execute(reqParams);
        return true;
    }
    return super.onOptionsItemSelected(item);
}

From source file:app.cloud9.com.cloud9.NoticeBoard.java

@Override
public boolean onSearchRequested() {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
        MenuItem mi = mMenu.findItem(R.id.search_notice);
        if (mi.isActionViewExpanded()) {
            mi.collapseActionView();/* w ww.j  av  a  2s  .c om*/
        } else {
            mi.expandActionView();
        }
    } else {
        //onOptionsItemSelected(mMenu.findItem(R.id.search));
    }
    return super.onSearchRequested();
}

From source file:fr.cph.chicago.activity.StationActivity.java

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

    MenuItem refreshMenuItem = menu.findItem(R.id.action_refresh);
    refreshMenuItem.setActionView(R.layout.progressbar);
    refreshMenuItem.expandActionView();

    return true;/*from  ww  w  .  jav a 2s.co  m*/
}

From source file:com.viktorrudometkin.burramys.fragment.EntriesListFragment.java

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    menu.clear(); // This is needed to remove a bug on Android 4.0.3

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

    MenuItem searchItem = menu.findItem(R.id.menu_search);
    final SearchView searchView = (SearchView) searchItem.getActionView();
    if (EntryColumns.isSearchUri(mCurrentUri)) {
        searchItem.expandActionView();
        searchView.post(new Runnable() { // Without that, it just does not work
            @Override/*www.  j av a  2 s.co  m*/
            public void run() {
                searchView.setQuery(mCurrentUri.getLastPathSegment(), false);
                searchView.clearFocus();
            }
        });

    }

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

        @Override
        public boolean onQueryTextChange(String newText) {
            if (TextUtils.isEmpty(newText)) {
                setData(mOriginalUri, true);
            } else {
                setData(EntryColumns.SEARCH_URI(newText), true, true);
            }
            return false;
        }
    });
    searchView.setOnCloseListener(new SearchView.OnCloseListener() {
        @Override
        public boolean onClose() {
            setData(mOriginalUri, true);
            return false;
        }
    });

    if (EntryColumns.FAVORITES_CONTENT_URI.equals(mCurrentUri)) {
        menu.findItem(R.id.menu_refresh).setVisible(false);
    } else {
        menu.findItem(R.id.menu_share_starred).setVisible(false);
    }

    super.onCreateOptionsMenu(menu, inflater);
}

From source file:fr.cph.chicago.activity.MainActivity.java

/**
 * Load animation in menu/*  w  w w. ja v a 2  s. co m*/
 */
public final void startRefreshAnimation() {
    if (mMenu != null) {
        MenuItem refreshMenuItem = mMenu.findItem(R.id.action_refresh);
        refreshMenuItem.setActionView(R.layout.progressbar);
        refreshMenuItem.expandActionView();
    }
}

From source file:fr.shywim.antoinedaniel.ui.fragment.SoundPagerFragment.java

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    menu.removeGroup(R.id.sound_menu);// w ww  .  j a  v a2 s . co  m
    inflater.inflate(R.menu.sound_options_menu, menu);

    // find the searchView and handle search manually inside fragment
    MenuItem searchItem = menu.findItem(R.id.search);
    SearchView searchView = (SearchView) MenuItemCompat.getActionView(searchItem);
    if (searchView != null) {
        searchView.setOnQueryTextListener(this);
        MainActivity act = (MainActivity) getActivity();
        if (act.searchQuery != null) {
            searchItem.expandActionView();
            ((EditText) searchView.findViewById(R.id.search_src_text)).setText(act.searchQuery);
            switchFragmentsIfNecessary(true, act.searchQuery);
        }
    }
    super.onCreateOptionsMenu(menu, inflater);
}

From source file:com.necisstudio.highlightgoal.MainActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    int id = item.getItemId();
    if (id == R.id.refresh) {
        drawermenu(iddrawer);//from w  ww  .  j  av  a  2  s  . c  om
        return true;
    } else if (id == R.id.search) {
        item.expandActionView();
        MenuItemCompat.setOnActionExpandListener(item, new MenuItemCompat.OnActionExpandListener() {
            @Override
            public boolean onMenuItemActionExpand(MenuItem item) {
                return true;
            }

            @Override
            public boolean onMenuItemActionCollapse(MenuItem item) {
                //                    getFragmentManager().popBackStack(null, FragmentManager.POP_BACK_STACK_INCLUSIVE);
                ApplicationConfig.status = R.id.latest;
                iddrawer = R.id.latest;
                imgLogo.setImageResource(0);
                txtTitle.setText("Latest");
                fList = new ArrayList<Fragment>();
                List<Fragment> fragments = getFragments(HighlightLatestFragment.newInstance(""),
                        KlasementLigaFragment.newInstance("inggris"),
                        ScheduleLigaLatestFragment.newInstance(""));
                adapter_viewPager = new Adapter_ViewPager(getSupportFragmentManager(), fragments);
                final ViewPager pager = (ViewPager) findViewById(R.id.viewpager);
                tabHost = (TabLayout) findViewById(R.id.materialTabHost);
                pager.setAdapter(adapter_viewPager);
                DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
                drawer.closeDrawer(GravityCompat.START);
                tabHost.setupWithViewPager(pager);
                tabHost.getTabAt(0).setText("Highlight");
                tabHost.getTabAt(1).setText("Schedule");
                return true;
            }
        });

        searchview = (SearchView) MenuItemCompat.getActionView(item);
        SearchManager searchManager = (SearchManager) getSystemService(SEARCH_SERVICE);
        searchview.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
        searchview.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
            @Override
            public boolean onQueryTextSubmit(String query) {
                getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
                iddrawer = 20;
                fList = new ArrayList<Fragment>();
                List<Fragment> fragments = getFragments(
                        HighlightLatestFragment.newInstance(searchview.getQuery().toString()),
                        KlasementLigaFragment.newInstance("inggris"),
                        ScheduleLigaLatestFragment.newInstance(searchview.getQuery().toString()));
                adapter_viewPager = new Adapter_ViewPager(getSupportFragmentManager(), fragments);
                final ViewPager pager = (ViewPager) findViewById(R.id.viewpager);
                tabHost = (TabLayout) findViewById(R.id.materialTabHost);
                pager.setAdapter(adapter_viewPager);
                DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
                drawer.closeDrawer(GravityCompat.START);
                tabHost.setupWithViewPager(pager);
                tabHost.getTabAt(0).setText("Highlight");
                tabHost.getTabAt(1).setText("Schedule");
                return false;
            }

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

    }

    return super.onOptionsItemSelected(item);
}