SearchIndexableData.java revision 773a56bbf48beaa0ee10de55e08387ab1024ae26
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 class name associated with the data. Generally this is a Fragment class name for
62     * referring where the data is coming from and for launching the associated Fragment for
63     * displaying the data. This is used only when the data is provided "locally".
64     *
65     * If the data is provided "externally", the relevant information come from the
66     * {@link SearchIndexableData#intentAction} and {@link SearchIndexableData#intentTargetPackage}
67     * and {@link SearchIndexableData#intentTargetClass}.
68     *
69     * @see SearchIndexableData#intentAction
70     * @see SearchIndexableData#intentTargetPackage
71     * @see SearchIndexableData#intentTargetClass
72     */
73    public String className;
74
75    /**
76     * The package name for retrieving the icon associated with the data.
77     *
78     * @see SearchIndexableData#iconResId
79     */
80    public String packageName;
81
82    /**
83     * The icon resource ID associated with the data.
84     *
85     * @see SearchIndexableData#packageName
86     */
87    public int iconResId;
88
89    /**
90     * The Intent action associated with the data. This is used when the
91     * {@link SearchIndexableData#className} is not relevant.
92     *
93     * @see SearchIndexableData#intentTargetPackage
94     * @see SearchIndexableData#intentTargetClass
95     */
96    public String intentAction;
97
98    /**
99     * The Intent target package associated with the data.
100     *
101     * @see SearchIndexableData#intentAction
102     * @see SearchIndexableData#intentTargetClass
103     */
104    public String intentTargetPackage;
105
106    /**
107     * The Intent target class associated with the data.
108     *
109     * @see SearchIndexableData#intentAction
110     * @see SearchIndexableData#intentTargetPackage
111     */
112    public String intentTargetClass;
113
114    /**
115     * Default constructor.
116     */
117    public SearchIndexableData() {
118        locale = Locale.getDefault();
119        enabled = true;
120    }
121
122    /**
123     * Constructor with a {@link Context}.
124     *
125     * @param ctx the Context
126     */
127    public SearchIndexableData(Context ctx) {
128        this();
129        context = ctx;
130    }
131
132    @Override
133    public String toString() {
134        final StringBuilder sb = new StringBuilder();
135        sb.append("SearchIndexableData[context: ");
136        sb.append(context);
137        sb.append(", ");
138        sb.append("locale: ");
139        sb.append(locale);
140        sb.append(", ");
141        sb.append("enabled: ");
142        sb.append(enabled);
143        sb.append(", ");
144        sb.append("rank: ");
145        sb.append(rank);
146        sb.append(", ");
147        sb.append("key: ");
148        sb.append(key);
149        sb.append(", ");
150        sb.append("className: ");
151        sb.append(className);
152        sb.append(", ");
153        sb.append("packageName: ");
154        sb.append(packageName);
155        sb.append(", ");
156        sb.append("iconResId: ");
157        sb.append(iconResId);
158        sb.append(", ");
159        sb.append("intentAction: ");
160        sb.append(intentAction);
161        sb.append(", ");
162        sb.append("intentTargetPackage: ");
163        sb.append(intentTargetPackage);
164        sb.append(", ");
165        sb.append("intentTargetClass: ");
166        sb.append(intentTargetClass);
167        sb.append("]");
168
169        return sb.toString();
170    }
171}
172