Home | History | Annotate | Download | only in repository
      1 /*
      2  * Copyright (C) 2011 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.sdklib.internal.repository;
     18 
     19 import com.android.sdklib.ISdkLog;
     20 import com.android.sdklib.NullSdkLog;
     21 import com.android.util.Pair;
     22 
     23 
     24 /**
     25  * A no-op implementation of the {@link ITaskMonitor} interface.
     26  * <p/>
     27  * This can be passed to methods that require a monitor when the caller doesn't
     28  * have any UI to update or means to report tracked progress.
     29  * A custom {@link ISdkLog} is used. Clients could use {@link NullSdkLog} if
     30  * they really don't care about the logging either.
     31  */
     32 public class NullTaskMonitor implements ITaskMonitor {
     33 
     34     private final ISdkLog mLog;
     35 
     36     /**
     37      * Creates a no-op {@link ITaskMonitor} that defers logging to the specified
     38      * logger.
     39      * <p/>
     40      * This can be passed to methods that require a monitor when the caller doesn't
     41      * have any UI to update or means to report tracked progress.
     42      *
     43      * @param log An {@link ISdkLog}. Must not be null. Consider using {@link NullSdkLog}.
     44      */
     45     public NullTaskMonitor(ISdkLog log) {
     46         mLog = log;
     47     }
     48 
     49     public void setDescription(String format, Object...args) {
     50         // pass
     51     }
     52 
     53     public void log(String format, Object...args) {
     54         mLog.printf(format, args);
     55     }
     56 
     57     public void logError(String format, Object...args) {
     58         mLog.error(null /*throwable*/, format, args);
     59     }
     60 
     61     public void logVerbose(String format, Object...args) {
     62         mLog.printf(format, args);
     63     }
     64 
     65     public void setProgressMax(int max) {
     66         // pass
     67     }
     68 
     69     public int getProgressMax() {
     70         return 0;
     71     }
     72 
     73     public void incProgress(int delta) {
     74         // pass
     75     }
     76 
     77     /** Always return 1. */
     78     public int getProgress() {
     79         return 1;
     80     }
     81 
     82     /** Always return false. */
     83     public boolean isCancelRequested() {
     84         return false;
     85     }
     86 
     87     public ITaskMonitor createSubMonitor(int tickCount) {
     88         return this;
     89     }
     90 
     91     /** Always return false. */
     92     public boolean displayPrompt(final String title, final String message) {
     93         return false;
     94     }
     95 
     96     /** Always return null. */
     97     public Pair<String, String> displayLoginPasswordPrompt(String title, String message) {
     98         return null;
     99     }
    100 
    101     // --- ISdkLog ---
    102 
    103     public void error(Throwable t, String errorFormat, Object... args) {
    104         mLog.error(t, errorFormat, args);
    105     }
    106 
    107     public void warning(String warningFormat, Object... args) {
    108         mLog.warning(warningFormat, args);
    109     }
    110 
    111     public void printf(String msgFormat, Object... args) {
    112         mLog.printf(msgFormat, args);
    113     }
    114 
    115 }
    116