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 android.content.SharedPreferences;
     20 import android.os.Parcel;
     21 import android.os.Parcelable;
     22 import android.util.Log;
     23 import android.view.View;
     24 
     25 import java.util.ArrayList;
     26 import java.util.HashSet;
     27 import java.util.Iterator;
     28 import java.util.Set;
     29 
     30 public class Timers {
     31     // Private actions processed by the receiver
     32     public static final String START_TIMER = "start_timer";
     33     public static final String DELETE_TIMER = "delete_timer";
     34     public static final String TIMES_UP = "times_up";
     35     public static final String TIMER_RESET = "timer_reset";
     36     public static final String TIMER_STOP = "timer_stop";
     37     public static final String TIMER_DONE = "timer_done";
     38     public static final String TIMER_UPDATE = "timer_update";
     39 
     40     public static final String TIMER_INTENT_EXTRA = "timer.intent.extra";
     41 
     42     public static final String NOTIF_UPDATE = "notif_update";
     43     public static final String NOTIF_TIME = "timer_notif_time";
     44     public static final String NOTIF_ID = "timer_notif_id";
     45     public static final String NOTIF_LABEL = "timer_notif_label";
     46     public static final String NOTIF_IN_USE_SHOW = "notif_in_use_show";
     47     public static final String NOTIF_IN_USE_CANCEL = "notif_in_use_cancel";
     48     public static final String NOTIF_APP_OPEN = "notif_app_open";
     49     public static final String FROM_NOTIFICATION = "from_notification";
     50     public static final String UPDATE_NOTIFICATION = "update_notification";
     51     public static final String FROM_ALERT = "from_alert";
     52 
     53     public static final String TIMESUP_MODE = "times_up";
     54 
     55     public static TimerObj findTimer(ArrayList<TimerObj> timers, int timerId) {
     56         Iterator<TimerObj> i = timers.iterator();
     57         while(i.hasNext()) {
     58             TimerObj t = i.next();
     59             if (t.mTimerId == timerId) {
     60                 return t;
     61             }
     62         }
     63         return null;
     64     }
     65     public static TimerObj findExpiredTimer(ArrayList<TimerObj> timers) {
     66         Iterator<TimerObj> i = timers.iterator();
     67         while(i.hasNext()) {
     68             TimerObj t = i.next();
     69             if (t.mState == TimerObj.STATE_TIMESUP) {
     70                 return t;
     71             }
     72         }
     73         return null;
     74     }
     75 
     76     public static ArrayList<TimerObj> timersInUse(ArrayList<TimerObj> timers) {
     77         ArrayList<TimerObj> result = (ArrayList<TimerObj>) timers.clone();
     78         Iterator<TimerObj> it = result.iterator();
     79         while(it.hasNext()) {
     80             TimerObj timer = it.next();
     81             if (!timer.isInUse()) {
     82                 it.remove();
     83             }
     84         }
     85         return result;
     86     }
     87 }
     88