AigeStudio / DatePicker

Useful and powerful date picker for android
Apache License 2.0
1.86k stars 414 forks source link

怎么修改日历下方的节日文字呢? #37

Open huyong36 opened 8 years ago

huyong36 commented 8 years ago

我想把下面的农历日期改成我自定义的文字,能做到吗?

pateelhs commented 7 years ago

public class DPUSCalendar extends DPCalendar { private static final String[][] FESTIVAL_G = { {"New Year", "Republic Day"}, {"St.Valentine's Day"}, {}, {"All Fools' Day"}, {"May Day"}, {"Environment Day"}, {""}, {"Independence Day"}, {}, {"Gandhi Jayanthi"}, {}, {"Christmas"}};

private static final int[][] FESTIVAL_G_DATE = {
        {1,26},
        {14},
        {},
        {1},
        {1},
        {6},
        {},
        {15},
        {},
        {2},
        {},
        {25}};
private static final String[][] HOLIDAY = {{"1", "26"}, {""}, {""}, {""}, {"1"}, {""}, {""}, {"15"}, {""}, {"2"}, {""}, {"25"}};

@Override
public String[][] buildMonthFestival(int year, int month) {
    String[][] gregorianMonth = buildMonthG(year, month);
    String tmp[][] = new String[6][7];
    for (int i = 0; i < tmp.length; i++) {
        for (int j = 0; j < tmp[0].length; j++) {
            tmp[i][j] = "";
            String day = gregorianMonth[i][j];
            if (!TextUtils.isEmpty(day)) {
                tmp[i][j] = getFestivalG(month, Integer.valueOf(day));
            }
        }
    }
    return tmp;
}

@Override
public Set<String> buildMonthHoliday(int year, int month) {
    Set<String> tmp = new HashSet<>();
    if (year == 2015) {
        Collections.addAll(tmp, HOLIDAY[month - 1]);
    }
    return tmp;
}

private String getFestivalG(int month, int day) {
    String tmp = "";
    int[] daysInMonth = FESTIVAL_G_DATE[month - 1];
    for (int i = 0; i < daysInMonth.length; i++) {
        if (day == daysInMonth[i]) {
            tmp = FESTIVAL_G[month - 1][i];
        }
    }
    return tmp;
}

}

waterhxs commented 6 years ago

setDecorBG , and use canvas draw the text you want , here is the code:

List tmp = new ArrayList<>(); tmp.add("2017-11-23"); DPCManager.getInstance().setDecorBG(tmp);

    picker.setDPDecor(new DPDecor() {

        @Override
        public void drawDecorBG(Canvas canvas, Rect rect, Paint paint, String data) {

            if (data.equals("2017-11-23")){
                paint.setColor(Color.BLACK);
                paint.setTextSize(16);
                canvas.drawText("some text you want", rect.centerX(), rect.centerY() + 40, paint);
            }
        }
    });

@huyong36