Home | History | Annotate | Download | only in console
      1 /*
      2  * Copyright (C) 2007 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.ddmuilib.console;
     18 
     19 
     20 /**
     21  * Static Console used to ouput messages. By default outputs the message to System.out and
     22  * System.err, but can receive a IDdmConsole object which will actually do something.
     23  */
     24 public class DdmConsole {
     25 
     26     private static IDdmConsole mConsole;
     27 
     28     /**
     29      * Prints a message to the android console.
     30      * @param message the message to print
     31      * @param forceDisplay if true, this force the console to be displayed.
     32      */
     33     public static void printErrorToConsole(String message) {
     34         if (mConsole != null) {
     35             mConsole.printErrorToConsole(message);
     36         } else {
     37             System.err.println(message);
     38         }
     39     }
     40 
     41     /**
     42      * Prints several messages to the android console.
     43      * @param messages the messages to print
     44      * @param forceDisplay if true, this force the console to be displayed.
     45      */
     46     public static void printErrorToConsole(String[] messages) {
     47         if (mConsole != null) {
     48             mConsole.printErrorToConsole(messages);
     49         } else {
     50             for (String message : messages) {
     51                 System.err.println(message);
     52             }
     53         }
     54     }
     55 
     56     /**
     57      * Prints a message to the android console.
     58      * @param message the message to print
     59      * @param forceDisplay if true, this force the console to be displayed.
     60      */
     61     public static void printToConsole(String message) {
     62         if (mConsole != null) {
     63             mConsole.printToConsole(message);
     64         } else {
     65             System.out.println(message);
     66         }
     67     }
     68 
     69     /**
     70      * Prints several messages to the android console.
     71      * @param messages the messages to print
     72      * @param forceDisplay if true, this force the console to be displayed.
     73      */
     74     public static void printToConsole(String[] messages) {
     75         if (mConsole != null) {
     76             mConsole.printToConsole(messages);
     77         } else {
     78             for (String message : messages) {
     79                 System.out.println(message);
     80             }
     81         }
     82     }
     83 
     84     /**
     85      * Sets a IDdmConsole to override the default behavior of the console
     86      * @param console The new IDdmConsole
     87      * **/
     88     public static void setConsole(IDdmConsole console) {
     89         mConsole = console;
     90     }
     91 }
     92