Skip to content
This repository has been archived by the owner on Jul 6, 2024. It is now read-only.

Commit

Permalink
Add different shape marker to day cell.
Browse files Browse the repository at this point in the history
  • Loading branch information
naz013 committed Aug 7, 2017
1 parent 61126d3 commit 5977d5f
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

import com.github.naz013.awcalendar.AwesomeCalendarView;
import com.github.naz013.awcalendar.Event;
import com.github.naz013.awcalendar.Shape;
import com.github.naz013.awcalendar.Utils;

import java.util.ArrayList;
Expand Down Expand Up @@ -65,7 +66,7 @@ private List<Event> getEvents() {
for (int i = 0; i < 500; i++) {
int rand = r.nextInt(10);
while (rand > 0) {
events.add(new Event(-1, "" + i, Utils.toDateTime(calendar.getTimeInMillis())));
events.add(new Event(Utils.toDateTime(calendar.getTimeInMillis()), getRandomShape()));
rand--;
i++;
}
Expand All @@ -74,6 +75,17 @@ private List<Event> getEvents() {
return events;
}

private Shape getRandomShape() {
int i = new Random().nextInt(50);
if (i % 5 == 0) {
return Shape.CIRCLE;
} else if (i % 4 == 0) {
return Shape.SQUARE;
} else if (i % 3 == 0) {
return Shape.DIAMOND;
} else return Shape.TRIANGLE;
}

class SimpleAdapter extends RecyclerView.Adapter<SimpleAdapter.Holder> {

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.Rect;

import java.util.ArrayList;
Expand Down Expand Up @@ -174,15 +175,45 @@ private void drawEvents(Canvas canvas, Painter painter) {
int left = j * circleWidth + rectLeft;
Rect r = new Rect(left, top, left + circleWidth, top + circleHeight);
Paint p = painter.getEventPaint();
if (events.get(index).color != -1) {
Event event = events.get(index);
float gap = r.width() / 4f;
if (event.color != -1) {
p = painter.getEventShadowPaint();
p.setColor(events.get(index).color);
p.setColor(event.color);
}
if (event.shape == Shape.SQUARE) {
canvas.drawRect(r.left + gap, r.top + gap, r.right - gap, r.bottom - gap, p);
} else if (event.shape == Shape.DIAMOND) {
canvas.drawPath(getDiamond(r, gap), p);
} else if (event.shape == Shape.TRIANGLE) {
canvas.drawPath(getTriangle(r, gap), p);
} else {
canvas.drawCircle(r.centerX(), r.centerY(), gap, p);
}
canvas.drawCircle(r.centerX(), r.centerY(), r.width() / 4f, p);
}
}
}

private Path getTriangle(Rect r, float gap) {
Path path = new Path();
path.moveTo(r.left + (gap * 2f), r.top + (gap * 0.5f));
path.lineTo(r.right - (gap * 0.5f), r.bottom - gap);
path.lineTo(r.left + (gap * 0.5f), r.bottom - gap);
path.close();
return path;
}

private Path getDiamond(Rect r, float gap) {
Path path = new Path();
path.moveTo(r.left + (r.width() / 2), r.top + (gap * 0.5f));
path.lineTo(r.right - (gap * 0.5f), r.top + (r.height() / 2));
path.lineTo(r.right - (r.width() / 2), r.bottom - (gap * 0.5f));
path.lineTo(r.left + (gap * 0.5f), r.bottom - (r.height() / 2));
path.lineTo(r.left + (r.width() / 2), r.top + (gap * 0.5f));
path.close();
return path;
}

private void drawRectText(String text, Canvas canvas, Rect r, Painter painter) {
Paint paint = painter.getTextPaint();
if (isCurrent) paint = painter.getCurrentDayPaint();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,19 @@

/**
* MIT License
*
* <p>
* Copyright (c) 2017 Nazar Suhovich
*
* <p>
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* <p>
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* <p>
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
Expand All @@ -37,12 +37,18 @@ public class Event {
public int color = -1;
public String title = "";
public DateTime dateTime;
public Shape shape = Shape.CIRCLE;

public Event(DateTime dateTime){
public Event(DateTime dateTime) {
this.dateTime = dateTime;
}

public Event(String title, DateTime dateTime){
public Event(DateTime dateTime, Shape shape) {
this.dateTime = dateTime;
this.shape = shape;
}

public Event(String title, DateTime dateTime) {
this.title = title;
this.dateTime = dateTime;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.github.naz013.awcalendar;

/**
* MIT License
* <p>
* Copyright (c) 2017 Nazar Suhovich
* <p>
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
* <p>
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
* <p>
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

public enum Shape {
CIRCLE,
TRIANGLE,
SQUARE,
DIAMOND
}

0 comments on commit 5977d5f

Please sign in to comment.