SuggestionUtils.java revision 93bd2e70b8b08da1ec37fd0e990dac05551d2e90
1/* 2 * Copyright (C) 2010 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17package com.android.quicksearchbox; 18 19import android.app.SearchManager; 20import android.content.Intent; 21import android.net.Uri; 22import android.os.Bundle; 23 24/** 25 * Some utilities for suggestions. 26 */ 27public class SuggestionUtils { 28 29 private SuggestionUtils() { 30 } 31 32 public static Intent getSuggestionIntent(SuggestionCursor suggestion, Bundle appSearchData) { 33 Source source = suggestion.getSuggestionSource(); 34 String action = suggestion.getSuggestionIntentAction(); 35 36 String data = suggestion.getSuggestionIntentDataString(); 37 String query = suggestion.getSuggestionQuery(); 38 String userQuery = suggestion.getUserQuery(); 39 String extraData = suggestion.getSuggestionIntentExtraData(); 40 41 // Now build the Intent 42 Intent intent = new Intent(action); 43 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 44 // We need CLEAR_TOP to avoid reusing an old task that has other activities 45 // on top of the one we want. 46 intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); 47 if (data != null) { 48 intent.setData(Uri.parse(data)); 49 } 50 intent.putExtra(SearchManager.USER_QUERY, userQuery); 51 if (query != null) { 52 intent.putExtra(SearchManager.QUERY, query); 53 } 54 if (extraData != null) { 55 intent.putExtra(SearchManager.EXTRA_DATA_KEY, extraData); 56 } 57 if (appSearchData != null) { 58 intent.putExtra(SearchManager.APP_DATA, appSearchData); 59 } 60 61 intent.setComponent(source.getIntentComponent()); 62 return intent; 63 } 64 65} 66