SuggestionUtils.java revision 38eb02e676db9e5a633e3c88a90beb8a477b1ca1
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 String action = suggestion.getSuggestionIntentAction(); 34 35 String data = suggestion.getSuggestionIntentDataString(); 36 String query = suggestion.getSuggestionQuery(); 37 String userQuery = suggestion.getUserQuery(); 38 String extraData = suggestion.getSuggestionIntentExtraData(); 39 40 // Now build the Intent 41 Intent intent = new Intent(action); 42 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 43 // We need CLEAR_TOP to avoid reusing an old task that has other activities 44 // on top of the one we want. 45 intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); 46 if (data != null) { 47 intent.setData(Uri.parse(data)); 48 } 49 intent.putExtra(SearchManager.USER_QUERY, userQuery); 50 if (query != null) { 51 intent.putExtra(SearchManager.QUERY, query); 52 } 53 if (extraData != null) { 54 intent.putExtra(SearchManager.EXTRA_DATA_KEY, extraData); 55 } 56 if (appSearchData != null) { 57 intent.putExtra(SearchManager.APP_DATA, appSearchData); 58 } 59 60 intent.setComponent(suggestion.getSuggestionIntentComponent()); 61 return intent; 62 } 63 64} 65