import com.android.ide.eclipse.adt.internal.sdk.Sdk;
import com.android.ide.eclipse.adt.internal.sdk.Sdk.ITargetChangeListener;
import com.android.ide.eclipse.adt.io.IFileWrapper;
-import com.android.layoutlib.api.ILayoutLog;
import com.android.layoutlib.api.IResourceValue;
import com.android.layoutlib.api.IXmlPullParser;
import com.android.layoutlib.api.LayoutBridge;
+import com.android.layoutlib.api.LayoutLog;
import com.android.layoutlib.api.LayoutScene;
import com.android.layoutlib.api.SceneParams;
import com.android.layoutlib.api.SceneParams.RenderingMode;
private Map<String, Map<String, IResourceValue>> mConfiguredFrameworkRes;
private Map<String, Map<String, IResourceValue>> mConfiguredProjectRes;
private ProjectCallback mProjectCallback;
- private ILayoutLog mLogger;
+ private LayoutLog mLog;
private boolean mNeedsRecompute = false;
// no root view yet indicates success and then update the canvas with it.
mCanvasViewer.getCanvas().setResult(
- new BasicLayoutScene(SceneStatus.SUCCESS.getResult(),
+ new BasicLayoutScene(SceneStatus.SUCCESS.createResult(),
null /*rootViewInfo*/, null /*image*/),
null /*explodeNodes*/);
return;
}
// Lazily create the logger the first time we need it
- if (mLogger == null) {
- mLogger = new ILayoutLog() {
- public void error(String message) {
+ if (mLog == null) {
+ mLog = new LayoutLog() {
+ @Override
+ public void error(String tag, String message) {
AdtPlugin.printErrorToConsole(mEditedFile.getName(), message);
}
- public void error(Throwable error) {
- String message = error.getMessage();
+ @Override
+ public void error(String tag, Throwable throwable) {
+ String message = throwable.getMessage();
if (message == null) {
- message = error.getClass().getName();
+ message = throwable.getClass().getName();
}
PrintStream ps = new PrintStream(AdtPlugin.getErrorStream());
- error.printStackTrace(ps);
+ throwable.printStackTrace(ps);
}
- public void warning(String message) {
+ @Override
+ public void error(String tag, String message, Throwable throwable) {
+ AdtPlugin.printErrorToConsole(mEditedFile.getName(), message);
+
+ PrintStream ps = new PrintStream(AdtPlugin.getErrorStream());
+ throwable.printStackTrace(ps);
+ }
+
+ @Override
+ public void warning(String tag, String message) {
AdtPlugin.printToConsole(mEditedFile.getName(), message);
}
};
density, xdpi, ydpi,
theme, isProjectTheme,
configuredProjectRes, frameworkResources, mProjectCallback,
- mLogger);
+ mLog);
if (transparentBackground) {
// It doesn't matter what the background color is as long as the alpha
package com.android.ide.common.layoutlib;
import com.android.layoutlib.api.ILayoutBridge;
+import com.android.layoutlib.api.ILayoutLog;
import com.android.layoutlib.api.ILayoutResult;
import com.android.layoutlib.api.LayoutBridge;
+import com.android.layoutlib.api.LayoutLog;
import com.android.layoutlib.api.LayoutScene;
import com.android.layoutlib.api.SceneParams;
import com.android.layoutlib.api.SceneResult;
public LayoutScene createScene(SceneParams params) {
int apiLevel = mBridge.getApiLevel();
+ // create a log wrapper since the older api requires a ILayoutLog
+ final LayoutLog log = params.getLog();
+ ILayoutLog logWrapper = new ILayoutLog() {
+
+ public void warning(String message) {
+ log.warning(null, message);
+ }
+
+ public void error(Throwable t) {
+ log.error(null, t);
+ }
+
+ public void error(String message) {
+ log.error(null, message);
+ }
+ };
+
ILayoutResult result = null;
if (apiLevel == 4) {
params.getDensity(), params.getXdpi(), params.getYdpi(),
params.getThemeName(), params.getIsProjectTheme(),
params.getProjectResources(), params.getFrameworkResources(),
- params.getProjectCallback(), params.getLogger());
+ params.getProjectCallback(), logWrapper);
} else if (apiLevel == 3) {
// api 3 add density support.
result = mBridge.computeLayout(
params.getDensity(), params.getXdpi(), params.getYdpi(),
params.getThemeName(), params.getIsProjectTheme(),
params.getProjectResources(), params.getFrameworkResources(),
- params.getProjectCallback(), params.getLogger());
+ params.getProjectCallback(), logWrapper);
} else if (apiLevel == 2) {
// api 2 added boolean for separation of project/framework theme
result = mBridge.computeLayout(
params.getScreenWidth(), params.getScreenHeight(),
params.getThemeName(), params.getIsProjectTheme(),
params.getProjectResources(), params.getFrameworkResources(),
- params.getProjectCallback(), params.getLogger());
+ params.getProjectCallback(), logWrapper);
} else {
// First api with no density/dpi, and project theme boolean mixed
// into the theme name.
params.getScreenWidth(), params.getScreenHeight(),
themeName,
params.getProjectResources(), params.getFrameworkResources(),
- params.getProjectCallback(), params.getLogger());
+ params.getProjectCallback(), logWrapper);
}
// clean up that is not done by the ILayoutBridge itself
ViewInfo rootViewInfo;
if (result.getSuccess() == ILayoutResult.SUCCESS) {
- sceneResult = SceneStatus.SUCCESS.getResult();
+ sceneResult = SceneStatus.SUCCESS.createResult();
rootViewInfo = convertToViewInfo(result.getRootView());
} else {
- sceneResult = SceneStatus.ERROR_UNKNOWN.getResult(result.getErrorMessage());
+ sceneResult = SceneStatus.ERROR_UNKNOWN.createResult(result.getErrorMessage());
rootViewInfo = null;
}
/**
* Callback interface to display warnings/errors that happened during the computation and
- * rendering of the layout.
+ * rendering of the layout.
+ * @deprecated use {@link LayoutLog}.
*/
+@Deprecated
public interface ILayoutLog {
-
+
/**
- * Displays a warning message.
- * @param message the message to display.
+ * Logs a warning message.
+ * @param message the message to log.
*/
void warning(String message);
-
+
/**
- * Displays an error message.
- * @param message the message to display.
+ * Logs an error message.
+ * @param message the message to log.
*/
void error(String message);
-
+
/**
- * Displays an exception
- * @param t the {@link Throwable} to display.
+ * Logs an exception
+ * @param t the {@link Throwable} to log.
*/
void error(Throwable t);
}
--- /dev/null
+/*
+ * Copyright (C) 2010 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.layoutlib.api;
+
+public class LayoutLog {
+
+ public void error(String tag, String message) {
+ }
+
+ public void error(String tag, Throwable t) {
+ }
+
+ public void warning(String tag, String message) {
+ }
+
+ /**
+ * Logs an error message and a {@link Throwable}.
+ * @param message the message to log.
+ * @param throwable the {@link Throwable} to log.
+ */
+ public void error(String tag, String message, Throwable throwable) {
+
+ }
+}
* Returns the last operation result.
*/
public SceneResult getResult() {
- return NOT_IMPLEMENTED.getResult();
+ return NOT_IMPLEMENTED.createResult();
}
/**
* @return a {@link SceneResult} indicating the status of the action.
*/
public SceneResult render(long timeout) {
- return NOT_IMPLEMENTED.getResult();
+ return NOT_IMPLEMENTED.createResult();
}
/**
* @return a {@link SceneResult} indicating the status of the action.
*/
public SceneResult setProperty(Object objectView, String propertyName, String propertyValue) {
- return NOT_IMPLEMENTED.getResult();
+ return NOT_IMPLEMENTED.createResult();
}
/**
*/
public SceneResult insertChild(Object parentView, IXmlPullParser childXml, int index,
IAnimationListener listener) {
- return NOT_IMPLEMENTED.getResult();
+ return NOT_IMPLEMENTED.createResult();
}
/**
*/
public SceneResult moveChild(Object parentView, Object childView, int index,
Map<String, String> layoutParams, IAnimationListener listener) {
- return NOT_IMPLEMENTED.getResult();
+ return NOT_IMPLEMENTED.createResult();
}
/**
* @return a {@link SceneResult} indicating the status of the action.
*/
public SceneResult removeChild(Object childView, IAnimationListener listener) {
- return NOT_IMPLEMENTED.getResult();
+ return NOT_IMPLEMENTED.createResult();
}
/**
*/
public SceneResult animate(Object targetObject, String animationName,
boolean isFrameworkAnimation, IAnimationListener listener) {
- return NOT_IMPLEMENTED.getResult();
+ return NOT_IMPLEMENTED.createResult();
}
/**
private Map<String, Map<String, IResourceValue>> mProjectResources;
private Map<String, Map<String, IResourceValue>> mFrameworkResources;
private IProjectCallback mProjectCallback;
- private ILayoutLog mLogger;
+ private LayoutLog mLog;
private boolean mCustomBackgroundEnabled;
private int mCustomBackgroundColor;
* value is the resource value.
* @param projectCallback The {@link IProjectCallback} object to get information from
* the project.
- * @param logger the object responsible for displaying warning/errors to the user.
+ * @param log the object responsible for displaying warning/errors to the user.
*/
public SceneParams(IXmlPullParser layoutDescription,
Object projectKey,
String themeName, boolean isProjectTheme,
Map<String, Map<String, IResourceValue>> projectResources,
Map<String, Map<String, IResourceValue>> frameworkResources,
- IProjectCallback projectCallback, ILayoutLog logger) {
+ IProjectCallback projectCallback, LayoutLog log) {
mLayoutDescription = layoutDescription;
mProjectKey = projectKey;
mScreenWidth = screenWidth;
mProjectResources = projectResources;
mFrameworkResources = frameworkResources;
mProjectCallback = projectCallback;
- mLogger = logger;
+ mLog = log;
mCustomBackgroundEnabled = false;
mTimeout = DEFAULT_TIMEOUT;
}
mProjectResources = params.mProjectResources;
mFrameworkResources = params.mFrameworkResources;
mProjectCallback = params.mProjectCallback;
- mLogger = params.mLogger;
+ mLog = params.mLog;
mCustomBackgroundEnabled = params.mCustomBackgroundEnabled;
mCustomBackgroundColor = params.mCustomBackgroundColor;
mTimeout = params.mTimeout;
return mProjectCallback;
}
- public ILayoutLog getLogger() {
- return mLogger;
+ public LayoutLog getLog() {
+ return mLog;
}
public boolean isCustomBackgroundEnabled() {
* Returns a {@link SceneResult} object with this status.
* @return an instance of SceneResult;
*/
- public SceneResult getResult() {
+ public SceneResult createResult() {
// don't want to get generic error that way.
assert this != ERROR_UNKNOWN;
*
* @see SceneResult#getData()
*/
- public SceneResult getResult(Object data) {
- SceneResult res = getResult();
+ public SceneResult createResult(Object data) {
+ SceneResult res = createResult();
if (data != null) {
res = res.getCopyWithData(data);
* @param throwable the throwable
* @return an instance of SceneResult.
*/
- public SceneResult getResult(String errorMessage, Throwable throwable) {
+ public SceneResult createResult(String errorMessage, Throwable throwable) {
return new SceneResult(this, errorMessage, throwable);
}
* @param errorMessage the error message
* @return an instance of SceneResult.
*/
- public SceneResult getResult(String errorMessage) {
+ public SceneResult createResult(String errorMessage) {
return new SceneResult(this, errorMessage, null /*throwable*/);
}
}