use of com.android.ide.common.rendering.api.RenderResources in project android_frameworks_base by ResurrectionRemix.
the class Resources_Delegate method getResourceValue.
private static Pair<String, ResourceValue> getResourceValue(Resources resources, int id, boolean[] platformResFlag_out) {
Pair<ResourceType, String> resourceInfo = getResourceInfo(resources, id, platformResFlag_out);
if (resourceInfo != null) {
String attributeName = resourceInfo.getSecond();
RenderResources renderResources = resources.mContext.getRenderResources();
return Pair.of(attributeName, platformResFlag_out[0] ? renderResources.getFrameworkResource(resourceInfo.getFirst(), attributeName) : renderResources.getProjectResource(resourceInfo.getFirst(), attributeName));
}
return null;
}
use of com.android.ide.common.rendering.api.RenderResources in project android_frameworks_base by ResurrectionRemix.
the class BridgeTypedArray method resolveEnumAttribute.
/**
* Searches for the string in the attributes (flag or enums) and returns the integer.
* If found, it will return an integer matching the value.
*
* @param index Index of attribute to retrieve.
*
* @return Attribute int value, or null if not defined.
*/
private Integer resolveEnumAttribute(int index) {
// Get the map of attribute-constant -> IntegerValue
Map<String, Integer> map = null;
if (mIsFramework[index]) {
map = Bridge.getEnumValues(mNames[index]);
} else {
// get the styleable matching the resolved name
RenderResources res = mContext.getRenderResources();
ResourceValue attr = res.getProjectResource(ResourceType.ATTR, mNames[index]);
if (attr instanceof AttrResourceValue) {
map = ((AttrResourceValue) attr).getAttributeValues();
}
}
if (map != null) {
// accumulator to store the value of the 1+ constants.
int result = 0;
boolean found = false;
// split the value in case this is a mix of several flags.
String[] keywords = mResourceData[index].getValue().split("\\|");
for (String keyword : keywords) {
Integer i = map.get(keyword.trim());
if (i != null) {
result |= i;
found = true;
}
// TODO: We should act smartly and log a warning for incorrect keywords. However,
// this method is currently called even if the resourceValue is not an enum.
}
if (found) {
return result;
}
}
return null;
}
use of com.android.ide.common.rendering.api.RenderResources in project android_frameworks_base by ResurrectionRemix.
the class RenderAction method init.
/**
* Initializes and acquires the scene, creating various Android objects such as context,
* inflater, and parser.
*
* @param timeout the time to wait if another rendering is happening.
*
* @return whether the scene was prepared
*
* @see #acquire(long)
* @see #release()
*/
public Result init(long timeout) {
// acquire the lock. if the result is null, lock was just acquired, otherwise, return
// the result.
Result result = acquireLock(timeout);
if (result != null) {
return result;
}
HardwareConfig hardwareConfig = mParams.getHardwareConfig();
// setup the display Metrics.
DisplayMetrics metrics = new DisplayMetrics();
metrics.densityDpi = metrics.noncompatDensityDpi = hardwareConfig.getDensity().getDpiValue();
metrics.density = metrics.noncompatDensity = metrics.densityDpi / (float) DisplayMetrics.DENSITY_DEFAULT;
metrics.scaledDensity = metrics.noncompatScaledDensity = metrics.density;
metrics.widthPixels = metrics.noncompatWidthPixels = hardwareConfig.getScreenWidth();
metrics.heightPixels = metrics.noncompatHeightPixels = hardwareConfig.getScreenHeight();
metrics.xdpi = metrics.noncompatXdpi = hardwareConfig.getXdpi();
metrics.ydpi = metrics.noncompatYdpi = hardwareConfig.getYdpi();
RenderResources resources = mParams.getResources();
// build the context
mContext = new BridgeContext(mParams.getProjectKey(), metrics, resources, mParams.getAssets(), mParams.getLayoutlibCallback(), getConfiguration(mParams), mParams.getTargetSdkVersion(), mParams.isRtlSupported());
setUp();
return SUCCESS.createResult();
}
use of com.android.ide.common.rendering.api.RenderResources in project android_frameworks_base by crdroidandroid.
the class RenderAction method init.
/**
* Initializes and acquires the scene, creating various Android objects such as context,
* inflater, and parser.
*
* @param timeout the time to wait if another rendering is happening.
*
* @return whether the scene was prepared
*
* @see #acquire(long)
* @see #release()
*/
public Result init(long timeout) {
// acquire the lock. if the result is null, lock was just acquired, otherwise, return
// the result.
Result result = acquireLock(timeout);
if (result != null) {
return result;
}
HardwareConfig hardwareConfig = mParams.getHardwareConfig();
// setup the display Metrics.
DisplayMetrics metrics = new DisplayMetrics();
metrics.densityDpi = metrics.noncompatDensityDpi = hardwareConfig.getDensity().getDpiValue();
metrics.density = metrics.noncompatDensity = metrics.densityDpi / (float) DisplayMetrics.DENSITY_DEFAULT;
metrics.scaledDensity = metrics.noncompatScaledDensity = metrics.density;
metrics.widthPixels = metrics.noncompatWidthPixels = hardwareConfig.getScreenWidth();
metrics.heightPixels = metrics.noncompatHeightPixels = hardwareConfig.getScreenHeight();
metrics.xdpi = metrics.noncompatXdpi = hardwareConfig.getXdpi();
metrics.ydpi = metrics.noncompatYdpi = hardwareConfig.getYdpi();
RenderResources resources = mParams.getResources();
// build the context
mContext = new BridgeContext(mParams.getProjectKey(), metrics, resources, mParams.getAssets(), mParams.getLayoutlibCallback(), getConfiguration(mParams), mParams.getTargetSdkVersion(), mParams.isRtlSupported());
setUp();
return SUCCESS.createResult();
}
use of com.android.ide.common.rendering.api.RenderResources in project android_frameworks_base by crdroidandroid.
the class RenderSessionImpl method setActiveToolbar.
/**
* If the root layout is a CoordinatorLayout with an AppBar:
* Set the title of the AppBar to the title of the activity context.
*/
private void setActiveToolbar(View view, BridgeContext context, SessionParams params) {
View coordinatorLayout = findChildView(view, DesignLibUtil.CN_COORDINATOR_LAYOUT);
if (coordinatorLayout == null) {
return;
}
View appBar = findChildView(coordinatorLayout, DesignLibUtil.CN_APPBAR_LAYOUT);
if (appBar == null) {
return;
}
ViewGroup collapsingToolbar = (ViewGroup) findChildView(appBar, DesignLibUtil.CN_COLLAPSING_TOOLBAR_LAYOUT);
if (collapsingToolbar == null) {
return;
}
if (!hasToolbar(collapsingToolbar)) {
return;
}
RenderResources res = context.getRenderResources();
String title = params.getAppLabel();
ResourceValue titleValue = res.findResValue(title, false);
if (titleValue != null && titleValue.getValue() != null) {
title = titleValue.getValue();
}
DesignLibUtil.setTitle(collapsingToolbar, title);
}
Aggregations