use of com.android.ide.common.rendering.api.HardwareConfig in project android_frameworks_base by ParanoidAndroid.
the class RenderSessionImpl method inflate.
/**
* Inflates the layout.
* <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 #init(long)} was not called.
*/
public Result inflate() {
checkLock();
try {
SessionParams params = getParams();
HardwareConfig hardwareConfig = params.getHardwareConfig();
BridgeContext context = getContext();
// the view group that receives the window background.
ViewGroup backgroundView = null;
if (mWindowIsFloating || params.isForceNoDecor()) {
backgroundView = mViewRoot = mContentRoot = new FrameLayout(context);
} else {
if (hasSoftwareButtons() && mNavigationBarOrientation == LinearLayout.VERTICAL) {
/*
* This is a special case where the navigation bar is on the right.
+-------------------------------------------------+---+
| Status bar (always) | |
+-------------------------------------------------+ |
| (Layout with background drawable) | |
| +---------------------------------------------+ | |
| | Title/Action bar (optional) | | |
| +---------------------------------------------+ | |
| | Content, vertical extending | | |
| | | | |
| +---------------------------------------------+ | |
+-------------------------------------------------+---+
So we create a horizontal layout, with the nav bar on the right,
and the left part is the normal layout below without the nav bar at
the bottom
*/
LinearLayout topLayout = new LinearLayout(context);
mViewRoot = topLayout;
topLayout.setOrientation(LinearLayout.HORIZONTAL);
try {
NavigationBar navigationBar = new NavigationBar(context, hardwareConfig.getDensity(), LinearLayout.VERTICAL);
navigationBar.setLayoutParams(new LinearLayout.LayoutParams(mNavigationBarSize, LayoutParams.MATCH_PARENT));
topLayout.addView(navigationBar);
} catch (XmlPullParserException e) {
}
}
/*
* we're creating the following layout
*
+-------------------------------------------------+
| Status bar (always) |
+-------------------------------------------------+
| (Layout with background drawable) |
| +---------------------------------------------+ |
| | Title/Action bar (optional) | |
| +---------------------------------------------+ |
| | Content, vertical extending | |
| | | |
| +---------------------------------------------+ |
+-------------------------------------------------+
| Navigation bar for soft buttons, maybe see above|
+-------------------------------------------------+
*/
LinearLayout topLayout = new LinearLayout(context);
topLayout.setOrientation(LinearLayout.VERTICAL);
// if we don't already have a view root this is it
if (mViewRoot == null) {
mViewRoot = topLayout;
} else {
LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT);
layoutParams.weight = 1;
topLayout.setLayoutParams(layoutParams);
// this is the case of soft buttons + vertical bar.
// this top layout is the first layout in the horizontal layout. see above)
mViewRoot.addView(topLayout, 0);
}
if (mStatusBarSize > 0) {
// system bar
try {
StatusBar systemBar = new StatusBar(context, hardwareConfig.getDensity());
systemBar.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, mStatusBarSize));
topLayout.addView(systemBar);
} catch (XmlPullParserException e) {
}
}
LinearLayout backgroundLayout = new LinearLayout(context);
backgroundView = backgroundLayout;
backgroundLayout.setOrientation(LinearLayout.VERTICAL);
LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
layoutParams.weight = 1;
backgroundLayout.setLayoutParams(layoutParams);
topLayout.addView(backgroundLayout);
// if the theme says no title/action bar, then the size will be 0
if (mActionBarSize > 0) {
try {
FakeActionBar actionBar = new FakeActionBar(context, hardwareConfig.getDensity(), params.getAppLabel(), params.getAppIcon());
actionBar.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, mActionBarSize));
backgroundLayout.addView(actionBar);
} catch (XmlPullParserException e) {
}
} else if (mTitleBarSize > 0) {
try {
TitleBar titleBar = new TitleBar(context, hardwareConfig.getDensity(), params.getAppLabel());
titleBar.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, mTitleBarSize));
backgroundLayout.addView(titleBar);
} catch (XmlPullParserException e) {
}
}
// content frame
mContentRoot = new FrameLayout(context);
layoutParams = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
layoutParams.weight = 1;
mContentRoot.setLayoutParams(layoutParams);
backgroundLayout.addView(mContentRoot);
if (mNavigationBarOrientation == LinearLayout.HORIZONTAL && mNavigationBarSize > 0) {
// system bar
try {
NavigationBar navigationBar = new NavigationBar(context, hardwareConfig.getDensity(), LinearLayout.HORIZONTAL);
navigationBar.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, mNavigationBarSize));
topLayout.addView(navigationBar);
} catch (XmlPullParserException e) {
}
}
}
// Sets the project callback (custom view loader) to the fragment delegate so that
// it can instantiate the custom Fragment.
Fragment_Delegate.setProjectCallback(params.getProjectCallback());
View view = mInflater.inflate(mBlockParser, mContentRoot);
// done with the parser, pop it.
context.popParser();
Fragment_Delegate.setProjectCallback(null);
// set the AttachInfo on the root view.
AttachInfo_Accessor.setAttachInfo(mViewRoot);
// post-inflate process. For now this supports TabHost/TabWidget
postInflateProcess(view, params.getProjectCallback());
// get the background drawable
if (mWindowBackground != null && backgroundView != null) {
Drawable d = ResourceHelper.getDrawable(mWindowBackground, context);
backgroundView.setBackground(d);
}
return SUCCESS.createResult();
} catch (PostInflateException e) {
return ERROR_INFLATION.createResult(e.getMessage(), e);
} catch (Throwable e) {
// get the real cause of the exception.
Throwable t = e;
while (t.getCause() != null) {
t = t.getCause();
}
return ERROR_INFLATION.createResult(t.getMessage(), t);
}
}
use of com.android.ide.common.rendering.api.HardwareConfig in project android_frameworks_base by ParanoidAndroid.
the class RenderSessionImpl method findNavigationBar.
private void findNavigationBar(RenderResources resources, DisplayMetrics metrics) {
if (hasSoftwareButtons() && mWindowIsFloating == false) {
// default value
// ??
mNavigationBarSize = 48;
HardwareConfig hardwareConfig = getParams().getHardwareConfig();
boolean barOnBottom = true;
if (hardwareConfig.getOrientation() == ScreenOrientation.LANDSCAPE) {
// compute the dp of the screen.
int shortSize = hardwareConfig.getScreenHeight();
// compute in dp
int shortSizeDp = shortSize * DisplayMetrics.DENSITY_DEFAULT / hardwareConfig.getDensity().getDpiValue();
if (shortSizeDp < 600) {
// 0-599dp: "phone" UI with bar on the side
barOnBottom = false;
} else {
// 600+dp: "tablet" UI with bar on the bottom
barOnBottom = true;
}
}
if (barOnBottom) {
mNavigationBarOrientation = LinearLayout.HORIZONTAL;
} else {
mNavigationBarOrientation = LinearLayout.VERTICAL;
}
// get the real value
ResourceValue value = resources.getFrameworkResource(ResourceType.DIMEN, barOnBottom ? "navigation_bar_height" : "navigation_bar_width");
if (value != null) {
TypedValue typedValue = ResourceHelper.getValue("navigation_bar_height", value.getValue(), true);
if (typedValue != null) {
// compute the pixel value based on the display metrics
mNavigationBarSize = (int) typedValue.getDimension(metrics);
}
}
}
}
use of com.android.ide.common.rendering.api.HardwareConfig in project platform_frameworks_base by android.
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.HardwareConfig in project platform_frameworks_base by android.
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 getConfiguration.
// VisibleForTesting
public static Configuration getConfiguration(RenderParams params) {
Configuration config = new Configuration();
HardwareConfig hardwareConfig = params.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) {
//noinspection SuspiciousNameCombination
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:
//noinspection deprecation
config.orientation = Configuration.ORIENTATION_SQUARE;
break;
}
} else {
config.orientation = Configuration.ORIENTATION_UNDEFINED;
}
ScreenRound roundness = hardwareConfig.getScreenRoundness();
if (roundness != null) {
switch(roundness) {
case ROUND:
config.screenLayout |= Configuration.SCREENLAYOUT_ROUND_YES;
break;
case NOTROUND:
config.screenLayout |= Configuration.SCREENLAYOUT_ROUND_NO;
}
} else {
config.screenLayout |= Configuration.SCREENLAYOUT_ROUND_UNDEFINED;
}
String locale = params.getLocale();
if (locale != null && !locale.isEmpty())
config.locale = new Locale(locale);
return config;
}
Aggregations