blob: dec053b83948bc8757f5c9c0f45b5ea91ee4d674 [file] [log] [blame]
Adam Lesinski182f73f2013-12-05 16:48:06 -08001/*
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 {
Justin Klaassen63848782016-07-12 13:36:45 -070027
Adam Lesinski182f73f2013-12-05 16:48:06 -080028 private final boolean mIsNight;
Jason Monk5dbd4aa2016-02-07 13:13:39 -050029 private final float mAmount;
Adam Lesinski182f73f2013-12-05 16:48:06 -080030
Jason Monk5dbd4aa2016-02-07 13:13:39 -050031 TwilightState(boolean isNight, float amount) {
Adam Lesinski182f73f2013-12-05 16:48:06 -080032 mIsNight = isNight;
Jason Monk5dbd4aa2016-02-07 13:13:39 -050033 mAmount = amount;
Adam Lesinski182f73f2013-12-05 16:48:06 -080034 }
35
36 /**
37 * Returns true if it is currently night time.
38 */
39 public boolean isNight() {
40 return mIsNight;
41 }
42
43 /**
Jason Monk5dbd4aa2016-02-07 13:13:39 -050044 * For twilight affects that change gradually over time, this is the amount they
45 * should currently be in effect.
Adam Lesinski182f73f2013-12-05 16:48:06 -080046 */
Jason Monk5dbd4aa2016-02-07 13:13:39 -050047 public float getAmount() {
48 return mAmount;
Adam Lesinski182f73f2013-12-05 16:48:06 -080049 }
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 Monk5dbd4aa2016-02-07 13:13:39 -050059 && mAmount == other.mAmount;
Adam Lesinski182f73f2013-12-05 16:48:06 -080060 }
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 Monk5dbd4aa2016-02-07 13:13:39 -050071 + ", mAmount=" + mAmount
Adam Lesinski182f73f2013-12-05 16:48:06 -080072 + "}";
73 }
74}