Example usage for android.app SearchManager SEARCH_MODE

List of usage examples for android.app SearchManager SEARCH_MODE

Introduction

In this page you can find the example usage for android.app SearchManager SEARCH_MODE.

Prototype

String SEARCH_MODE

To view the source code for android.app SearchManager SEARCH_MODE.

Click Source Link

Document

Intent extra data key: Use android.content.Intent#getBundleExtra content.Intent.getBundleExtra(SEARCH_MODE) to get the search mode used to launch the intent.

Usage

From source file:com.cyanogenmod.eleven.ui.activities.SearchActivity.java

/**
 * {@inheritDoc}// ww w .j  a v  a 2 s .  co  m
 */
@Override
public void onCreate(final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    mPopupMenuHelper = new PopupMenuHelper(this, getSupportFragmentManager()) {
        private SearchResult mSelectedItem;

        @Override
        public PopupMenuType onPreparePopupMenu(int position) {
            mSelectedItem = mAdapter.getTItem(position);

            return PopupMenuType.SearchResult;
        }

        @Override
        protected long[] getIdList() {
            switch (mSelectedItem.mType) {
            case Artist:
                return MusicUtils.getSongListForArtist(SearchActivity.this, mSelectedItem.mId);
            case Album:
                return MusicUtils.getSongListForAlbum(SearchActivity.this, mSelectedItem.mId);
            case Song:
                return new long[] { mSelectedItem.mId };
            case Playlist:
                return MusicUtils.getSongListForPlaylist(SearchActivity.this, mSelectedItem.mId);
            default:
                return null;
            }
        }

        @Override
        protected long getSourceId() {
            return mSelectedItem.mId;
        }

        @Override
        protected Config.IdType getSourceType() {
            return mSelectedItem.mType.getSourceType();
        }

        @Override
        protected void updateMenuIds(PopupMenuType type, TreeSet<Integer> set) {
            super.updateMenuIds(type, set);

            if (mSelectedItem.mType == ResultType.Album) {
                set.add(FragmentMenuItems.MORE_BY_ARTIST);
            }
        }

        @Override
        protected String getArtistName() {
            return mSelectedItem.mArtist;
        }
    };

    // Fade it in
    overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out);

    // Control the media volume
    setVolumeControlStream(AudioManager.STREAM_MUSIC);

    // Bind Apollo's service
    mToken = MusicUtils.bindToService(this, this);

    // Set the layout
    setContentView(R.layout.activity_search);

    // get the input method manager
    mImm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);

    // Initialize the adapter
    SummarySearchAdapter adapter = new SummarySearchAdapter(this);
    mAdapter = new SectionAdapter<SearchResult, SummarySearchAdapter>(this, adapter);
    // Set the prefix
    mAdapter.getUnderlyingAdapter().setPrefix(mFilterString);
    mAdapter.setupHeaderParameters(R.layout.list_search_header, false);
    mAdapter.setupFooterParameters(R.layout.list_search_footer, true);
    mAdapter.setPopupMenuClickedListener(new IPopupMenuCallback.IListener() {
        @Override
        public void onPopupMenuClicked(View v, int position) {
            mPopupMenuHelper.showPopupMenu(v, position);
        }
    });

    mLoadingEmptyContainer = (LoadingEmptyContainer) findViewById(R.id.loading_empty_container);
    // setup the no results container
    NoResultsContainer noResults = mLoadingEmptyContainer.getNoResultsContainer();
    noResults.setMainText(R.string.empty_search);
    noResults.setSecondaryText(R.string.empty_search_check);

    initListView();

    // setup handler and runnable
    mHandler = new Handler();
    mLoadingRunnable = new Runnable() {
        @Override
        public void run() {
            setState(VisibleState.Loading);
        }
    };

    // Theme the action bar
    final ActionBar actionBar = getActionBar();
    actionBar.setDisplayHomeAsUpEnabled(true);

    // Get the query String
    mFilterString = getIntent().getStringExtra(SearchManager.QUERY);

    // if we have a non-empty search string, this is a 2nd lvl search
    if (!TextUtils.isEmpty(mFilterString)) {
        mTopLevelSearch = false;

        // get the search type to filter by
        int type = getIntent().getIntExtra(SearchManager.SEARCH_MODE, -1);
        if (type >= 0 && type < ResultType.values().length) {
            mSearchType = ResultType.values()[type];
        }

        int resourceId = 0;
        switch (mSearchType) {
        case Artist:
            resourceId = R.string.search_title_artists;
            break;
        case Album:
            resourceId = R.string.search_title_albums;
            break;
        case Playlist:
            resourceId = R.string.search_title_playlists;
            break;
        case Song:
            resourceId = R.string.search_title_songs;
            break;
        }
        actionBar.setTitle(getString(resourceId, mFilterString).toUpperCase());
        actionBar.setDisplayHomeAsUpEnabled(true);

        // Set the prefix
        mAdapter.getUnderlyingAdapter().setPrefix(mFilterString);

        // Start the loader for the query
        getSupportLoaderManager().initLoader(SEARCH_LOADER, null, this);
    } else {
        mTopLevelSearch = true;
        mSearchHistoryCallback = new SearchHistoryCallback();

        // Start the loader for the search history
        getSupportLoaderManager().initLoader(HISTORY_LOADER, null, mSearchHistoryCallback);
    }

    // set the background on the root view
    getWindow().getDecorView().getRootView()
            .setBackgroundColor(getResources().getColor(R.color.background_color));
}

From source file:com.cyanogenmod.eleven.ui.activities.SearchActivity.java

/**
 * {@inheritDoc}/*  w  w w.  j  a  v a2 s  .c o  m*/
 */
@Override
public void onItemClick(final AdapterView<?> parent, final View view, final int position, final long id) {
    if (mAdapter.isSectionFooter(position)) {
        // since a footer should be after a list item by definition, let's look up the type
        // of the previous item
        SearchResult item = mAdapter.getTItem(position - 1);
        Intent intent = new Intent(this, SearchActivity.class);
        intent.putExtra(SearchManager.QUERY, mFilterString);
        intent.putExtra(SearchManager.SEARCH_MODE, item.mType.ordinal());
        startActivity(intent);
    } else {
        SearchResult item = mAdapter.getTItem(position);
        switch (item.mType) {
        case Artist:
            NavUtils.openArtistProfile(this, item.mArtist);
            break;
        case Album:
            NavUtils.openAlbumProfile(this, item.mAlbum, item.mArtist, item.mId);
            break;
        case Playlist:
            NavUtils.openPlaylist(this, item.mId, item.mTitle);
            break;
        case Song:
            // If it's a song, play it and leave
            final long[] list = new long[] { item.mId };
            MusicUtils.playAll(this, list, 0, -1, Config.IdType.NA, false);
            break;
        }
    }
}