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:ca.zadrox.dota2esportticker.ui.TeamSearchActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    super.onCreateOptionsMenu(menu);
    getMenuInflater().inflate(R.menu.team_search, menu);
    MenuItem searchItem = menu.findItem(R.id.action_search);
    Toolbar.LayoutParams params = new Toolbar.LayoutParams(Toolbar.LayoutParams.MATCH_PARENT,
            Toolbar.LayoutParams.MATCH_PARENT);

    SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
    mSearchView = (SearchView) searchItem.getActionView();
    mSearchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));

    mSearchView.setLayoutParams(params);
    mSearchView.setMaxWidth(getResources().getDisplayMetrics().widthPixels);

    mSearchView.setIconifiedByDefault(false);
    mSearchView.setQueryHint("Search");

    ImageView magImage = (ImageView) mSearchView.findViewById(R.id.search_mag_icon);
    magImage.setLayoutParams(new LinearLayout.LayoutParams(0, 0));

    final EditText editText = (AutoCompleteTextView) mSearchView.findViewById(R.id.search_src_text);
    editText.setHintTextColor(getResources().getColor(R.color.theme_primary_light));

    if (mQuery != null) {
        mSearchView.setQuery(mQuery, false);
    } else {/*from  w  w w. j a  v a 2 s  .  c  o m*/
        mSearchView.requestFocus();
    }

    mSearchView.setOnSuggestionListener(new SearchView.OnSuggestionListener() {
        @Override
        public boolean onSuggestionSelect(int i) {
            return onSuggestionClick(i);
        }

        @Override
        public boolean onSuggestionClick(int i) {
            Cursor c = (Cursor) mSearchView.getSuggestionsAdapter().getItem(i);
            mSearchView.setQuery(c.getString(1), true);
            mSearchView.clearFocus();

            return true;
        }
    });

    return true;
}

From source file:it.polimi.spf.app.fragments.profile.ProfileFragment.java

@Override
public void onPrepareOptionsMenu(Menu menu) {
    super.onPrepareOptionsMenu(menu);
    MenuItem personaSelector = menu.findItem(R.id.profileview_persona_selector);
    if (personaSelector == null) {
        return;/*from w w  w.  ja  v a 2  s .  c o m*/
    }

    Spinner spinner = (Spinner) personaSelector.getActionView().findViewById(R.id.profileview_persona_spinner);
    if (spinner == null) {
        return;
    }

    List<SPFPersona> personas = SPF.get().getProfileManager().getAvailablePersonas();
    spinner.setAdapter(new ArrayAdapter<SPFPersona>(getActivity().getActionBar().getThemedContext(),
            android.R.layout.simple_list_item_1, personas));
    spinner.setSelection(personas.indexOf(mCurrentPersona), false);
    spinner.setOnItemSelectedListener(this);

}

From source file:nyc.c4q.jordansmith.finefree.ActivityMain.java

public void addCarstoNav() {
    final Menu menu = navDrawerView.getMenu();
    if (submenu == null) {
        submenu = menu.addSubMenu("Your Cars");
        for (int i = 0; i < cars.size(); i++) {
            submenu.add(cars.get(i).getName()).setTitle(cars.get(i).getName().toString())
                    .setIcon(R.drawable.ic_car_black_36dp);

            System.out.println(submenu.getItem(i).getItemId() + " " + submenu.getItem(i).getTitle());

            final MenuItem item = submenu.getItem(i);
            Button button = new Button(this);
            button.setText("Remove");
            button.setTextColor(ContextCompat.getColor(this, R.color.white));
            item.setActionView(button);/*from   w  w w  .  ja va2 s  .  c o m*/
            button.setBackground(getDrawable(R.drawable.button_shape));
            item.getActionView().setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    new AlertDialog.Builder(ActivityMain.this).setIcon(android.R.drawable.ic_dialog_alert)
                            .setTitle("Delete Car").setMessage("Are you sure you want to remove car?")
                            .setPositiveButton("Yes", new DialogInterface.OnClickListener() {
                                @Override
                                public void onClick(DialogInterface dialogInterface, int i) {
                                    System.out.println("CLICKED " + item.getTitle());
                                    cupboard().withDatabase(db).delete(Car.class, "name = ?",
                                            (String) item.getTitle());

                                    updateSubmenu();
                                }
                            }).setNegativeButton("Cancel", null).show();

                }
            });
        }
    } else {
        //            for (int i = 0; i < cars.size(); i++) {
        //                submenu.clear();
        //                submenu.add(cars.get(i).getName()).setTitle(cars.get(i).getName().toString())
        //                        .setIcon(R.drawable.ic_car_black_36dp);
        //
        //                final MenuItem item = submenu.getItem(i);
        //                Button button = new Button(this);
        //                button.setText("Remove");
        //                item.setActionView(button);
        //                item.getActionView().setOnClickListener(new View.OnClickListener() {
        //                    @Override
        //                    public void onClick(View view) {
        //
        //                        System.out.println("CLICKED " + item.getTitle());
        //                        cupboard().withDatabase(db).delete(Car.class, "name = ?", (String) item.getTitle());
        //
        //                        updateSubmenu();
        //                    }
        //                });
        //
        //            }
        setupCarMenu();

    }
}

From source file:ua.boberproduction.bbr.BaseActivity.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_main, menu);
    MenuItem searchItem = menu.findItem(R.id.action_search);

    SearchManager searchManager = (SearchManager) this.getSystemService(Context.SEARCH_SERVICE);

    searchView = null;//ww w.  j  ava2 s.  c o  m
    if (searchItem != null) {
        searchView = (SearchView) searchItem.getActionView();
    }
    if (searchView != null) {
        searchView.setSearchableInfo(searchManager.getSearchableInfo(this.getComponentName()));

        searchView.setIconified(true);
        searchView.clearFocus();
        searchView.onActionViewCollapsed();
    }

    // if user activated God Mode, hide the 'remove ads' menu option..
    if (Ad.getGodModeStatus(this)) {
        MenuItem item = menu.findItem(R.id.action_remove_ads);
        item.setVisible(false);
    }

    return super.onCreateOptionsMenu(menu);
}

From source file:com.projecty.sleepgroundbox.activity.HomeActivity.java

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

    MenuItem searchMenuItem = menu.findItem(R.id.action_search);
    final SearchView searchView = (SearchView) searchMenuItem.getActionView();

    searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
        @Override//from  ww w  .jav a 2  s .  c  o  m
        public boolean onQueryTextSubmit(String s) {
            SearchResultFragment fragment = new SearchResultFragment();
            fragment.setQuery(s);
            getSupportFragmentManager().beginTransaction().add(R.id.container, fragment, "SEARCH_RESULT")
                    .commit();
            return false;
        }

        @Override
        public boolean onQueryTextChange(String s) {
            return false;
        }
    });
    searchView.setOnQueryTextFocusChangeListener(new View.OnFocusChangeListener() {
        @Override
        public void onFocusChange(View v, boolean hasFocus) {
            if (!hasFocus) {
                closeFragment();

                searchView.onActionViewCollapsed();
            }
        }
    });

    searchView.setOnSearchClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            getSupportFragmentManager().beginTransaction().add(R.id.container, new SearchFragment(), "SEARCH")
                    .commit();
        }
    });
    searchView.setOnCloseListener(new SearchView.OnCloseListener() {
        @Override
        public boolean onClose() {
            closeFragment();
            return false;

        }
    });

    return true;
}

From source file:com.brq.wallet.activity.modern.ModernMain.java

public void setRefreshAnimation() {
    if (refreshItem != null) {
        if (_mbwManager.getWalletManager(false).getState() == WalletManager.State.SYNCHRONIZING) {
            MenuItem menuItem = MenuItemCompat.setActionView(refreshItem,
                    R.layout.actionbar_indeterminate_progress);
            ImageView ivTorIcon = (ImageView) menuItem.getActionView().findViewById(R.id.ivTorIcon);

            if (_mbwManager.getTorMode() == ServerEndpointType.Types.ONLY_TOR
                    && _mbwManager.getTorManager() != null) {
                ivTorIcon.setVisibility(View.VISIBLE);
                if (_mbwManager.getTorManager().getInitState() == 100) {
                    ivTorIcon.setImageResource(R.drawable.tor);
                } else {
                    ivTorIcon.setImageResource(R.drawable.tor_gray);
                }//from   w  ww.ja va 2 s  .  co  m
            } else {
                ivTorIcon.setVisibility(View.GONE);
            }

        } else {
            MenuItemCompat.setActionView(refreshItem, null);
        }
    }
}

From source file:com.fitme.MainActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.options, menu);
    MenuItem mi = menu.findItem(R.id.menu_spinner_active_program);
    final TextView tv = (TextView) mi.getActionView();
    ActiveProgramDAO apd = new ActiveProgramDAO(MainActivity.this);
    activeProgram = apd.getActiveProgramName();
    tv.setText(activeProgram);/*from   ww  w.  j a  v  a 2 s  .c  o m*/

    tv.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View view) {
            final Dialog dialog = new Dialog(MainActivity.this);
            dialog.setTitle(getText(R.string.title_select_prog_dialog));
            View programView = getLayoutInflater().inflate(R.layout.programs_list, null);
            ExpandableListView elv = (ExpandableListView) programView.findViewById(R.id.list_programs);
            final ProgramListAdapter pda = new ProgramListAdapter(MainActivity.this);
            elv.setAdapter(pda);
            // Setting listener for Add Program button
            Button addProgram = (Button) programView.findViewById(R.id.button_add_program);
            addProgram.setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(View view) {
                    onAddProgramRequested(pda);
                }
            });
            elv.setGroupIndicator(null);
            elv.setOnGroupClickListener(null);
            elv.setOnChildClickListener(new ExpandableListView.OnChildClickListener() {
                @Override
                public boolean onChildClick(ExpandableListView expandableListView, View view, int groupPosition,
                        int childPosition, long l) {
                    pda.setProgramSelected(groupPosition, childPosition);
                    onNewProgramSelected(pda.getSelectedProgramName());
                    // Refresh trainings section list
                    TrainingsSectionFragment tsf = (TrainingsSectionFragment) mAppSectionsPagerAdapter
                            .getItem(AppSectionsPagerAdapter.SECTION_TRAININGS);
                    tsf.onNewProgramSelected();
                    dialog.dismiss();
                    return false;
                }
            });
            dialog.setContentView(programView);
            dialog.show();
            dialog.getWindow().setLayout(WindowManager.LayoutParams.MATCH_PARENT,
                    WindowManager.LayoutParams.MATCH_PARENT);
        }
    });

    return true;
}

From source file:io.mpos.ui.shared.view.SummaryFragment.java

@Override
public void onPrepareOptionsMenu(Menu menu) {
    MenuItem sendItem = menu.findItem(R.id.mpu_send_receipt_action_id);
    if (sendItem != null) {
        sendItem.setActionView(R.layout.mpu_send_action_view);
        mSendReceiptButton = (Button) sendItem.getActionView().findViewById(R.id.mpu_menu_send_button);
        mSendReceiptButton.setTextColor(
                MposUi.getInitializedInstance().getConfiguration().getAppearance().getTextColorPrimary());
        mSendReceiptButton.setOnClickListener(new View.OnClickListener() {
            @Override/*from  ww w . j  a  va 2 s  . c  o  m*/
            public void onClick(View v) {
                mInteractionActivity
                        .onSendReceiptButtonClicked(getTransactionIdentifierForSendingAndPrinting());
            }
        });
    }
    super.onPrepareOptionsMenu(menu);
}

From source file:net.kourlas.voipms_sms.activities.ConversationActivity.java

@Override
public void onBackPressed() {
    if (actionModeEnabled) {
        actionMode.finish();//from   w w w  . j  av a 2  s  .c  om
    } else if (menu != null) {
        MenuItem searchItem = menu.findItem(R.id.search_button);
        SearchView searchView = (SearchView) searchItem.getActionView();
        if (!searchView.isIconified()) {
            searchItem.collapseActionView();
        } else {
            super.onBackPressed();
        }
    }
}

From source file:de.kuschku.util.ui.MenuTint.java

public void apply() {
    if (forceIcons) {
        forceMenuIcons(menu);/*from   w  w  w. ja va2  s  .c  om*/
    }

    for (int i = 0, size = menu.size(); i < size; i++) {
        MenuItem item = menu.getItem(i);
        colorMenuItem(item, menuItemIconColor, menuItemIconAlpha);
        if (reApplyOnChange) {
            View view = item.getActionView();
            if (view != null) {
                if (item instanceof MenuItemImpl) {
                    ((MenuItemImpl) item)
                            .setSupportOnActionExpandListener(new SupportActionExpandListener(this));
                } else {
                    item.setOnActionExpandListener(new NativeActionExpandListener(this));
                }
            }
        }
    }
}