• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2009 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 import com.google.common.annotations.VisibleForTesting;
20 
21 import android.content.Intent;
22 
23 
24 /**
25  * Holds data for each suggest item including the display data and how to launch the result.
26  * Used for passing from the provider to the suggest cursor.
27  */
28 public class SuggestionData implements Suggestion {
29 
30     private final Source mSource;
31     private String mFormat;
32     private String mText1;
33     private String mText2;
34     private String mText2Url;
35     private String mIcon1;
36     private String mIcon2;
37     private String mShortcutId;
38     private boolean mSpinnerWhileRefreshing;
39     private String mIntentAction;
40     private String mIntentData;
41     private String mIntentExtraData;
42     private String mSuggestionQuery;
43     private String mLogType;
44     private boolean mIsShortcut;
45 
SuggestionData(Source source)46     public SuggestionData(Source source) {
47         mSource = source;
48     }
49 
getSuggestionSource()50     public Source getSuggestionSource() {
51         return mSource;
52     }
53 
getSuggestionFormat()54     public String getSuggestionFormat() {
55         return mFormat;
56     }
57 
getSuggestionText1()58     public String getSuggestionText1() {
59         return mText1;
60     }
61 
getSuggestionText2()62     public String getSuggestionText2() {
63         return mText2;
64     }
65 
getSuggestionText2Url()66     public String getSuggestionText2Url() {
67         return mText2Url;
68     }
69 
getSuggestionIcon1()70     public String getSuggestionIcon1() {
71         return mIcon1;
72     }
73 
getSuggestionIcon2()74     public String getSuggestionIcon2() {
75         return mIcon2;
76     }
77 
isSpinnerWhileRefreshing()78     public boolean isSpinnerWhileRefreshing() {
79         return mSpinnerWhileRefreshing;
80     }
81 
getIntentExtraData()82     public String getIntentExtraData() {
83         return mIntentExtraData;
84     }
85 
getShortcutId()86     public String getShortcutId() {
87         return mShortcutId;
88     }
89 
getSuggestionIntentAction()90     public String getSuggestionIntentAction() {
91         if (mIntentAction != null) return mIntentAction;
92         return mSource.getDefaultIntentAction();
93     }
94 
getSuggestionIntentDataString()95     public String getSuggestionIntentDataString() {
96         return mIntentData;
97     }
98 
getSuggestionIntentExtraData()99     public String getSuggestionIntentExtraData() {
100         return mIntentExtraData;
101     }
102 
getSuggestionQuery()103     public String getSuggestionQuery() {
104         return mSuggestionQuery;
105     }
106 
getSuggestionLogType()107     public String getSuggestionLogType() {
108         return mLogType;
109     }
110 
isSuggestionShortcut()111     public boolean isSuggestionShortcut() {
112         return mIsShortcut;
113     }
114 
isWebSearchSuggestion()115     public boolean isWebSearchSuggestion() {
116         return Intent.ACTION_WEB_SEARCH.equals(getSuggestionIntentAction());
117     }
118 
119     @VisibleForTesting
setFormat(String format)120     public SuggestionData setFormat(String format) {
121         mFormat = format;
122         return this;
123     }
124 
125     @VisibleForTesting
setText1(String text1)126     public SuggestionData setText1(String text1) {
127         mText1 = text1;
128         return this;
129     }
130 
131     @VisibleForTesting
setText2(String text2)132     public SuggestionData setText2(String text2) {
133         mText2 = text2;
134         return this;
135     }
136 
137     @VisibleForTesting
setText2Url(String text2Url)138     public SuggestionData setText2Url(String text2Url) {
139         mText2Url = text2Url;
140         return this;
141     }
142 
143     @VisibleForTesting
setIcon1(String icon1)144     public SuggestionData setIcon1(String icon1) {
145         mIcon1 = icon1;
146         return this;
147     }
148 
149     @VisibleForTesting
setIcon2(String icon2)150     public SuggestionData setIcon2(String icon2) {
151         mIcon2 = icon2;
152         return this;
153     }
154 
155     @VisibleForTesting
setIntentAction(String intentAction)156     public SuggestionData setIntentAction(String intentAction) {
157         mIntentAction = intentAction;
158         return this;
159     }
160 
161     @VisibleForTesting
setIntentData(String intentData)162     public SuggestionData setIntentData(String intentData) {
163         mIntentData = intentData;
164         return this;
165     }
166 
167     @VisibleForTesting
setIntentExtraData(String intentExtraData)168     public SuggestionData setIntentExtraData(String intentExtraData) {
169         mIntentExtraData = intentExtraData;
170         return this;
171     }
172 
173     @VisibleForTesting
setSuggestionQuery(String suggestionQuery)174     public SuggestionData setSuggestionQuery(String suggestionQuery) {
175         mSuggestionQuery = suggestionQuery;
176         return this;
177     }
178 
179     @VisibleForTesting
setShortcutId(String shortcutId)180     public SuggestionData setShortcutId(String shortcutId) {
181         mShortcutId = shortcutId;
182         return this;
183     }
184 
185     @VisibleForTesting
setSpinnerWhileRefreshing(boolean spinnerWhileRefreshing)186     public SuggestionData setSpinnerWhileRefreshing(boolean spinnerWhileRefreshing) {
187         mSpinnerWhileRefreshing = spinnerWhileRefreshing;
188         return this;
189     }
190 
191     @VisibleForTesting
setSuggestionLogType(String logType)192     public SuggestionData setSuggestionLogType(String logType) {
193         mLogType = logType;
194         return this;
195     }
196 
197     @VisibleForTesting
setIsShortcut(boolean isShortcut)198     public SuggestionData setIsShortcut(boolean isShortcut) {
199         mIsShortcut = isShortcut;
200         return this;
201     }
202 
203     @Override
hashCode()204     public int hashCode() {
205         final int prime = 31;
206         int result = 1;
207         result = prime * result + ((mFormat == null) ? 0 : mFormat.hashCode());
208         result = prime * result + ((mIcon1 == null) ? 0 : mIcon1.hashCode());
209         result = prime * result + ((mIcon2 == null) ? 0 : mIcon2.hashCode());
210         result = prime * result + ((mIntentAction == null) ? 0 : mIntentAction.hashCode());
211         result = prime * result + ((mIntentData == null) ? 0 : mIntentData.hashCode());
212         result = prime * result + ((mIntentExtraData == null) ? 0 : mIntentExtraData.hashCode());
213         result = prime * result + ((mLogType == null) ? 0 : mLogType.hashCode());
214         result = prime * result + ((mShortcutId == null) ? 0 : mShortcutId.hashCode());
215         result = prime * result + ((mSource == null) ? 0 : mSource.hashCode());
216         result = prime * result + (mSpinnerWhileRefreshing ? 1231 : 1237);
217         result = prime * result + ((mSuggestionQuery == null) ? 0 : mSuggestionQuery.hashCode());
218         result = prime * result + ((mText1 == null) ? 0 : mText1.hashCode());
219         result = prime * result + ((mText2 == null) ? 0 : mText2.hashCode());
220         return result;
221     }
222 
223     @Override
equals(Object obj)224     public boolean equals(Object obj) {
225         if (this == obj)
226             return true;
227         if (obj == null)
228             return false;
229         if (getClass() != obj.getClass())
230             return false;
231         SuggestionData other = (SuggestionData)obj;
232         if (mFormat == null) {
233             if (other.mFormat != null)
234                 return false;
235         } else if (!mFormat.equals(other.mFormat))
236             return false;
237         if (mIcon1 == null) {
238             if (other.mIcon1 != null)
239                 return false;
240         } else if (!mIcon1.equals(other.mIcon1))
241             return false;
242         if (mIcon2 == null) {
243             if (other.mIcon2 != null)
244                 return false;
245         } else if (!mIcon2.equals(other.mIcon2))
246             return false;
247         if (mIntentAction == null) {
248             if (other.mIntentAction != null)
249                 return false;
250         } else if (!mIntentAction.equals(other.mIntentAction))
251             return false;
252         if (mIntentData == null) {
253             if (other.mIntentData != null)
254                 return false;
255         } else if (!mIntentData.equals(other.mIntentData))
256             return false;
257         if (mIntentExtraData == null) {
258             if (other.mIntentExtraData != null)
259                 return false;
260         } else if (!mIntentExtraData.equals(other.mIntentExtraData))
261             return false;
262         if (mLogType == null) {
263             if (other.mLogType != null)
264                 return false;
265         } else if (!mLogType.equals(other.mLogType))
266             return false;
267         if (mShortcutId == null) {
268             if (other.mShortcutId != null)
269                 return false;
270         } else if (!mShortcutId.equals(other.mShortcutId))
271             return false;
272         if (mSource == null) {
273             if (other.mSource != null)
274                 return false;
275         } else if (!mSource.equals(other.mSource))
276             return false;
277         if (mSpinnerWhileRefreshing != other.mSpinnerWhileRefreshing)
278             return false;
279         if (mSuggestionQuery == null) {
280             if (other.mSuggestionQuery != null)
281                 return false;
282         } else if (!mSuggestionQuery.equals(other.mSuggestionQuery))
283             return false;
284         if (mText1 == null) {
285             if (other.mText1 != null)
286                 return false;
287         } else if (!mText1.equals(other.mText1))
288             return false;
289         if (mText2 == null) {
290             if (other.mText2 != null)
291                 return false;
292         } else if (!mText2.equals(other.mText2))
293             return false;
294         return true;
295     }
296 
297     /**
298      * Returns a string representation of the contents of this SuggestionData,
299      * for debugging purposes.
300      */
301     @Override
toString()302     public String toString() {
303         StringBuilder builder = new StringBuilder("SuggestionData(");
304         appendField(builder, "source", mSource.getName());
305         appendField(builder, "text1", mText1);
306         appendField(builder, "intentAction", mIntentAction);
307         appendField(builder, "intentData", mIntentData);
308         appendField(builder, "query", mSuggestionQuery);
309         appendField(builder, "shortcutid", mShortcutId);
310         appendField(builder, "logtype", mLogType);
311         return builder.toString();
312     }
313 
appendField(StringBuilder builder, String name, String value)314     private void appendField(StringBuilder builder, String name, String value) {
315         if (value != null) {
316             builder.append(",").append(name).append("=").append(value);
317         }
318     }
319 
320 }
321