use of android.graphics.Paint.Style in project Etar-Calendar by Etar-Group.
the class MonthWeekEventsView method drawEvent.
/**
* Attempts to draw the given event. Returns the y for the next event or the
* original y if the event will not fit. An event is considered to not fit
* if the event and its extras won't fit or if there are more events and the
* more events line would not fit after drawing this event.
*
* @param canvas the canvas to draw on
* @param event the event to draw
* @param x the top left corner for this event's color chip
* @param y the top left corner for this event's color chip
* @param rightEdge the rightmost point we're allowed to draw on (exclusive)
* @param moreEvents indicates whether additional events will follow this one
* @param showTimes if set, a second line with a time range will be displayed for non-all-day
* events
* @param doDraw if set, do the actual drawing; otherwise this just computes the height
* and returns
* @return the y for the next event or the original y if it won't fit
*/
protected int drawEvent(Canvas canvas, Event event, int x, int y, int rightEdge, boolean moreEvents, boolean showTimes, boolean doDraw) {
/*
* Vertical layout:
* (top of box)
* a. EVENT_Y_OFFSET_LANDSCAPE or portrait equivalent
* b. Event title: mEventHeight for a normal event, + 2xBORDER_SPACE for all-day event
* c. [optional] Time range (mExtrasHeight)
* d. EVENT_LINE_PADDING
*
* Repeat (b,c,d) as needed and space allows. If we have more events than fit, we need
* to leave room for something like "+2" at the bottom:
*
* e. "+ more" line (mExtrasHeight)
*
* f. EVENT_BOTTOM_PADDING (overlaps EVENT_LINE_PADDING)
* (bottom of box)
*/
// want a 1-pixel gap inside border
final int BORDER_SPACE = EVENT_SQUARE_BORDER + 1;
// adjust bounds for stroke width
final int STROKE_WIDTH_ADJ = EVENT_SQUARE_BORDER / 2;
boolean allDay = event.allDay;
int eventRequiredSpace = mEventHeight;
if (allDay) {
// Add a few pixels for the box we draw around all-day events.
eventRequiredSpace += BORDER_SPACE * 2;
} else if (showTimes) {
// Need room for the "1pm - 2pm" line.
eventRequiredSpace += mExtrasHeight;
}
// leave a bit of room at the bottom
int reservedSpace = EVENT_BOTTOM_PADDING;
if (moreEvents) {
// More events follow. Leave a bit of space between events.
eventRequiredSpace += EVENT_LINE_PADDING;
// Make sure we have room for the "+ more" line. (The "+ more" line is expected
// to be <= the height of an event line, so we won't show "+1" when we could be
// showing the event.)
reservedSpace += mExtrasHeight;
}
if (y + eventRequiredSpace + reservedSpace > mHeight) {
// Not enough space, return original y
return y;
} else if (!doDraw) {
return y + eventRequiredSpace;
}
boolean isDeclined = event.selfAttendeeStatus == Attendees.ATTENDEE_STATUS_DECLINED;
int color = event.color;
if (isDeclined) {
color = Utils.getDeclinedColorFromColor(color);
}
int textX, textY, textRightEdge;
if (allDay) {
// We shift the render offset "inward", because drawRect with a stroke width greater
// than 1 draws outside the specified bounds. (We don't adjust the left edge, since
// we want to match the existing appearance of the "event square".)
r.left = x;
r.right = rightEdge - STROKE_WIDTH_ADJ;
r.top = y + STROKE_WIDTH_ADJ;
r.bottom = y + mEventHeight + BORDER_SPACE * 2 - STROKE_WIDTH_ADJ;
textX = x + BORDER_SPACE;
textY = y + mEventAscentHeight + BORDER_SPACE;
textRightEdge = rightEdge - BORDER_SPACE;
} else {
r.left = x;
r.right = x + EVENT_SQUARE_WIDTH;
r.bottom = y + mEventAscentHeight;
r.top = r.bottom - EVENT_SQUARE_HEIGHT;
textX = x + EVENT_SQUARE_WIDTH + EVENT_RIGHT_PADDING;
textY = y + mEventAscentHeight;
textRightEdge = rightEdge;
}
Style boxStyle = Style.STROKE;
boolean solidBackground = false;
if (event.selfAttendeeStatus != Attendees.ATTENDEE_STATUS_INVITED) {
boxStyle = Style.FILL_AND_STROKE;
if (allDay) {
solidBackground = true;
}
}
mEventSquarePaint.setStyle(boxStyle);
mEventSquarePaint.setColor(color);
canvas.drawRect(r, mEventSquarePaint);
float avail = textRightEdge - textX;
CharSequence text = TextUtils.ellipsize(event.title, mEventPaint, avail, TextUtils.TruncateAt.END);
Paint textPaint;
if (solidBackground) {
// Text color needs to contrast with solid background.
textPaint = mSolidBackgroundEventPaint;
} else if (isDeclined) {
// Use "declined event" color.
textPaint = mDeclinedEventPaint;
} else if (allDay) {
// Text inside frame is same color as frame.
mFramedEventPaint.setColor(color);
textPaint = mFramedEventPaint;
} else {
// Use generic event text color.
textPaint = mEventPaint;
}
canvas.drawText(text.toString(), textX, textY, textPaint);
y += mEventHeight;
if (allDay) {
y += BORDER_SPACE * 2;
}
if (showTimes && !allDay) {
// show start/end time, e.g. "1pm - 2pm"
textY = y + mExtrasAscentHeight;
mStringBuilder.setLength(0);
text = DateUtils.formatDateRange(getContext(), mFormatter, event.startMillis, event.endMillis, DateUtils.FORMAT_SHOW_TIME | DateUtils.FORMAT_ABBREV_ALL, Utils.getTimeZone(getContext(), null)).toString();
text = TextUtils.ellipsize(text, mEventExtrasPaint, avail, TextUtils.TruncateAt.END);
canvas.drawText(text.toString(), textX, textY, isDeclined ? mEventDeclinedExtrasPaint : mEventExtrasPaint);
y += mExtrasHeight;
}
y += EVENT_LINE_PADDING;
return y;
}
use of android.graphics.Paint.Style in project Anki-Android by Ramblurr.
the class XYChart method drawSeries.
/**
* Draws the series.
*
* @param series the series
* @param canvas the canvas
* @param paint the paint object
* @param pointsList the points to be rendered
* @param seriesRenderer the series renderer
* @param yAxisValue the y axis value in pixels
* @param seriesIndex the series index
* @param or the orientation
* @param startIndex the start index of the rendering points
*/
protected void drawSeries(XYSeries series, Canvas canvas, Paint paint, List<Float> pointsList, SimpleSeriesRenderer seriesRenderer, float yAxisValue, int seriesIndex, Orientation or, int startIndex, int range) {
BasicStroke stroke = seriesRenderer.getStroke();
Cap cap = paint.getStrokeCap();
Join join = paint.getStrokeJoin();
float miter = paint.getStrokeMiter();
PathEffect pathEffect = paint.getPathEffect();
Style style = paint.getStyle();
if (stroke != null) {
PathEffect effect = null;
if (stroke.getIntervals() != null) {
effect = new DashPathEffect(stroke.getIntervals(), stroke.getPhase());
}
setStroke(stroke.getCap(), stroke.getJoin(), stroke.getMiter(), Style.FILL_AND_STROKE, effect, paint);
}
float[] points = MathHelper.getFloats(pointsList);
drawSeries(canvas, paint, points, seriesRenderer, yAxisValue, seriesIndex, startIndex, range);
if (isRenderPoints(seriesRenderer)) {
ScatterChart pointsChart = getPointsChart();
if (pointsChart != null) {
pointsChart.drawSeries(canvas, paint, points, seriesRenderer, yAxisValue, seriesIndex, startIndex, range);
}
}
paint.setTextSize(seriesRenderer.getChartValuesTextSize());
if (or == Orientation.HORIZONTAL) {
paint.setTextAlign(Align.CENTER);
} else {
paint.setTextAlign(Align.LEFT);
}
if (seriesRenderer.isDisplayChartValues()) {
paint.setTextAlign(seriesRenderer.getChartValuesTextAlign());
drawChartValuesText(canvas, series, seriesRenderer, paint, points, seriesIndex, startIndex);
}
if (stroke != null) {
setStroke(cap, join, miter, style, pathEffect, paint);
}
}
use of android.graphics.Paint.Style in project sensorreadout by onyxbits.
the class XYChart method drawSeries.
/**
* Draws the series.
*
* @param series the series
* @param canvas the canvas
* @param paint the paint object
* @param pointsList the points to be rendered
* @param seriesRenderer the series renderer
* @param yAxisValue the y axis value in pixels
* @param seriesIndex the series index
* @param or the orientation
* @param startIndex the start index of the rendering points
*/
protected void drawSeries(XYSeries series, Canvas canvas, Paint paint, List<Float> pointsList, XYSeriesRenderer seriesRenderer, float yAxisValue, int seriesIndex, Orientation or, int startIndex) {
BasicStroke stroke = seriesRenderer.getStroke();
Cap cap = paint.getStrokeCap();
Join join = paint.getStrokeJoin();
float miter = paint.getStrokeMiter();
PathEffect pathEffect = paint.getPathEffect();
Style style = paint.getStyle();
if (stroke != null) {
PathEffect effect = null;
if (stroke.getIntervals() != null) {
effect = new DashPathEffect(stroke.getIntervals(), stroke.getPhase());
}
setStroke(stroke.getCap(), stroke.getJoin(), stroke.getMiter(), Style.FILL_AND_STROKE, effect, paint);
}
// float[] points = MathHelper.getFloats(pointsList);
drawSeries(canvas, paint, pointsList, seriesRenderer, yAxisValue, seriesIndex, startIndex);
if (isRenderPoints(seriesRenderer)) {
ScatterChart pointsChart = getPointsChart();
if (pointsChart != null) {
pointsChart.drawSeries(canvas, paint, pointsList, seriesRenderer, yAxisValue, seriesIndex, startIndex);
}
}
paint.setTextSize(seriesRenderer.getChartValuesTextSize());
if (or == Orientation.HORIZONTAL) {
paint.setTextAlign(Align.CENTER);
} else {
paint.setTextAlign(Align.LEFT);
}
if (seriesRenderer.isDisplayChartValues()) {
paint.setTextAlign(seriesRenderer.getChartValuesTextAlign());
drawChartValuesText(canvas, series, seriesRenderer, paint, pointsList, seriesIndex, startIndex);
}
if (stroke != null) {
setStroke(cap, join, miter, style, pathEffect, paint);
}
}
use of android.graphics.Paint.Style in project Etar-Calendar by Etar-Group.
the class DayView method drawGridBackground.
private void drawGridBackground(Rect r, Canvas canvas, Paint p) {
Paint.Style savedStyle = p.getStyle();
final float stopX = computeDayLeftPosition(mNumDays);
float y = 0;
final float deltaY = mCellHeight + HOUR_GAP;
int linesIndex = 0;
final float startY = 0;
final float stopY = HOUR_GAP + 24 * (mCellHeight + HOUR_GAP);
float x = mHoursWidth;
// Draw the inner horizontal grid lines
p.setColor(mCalendarGridLineInnerHorizontalColor);
p.setStrokeWidth(GRID_LINE_INNER_WIDTH);
p.setAntiAlias(false);
y = 0;
linesIndex = 0;
for (int hour = 0; hour <= 24; hour++) {
mLines[linesIndex++] = GRID_LINE_LEFT_MARGIN;
mLines[linesIndex++] = y;
mLines[linesIndex++] = stopX;
mLines[linesIndex++] = y;
y += deltaY;
}
if (mCalendarGridLineInnerVerticalColor != mCalendarGridLineInnerHorizontalColor) {
canvas.drawLines(mLines, 0, linesIndex, p);
linesIndex = 0;
p.setColor(mCalendarGridLineInnerVerticalColor);
}
// Draw the inner vertical grid lines
for (int day = 0; day <= mNumDays; day++) {
x = computeDayLeftPosition(day);
mLines[linesIndex++] = x;
mLines[linesIndex++] = startY;
mLines[linesIndex++] = x;
mLines[linesIndex++] = stopY;
}
canvas.drawLines(mLines, 0, linesIndex, p);
// Restore the saved style.
p.setStyle(savedStyle);
p.setAntiAlias(true);
}
Aggregations