aboutsummaryrefslogtreecommitdiffstats
path: root/sdkmanager/libs/sdkuilib
diff options
context:
space:
mode:
Diffstat (limited to 'sdkmanager/libs/sdkuilib')
-rwxr-xr-xsdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/repository/sdkman2/AdtUpdateDialog.java2
-rwxr-xr-xsdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/repository/sdkman2/LogWindow.java342
-rwxr-xr-xsdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/repository/sdkman2/SdkLogAdapter.java108
-rwxr-xr-xsdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/repository/sdkman2/SdkUpdaterWindowImpl2.java34
-rwxr-xr-xsdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/tasks/ILogUiProvider.java50
-rwxr-xr-xsdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/tasks/IProgressUiProvider.java21
-rwxr-xr-xsdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/tasks/ProgressView.java89
7 files changed, 538 insertions, 108 deletions
diff --git a/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/repository/sdkman2/AdtUpdateDialog.java b/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/repository/sdkman2/AdtUpdateDialog.java
index 362496c..8a525e3 100755
--- a/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/repository/sdkman2/AdtUpdateDialog.java
+++ b/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/repository/sdkman2/AdtUpdateDialog.java
@@ -157,7 +157,7 @@ public class AdtUpdateDialog extends SwtBaseDialog {
mStatusText,
mProgressBar,
null /*buttonStop*/,
- mUpdaterData.getSdkLog()));
+ new SdkLogAdapter(mUpdaterData.getSdkLog())));
mUpdaterData.setTaskFactory(factory);
setupSources();
diff --git a/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/repository/sdkman2/LogWindow.java b/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/repository/sdkman2/LogWindow.java
new file mode 100755
index 0000000..6c563f2
--- /dev/null
+++ b/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/repository/sdkman2/LogWindow.java
@@ -0,0 +1,342 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.sdkuilib.internal.repository.sdkman2;
+
+import com.android.sdklib.ISdkLog;
+import com.android.sdkuilib.internal.tasks.ILogUiProvider;
+import com.android.sdkuilib.ui.GridDataBuilder;
+import com.android.sdkuilib.ui.GridLayoutBuilder;
+
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.custom.StyleRange;
+import org.eclipse.swt.custom.StyledText;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.events.ShellAdapter;
+import org.eclipse.swt.events.ShellEvent;
+import org.eclipse.swt.graphics.Point;
+import org.eclipse.swt.graphics.Rectangle;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.swt.widgets.Widget;
+
+
+/**
+ * A floating log window that can be displayed or hidden by the main SDK Manager 2 window.
+ * It displays a log of the sdk manager operation (listing, install, delete) including
+ * any errors (e.g. network error or install/delete errors.)
+ */
+class LogWindow implements ILogUiProvider {
+
+ private Shell mParentShell;
+ private Shell mShell;
+ private Composite mRootComposite;
+ private StyledText mStyledText;
+ private Label mLogDescription;
+ private Button mCloseButton;
+
+ private final ISdkLog mSecondaryLog;
+ private boolean mCloseRequested;
+ private boolean mInitPosition = true;
+ private String mLastLogMsg = null;
+
+ private enum TextStyle {
+ DEFAULT,
+ TITLE,
+ ERROR
+ }
+
+ /**
+ * Create the dialog.
+ * @param parentShell Parent container
+ * @param secondaryLog An optional logger where messages will <em>also</em> be output.
+ */
+ public LogWindow(Shell parentShell, ISdkLog secondaryLog) {
+ mParentShell = parentShell;
+ mSecondaryLog = secondaryLog;
+ }
+
+ /**
+ * For testing only. See {@link #open()} and {@link #close()} for normal usage.
+ * @wbp.parser.entryPoint
+ */
+ void openBlocking() {
+ open();
+ Display display = Display.getDefault();
+ while (!mShell.isDisposed()) {
+ if (!display.readAndDispatch()) {
+ display.sleep();
+ }
+ }
+ close();
+ }
+
+ /**
+ * Opens the window. Does not block. Caller should use close() later.
+ */
+ public void open() {
+ createShell();
+ createContents();
+ mShell.open();
+ mShell.layout();
+ mShell.setVisible(false);
+ }
+
+ public void close() {
+ if (mShell != null && !mShell.isDisposed()) {
+ mCloseRequested = true;
+ mShell.close();
+ mShell = null;
+ }
+ }
+
+ public boolean isVisible() {
+ return mShell != null && !mShell.isDisposed() && mShell.isVisible();
+ }
+
+ public void setVisible(boolean visible) {
+ if (mShell != null && !mShell.isDisposed()) {
+ mShell.setVisible(visible);
+ if (visible && mInitPosition) {
+ mInitPosition = false;
+ positionWindow();
+ }
+ }
+ }
+
+ private void createShell() {
+ mShell = new Shell(mParentShell, SWT.SHELL_TRIM | SWT.TOOL);
+ mShell.setMinimumSize(new Point(600, 300));
+ mShell.setSize(450, 300);
+ mShell.setText("Log Window");
+ GridLayoutBuilder.create(mShell);
+
+ mShell.addShellListener(new ShellAdapter() {
+ @Override
+ public void shellClosed(ShellEvent e) {
+ if (!mCloseRequested) {
+ e.doit = false;
+ setVisible(false);
+ }
+ }
+ });
+ }
+
+ /**
+ * Create contents of the dialog.
+ */
+ private void createContents() {
+ mRootComposite = new Composite(mShell, SWT.NONE);
+ GridLayoutBuilder.create(mRootComposite).columns(2);
+ GridDataBuilder.create(mRootComposite).fill().grab();
+
+ mStyledText = new StyledText(mRootComposite,
+ SWT.BORDER | SWT.MULTI | SWT.READ_ONLY | SWT.WRAP | SWT.V_SCROLL);
+ GridDataBuilder.create(mStyledText).hSpan(2).fill().grab();
+
+ mLogDescription = new Label(mRootComposite, SWT.NONE);
+ GridDataBuilder.create(mLogDescription).hFill().hGrab();
+
+ mCloseButton = new Button(mRootComposite, SWT.NONE);
+ mCloseButton.setText("Close");
+ mCloseButton.setToolTipText("Closes the log window");
+ mCloseButton.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ setVisible(false); //$hide$
+ }
+ });
+ }
+
+ // --- Implementation of ILogUiProvider ---
+
+
+ /**
+ * Sets the description in the current task dialog.
+ * This method can be invoked from a non-UI thread.
+ */
+ public void setDescription(final String description) {
+ syncExec(mLogDescription, new Runnable() {
+ public void run() {
+ mLogDescription.setText(description);
+
+ if (acceptLog(description, true /*isDescription*/)) {
+ appendLine(TextStyle.TITLE, description);
+
+ if (mSecondaryLog != null) {
+ mSecondaryLog.printf("%1$s", description);
+ }
+ }
+ }
+ });
+ }
+
+ /**
+ * Logs a "normal" information line.
+ * This method can be invoked from a non-UI thread.
+ */
+ public void log(final String log) {
+ if (acceptLog(log, false /*isDescription*/)) {
+ syncExec(mLogDescription, new Runnable() {
+ public void run() {
+ appendLine(TextStyle.DEFAULT, log);
+ }
+ });
+
+ if (mSecondaryLog != null) {
+ mSecondaryLog.printf(" %1$s", log);
+ }
+ }
+ }
+
+ /**
+ * Logs an "error" information line.
+ * This method can be invoked from a non-UI thread.
+ */
+ public void logError(final String log) {
+ if (acceptLog(log, false /*isDescription*/)) {
+ syncExec(mLogDescription, new Runnable() {
+ public void run() {
+ appendLine(TextStyle.ERROR, log);
+
+ // Error also make the log window rise
+ setVisible(true);
+ }
+ });
+
+ if (mSecondaryLog != null) {
+ mSecondaryLog.printf("ERROR: %1$s", log);
+ }
+ }
+ }
+
+ /**
+ * Logs a "verbose" information line, that is extra details which are typically
+ * not that useful for the end-user and might be hidden until explicitly shown.
+ * This method can be invoked from a non-UI thread.
+ */
+ public void logVerbose(final String log) {
+ if (acceptLog(log, false /*isDescription*/)) {
+ syncExec(mLogDescription, new Runnable() {
+ public void run() {
+ appendLine(TextStyle.DEFAULT, " " + log);
+ }
+ });
+
+ if (mSecondaryLog != null) {
+ mSecondaryLog.printf(" %1$s", log);
+ }
+ }
+ }
+
+
+ // ----
+
+
+ /**
+ * Centers the dialog in its parent shell.
+ */
+ private void positionWindow() {
+ // Centers the dialog in its parent shell
+ Shell child = mShell;
+ if (child != null && mParentShell != null) {
+ // get the parent client area with a location relative to the display
+ Rectangle parentArea = mParentShell.getClientArea();
+ Point parentLoc = mParentShell.getLocation();
+ int px = parentLoc.x;
+ int py = parentLoc.y;
+ int pw = parentArea.width;
+ int ph = parentArea.height;
+
+ Point childSize = child.getSize();
+ int cw = Math.max(childSize.x, pw);
+ int ch = childSize.y;
+
+ int x = 30 + px + (pw - cw) / 2;
+ if (x < 0) x = 0;
+
+ int y = py + (ph - ch) / 2;
+ if (y < py) y = py;
+
+ child.setLocation(x, y);
+ child.setSize(cw, ch);
+ }
+ }
+
+ private void appendLine(TextStyle style, String text) {
+ if (!text.endsWith("\n")) {
+ text += '\n';
+ }
+
+ if (style == TextStyle.DEFAULT) {
+ mStyledText.append(text);
+
+ } else {
+ String s = mStyledText.getText();
+ int start = (s == null ? 0 : s.length());
+ mStyledText.append(text);
+
+ StyleRange sr = new StyleRange();
+ sr.start = start;
+ sr.length = text.length();
+ sr.fontStyle = SWT.BOLD;
+ if (style == TextStyle.ERROR) {
+ sr.foreground = mStyledText.getDisplay().getSystemColor(SWT.COLOR_DARK_RED);
+ }
+ sr.underline = false;
+ mStyledText.setStyleRange(sr);
+ }
+ }
+
+
+ private void syncExec(final Widget widget, final Runnable runnable) {
+ if (widget != null && !widget.isDisposed()) {
+ widget.getDisplay().syncExec(runnable);
+ }
+ }
+
+ /**
+ * Filter messages displayed in the log: <br/>
+ * - Messages with a % are typical part of a progress update and shouldn't be in the log. <br/>
+ * - Messages that are the same as the same output message should be output a second time.
+ *
+ * @param msg The potential log line to print.
+ * @return True if the log line should be printed, false otherwise.
+ */
+ private boolean acceptLog(String msg, boolean isDescription) {
+ if (msg == null) {
+ return false;
+ }
+
+ msg = msg.trim();
+
+ // Descriptions also have the download progress status (0..100%) which we want to avoid
+ if (isDescription && msg.indexOf('%') != -1) {
+ return false;
+ }
+
+ if (msg.equals(mLastLogMsg)) {
+ return false;
+ }
+
+ mLastLogMsg = msg;
+ return true;
+ }
+}
diff --git a/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/repository/sdkman2/SdkLogAdapter.java b/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/repository/sdkman2/SdkLogAdapter.java
new file mode 100755
index 0000000..aa0b6a5
--- /dev/null
+++ b/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/repository/sdkman2/SdkLogAdapter.java
@@ -0,0 +1,108 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.sdkuilib.internal.repository.sdkman2;
+
+import com.android.sdklib.ISdkLog;
+import com.android.sdkuilib.internal.tasks.ILogUiProvider;
+
+
+/**
+ * Adapter that transform log from an {@link ILogUiProvider} to an {@link ISdkLog}.
+ */
+public final class SdkLogAdapter implements ILogUiProvider {
+
+ private ISdkLog mSdkLog;
+ private String mLastLogMsg;
+
+ /**
+ * Creates a new adapter to output log on the given {@code sdkLog}.
+ *
+ * @param sdkLog The logger to output to. Must not be null.
+ */
+ public SdkLogAdapter(ISdkLog sdkLog) {
+ mSdkLog = sdkLog;
+ }
+
+ /**
+ * Sets the description in the current task dialog.
+ * This method can be invoked from a non-UI thread.
+ */
+ public void setDescription(final String description) {
+ if (acceptLog(description)) {
+ mSdkLog.printf("%1$s", description);
+ }
+ }
+
+ /**
+ * Logs a "normal" information line.
+ * This method can be invoked from a non-UI thread.
+ */
+ public void log(String log) {
+ if (acceptLog(log)) {
+ mSdkLog.printf(" %1$s", log);
+ }
+ }
+
+ /**
+ * Logs an "error" information line.
+ * This method can be invoked from a non-UI thread.
+ */
+ public void logError(String log) {
+ if (acceptLog(log)) {
+ mSdkLog.error(null, " %1$s", log);
+ }
+ }
+
+ /**
+ * Logs a "verbose" information line, that is extra details which are typically
+ * not that useful for the end-user and might be hidden until explicitly shown.
+ * This method can be invoked from a non-UI thread.
+ */
+ public void logVerbose(String log) {
+ if (acceptLog(log)) {
+ mSdkLog.printf(" %1$s", log);
+ }
+ }
+
+ // ----
+
+ /**
+ * Filter messages displayed in the log: <br/>
+ * - Messages with a % are typical part of a progress update and shouldn't be in the log. <br/>
+ * - Messages that are the same as the same output message should be output a second time.
+ *
+ * @param msg The potential log line to print.
+ * @return True if the log line should be printed, false otherwise.
+ */
+ private boolean acceptLog(String msg) {
+ if (msg == null) {
+ return false;
+ }
+
+ msg = msg.trim();
+ if (msg.indexOf('%') != -1) {
+ return false;
+ }
+
+ if (msg.equals(mLastLogMsg)) {
+ return false;
+ }
+
+ mLastLogMsg = msg;
+ return true;
+ }
+}
diff --git a/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/repository/sdkman2/SdkUpdaterWindowImpl2.java b/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/repository/sdkman2/SdkUpdaterWindowImpl2.java
index d2472cb..d6a78f8 100755
--- a/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/repository/sdkman2/SdkUpdaterWindowImpl2.java
+++ b/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/repository/sdkman2/SdkUpdaterWindowImpl2.java
@@ -89,8 +89,9 @@ public class SdkUpdaterWindowImpl2 implements ISdkUpdaterWindow {
private ProgressBar mProgressBar;
private Label mStatusText;
private ImgDisabledButton mButtonStop;
- private ToggleButton mButtonDetails;
+ private ToggleButton mButtonShowLog;
private SettingsController mSettingsController;
+ private LogWindow mLogWindow;
/**
* Creates a new window. Caller must call open(), which will block.
@@ -144,6 +145,7 @@ public class SdkUpdaterWindowImpl2 implements ISdkUpdaterWindow {
preCreateContent();
createContents();
createMenuBar();
+ createLogWindow();
mShell.open();
mShell.layout();
@@ -207,12 +209,12 @@ public class SdkUpdaterWindowImpl2 implements ISdkUpdaterWindow {
}
});
- mButtonDetails = new ToggleButton(composite2, SWT.NONE,
+ mButtonShowLog = new ToggleButton(composite2, SWT.NONE,
getImage("collapsed_16.png"), //$NON-NLS-1$
getImage("expanded_16.png")); //$NON-NLS-1$
- mButtonDetails.addListener(SWT.Selection, new Listener() {
+ mButtonShowLog.addListener(SWT.Selection, new Listener() {
public void handleEvent(Event event) {
- onToggleDetails();
+ onToggleLogWindow();
}
});
}
@@ -348,6 +350,19 @@ public class SdkUpdaterWindowImpl2 implements ISdkUpdaterWindow {
return null;
}
+ /**
+ * Creates the log window.
+ * <p/>
+ * If this is invoked from an IDE, we also define a secondary logger so that all
+ * messages flow to the IDE log. This may or may not be what we want in the end
+ * (e.g. a middle ground would be to repeat error, and ignore normal/verbose)
+ */
+ private void createLogWindow() {
+ mLogWindow = new LogWindow(mShell,
+ mContext == SdkInvocationContext.IDE ? mUpdaterData.getSdkLog() : null);
+ mLogWindow.open();
+ }
+
// -- Start of internal part ----------
// Hide everything down-below from SWT designer
@@ -425,7 +440,7 @@ public class SdkUpdaterWindowImpl2 implements ISdkUpdaterWindow {
/**
* Once the UI has been created, initializes the content.
- * This creates the pages, selects the first one, setup sources and scan for local folders.
+ * This creates the pages, selects the first one, setups sources and scans for local folders.
*
* Returns true if we should show the window.
*/
@@ -433,7 +448,7 @@ public class SdkUpdaterWindowImpl2 implements ISdkUpdaterWindow {
ProgressViewFactory factory = new ProgressViewFactory();
factory.setProgressView(new ProgressView(
mStatusText, mProgressBar, mButtonStop,
- mContext == SdkInvocationContext.IDE ? mUpdaterData.getSdkLog() : null));
+ mLogWindow));
mUpdaterData.setTaskFactory(factory);
setWindowImage(mShell);
@@ -482,6 +497,7 @@ public class SdkUpdaterWindowImpl2 implements ISdkUpdaterWindow {
* Called by the main loop when the window has been disposed.
*/
private void dispose() {
+ mLogWindow.close();
mUpdaterData.getSources().saveUserAddons(mUpdaterData.getSdkLog());
}
@@ -516,8 +532,10 @@ public class SdkUpdaterWindowImpl2 implements ISdkUpdaterWindow {
mSettingsController.applySettings();
}
- private void onToggleDetails() {
- mButtonDetails.setState(1 - mButtonDetails.getState());
+ private void onToggleLogWindow() {
+ // toggle visibility
+ mLogWindow.setVisible(!mLogWindow.isVisible());
+ mButtonShowLog.setState(mLogWindow.isVisible() ? 1 : 0);
}
private void onStopSelected() {
diff --git a/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/tasks/ILogUiProvider.java b/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/tasks/ILogUiProvider.java
new file mode 100755
index 0000000..8f77b7a
--- /dev/null
+++ b/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/tasks/ILogUiProvider.java
@@ -0,0 +1,50 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.sdkuilib.internal.tasks;
+
+
+/**
+ * Interface for a user interface that displays the log from a task monitor.
+ */
+public interface ILogUiProvider {
+
+ /**
+ * Sets the description in the current task dialog.
+ * This method can be invoked from a non-UI thread.
+ */
+ public abstract void setDescription(String description);
+
+ /**
+ * Logs a "normal" information line.
+ * This method can be invoked from a non-UI thread.
+ */
+ public abstract void log(String log);
+
+ /**
+ * Logs an "error" information line.
+ * This method can be invoked from a non-UI thread.
+ */
+ public abstract void logError(String log);
+
+ /**
+ * Logs a "verbose" information line, that is extra details which are typically
+ * not that useful for the end-user and might be hidden until explicitly shown.
+ * This method can be invoked from a non-UI thread.
+ */
+ public abstract void logVerbose(String log);
+
+}
diff --git a/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/tasks/IProgressUiProvider.java b/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/tasks/IProgressUiProvider.java
index f6e13c6..1eca704 100755
--- a/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/tasks/IProgressUiProvider.java
+++ b/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/tasks/IProgressUiProvider.java
@@ -29,7 +29,7 @@ import org.eclipse.swt.widgets.ProgressBar;
* See {@link ITaskMonitor} for details on how a monitor expects to
* be displayed.
*/
-interface IProgressUiProvider {
+interface IProgressUiProvider extends ILogUiProvider {
public abstract boolean isCancelRequested();
@@ -40,25 +40,6 @@ interface IProgressUiProvider {
public abstract void setDescription(String description);
/**
- * Logs a "normal" information line.
- * This method can be invoked from a non-UI thread.
- */
- public abstract void log(String log);
-
- /**
- * Logs an "error" information line.
- * This method can be invoked from a non-UI thread.
- */
- public abstract void logError(String log);
-
- /**
- * Logs a "verbose" information line, that is extra details which are typically
- * not that useful for the end-user and might be hidden until explicitly shown.
- * This method can be invoked from a non-UI thread.
- */
- public abstract void logVerbose(String log);
-
- /**
* Sets the max value of the progress bar.
* This method can be invoked from a non-UI thread.
*
diff --git a/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/tasks/ProgressView.java b/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/tasks/ProgressView.java
index 9485885..3bc755f 100755
--- a/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/tasks/ProgressView.java
+++ b/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/tasks/ProgressView.java
@@ -16,7 +16,6 @@
package com.android.sdkuilib.internal.tasks;
-import com.android.sdklib.ISdkLog;
import com.android.sdklib.internal.repository.ITask;
import com.android.sdklib.internal.repository.ITaskMonitor;
import com.android.sdkuilib.ui.AuthenticationDialog;
@@ -59,17 +58,8 @@ public final class ProgressView implements IProgressUiProvider {
private final Control mStopButton;
private final ProgressBar mProgressBar;
- /**
- * Accumulated log text. This is intended to be displayed in a scrollable
- * text area. The various methods that append to the log might not be called
- * from the UI thread, so accesses should be synchronized on the builder.
- */
- private final StringBuilder mLogText = new StringBuilder();
-
- /** Logger object. Can be null. */
- private final ISdkLog mLog;
-
- private String mLastLogMsg = null;
+ /** Logger object. Cannot not be null. */
+ private final ILogUiProvider mLog;
/**
* Creates a new {@link ProgressView} object, a simple "holder" for the various
@@ -80,14 +70,14 @@ public final class ProgressView implements IProgressUiProvider {
* @param progressBar The progress bar to update during a task. Must not be null.
* @param stopButton The stop button. It will be disabled when there's no task that can
* be interrupted. A selection listener will be attached to it. Optional. Can be null.
- * @param log An <em>optional</em> logger object that will be used to report all the log.
- * If null, all logging will be collected here with a little UI to display it.
+ * @param log A <em>mandatory</em> logger object that will be used to report all the log.
+ * Must not be null.
*/
public ProgressView(
Label label,
ProgressBar progressBar,
Control stopButton,
- ISdkLog log) {
+ ILogUiProvider log) {
mLabel = label;
mProgressBar = progressBar;
mLog = log;
@@ -217,15 +207,7 @@ public final class ProgressView implements IProgressUiProvider {
}
});
- if (acceptLog(description)) {
- if (mLog != null) {
- mLog.printf("%1$s", description);
- } else {
- synchronized (mLogText) {
- mLogText.append(description);
- }
- }
- }
+ mLog.setDescription(description);
}
/**
@@ -233,15 +215,7 @@ public final class ProgressView implements IProgressUiProvider {
* This method can be invoked from a non-UI thread.
*/
public void log(String log) {
- if (acceptLog(log)) {
- if (mLog != null) {
- mLog.printf(" %1$s", log);
- } else {
- synchronized (mLogText) {
- mLogText.append(" ").append(log);
- }
- }
- }
+ mLog.log(log);
}
/**
@@ -249,15 +223,7 @@ public final class ProgressView implements IProgressUiProvider {
* This method can be invoked from a non-UI thread.
*/
public void logError(String log) {
- if (acceptLog(log)) {
- if (mLog != null) {
- mLog.error(null, " %1$s", log);
- } else {
- synchronized (mLogText) {
- mLogText.append("ERROR: ").append(log);
- }
- }
- }
+ mLog.logError(log);
}
/**
@@ -266,15 +232,7 @@ public final class ProgressView implements IProgressUiProvider {
* This method can be invoked from a non-UI thread.
*/
public void logVerbose(String log) {
- if (acceptLog(log)) {
- if (mLog != null) {
- mLog.printf(" %1$s", log);
- } else {
- synchronized (mLogText) {
- mLogText.append(" ").append(log);
- }
- }
- }
+ mLog.logVerbose(log);
}
/**
@@ -335,7 +293,7 @@ public final class ProgressView implements IProgressUiProvider {
});
return result[0];
- }
+ }
/**
* This method opens a pop-up window which requests for User Login and
@@ -374,31 +332,4 @@ public final class ProgressView implements IProgressUiProvider {
return resultArray[0] == null ? null : Pair.of(resultArray[0], resultArray[1]);
}
- // ----
-
- /**
- * Filter messages displayed in the log: <br/>
- * - Messages with a % are typical part of a progress update and shouldn't be in the log. <br/>
- * - Messages that are the same as the same output message should be output a second time.
- *
- * @param msg The potential log line to print.
- * @return True if the log line should be printed, false otherwise.
- */
- private boolean acceptLog(String msg) {
- if (msg == null) {
- return false;
- }
-
- msg = msg.trim();
- if (msg.indexOf('%') != -1) {
- return false;
- }
-
- if (msg.equals(mLastLogMsg)) {
- return false;
- }
-
- mLastLogMsg = msg;
- return true;
- }
}