Merge "Misc fix in layoutlib bridge + View.isIneditMode as delegate."

This commit is contained in:
Xavier Ducrohet
2010-11-11 17:43:28 -08:00
committed by Android (Google) Code Review
8 changed files with 61 additions and 39 deletions

View File

@@ -0,0 +1,31 @@
/*
* 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 android.view;
/**
* Delegate used to provide new implementation of a select few methods of {@link View}
*
* Through the layoutlib_create tool, the original methods of View have been replaced
* by calls to methods of the same name in this delegate class.
*
*/
public class View_Delegate {
/*package*/ static boolean isInEditMode(View thisView) {
return true;
}
}

View File

@@ -157,20 +157,6 @@ public final class Bridge extends LayoutBridge {
});
}
// Override View.isInEditMode to return true.
//
// This allows custom views that are drawn in the Graphical Layout Editor to adapt their
// rendering for preview. Most important this let custom views know that they can't expect
// the rest of their activities to be alive.
OverrideMethod.setMethodListener("android.view.View#isInEditMode()Z",
new MethodAdapter() {
@Override
public int onInvokeI(String signature, boolean isNative, Object caller) {
return 1;
}
}
);
// load the fonts.
FontLoader fontLoader = FontLoader.create(fontOsLocation);
if (fontLoader != null) {

View File

@@ -1111,25 +1111,20 @@ public final class BridgeContext extends Activity {
}
@SuppressWarnings("unused")
@Override
public FileInputStream openFileInput(String arg0)
throws FileNotFoundException {
// TODO Auto-generated method stub
return null;
}
@SuppressWarnings("unused")
@Override
public FileOutputStream openFileOutput(String arg0, int arg1)
throws FileNotFoundException {
public FileInputStream openFileInput(String arg0) throws FileNotFoundException {
// TODO Auto-generated method stub
return null;
}
@Override
public SQLiteDatabase openOrCreateDatabase(String arg0, int arg1,
CursorFactory arg2) {
public FileOutputStream openFileOutput(String arg0, int arg1) throws FileNotFoundException {
// TODO Auto-generated method stub
return null;
}
@Override
public SQLiteDatabase openOrCreateDatabase(String arg0, int arg1, CursorFactory arg2) {
// TODO Auto-generated method stub
return null;
}
@@ -1217,14 +1212,12 @@ public final class BridgeContext extends Activity {
}
@SuppressWarnings("unused")
@Override
public void setWallpaper(Bitmap arg0) throws IOException {
// TODO Auto-generated method stub
}
@SuppressWarnings("unused")
@Override
public void setWallpaper(InputStream arg0) throws IOException {
// TODO Auto-generated method stub

View File

@@ -43,10 +43,8 @@ import java.util.Map;
*/
public final class BridgeTypedArray extends TypedArray {
@SuppressWarnings("hiding")
private BridgeResources mResources;
private BridgeContext mContext;
@SuppressWarnings("hiding")
private IResourceValue[] mData;
private String[] mNames;
private final boolean mPlatformFile;

View File

@@ -49,7 +49,8 @@ public final class BridgeWindow implements IWindow {
// pass for now.
}
public void dispatchTrackball(MotionEvent arg0, long arg1, boolean arg2) throws RemoteException {
public void dispatchTrackball(MotionEvent arg0, long arg1, boolean arg2)
throws RemoteException {
// pass for now.
}

View File

@@ -16,14 +16,14 @@
package com.android.layoutlib.bridge.impl;
import com.android.layoutlib.api.ILayoutBridge;
import com.android.layoutlib.api.IResourceValue;
import com.android.layoutlib.api.LayoutBridge;
/**
* Basic implementation of IResourceValue for when it is needed to dynamically make a new
* {@link IResourceValue} object.
*
* Most of the time, implementations of IResourceValue come through the {@link ILayoutBridge}
* Most of the time, implementations of IResourceValue come through the {@link LayoutBridge}
* API.
*/
public class TempResourceValue implements IResourceValue {

View File

@@ -37,9 +37,9 @@ import junit.framework.TestCase;
* include the original class as first parameter (to access "this").
*
*/
public class TestNativeDelegate extends TestCase {
public class TestDelegates extends TestCase {
public void testNativeDelegates() {
public void testNativeDelegates() {
final String[] classes = CreateInfo.DELEGATE_CLASS_NATIVES;
final int count = classes.length;
@@ -48,10 +48,23 @@ public class TestNativeDelegate extends TestCase {
}
}
public void testMethodDelegates() {
final String[] methods = CreateInfo.DELEGATE_METHODS;
final int count = methods.length;
for (int i = 0 ; i < count ; i++) {
String methodName = methods[i];
// extract the class name
String className = methodName.substring(0, methodName.indexOf('#'));
loadAndCompareClasses(className, className + "_Delegate");
}
}
private void loadAndCompareClasses(String originalClassName, String delegateClassName) {
// load the classes
try {
ClassLoader classLoader = TestNativeDelegate.class.getClassLoader();
ClassLoader classLoader = TestDelegates.class.getClassLoader();
Class<?> originalClass = classLoader.loadClass(originalClassName);
Class<?> delegateClass = classLoader.loadClass(delegateClassName);

View File

@@ -95,8 +95,8 @@ public final class CreateInfo implements ICreateInfo {
*/
private final static String[] DELEGATE_METHODS = new String[] {
"android.app.Fragment#instantiate", //(Landroid/content/Context;Ljava/lang/String;Landroid/os/Bundle;)Landroid/app/Fragment;",
"android.view.View#isInEditMode",
// TODO: comment out once DelegateClass is working
// "android.view.View#isInEditMode",
// "android.content.res.Resources$Theme#obtainStyledAttributes",
};
@@ -126,7 +126,6 @@ public final class CreateInfo implements ICreateInfo {
*/
private final static String[] OVERRIDDEN_METHODS = new String[] {
// TODO: remove once DelegateClass is working
"android.view.View#isInEditMode",
"android.content.res.Resources$Theme#obtainStyledAttributes",
};
@@ -141,6 +140,7 @@ public final class CreateInfo implements ICreateInfo {
"android.os.ServiceManager", "android.os._Original_ServiceManager",
"android.view.SurfaceView", "android.view._Original_SurfaceView",
"android.view.accessibility.AccessibilityManager", "android.view.accessibility._Original_AccessibilityManager",
"android.webkit.WebView", "android.webkit._Original_WebView",
};
/**