LayoutLib: Add debug mode.
Change-Id: If4263c7dba63a063f84e0c6988c270eb6d291ac3
This commit is contained in:
@@ -54,7 +54,7 @@ public final class Bitmap_Delegate {
|
||||
|
||||
// ---- delegate manager ----
|
||||
private static final DelegateManager<Bitmap_Delegate> sManager =
|
||||
new DelegateManager<Bitmap_Delegate>();
|
||||
new DelegateManager<Bitmap_Delegate>(Bitmap_Delegate.class);
|
||||
|
||||
// ---- delegate helper data ----
|
||||
|
||||
|
||||
@@ -54,7 +54,7 @@ public final class Canvas_Delegate {
|
||||
|
||||
// ---- delegate manager ----
|
||||
private static final DelegateManager<Canvas_Delegate> sManager =
|
||||
new DelegateManager<Canvas_Delegate>();
|
||||
new DelegateManager<Canvas_Delegate>(Canvas_Delegate.class);
|
||||
|
||||
// ---- delegate helper data ----
|
||||
|
||||
|
||||
@@ -38,7 +38,7 @@ public abstract class ColorFilter_Delegate {
|
||||
|
||||
// ---- delegate manager ----
|
||||
protected static final DelegateManager<ColorFilter_Delegate> sManager =
|
||||
new DelegateManager<ColorFilter_Delegate>();
|
||||
new DelegateManager<ColorFilter_Delegate>(ColorFilter_Delegate.class);
|
||||
|
||||
// ---- delegate helper data ----
|
||||
|
||||
|
||||
@@ -38,7 +38,7 @@ public abstract class DrawFilter_Delegate {
|
||||
|
||||
// ---- delegate manager ----
|
||||
protected static final DelegateManager<DrawFilter_Delegate> sManager =
|
||||
new DelegateManager<DrawFilter_Delegate>();
|
||||
new DelegateManager<DrawFilter_Delegate>(DrawFilter_Delegate.class);
|
||||
|
||||
// ---- delegate helper data ----
|
||||
|
||||
|
||||
@@ -38,7 +38,7 @@ public abstract class MaskFilter_Delegate {
|
||||
|
||||
// ---- delegate manager ----
|
||||
protected static final DelegateManager<MaskFilter_Delegate> sManager =
|
||||
new DelegateManager<MaskFilter_Delegate>();
|
||||
new DelegateManager<MaskFilter_Delegate>(MaskFilter_Delegate.class);
|
||||
|
||||
// ---- delegate helper data ----
|
||||
|
||||
|
||||
@@ -46,7 +46,7 @@ public final class Matrix_Delegate {
|
||||
|
||||
// ---- delegate manager ----
|
||||
private static final DelegateManager<Matrix_Delegate> sManager =
|
||||
new DelegateManager<Matrix_Delegate>();
|
||||
new DelegateManager<Matrix_Delegate>(Matrix_Delegate.class);
|
||||
|
||||
// ---- delegate data ----
|
||||
private float mValues[] = new float[MATRIX_SIZE];
|
||||
|
||||
@@ -62,7 +62,7 @@ public class Paint_Delegate {
|
||||
|
||||
// ---- delegate manager ----
|
||||
private static final DelegateManager<Paint_Delegate> sManager =
|
||||
new DelegateManager<Paint_Delegate>();
|
||||
new DelegateManager<Paint_Delegate>(Paint_Delegate.class);
|
||||
|
||||
// ---- delegate helper data ----
|
||||
private List<FontInfo> mFonts;
|
||||
|
||||
@@ -40,7 +40,7 @@ public abstract class PathEffect_Delegate {
|
||||
|
||||
// ---- delegate manager ----
|
||||
protected static final DelegateManager<PathEffect_Delegate> sManager =
|
||||
new DelegateManager<PathEffect_Delegate>();
|
||||
new DelegateManager<PathEffect_Delegate>(PathEffect_Delegate.class);
|
||||
|
||||
// ---- delegate helper data ----
|
||||
|
||||
|
||||
@@ -50,7 +50,7 @@ public final class Path_Delegate {
|
||||
|
||||
// ---- delegate manager ----
|
||||
private static final DelegateManager<Path_Delegate> sManager =
|
||||
new DelegateManager<Path_Delegate>();
|
||||
new DelegateManager<Path_Delegate>(Path_Delegate.class);
|
||||
|
||||
// ---- delegate data ----
|
||||
private FillType mFillType = FillType.WINDING;
|
||||
|
||||
@@ -38,7 +38,7 @@ public abstract class Rasterizer_Delegate {
|
||||
|
||||
// ---- delegate manager ----
|
||||
protected static final DelegateManager<Rasterizer_Delegate> sManager =
|
||||
new DelegateManager<Rasterizer_Delegate>();
|
||||
new DelegateManager<Rasterizer_Delegate>(Rasterizer_Delegate.class);
|
||||
|
||||
// ---- delegate helper data ----
|
||||
|
||||
|
||||
@@ -48,7 +48,7 @@ public class Region_Delegate {
|
||||
|
||||
// ---- delegate manager ----
|
||||
protected static final DelegateManager<Region_Delegate> sManager =
|
||||
new DelegateManager<Region_Delegate>();
|
||||
new DelegateManager<Region_Delegate>(Region_Delegate.class);
|
||||
|
||||
// ---- delegate helper data ----
|
||||
|
||||
|
||||
@@ -40,7 +40,7 @@ public abstract class Shader_Delegate {
|
||||
|
||||
// ---- delegate manager ----
|
||||
protected static final DelegateManager<Shader_Delegate> sManager =
|
||||
new DelegateManager<Shader_Delegate>();
|
||||
new DelegateManager<Shader_Delegate>(Shader_Delegate.class);
|
||||
|
||||
// ---- delegate helper data ----
|
||||
|
||||
|
||||
@@ -46,7 +46,7 @@ public final class Typeface_Delegate {
|
||||
|
||||
// ---- delegate manager ----
|
||||
private static final DelegateManager<Typeface_Delegate> sManager =
|
||||
new DelegateManager<Typeface_Delegate>();
|
||||
new DelegateManager<Typeface_Delegate>(Typeface_Delegate.class);
|
||||
|
||||
// ---- delegate helper data ----
|
||||
private static final String DEFAULT_FAMILY = "sans-serif";
|
||||
|
||||
@@ -40,7 +40,7 @@ public abstract class Xfermode_Delegate {
|
||||
|
||||
// ---- delegate manager ----
|
||||
protected static final DelegateManager<Xfermode_Delegate> sManager =
|
||||
new DelegateManager<Xfermode_Delegate>();
|
||||
new DelegateManager<Xfermode_Delegate>(Xfermode_Delegate.class);
|
||||
|
||||
// ---- delegate helper data ----
|
||||
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
package com.android.layoutlib.bridge.impl;
|
||||
|
||||
import com.android.layoutlib.bridge.util.Debug;
|
||||
import com.android.layoutlib.bridge.util.SparseWeakArray;
|
||||
|
||||
import android.util.SparseArray;
|
||||
@@ -69,6 +70,7 @@ import java.util.List;
|
||||
* @param <T> the delegate class to manage
|
||||
*/
|
||||
public final class DelegateManager<T> {
|
||||
private final Class<T> mClass;
|
||||
private final SparseWeakArray<T> mDelegates = new SparseWeakArray<T>();
|
||||
/** list used to store delegates when their main object holds a reference to them.
|
||||
* This is to ensure that the WeakReference in the SparseWeakArray doesn't get GC'ed
|
||||
@@ -78,6 +80,10 @@ public final class DelegateManager<T> {
|
||||
private final List<T> mJavaReferences = new ArrayList<T>();
|
||||
private int mDelegateCounter = 0;
|
||||
|
||||
public DelegateManager(Class<T> theClass) {
|
||||
mClass = theClass;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the delegate from the given native int.
|
||||
* <p>
|
||||
@@ -91,6 +97,14 @@ public final class DelegateManager<T> {
|
||||
public T getDelegate(int native_object) {
|
||||
if (native_object > 0) {
|
||||
T delegate = mDelegates.get(native_object);
|
||||
|
||||
if (Debug.DEBUG) {
|
||||
if (delegate == null) {
|
||||
System.out.println("Unknown " + mClass.getSimpleName() + " with int " +
|
||||
native_object);
|
||||
}
|
||||
}
|
||||
|
||||
assert delegate != null;
|
||||
return delegate;
|
||||
}
|
||||
@@ -107,6 +121,11 @@ public final class DelegateManager<T> {
|
||||
mDelegates.put(native_object, newDelegate);
|
||||
assert !mJavaReferences.contains(newDelegate);
|
||||
mJavaReferences.add(newDelegate);
|
||||
|
||||
if (Debug.DEBUG) {
|
||||
System.out.println("New " + mClass.getSimpleName() + " with int " + native_object);
|
||||
}
|
||||
|
||||
return native_object;
|
||||
}
|
||||
|
||||
@@ -116,6 +135,12 @@ public final class DelegateManager<T> {
|
||||
*/
|
||||
public void removeJavaReferenceFor(int native_object) {
|
||||
T delegate = getDelegate(native_object);
|
||||
|
||||
if (Debug.DEBUG) {
|
||||
System.out.println("Removing main Java ref on " + mClass.getSimpleName() +
|
||||
" with int " + native_object);
|
||||
}
|
||||
|
||||
mJavaReferences.remove(delegate);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
/*
|
||||
* 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.layoutlib.bridge.util;
|
||||
|
||||
public class Debug {
|
||||
|
||||
public final static boolean DEBUG = false;
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user