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 17 package com.android.tv.settings.util.bluetooth; 18 19 import android.os.Parcel; 20 import android.os.Parcelable; 21 22 public class LedConfiguration implements Parcelable { 23 24 public static final Parcelable.Creator<LedConfiguration> CREATOR = 25 new Parcelable.Creator<LedConfiguration>() { 26 27 @Override 28 public LedConfiguration createFromParcel(Parcel source) { 29 int color0 = source.readInt(); 30 int color1 = source.readInt(); 31 boolean[] bools = new boolean[2]; 32 source.readBooleanArray(bools); 33 LedConfiguration config = new LedConfiguration(color0, color1, bools[0]); 34 config.isTransient = bools[1]; 35 return config; 36 } 37 38 @Override 39 public LedConfiguration[] newArray(int size) { 40 return new LedConfiguration[size]; 41 } 42 }; 43 44 public int color0; 45 public int color1; 46 public boolean pulse; 47 public boolean isTransient; 48 49 public LedConfiguration(int color0, int color1, boolean pulse) { 50 this.color0 = color0; 51 this.color1 = color1; 52 this.pulse = pulse; 53 } 54 55 public LedConfiguration(LedConfiguration that) { 56 this.color0 = that.color0; 57 this.color1 = that.color1; 58 this.pulse = that.pulse; 59 } 60 61 @Override 62 public boolean equals(Object o) { 63 if (!(o instanceof LedConfiguration)) { 64 return false; 65 } 66 final LedConfiguration that = (LedConfiguration)o; 67 return areColorsEqual(that) 68 && this.pulse == that.pulse 69 && this.isTransient == that.isTransient; 70 } 71 72 public boolean areColorsEqual(LedConfiguration that) { 73 if (that == null) { 74 return false; 75 } 76 return (this.color0 == that.color0 && this.color1 == that.color1) 77 || (this.color0 == that.color1 && this.color1 == that.color0); 78 } 79 80 @Override 81 public String toString() { 82 return String.format("LedConfiguration(" + getNameString() + ")"); 83 } 84 85 public String getNameString() { 86 return String.format("#%06x-#%06x%s%s", color0 & 0x00ffffff, color1 & 0x00ffffff, 87 this.pulse ? "p" : "", this.isTransient ? "t" : ""); 88 } 89 90 @Override 91 public int describeContents() { 92 return 0; 93 } 94 95 @Override 96 public void writeToParcel(Parcel parcel, int flags) { 97 parcel.writeInt(color0); 98 parcel.writeInt(color1); 99 parcel.writeBooleanArray(new boolean[] {pulse, isTransient}); 100 } 101 } 102