Home | History | Annotate | Download | only in notification
      1 /*
      2  * Copyright (C) 2016 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 package android.service.notification;
     17 
     18 import android.annotation.SystemApi;
     19 import android.annotation.TestApi;
     20 import android.os.Parcel;
     21 import android.os.Parcelable;
     22 
     23 /**
     24  * Represents an option to be shown to users for snoozing a notification until a given context
     25  * instead of for a fixed amount of time.
     26  * @hide
     27  */
     28 @SystemApi
     29 @TestApi
     30 public final class SnoozeCriterion implements Parcelable {
     31     private final String mId;
     32     private final CharSequence mExplanation;
     33     private final CharSequence mConfirmation;
     34 
     35     public SnoozeCriterion(String id, CharSequence explanation, CharSequence confirmation) {
     36         mId = id;
     37         mExplanation = explanation;
     38         mConfirmation = confirmation;
     39     }
     40 
     41     protected SnoozeCriterion(Parcel in) {
     42         if (in.readByte() != 0) {
     43             mId = in.readString();
     44         } else {
     45             mId = null;
     46         }
     47         if (in.readByte() != 0) {
     48             mExplanation = in.readCharSequence();
     49         } else {
     50             mExplanation = null;
     51         }
     52         if (in.readByte() != 0) {
     53             mConfirmation = in.readCharSequence();
     54         } else {
     55             mConfirmation = null;
     56         }
     57     }
     58 
     59     /**
     60      * Returns the id of this criterion.
     61      */
     62     public String getId() {
     63         return mId;
     64     }
     65 
     66     /**
     67      * Returns the user visible explanation of how long a notification will be snoozed if
     68      * this criterion is chosen.
     69      */
     70     public CharSequence getExplanation() {
     71         return mExplanation;
     72     }
     73 
     74     /**
     75      * Returns the user visible confirmation message shown when this criterion is chosen.
     76      */
     77     public CharSequence getConfirmation() {
     78         return mConfirmation;
     79     }
     80 
     81     public static final Creator<SnoozeCriterion> CREATOR = new Creator<SnoozeCriterion>() {
     82         @Override
     83         public SnoozeCriterion createFromParcel(Parcel in) {
     84             return new SnoozeCriterion(in);
     85         }
     86 
     87         @Override
     88         public SnoozeCriterion[] newArray(int size) {
     89             return new SnoozeCriterion[size];
     90         }
     91     };
     92 
     93     @Override
     94     public int describeContents() {
     95         return 0;
     96     }
     97 
     98     @Override
     99     public void writeToParcel(Parcel dest, int flags) {
    100         if (mId != null) {
    101             dest.writeByte((byte) 1);
    102             dest.writeString(mId);
    103         } else {
    104             dest.writeByte((byte) 0);
    105         }
    106         if (mExplanation != null) {
    107             dest.writeByte((byte) 1);
    108             dest.writeCharSequence(mExplanation);
    109         } else {
    110             dest.writeByte((byte) 0);
    111         }
    112         if (mConfirmation != null) {
    113             dest.writeByte((byte) 1);
    114             dest.writeCharSequence(mConfirmation);
    115         } else {
    116             dest.writeByte((byte) 0);
    117         }
    118     }
    119 
    120     @Override
    121     public boolean equals(Object o) {
    122         if (this == o) return true;
    123         if (o == null || getClass() != o.getClass()) return false;
    124 
    125         SnoozeCriterion that = (SnoozeCriterion) o;
    126 
    127         if (mId != null ? !mId.equals(that.mId) : that.mId != null) return false;
    128         if (mExplanation != null ? !mExplanation.equals(that.mExplanation)
    129                 : that.mExplanation != null) {
    130             return false;
    131         }
    132         return mConfirmation != null ? mConfirmation.equals(that.mConfirmation)
    133                 : that.mConfirmation == null;
    134 
    135     }
    136 
    137     @Override
    138     public int hashCode() {
    139         int result = mId != null ? mId.hashCode() : 0;
    140         result = 31 * result + (mExplanation != null ? mExplanation.hashCode() : 0);
    141         result = 31 * result + (mConfirmation != null ? mConfirmation.hashCode() : 0);
    142         return result;
    143     }
    144 }
    145