1/* 2 * Copyright (C) 2013 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 com.android.server.twilight; 18 19import java.text.DateFormat; 20import java.util.Date; 21 22/** 23 * Describes whether it is day or night. 24 * This object is immutable. 25 */ 26public class TwilightState { 27 private final boolean mIsNight; 28 private final float mAmount; 29 30 TwilightState(boolean isNight, float amount) { 31 mIsNight = isNight; 32 mAmount = amount; 33 } 34 35 /** 36 * Returns true if it is currently night time. 37 */ 38 public boolean isNight() { 39 return mIsNight; 40 } 41 42 /** 43 * For twilight affects that change gradually over time, this is the amount they 44 * should currently be in effect. 45 */ 46 public float getAmount() { 47 return mAmount; 48 } 49 50 @Override 51 public boolean equals(Object o) { 52 return o instanceof TwilightState && equals((TwilightState)o); 53 } 54 55 public boolean equals(TwilightState other) { 56 return other != null 57 && mIsNight == other.mIsNight 58 && mAmount == other.mAmount; 59 } 60 61 @Override 62 public int hashCode() { 63 return 0; // don't care 64 } 65 66 @Override 67 public String toString() { 68 DateFormat f = DateFormat.getDateTimeInstance(); 69 return "{TwilightState: isNight=" + mIsNight 70 + ", mAmount=" + mAmount 71 + "}"; 72 } 73} 74