如何随日期更改压光机装饰颜色

时间:2019-03-03 15:14:17

标签: android json events calendar

自上周以来,我一直在尝试这样做,但是它在所有日期上都显示相同的颜色。

private void makeJsonObjectRequest() {


    SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss", Locale.getDefault());

    // i copied your json to load form assets folder
    // in our case you can get the json from the server
    // or any other location of your choice
    String response = loadJSONFromAsset();
    try {
        JSONArray jArray = new JSONArray(response);
        for (int i = 0; i < jArray.length(); i++) {
            JSONObject jsonObject = jArray.getJSONObject(i);
            String StartDate = jsonObject.getString("StartDate");
            Date date = simpleDateFormat.parse(StartDate);

            Log.d("Date ",""+date);
            CalendarDay day = CalendarDay.from(date);
            events.add(day);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }

    EventDecorator eventDecorator = new EventDecorator(Color.RED, events);
    calendarView.addDecorator(eventDecorator);

}

然后是装饰器

public class EventDecorator implements DayViewDecorator {

    private int color;
    private HashSet<CalendarDay> dates;

    public EventDecorator(int color, Collection<CalendarDay> dates) {
        this.color = color;
        this.dates = new HashSet<>(dates);
    }

    @Override
    public boolean shouldDecorate(CalendarDay day) {
        return dates.contains(day);
    }

    @Override
    public void decorate(DayViewFacade view) {
        view.addSpan(new DotSpan(5, color));
    }
}

0 个答案:

没有答案