Java Code Examples for android.support.v4.view.MenuItemCompat#setActionView()

The following examples show how to use android.support.v4.view.MenuItemCompat#setActionView() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SearchDetailsActivity.java    From aMuleRemote with GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    
    if (mApp != null && DEBUG) Log.d(TAG, "SearchDetailsActivity.onPrepareOptionsMenu: Setting items visibility");
    
    if (refreshItem != null)  {
        
        if (mSearch != null && (mSearch.mSearchStatus== ECSearchStatus.STARTING || mSearch.mSearchStatus == ECSearchStatus.RUNNING)) {
            if (mIsProgressShown) {
                MenuItemCompat.setActionView(refreshItem, R.layout.part_refresh_progress);
                //refreshItem.setActionView(R.layout.part_refresh_progress);
            } else {
                MenuItemCompat.setActionView(refreshItem, null);
                //refreshItem.setActionView(null);
            }
            refreshItem.setVisible(true);
        } else {
            refreshItem.setVisible(false);
        }
    }
    
    if (mApp != null && DEBUG) Log.d(TAG, "SearchDetailsActivity.onPrepareOptionsMenu: calling super");
    boolean superRet = super.onPrepareOptionsMenu(menu);
    if (mApp != null && DEBUG) Log.d(TAG, "SearchDetailsActivity.onPrepareOptionsMenu: super returned " + superRet + " - end");
    return superRet;
}
 
Example 2
Source File: SearchActivity.java    From aMuleRemote with GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    
    if (mApp != null && DEBUG) Log.d(TAG, "SearchActivity.onPrepareOptionsMenu: Setting items visibility");
    
    if (refreshItem != null)  {
        
        if (lastSearch != null && (lastSearch.mSearchStatus == ECSearchStatus.STARTING || lastSearch.mSearchStatus == ECSearchStatus.RUNNING)) {
            if (mIsProgressShown) {
                MenuItemCompat.setActionView(refreshItem, R.layout.part_refresh_progress);
                //refreshItem.setActionView(R.layout.part_refresh_progress);
            } else {
                MenuItemCompat.setActionView(refreshItem, null);
                //refreshItem.setActionView(null);
            }
            refreshItem.setVisible(true);
        } else {
            refreshItem.setVisible(false);
        }
    }
    
    if (mApp != null && DEBUG) Log.d(TAG, "SearchActivity.onPrepareOptionsMenu: calling super");
    boolean superRet = super.onPrepareOptionsMenu(menu);
    if (mApp != null && DEBUG) Log.d(TAG, "SearchActivity.onPrepareOptionsMenu: super returned " + superRet + " - end");
    return superRet;
}
 
Example 3
Source File: DlQueueActivity.java    From aMuleRemote with GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    
    if (mApp != null && DEBUG) Log.d(TAG, "DlQueueActivity.onPrepareOptionsMenu: Setting items visibility");
    
    if (refreshItem != null) {
        refreshItem.setVisible(mServerConfigured);
        if (mIsProgressShown) {
            MenuItemCompat.setActionView(refreshItem, R.layout.part_refresh_progress);
        } else {
            MenuItemCompat.setActionView(refreshItem, null);
        }
    }

    addEd2kItem.setVisible(mServerConfigured);
    
    if (mApp != null) {
        if (debugOptionsItem != null) debugOptionsItem.setVisible(DEBUG);
    }

    if (mApp != null && DEBUG) Log.d(TAG, "DlQueueActivity.onPrepareOptionsMenu: calling super");
    boolean superRet = super.onPrepareOptionsMenu(menu);
    if (mApp != null && DEBUG) Log.d(TAG, "DlQueueActivity.onPrepareOptionsMenu: super returned " + superRet + " - end");
    return superRet;
}
 
Example 4
Source File: PartFileActivity.java    From aMuleRemote with GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    
    MenuItem refreshItem = menu.findItem(R.id.menu_detail_opt_refresh);
    
    if (refreshItem != null) {
        if (mIsProgressShown) {
            MenuItemCompat.setActionView(refreshItem, R.layout.part_refresh_progress);
            //refreshItem.setActionView(R.layout.part_refresh_progress);
        } else {
            MenuItemCompat.setActionView(refreshItem, null);
            //refreshItem.setActionView(null);
        }
    }
    return super.onPrepareOptionsMenu(menu);
}
 
Example 5
Source File: PagedListFragment.java    From COCOFramework with Apache License 2.0 5 votes vote down vote up
@Override
protected void onStartLoading() {
    super.onStartLoading();
    if (refresh != null) {
        MenuItemCompat.setActionView(refresh, R.layout.indeterminate_progress_action);
    }
}
 
Example 6
Source File: TaskListFragment.java    From mvp-helpers with MIT License 5 votes vote down vote up
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    inflater.inflate(R.menu.task_list_menu, menu);

    final MenuItem item = menu.findItem(R.id.action_search);
    final ActionBar actionBar = ((AppCompatActivity) getActivity()).getSupportActionBar();

    if (null != actionBar) {
        final SearchView searchView = new SearchView(actionBar.getThemedContext());

        MenuItemCompat.setActionView(item, searchView);

        searchView.setOnQueryTextListener(this);
        searchView.setIconifiedByDefault(false);

        searchView.setOnSearchClickListener(v -> newTaskButton.hide());
        searchView.setOnCloseListener(this::onClose);

        MenuItemCompat.setOnActionExpandListener(item, this);
    }

    if (isPresenterAvailable()) {
        Long count = getPresenter().getTasksCount();

        menu.findItem(R.id.action_delete_all).setEnabled(count != 0);
        menu.findItem(R.id.action_delete_all).setVisible(count != 0);
    }

    super.onCreateOptionsMenu(menu, inflater);
}
 
Example 7
Source File: PagedRecyclerViewFragment.java    From COCOFramework with Apache License 2.0 5 votes vote down vote up
@Override
public void onLoadFinished(final Loader<List<T>> loader, final List<T> items) {
    final Exception exception = getException(loader);
    onStopLoading();
    if (refresh != null) {
        MenuItemCompat.setActionView(refresh,null);
    }
    if (exception != null) {
        ended.set(true);
        showError(exception);
        showList();
        return;
    }
    if (items != null && mAdapter != null && !items.isEmpty()) {
        if (time == 0)
            getAdapter().refresh();
        getAdapter().add(items);
    }
    showList();
    updateAdapter();
    onLoaderDone(items);

    showLoading();
    if (items == null || items.size() < pagedSize(time)) {
        ended.set(true);
        onAllDataLoaded();
        hideLoading();
    }

    time++;
}
 
Example 8
Source File: ActPlaylist.java    From freemp with Apache License 2.0 5 votes vote down vote up
public void setRefreshActionButtonState() {

        if (optionsMenu != null) {
            final MenuItem refreshItem = optionsMenu
                    .findItem(R.id.menu_refresh);
            if (refreshItem != null) {
                if (refreshing) {
                    MenuItemCompat.setActionView(refreshItem, R.layout.actionbar_progress);
                } else {
                    MenuItemCompat.setActionView(refreshItem, null);
                }
            }
        }
    }
 
Example 9
Source File: ActFreemporg.java    From freemp with Apache License 2.0 5 votes vote down vote up
public void setRefreshActionButtonState() {

        //если статус обновляется - заменяем иконку обновить на крутящийся прогрессбар
        if (optionsMenu != null) {
            final MenuItem refreshItem = optionsMenu
                    .findItem(R.id.menu_refresh);
            if (refreshItem != null) {
                if (refreshing) {
                    MenuItemCompat.setActionView(refreshItem, R.layout.actionbar_progress);
                } else {
                    MenuItemCompat.setActionView(refreshItem, null);
                }
            }
        }
    }
 
Example 10
Source File: LoaderCustomSupport.java    From V.FlyoutTest with MIT License 5 votes vote down vote up
@Override public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    // Place an action bar item for searching.
    MenuItem item = menu.add("Search");
    item.setIcon(android.R.drawable.ic_menu_search);
    MenuItemCompat.setShowAsAction(item, MenuItemCompat.SHOW_AS_ACTION_IF_ROOM
            | MenuItemCompat.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW);
    final View searchView = SearchViewCompat.newSearchView(getActivity());
    if (searchView != null) {
        SearchViewCompat.setOnQueryTextListener(searchView,
                new OnQueryTextListenerCompat() {
            @Override
            public boolean onQueryTextChange(String newText) {
                // Called when the action bar search text has changed.  Since this
                // is a simple array adapter, we can just have it do the filtering.
                mCurFilter = !TextUtils.isEmpty(newText) ? newText : null;
                mAdapter.getFilter().filter(mCurFilter);
                return true;
            }
        });
        SearchViewCompat.setOnCloseListener(searchView,
                new OnCloseListenerCompat() {
                    @Override
                    public boolean onClose() {
                        if (!TextUtils.isEmpty(SearchViewCompat.getQuery(searchView))) {
                            SearchViewCompat.setQuery(searchView, null, true);
                        }
                        return true;
                    }
            
        });
        MenuItemCompat.setActionView(item, searchView);
    }
}
 
Example 11
Source File: LoaderRetainedSupport.java    From V.FlyoutTest with MIT License 5 votes vote down vote up
@Override public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    // Place an action bar item for searching.
    MenuItem item = menu.add("Search");
    item.setIcon(android.R.drawable.ic_menu_search);
    MenuItemCompat.setShowAsAction(item, MenuItemCompat.SHOW_AS_ACTION_ALWAYS
            | MenuItemCompat.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW);
    View searchView = SearchViewCompat.newSearchView(getActivity());
    if (searchView != null) {
        SearchViewCompat.setOnQueryTextListener(searchView,
                new OnQueryTextListenerCompat() {
            @Override
            public boolean onQueryTextChange(String newText) {
                // Called when the action bar search text has changed.  Update
                // the search filter, and restart the loader to do a new query
                // with this filter.
                String newFilter = !TextUtils.isEmpty(newText) ? newText : null;
                // Don't do anything if the filter hasn't actually changed.
                // Prevents restarting the loader when restoring state.
                if (mCurFilter == null && newFilter == null) {
                    return true;
                }
                if (mCurFilter != null && mCurFilter.equals(newFilter)) {
                    return true;
                }
                mCurFilter = newFilter;
                getLoaderManager().restartLoader(0, null, CursorLoaderListFragment.this);
                return true;
            }
        });
        MenuItemCompat.setActionView(item, searchView);
    }
}
 
Example 12
Source File: SwapWorkflowActivity.java    From fdroidclient with GNU General Public License v3.0 5 votes vote down vote up
private void setUpSearchView(Menu menu) {
    SearchView searchView = new SearchView(this);

    MenuItem searchMenuItem = menu.findItem(R.id.action_search);
    MenuItemCompat.setActionView(searchMenuItem, searchView);
    MenuItemCompat.setShowAsAction(searchMenuItem, MenuItemCompat.SHOW_AS_ACTION_IF_ROOM);

    searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {

        @Override
        public boolean onQueryTextSubmit(String newText) {
            String currentFilterString = currentView.getCurrentFilterString();
            String newFilter = !TextUtils.isEmpty(newText) ? newText : null;
            if (currentFilterString == null && newFilter == null) {
                return true;
            }
            if (currentFilterString != null && currentFilterString.equals(newFilter)) {
                return true;
            }
            currentView.setCurrentFilterString(newFilter);
            if (currentView instanceof SelectAppsView) {
                getSupportLoaderManager().restartLoader(currentView.getLayoutResId(), null,
                        (SelectAppsView) currentView);
            } else if (currentView instanceof SwapSuccessView) {
                getSupportLoaderManager().restartLoader(currentView.getLayoutResId(), null,
                        (SwapSuccessView) currentView);
            } else {
                throw new IllegalStateException(currentView.getClass() + " does not have Loader!");
            }
            return true;
        }

        @Override
        public boolean onQueryTextChange(String s) {
            return true;
        }
    });
}
 
Example 13
Source File: General.java    From redalert-android with Apache License 2.0 5 votes vote down vote up
void initializeLoadingIndicator(Menu OptionsMenu) {
    // Add refresh in Action Bar
    mLoadingItem = OptionsMenu.add(Menu.NONE, Menu.NONE, Menu.NONE, getString(R.string.signing_up));

    // Set up the view
    MenuItemCompat.setActionView(mLoadingItem, R.layout.loading);

    // Specify the show flags
    MenuItemCompat.setShowAsAction(mLoadingItem, MenuItem.SHOW_AS_ACTION_ALWAYS);

    // Hide by default
    mLoadingItem.setVisible(false);
}
 
Example 14
Source File: Main.java    From redalert-android with Apache License 2.0 5 votes vote down vote up
void initializeLoadingIndicator(Menu OptionsMenu) {
    // Add refresh in Action Bar
    mLoadingItem = OptionsMenu.add(Menu.NONE, Menu.NONE, Menu.NONE, getString(R.string.loading));

    // Set up the view
    MenuItemCompat.setActionView(mLoadingItem, R.layout.loading);

    // Specify the show flags
    MenuItemCompat.setShowAsAction(mLoadingItem, MenuItem.SHOW_AS_ACTION_ALWAYS);

    // Hide by default
    mLoadingItem.setVisible(false);
}
 
Example 15
Source File: BuildpropFragment.java    From kernel_adiutor with Apache License 2.0 5 votes vote down vote up
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    super.onCreateOptionsMenu(menu, inflater);
    inflater.inflate(R.menu.build_prop_menu, menu);

    searchItem = menu.findItem(R.id.search);
    SearchView searchView = new SearchView(getActionBar().getThemedContext());
    searchView.setQueryHint(getString(R.string.search));

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

        @Override
        public boolean onQueryTextChange(String newText) {
            removeAllViews();

            Object[] keys = buildpropItem.keySet().toArray();
            Object[] values = buildpropItem.values().toArray();
            for (int i = 0; i < keys.length; i++)
                if (((String) keys[i]).contains(newText)) {
                    PopupCardView.DPopupCard mPopupCard = new PopupCardView.DPopupCard(null);
                    mPopupCard.setDescription(newText.isEmpty() ?
                            (String) keys[i] : Html.fromHtml(((String) keys[i]).replace(newText, "" +
                            "<b><font color=\"#2A7289\">" + newText + "</font></b>")));
                    mPopupCard.setItem((String) values[i]);
                    mPopupCard.setOnClickListener(BuildpropFragment.this);

                    addView(mPopupCard);
                }
            return true;
        }
    });
}
 
Example 16
Source File: UserFragment.java    From droidddle with Apache License 2.0 5 votes vote down vote up
private void startMenuLoading() {
    if (mMenuProgressView == null) {
        initMenuProgressView();
    }
    MenuItemCompat.setActionView(mFollowMenu, R.layout.menu_item_action_refresh);
    MenuItemCompat.expandActionView(mFollowMenu);
    View view = MenuItemCompat.getActionView(mFollowMenu);
    ((ProgressView) view.findViewById(R.id.progress)).start();
}
 
Example 17
Source File: LoaderCursorSupport.java    From V.FlyoutTest with MIT License 4 votes vote down vote up
@Override public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    // Place an action bar item for searching.
    MenuItem item = menu.add("Search");
    item.setIcon(android.R.drawable.ic_menu_search);
    MenuItemCompat.setShowAsAction(item, MenuItemCompat.SHOW_AS_ACTION_ALWAYS
            | MenuItemCompat.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW);
    final View searchView = SearchViewCompat.newSearchView(getActivity());
    if (searchView != null) {
        SearchViewCompat.setOnQueryTextListener(searchView,
                new OnQueryTextListenerCompat() {
            @Override
            public boolean onQueryTextChange(String newText) {
                // Called when the action bar search text has changed.  Update
                // the search filter, and restart the loader to do a new query
                // with this filter.
                String newFilter = !TextUtils.isEmpty(newText) ? newText : null;
                // Don't do anything if the filter hasn't actually changed.
                // Prevents restarting the loader when restoring state.
                if (mCurFilter == null && newFilter == null) {
                    return true;
                }
                if (mCurFilter != null && mCurFilter.equals(newFilter)) {
                    return true;
                }
                mCurFilter = newFilter;
                getLoaderManager().restartLoader(0, null, CursorLoaderListFragment.this);
                return true;
            }
        });
        SearchViewCompat.setOnCloseListener(searchView,
                new OnCloseListenerCompat() {
                    @Override
                    public boolean onClose() {
                        if (!TextUtils.isEmpty(SearchViewCompat.getQuery(searchView))) {
                            SearchViewCompat.setQuery(searchView, null, true);
                        }
                        return true;
                    }
            
        });
        MenuItemCompat.setActionView(item, searchView);
    }
}
 
Example 18
Source File: UserFragment.java    From droidddle with Apache License 2.0 4 votes vote down vote up
private void stopMenuLoading() {
    MenuItemCompat.collapseActionView(mFollowMenu);
    MenuItemCompat.setActionView(mFollowMenu, null);
}
 
Example 19
Source File: TeamFragment.java    From droidddle with Apache License 2.0 4 votes vote down vote up
private void stopMenuLoading() {
    MenuItemCompat.collapseActionView(mFollowMenu);
    MenuItemCompat.setActionView(mFollowMenu, null);
}
 
Example 20
Source File: TeamFragment.java    From droidddle with Apache License 2.0 4 votes vote down vote up
private void startMenuLoading() {
    MenuItemCompat.setActionView(mFollowMenu, R.layout.menu_item_action_refresh);
    MenuItemCompat.expandActionView(mFollowMenu);
    View view = MenuItemCompat.getActionView(mFollowMenu);
    ((ProgressView) view.findViewById(R.id.progress)).start();
}