Home | History | Annotate | Download | only in search
      1 /*
      2  * Copyright (C) 2017 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 
     18 package com.android.settings.search;
     19 
     20 import android.annotation.IntDef;
     21 import android.content.Intent;
     22 import android.os.Parcel;
     23 import android.os.Parcelable;
     24 
     25 import java.lang.annotation.Retention;
     26 import java.lang.annotation.RetentionPolicy;
     27 
     28 /**
     29  * A interface for search results types. Examples include Inline results, third party apps
     30  * or any future possibilities.
     31  */
     32 public class ResultPayload implements Parcelable {
     33     protected final Intent mIntent;
     34 
     35     @IntDef({PayloadType.INTENT, PayloadType.INLINE_SLIDER, PayloadType.INLINE_SWITCH,
     36             PayloadType.INLINE_LIST, PayloadType.SAVED_QUERY})
     37     @Retention(RetentionPolicy.SOURCE)
     38     public @interface PayloadType {
     39         /**
     40          * Resulting page will be started using an mIntent
     41          */
     42         int INTENT = 0;
     43 
     44         /**
     45          * Result is a inline widget, using a slider widget as UI.
     46          */
     47         int INLINE_SLIDER = 1;
     48 
     49         /**
     50          * Result is a inline widget, using a toggle widget as UI.
     51          */
     52         int INLINE_SWITCH = 2;
     53 
     54         /**
     55          * Result is an inline list-select, with an undefined UI.
     56          */
     57         int INLINE_LIST = 3;
     58 
     59         /**
     60          * Result is a recently saved query.
     61          */
     62         int SAVED_QUERY = 4;
     63     }
     64 
     65     /**
     66      * Enumerates the possible values for the Availability of a setting.
     67      */
     68     @IntDef({Availability.AVAILABLE,
     69             Availability.DISABLED_DEPENDENT_SETTING,
     70             Availability.DISABLED_DEPENDENT_APP,
     71             Availability.DISABLED_UNSUPPORTED,
     72             Availability.RESOURCE_CONTENTION,
     73             Availability.INTENT_ONLY,
     74             Availability.DISABLED_FOR_USER,})
     75     @Retention(RetentionPolicy.SOURCE)
     76     public @interface Availability {
     77         /**
     78          * The setting is available.
     79          */
     80         int AVAILABLE = 0;
     81 
     82         /**
     83          * The setting has a dependency in settings app which is currently disabled, blocking
     84          * access.
     85          */
     86         int DISABLED_DEPENDENT_SETTING = 1;
     87 
     88         /**
     89          * The setting is not supported by the device.
     90          */
     91         int DISABLED_UNSUPPORTED = 2;
     92 
     93         /**
     94          * The setting you are trying to change is being used by another application and cannot
     95          * be changed until it is released by said application.
     96          */
     97         int RESOURCE_CONTENTION = 3;
     98 
     99         /**
    100          * The setting is disabled because corresponding app is disabled.
    101          */
    102         int DISABLED_DEPENDENT_APP = 4;
    103 
    104         /**
    105          * This setting is supported on the device but cannot be changed inline.
    106          */
    107         int INTENT_ONLY = 5;
    108 
    109         /**
    110          * The setting cannot be changed by the current user.
    111          * ex: MobileNetworkTakeMeThereSetting should not be available to a secondary user.
    112          */
    113         int DISABLED_FOR_USER = 6;
    114     }
    115 
    116     @IntDef({SettingsSource.UNKNOWN, SettingsSource.SYSTEM, SettingsSource.SECURE,
    117             SettingsSource.GLOBAL})
    118     @Retention(RetentionPolicy.SOURCE)
    119     public @interface SettingsSource {
    120         int UNKNOWN = 0;
    121         int SYSTEM = 1;
    122         int SECURE = 2;
    123         int GLOBAL = 3;
    124     }
    125 
    126 
    127     private ResultPayload(Parcel in) {
    128         mIntent = in.readParcelable(ResultPayload.class.getClassLoader());
    129     }
    130 
    131     public ResultPayload(Intent intent) {
    132         mIntent = intent;
    133     }
    134 
    135     @ResultPayload.PayloadType
    136     public int getType() {
    137         return PayloadType.INTENT;
    138     }
    139 
    140     @Override
    141     public int describeContents() {
    142         return 0;
    143     }
    144 
    145     @Override
    146     public void writeToParcel(Parcel dest, int flags) {
    147         dest.writeParcelable(mIntent, flags);
    148     }
    149 
    150     public static final Creator<ResultPayload> CREATOR = new Creator<ResultPayload>() {
    151         @Override
    152         public ResultPayload createFromParcel(Parcel in) {
    153             return new ResultPayload(in);
    154         }
    155 
    156         @Override
    157         public ResultPayload[] newArray(int size) {
    158             return new ResultPayload[size];
    159         }
    160     };
    161 
    162     public Intent getIntent() {
    163         return mIntent;
    164     }
    165 }
    166