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.Context;
     20 import android.util.AttributeSet;
     21 import android.view.LayoutInflater;
     22 import android.widget.ImageButton;
     23 import android.widget.LinearLayout;
     24 
     25 import com.android.deskclock.CircleTimerView;
     26 import com.android.deskclock.R;
     27 
     28 
     29 public class TimerListItem extends LinearLayout {
     30 
     31     CountingTimerView mTimerText;
     32     CircleTimerView mCircleView;
     33 
     34     long mTimerLength;
     35 
     36     public TimerListItem(Context context) {
     37         this(context, null);
     38     }
     39 
     40     public TimerListItem(Context context, AttributeSet attrs) {
     41         super(context, attrs);
     42         LayoutInflater layoutInflater =
     43                 (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
     44         layoutInflater.inflate(R.layout.timer_list_item, this);
     45     }
     46 
     47     @Override
     48     protected void onFinishInflate() {
     49         super.onFinishInflate();
     50         mTimerText = (CountingTimerView)findViewById(R.id.timer_time_text);
     51         mCircleView = (CircleTimerView)findViewById(R.id.timer_time);
     52         mCircleView.setTimerMode(true);
     53     }
     54 
     55     public void set(long timerLength, long timeLeft, boolean drawRed) {
     56         if (mCircleView == null) {
     57             mCircleView = (CircleTimerView)findViewById(R.id.timer_time);
     58             mCircleView.setTimerMode(true);
     59         }
     60         mTimerLength = timerLength;
     61         mCircleView.setIntervalTime(mTimerLength);
     62         mCircleView.setPassedTime(timerLength - timeLeft, drawRed);
     63         invalidate();
     64     }
     65 
     66     public void start() {
     67         mCircleView.startIntervalAnimation();
     68         mTimerText.redTimeStr(false, true);
     69         mTimerText.showTime(true);
     70         mCircleView.setVisibility(VISIBLE);
     71     }
     72 
     73     public void pause() {
     74         mCircleView.pauseIntervalAnimation();
     75         mTimerText.redTimeStr(false, true);
     76     }
     77 
     78     public void stop() {
     79         mCircleView.stopIntervalAnimation();
     80         mTimerText.redTimeStr(false, true);
     81         mTimerText.showTime(true);
     82         mCircleView.setVisibility(VISIBLE);
     83     }
     84 
     85     public void timesUp() {
     86         mCircleView.abortIntervalAnimation();
     87         mTimerText.redTimeStr(true, true);
     88     }
     89 
     90     public void done() {
     91         mCircleView.stopIntervalAnimation();
     92         mCircleView.setVisibility(VISIBLE);
     93         mCircleView.invalidate();
     94         mTimerText.redTimeStr(true, false);
     95     }
     96 
     97     public void setLength(long timerLength) {
     98         mTimerLength = timerLength;
     99         mCircleView.setIntervalTime(mTimerLength);
    100         mCircleView.invalidate();
    101     }
    102 
    103     public void setTextBlink(boolean blink) {
    104         mTimerText.showTime(!blink);
    105     }
    106 
    107     public void setCircleBlink(boolean blink) {
    108         mCircleView.setVisibility(blink ? INVISIBLE : VISIBLE);
    109     }
    110 
    111     public void setTime(long time, boolean forceUpdate) {
    112         if (mTimerText == null) {
    113             mTimerText = (CountingTimerView)findViewById(R.id.timer_time_text);
    114         }
    115         mTimerText.setTime(time, false, forceUpdate);
    116     }
    117 
    118     // Used by animator to animate the size of a timer
    119     @SuppressWarnings("unused")
    120     public void setAnimatedHeight(int height) {
    121         getLayoutParams().height = height;
    122         requestLayout();
    123     }
    124 
    125 
    126 
    127 }
    128