1 /*
2  * Copyright (C) 2012 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.deskclock.timer;
18 
19 import java.util.ArrayList;
20 import java.util.Iterator;
21 
22 public class Timers {
23     // Logging shared by TimerReceiver and TimerAlertFullScreen
24     public static final boolean LOGGING = true;
25 
26     // Private actions processed by the receiver
27     public static final String START_TIMER = "start_timer";
28     public static final String DELETE_TIMER = "delete_timer";
29     public static final String TIMES_UP = "times_up";
30     public static final String TIMER_RESET = "timer_reset";
31     public static final String TIMER_STOP = "timer_stop";
32     public static final String TIMER_DONE = "timer_done";
33     public static final String TIMER_UPDATE = "timer_update";
34 
35     public static final String TIMER_INTENT_EXTRA = "timer.intent.extra";
36 
37     public static final String NOTIF_IN_USE_SHOW = "notif_in_use_show";
38     public static final String NOTIF_IN_USE_CANCEL = "notif_in_use_cancel";
39     public static final String NOTIF_APP_OPEN = "notif_app_open";
40     public static final String FROM_NOTIFICATION = "from_notification";
41     public static final String NOTIF_TIMES_UP_STOP = "notif_times_up_stop";
42     public static final String NOTIF_TIMES_UP_PLUS_ONE = "notif_times_up_plus_one";
43     public static final String NOTIF_TIMES_UP_SHOW = "notif_times_up_show";
44     public static final String NOTIF_TIMES_UP_CANCEL = "notif_times_up_cancel";
45     public static final String FROM_ALERT = "from_alert";
46     public static final String FIRST_LAUNCH_FROM_API_CALL = "first_launch_from_api_call";
47 
48     public static final String TIMESUP_MODE = "times_up";
49 
findTimer(ArrayList<TimerObj> timers, int timerId)50     public static TimerObj findTimer(ArrayList<TimerObj> timers, int timerId) {
51         Iterator<TimerObj> i = timers.iterator();
52         while(i.hasNext()) {
53             TimerObj t = i.next();
54             if (t.mTimerId == timerId) {
55                 return t;
56             }
57         }
58         return null;
59     }
findExpiredTimer(ArrayList<TimerObj> timers)60     public static TimerObj findExpiredTimer(ArrayList<TimerObj> timers) {
61         Iterator<TimerObj> i = timers.iterator();
62         while(i.hasNext()) {
63             TimerObj t = i.next();
64             if (t.mState == TimerObj.STATE_TIMESUP) {
65                 return t;
66             }
67         }
68         return null;
69     }
70 
timersInUse(ArrayList<TimerObj> timers)71     public static ArrayList<TimerObj> timersInUse(ArrayList<TimerObj> timers) {
72         ArrayList<TimerObj> result = (ArrayList<TimerObj>) timers.clone();
73         Iterator<TimerObj> it = result.iterator();
74         while(it.hasNext()) {
75             TimerObj timer = it.next();
76             if (!timer.isInUse()) {
77                 it.remove();
78             }
79         }
80         return result;
81     }
82 
timersInTimesUp(ArrayList<TimerObj> timers)83     public static ArrayList<TimerObj> timersInTimesUp(ArrayList<TimerObj> timers) {
84         ArrayList<TimerObj> result = (ArrayList<TimerObj>) timers.clone();
85         Iterator<TimerObj> it = result.iterator();
86         while(it.hasNext()) {
87             TimerObj timer = it.next();
88             if (timer.mState != TimerObj.STATE_TIMESUP) {
89                 it.remove();
90             }
91         }
92         return result;
93     }
94 }
95