SuggestionUtils.java revision 38eb02e676db9e5a633e3c88a90beb8a477b1ca1
13e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert/* 2fde948e69f59589cf0d217ea414af7947de600bbBjorn Bringert * Copyright (C) 2010 The Android Open Source Project 33e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert * 43e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert * Licensed under the Apache License, Version 2.0 (the "License"); 53e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert * you may not use this file except in compliance with the License. 63e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert * You may obtain a copy of the License at 73e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert * 83e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert * http://www.apache.org/licenses/LICENSE-2.0 93e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert * 103e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert * Unless required by applicable law or agreed to in writing, software 113e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert * distributed under the License is distributed on an "AS IS" BASIS, 123e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 133e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert * See the License for the specific language governing permissions and 143e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert * limitations under the License. 153e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert */ 163e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert 173e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringertpackage com.android.quicksearchbox; 183e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert 1981a0897ff9685f3313c58294bf7973700c468b2bBjorn Bringertimport android.app.SearchManager; 2081a0897ff9685f3313c58294bf7973700c468b2bBjorn Bringertimport android.content.Intent; 2181a0897ff9685f3313c58294bf7973700c468b2bBjorn Bringertimport android.net.Uri; 2281a0897ff9685f3313c58294bf7973700c468b2bBjorn Bringertimport android.os.Bundle; 2381a0897ff9685f3313c58294bf7973700c468b2bBjorn Bringert 243e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert/** 2593bd2e70b8b08da1ec37fd0e990dac05551d2e90Bjorn Bringert * Some utilities for suggestions. 263e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert */ 2793bd2e70b8b08da1ec37fd0e990dac05551d2e90Bjorn Bringertpublic class SuggestionUtils { 283e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert 2993bd2e70b8b08da1ec37fd0e990dac05551d2e90Bjorn Bringert private SuggestionUtils() { 303e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert } 313e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert 3293bd2e70b8b08da1ec37fd0e990dac05551d2e90Bjorn Bringert public static Intent getSuggestionIntent(SuggestionCursor suggestion, Bundle appSearchData) { 3393bd2e70b8b08da1ec37fd0e990dac05551d2e90Bjorn Bringert String action = suggestion.getSuggestionIntentAction(); 3481a0897ff9685f3313c58294bf7973700c468b2bBjorn Bringert 3593bd2e70b8b08da1ec37fd0e990dac05551d2e90Bjorn Bringert String data = suggestion.getSuggestionIntentDataString(); 3693bd2e70b8b08da1ec37fd0e990dac05551d2e90Bjorn Bringert String query = suggestion.getSuggestionQuery(); 3793bd2e70b8b08da1ec37fd0e990dac05551d2e90Bjorn Bringert String userQuery = suggestion.getUserQuery(); 3893bd2e70b8b08da1ec37fd0e990dac05551d2e90Bjorn Bringert String extraData = suggestion.getSuggestionIntentExtraData(); 3981a0897ff9685f3313c58294bf7973700c468b2bBjorn Bringert 4081a0897ff9685f3313c58294bf7973700c468b2bBjorn Bringert // Now build the Intent 4181a0897ff9685f3313c58294bf7973700c468b2bBjorn Bringert Intent intent = new Intent(action); 4281a0897ff9685f3313c58294bf7973700c468b2bBjorn Bringert intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 4381a0897ff9685f3313c58294bf7973700c468b2bBjorn Bringert // We need CLEAR_TOP to avoid reusing an old task that has other activities 4481a0897ff9685f3313c58294bf7973700c468b2bBjorn Bringert // on top of the one we want. 4581a0897ff9685f3313c58294bf7973700c468b2bBjorn Bringert intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); 4681a0897ff9685f3313c58294bf7973700c468b2bBjorn Bringert if (data != null) { 4781a0897ff9685f3313c58294bf7973700c468b2bBjorn Bringert intent.setData(Uri.parse(data)); 4881a0897ff9685f3313c58294bf7973700c468b2bBjorn Bringert } 4981a0897ff9685f3313c58294bf7973700c468b2bBjorn Bringert intent.putExtra(SearchManager.USER_QUERY, userQuery); 5081a0897ff9685f3313c58294bf7973700c468b2bBjorn Bringert if (query != null) { 5181a0897ff9685f3313c58294bf7973700c468b2bBjorn Bringert intent.putExtra(SearchManager.QUERY, query); 5281a0897ff9685f3313c58294bf7973700c468b2bBjorn Bringert } 5381a0897ff9685f3313c58294bf7973700c468b2bBjorn Bringert if (extraData != null) { 5481a0897ff9685f3313c58294bf7973700c468b2bBjorn Bringert intent.putExtra(SearchManager.EXTRA_DATA_KEY, extraData); 5581a0897ff9685f3313c58294bf7973700c468b2bBjorn Bringert } 5681a0897ff9685f3313c58294bf7973700c468b2bBjorn Bringert if (appSearchData != null) { 5781a0897ff9685f3313c58294bf7973700c468b2bBjorn Bringert intent.putExtra(SearchManager.APP_DATA, appSearchData); 5881a0897ff9685f3313c58294bf7973700c468b2bBjorn Bringert } 5981a0897ff9685f3313c58294bf7973700c468b2bBjorn Bringert 6038eb02e676db9e5a633e3c88a90beb8a477b1ca1Bjorn Bringert intent.setComponent(suggestion.getSuggestionIntentComponent()); 6181a0897ff9685f3313c58294bf7973700c468b2bBjorn Bringert return intent; 6281a0897ff9685f3313c58294bf7973700c468b2bBjorn Bringert } 6381a0897ff9685f3313c58294bf7973700c468b2bBjorn Bringert 643e44ff1f2a204db3f479698cf0b3eab3d451dec2Bjorn Bringert} 65