Home | History | Annotate | Download | only in cts
      1 /*
      2  * Copyright (C) 2008 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.cts;
     18 
     19 import java.util.Timer;
     20 import java.util.TimerTask;
     21 
     22 /**
     23  * Observes test progressing status.
     24  *
     25  */
     26 public class ProgressObserver {
     27     private Timer mNotifyTimer;
     28 
     29     /**
     30      * Start a process displayer.
     31      */
     32     public void start() {
     33         mNotifyTimer = new Timer();
     34         mNotifyTimer.schedule(new ProgressPrinter(),
     35                 ProgressPrinter.DELAY, ProgressPrinter.TIMEOUT);
     36     }
     37 
     38     /**
     39      * Stop a process displayer.
     40      */
     41     public void stop() {
     42         if (mNotifyTimer != null) {
     43             mNotifyTimer.cancel();
     44         }
     45         mNotifyTimer = null;
     46     }
     47 
     48     /**
     49      * Display running notification when a test/package is executing, </br>
     50      * especially for the ones running for a very long time.
     51      */
     52     class ProgressPrinter extends TimerTask {
     53         public final static int DELAY = 2000;
     54         public final static int TIMEOUT = 2000;
     55 
     56         /** {@inheritDoc} */
     57         @Override
     58         public void run() {
     59             CUIOutputStream.print(".");
     60         }
     61     }
     62 }
     63