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 STOP_TIMER = "stop_timer";
     29     public static final String DELETE_TIMER = "delete_timer";
     30     public static final String RESET_TIMER = "reset_timer";
     31     public static final String TIMES_UP = "times_up";
     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 UPDATE_NEXT_TIMESUP = "timer_update_next_timesup";
     38 
     39     public static final String NOTIF_IN_USE_SHOW = "notif_in_use_show";
     40     public static final String NOTIF_IN_USE_CANCEL = "notif_in_use_cancel";
     41     public static final String NOTIF_APP_OPEN = "notif_app_open";
     42     public static final String NOTIF_TIMES_UP_STOP = "notif_times_up_stop";
     43     public static final String NOTIF_TIMES_UP_PLUS_ONE = "notif_times_up_plus_one";
     44     public static final String NOTIF_TIMES_UP_SHOW = "notif_times_up_show";
     45     public static final String NOTIF_TIMES_UP_CANCEL = "notif_times_up_cancel";
     46     public static final String FIRST_LAUNCH_FROM_API_CALL = "first_launch_from_api_call";
     47     public static final String SCROLL_TO_TIMER_ID = "scroll_to_timer_id";
     48 
     49     public static final String TIMESUP_MODE = "times_up";
     50 
     51     /**
     52      * Key to a shared preference that forces Timer user interfaces to refresh in order to reflect
     53      * changes in the database.
     54      */
     55     public static final String REFRESH_UI_WITH_LATEST_DATA = "refresh_ui_with_latest_data";
     56 
     57     public static TimerObj findTimer(ArrayList<TimerObj> timers, int timerId) {
     58         for (TimerObj t : timers) {
     59             if (t.mTimerId == timerId) {
     60                 return t;
     61             }
     62         }
     63         return null;
     64     }
     65 
     66     public static TimerObj findExpiredTimer(ArrayList<TimerObj> timers) {
     67         for (TimerObj t : timers) {
     68             if (t.mState == TimerObj.STATE_TIMESUP) {
     69                 return t;
     70             }
     71         }
     72         return null;
     73     }
     74 
     75     public static ArrayList<TimerObj> timersInUse(ArrayList<TimerObj> timers) {
     76         final ArrayList<TimerObj> result = new ArrayList<>(timers);
     77         for (Iterator<TimerObj> it = result.iterator(); it.hasNext();) {
     78             if (!it.next().isInUse()) {
     79                 it.remove();
     80             }
     81         }
     82         return result;
     83     }
     84 
     85     public static ArrayList<TimerObj> timersInTimesUp(ArrayList<TimerObj> timers) {
     86         final ArrayList<TimerObj> result = new ArrayList<>(timers);
     87         for (Iterator<TimerObj> it = result.iterator(); it.hasNext();) {
     88             if (it.next().mState != TimerObj.STATE_TIMESUP) {
     89                 it.remove();
     90             }
     91         }
     92         return result;
     93     }
     94 }
     95