use of com.android.layoutlib.bridge.android.BridgeContext in project android_frameworks_base by crdroidandroid.
the class RenderSessionImpl method animate.
/**
* Animate an object
* <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#animate(Object, String, boolean, IAnimationListener)
*/
public Result animate(Object targetObject, String animationName, boolean isFrameworkAnimation, IAnimationListener listener) {
checkLock();
BridgeContext context = getContext();
// find the animation file.
ResourceValue animationResource;
int animationId = 0;
if (isFrameworkAnimation) {
animationResource = context.getRenderResources().getFrameworkResource(ResourceType.ANIMATOR, animationName);
if (animationResource != null) {
animationId = Bridge.getResourceId(ResourceType.ANIMATOR, animationName);
}
} else {
animationResource = context.getRenderResources().getProjectResource(ResourceType.ANIMATOR, animationName);
if (animationResource != null) {
animationId = context.getLayoutlibCallback().getResourceId(ResourceType.ANIMATOR, animationName);
}
}
if (animationResource != null) {
try {
Animator anim = AnimatorInflater.loadAnimator(context, animationId);
if (anim != null) {
anim.setTarget(targetObject);
new PlayAnimationThread(anim, this, animationName, listener).start();
return SUCCESS.createResult();
}
} catch (Exception e) {
// get the real cause of the exception.
Throwable t = e;
while (t.getCause() != null) {
t = t.getCause();
}
return ERROR_UNKNOWN.createResult(t.getMessage(), t);
}
}
return ERROR_ANIM_NOT_FOUND.createResult();
}
use of com.android.layoutlib.bridge.android.BridgeContext in project android_frameworks_base by crdroidandroid.
the class AdapterHelper method getView.
@SuppressWarnings("deprecation")
static Pair<View, Boolean> getView(AdapterItem item, AdapterItem parentItem, ViewGroup parent, LayoutlibCallback callback, ResourceReference adapterRef, boolean skipCallbackParser) {
// we don't care about recycling here because we never scroll.
DataBindingItem dataBindingItem = item.getDataBindingItem();
BridgeContext context = RenderAction.getCurrentContext();
Pair<View, Boolean> pair = context.inflateView(dataBindingItem.getViewReference(), parent, false, /*attachToRoot*/
skipCallbackParser);
View view = pair.getFirst();
skipCallbackParser |= pair.getSecond();
if (view != null) {
fillView(context, view, item, parentItem, callback, adapterRef);
} else {
// create a text view to display an error.
TextView tv = new TextView(context);
tv.setText("Unable to find layout: " + dataBindingItem.getViewReference().getName());
view = tv;
}
return Pair.of(view, skipCallbackParser);
}
use of com.android.layoutlib.bridge.android.BridgeContext in project android_frameworks_base by crdroidandroid.
the class RenderDrawable method render.
public Result render() {
checkLock();
// get the drawable resource value
DrawableParams params = getParams();
HardwareConfig hardwareConfig = params.getHardwareConfig();
ResourceValue drawableResource = params.getDrawable();
// resolve it
BridgeContext context = getContext();
drawableResource = context.getRenderResources().resolveResValue(drawableResource);
if (drawableResource == null) {
return Status.ERROR_NOT_A_DRAWABLE.createResult();
}
ResourceType resourceType = drawableResource.getResourceType();
if (resourceType != ResourceType.DRAWABLE && resourceType != ResourceType.MIPMAP) {
return Status.ERROR_NOT_A_DRAWABLE.createResult();
}
Drawable d = ResourceHelper.getDrawable(drawableResource, context);
final Boolean allStates = params.getFlag(RenderParamsFlags.FLAG_KEY_RENDER_ALL_DRAWABLE_STATES);
if (allStates == Boolean.TRUE) {
final List<BufferedImage> result;
if (d instanceof StateListDrawable) {
result = new ArrayList<BufferedImage>();
final StateListDrawable stateList = (StateListDrawable) d;
for (int i = 0; i < stateList.getStateCount(); i++) {
final Drawable stateDrawable = stateList.getStateDrawable(i);
result.add(renderImage(hardwareConfig, stateDrawable, context));
}
} else {
result = Collections.singletonList(renderImage(hardwareConfig, d, context));
}
return Status.SUCCESS.createResult(result);
} else {
BufferedImage image = renderImage(hardwareConfig, d, context);
return Status.SUCCESS.createResult(image);
}
}
use of com.android.layoutlib.bridge.android.BridgeContext in project android_frameworks_base by AOSPA.
the class RenderDrawable method render.
public Result render() {
checkLock();
// get the drawable resource value
DrawableParams params = getParams();
HardwareConfig hardwareConfig = params.getHardwareConfig();
ResourceValue drawableResource = params.getDrawable();
// resolve it
BridgeContext context = getContext();
drawableResource = context.getRenderResources().resolveResValue(drawableResource);
if (drawableResource == null) {
return Status.ERROR_NOT_A_DRAWABLE.createResult();
}
ResourceType resourceType = drawableResource.getResourceType();
if (resourceType != ResourceType.DRAWABLE && resourceType != ResourceType.MIPMAP) {
return Status.ERROR_NOT_A_DRAWABLE.createResult();
}
Drawable d = ResourceHelper.getDrawable(drawableResource, context);
final Boolean allStates = params.getFlag(RenderParamsFlags.FLAG_KEY_RENDER_ALL_DRAWABLE_STATES);
if (allStates == Boolean.TRUE) {
final List<BufferedImage> result;
if (d instanceof StateListDrawable) {
result = new ArrayList<BufferedImage>();
final StateListDrawable stateList = (StateListDrawable) d;
for (int i = 0; i < stateList.getStateCount(); i++) {
final Drawable stateDrawable = stateList.getStateDrawable(i);
result.add(renderImage(hardwareConfig, stateDrawable, context));
}
} else {
result = Collections.singletonList(renderImage(hardwareConfig, d, context));
}
return Status.SUCCESS.createResult(result);
} else {
BufferedImage image = renderImage(hardwareConfig, d, context);
return Status.SUCCESS.createResult(image);
}
}
use of com.android.layoutlib.bridge.android.BridgeContext in project android_frameworks_base by AOSPA.
the class AdapterHelper method getView.
@SuppressWarnings("deprecation")
static Pair<View, Boolean> getView(AdapterItem item, AdapterItem parentItem, ViewGroup parent, LayoutlibCallback callback, ResourceReference adapterRef, boolean skipCallbackParser) {
// we don't care about recycling here because we never scroll.
DataBindingItem dataBindingItem = item.getDataBindingItem();
BridgeContext context = RenderAction.getCurrentContext();
Pair<View, Boolean> pair = context.inflateView(dataBindingItem.getViewReference(), parent, false, /*attachToRoot*/
skipCallbackParser);
View view = pair.getFirst();
skipCallbackParser |= pair.getSecond();
if (view != null) {
fillView(context, view, item, parentItem, callback, adapterRef);
} else {
// create a text view to display an error.
TextView tv = new TextView(context);
tv.setText("Unable to find layout: " + dataBindingItem.getViewReference().getName());
view = tv;
}
return Pair.of(view, skipCallbackParser);
}
Aggregations