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