CalendarVisualizer.java 文件源码

java
阅读 47 收藏 0 点赞 0 评论 0

项目:meeting-room-tablet 作者:
private void drawCalendarReservations(Canvas c, RectF area) {
    c.save();
    c.clipRect(area.left + getScrollX(), area.top, area.right + getScrollX(), area.bottom);
    c.translate(area.left, area.top);
    int height = (int) area.height();
    if (reservations.length > 0) {
        float[] points = new float[reservations.length * 8];
        short[] indices = new short[reservations.length * 6];
        for (int i = 0; i < reservations.length; i++) {
            int j = 8 * i;
            //order of points is top-left, top-right, bottom-left, bottom-right
            points[j] = getXForTime(reservations[i].getStartTime());
            points[j + 1] = getProportionalY(reservations[i].getStartTime()) * height;
            points[j + 2] = getXForTime(reservations[i].getStartTime()) + dayWidth;
            points[j + 3] = points[j + 1];
            points[j + 4] = points[j];
            points[j + 5] = getProportionalEndY(reservations[i].getEndTime()) * height;
            points[j + 6] = points[j + 2];
            points[j + 7] = points[j + 5];
            j += 8;
            //top-left * 2, top-right, bottom-left, bottom-right * 2
            // *2 makes reservation connecting triangles zero area
            int p = 6 * i;
            short vi = (short) (4 * i); //each reservation needs 4 vertices
            indices[p] = vi;
            indices[p + 1] = vi;
            indices[p + 2] = (short) (vi + 1);
            indices[p + 3] = (short) (vi + 2);
            indices[p + 4] = (short) (vi + 3);
            indices[p + 5] = (short) (vi + 3);
        }
        c.drawVertices(VertexMode.TRIANGLE_STRIP, points.length, points, 0,
                points, 0, null, 0, indices, 0, indices.length, markerPaint);

        Paint linePaint = new Paint();
        // linePaint.setARGB(200, 255, 255, 255);
        linePaint.setColor(Color.WHITE);

        // Draw the separator line only if the next reservation is following this one immediately.
        for (int i = 0; i < reservations.length; i++) {
            if ((i + 1) < reservations.length &&
                    reservations[i].getEndTime().getTimeInMillis() == reservations[i + 1].getStartTime().getTimeInMillis()) {
                c.drawLine(getXForTime(reservations[i].getStartTime()),
                        getProportionalEndY(reservations[i].getEndTime()) * height,
                        getXForTime(reservations[i].getStartTime()) + dayWidth,
                        getProportionalEndY(reservations[i].getEndTime()) * height,
                        linePaint);
            }
        }

    }
    c.restore();
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号