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