use of com.android.ide.common.rendering.api.HardwareConfig in project android_frameworks_base by ParanoidAndroid.
the class RenderAction method getConfiguration.
private Configuration getConfiguration() {
Configuration config = new Configuration();
HardwareConfig hardwareConfig = mParams.getHardwareConfig();
ScreenSize screenSize = hardwareConfig.getScreenSize();
if (screenSize != null) {
switch(screenSize) {
case SMALL:
config.screenLayout |= Configuration.SCREENLAYOUT_SIZE_SMALL;
break;
case NORMAL:
config.screenLayout |= Configuration.SCREENLAYOUT_SIZE_NORMAL;
break;
case LARGE:
config.screenLayout |= Configuration.SCREENLAYOUT_SIZE_LARGE;
break;
case XLARGE:
config.screenLayout |= Configuration.SCREENLAYOUT_SIZE_XLARGE;
break;
}
}
Density density = hardwareConfig.getDensity();
if (density == null) {
density = Density.MEDIUM;
}
config.screenWidthDp = hardwareConfig.getScreenWidth() / density.getDpiValue();
config.screenHeightDp = hardwareConfig.getScreenHeight() / density.getDpiValue();
if (config.screenHeightDp < config.screenWidthDp) {
config.smallestScreenWidthDp = config.screenHeightDp;
} else {
config.smallestScreenWidthDp = config.screenWidthDp;
}
config.densityDpi = density.getDpiValue();
// never run in compat mode:
config.compatScreenWidthDp = config.screenWidthDp;
config.compatScreenHeightDp = config.screenHeightDp;
ScreenOrientation orientation = hardwareConfig.getOrientation();
if (orientation != null) {
switch(orientation) {
case PORTRAIT:
config.orientation = Configuration.ORIENTATION_PORTRAIT;
break;
case LANDSCAPE:
config.orientation = Configuration.ORIENTATION_LANDSCAPE;
break;
case SQUARE:
config.orientation = Configuration.ORIENTATION_SQUARE;
break;
}
} else {
config.orientation = Configuration.ORIENTATION_UNDEFINED;
}
return config;
}
use of com.android.ide.common.rendering.api.HardwareConfig in project android by JetBrains.
the class LayoutPullParserFactory method create.
@Nullable
public static ILayoutPullParser create(@NotNull final RenderTask renderTask) {
final ResourceFolderType folderType = renderTask.getFolderType();
if (folderType == null) {
return null;
}
if ((folderType == ResourceFolderType.DRAWABLE || folderType == ResourceFolderType.MENU || folderType == ResourceFolderType.XML) && !ApplicationManager.getApplication().isReadAccessAllowed()) {
return ApplicationManager.getApplication().runReadAction((Computable<ILayoutPullParser>) () -> create(renderTask));
}
XmlFile file = renderTask.getPsiFile();
if (file == null) {
throw new IllegalArgumentException("RenderTask always should always have PsiFile when it has ResourceFolderType");
}
switch(folderType) {
case LAYOUT:
{
RenderLogger logger = renderTask.getLogger();
Set<XmlTag> expandNodes = renderTask.getExpandNodes();
HardwareConfig hardwareConfig = renderTask.getHardwareConfigHelper().getConfig();
return LayoutPsiPullParser.create(file, logger, expandNodes, hardwareConfig.getDensity());
}
case DRAWABLE:
renderTask.setDecorations(false);
return createDrawableParser(file);
case MENU:
if (renderTask.supportsCapability(Features.ACTION_BAR)) {
return new MenuLayoutParserFactory(renderTask).render();
}
renderTask.setRenderingMode(V_SCROLL);
renderTask.setDecorations(false);
return new MenuPreviewRenderer(renderTask, file).render();
case XML:
{
// Switch on root type
XmlTag rootTag = file.getRootTag();
if (rootTag != null) {
String tag = rootTag.getName();
if (tag.equals(TAG_APPWIDGET_PROVIDER)) {
// Widget
renderTask.setDecorations(false);
return createWidgetParser(rootTag);
} else if (tag.equals(TAG_PREFERENCE_SCREEN)) {
RenderLogger logger = renderTask.getLogger();
Set<XmlTag> expandNodes = renderTask.getExpandNodes();
HardwareConfig hardwareConfig = renderTask.getHardwareConfigHelper().getConfig();
return LayoutPsiPullParser.create(file, logger, expandNodes, hardwareConfig.getDensity());
}
}
return null;
}
default:
// Should have been prevented by isSupported(PsiFile)
assert false : folderType;
return null;
}
}
use of com.android.ide.common.rendering.api.HardwareConfig in project android by JetBrains.
the class ScreenView method getPreferredSize.
/**
* Returns the current preferred size for the view.
* @param dimension optional existing {@link Dimension} instance to be reused. If not null, the values will be set and this instance
* returned.
*/
@NotNull
public Dimension getPreferredSize(@Nullable Dimension dimension) {
if (dimension == null) {
dimension = new Dimension();
}
Configuration configuration = getConfiguration();
Device device = configuration.getDevice();
State state = configuration.getDeviceState();
if (device != null && state != null) {
HardwareConfig config = new HardwareConfigHelper(device).setOrientation(state.getOrientation()).getConfig();
dimension.setSize(config.getScreenWidth(), config.getScreenHeight());
}
return dimension;
}
use of com.android.ide.common.rendering.api.HardwareConfig in project android_frameworks_base by DirtyUnicorns.
the class RenderSessionImpl method render.
/**
* Renders the scene.
* <p>
* {@link #acquire(long)} must have been called before this.
*
* @param freshRender whether the render is a new one and should erase the existing bitmap (in
* the case where bitmaps are reused). This is typically needed when not playing
* animations.)
*
* @throws IllegalStateException if the current context is different than the one owned by
* the scene, or if {@link #acquire(long)} was not called.
*
* @see SessionParams#getRenderingMode()
* @see RenderSession#render(long)
*/
public Result render(boolean freshRender) {
checkLock();
SessionParams params = getParams();
try {
if (mViewRoot == null) {
return ERROR_NOT_INFLATED.createResult();
}
measure(params);
HardwareConfig hardwareConfig = params.getHardwareConfig();
Result renderResult = SUCCESS.createResult();
if (params.isLayoutOnly()) {
// delete the canvas and image to reset them on the next full rendering
mImage = null;
mCanvas = null;
} else {
// draw the views
// create the BufferedImage into which the layout will be rendered.
boolean newImage = false;
// When disableBitmapCaching is true, we do not reuse mImage and
// we create a new one in every render.
// This is useful when mImage is just a wrapper of Graphics2D so
// it doesn't get cached.
boolean disableBitmapCaching = Boolean.TRUE.equals(params.getFlag(RenderParamsFlags.FLAG_KEY_DISABLE_BITMAP_CACHING));
if (mNewRenderSize || mCanvas == null || disableBitmapCaching) {
mNewRenderSize = false;
if (params.getImageFactory() != null) {
mImage = params.getImageFactory().getImage(mMeasuredScreenWidth, mMeasuredScreenHeight);
} else {
mImage = new BufferedImage(mMeasuredScreenWidth, mMeasuredScreenHeight, BufferedImage.TYPE_INT_ARGB);
newImage = true;
}
if (params.isBgColorOverridden()) {
// since we override the content, it's the same as if it was a new image.
newImage = true;
Graphics2D gc = mImage.createGraphics();
gc.setColor(new Color(params.getOverrideBgColor(), true));
gc.setComposite(AlphaComposite.Src);
gc.fillRect(0, 0, mMeasuredScreenWidth, mMeasuredScreenHeight);
gc.dispose();
}
// create an Android bitmap around the BufferedImage
Bitmap bitmap = Bitmap_Delegate.createBitmap(mImage, true, /*isMutable*/
hardwareConfig.getDensity());
if (mCanvas == null) {
// create a Canvas around the Android bitmap
mCanvas = new Canvas(bitmap);
} else {
mCanvas.setBitmap(bitmap);
}
mCanvas.setDensity(hardwareConfig.getDensity().getDpiValue());
}
if (freshRender && !newImage) {
Graphics2D gc = mImage.createGraphics();
gc.setComposite(AlphaComposite.Src);
gc.setColor(new Color(0x00000000, true));
gc.fillRect(0, 0, mMeasuredScreenWidth, mMeasuredScreenHeight);
// done
gc.dispose();
}
if (mElapsedFrameTimeNanos >= 0) {
long initialTime = System_Delegate.nanoTime();
if (!mFirstFrameExecuted) {
// We need to run an initial draw call to initialize the animations
render(getContext(), mViewRoot, NOP_CANVAS, mMeasuredScreenWidth, mMeasuredScreenHeight);
// The first frame will initialize the animations
Choreographer_Delegate.doFrame(initialTime);
mFirstFrameExecuted = true;
}
// Second frame will move the animations
Choreographer_Delegate.doFrame(initialTime + mElapsedFrameTimeNanos);
}
renderResult = render(getContext(), mViewRoot, mCanvas, mMeasuredScreenWidth, mMeasuredScreenHeight);
}
mSystemViewInfoList = visitAllChildren(mViewRoot, 0, params.getExtendedViewInfoMode(), false);
// success!
return renderResult;
} catch (Throwable 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);
}
}
use of com.android.ide.common.rendering.api.HardwareConfig in project android_frameworks_base by DirtyUnicorns.
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();
}
Aggregations