项目作者: jessieeeee

项目描述 :
week and month calendar
高级语言: Java
项目地址: git://github.com/jessieeeee/JourneyCalendar.git
创建时间: 2017-03-15T14:43:26Z
项目社区:https://github.com/jessieeeee/JourneyCalendar

开源协议:

下载


JourneyCalendar

  • image

    support

    week and month calendar

    two modes

  1. Dynamic setting range
    Based on the current month, for example, previous three months and next six months
  2. Custom range
    such as 2019-1 to 2019-2

    Using library in your application

    Step 1. Add the JitPack repository to your build file

    Add it in your root build.gradle at the end of repositories:
    1. allprojects {
    2. repositories {
    3. ...
    4. maven { url 'https://jitpack.io' }
    5. }
    6. }
    ### Step 2. Add the dependency
    1. dependencies {
    2. implementation 'com.github.jessieeeee:JourneyCalendar:v1.0.3'
    3. }

How to Use

Configuration tool

  • DateUtil
    you should set this before container render

    1. DateUtil.setCurState(DYNAMIC); //Dynamic setting range
    2. // if you set dynamic range, you should set these
    3. setMonthRange(3,6); //previous three months,next six months
    4. DateUtil.setCurState(CUSTOM); //custom range
    5. // if you set custom range, you should set these
    6. DateUtil.setStartYear(2019);
    7. DateUtil.setEndYear(2019);
    8. DateUtil.setStartMonth(1);
    9. DateUtil.setEndMonth(2);
    10. // you can set today , but the call must be after set range (dynamic or custom)
    11. DateUtil.setCurDay(2019,1,12);

    attrs list

    1. <resources>
    2. <!-- 周日历-->
    3. <declare-styleable name="WeekCalendar">
    4. <!--日期文字大小-->
    5. <attr name="dayTextSize_week" format="dimension"></attr>
    6. <!--过去日期颜色-->
    7. <attr name="previousTextColor_week" format="color"></attr>
    8. <!--未来日期颜色-->
    9. <attr name="normalTextColor_week" format="color" ></attr>
    10. <!--星期文字大小-->
    11. <attr name="weekTextSize" format="dimension"></attr>
    12. <!--星期文字颜色-->
    13. <attr name="weekTextColor" format="color"></attr>
    14. <!--选择星期文字颜色-->
    15. <attr name="selectedTextColor_week" format="color"></attr>
    16. <!--选择背景颜色-->
    17. <attr name="selectedBgColor_week" format="color"></attr>
    18. <!-- 是否隐藏星期-->
    19. <attr name="hideWeekNum" format="boolean"></attr>
    20. <!--今日文字颜色-->
    21. <attr name="todayTextColor_week" format="color"></attr>
    22. <!--今日与选择日是否为矩形-->
    23. <attr name="isRoundRect_week" format="boolean"></attr>
    24. <!--标记文本-->
    25. <attr name="flagTextStr_week" format="string"></attr>
    26. <!--标记文本颜色-->
    27. <attr name="flagTextColor_week" format="color"></attr>
    28. <!--标记文本已过背景颜色-->
    29. <attr name="flagPreBgColor_week" format="color"></attr>
    30. <!--标记文本未来背景颜色-->
    31. <attr name="flagNormalBgColor_week" format="color"></attr>
    32. </declare-styleable>
    33. <!--月日历-->
    34. <declare-styleable name="MonthCalendarView">
    35. <!--标记文本-->
    36. <attr name="flagTextStr_month" format="string"></attr>
    37. <!--今日文字颜色-->
    38. <attr name="todayTextColor_month" format="color"></attr>
    39. <!--选择日期背景颜色-->
    40. <attr name="selectedBgColor_month" format="color"></attr>
    41. <!--选择日期文字-->
    42. <attr name="selectedTextColor_month" format="color"></attr>
    43. <!--过去日期颜色-->
    44. <attr name="previousDayTextColor_month" format="color"></attr>
    45. <!--未来日期颜色-->
    46. <attr name="normalDayTextColor_month" format="color" ></attr>
    47. <!--月份标题颜色-->
    48. <attr name="monthTitleColor" format="color" ></attr>
    49. <!--月份标题线颜色-->
    50. <attr name="monthLineColor" format="color" ></attr>
    51. <!--日期文字大小-->
    52. <attr name="dayTextSize_month" format="dimension"></attr>
    53. <!--月份标题文字大小-->
    54. <attr name="monthTitleTextSize" format="dimension" ></attr>
    55. <!--月份标题线粗细-->
    56. <attr name="monthLineTextSize" format="dimension"></attr>
    57. <!--月份标题高度-->
    58. <attr name="headerMonthHeight" format="dimension" ></attr>
    59. <!--选择日背景大小-->
    60. <attr name="selectedDayBgRadius" format="dimension" ></attr>
    61. <!--日历高度-->
    62. <attr name="calendarHeight" format="dimension" ></attr>
    63. <!--今日与选择日是否为矩形-->
    64. <attr name="isRoundRect_month" format="boolean" ></attr>
    65. <!--标记文本颜色-->
    66. <attr name="flagTextColor_month" format="color"></attr>
    67. <!--标记文本已过背景颜色-->
    68. <attr name="flagPreBgColor_month" format="color"></attr>
    69. <!--标记文本未来背景颜色-->
    70. <attr name="flagNormalBgColor_month" format="color"></attr>
    71. </declare-styleable>
    72. </resources>

    weekCalendar

  • xml

    1. <journeycalendar.jessie.com.calendarlib.journey.week.WeekCalendar
    2. android:id="@+id/weekCalendar"
    3. android:layout_width="match_parent"
    4. android:layout_height="match_parent"
    5. android:gravity="center"
    6. android:orientation="vertical"
    7. app:previousTextColor_week="@color/default_light_gray"
    8. app:normalTextColor_week="@color/default_black"
    9. app:dayTextSize_week="14sp"
    10. app:flagTextStr_week="@string/flag"
    11. app:selectedTextColor_week="@color/white"
    12. app:selectedBgColor_week="@color/default_blue"
    13. app:todayTextColor_week="@color/default_blue"
    14. app:weekTextColor="@color/default_gray"
    15. app:weekTextSize="12sp"
    16. app:isRoundRect_week="false"
    17. >
    18. </journeycalendar.jessie.com.calendarlib.journey.week.WeekCalendar>
  • java
    1. weekCalendar = WeekCalendar.newInstance(context)
    2. .setSelectedBgColor(ContextCompat.getColor(context, R.color.colorAccent))
    3. .setDayTextColorPre( Color.GRAY)
    4. .setDayTextColorNormal(ContextCompat.getColor(context, R.color.colorPrimary))
    5. .setDaysTextSize(12)
    6. .setTodayDateTextColor(Color.RED)
    7. .setSelectedTextColor(Color.WHITE)
    8. .setFlagPreBgColor(ContextCompat.getColor(context,R.color.default_black))
    9. .setFlagNormalBgColor(ContextCompat.getColor(context, R.color.default_blue))
    10. .setFlagTextColor(Color.WHITE)
    11. .setFlagTextStr("行")
    12. .setDrawRoundRect(true)
    13. .build();
  • date click
    ```java
    weekCalendar.setOnDateClickListener(new OnDateClickListener() {

    1. @Override
    2. public void onDateClick(DateTime dateTime) {
    3. clickDateTime=dateTime;
    4. journey_month.setText(dateTime.getMonthOfYear() + "");
    5. journey_data_title.setText(OtherUtils.formatDate(dateTime.toDate()));
    6. journeyListAdapter.setData(setCurJourneyList(dateTime.toDate()));//设置当天的行程数据
    7. }
    8. });
  1. - week change
  2. ```java
  3. weekCalendar.setOnWeekChangeListener(new OnWeekChangeListener() {
  4. @Override
  5. public void onWeekChange(DateTime firstDayOfTheWeek, boolean forward) {
  6. journey_month.setText(firstDayOfTheWeek.getMonthOfYear() + "");
  7. Toast.makeText(context, "Week changed: " + firstDayOfTheWeek +
  8. " Forward: " + forward, Toast.LENGTH_SHORT).show();
  9. }
  10. });
  • set today
    1. weekCalendar.reset();
  • set selected date
    1. weekCalendar.setSelectedDate(dateTime);
  • set bottom flag
    1. weekCalendar.setFlagList(dates);

monthCalendar

  • xml

    1. <journeycalendar.jessie.com.calendarlib.journey.all.MonthCalendarView
    2. android:id="@+id/pop_pickerView"
    3. android:layout_width="match_parent"
    4. android:layout_height="match_parent"
    5. android:background="@color/default_bg"
    6. app:normalDayTextColor_month="@color/default_black"
    7. app:previousDayTextColor_month="@color/default_light_gray"
    8. app:selectedBgColor_month="@color/default_blue"
    9. app:selectedTextColor_month="@color/white"
    10. app:todayTextColor_month="@color/default_blue"
    11. app:isRoundRect_month="false"
    12. app:stackFromEnd="true"
    13. app:dayTextSize_month="12sp"
    14. app:flagNormalBgColor_month="@color/default_orange"
    15. app:flagPreBgColor_month="@color/default_light_gray"
    16. app:flagTextStr_month="@string/flag"
    17. app:flagTextColor_month="@color/white"
    18. app:monthLineTextSize="12sp"
    19. app:monthTitleTextSize="10sp">
    20. </journeycalendar.jessie.com.calendarlib.journey.all.MonthCalendarView>
  • use in popwindow
    ```java

    LayoutInflater inflater = LayoutInflater.from(context);

    1. vPop = inflater.inflate(R.layout.view_popwindow_calendar_select, null);
    2. pop = new PopupWindow(vPop, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);

    // pop.setBackgroundDrawable(new ColorDrawable(0));

    1. pop.setFocusable(false);
    2. pop.setOutsideTouchable(false);
    3. dayPickerView = (DayPickerView) vPop.findViewById(R.id.pop_pickerView);
    4. dayPickerView.setController(new DatePickerController() {
    5. @Override
    6. public int getMaxYear() {
    7. return DateUtil.getEndYear();
    8. }
    9. @Override
    10. public void onDayOfMonthSelected(int year, int month, int day) {
    11. if (listener != null) {
    12. listener.onCalendarSelect(year, month, day);
    13. }
    14. if (pop != null && pop.isShowing()) {

    // pop.dismiss();

    1. }
    2. }
    3. });

```