Example usage for android.view MenuItem setActionView

List of usage examples for android.view MenuItem setActionView

Introduction

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

Prototype

public MenuItem setActionView(@LayoutRes int resId);

Source Link

Document

Set an action view for this menu item.

Usage

From source file:Main.java

public static void setActionView(final MenuItem item, final Integer layout) {
    if (item == null) {
        return;/*from  www  .  ja va2 s  .  co m*/
    }

    if (layout == null) {
        item.setActionView(null);
    } else {
        item.setActionView(layout);
    }
}

From source file:com.balch.android.app.framework.TemplateActivity.java

public void showProgress() {
    if (this.optionsMenu != null) {
        MenuItem menuItem = this.optionsMenu.findItem(R.id.action_bar_menu_refresh);
        menuItem.setActionView(R.layout.action_bar_progress);
        menuItem.expandActionView();/*from  w ww. j  av a2 s . 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);//from w ww. ja v  a  2s.  c  om
    }
}

From source file:com.balch.android.app.framework.TemplateActivity.java

public void hideProgress() {
    if (this.optionsMenu != null) {
        MenuItem menuItem = this.optionsMenu.findItem(R.id.action_bar_menu_refresh);
        menuItem.collapseActionView();/*  w w w  .j  a  va 2s.c om*/
        menuItem.setActionView(null);
    }
}

From source file:net.vexelon.currencybg.app.ui.fragments.AbstractFragment.java

protected void setRefreshActionButtonState(final boolean isRefreshing) {
    if (mMenu != null) {
        MenuItem menuItem = mMenu.findItem(R.id.action_refresh);
        if (menuItem != null) {
            if (isRefreshing) {
                menuItem.setActionView(isRefreshing ? R.layout.actionbar_indeterminate_progress : null);
            } else {
                menuItem.setActionView(null);
            }//from ww  w . j a  v  a  2  s. co  m
        }
    }
}

From source file:com.egoclean.testpregnancy.util.ActivityHelperHoneycomb.java

/** {@inheritDoc} */
@Override//w w  w .j a  va  2  s  .c  om
public void setRefreshActionButtonCompatState(boolean refreshing) {
    // On Honeycomb, we can set the state of the refresh button by giving it a custom
    // action view.
    if (mOptionsMenu == null) {
        return;
    }

    final MenuItem refreshItem = mOptionsMenu.findItem(R.id.menu_refresh);
    if (refreshItem != null) {
        if (refreshing) {
            refreshItem.setActionView(R.layout.actionbar_indeterminate_progress);
        } else {
            refreshItem.setActionView(null);
        }
    }
}

From source file:com.sonaive.v2ex.ui.FeedDetailActivity.java

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

    MenuItem refreshMenu = menu.findItem(R.id.menu_refresh);
    if (isRefreshing()) {
        refreshMenu.setVisible(true);//from   w  w  w  .j  a  v  a2 s  .co  m
        refreshMenu.setActionView(R.layout.progress_bar);
    }

    return true;
}

From source file:ca.farrelltonsolar.classic.HourLogChart.java

private void setupSpinner(MenuItem item) {
    try {//  ww  w .  j  a v  a  2 s.com
        item.setVisible(true);
        item.setActionView(R.layout.action_chart_select);
        View view = MenuItemCompat.getActionView(item);
        if (view instanceof Spinner) {
            Spinner spinner = (Spinner) view;
            String[] itemArray = getResources().getStringArray(R.array.minute_log_chart_selection);
            ArrayAdapter<String> spinnerArrayAdapter = new ArrayAdapter<String>(this.getActivity(),
                    android.R.layout.simple_spinner_item, itemArray); //selected item will look like a spinner set from XML
            spinnerArrayAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
            spinner.setAdapter(spinnerArrayAdapter);
            spinner.setSelection(MonitorApplication.chargeControllers().getCurrentChargeController()
                    .getHourLogMenuSelection(), false);
            spinner.setOnItemSelectedListener(
                    new OnItemSelectedListenerWrapper(new AdapterView.OnItemSelectedListener() {

                        @Override
                        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
                            chartView.clearSeries();
                            if (position < mSeries.size()) {
                                MonitorApplication.chargeControllers().getCurrentChargeController()
                                        .setHourLogMenuSelection(position);
                                chartView.addSeries(mSeries.get(position));
                            }
                        }

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

                        }
                    }));
        }
    } catch (Exception ex) {
        Log.w(getClass().getName(), String.format("Hour Log Chart failed to load setupSpinner %s ex: %s",
                Thread.currentThread().getName(), ex));
    }
}

From source file:fr.cph.chicago.fragment.BikeFragment.java

@Override
public final boolean onOptionsItemSelected(final MenuItem item) {
    switch (item.getItemId()) {
    case R.id.action_refresh:
        SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(mActivity);
        boolean loadBike = sharedPref.getBoolean("divvy_bike", true);
        if (loadBike) {
            MenuItem menuItem = item;
            menuItem.setActionView(R.layout.progressbar);
            menuItem.expandActionView();

            new DivvyAsyncTask().execute();

            Bundle bundle = mActivity.getIntent().getExtras();
            List<BikeStation> bikeStations = bundle.getParcelableArrayList("bikeStations");

            if (bikeStations == null) {
                mActivity.startRefreshAnimation();
                mActivity.new LoadData().execute();
            }/*  ww  w  . j  ava2s  . co  m*/
        }
        Util.trackAction(mActivity, R.string.analytics_category_ui, R.string.analytics_action_press,
                R.string.analytics_action_refresh_bike, 0);
        return false;
    }
    return super.onOptionsItemSelected(item);
}

From source file:ca.farrelltonsolar.classic.DayLogChart.java

private void setupSpinner(MenuItem item) {
    try {/*  ww w. java  2  s  .c  o m*/
        item.setVisible(true);
        item.setActionView(R.layout.action_chart_select);
        View view = MenuItemCompat.getActionView(item);
        if (view instanceof Spinner) {
            Spinner spinner = (Spinner) view;
            String[] itemArray = getResources().getStringArray(R.array.day_log_chart_selection);
            ArrayAdapter<String> spinnerArrayAdapter = new ArrayAdapter<String>(this.getActivity(),
                    android.R.layout.simple_spinner_item, itemArray); //selected item will look like a spinner set from XML
            spinnerArrayAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
            spinner.setAdapter(spinnerArrayAdapter);
            spinner.setSelection(MonitorApplication.chargeControllers().getCurrentChargeController()
                    .getDayLogMenuSelection(), false);
            spinner.setOnItemSelectedListener(
                    new OnItemSelectedListenerWrapper(new AdapterView.OnItemSelectedListener() {

                        @Override
                        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
                            chartView.clearSeries();
                            if (position < mSeries.size()) {
                                MonitorApplication.chargeControllers().getCurrentChargeController()
                                        .setDayLogMenuSelection(position);
                                chartView.addSeries(mSeries.get(position));
                            }
                        }

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

                        }
                    }));
        }
    } catch (Exception ex) {
        Log.w(getClass().getName(), String.format("Day Log Chart failed to load setupSpinner %s ex: %s",
                Thread.currentThread().getName(), ex));
    }
}