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