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