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