Example usage for android.app SearchManager setOnDismissListener

List of usage examples for android.app SearchManager setOnDismissListener

Introduction

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

Prototype

public void setOnDismissListener(final OnDismissListener listener) 

Source Link

Document

Set or clear the callback that will be invoked whenever the search UI is dismissed.

Usage

From source file:org.dicadeveloper.runnerapp.TrackListActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    if (BuildConfig.DEBUG) {
        ApiAdapterFactory.getApiAdapter().enableStrictMode();
    }/* ww w  .  j a  v  a 2  s.com*/

    myTracksProviderUtils = MyTracksProviderUtils.Factory.get(this);
    sharedPreferences = getSharedPreferences(Constants.SETTINGS_NAME, Context.MODE_PRIVATE);

    trackRecordingServiceConnection = new TrackRecordingServiceConnection(this, bindChangedCallback);
    trackController = new TrackController(this, trackRecordingServiceConnection, true, recordListener,
            stopListener);

    setDefaultKeyMode(DEFAULT_KEYS_SEARCH_LOCAL);
    // Show trackController when search dialog is dismissed
    SearchManager searchManager = (SearchManager) getSystemService(SEARCH_SERVICE);
    searchManager.setOnDismissListener(new SearchManager.OnDismissListener() {
        @Override
        public void onDismiss() {
            trackController.show();
        }
    });

    listView = (ListView) findViewById(R.id.track_list);
    listView.setEmptyView(findViewById(R.id.track_list_empty_view));
    listView.setOnItemClickListener(new OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            Intent newIntent = IntentUtils.newIntent(TrackListActivity.this, TrackDetailActivity.class)
                    .putExtra(TrackDetailActivity.EXTRA_TRACK_ID, id);
            startActivity(newIntent);
        }
    });
    sectionResourceCursorAdapter = new SectionResourceCursorAdapter(this, R.layout.list_item, null, 0) {
        @Override
        public void bindView(View view, Context context, Cursor cursor) {
            int idIndex = cursor.getColumnIndex(TracksColumns._ID);
            int iconIndex = cursor.getColumnIndex(TracksColumns.ICON);
            int nameIndex = cursor.getColumnIndex(TracksColumns.NAME);
            int sharedOwnerIndex = cursor.getColumnIndex(TracksColumns.SHAREDOWNER);
            int totalTimeIndex = cursor.getColumnIndexOrThrow(TracksColumns.TOTALTIME);
            int totalDistanceIndex = cursor.getColumnIndexOrThrow(TracksColumns.TOTALDISTANCE);
            int startTimeIndex = cursor.getColumnIndexOrThrow(TracksColumns.STARTTIME);
            int categoryIndex = cursor.getColumnIndex(TracksColumns.CATEGORY);
            int descriptionIndex = cursor.getColumnIndex(TracksColumns.DESCRIPTION);

            long trackId = cursor.getLong(idIndex);
            boolean isRecording = trackId == recordingTrackId;
            String icon = cursor.getString(iconIndex);
            int iconId = TrackIconUtils.getIconDrawable(icon);
            String name = cursor.getString(nameIndex);
            String sharedOwner = cursor.getString(sharedOwnerIndex);
            String totalTime = StringUtils.formatElapsedTime(cursor.getLong(totalTimeIndex));
            String totalDistance = StringUtils.formatDistance(TrackListActivity.this,
                    cursor.getDouble(totalDistanceIndex), metricUnits);
            int markerCount = myTracksProviderUtils.getWaypointCount(trackId);
            long startTime = cursor.getLong(startTimeIndex);
            String category = icon != null && !icon.equals("") ? null : cursor.getString(categoryIndex);
            String description = cursor.getString(descriptionIndex);

            ListItemUtils.setListItem(TrackListActivity.this, view, isRecording, recordingTrackPaused, iconId,
                    R.string.image_track, name, sharedOwner, totalTime, totalDistance, markerCount, startTime,
                    true, category, description, null);
        }
    };
    listView.setAdapter(sectionResourceCursorAdapter);
    ApiAdapterFactory.getApiAdapter().configureListViewContextualMenu(this, listView,
            contextualActionModeCallback);

    getSupportLoaderManager().initLoader(0, null, loaderCallbacks);
    showStartupDialogs();
}

From source file:br.com.bioscada.apps.biotracks.TrackListActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    if (BuildConfig.DEBUG) {
        ApiAdapterFactory.getApiAdapter().enableStrictMode();
    }/*from  www .j a v  a2  s. c  o m*/

    myTracksProviderUtils = MyTracksProviderUtils.Factory.get(this);
    sharedPreferences = getSharedPreferences(Constants.SETTINGS_NAME, Context.MODE_PRIVATE);

    trackRecordingServiceConnection = new TrackRecordingServiceConnection(this, bindChangedCallback);
    trackController = new TrackController(this, trackRecordingServiceConnection, true, recordListener,
            stopListener);

    setDefaultKeyMode(DEFAULT_KEYS_SEARCH_LOCAL);
    // Show trackController when search dialog is dismissed
    SearchManager searchManager = (SearchManager) getSystemService(SEARCH_SERVICE);
    searchManager.setOnDismissListener(new SearchManager.OnDismissListener() {
        @Override
        public void onDismiss() {
            trackController.show();
        }
    });

    listView = (ListView) findViewById(R.id.track_list);
    listView.setEmptyView(findViewById(R.id.track_list_empty_view));
    listView.setOnItemClickListener(new OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            Intent newIntent = IntentUtils.newIntent(TrackListActivity.this, TrackDetailActivity.class)
                    .putExtra(TrackDetailActivity.EXTRA_TRACK_ID, id);
            startActivity(newIntent);
        }
    });
    sectionResourceCursorAdapter = new SectionResourceCursorAdapter(this, R.layout.list_item, null, 0) {
        @Override
        public void bindView(View view, Context context, Cursor cursor) {
            int idIndex = cursor.getColumnIndex(TracksColumns._ID);
            int iconIndex = cursor.getColumnIndex(TracksColumns.ICON);
            int nameIndex = cursor.getColumnIndex(TracksColumns.NAME);
            int sharedOwnerIndex = cursor.getColumnIndex(TracksColumns.SHAREDOWNER);
            int totalTimeIndex = cursor.getColumnIndexOrThrow(TracksColumns.TOTALTIME);
            int totalDistanceIndex = cursor.getColumnIndexOrThrow(TracksColumns.TOTALDISTANCE);
            int startTimeIndex = cursor.getColumnIndexOrThrow(TracksColumns.STARTTIME);
            int categoryIndex = cursor.getColumnIndex(TracksColumns.CATEGORY);
            int descriptionIndex = cursor.getColumnIndex(TracksColumns.DESCRIPTION);

            long trackId = cursor.getLong(idIndex);
            boolean isRecording = trackId == recordingTrackId;
            String icon = cursor.getString(iconIndex);
            int iconId = TrackIconUtils.getIconDrawable(icon);
            String name = cursor.getString(nameIndex);
            String sharedOwner = cursor.getString(sharedOwnerIndex);
            String totalTime = StringUtils.formatElapsedTime(cursor.getLong(totalTimeIndex));
            String totalDistance = StringUtils.formatDistance(TrackListActivity.this,
                    cursor.getDouble(totalDistanceIndex), metricUnits);
            int markerCount = 0;
            try {
                markerCount = myTracksProviderUtils.getWaypointCount(trackId);
            } catch (Exception e) {
                Log.d("BIOTRACKS", e.getMessage());
            }

            long startTime = cursor.getLong(startTimeIndex);
            String category = icon != null && !icon.equals("") ? null : cursor.getString(categoryIndex);
            String description = cursor.getString(descriptionIndex);

            ListItemUtils.setListItem(TrackListActivity.this, view, isRecording, recordingTrackPaused, iconId,
                    R.string.image_track, name, sharedOwner, totalTime, totalDistance, markerCount, startTime,
                    true, category, description, null);
        }
    };
    listView.setAdapter(sectionResourceCursorAdapter);
    ApiAdapterFactory.getApiAdapter().configureListViewContextualMenu(this, listView,
            contextualActionModeCallback);

    getSupportLoaderManager().initLoader(0, null, loaderCallbacks);
    showStartupDialogs();
}

From source file:com.android.music.MusicBrowserActivity.java

/**
 * M: init search button, set on click listener and search dialog on dismiss
 * listener, disable search button//  w  ww .  j  a v  a  2  s  .  c om
 * when search dialog has shown and enable it after dismiss search dialog.
 */
private void initSearchButton() {
    mSearchButton = (ImageButton) findViewById(R.id.search_menu_nowplaying);
    final View blankView = this.findViewById(R.id.blank_between_search_and_overflow);
    final View nowPlayingView = this.findViewById(R.id.nowplaying);
    if (mSearchButton != null) {
        mSearchButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (mOverflowMenuButton != null) {
                    mOverflowMenuButton.setEnabled(false);
                }
                mSearchButton.setVisibility(View.GONE);
                onSearchRequested();
                if (blankView.getVisibility() == View.VISIBLE) {
                    blankView.setVisibility(View.GONE);
                }
                mSearchViewShowing = true;
            }
        });
        SearchManager searchManager = (SearchManager) this.getSystemService(Context.SEARCH_SERVICE);
        searchManager.setOnDismissListener(new SearchManager.OnDismissListener() {
            @Override
            public void onDismiss() {
                if (mOverflowMenuButton != null) {
                    mOverflowMenuButton.setEnabled(true);
                }
                mSearchButton.setVisibility(View.VISIBLE);
                if (nowPlayingView.getVisibility() != View.VISIBLE && !mHasMenukey) {
                    blankView.setVisibility(View.VISIBLE);
                }
                mSearchViewShowing = false;

                InputMethodManager imm = (InputMethodManager) getApplicationContext()
                        .getSystemService(Context.INPUT_METHOD_SERVICE);
                if (imm != null) {
                    MusicLogUtils.d(TAG, "IIME getService failed");
                }
                MusicLogUtils.d(TAG, "IME getService success");
                if (imm != null) {
                    MusicLogUtils.d(TAG, "Search Dialog hiding the IME");
                    imm.hideSoftInputFromWindow(mSearchButton.getWindowToken(), 0);
                }
                MusicLogUtils.d(TAG, "Search dialog on dismiss, enalbe search button");
            }
        });
    }
}