• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2009 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 
20 /**
21  * A monitor interface for a {@link ITask}.
22  * <p/>
23  * Depending on the task factory that created the task, there might not be any UI
24  * or it might not implement all the methods, in which case calling them would be
25  * a no-op but is guaranteed not to crash.
26  * <p/>
27  * If the task runs in a non-UI worker thread, the task factory implementation
28  * will take care of the update the UI in the correct thread. The task itself
29  * must not have to deal with it.
30  */
31 public interface ITaskMonitor {
32 
33     /**
34      * Sets the description in the current task dialog.
35      * This method can be invoked from a non-UI thread.
36      */
setDescription(String descriptionFormat, Object...args)37     public void setDescription(String descriptionFormat, Object...args);
38 
39     /**
40      * Sets the result text in the current task dialog.
41      * This method can be invoked from a non-UI thread.
42      */
setResult(String resultFormat, Object...args)43     public void setResult(String resultFormat, Object...args);
44 
45     /**
46      * Sets the max value of the progress bar.
47      * This method can be invoked from a non-UI thread.
48      *
49      * This method MUST be invoked once before using {@link #incProgress(int)} or
50      * {@link #getProgress()} or {@link #createSubMonitor(int)}. Callers are
51      * discouraged from using more than once -- implementations can either discard
52      * the next calls or behave incoherently.
53      */
setProgressMax(int max)54     public void setProgressMax(int max);
55 
56     /**
57      * Increments the current value of the progress bar.
58      * This method can be invoked from a non-UI thread.
59      *
60      * Callers MUST use setProgressMax before using this method.
61      */
incProgress(int delta)62     public void incProgress(int delta);
63 
64     /**
65      * Returns the current value of the progress bar,
66      * between 0 and up to {@link #setProgressMax(int)} - 1.
67      *
68      * Callers MUST use setProgressMax before using this method.
69      */
getProgress()70     public int getProgress();
71 
72     /**
73      * Returns true if the user requested to cancel the operation.
74      * It is up to the task thread to pool this and exit as soon
75      * as possible.
76      */
isCancelRequested()77     public boolean isCancelRequested();
78 
79     /**
80      * Creates a sub-monitor that will use up to tickCount on the progress bar.
81      * tickCount must be 1 or more.
82      */
createSubMonitor(int tickCount)83     public ITaskMonitor createSubMonitor(int tickCount);
84 
85     /**
86      * Display a yes/no question dialog box.
87      *
88      * Implementations MUST allow this to be called from any thread, e.g. by
89      * making sure the dialog is opened synchronously in the ui thread.
90      *
91      * @param title The title of the dialog box
92      * @param message The error message
93      * @return true if YES was clicked.
94      */
displayPrompt(final String title, final String message)95     public boolean displayPrompt(final String title, final String message);
96 
97 }
98