use of com.android.layoutlib.bridge.android.BridgeContext in project android_frameworks_base by AOSPA.
the class RenderSessionImpl method insertChild.
/**
* Insert a new child into an existing parent.
* <p>
* {@link #acquire(long)} must have been called before this.
*
* @throws IllegalStateException if the current context is different than the one owned by
* the scene, or if {@link #acquire(long)} was not called.
*
* @see RenderSession#insertChild(Object, ILayoutPullParser, int, IAnimationListener)
*/
public Result insertChild(final ViewGroup parentView, ILayoutPullParser childXml, final int index, IAnimationListener listener) {
checkLock();
BridgeContext context = getContext();
// create a block parser for the XML
BridgeXmlBlockParser blockParser = new BridgeXmlBlockParser(childXml, context, false);
// inflate the child without adding it to the root since we want to control where it'll
// get added. We do pass the parentView however to ensure that the layoutParams will
// be created correctly.
final View child = mInflater.inflate(blockParser, parentView, false);
blockParser.ensurePopped();
invalidateRenderingSize();
if (listener != null) {
new AnimationThread(this, "insertChild", listener) {
@Override
public Result preAnimation() {
parentView.setLayoutTransition(new LayoutTransition());
return addView(parentView, child, index);
}
@Override
public void postAnimation() {
parentView.setLayoutTransition(null);
}
}.start();
// always return success since the real status will come through the listener.
return SUCCESS.createResult(child);
}
// add it to the parentView in the correct location
Result result = addView(parentView, child, index);
if (!result.isSuccess()) {
return result;
}
result = render(false);
if (result.isSuccess()) {
result = result.getCopyWithData(child);
}
return result;
}
use of com.android.layoutlib.bridge.android.BridgeContext in project android_frameworks_base by AOSPA.
the class RenderSessionImpl method getViewKey.
/* (non-Javadoc)
* The cookie for menu items are stored in menu item and not in the map from View stored in
* BridgeContext.
*/
@Nullable
private Object getViewKey(View view) {
BridgeContext context = getContext();
if (!(view instanceof MenuView.ItemView)) {
return context.getViewKey(view);
}
MenuItemImpl menuItem;
if (view instanceof ActionMenuItemView) {
menuItem = ((ActionMenuItemView) view).getItemData();
} else if (view instanceof ListMenuItemView) {
menuItem = ((ListMenuItemView) view).getItemData();
} else if (view instanceof IconMenuItemView) {
menuItem = ((IconMenuItemView) view).getItemData();
} else {
menuItem = null;
}
if (menuItem instanceof BridgeMenuItemImpl) {
return ((BridgeMenuItemImpl) menuItem).getViewCookie();
}
return null;
}
use of com.android.layoutlib.bridge.android.BridgeContext in project android_frameworks_base by AOSPA.
the class HandlerThread_Delegate method run.
// -------- Delegate methods
@LayoutlibDelegate
static /*package*/
void run(HandlerThread theThread) {
// record the thread so that it can be quit() on clean up.
BridgeContext context = RenderAction.getCurrentContext();
List<HandlerThread> list = sThreads.get(context);
if (list == null) {
list = new ArrayList<HandlerThread>();
sThreads.put(context, list);
}
list.add(theThread);
// ---- START DEFAULT IMPLEMENTATION.
theThread.mTid = Process.myTid();
Looper.prepare();
synchronized (theThread) {
theThread.mLooper = Looper.myLooper();
theThread.notifyAll();
}
Process.setThreadPriority(theThread.mPriority);
theThread.onLooperPrepared();
Looper.loop();
theThread.mTid = -1;
}
use of com.android.layoutlib.bridge.android.BridgeContext in project android_frameworks_base by AOSPA.
the class Main method testGetResourceNameVariants.
@Test
public void testGetResourceNameVariants() throws Exception {
// Setup
SessionParams params = createSessionParams("", ConfigGenerator.NEXUS_4);
AssetManager assetManager = AssetManager.getSystem();
DisplayMetrics metrics = new DisplayMetrics();
Configuration configuration = RenderAction.getConfiguration(params);
Resources resources = new Resources(assetManager, metrics, configuration);
resources.mLayoutlibCallback = params.getLayoutlibCallback();
resources.mContext = new BridgeContext(params.getProjectKey(), metrics, params.getResources(), params.getAssets(), params.getLayoutlibCallback(), configuration, params.getTargetSdkVersion(), params.isRtlSupported());
// Test
assertEquals("android:style/ButtonBar", resources.getResourceName(android.R.style.ButtonBar));
assertEquals("android", resources.getResourcePackageName(android.R.style.ButtonBar));
assertEquals("ButtonBar", resources.getResourceEntryName(android.R.style.ButtonBar));
assertEquals("style", resources.getResourceTypeName(android.R.style.ButtonBar));
int id = resources.mLayoutlibCallback.getResourceId(ResourceType.STRING, "app_name");
assertEquals("com.android.layoutlib.test.myapplication:string/app_name", resources.getResourceName(id));
assertEquals("com.android.layoutlib.test.myapplication", resources.getResourcePackageName(id));
assertEquals("string", resources.getResourceTypeName(id));
assertEquals("app_name", resources.getResourceEntryName(id));
}
use of com.android.layoutlib.bridge.android.BridgeContext in project android_frameworks_base by AOSPA.
the class BridgeInflater method inflate.
@Override
public View inflate(int resource, ViewGroup root) {
Context context = getContext();
context = getBaseContext(context);
if (context instanceof BridgeContext) {
BridgeContext bridgeContext = (BridgeContext) context;
ResourceValue value = null;
@SuppressWarnings("deprecation") Pair<ResourceType, String> layoutInfo = Bridge.resolveResourceId(resource);
if (layoutInfo != null) {
value = bridgeContext.getRenderResources().getFrameworkResource(ResourceType.LAYOUT, layoutInfo.getSecond());
} else {
layoutInfo = mLayoutlibCallback.resolveResourceId(resource);
if (layoutInfo != null) {
value = bridgeContext.getRenderResources().getProjectResource(ResourceType.LAYOUT, layoutInfo.getSecond());
}
}
if (value != null) {
File f = new File(value.getValue());
if (f.isFile()) {
try {
XmlPullParser parser = ParserFactory.create(f, true);
BridgeXmlBlockParser bridgeParser = new BridgeXmlBlockParser(parser, bridgeContext, value.isFramework());
return inflate(bridgeParser, root);
} catch (Exception e) {
Bridge.getLog().error(LayoutLog.TAG_RESOURCES_READ, "Failed to parse file " + f.getAbsolutePath(), e, null);
return null;
}
}
}
}
return null;
}
Aggregations