Condition.java revision 7340fc8665ae3f9f1978f42aa0e5e1da85036158
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 17package android.service.notification; 18 19import android.net.Uri; 20import android.os.Parcel; 21import android.os.Parcelable; 22 23import java.util.Objects; 24 25/** 26 * Condition information from condition providers. 27 * 28 * @hide 29 */ 30public class Condition implements Parcelable { 31 32 public static final int FLAG_RELEVANT_NOW = 1 << 0; 33 public static final int FLAG_RELEVANT_ALWAYS = 1 << 1; 34 35 public final Uri id; 36 public String caption; 37 public boolean state; 38 public int flags; 39 40 41 public Condition(Uri id, String caption, boolean state, int flags) { 42 if (id == null) throw new IllegalArgumentException("id is required"); 43 if (caption == null) throw new IllegalArgumentException("caption is required"); 44 this.id = id; 45 this.caption = caption; 46 this.state = state; 47 this.flags = flags; 48 } 49 50 private Condition(Parcel source) { 51 id = Uri.CREATOR.createFromParcel(source); 52 caption = source.readString(); 53 state = source.readInt() == 1; 54 flags = source.readInt(); 55 } 56 57 @Override 58 public void writeToParcel(Parcel dest, int flags) { 59 dest.writeParcelable(id, 0); 60 dest.writeString(caption); 61 dest.writeInt(state ? 1 : 0); 62 dest.writeInt(flags); 63 } 64 65 @Override 66 public String toString() { 67 return new StringBuilder(Condition.class.getSimpleName()).append('[') 68 .append("id=").append(id) 69 .append(",caption=").append(caption) 70 .append(",state=").append(state) 71 .append(",flags=").append(flags) 72 .append(']').toString(); 73 } 74 75 @Override 76 public boolean equals(Object o) { 77 if (!(o instanceof Condition)) return false; 78 if (o == this) return true; 79 final Condition other = (Condition) o; 80 return Objects.equals(other.id, id) 81 && Objects.equals(other.caption, caption) 82 && other.state == state 83 && other.flags == flags; 84 } 85 86 @Override 87 public int hashCode() { 88 return Objects.hash(id, caption, state, flags); 89 } 90 91 @Override 92 public int describeContents() { 93 return 0; 94 } 95 96 public Condition copy() { 97 final Parcel parcel = Parcel.obtain(); 98 try { 99 writeToParcel(parcel, 0); 100 parcel.setDataPosition(0); 101 return new Condition(parcel); 102 } finally { 103 parcel.recycle(); 104 } 105 } 106 107 public static final Parcelable.Creator<Condition> CREATOR 108 = new Parcelable.Creator<Condition>() { 109 @Override 110 public Condition createFromParcel(Parcel source) { 111 return new Condition(source); 112 } 113 114 @Override 115 public Condition[] newArray(int size) { 116 return new Condition[size]; 117 } 118 }; 119} 120