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.view.ViewGroup;
     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         mTimerText.showTime(true);
     77         mCircleView.setVisibility(VISIBLE);
     78     }
     79 
     80     public void stop() {
     81         mCircleView.stopIntervalAnimation();
     82         mTimerText.redTimeStr(false, true);
     83         mTimerText.showTime(true);
     84         mCircleView.setVisibility(VISIBLE);
     85     }
     86 
     87     public void timesUp() {
     88         mCircleView.abortIntervalAnimation();
     89         mTimerText.redTimeStr(true, true);
     90     }
     91 
     92     public void done() {
     93         mCircleView.stopIntervalAnimation();
     94         mCircleView.setVisibility(VISIBLE);
     95         mCircleView.invalidate();
     96         mTimerText.redTimeStr(true, false);
     97     }
     98 
     99     public void setLength(long timerLength) {
    100         mTimerLength = timerLength;
    101         mCircleView.setIntervalTime(mTimerLength);
    102         mCircleView.invalidate();
    103     }
    104 
    105     public void setTextBlink(boolean blink) {
    106         mTimerText.showTime(!blink);
    107     }
    108 
    109     public void setCircleBlink(boolean blink) {
    110         mCircleView.setVisibility(blink ? INVISIBLE : VISIBLE);
    111     }
    112 
    113     public void setTime(long time, boolean forceUpdate) {
    114         if (mTimerText == null) {
    115             mTimerText = (CountingTimerView)findViewById(R.id.timer_time_text);
    116         }
    117         mTimerText.setTime(time, false, forceUpdate);
    118     }
    119 
    120     // Used by animator to animate the size of a timer
    121     @SuppressWarnings("unused")
    122     public void setAnimatedHeight(int height) {
    123         ViewGroup.LayoutParams layoutParams = getLayoutParams();
    124         if (layoutParams != null) {
    125             layoutParams.height = height;
    126             requestLayout();
    127         }
    128     }
    129 
    130 }
    131