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.coinblesk.client.MainActivity.java

private void initSwitch(Menu menu) {
    MenuItem item = menu.findItem(R.id.myswitch);
    View view = item.getActionView();
    final Switch mySwitch = (Switch) view.findViewById(R.id.switchAB);
    final AtomicReference<CountDownTimer> ref = new AtomicReference<>();
    mySwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        @Override//from   w ww  . j  ava  2 s.  com
        public void onCheckedChanged(CompoundButton compoundButton, boolean isChecked) {
            if (isChecked) {
                //enable BT
                ref.set(new CountDownTimer(30000, 1000) {
                    int i = 0;

                    public void onTick(final long millisUntilFinished) {
                        mySwitch.setButtonDrawable(
                                (i++ % 2) == 0 ? R.drawable.bluetooth_onon : R.drawable.bluetooth_on);
                        mySwitch.setTextOn("" + millisUntilFinished / 1000);
                    }

                    public void onFinish() {
                        mySwitch.setButtonDrawable(R.drawable.bluetooth_on);
                        mySwitch.setChecked(false);
                    }

                });
                ref.get().start();
                LocalBroadcastManager.getInstance(MainActivity.this)
                        .sendBroadcast(new Intent(Constants.START_CLIENTS_ACTION));

            } else {
                //mySwitch.setShowText(false);
                CountDownTimer tmp;
                if ((tmp = ref.getAndSet(null)) != null) {
                    tmp.cancel();
                }
                LocalBroadcastManager.getInstance(MainActivity.this)
                        .sendBroadcast(new Intent(Constants.STOP_CLIENTS_ACTION));
            }
        }
    });
}

From source file:org.catnut.ui.ComposeTweetActivity.java

@Override
public boolean onMenuItemActionExpand(MenuItem item) {
    if (mAutoCompleteTextView == null) {
        mAutoCompleteTextView = (AutoCompleteTextView) item.getActionView().findViewById(R.id.mention_search);
        mAutoCompleteTextView.setThreshold(1); // ??
        mMentionSearchAdapter = new MentionSearchAdapter(ComposeTweetActivity.this);
        mAutoCompleteTextView.setAdapter(mMentionSearchAdapter);
    }//from ww w. j  a  v a 2s .co  m
    //      Toast.makeText(ComposeTweetActivity.this, getString(R.string.mention_helper_toast), Toast.LENGTH_SHORT).show();
    final View clear = item.getActionView().findViewById(R.id.clear);
    clear.setOnClickListener(ComposeTweetActivity.this);
    mAutoCompleteTextView.addTextChangedListener(new TextWatcher() {
        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
            // no-op
        }

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            // no-op
        }

        @Override
        public void afterTextChanged(Editable s) {
            String text = s.toString();
            if (text.length() > 0) {
                clear.setVisibility(View.VISIBLE);
            } else {
                clear.setVisibility(View.GONE);
            }
            String key = text.trim();
            if (!TextUtils.isEmpty(key) && !key.equals(mCurKeywords)) {
                mCurKeywords = key;
                getLoaderManager().restartLoader(0, null, ComposeTweetActivity.this);
            }
        }
    });
    mAutoCompleteTextView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            Cursor cursor = (Cursor) mMentionSearchAdapter.getItem(position);
            mText.getText().append(getString(R.string.mention_text,
                    cursor.getString(cursor.getColumnIndex(User.screen_name))));
            mText.setSelection(mText.length());
        }
    });
    mText.clearFocus();
    mAutoCompleteTextView.requestFocus();
    mAutoCompleteTextView.post(new Runnable() {
        @Override
        public void run() {
            mInputMethodManager.showSoftInput(mAutoCompleteTextView, InputMethodManager.SHOW_FORCED);
        }
    });
    return true;
}

From source file:inc.bait.jubilee.ui.fragments.ContactsListFragment.java

@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
@Override//  w  w  w.  ja  v  a2  s .  co  m
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    inflater.inflate(R.menu.contact_list_menu, menu);
    MenuItem searchItem = menu.findItem(R.id.menu_search);
    if (isSearchResultView) {
        searchItem.setVisible(false);
    }
    if (ApiHelper.hasHoneycomb()) {
        final SearchManager searchManager = (SearchManager) getActivity()
                .getSystemService(Context.SEARCH_SERVICE);
        final SearchView searchView = (SearchView) searchItem.getActionView();
        searchView.setSearchableInfo(searchManager.getSearchableInfo(getActivity().getComponentName()));
        searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
            @Override
            public boolean onQueryTextSubmit(String queryText) {
                return true;
            }

            @Override
            public boolean onQueryTextChange(String newText) {
                String newFilter = !TextUtils.isEmpty(newText) ? newText : null;
                if (searchString == null && newFilter == null) {
                    return true;
                }
                if (searchString != null && searchString.equals(newFilter)) {
                    return true;
                }
                searchString = newFilter;
                mSearchQueryChanged = true;
                getLoaderManager().restartLoader(ContactsQuery.QUERY_ID, null, ContactsListFragment.this);
                return true;
            }
        });

        if (ApiHelper.hasICS()) {
            searchItem.setOnActionExpandListener(new MenuItem.OnActionExpandListener() {
                @Override
                public boolean onMenuItemActionExpand(MenuItem menuItem) {
                    return true;
                }

                @Override
                public boolean onMenuItemActionCollapse(MenuItem menuItem) {
                    if (!TextUtils.isEmpty(searchString)) {
                        onSelectionCleared();
                    }
                    searchString = null;
                    getLoaderManager().restartLoader(ContactsQuery.QUERY_ID, null, ContactsListFragment.this);
                    return true;
                }
            });
        }

        if (searchString != null) {
            final String savedSearchTerm = searchString;

            // Expands the search menu item
            if (ApiHelper.hasICS()) {
                searchItem.expandActionView();
            }
            searchView.setQuery(savedSearchTerm, false);
        }
    }
}

From source file:bf.io.openshop.ux.MainActivity.java

/**
 * Prepare toolbar search view. Invoke search suggestions and handle search queries.
 *
 * @param searchItem corresponding menu item.
 *//*from  w w  w  . jav  a2 s  .co m*/
private void prepareSearchView(@NonNull final MenuItem searchItem) {
    final SearchView searchView = (SearchView) searchItem.getActionView();
    searchView.setSubmitButtonEnabled(true);
    SearchManager searchManager = (SearchManager) MainActivity.this.getSystemService(Context.SEARCH_SERVICE);
    searchView.setSearchableInfo(searchManager.getSearchableInfo(MainActivity.this.getComponentName()));
    SearchView.OnQueryTextListener queryTextListener = new SearchView.OnQueryTextListener() {
        public boolean onQueryTextChange(String newText) {
            Timber.d("Search query text changed to: %s", newText);
            showSearchSuggestions(newText, searchView);
            return false;
        }

        public boolean onQueryTextSubmit(String query) {
            // Submit search query and hide search action view.
            onSearchSubmitted(query);
            searchView.setQuery("", false);
            searchView.setIconified(true);
            searchItem.collapseActionView();
            return true;
        }
    };

    searchView.setOnSuggestionListener(new SearchView.OnSuggestionListener() {
        @Override
        public boolean onSuggestionSelect(int position) {
            return false;
        }

        @Override
        public boolean onSuggestionClick(int position) {
            // Submit search suggestion query and hide search action view.
            MatrixCursor c = (MatrixCursor) searchSuggestionsAdapter.getItem(position);
            onSearchSubmitted(c.getString(1));
            searchView.setQuery("", false);
            searchView.setIconified(true);
            searchItem.collapseActionView();
            return true;
        }
    });
    searchView.setOnQueryTextListener(queryTextListener);
}

From source file:com.piusvelte.webcaster.MainActivity.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.main, menu);

    MenuItem mediaRouteItem = menu.findItem(R.id.action_mediaroute);

    if (mediaRouteSelector != null) {
        mediaRouteButton = (MediaRouteButton) mediaRouteItem.getActionView();
        mediaRouteButton.setRouteSelector(mediaRouteSelector);
        mediaRouteButton.setDialogFactory(new MediaRouteDialogFactory());
        mediaRouteItem.setVisible(true);
        mediaRouteItem.setEnabled(true);
    } else {//from  www .ja  v  a2s . com
        mediaRouteItem.setVisible(false);
        mediaRouteItem.setEnabled(false);
    }

    return true;
}

From source file:com.example.office.ui.Office365DemoActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    try {/* w  w w  .j a v a 2s  .c om*/
        getMenuInflater().inflate(R.menu.menu_inbox, menu);

        // search
        MenuItem searchItem = menu.findItem(R.id.inbox_menu_search);
        mSearchView = (SearchView) searchItem.getActionView();
        mSearchView.setOnQueryTextListener(this);

        searchItem.setOnActionExpandListener(new OnActionExpandListener() {
            @Override
            public boolean onMenuItemActionCollapse(MenuItem item) {
                return true; // Return true to collapse action view
            }

            @Override
            public boolean onMenuItemActionExpand(MenuItem item) {
                return true; // Return true to expand action view
            }
        });

        // logout
        MenuItem logoutItem = menu.findItem(R.id.menu_log_out);
        logoutItem.setOnMenuItemClickListener(new OnMenuItemClickListener() {

            @SuppressWarnings({ "unchecked", "rawtypes" })
            @Override
            public boolean onMenuItemClick(MenuItem item) {
                switch (item.getItemId()) {
                case R.id.menu_log_out:
                    // remove stored credentials
                    AuthPreferences.storeCredentials(null);
                    // remove stored mails
                    MailConfigPreferences.saveConfiguration(null);
                    // clear authentication context
                    resetToken();
                    clearCookies();
                    // reset authenticator
                    setAuthenticator(null);
                    // clear currently displayed items
                    ((ItemsFragment) getCurrentFragment()).updateList(Collections.emptyList());
                    // clear default screen
                    ((ItemsFragment) getFragmentManager()
                            .findFragmentByTag(DEFAULT_SCREEN.getName(Office365DemoActivity.this)))
                                    .updateList(Collections.emptyList());
                    // notify current fragment that user logged out
                    ((ItemsFragment) getCurrentFragment()).notifyUserLoggedOut();

                    // open authentication activity
                    tryAuthenticate();

                default:
                    return false;
                }
            }

        });

        return true;
    } catch (Exception e) {
        Logger.logApplicationException(e, getClass().getSimpleName() + ".onCreateOptionsMenu(): Error.");
        return false;
    }
}

From source file:com.nextgis.mobile.activity.MainActivity.java

public synchronized void onRefresh(boolean isRefresh) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        MenuItem refreshItem = mToolbar.getMenu().findItem(R.id.menu_refresh);
        if (null != refreshItem) {
            if (isRefresh) {
                if (refreshItem.getActionView() == null) {
                    refreshItem.setActionView(R.layout.layout_refresh);
                    ProgressBar progress = (ProgressBar) refreshItem.getActionView()
                            .findViewById(R.id.refreshingProgress);
                    if (progress != null)
                        progress.getIndeterminateDrawable().setColorFilter(
                                ContextCompat.getColor(this, R.color.color_grey_200), PorterDuff.Mode.SRC_IN);
                }/*w w  w  .java2s . com*/
            } else
                stopRefresh(refreshItem);
        }
    }
}

From source file:org.deviceconnect.android.manager.setting.ServiceListActivity.java

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

    MenuItem managerSwitch = menu.findItem(R.id.activity_service_manager_power);
    if (managerSwitch == null) {
        return super.onCreateOptionsMenu(menu);
    }//from   w  w  w.jav  a 2s. c  o m

    Switch switchAction = (Switch) managerSwitch.getActionView();
    if (switchAction != null) {
        mSwitchAction = switchAction;

        DisplayMetrics metrics = getResources().getDisplayMetrics();
        mSwitchAction.setPadding((int) (12 * metrics.density), 0, (int) (12 * metrics.density), 0);
        mSwitchAction.setOnCheckedChangeListener(mSwitchActionListener);

        DConnectService managerService = getManagerService();
        if (managerService != null) {
            mSwitchAction.setChecked(managerService.isRunning());
        }
    }

    return true;
}

From source file:com.amaze.filemanager.ui.views.drawer.Drawer.java

private void addNewItem(Menu menu, int group, int order, @StringRes int text, MenuMetadata meta,
        @DrawableRes int icon, @DrawableRes Integer actionViewIcon) {
    if (BuildConfig.DEBUG && menu.findItem(order) != null)
        throw new IllegalStateException("Item already id exists: " + order);

    MenuItem item = menu.add(group, order, order, text).setIcon(icon);
    dataUtils.putDrawerMetadata(item, meta);
    if (actionViewIcon != null) {
        item.setActionView(R.layout.layout_draweractionview);

        ImageView imageView = item.getActionView().findViewById(R.id.imageButton);
        imageView.setImageResource(actionViewIcon);
        if (!mainActivity.getAppTheme().equals(AppTheme.LIGHT)) {
            imageView.setColorFilter(Color.WHITE);
        }/*from w ww  .  java2s  .c  o  m*/

        item.getActionView().setOnClickListener((view) -> onNavigationItemActionClick(item));
    }
}

From source file:com.amaze.filemanager.ui.views.drawer.Drawer.java

private void addNewItem(Menu menu, int group, int order, String text, MenuMetadata meta, @DrawableRes int icon,
        @DrawableRes Integer actionViewIcon) {
    if (BuildConfig.DEBUG && menu.findItem(order) != null)
        throw new IllegalStateException("Item already id exists: " + order);

    MenuItem item = menu.add(group, order, order, text).setIcon(icon);
    dataUtils.putDrawerMetadata(item, meta);

    if (actionViewIcon != null) {
        item.setActionView(R.layout.layout_draweractionview);

        ImageView imageView = item.getActionView().findViewById(R.id.imageButton);
        imageView.setImageResource(actionViewIcon);
        if (!mainActivity.getAppTheme().equals(AppTheme.LIGHT)) {
            imageView.setColorFilter(Color.WHITE);
        }//from www.  j  a  v a  2s .c  om

        item.getActionView().setOnClickListener((view) -> onNavigationItemActionClick(item));
    }
}