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