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 17 package com.android.quicksearchbox; 18 19 20 /** 21 * Base class for suggestion cursors. 22 */ 23 public abstract class AbstractSuggestionCursor implements SuggestionCursor { 24 25 private final String mUserQuery; 26 27 public AbstractSuggestionCursor(String userQuery) { 28 mUserQuery = userQuery; 29 } 30 31 public String getUserQuery() { 32 return mUserQuery; 33 } 34 35 public String getSuggestionDisplayQuery() { 36 String query = getSuggestionQuery(); 37 if (query != null) { 38 return query; 39 } 40 Source source = getSuggestionSource(); 41 if (source.shouldRewriteQueryFromData()) { 42 String data = getSuggestionIntentDataString(); 43 if (data != null) { 44 return data; 45 } 46 } 47 if (source.shouldRewriteQueryFromText()) { 48 String text1 = getSuggestionText1(); 49 if (text1 != null) { 50 return text1; 51 } 52 } 53 return null; 54 } 55 56 } 57