当前位置:   article > 正文

Android 仿冰草约课 日历_安卓 日历scheme_text

安卓 日历scheme_text

上依赖:

  1. //日历
  2. implementation 'com.haibin:calendarview:3.7.1'
  3. // 时间选择wheel
  4. compile 'cn.aigestudio.wheelpicker:WheelPicker:1.1.3'
  5. //弹窗
  6. implementation 'com.github.li-xiaojun:XPopup:2.8.10'

俩个魔改的View

  1. package com.as.zqfjavasample.customrili;
  2. import android.content.Context;
  3. import android.graphics.Canvas;
  4. import android.graphics.Color;
  5. import android.graphics.Paint;
  6. import android.graphics.Rect;
  7. import com.blankj.utilcode.util.ConvertUtils;
  8. import com.haibin.calendarview.Calendar;
  9. import com.haibin.calendarview.MultiMonthView;
  10. import java.util.List;
  11. /**
  12. * 高仿魅族日历布局
  13. * Created by huanghaibin on 2017/11/15.
  14. */
  15. public class CustomMultiMonthView extends MultiMonthView {
  16. private int mRadius;
  17. /**
  18. * 今天的背景色
  19. */
  20. private Paint mCurrentDayPaint = new Paint();
  21. // 写时间文字的画笔
  22. private Paint mTimePaint = new Paint();
  23. // 写文字底部横杠的画笔
  24. private Paint mLinePaint = new Paint();
  25. private final int margin1dp;
  26. public CustomMultiMonthView(Context context) {
  27. super(context);
  28. mCurrentDayPaint.setAntiAlias(true);
  29. mCurrentDayPaint.setStyle(Paint.Style.FILL);
  30. mCurrentDayPaint.setColor(0xFFeaeaea);
  31. mTimePaint.setAntiAlias(true);
  32. mTimePaint.setStyle(Paint.Style.FILL_AND_STROKE);
  33. mTimePaint.setColor(0xFF000000);
  34. mTimePaint.setTextSize(ConvertUtils.sp2px(10));
  35. mLinePaint.setAntiAlias(true);
  36. mLinePaint.setStyle(Paint.Style.FILL_AND_STROKE);
  37. mLinePaint.setColor(0xFF000000);
  38. mLinePaint.setStrokeWidth(ConvertUtils.dp2px(1));
  39. margin1dp = ConvertUtils.dp2px(1);
  40. }
  41. @Override
  42. protected void onPreviewHook() {
  43. mRadius = Math.min(mItemWidth, mItemHeight) / 10 * 3;
  44. mSchemePaint.setStyle(Paint.Style.FILL_AND_STROKE);
  45. }
  46. @Override
  47. protected boolean onDrawSelected(Canvas canvas, Calendar calendar, int x, int y, boolean hasScheme,
  48. boolean isSelectedPre, boolean isSelectedNext) {
  49. int cx = x + mItemWidth / 2;
  50. int cy = y + mItemHeight / 2;
  51. // 改动 自己添加只要圆形选中
  52. canvas.drawCircle(cx, cy, mRadius, mSelectedPaint);
  53. int Xcx = x + mItemWidth / 2;
  54. int Xcy = cy + mRadius;
  55. if (hasScheme){
  56. List<Calendar.Scheme> schemes = calendar.getSchemes();
  57. Calendar.Scheme scheme1 = schemes.get(0);
  58. String scheme = scheme1.getScheme();
  59. float[] textBounds = getTextBounds(mTimePaint, scheme);
  60. float width = textBounds[0];
  61. float height = textBounds[1];
  62. canvas.drawText(scheme, Xcx - width / 2, Xcy + height + margin1dp * 3, mTimePaint);
  63. // 添加横杠
  64. int type = scheme1.getType();
  65. if (type==1) {
  66. mLinePaint.setColor(Color.BLACK);
  67. } else {
  68. mLinePaint.setColor(Color.WHITE);
  69. }
  70. canvas.drawLine(Xcx - width / 2, Xcy + height * 3 / 2 + margin1dp * 3, Xcx + width / 2, Xcy + height * 3 / 2 + margin1dp * 3, mLinePaint);
  71. }
  72. return false;
  73. }
  74. private static float[] getTextBounds(Paint paint, String txt) {
  75. Rect rect = new Rect();
  76. float[] floats = new float[2];
  77. paint.getTextBounds(txt, 0, txt.length(), rect);
  78. int w = rect.width();
  79. int h = rect.height();
  80. floats[0] = w;
  81. floats[1] = h;
  82. return floats;
  83. }
  84. @Override
  85. protected void onDrawScheme(Canvas canvas, Calendar calendar, int x, int y, boolean isSelected) {
  86. // int cx = x + mItemWidth / 2;
  87. // int cy = mItemHeight / 2;
  88. //
  89. // canvas.drawCircle(cx, y + cy, mRadius, mSchemePaint);
  90. }
  91. @Override
  92. protected void onDrawText(Canvas canvas, Calendar calendar, int x, int y, boolean hasScheme, boolean isSelected) {
  93. float baselineY = mTextBaseLine + y;
  94. int cx = x + mItemWidth / 2;
  95. // 改动 添加一个默认的y
  96. int cy = mItemHeight / 2;
  97. boolean isInRange = isInRange(calendar);
  98. boolean isEnable = !onCalendarIntercept(calendar);
  99. // 添加今天日期的默认 半选中效果
  100. if (calendar.isCurrentDay() && !isSelected) {
  101. canvas.drawCircle(cx, y + cy, mRadius, mCurrentDayPaint);
  102. }
  103. if (isSelected) {
  104. canvas.drawText(String.valueOf(calendar.getDay()),
  105. cx,
  106. baselineY,
  107. mSelectTextPaint);
  108. } else if (hasScheme) {
  109. canvas.drawText(String.valueOf(calendar.getDay()),
  110. cx,
  111. baselineY,
  112. calendar.isCurrentDay() ? mCurDayTextPaint :
  113. // calendar.isCurrentMonth() ? mSchemeTextPaint : mOtherMonthTextPaint);
  114. calendar.isCurrentMonth() && isInRange && isEnable ? mSchemeTextPaint : mOtherMonthTextPaint);
  115. } else {
  116. canvas.drawText(String.valueOf(calendar.getDay()), cx, baselineY,
  117. calendar.isCurrentDay() ? mCurDayTextPaint :
  118. // calendar.isCurrentMonth() ? mCurMonthTextPaint : mOtherMonthTextPaint);
  119. calendar.isCurrentMonth() && isInRange && isEnable ? mCurMonthTextPaint : mOtherMonthTextPaint);
  120. }
  121. }
  122. }
  1. package com.as.zqfjavasample.customrili;
  2. import android.content.Context;
  3. import android.graphics.Canvas;
  4. import android.graphics.Color;
  5. import android.graphics.Paint;
  6. import android.graphics.Rect;
  7. import com.blankj.utilcode.util.ConvertUtils;
  8. import com.haibin.calendarview.Calendar;
  9. import com.haibin.calendarview.MultiWeekView;
  10. import java.util.List;
  11. /**
  12. * 魅族周视图
  13. * Created by huanghaibin on 2017/11/29.
  14. */
  15. public class CustomMultiWeekView extends MultiWeekView {
  16. private int mRadius;
  17. /**
  18. * 今天的背景色
  19. */
  20. private Paint mCurrentDayPaint = new Paint();
  21. // 写时间文字的画笔
  22. private Paint mTimePaint = new Paint();
  23. // 写文字底部横杠的画笔
  24. private Paint mLinePaint = new Paint();
  25. private int margin1dp;
  26. public CustomMultiWeekView(Context context) {
  27. super(context);
  28. mCurrentDayPaint.setAntiAlias(true);
  29. mCurrentDayPaint.setStyle(Paint.Style.FILL);
  30. mCurrentDayPaint.setColor(0xFFeaeaea);
  31. mTimePaint.setAntiAlias(true);
  32. mTimePaint.setStyle(Paint.Style.FILL_AND_STROKE);
  33. mTimePaint.setColor(0xFF000000);
  34. mTimePaint.setTextSize(ConvertUtils.sp2px(10));
  35. mLinePaint.setAntiAlias(true);
  36. mLinePaint.setStyle(Paint.Style.FILL_AND_STROKE);
  37. mLinePaint.setColor(0xFF000000);
  38. mLinePaint.setStrokeWidth(ConvertUtils.dp2px(1));
  39. margin1dp = ConvertUtils.dp2px(1);
  40. }
  41. @Override
  42. protected boolean onDrawSelected(Canvas canvas, Calendar calendar, int x, boolean hasScheme, boolean isSelectedPre, boolean isSelectedNext) {
  43. int cx = x + mItemWidth / 2;
  44. int cy = 0 + mItemHeight / 2;
  45. // 改动 自己添加只要圆形选中
  46. canvas.drawCircle(cx, cy, mRadius, mSelectedPaint);
  47. int Xcx = x + mItemWidth / 2;
  48. int Xcy = cy + mRadius;
  49. List<Calendar.Scheme> schemes = calendar.getSchemes();
  50. Calendar.Scheme scheme1 = schemes.get(0);
  51. String scheme = scheme1.getScheme();
  52. float[] textBounds = getTextBounds(mTimePaint, scheme);
  53. float width = textBounds[0];
  54. float height = textBounds[1];
  55. canvas.drawText(scheme, Xcx - width / 2, Xcy + height + margin1dp * 3, mTimePaint);
  56. // 添加横杠
  57. int type = scheme1.getType();
  58. if (type==1) {
  59. mLinePaint.setColor(Color.BLACK);
  60. } else {
  61. mLinePaint.setColor(Color.WHITE);
  62. }
  63. canvas.drawLine(Xcx - width / 2, Xcy + height * 3 / 2 + margin1dp * 3, Xcx + width / 2, Xcy + height * 3 / 2 + margin1dp * 3, mLinePaint);
  64. return false;
  65. }
  66. @Override
  67. protected void onDrawScheme(Canvas canvas, Calendar calendar, int x, boolean isSelected) {
  68. // int cx = x + mItemWidth / 2;
  69. // int cy = mItemHeight / 2;
  70. // mSchemePaint.setStyle(Paint.Style.FILL_AND_STROKE);
  71. // canvas.drawCircle(cx, cy, mRadius, mSchemePaint);
  72. }
  73. private static float[] getTextBounds(Paint paint, String txt) {
  74. Rect rect = new Rect();
  75. float[] floats = new float[2];
  76. paint.getTextBounds(txt, 0, txt.length(), rect);
  77. int w = rect.width();
  78. int h = rect.height();
  79. floats[0] = w;
  80. floats[1] = h;
  81. return floats;
  82. }
  83. @Override
  84. protected void onPreviewHook() {
  85. mRadius = Math.min(mItemWidth, mItemHeight) / 10 * 3;
  86. mSchemePaint.setStyle(Paint.Style.STROKE);
  87. }
  88. @Override
  89. protected void onDrawText(Canvas canvas, Calendar calendar, int x, boolean hasScheme, boolean isSelected) {
  90. float baselineY = mTextBaseLine + 0;
  91. int cx = x + mItemWidth / 2;
  92. // 改动 添加一个默认的y
  93. int cy = mItemHeight / 2;
  94. boolean isInRange = isInRange(calendar);
  95. boolean isEnable = !onCalendarIntercept(calendar);
  96. // 添加今天日期的默认 半选中效果
  97. if (calendar.isCurrentDay() && !isSelected) {
  98. canvas.drawCircle(cx, 0 + cy, mRadius, mCurrentDayPaint);
  99. }
  100. if (isSelected) {
  101. canvas.drawText(String.valueOf(calendar.getDay()),
  102. cx,
  103. baselineY,
  104. mSelectTextPaint);
  105. } else if (hasScheme) {
  106. canvas.drawText(String.valueOf(calendar.getDay()),
  107. cx,
  108. baselineY,
  109. calendar.isCurrentDay() ? mCurDayTextPaint :
  110. // calendar.isCurrentMonth() ? mSchemeTextPaint : mOtherMonthTextPaint);
  111. calendar.isCurrentMonth() && isInRange && isEnable ? mSchemeTextPaint : mOtherMonthTextPaint);
  112. } else {
  113. canvas.drawText(String.valueOf(calendar.getDay()), cx, baselineY,
  114. calendar.isCurrentDay() ? mCurDayTextPaint :
  115. // calendar.isCurrentMonth() ? mCurMonthTextPaint : mOtherMonthTextPaint);
  116. calendar.isCurrentMonth() && isInRange && isEnable ? mCurMonthTextPaint : mOtherMonthTextPaint);
  117. }
  118. }
  119. }

XML

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <layout xmlns:android="http://schemas.android.com/apk/res/android"
  3. xmlns:app="http://schemas.android.com/apk/res-auto">
  4. <LinearLayout
  5. android:layout_width="match_parent"
  6. android:layout_height="wrap_content"
  7. android:background="@color/white"
  8. android:orientation="vertical">
  9. <RelativeLayout
  10. android:layout_width="match_parent"
  11. android:layout_height="wrap_content">
  12. <TextView
  13. android:id="@+id/tvCancel"
  14. android:layout_width="wrap_content"
  15. android:layout_height="wrap_content"
  16. android:layout_marginLeft="@dimen/dp10"
  17. android:layout_marginTop="@dimen/dp10"
  18. android:layout_marginBottom="@dimen/dp10"
  19. android:text="取消"
  20. android:textColor="@color/black"
  21. android:textSize="18sp" />
  22. <TextView
  23. android:id="@+id/tvSure"
  24. android:layout_width="wrap_content"
  25. android:layout_height="wrap_content"
  26. android:layout_alignParentRight="true"
  27. android:layout_marginTop="@dimen/dp10"
  28. android:layout_marginRight="@dimen/dp10"
  29. android:layout_marginBottom="@dimen/dp10"
  30. android:text="确定"
  31. android:textColor="@color/green"
  32. android:textSize="18sp" />
  33. </RelativeLayout>
  34. <View
  35. android:background="@color/darkgrey"
  36. android:layout_marginBottom="@dimen/dp10"
  37. android:layout_width="match_parent"
  38. android:layout_height="@dimen/dp1" />
  39. <RelativeLayout
  40. android:layout_width="match_parent"
  41. android:layout_height="wrap_content">
  42. <TextView
  43. android:layout_width="wrap_content"
  44. android:layout_height="wrap_content"
  45. android:layout_alignParentLeft="true"
  46. android:layout_marginLeft="@dimen/dp10"
  47. android:text="选择时间" />
  48. <TextView
  49. android:id="@+id/currentTime"
  50. android:layout_width="wrap_content"
  51. android:layout_height="wrap_content"
  52. android:layout_alignParentRight="true"
  53. android:layout_marginRight="@dimen/dp10"
  54. android:text="2022年06月"
  55. android:textColor="@color/black" />
  56. </RelativeLayout>
  57. <com.haibin.calendarview.CalendarView
  58. android:id="@+id/calendarView"
  59. android:layout_width="match_parent"
  60. android:layout_height="wrap_content"
  61. android:background="@color/white"
  62. app:calendar_height="@dimen/dp62"
  63. app:current_month_lunar_text_color="#CFCFCF"
  64. app:current_month_text_color="#333333"
  65. app:max_multi_select_size="20"
  66. app:month_view="com.as.zqfjavasample.customrili.CustomMultiMonthView"
  67. app:month_view_show_mode="mode_all"
  68. app:other_month_lunar_text_color="#e1e1e1"
  69. app:other_month_text_color="#e1e1e1"
  70. app:scheme_text="假"
  71. app:scheme_text_color="#333"
  72. app:scheme_theme_color="#128c4b"
  73. app:select_mode="multi_mode"
  74. app:selected_lunar_text_color="#CFCFCF"
  75. app:selected_text_color="#ffffff"
  76. app:selected_theme_color="#f17706"
  77. app:week_background="#fff"
  78. app:week_start_with="sun"
  79. app:week_text_color="#111111"
  80. app:week_view="com.as.zqfjavasample.customrili.CustomMultiWeekView"
  81. app:week_view_scrollable="true"
  82. app:year_view_day_text_color="#333333"
  83. app:year_view_day_text_size="9sp"
  84. app:year_view_month_text_color="#ff0000"
  85. app:year_view_month_text_size="18sp"
  86. app:year_view_scheme_color="#f17706"
  87. />
  88. <ImageView
  89. android:id="@+id/ivExpand"
  90. android:layout_width="@dimen/dp20"
  91. android:layout_height="@dimen/dp20"
  92. android:layout_gravity="center_horizontal"
  93. android:src="@drawable/icshang" />
  94. <LinearLayout
  95. android:layout_width="match_parent"
  96. android:layout_height="@dimen/dp160"
  97. android:orientation="horizontal">
  98. <com.aigestudio.wheelpicker.WheelPicker
  99. android:id="@+id/wheelViewHour"
  100. android:layout_width="0dp"
  101. android:layout_height="match_parent"
  102. android:layout_weight="1"
  103. app:wheel_atmospheric="true"
  104. app:wheel_indicator="true"
  105. app:wheel_indicator_color="@color/darkgrey"
  106. app:wheel_indicator_size="@dimen/dp1"
  107. app:wheel_item_text_color="@color/darkgrey"
  108. app:wheel_item_text_size="18sp"
  109. app:wheel_selected_item_text_color="@color/black"
  110. app:wheel_visible_item_count="5" />
  111. <com.aigestudio.wheelpicker.WheelPicker
  112. android:id="@+id/wheelViewMinute"
  113. android:layout_width="0dp"
  114. android:layout_height="match_parent"
  115. android:layout_weight="1"
  116. app:wheel_atmospheric="true"
  117. app:wheel_indicator="true"
  118. app:wheel_indicator_color="@color/darkgrey"
  119. app:wheel_indicator_size="@dimen/dp1"
  120. app:wheel_item_text_color="@color/darkgrey"
  121. app:wheel_item_text_size="18sp"
  122. app:wheel_selected_item_text_color="@color/black"
  123. app:wheel_visible_item_count="5" />
  124. </LinearLayout>
  125. </LinearLayout>
  126. </layout>

主要的代码

  1. package com.as.zqfjavasample.myclass.detail.guanli;
  2. import android.os.Bundle;
  3. import android.view.View;
  4. import androidx.databinding.DataBindingUtil;
  5. import com.aigestudio.wheelpicker.WheelPicker;
  6. import com.as.zqfjavasample.Const;
  7. import com.as.zqfjavasample.R;
  8. import com.as.zqfjavasample.base.base_ui.activity.BaseActivity;
  9. import com.as.zqfjavasample.base.http.BeanCallback_NoDialog;
  10. import com.as.zqfjavasample.databinding.ActivityAddClassTimeBinding;
  11. import com.as.zqfjavasample.databinding.PopRiliBinding;
  12. import com.blankj.utilcode.util.JsonUtils;
  13. import com.blankj.utilcode.util.ScreenUtils;
  14. import com.blankj.utilcode.util.TimeUtils;
  15. import com.blankj.utilcode.util.ToastUtils;
  16. import com.haibin.calendarview.Calendar;
  17. import com.haibin.calendarview.CalendarView;
  18. import com.lxj.xpopup.XPopup;
  19. import com.lxj.xpopup.core.BasePopupView;
  20. import com.lxj.xpopup.core.BottomPopupView;
  21. import com.lxj.xpopup.enums.PopupAnimation;
  22. import com.lzy.okgo.OkGo;
  23. import org.json.JSONObject;
  24. import java.text.ParseException;
  25. import java.text.SimpleDateFormat;
  26. import java.util.ArrayList;
  27. import java.util.Date;
  28. import java.util.HashMap;
  29. import java.util.List;
  30. import java.util.Map;
  31. import okhttp3.Response;
  32. public class AddClassTimeActivity extends BaseActivity<ActivityAddClassTimeBinding> {
  33. // 设置小时选择
  34. int defaultHour = 0;
  35. // 设置分钟选择
  36. int defaultMinute = 0;
  37. // 默认的年月日
  38. private Calendar lastCalendar;
  39. private Map<String, Calendar> map;
  40. @Override
  41. protected int getLayoutId() {
  42. return R.layout.activity_add_class_time;
  43. }
  44. @Override
  45. protected void getBundleExtras(Bundle extras) {
  46. }
  47. @Override
  48. protected void initView() {
  49. }
  50. @Override
  51. protected void initData() {
  52. }
  53. @Override
  54. protected void initListener() {
  55. BasePopupView popupView = new XPopup.Builder(mContext)
  56. .popupAnimation(PopupAnimation.TranslateFromBottom) //设置动画
  57. .dismissOnTouchOutside(false) // 点击外面不消失
  58. // .dismissOnBackPressed(false) //不管用
  59. .hasShadowBg(true)
  60. // .enableDrag(false)
  61. .asCustom(new BottomPopupView(mContext) {
  62. // 返回自定义弹窗的布局
  63. @Override
  64. protected int getImplLayoutId() {
  65. return R.layout.pop_rili;
  66. }
  67. @Override
  68. protected void onCreate() {
  69. super.onCreate();
  70. PopRiliBinding mViewBinding = DataBindingUtil.bind(getPopupImplView());
  71. int year = mViewBinding.calendarView.getCurYear();
  72. int month = mViewBinding.calendarView.getCurMonth();
  73. int day = mViewBinding.calendarView.getCurDay();
  74. mViewBinding.calendarView.setRange(
  75. year,
  76. month,
  77. day,
  78. year + 1, 12, 24);
  79. mViewBinding.currentTime.setText(year + "年" + month + "月");
  80. map = new HashMap<>();
  81. // 设置默认选中的日期
  82. Calendar calendar1 = new Calendar();
  83. calendar1.setYear(year);
  84. calendar1.setMonth(month);
  85. calendar1.setDay(14);
  86. Calendar calendar2 = new Calendar();
  87. calendar2.setYear(year);
  88. calendar2.setMonth(month);
  89. calendar2.setDay(18);
  90. // 这里为了获取时间
  91. map.put(getSchemeCalendar(calendar1.getYear(), calendar1.getMonth(), calendar1.getDay(), 0xDDDD, "11:00", 0).toString(),
  92. getSchemeCalendar(calendar1.getYear(), calendar1.getMonth(), calendar1.getDay(), 0xDDDD, "11:00", 0));
  93. map.put(getSchemeCalendar(calendar2.getYear(), calendar2.getMonth(), calendar2.getDay(), 0xDDDD, "11:00", 1).toString(),
  94. getSchemeCalendar(calendar2.getYear(), calendar2.getMonth(), calendar2.getDay(), 0xDDDD, "11:00", 1));
  95. lastCalendar = calendar2;
  96. mViewBinding.calendarView.setSchemeDate(map);
  97. mViewBinding.calendarView.setMaxMultiSelectSize(20);
  98. mViewBinding.calendarView.putMultiSelect(calendar1, calendar2);
  99. mViewBinding.calendarView.setOnCalendarMultiSelectListener(new CalendarView.OnCalendarMultiSelectListener() {
  100. @Override
  101. public void onCalendarMultiSelectOutOfRange(Calendar calendar) {
  102. }
  103. @Override
  104. public void onMultiSelectOutOfSize(Calendar calendar, int maxSize) {
  105. ToastUtils.showShort("超过最大选择数量");
  106. }
  107. @Override
  108. public void onCalendarMultiSelect(Calendar calendar, int curSize, int maxSize) {
  109. // if (calendar == lastCalendar) {
  110. //
  111. // }
  112. int mSelectYear = calendar.getYear();
  113. int mSelectMonth = calendar.getMonth();
  114. int mSelectday = calendar.getDay();
  115. mViewBinding.currentTime.setText(mSelectYear + "年" + mSelectMonth + "月");
  116. List<Calendar> multiSelectCalendars = mViewBinding.calendarView.getMultiSelectCalendars();
  117. if (multiSelectCalendars.contains(calendar)) {
  118. String strHour = getTrueForm(defaultHour);
  119. String strMinute = getTrueForm(defaultMinute);
  120. // 把上一次的横杠去掉 Type改为0
  121. map.put(getSchemeCalendar(lastCalendar.getYear(), lastCalendar.getMonth(), lastCalendar.getDay(), 0xDDDD, strHour + ":" + strMinute, 0).toString(),
  122. getSchemeCalendar(lastCalendar.getYear(), lastCalendar.getMonth(), lastCalendar.getDay(), 0xDDDD, strHour + ":" + strMinute, 0));
  123. // 选择
  124. map.put(getSchemeCalendar(mSelectYear, mSelectMonth, mSelectday, 0xDDDD, strHour + ":" + strMinute, 1).toString(),
  125. getSchemeCalendar(mSelectYear, mSelectMonth, mSelectday, 0xDDDD, strHour + ":" + strMinute, 1));
  126. mViewBinding.calendarView.setSchemeDate(map);
  127. lastCalendar = calendar;
  128. }
  129. }
  130. });
  131. // 设置时间选择器的 小时 分钟
  132. List<String> dataHours = new ArrayList<>();
  133. List<Integer> dataHoursInt = new ArrayList<>();
  134. for (int i = 0; i < 24; i++) {
  135. dataHoursInt.add(i);
  136. dataHours.add(i + "时");
  137. }
  138. List<String> dataMinutes = new ArrayList<>();
  139. List<Integer> dataMinutesInt = new ArrayList<>();
  140. for (int i = 0; i < 12; i++) {
  141. dataMinutesInt.add(i * 5);
  142. dataMinutes.add(i * 5 + "分");
  143. }
  144. mViewBinding.wheelViewHour.setData(dataHours);
  145. mViewBinding.wheelViewMinute.setData(dataMinutes);
  146. mViewBinding.wheelViewHour.setSelectedItemPosition(4, false);
  147. defaultHour = dataHoursInt.get(4);
  148. mViewBinding.wheelViewHour.setOnItemSelectedListener(new WheelPicker.OnItemSelectedListener() {
  149. @Override
  150. public void onItemSelected(WheelPicker picker, Object data, int position) {
  151. defaultHour = dataHoursInt.get(position);
  152. String strHour = getTrueForm(defaultHour);
  153. String strMinute = getTrueForm(defaultMinute);
  154. map.put(getSchemeCalendar(lastCalendar.getYear(), lastCalendar.getMonth(), lastCalendar.getDay(), 0xDDDD, strHour + ":" + strMinute, 1).toString(),
  155. getSchemeCalendar(lastCalendar.getYear(), lastCalendar.getMonth(), lastCalendar.getDay(), 0xDDDD, strHour + ":" + strMinute, 1));
  156. mViewBinding.calendarView.setSchemeDate(map);
  157. }
  158. });
  159. mViewBinding.wheelViewMinute.setOnItemSelectedListener(new WheelPicker.OnItemSelectedListener() {
  160. @Override
  161. public void onItemSelected(WheelPicker picker, Object data, int position) {
  162. defaultMinute = dataMinutesInt.get(position);
  163. String strHour = getTrueForm(defaultHour);
  164. String strMinute = getTrueForm(defaultMinute);
  165. map.put(getSchemeCalendar(lastCalendar.getYear(), lastCalendar.getMonth(), lastCalendar.getDay(), 0xDDDD, strHour + ":" + strMinute, 1).toString(),
  166. getSchemeCalendar(lastCalendar.getYear(), lastCalendar.getMonth(), lastCalendar.getDay(), 0xDDDD, strHour + ":" + strMinute, 1));
  167. mViewBinding.calendarView.setSchemeDate(map);
  168. }
  169. });
  170. mViewBinding.ivExpand.setOnClickListener(new OnClickListener() {
  171. @Override
  172. public void onClick(View v) {
  173. if (mViewBinding.calendarView.getWeekViewPager().getVisibility() == View.GONE) {
  174. mViewBinding.calendarView.getMonthViewPager().setVisibility(View.GONE);
  175. mViewBinding.calendarView.getWeekViewPager().setVisibility(View.VISIBLE);
  176. v.animate()
  177. .setDuration(100)
  178. .rotationX(180)
  179. .start();
  180. } else {
  181. mViewBinding.calendarView.getMonthViewPager().setVisibility(View.VISIBLE);
  182. mViewBinding.calendarView.getWeekViewPager().setVisibility(View.GONE);
  183. v.animate()
  184. .setDuration(100)
  185. .rotationX(360)
  186. .start();
  187. }
  188. }
  189. });
  190. mViewBinding.tvCancel.setOnClickListener(new OnClickListener() {
  191. @Override
  192. public void onClick(View v) {
  193. dismiss();
  194. }
  195. });
  196. mViewBinding.tvSure.setOnClickListener(new OnClickListener() {
  197. @Override
  198. public void onClick(View v) {
  199. List<Long> list = new ArrayList<>();
  200. if (map == null) {
  201. return;
  202. }
  203. for (String key : map.keySet()) {
  204. Calendar calendar = map.get(key);
  205. Calendar.Scheme scheme = calendar.getSchemes().get(0);
  206. String scheme1 = scheme.getScheme();
  207. String[] split = scheme1.split(":");
  208. SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm");
  209. Date date = null;
  210. try {
  211. date = simpleDateFormat.parse(calendar.getYear() + "-" + calendar.getMonth() + "-" + calendar.getDay() + " " + split[0] + ":" + split[1]);
  212. long l = TimeUtils.date2Millis(date) / 1000;
  213. list.add(l);
  214. } catch (ParseException e) {
  215. e.printStackTrace();
  216. }
  217. }
  218. String s = JsonUtils.formatJson(list.toString());
  219. OkGo.<Object>post(Const.AddClassTimes)
  220. .params("class_id", 1)
  221. .params("times", s)
  222. .execute(new BeanCallback_NoDialog<Object>() {
  223. @Override
  224. public Object convertResponse(Response response) throws Throwable {
  225. String string = response.body().string();
  226. JSONObject jsonObject = new JSONObject(string);
  227. int code = jsonObject.getInt("code");
  228. String message = jsonObject.getString("message");
  229. ToastUtils.showShort(message + "");
  230. System.out.println("string : " + string);
  231. return super.convertResponse(response);
  232. }
  233. });
  234. for (int i = 0; i < list.size(); i++) {
  235. System.out.println("数据 :" + list.get(i));
  236. }
  237. }
  238. });
  239. }
  240. @Override
  241. protected boolean onBackPressed() {
  242. dismiss();
  243. return true;
  244. }
  245. @Override
  246. protected int getPopupWidth() {
  247. return ScreenUtils.getScreenWidth();
  248. }
  249. });
  250. mViewBinding.llStart.setOnClickListener(new View.OnClickListener() {
  251. @Override
  252. public void onClick(View v) {
  253. popupView.show();
  254. }
  255. });
  256. }
  257. private String getTrueForm(int time) {
  258. if (time < 10) {
  259. return 0 + "" + time;
  260. } else {
  261. return time + "";
  262. }
  263. }
  264. //hasLine : 0 代表乜有 1代表有
  265. private Calendar getSchemeCalendar(int year, int month, int day, int color, String text, int type) {
  266. Calendar calendar = new Calendar();
  267. calendar.setYear(year);
  268. calendar.setMonth(month);
  269. calendar.setDay(day);
  270. calendar.setSchemeColor(color);//如果单独标记颜色、则会使用这个颜色
  271. List<Calendar.Scheme> list = new ArrayList<>();
  272. list.add(new Calendar.Scheme(type, color, text));
  273. calendar.setSchemes(list);
  274. return calendar;
  275. }
  276. }



魔改2.

 

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <layout xmlns:android="http://schemas.android.com/apk/res/android"
  3. xmlns:app="http://schemas.android.com/apk/res-auto"
  4. xmlns:tools="http://schemas.android.com/tools"
  5. tools:context=".myclass.detail.yuyue.YuyueActivity">
  6. <LinearLayout
  7. android:layout_width="match_parent"
  8. android:layout_height="match_parent"
  9. android:orientation="vertical">
  10. <RelativeLayout
  11. android:layout_width="match_parent"
  12. android:layout_height="wrap_content">
  13. <ImageView
  14. android:layout_width="@dimen/dp40"
  15. android:layout_height="@dimen/dp40"
  16. android:layout_centerVertical="true"
  17. android:padding="@dimen/dp10"
  18. android:src="@drawable/toleftblack" />
  19. <TextView
  20. android:layout_width="wrap_content"
  21. android:layout_height="wrap_content"
  22. android:layout_centerInParent="true"
  23. android:layout_marginTop="@dimen/dp10"
  24. android:layout_marginBottom="@dimen/dp10"
  25. android:text="课程预约"
  26. android:textColor="@color/black"
  27. android:textSize="18sp" />
  28. </RelativeLayout>
  29. <TextView
  30. android:id="@+id/tvCurrentTime"
  31. android:layout_width="wrap_content"
  32. android:layout_height="wrap_content"
  33. android:text="2022年7月"
  34. android:textColor="@color/black" />
  35. <com.haibin.calendarview.CalendarView
  36. android:id="@+id/calendarView"
  37. android:layout_width="match_parent"
  38. android:layout_height="wrap_content"
  39. android:background="@color/white"
  40. app:calendar_height="@dimen/dp62"
  41. app:current_month_lunar_text_color="#CFCFCF"
  42. app:current_month_text_color="#333333"
  43. app:max_multi_select_size="20"
  44. app:month_view="com.as.zqfjavasample.customrili.SimpleMonthView"
  45. app:month_view_show_mode="mode_all"
  46. app:other_month_lunar_text_color="#e1e1e1"
  47. app:other_month_text_color="#e1e1e1"
  48. app:scheme_text="假"
  49. app:scheme_text_color="#333"
  50. app:scheme_theme_color="#CFCFCF"
  51. app:select_mode="single_mode"
  52. app:selected_lunar_text_color="#CFCFCF"
  53. app:selected_text_color="#ffffff"
  54. app:selected_theme_color="#f17706"
  55. app:week_background="#fff"
  56. app:week_start_with="sun"
  57. app:week_text_color="#111111"
  58. app:week_view="com.as.zqfjavasample.customrili.SimpleWeekView"
  59. app:week_view_scrollable="true"
  60. app:year_view_day_text_color="#333333"
  61. app:year_view_day_text_size="9sp"
  62. app:year_view_month_text_color="#ff0000"
  63. app:year_view_month_text_size="18sp"
  64. app:year_view_scheme_color="#f17706"
  65. />
  66. <ImageView
  67. android:id="@+id/ivExpand"
  68. android:layout_width="@dimen/dp20"
  69. android:layout_height="@dimen/dp20"
  70. android:layout_gravity="center_horizontal"
  71. android:src="@drawable/icshang" />
  72. </LinearLayout>
  73. </layout>
  1. package com.as.zqfjavasample.myclass.detail.yuyue;
  2. import android.os.Build;
  3. import android.os.Bundle;
  4. import android.view.View;
  5. import androidx.annotation.RequiresApi;
  6. import com.as.zqfjavasample.R;
  7. import com.as.zqfjavasample.base.base_ui.activity.BaseActivity;
  8. import com.as.zqfjavasample.databinding.ActivityYuyueBinding;
  9. import com.haibin.calendarview.Calendar;
  10. import java.time.LocalDateTime;
  11. import java.util.HashMap;
  12. import java.util.Map;
  13. public class YuyueActivity extends BaseActivity<ActivityYuyueBinding> {
  14. @Override
  15. protected int getLayoutId() {
  16. return R.layout.activity_yuyue;
  17. }
  18. @Override
  19. protected void getBundleExtras(Bundle extras) {
  20. }
  21. @RequiresApi(api = Build.VERSION_CODES.O)
  22. @Override
  23. protected void initView() {
  24. int curYear = mViewBinding.calendarView.getCurYear();
  25. int curMonth = mViewBinding.calendarView.getCurMonth();
  26. int curDay = mViewBinding.calendarView.getCurDay();
  27. Map<String, Calendar> map = new HashMap<>();
  28. for (int i = 1; i < 31; i++) {
  29. LocalDateTime time=LocalDateTime. now();
  30. LocalDateTime time2= time.minusDays(i);
  31. // java.util.Calendar instance = java.util.Calendar.getInstance();
  32. // instance.setTime(new Date());
  33. // instance.add(java.util.Calendar.DATE,-i);
  34. // int year = instance.get(java.util.Calendar.YEAR);
  35. // int month = instance.get(java.util.Calendar.MONTH+1);
  36. // int day = instance.get(java.util.Calendar.DATE+1);
  37. // Date time1 = instance.getTime();
  38. // System.out.println("time1.getYear() :"+time1.getYear());
  39. // System.out.println("time1.getMonth() :"+time1.getMonth());
  40. // System.out.println("time1.getDay() :"+time1.getDay());
  41. Calendar calendar1 = new Calendar();
  42. calendar1.setYear(time2.getYear());
  43. calendar1.setMonth(time2.getMonthValue());
  44. calendar1.setDay(time2.getDayOfMonth());
  45. map.put(getSchemeCalendar(calendar1.getYear(), calendar1.getMonth(), calendar1.getDay(), 0XffCFCFCF, "11:00").toString(),
  46. getSchemeCalendar(calendar1.getYear(), calendar1.getMonth(), calendar1.getDay(), 0XffCFCFCF, "11:00"));
  47. }
  48. mViewBinding.calendarView.setSchemeDate(map);
  49. mViewBinding.calendarView.setRange(
  50. curYear,
  51. curMonth-1,
  52. curDay,
  53. curYear + 1, curMonth, curDay);
  54. mViewBinding.calendarView.clearSingleSelect();
  55. mViewBinding.calendarView.scrollToCurrent();
  56. mViewBinding.tvCurrentTime.setText(curYear + "年" + curMonth + "月");
  57. }
  58. //hasLine : 0 代表乜有 1代表有
  59. private Calendar getSchemeCalendar(int year, int month, int day, int color, String text) {
  60. Calendar calendar = new Calendar();
  61. calendar.setYear(year);
  62. calendar.setMonth(month);
  63. calendar.setDay(day);
  64. calendar.setSchemeColor(color);//如果单独标记颜色、则会使用这个颜色
  65. calendar.setScheme(text);
  66. return calendar;
  67. }
  68. @Override
  69. protected void initData() {
  70. }
  71. @Override
  72. protected void initListener() {
  73. mViewBinding.ivExpand.setOnClickListener(new View.OnClickListener() {
  74. @Override
  75. public void onClick(View v) {
  76. if (mViewBinding.calendarView.getWeekViewPager().getVisibility() == View.GONE) {
  77. mViewBinding.calendarView.getMonthViewPager().setVisibility(View.GONE);
  78. mViewBinding.calendarView.getWeekViewPager().setVisibility(View.VISIBLE);
  79. v.animate()
  80. .setDuration(100)
  81. .rotationX(180)
  82. .start();
  83. } else {
  84. mViewBinding.calendarView.getMonthViewPager().setVisibility(View.VISIBLE);
  85. mViewBinding.calendarView.getWeekViewPager().setVisibility(View.GONE);
  86. v.animate()
  87. .setDuration(100)
  88. .rotationX(360)
  89. .start();
  90. }
  91. }
  92. });
  93. }
  94. }

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小蓝xlanll/article/detail/543225
推荐阅读
相关标签
  

闽ICP备14008679号