summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDeepanshu Gupta <deepanshu@google.com>2015-05-21 11:47:36 -0700
committerDeepanshu Gupta <deepanshu@google.com>2015-08-25 12:06:44 -0700
commitc96ef95285e935034377dee30f3b8a0329f6c3a2 (patch)
tree9eb0186011d6d2459a931d5ecf5f88efb53397dd
parentb318ff54fcd17e7aadd1b0251c34cba348898704 (diff)
downloadframeworks_base-c96ef95285e935034377dee30f3b8a0329f6c3a2.zip
frameworks_base-c96ef95285e935034377dee30f3b8a0329f6c3a2.tar.gz
frameworks_base-c96ef95285e935034377dee30f3b8a0329f6c3a2.tar.bz2
Add documentation about hack in commit: f8ea750455 [DO NOT MERGE]
Change-Id: I9ce871a67fb67e02e0c4df1eb5c3261ea52a914b (cherry picked from commit 6330971ed293a2777bbdab09288f90ea4b2d0255)
-rw-r--r--tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeContext.java14
1 files changed, 14 insertions, 0 deletions
diff --git a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeContext.java b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeContext.java
index 6ef0b79..6b54cb6 100644
--- a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeContext.java
+++ b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeContext.java
@@ -464,6 +464,20 @@ public final class BridgeContext extends Context {
@Override
public ClassLoader getClassLoader() {
+ // The documentation for this method states that it should return a class loader one can
+ // use to retrieve classes in this package. However, when called by LayoutInflater, we do
+ // not want the class loader to return app's custom views.
+ // This is so that the IDE can instantiate the custom views and also generate proper error
+ // messages in case of failure. This also enables the IDE to fallback to MockView in case
+ // there's an exception thrown when trying to inflate the custom view.
+ // To work around this issue, LayoutInflater is modified via LayoutLib Create tool to
+ // replace invocations of this method to a new method: getFrameworkClassLoader(). Also,
+ // the method is injected into Context. The implementation of getFrameworkClassLoader() is:
+ // "return getClass().getClassLoader();". This means that when LayoutInflater asks for
+ // the context ClassLoader, it gets only LayoutLib's ClassLoader which doesn't have
+ // access to the apps's custom views.
+ // This method can now return the right ClassLoader, which CustomViews can use to do the
+ // right thing.
if (mClassLoader == null) {
mClassLoader = new ClassLoader(getClass().getClassLoader()) {
@Override