Home | History | Annotate | Download | only in timer
      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 
     47     public static final String TIMESUP_MODE = "times_up";
     48 
     49     public static TimerObj findTimer(ArrayList<TimerObj> timers, int timerId) {
     50         Iterator<TimerObj> i = timers.iterator();
     51         while(i.hasNext()) {
     52             TimerObj t = i.next();
     53             if (t.mTimerId == timerId) {
     54                 return t;
     55             }
     56         }
     57         return null;
     58     }
     59     public static TimerObj findExpiredTimer(ArrayList<TimerObj> timers) {
     60         Iterator<TimerObj> i = timers.iterator();
     61         while(i.hasNext()) {
     62             TimerObj t = i.next();
     63             if (t.mState == TimerObj.STATE_TIMESUP) {
     64                 return t;
     65             }
     66         }
     67         return null;
     68     }
     69 
     70     public static ArrayList<TimerObj> timersInUse(ArrayList<TimerObj> timers) {
     71         ArrayList<TimerObj> result = (ArrayList<TimerObj>) timers.clone();
     72         Iterator<TimerObj> it = result.iterator();
     73         while(it.hasNext()) {
     74             TimerObj timer = it.next();
     75             if (!timer.isInUse()) {
     76                 it.remove();
     77             }
     78         }
     79         return result;
     80     }
     81 
     82     public static ArrayList<TimerObj> timersInTimesUp(ArrayList<TimerObj> timers) {
     83         ArrayList<TimerObj> result = (ArrayList<TimerObj>) timers.clone();
     84         Iterator<TimerObj> it = result.iterator();
     85         while(it.hasNext()) {
     86             TimerObj timer = it.next();
     87             if (timer.mState != TimerObj.STATE_TIMESUP) {
     88                 it.remove();
     89             }
     90         }
     91         return result;
     92     }
     93 }
     94