1 /*
2  * Copyright (C) 2014 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 android.provider;
18 
19 import android.annotation.SystemApi;
20 import android.content.Context;
21 
22 import java.util.Locale;
23 
24 /**
25  * The Indexable data for Search.
26  *
27  * This abstract class defines the common parts for all search indexable data.
28  *
29  * @hide
30  */
31 @SystemApi
32 public abstract class SearchIndexableData {
33 
34     /**
35      * The context for the data. Will usually allow retrieving some resources.
36      *
37      * @see Context
38      */
39     public Context context;
40 
41     /**
42      * The locale for the data
43      */
44     public Locale locale;
45 
46     /**
47      * Tells if the data will be included into the search results. This is application specific.
48      */
49     public boolean enabled;
50 
51     /**
52      * The rank for the data. This is application specific.
53      */
54     public int rank;
55 
56     /**
57      * The key for the data. This is application specific. Should be unique per data as the data
58      * should be able to be retrieved by the key.
59      * <p/>
60      * This is required for indexing to work.
61      */
62     public String key;
63 
64     /**
65      * The UserID for the data (in a multi user context). This is application specific and -1 is the
66      * default non initialized value.
67      */
68     public int userId = -1;
69 
70     /**
71      * The class name associated with the data. Generally this is a Fragment class name for
72      * referring where the data is coming from and for launching the associated Fragment for
73      * displaying the data. This is used only when the data is provided "locally".
74      *
75      * If the data is provided "externally", the relevant information come from the
76      * {@link SearchIndexableData#intentAction} and {@link SearchIndexableData#intentTargetPackage}
77      * and {@link SearchIndexableData#intentTargetClass}.
78      *
79      * @see SearchIndexableData#intentAction
80      * @see SearchIndexableData#intentTargetPackage
81      * @see SearchIndexableData#intentTargetClass
82      */
83     public String className;
84 
85     /**
86      * The package name for retrieving the icon associated with the data.
87      *
88      * @see SearchIndexableData#iconResId
89      */
90     public String packageName;
91 
92     /**
93      * The icon resource ID associated with the data.
94      *
95      * @see SearchIndexableData#packageName
96      */
97     public int iconResId;
98 
99     /**
100      * The Intent action associated with the data. This is used when the
101      * {@link SearchIndexableData#className} is not relevant.
102      *
103      * @see SearchIndexableData#intentTargetPackage
104      * @see SearchIndexableData#intentTargetClass
105      */
106     public String intentAction;
107 
108     /**
109      * The Intent target package associated with the data.
110      *
111      * @see SearchIndexableData#intentAction
112      * @see SearchIndexableData#intentTargetClass
113      */
114     public String intentTargetPackage;
115 
116     /**
117      * The Intent target class associated with the data.
118      *
119      * @see SearchIndexableData#intentAction
120      * @see SearchIndexableData#intentTargetPackage
121      */
122     public String intentTargetClass;
123 
124     /**
125      * Default constructor.
126      */
SearchIndexableData()127     public SearchIndexableData() {
128         locale = Locale.getDefault();
129         enabled = true;
130     }
131 
132     /**
133      * Constructor with a {@link Context}.
134      *
135      * @param ctx the Context
136      */
SearchIndexableData(Context ctx)137     public SearchIndexableData(Context ctx) {
138         this();
139         context = ctx;
140     }
141 
142     @Override
toString()143     public String toString() {
144         final StringBuilder sb = new StringBuilder();
145         sb.append("SearchIndexableData[context: ");
146         sb.append(context);
147         sb.append(", ");
148         sb.append("locale: ");
149         sb.append(locale);
150         sb.append(", ");
151         sb.append("enabled: ");
152         sb.append(enabled);
153         sb.append(", ");
154         sb.append("rank: ");
155         sb.append(rank);
156         sb.append(", ");
157         sb.append("key: ");
158         sb.append(key);
159         sb.append(", ");
160         sb.append("userId: ");
161         sb.append(userId);
162         sb.append(", ");
163         sb.append("className: ");
164         sb.append(className);
165         sb.append(", ");
166         sb.append("packageName: ");
167         sb.append(packageName);
168         sb.append(", ");
169         sb.append("iconResId: ");
170         sb.append(iconResId);
171         sb.append(", ");
172         sb.append("intentAction: ");
173         sb.append(intentAction);
174         sb.append(", ");
175         sb.append("intentTargetPackage: ");
176         sb.append(intentTargetPackage);
177         sb.append(", ");
178         sb.append("intentTargetClass: ");
179         sb.append(intentTargetClass);
180         sb.append("]");
181 
182         return sb.toString();
183     }
184 }
185