use of android.graphics.RectF in project android_frameworks_base by ParanoidAndroid.
the class WindowManagerService method setUniverseTransformLocked.
public void setUniverseTransformLocked(WindowState window, float alpha, float offx, float offy, float dsdx, float dtdx, float dsdy, float dtdy) {
Transformation transform = window.mWinAnimator.mUniverseTransform;
transform.setAlpha(alpha);
Matrix matrix = transform.getMatrix();
matrix.getValues(mTmpFloats);
mTmpFloats[Matrix.MTRANS_X] = offx;
mTmpFloats[Matrix.MTRANS_Y] = offy;
mTmpFloats[Matrix.MSCALE_X] = dsdx;
mTmpFloats[Matrix.MSKEW_Y] = dtdx;
mTmpFloats[Matrix.MSKEW_X] = dsdy;
mTmpFloats[Matrix.MSCALE_Y] = dtdy;
matrix.setValues(mTmpFloats);
final DisplayInfo displayInfo = window.mDisplayContent.getDisplayInfo();
final RectF dispRect = new RectF(0, 0, displayInfo.logicalWidth, displayInfo.logicalHeight);
matrix.mapRect(dispRect);
window.mGivenTouchableRegion.set(0, 0, displayInfo.logicalWidth, displayInfo.logicalHeight);
window.mGivenTouchableRegion.op((int) dispRect.left, (int) dispRect.top, (int) dispRect.right, (int) dispRect.bottom, Region.Op.DIFFERENCE);
window.mTouchableInsets = ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_REGION;
window.mDisplayContent.layoutNeeded = true;
performLayoutAndPlaceSurfacesLocked();
}
use of android.graphics.RectF in project MPAndroidChart by PhilJay.
the class BarChart method getBarBounds.
/**
* Returns the bounding box of the specified Entry in the specified DataSet. Returns null if the Entry could not be
* found in the charts data. Performance-intensive code should use void getBarBounds(BarEntry, RectF) instead.
*
* @param e
* @return
*/
public RectF getBarBounds(BarEntry e) {
RectF bounds = new RectF();
getBarBounds(e, bounds);
return bounds;
}
use of android.graphics.RectF in project MPAndroidChart by PhilJay.
the class BarChart method getBarBounds.
/**
* The passed outputRect will be assigned the values of the bounding box of the specified Entry in the specified DataSet.
* The rect will be assigned Float.MIN_VALUE in all locations if the Entry could not be found in the charts data.
*
* @param e
* @return
*/
public void getBarBounds(BarEntry e, RectF outputRect) {
RectF bounds = outputRect;
IBarDataSet set = mData.getDataSetForEntry(e);
if (set == null) {
bounds.set(Float.MIN_VALUE, Float.MIN_VALUE, Float.MIN_VALUE, Float.MIN_VALUE);
return;
}
float y = e.getY();
float x = e.getX();
float barWidth = mData.getBarWidth();
float left = x - barWidth / 2f;
float right = x + barWidth / 2f;
float top = y >= 0 ? y : 0;
float bottom = y <= 0 ? y : 0;
bounds.set(left, top, right, bottom);
getTransformer(set.getAxisDependency()).rectValueToPixel(outputRect);
}
use of android.graphics.RectF in project MPAndroidChart by PhilJay.
the class PieChartRenderer method drawHighlighted.
@Override
public void drawHighlighted(Canvas c, Highlight[] indices) {
float phaseX = mAnimator.getPhaseX();
float phaseY = mAnimator.getPhaseY();
float angle;
float rotationAngle = mChart.getRotationAngle();
float[] drawAngles = mChart.getDrawAngles();
float[] absoluteAngles = mChart.getAbsoluteAngles();
final MPPointF center = mChart.getCenterCircleBox();
final float radius = mChart.getRadius();
final boolean drawInnerArc = mChart.isDrawHoleEnabled() && !mChart.isDrawSlicesUnderHoleEnabled();
final float userInnerRadius = drawInnerArc ? radius * (mChart.getHoleRadius() / 100.f) : 0.f;
final RectF highlightedCircleBox = mDrawHighlightedRectF;
highlightedCircleBox.set(0, 0, 0, 0);
for (int i = 0; i < indices.length; i++) {
// get the index to highlight
int index = (int) indices[i].getX();
if (index >= drawAngles.length)
continue;
IPieDataSet set = mChart.getData().getDataSetByIndex(indices[i].getDataSetIndex());
if (set == null || !set.isHighlightEnabled())
continue;
final int entryCount = set.getEntryCount();
int visibleAngleCount = 0;
for (int j = 0; j < entryCount; j++) {
// draw only if the value is greater than zero
if ((Math.abs(set.getEntryForIndex(j).getY()) > Utils.FLOAT_EPSILON)) {
visibleAngleCount++;
}
}
if (index == 0)
angle = 0.f;
else
angle = absoluteAngles[index - 1] * phaseX;
final float sliceSpace = visibleAngleCount <= 1 ? 0.f : set.getSliceSpace();
float sliceAngle = drawAngles[index];
float innerRadius = userInnerRadius;
float shift = set.getSelectionShift();
final float highlightedRadius = radius + shift;
highlightedCircleBox.set(mChart.getCircleBox());
highlightedCircleBox.inset(-shift, -shift);
final boolean accountForSliceSpacing = sliceSpace > 0.f && sliceAngle <= 180.f;
mRenderPaint.setColor(set.getColor(index));
final float sliceSpaceAngleOuter = visibleAngleCount == 1 ? 0.f : sliceSpace / (Utils.FDEG2RAD * radius);
final float sliceSpaceAngleShifted = visibleAngleCount == 1 ? 0.f : sliceSpace / (Utils.FDEG2RAD * highlightedRadius);
final float startAngleOuter = rotationAngle + (angle + sliceSpaceAngleOuter / 2.f) * phaseY;
float sweepAngleOuter = (sliceAngle - sliceSpaceAngleOuter) * phaseY;
if (sweepAngleOuter < 0.f) {
sweepAngleOuter = 0.f;
}
final float startAngleShifted = rotationAngle + (angle + sliceSpaceAngleShifted / 2.f) * phaseY;
float sweepAngleShifted = (sliceAngle - sliceSpaceAngleShifted) * phaseY;
if (sweepAngleShifted < 0.f) {
sweepAngleShifted = 0.f;
}
mPathBuffer.reset();
if (sweepAngleOuter >= 360.f && sweepAngleOuter % 360f <= Utils.FLOAT_EPSILON) {
// Android is doing "mod 360"
mPathBuffer.addCircle(center.x, center.y, highlightedRadius, Path.Direction.CW);
} else {
mPathBuffer.moveTo(center.x + highlightedRadius * (float) Math.cos(startAngleShifted * Utils.FDEG2RAD), center.y + highlightedRadius * (float) Math.sin(startAngleShifted * Utils.FDEG2RAD));
mPathBuffer.arcTo(highlightedCircleBox, startAngleShifted, sweepAngleShifted);
}
float sliceSpaceRadius = 0.f;
if (accountForSliceSpacing) {
sliceSpaceRadius = calculateMinimumRadiusForSpacedSlice(center, radius, sliceAngle * phaseY, center.x + radius * (float) Math.cos(startAngleOuter * Utils.FDEG2RAD), center.y + radius * (float) Math.sin(startAngleOuter * Utils.FDEG2RAD), startAngleOuter, sweepAngleOuter);
}
// API < 21 does not receive floats in addArc, but a RectF
mInnerRectBuffer.set(center.x - innerRadius, center.y - innerRadius, center.x + innerRadius, center.y + innerRadius);
if (drawInnerArc && (innerRadius > 0.f || accountForSliceSpacing)) {
if (accountForSliceSpacing) {
float minSpacedRadius = sliceSpaceRadius;
if (minSpacedRadius < 0.f)
minSpacedRadius = -minSpacedRadius;
innerRadius = Math.max(innerRadius, minSpacedRadius);
}
final float sliceSpaceAngleInner = visibleAngleCount == 1 || innerRadius == 0.f ? 0.f : sliceSpace / (Utils.FDEG2RAD * innerRadius);
final float startAngleInner = rotationAngle + (angle + sliceSpaceAngleInner / 2.f) * phaseY;
float sweepAngleInner = (sliceAngle - sliceSpaceAngleInner) * phaseY;
if (sweepAngleInner < 0.f) {
sweepAngleInner = 0.f;
}
final float endAngleInner = startAngleInner + sweepAngleInner;
if (sweepAngleOuter >= 360.f && sweepAngleOuter % 360f <= Utils.FLOAT_EPSILON) {
// Android is doing "mod 360"
mPathBuffer.addCircle(center.x, center.y, innerRadius, Path.Direction.CCW);
} else {
mPathBuffer.lineTo(center.x + innerRadius * (float) Math.cos(endAngleInner * Utils.FDEG2RAD), center.y + innerRadius * (float) Math.sin(endAngleInner * Utils.FDEG2RAD));
mPathBuffer.arcTo(mInnerRectBuffer, endAngleInner, -sweepAngleInner);
}
} else {
if (sweepAngleOuter % 360f > Utils.FLOAT_EPSILON) {
if (accountForSliceSpacing) {
final float angleMiddle = startAngleOuter + sweepAngleOuter / 2.f;
final float arcEndPointX = center.x + sliceSpaceRadius * (float) Math.cos(angleMiddle * Utils.FDEG2RAD);
final float arcEndPointY = center.y + sliceSpaceRadius * (float) Math.sin(angleMiddle * Utils.FDEG2RAD);
mPathBuffer.lineTo(arcEndPointX, arcEndPointY);
} else {
mPathBuffer.lineTo(center.x, center.y);
}
}
}
mPathBuffer.close();
mBitmapCanvas.drawPath(mPathBuffer, mRenderPaint);
}
MPPointF.recycleInstance(center);
}
use of android.graphics.RectF in project MPAndroidChart by PhilJay.
the class PieChartRenderer method drawCenterText.
/**
* draws the description text in the center of the pie chart makes most
* sense when center-hole is enabled
*/
protected void drawCenterText(Canvas c) {
CharSequence centerText = mChart.getCenterText();
if (mChart.isDrawCenterTextEnabled() && centerText != null) {
MPPointF center = mChart.getCenterCircleBox();
MPPointF offset = mChart.getCenterTextOffset();
float x = center.x + offset.x;
float y = center.y + offset.y;
float innerRadius = mChart.isDrawHoleEnabled() && !mChart.isDrawSlicesUnderHoleEnabled() ? mChart.getRadius() * (mChart.getHoleRadius() / 100f) : mChart.getRadius();
RectF holeRect = mRectBuffer[0];
holeRect.left = x - innerRadius;
holeRect.top = y - innerRadius;
holeRect.right = x + innerRadius;
holeRect.bottom = y + innerRadius;
RectF boundingRect = mRectBuffer[1];
boundingRect.set(holeRect);
float radiusPercent = mChart.getCenterTextRadiusPercent() / 100f;
if (radiusPercent > 0.0) {
boundingRect.inset((boundingRect.width() - boundingRect.width() * radiusPercent) / 2.f, (boundingRect.height() - boundingRect.height() * radiusPercent) / 2.f);
}
if (!centerText.equals(mCenterTextLastValue) || !boundingRect.equals(mCenterTextLastBounds)) {
// Next time we won't recalculate StaticLayout...
mCenterTextLastBounds.set(boundingRect);
mCenterTextLastValue = centerText;
float width = mCenterTextLastBounds.width();
// If width is 0, it will crash. Always have a minimum of 1
mCenterTextLayout = new StaticLayout(centerText, 0, centerText.length(), mCenterTextPaint, (int) Math.max(Math.ceil(width), 1.f), Layout.Alignment.ALIGN_CENTER, 1.f, 0.f, false);
}
//float layoutWidth = Utils.getStaticLayoutMaxWidth(mCenterTextLayout);
float layoutHeight = mCenterTextLayout.getHeight();
c.save();
if (Build.VERSION.SDK_INT >= 18) {
Path path = mDrawCenterTextPathBuffer;
path.reset();
path.addOval(holeRect, Path.Direction.CW);
c.clipPath(path);
}
c.translate(boundingRect.left, boundingRect.top + (boundingRect.height() - layoutHeight) / 2.f);
mCenterTextLayout.draw(c);
c.restore();
MPPointF.recycleInstance(center);
MPPointF.recycleInstance(offset);
}
}
Aggregations