use of android.graphics.RectF in project robolectric by robolectric.
the class ShadowCanvasTest method drawRect_shouldRecordRectHistoryEvents.
@Test
public void drawRect_shouldRecordRectHistoryEvents() throws Exception {
Canvas canvas = new Canvas();
Paint paint0 = new Paint();
paint0.setColor(Color.WHITE);
Paint paint1 = new Paint();
paint1.setColor(Color.BLACK);
RectF rect0 = new RectF(0f, 2f, 3f, 4f);
RectF rect1 = new RectF(5f, 6f, 7f, 8f);
canvas.drawRect(0f, 2f, 3f, 4f, paint0);
canvas.drawRect(5f, 6f, 7f, 8f, paint1);
ShadowCanvas shadowCanvas = shadowOf(canvas);
assertThat(shadowCanvas.getDrawnRect(0).left).isEqualTo(0f);
assertThat(shadowCanvas.getDrawnRect(0).top).isEqualTo(2f);
assertThat(shadowCanvas.getDrawnRect(0).right).isEqualTo(3f);
assertThat(shadowCanvas.getDrawnRect(0).bottom).isEqualTo(4f);
assertThat(shadowCanvas.getDrawnRect(0).rect).isEqualTo(rect0);
assertThat(shadowCanvas.getDrawnRect(0).paint.getColor()).isEqualTo(Color.WHITE);
assertThat(shadowCanvas.getDrawnRect(1).left).isEqualTo(5f);
assertThat(shadowCanvas.getDrawnRect(1).top).isEqualTo(6f);
assertThat(shadowCanvas.getDrawnRect(1).right).isEqualTo(7f);
assertThat(shadowCanvas.getDrawnRect(1).bottom).isEqualTo(8f);
assertThat(shadowCanvas.getDrawnRect(1).rect).isEqualTo(rect1);
assertThat(shadowCanvas.getDrawnRect(1).paint.getColor()).isEqualTo(Color.BLACK);
}
use of android.graphics.RectF in project LoadingView by ldoublem.
the class LVWifi method onDraw.
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
canvas.save();
canvas.translate(0, mWidth / signalSize);
mPaint.setStrokeWidth(mWidth / signalSize / 2 / 2 / 2);
int scale = (int) ((mAnimatedValue * signalSize - (int) (mAnimatedValue * signalSize)) * signalSize) + 1;
RectF rect = null;
float signalRadius = mWidth / 2 / signalSize;
for (int i = 0; i < signalSize; i++) {
if (i >= signalSize - scale) {
float radius = signalRadius * i;
rect = new RectF(radius, radius, mWidth - radius, mWidth - radius);
if (i < signalSize - 1) {
mPaint.setStyle(Paint.Style.STROKE);
canvas.drawArc(rect, -135, 90, false, mPaint);
} else {
mPaint.setStyle(Paint.Style.FILL);
canvas.drawArc(rect, -135, 90, true, mPaint);
}
}
}
canvas.restore();
}
use of android.graphics.RectF in project EazeGraph by blackfizz.
the class BarChart method drawBars.
/**
* Callback method for drawing the bars in the child classes.
* @param _Canvas The canvas object of the graph view.
*/
protected void drawBars(Canvas _Canvas) {
for (BarModel model : mData) {
RectF bounds = model.getBarBounds();
mGraphPaint.setColor(model.getColor());
_Canvas.drawRect(bounds.left, bounds.bottom - (bounds.height() * mRevealValue), bounds.right, bounds.bottom, mGraphPaint);
if (mShowValues) {
_Canvas.drawText(Utils.getFloatString(model.getValue(), mShowDecimal), model.getLegendBounds().centerX(), bounds.bottom - (bounds.height() * mRevealValue) - mValueDistance, mValuePaint);
}
}
}
use of android.graphics.RectF in project EazeGraph by blackfizz.
the class BarChart method calculateBounds.
/**
* Calculates the bar boundaries based on the bar width and bar margin.
* @param _Width Calculated bar width
* @param _Margin Calculated bar margin
*/
protected void calculateBounds(float _Width, float _Margin) {
float maxValue = 0;
int last = 0;
for (BarModel model : mData) {
if (model.getValue() > maxValue) {
maxValue = model.getValue();
}
}
int valuePadding = mShowValues ? (int) mValuePaint.getTextSize() + mValueDistance : 0;
float heightMultiplier = (mGraphHeight - valuePadding) / maxValue;
for (BarModel model : mData) {
float height = model.getValue() * heightMultiplier;
last += _Margin / 2;
model.setBarBounds(new RectF(last, mGraphHeight - height, last + _Width, mGraphHeight));
model.setLegendBounds(new RectF(last, 0, last + _Width, mLegendHeight));
last += _Width + (_Margin / 2);
}
Utils.calculateLegendInformation(mData, 0, mContentRect.width(), mLegendPaint);
}
use of android.graphics.RectF in project EazeGraph by blackfizz.
the class BaseBarChart method onGraphOverlayTouchEvent.
@Override
protected boolean onGraphOverlayTouchEvent(MotionEvent _Event) {
boolean result = mGestureDetector.onTouchEvent(_Event);
switch(_Event.getAction()) {
case MotionEvent.ACTION_DOWN:
result = true;
if (mListener == null) {
// we're not interested in clicks on individual bars here
BaseBarChart.this.onTouchEvent(_Event);
} else {
float newX = _Event.getX() + mCurrentViewport.left;
float newY = _Event.getY() + mCurrentViewport.top;
int counter = 0;
for (RectF rectF : getBarBounds()) {
if (Utils.intersectsPointWithRectF(rectF, newX, newY)) {
mListener.onBarClicked(counter);
// no need to check other bars
break;
}
counter++;
}
}
break;
}
return result;
}
Aggregations