赞
踩
上依赖:
- //日历
- implementation 'com.haibin:calendarview:3.7.1'
- // 时间选择wheel
- compile 'cn.aigestudio.wheelpicker:WheelPicker:1.1.3'
-
- //弹窗
- implementation 'com.github.li-xiaojun:XPopup:2.8.10'
俩个魔改的View
- package com.as.zqfjavasample.customrili;
-
- import android.content.Context;
- import android.graphics.Canvas;
- import android.graphics.Color;
- import android.graphics.Paint;
- import android.graphics.Rect;
-
- import com.blankj.utilcode.util.ConvertUtils;
- import com.haibin.calendarview.Calendar;
- import com.haibin.calendarview.MultiMonthView;
-
- import java.util.List;
-
- /**
- * 高仿魅族日历布局
- * Created by huanghaibin on 2017/11/15.
- */
- public class CustomMultiMonthView extends MultiMonthView {
-
- private int mRadius;
-
- /**
- * 今天的背景色
- */
- private Paint mCurrentDayPaint = new Paint();
- // 写时间文字的画笔
- private Paint mTimePaint = new Paint();
- // 写文字底部横杠的画笔
- private Paint mLinePaint = new Paint();
- private final int margin1dp;
-
- public CustomMultiMonthView(Context context) {
- super(context);
-
- mCurrentDayPaint.setAntiAlias(true);
- mCurrentDayPaint.setStyle(Paint.Style.FILL);
- mCurrentDayPaint.setColor(0xFFeaeaea);
-
- mTimePaint.setAntiAlias(true);
- mTimePaint.setStyle(Paint.Style.FILL_AND_STROKE);
- mTimePaint.setColor(0xFF000000);
- mTimePaint.setTextSize(ConvertUtils.sp2px(10));
-
-
- mLinePaint.setAntiAlias(true);
- mLinePaint.setStyle(Paint.Style.FILL_AND_STROKE);
- mLinePaint.setColor(0xFF000000);
- mLinePaint.setStrokeWidth(ConvertUtils.dp2px(1));
-
- margin1dp = ConvertUtils.dp2px(1);
-
- }
-
-
- @Override
- protected void onPreviewHook() {
- mRadius = Math.min(mItemWidth, mItemHeight) / 10 * 3;
- mSchemePaint.setStyle(Paint.Style.FILL_AND_STROKE);
- }
-
- @Override
- protected boolean onDrawSelected(Canvas canvas, Calendar calendar, int x, int y, boolean hasScheme,
- boolean isSelectedPre, boolean isSelectedNext) {
-
-
- int cx = x + mItemWidth / 2;
- int cy = y + mItemHeight / 2;
-
- // 改动 自己添加只要圆形选中
- canvas.drawCircle(cx, cy, mRadius, mSelectedPaint);
-
- int Xcx = x + mItemWidth / 2;
- int Xcy = cy + mRadius;
-
- if (hasScheme){
- List<Calendar.Scheme> schemes = calendar.getSchemes();
- Calendar.Scheme scheme1 = schemes.get(0);
-
- String scheme = scheme1.getScheme();
- float[] textBounds = getTextBounds(mTimePaint, scheme);
-
- float width = textBounds[0];
- float height = textBounds[1];
- canvas.drawText(scheme, Xcx - width / 2, Xcy + height + margin1dp * 3, mTimePaint);
-
- // 添加横杠
- int type = scheme1.getType();
- if (type==1) {
- mLinePaint.setColor(Color.BLACK);
- } else {
- mLinePaint.setColor(Color.WHITE);
- }
- canvas.drawLine(Xcx - width / 2, Xcy + height * 3 / 2 + margin1dp * 3, Xcx + width / 2, Xcy + height * 3 / 2 + margin1dp * 3, mLinePaint);
- }
-
- return false;
- }
-
- private static float[] getTextBounds(Paint paint, String txt) {
- Rect rect = new Rect();
- float[] floats = new float[2];
- paint.getTextBounds(txt, 0, txt.length(), rect);
- int w = rect.width();
- int h = rect.height();
- floats[0] = w;
- floats[1] = h;
- return floats;
- }
-
- @Override
- protected void onDrawScheme(Canvas canvas, Calendar calendar, int x, int y, boolean isSelected) {
- // int cx = x + mItemWidth / 2;
- // int cy = mItemHeight / 2;
- //
- // canvas.drawCircle(cx, y + cy, mRadius, mSchemePaint);
- }
-
- @Override
- protected void onDrawText(Canvas canvas, Calendar calendar, int x, int y, boolean hasScheme, boolean isSelected) {
- float baselineY = mTextBaseLine + y;
- int cx = x + mItemWidth / 2;
-
- // 改动 添加一个默认的y
- int cy = mItemHeight / 2;
-
- boolean isInRange = isInRange(calendar);
- boolean isEnable = !onCalendarIntercept(calendar);
- // 添加今天日期的默认 半选中效果
- if (calendar.isCurrentDay() && !isSelected) {
- canvas.drawCircle(cx, y + cy, mRadius, mCurrentDayPaint);
- }
- if (isSelected) {
- canvas.drawText(String.valueOf(calendar.getDay()),
- cx,
- baselineY,
- mSelectTextPaint);
- } else if (hasScheme) {
- canvas.drawText(String.valueOf(calendar.getDay()),
- cx,
- baselineY,
- calendar.isCurrentDay() ? mCurDayTextPaint :
- // calendar.isCurrentMonth() ? mSchemeTextPaint : mOtherMonthTextPaint);
- calendar.isCurrentMonth() && isInRange && isEnable ? mSchemeTextPaint : mOtherMonthTextPaint);
- } else {
- canvas.drawText(String.valueOf(calendar.getDay()), cx, baselineY,
- calendar.isCurrentDay() ? mCurDayTextPaint :
- // calendar.isCurrentMonth() ? mCurMonthTextPaint : mOtherMonthTextPaint);
- calendar.isCurrentMonth() && isInRange && isEnable ? mCurMonthTextPaint : mOtherMonthTextPaint);
- }
- }
- }
- package com.as.zqfjavasample.customrili;
-
- import android.content.Context;
- import android.graphics.Canvas;
- import android.graphics.Color;
- import android.graphics.Paint;
- import android.graphics.Rect;
-
- import com.blankj.utilcode.util.ConvertUtils;
- import com.haibin.calendarview.Calendar;
- import com.haibin.calendarview.MultiWeekView;
-
- import java.util.List;
-
- /**
- * 魅族周视图
- * Created by huanghaibin on 2017/11/29.
- */
- public class CustomMultiWeekView extends MultiWeekView {
- private int mRadius;
-
- /**
- * 今天的背景色
- */
- private Paint mCurrentDayPaint = new Paint();
- // 写时间文字的画笔
- private Paint mTimePaint = new Paint();
- // 写文字底部横杠的画笔
- private Paint mLinePaint = new Paint();
- private int margin1dp;
-
- public CustomMultiWeekView(Context context) {
- super(context);
-
- mCurrentDayPaint.setAntiAlias(true);
- mCurrentDayPaint.setStyle(Paint.Style.FILL);
- mCurrentDayPaint.setColor(0xFFeaeaea);
-
- mTimePaint.setAntiAlias(true);
- mTimePaint.setStyle(Paint.Style.FILL_AND_STROKE);
- mTimePaint.setColor(0xFF000000);
- mTimePaint.setTextSize(ConvertUtils.sp2px(10));
-
-
- mLinePaint.setAntiAlias(true);
- mLinePaint.setStyle(Paint.Style.FILL_AND_STROKE);
- mLinePaint.setColor(0xFF000000);
- mLinePaint.setStrokeWidth(ConvertUtils.dp2px(1));
-
- margin1dp = ConvertUtils.dp2px(1);
-
- }
-
- @Override
- protected boolean onDrawSelected(Canvas canvas, Calendar calendar, int x, boolean hasScheme, boolean isSelectedPre, boolean isSelectedNext) {
-
-
- int cx = x + mItemWidth / 2;
- int cy = 0 + mItemHeight / 2;
-
- // 改动 自己添加只要圆形选中
- canvas.drawCircle(cx, cy, mRadius, mSelectedPaint);
-
- int Xcx = x + mItemWidth / 2;
- int Xcy = cy + mRadius;
-
- List<Calendar.Scheme> schemes = calendar.getSchemes();
- Calendar.Scheme scheme1 = schemes.get(0);
-
- String scheme = scheme1.getScheme();
- float[] textBounds = getTextBounds(mTimePaint, scheme);
-
- float width = textBounds[0];
- float height = textBounds[1];
- canvas.drawText(scheme, Xcx - width / 2, Xcy + height + margin1dp * 3, mTimePaint);
-
- // 添加横杠
- int type = scheme1.getType();
- if (type==1) {
- mLinePaint.setColor(Color.BLACK);
- } else {
- mLinePaint.setColor(Color.WHITE);
- }
-
- canvas.drawLine(Xcx - width / 2, Xcy + height * 3 / 2 + margin1dp * 3, Xcx + width / 2, Xcy + height * 3 / 2 + margin1dp * 3, mLinePaint);
-
- return false;
- }
-
- @Override
- protected void onDrawScheme(Canvas canvas, Calendar calendar, int x, boolean isSelected) {
- // int cx = x + mItemWidth / 2;
- // int cy = mItemHeight / 2;
- // mSchemePaint.setStyle(Paint.Style.FILL_AND_STROKE);
- // canvas.drawCircle(cx, cy, mRadius, mSchemePaint);
- }
-
- private static float[] getTextBounds(Paint paint, String txt) {
- Rect rect = new Rect();
- float[] floats = new float[2];
- paint.getTextBounds(txt, 0, txt.length(), rect);
- int w = rect.width();
- int h = rect.height();
- floats[0] = w;
- floats[1] = h;
- return floats;
- }
-
- @Override
- protected void onPreviewHook() {
- mRadius = Math.min(mItemWidth, mItemHeight) / 10 * 3;
- mSchemePaint.setStyle(Paint.Style.STROKE);
- }
-
-
- @Override
- protected void onDrawText(Canvas canvas, Calendar calendar, int x, boolean hasScheme, boolean isSelected) {
- float baselineY = mTextBaseLine + 0;
- int cx = x + mItemWidth / 2;
-
- // 改动 添加一个默认的y
- int cy = mItemHeight / 2;
-
- boolean isInRange = isInRange(calendar);
- boolean isEnable = !onCalendarIntercept(calendar);
- // 添加今天日期的默认 半选中效果
- if (calendar.isCurrentDay() && !isSelected) {
- canvas.drawCircle(cx, 0 + cy, mRadius, mCurrentDayPaint);
- }
- if (isSelected) {
- canvas.drawText(String.valueOf(calendar.getDay()),
- cx,
- baselineY,
- mSelectTextPaint);
- } else if (hasScheme) {
- canvas.drawText(String.valueOf(calendar.getDay()),
- cx,
- baselineY,
- calendar.isCurrentDay() ? mCurDayTextPaint :
- // calendar.isCurrentMonth() ? mSchemeTextPaint : mOtherMonthTextPaint);
- calendar.isCurrentMonth() && isInRange && isEnable ? mSchemeTextPaint : mOtherMonthTextPaint);
- } else {
- canvas.drawText(String.valueOf(calendar.getDay()), cx, baselineY,
- calendar.isCurrentDay() ? mCurDayTextPaint :
- // calendar.isCurrentMonth() ? mCurMonthTextPaint : mOtherMonthTextPaint);
- calendar.isCurrentMonth() && isInRange && isEnable ? mCurMonthTextPaint : mOtherMonthTextPaint);
- }
- }
-
- }
XML
- <?xml version="1.0" encoding="utf-8"?>
- <layout xmlns:android="http://schemas.android.com/apk/res/android"
- xmlns:app="http://schemas.android.com/apk/res-auto">
-
- <LinearLayout
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:background="@color/white"
- android:orientation="vertical">
-
- <RelativeLayout
- android:layout_width="match_parent"
- android:layout_height="wrap_content">
-
- <TextView
- android:id="@+id/tvCancel"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_marginLeft="@dimen/dp10"
- android:layout_marginTop="@dimen/dp10"
- android:layout_marginBottom="@dimen/dp10"
- android:text="取消"
- android:textColor="@color/black"
- android:textSize="18sp" />
-
- <TextView
- android:id="@+id/tvSure"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_alignParentRight="true"
- android:layout_marginTop="@dimen/dp10"
- android:layout_marginRight="@dimen/dp10"
- android:layout_marginBottom="@dimen/dp10"
- android:text="确定"
- android:textColor="@color/green"
- android:textSize="18sp" />
-
- </RelativeLayout>
-
- <View
- android:background="@color/darkgrey"
- android:layout_marginBottom="@dimen/dp10"
- android:layout_width="match_parent"
- android:layout_height="@dimen/dp1" />
-
- <RelativeLayout
- android:layout_width="match_parent"
- android:layout_height="wrap_content">
-
- <TextView
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_alignParentLeft="true"
- android:layout_marginLeft="@dimen/dp10"
- android:text="选择时间" />
-
- <TextView
- android:id="@+id/currentTime"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_alignParentRight="true"
- android:layout_marginRight="@dimen/dp10"
- android:text="2022年06月"
- android:textColor="@color/black" />
-
- </RelativeLayout>
-
-
- <com.haibin.calendarview.CalendarView
- android:id="@+id/calendarView"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:background="@color/white"
- app:calendar_height="@dimen/dp62"
- app:current_month_lunar_text_color="#CFCFCF"
- app:current_month_text_color="#333333"
- app:max_multi_select_size="20"
- app:month_view="com.as.zqfjavasample.customrili.CustomMultiMonthView"
- app:month_view_show_mode="mode_all"
- app:other_month_lunar_text_color="#e1e1e1"
- app:other_month_text_color="#e1e1e1"
- app:scheme_text="假"
- app:scheme_text_color="#333"
- app:scheme_theme_color="#128c4b"
- app:select_mode="multi_mode"
- app:selected_lunar_text_color="#CFCFCF"
- app:selected_text_color="#ffffff"
- app:selected_theme_color="#f17706"
- app:week_background="#fff"
- app:week_start_with="sun"
- app:week_text_color="#111111"
- app:week_view="com.as.zqfjavasample.customrili.CustomMultiWeekView"
- app:week_view_scrollable="true"
- app:year_view_day_text_color="#333333"
- app:year_view_day_text_size="9sp"
- app:year_view_month_text_color="#ff0000"
- app:year_view_month_text_size="18sp"
- app:year_view_scheme_color="#f17706"
- />
-
-
- <ImageView
- android:id="@+id/ivExpand"
- android:layout_width="@dimen/dp20"
- android:layout_height="@dimen/dp20"
- android:layout_gravity="center_horizontal"
- android:src="@drawable/icshang" />
-
-
- <LinearLayout
- android:layout_width="match_parent"
- android:layout_height="@dimen/dp160"
- android:orientation="horizontal">
-
- <com.aigestudio.wheelpicker.WheelPicker
- android:id="@+id/wheelViewHour"
- android:layout_width="0dp"
- android:layout_height="match_parent"
- android:layout_weight="1"
- app:wheel_atmospheric="true"
- app:wheel_indicator="true"
- app:wheel_indicator_color="@color/darkgrey"
- app:wheel_indicator_size="@dimen/dp1"
- app:wheel_item_text_color="@color/darkgrey"
- app:wheel_item_text_size="18sp"
- app:wheel_selected_item_text_color="@color/black"
- app:wheel_visible_item_count="5" />
-
- <com.aigestudio.wheelpicker.WheelPicker
- android:id="@+id/wheelViewMinute"
- android:layout_width="0dp"
- android:layout_height="match_parent"
- android:layout_weight="1"
- app:wheel_atmospheric="true"
- app:wheel_indicator="true"
- app:wheel_indicator_color="@color/darkgrey"
- app:wheel_indicator_size="@dimen/dp1"
- app:wheel_item_text_color="@color/darkgrey"
- app:wheel_item_text_size="18sp"
- app:wheel_selected_item_text_color="@color/black"
- app:wheel_visible_item_count="5" />
-
-
- </LinearLayout>
- </LinearLayout>
-
- </layout>
主要的代码
- package com.as.zqfjavasample.myclass.detail.guanli;
-
- import android.os.Bundle;
- import android.view.View;
-
- import androidx.databinding.DataBindingUtil;
-
- import com.aigestudio.wheelpicker.WheelPicker;
- import com.as.zqfjavasample.Const;
- import com.as.zqfjavasample.R;
- import com.as.zqfjavasample.base.base_ui.activity.BaseActivity;
- import com.as.zqfjavasample.base.http.BeanCallback_NoDialog;
- import com.as.zqfjavasample.databinding.ActivityAddClassTimeBinding;
- import com.as.zqfjavasample.databinding.PopRiliBinding;
- import com.blankj.utilcode.util.JsonUtils;
- import com.blankj.utilcode.util.ScreenUtils;
- import com.blankj.utilcode.util.TimeUtils;
- import com.blankj.utilcode.util.ToastUtils;
- import com.haibin.calendarview.Calendar;
- import com.haibin.calendarview.CalendarView;
- import com.lxj.xpopup.XPopup;
- import com.lxj.xpopup.core.BasePopupView;
- import com.lxj.xpopup.core.BottomPopupView;
- import com.lxj.xpopup.enums.PopupAnimation;
- import com.lzy.okgo.OkGo;
-
- import org.json.JSONObject;
-
- import java.text.ParseException;
- import java.text.SimpleDateFormat;
- import java.util.ArrayList;
- import java.util.Date;
- import java.util.HashMap;
- import java.util.List;
- import java.util.Map;
-
- import okhttp3.Response;
-
- public class AddClassTimeActivity extends BaseActivity<ActivityAddClassTimeBinding> {
-
-
- // 设置小时选择
- int defaultHour = 0;
- // 设置分钟选择
- int defaultMinute = 0;
-
- // 默认的年月日
- private Calendar lastCalendar;
- private Map<String, Calendar> map;
-
-
- @Override
- protected int getLayoutId() {
- return R.layout.activity_add_class_time;
- }
-
- @Override
- protected void getBundleExtras(Bundle extras) {
-
- }
-
- @Override
- protected void initView() {
-
- }
-
- @Override
- protected void initData() {
-
- }
-
- @Override
- protected void initListener() {
-
- BasePopupView popupView = new XPopup.Builder(mContext)
- .popupAnimation(PopupAnimation.TranslateFromBottom) //设置动画
- .dismissOnTouchOutside(false) // 点击外面不消失
- // .dismissOnBackPressed(false) //不管用
- .hasShadowBg(true)
- // .enableDrag(false)
- .asCustom(new BottomPopupView(mContext) {
- // 返回自定义弹窗的布局
- @Override
- protected int getImplLayoutId() {
- return R.layout.pop_rili;
- }
-
- @Override
- protected void onCreate() {
- super.onCreate();
- PopRiliBinding mViewBinding = DataBindingUtil.bind(getPopupImplView());
- int year = mViewBinding.calendarView.getCurYear();
- int month = mViewBinding.calendarView.getCurMonth();
- int day = mViewBinding.calendarView.getCurDay();
-
- mViewBinding.calendarView.setRange(
- year,
- month,
- day,
- year + 1, 12, 24);
-
-
- mViewBinding.currentTime.setText(year + "年" + month + "月");
-
- map = new HashMap<>();
-
-
- // 设置默认选中的日期
- Calendar calendar1 = new Calendar();
- calendar1.setYear(year);
- calendar1.setMonth(month);
- calendar1.setDay(14);
-
- Calendar calendar2 = new Calendar();
- calendar2.setYear(year);
- calendar2.setMonth(month);
- calendar2.setDay(18);
-
- // 这里为了获取时间
- map.put(getSchemeCalendar(calendar1.getYear(), calendar1.getMonth(), calendar1.getDay(), 0xDDDD, "11:00", 0).toString(),
- getSchemeCalendar(calendar1.getYear(), calendar1.getMonth(), calendar1.getDay(), 0xDDDD, "11:00", 0));
-
- map.put(getSchemeCalendar(calendar2.getYear(), calendar2.getMonth(), calendar2.getDay(), 0xDDDD, "11:00", 1).toString(),
- getSchemeCalendar(calendar2.getYear(), calendar2.getMonth(), calendar2.getDay(), 0xDDDD, "11:00", 1));
-
- lastCalendar = calendar2;
- mViewBinding.calendarView.setSchemeDate(map);
-
- mViewBinding.calendarView.setMaxMultiSelectSize(20);
- mViewBinding.calendarView.putMultiSelect(calendar1, calendar2);
-
-
- mViewBinding.calendarView.setOnCalendarMultiSelectListener(new CalendarView.OnCalendarMultiSelectListener() {
-
- @Override
- public void onCalendarMultiSelectOutOfRange(Calendar calendar) {
-
- }
-
- @Override
- public void onMultiSelectOutOfSize(Calendar calendar, int maxSize) {
- ToastUtils.showShort("超过最大选择数量");
- }
-
- @Override
- public void onCalendarMultiSelect(Calendar calendar, int curSize, int maxSize) {
-
-
- // if (calendar == lastCalendar) {
- //
- // }
- int mSelectYear = calendar.getYear();
- int mSelectMonth = calendar.getMonth();
- int mSelectday = calendar.getDay();
-
- mViewBinding.currentTime.setText(mSelectYear + "年" + mSelectMonth + "月");
-
- List<Calendar> multiSelectCalendars = mViewBinding.calendarView.getMultiSelectCalendars();
- if (multiSelectCalendars.contains(calendar)) {
-
- String strHour = getTrueForm(defaultHour);
- String strMinute = getTrueForm(defaultMinute);
-
- // 把上一次的横杠去掉 Type改为0
- map.put(getSchemeCalendar(lastCalendar.getYear(), lastCalendar.getMonth(), lastCalendar.getDay(), 0xDDDD, strHour + ":" + strMinute, 0).toString(),
- getSchemeCalendar(lastCalendar.getYear(), lastCalendar.getMonth(), lastCalendar.getDay(), 0xDDDD, strHour + ":" + strMinute, 0));
-
- // 选择
- map.put(getSchemeCalendar(mSelectYear, mSelectMonth, mSelectday, 0xDDDD, strHour + ":" + strMinute, 1).toString(),
- getSchemeCalendar(mSelectYear, mSelectMonth, mSelectday, 0xDDDD, strHour + ":" + strMinute, 1));
-
- mViewBinding.calendarView.setSchemeDate(map);
- lastCalendar = calendar;
-
- }
- }
- });
-
- // 设置时间选择器的 小时 分钟
- List<String> dataHours = new ArrayList<>();
- List<Integer> dataHoursInt = new ArrayList<>();
- for (int i = 0; i < 24; i++) {
- dataHoursInt.add(i);
- dataHours.add(i + "时");
- }
- List<String> dataMinutes = new ArrayList<>();
- List<Integer> dataMinutesInt = new ArrayList<>();
- for (int i = 0; i < 12; i++) {
- dataMinutesInt.add(i * 5);
- dataMinutes.add(i * 5 + "分");
- }
- mViewBinding.wheelViewHour.setData(dataHours);
- mViewBinding.wheelViewMinute.setData(dataMinutes);
-
- mViewBinding.wheelViewHour.setSelectedItemPosition(4, false);
- defaultHour = dataHoursInt.get(4);
-
- mViewBinding.wheelViewHour.setOnItemSelectedListener(new WheelPicker.OnItemSelectedListener() {
- @Override
- public void onItemSelected(WheelPicker picker, Object data, int position) {
- defaultHour = dataHoursInt.get(position);
-
- String strHour = getTrueForm(defaultHour);
- String strMinute = getTrueForm(defaultMinute);
-
- map.put(getSchemeCalendar(lastCalendar.getYear(), lastCalendar.getMonth(), lastCalendar.getDay(), 0xDDDD, strHour + ":" + strMinute, 1).toString(),
- getSchemeCalendar(lastCalendar.getYear(), lastCalendar.getMonth(), lastCalendar.getDay(), 0xDDDD, strHour + ":" + strMinute, 1));
-
- mViewBinding.calendarView.setSchemeDate(map);
- }
- });
- mViewBinding.wheelViewMinute.setOnItemSelectedListener(new WheelPicker.OnItemSelectedListener() {
- @Override
- public void onItemSelected(WheelPicker picker, Object data, int position) {
- defaultMinute = dataMinutesInt.get(position);
-
- String strHour = getTrueForm(defaultHour);
- String strMinute = getTrueForm(defaultMinute);
-
- map.put(getSchemeCalendar(lastCalendar.getYear(), lastCalendar.getMonth(), lastCalendar.getDay(), 0xDDDD, strHour + ":" + strMinute, 1).toString(),
- getSchemeCalendar(lastCalendar.getYear(), lastCalendar.getMonth(), lastCalendar.getDay(), 0xDDDD, strHour + ":" + strMinute, 1));
-
- mViewBinding.calendarView.setSchemeDate(map);
-
- }
- });
-
- mViewBinding.ivExpand.setOnClickListener(new OnClickListener() {
- @Override
- public void onClick(View v) {
-
-
- if (mViewBinding.calendarView.getWeekViewPager().getVisibility() == View.GONE) {
- mViewBinding.calendarView.getMonthViewPager().setVisibility(View.GONE);
- mViewBinding.calendarView.getWeekViewPager().setVisibility(View.VISIBLE);
-
- v.animate()
- .setDuration(100)
- .rotationX(180)
- .start();
- } else {
-
- mViewBinding.calendarView.getMonthViewPager().setVisibility(View.VISIBLE);
- mViewBinding.calendarView.getWeekViewPager().setVisibility(View.GONE);
- v.animate()
- .setDuration(100)
- .rotationX(360)
- .start();
- }
- }
- });
-
-
- mViewBinding.tvCancel.setOnClickListener(new OnClickListener() {
- @Override
- public void onClick(View v) {
- dismiss();
- }
- });
- mViewBinding.tvSure.setOnClickListener(new OnClickListener() {
- @Override
- public void onClick(View v) {
- List<Long> list = new ArrayList<>();
-
- if (map == null) {
- return;
- }
- for (String key : map.keySet()) {
- Calendar calendar = map.get(key);
- Calendar.Scheme scheme = calendar.getSchemes().get(0);
- String scheme1 = scheme.getScheme();
- String[] split = scheme1.split(":");
-
- SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm");
- Date date = null;
- try {
- date = simpleDateFormat.parse(calendar.getYear() + "-" + calendar.getMonth() + "-" + calendar.getDay() + " " + split[0] + ":" + split[1]);
-
- long l = TimeUtils.date2Millis(date) / 1000;
- list.add(l);
-
- } catch (ParseException e) {
- e.printStackTrace();
- }
-
- }
-
- String s = JsonUtils.formatJson(list.toString());
-
- OkGo.<Object>post(Const.AddClassTimes)
- .params("class_id", 1)
- .params("times", s)
- .execute(new BeanCallback_NoDialog<Object>() {
- @Override
- public Object convertResponse(Response response) throws Throwable {
- String string = response.body().string();
- JSONObject jsonObject = new JSONObject(string);
- int code = jsonObject.getInt("code");
- String message = jsonObject.getString("message");
- ToastUtils.showShort(message + "");
-
- System.out.println("string : " + string);
- return super.convertResponse(response);
- }
- });
-
- for (int i = 0; i < list.size(); i++) {
- System.out.println("数据 :" + list.get(i));
- }
- }
- });
- }
-
- @Override
- protected boolean onBackPressed() {
- dismiss();
- return true;
- }
-
- @Override
- protected int getPopupWidth() {
- return ScreenUtils.getScreenWidth();
- }
- });
-
-
- mViewBinding.llStart.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- popupView.show();
- }
- });
-
-
- }
-
- private String getTrueForm(int time) {
- if (time < 10) {
- return 0 + "" + time;
- } else {
- return time + "";
- }
- }
-
- //hasLine : 0 代表乜有 1代表有
- private Calendar getSchemeCalendar(int year, int month, int day, int color, String text, int type) {
- Calendar calendar = new Calendar();
- calendar.setYear(year);
- calendar.setMonth(month);
- calendar.setDay(day);
- calendar.setSchemeColor(color);//如果单独标记颜色、则会使用这个颜色
- List<Calendar.Scheme> list = new ArrayList<>();
- list.add(new Calendar.Scheme(type, color, text));
- calendar.setSchemes(list);
- return calendar;
- }
-
-
- }
魔改2.
- <?xml version="1.0" encoding="utf-8"?>
- <layout xmlns:android="http://schemas.android.com/apk/res/android"
- xmlns:app="http://schemas.android.com/apk/res-auto"
- xmlns:tools="http://schemas.android.com/tools"
- tools:context=".myclass.detail.yuyue.YuyueActivity">
-
-
- <LinearLayout
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:orientation="vertical">
-
-
- <RelativeLayout
- android:layout_width="match_parent"
- android:layout_height="wrap_content">
-
- <ImageView
- android:layout_width="@dimen/dp40"
- android:layout_height="@dimen/dp40"
- android:layout_centerVertical="true"
- android:padding="@dimen/dp10"
- android:src="@drawable/toleftblack" />
-
- <TextView
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_centerInParent="true"
- android:layout_marginTop="@dimen/dp10"
- android:layout_marginBottom="@dimen/dp10"
- android:text="课程预约"
- android:textColor="@color/black"
- android:textSize="18sp" />
-
- </RelativeLayout>
-
-
- <TextView
- android:id="@+id/tvCurrentTime"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text="2022年7月"
- android:textColor="@color/black" />
-
- <com.haibin.calendarview.CalendarView
- android:id="@+id/calendarView"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:background="@color/white"
- app:calendar_height="@dimen/dp62"
- app:current_month_lunar_text_color="#CFCFCF"
- app:current_month_text_color="#333333"
- app:max_multi_select_size="20"
- app:month_view="com.as.zqfjavasample.customrili.SimpleMonthView"
- app:month_view_show_mode="mode_all"
- app:other_month_lunar_text_color="#e1e1e1"
- app:other_month_text_color="#e1e1e1"
- app:scheme_text="假"
- app:scheme_text_color="#333"
- app:scheme_theme_color="#CFCFCF"
- app:select_mode="single_mode"
- app:selected_lunar_text_color="#CFCFCF"
- app:selected_text_color="#ffffff"
- app:selected_theme_color="#f17706"
- app:week_background="#fff"
- app:week_start_with="sun"
- app:week_text_color="#111111"
- app:week_view="com.as.zqfjavasample.customrili.SimpleWeekView"
- app:week_view_scrollable="true"
- app:year_view_day_text_color="#333333"
- app:year_view_day_text_size="9sp"
- app:year_view_month_text_color="#ff0000"
- app:year_view_month_text_size="18sp"
- app:year_view_scheme_color="#f17706"
- />
- <ImageView
- android:id="@+id/ivExpand"
- android:layout_width="@dimen/dp20"
- android:layout_height="@dimen/dp20"
- android:layout_gravity="center_horizontal"
- android:src="@drawable/icshang" />
-
-
- </LinearLayout>
-
-
- </layout>
- package com.as.zqfjavasample.myclass.detail.yuyue;
-
- import android.os.Build;
- import android.os.Bundle;
- import android.view.View;
-
- import androidx.annotation.RequiresApi;
-
- import com.as.zqfjavasample.R;
- import com.as.zqfjavasample.base.base_ui.activity.BaseActivity;
- import com.as.zqfjavasample.databinding.ActivityYuyueBinding;
- import com.haibin.calendarview.Calendar;
-
- import java.time.LocalDateTime;
- import java.util.HashMap;
- import java.util.Map;
-
- public class YuyueActivity extends BaseActivity<ActivityYuyueBinding> {
-
-
- @Override
- protected int getLayoutId() {
- return R.layout.activity_yuyue;
- }
-
- @Override
- protected void getBundleExtras(Bundle extras) {
-
- }
-
- @RequiresApi(api = Build.VERSION_CODES.O)
- @Override
- protected void initView() {
- int curYear = mViewBinding.calendarView.getCurYear();
- int curMonth = mViewBinding.calendarView.getCurMonth();
- int curDay = mViewBinding.calendarView.getCurDay();
-
- Map<String, Calendar> map = new HashMap<>();
-
- for (int i = 1; i < 31; i++) {
-
- LocalDateTime time=LocalDateTime. now();
- LocalDateTime time2= time.minusDays(i);
- // java.util.Calendar instance = java.util.Calendar.getInstance();
- // instance.setTime(new Date());
- // instance.add(java.util.Calendar.DATE,-i);
- // int year = instance.get(java.util.Calendar.YEAR);
- // int month = instance.get(java.util.Calendar.MONTH+1);
- // int day = instance.get(java.util.Calendar.DATE+1);
-
- // Date time1 = instance.getTime();
- // System.out.println("time1.getYear() :"+time1.getYear());
- // System.out.println("time1.getMonth() :"+time1.getMonth());
- // System.out.println("time1.getDay() :"+time1.getDay());
- Calendar calendar1 = new Calendar();
- calendar1.setYear(time2.getYear());
- calendar1.setMonth(time2.getMonthValue());
- calendar1.setDay(time2.getDayOfMonth());
- map.put(getSchemeCalendar(calendar1.getYear(), calendar1.getMonth(), calendar1.getDay(), 0XffCFCFCF, "11:00").toString(),
- getSchemeCalendar(calendar1.getYear(), calendar1.getMonth(), calendar1.getDay(), 0XffCFCFCF, "11:00"));
- }
- mViewBinding.calendarView.setSchemeDate(map);
-
- mViewBinding.calendarView.setRange(
- curYear,
- curMonth-1,
- curDay,
- curYear + 1, curMonth, curDay);
-
- mViewBinding.calendarView.clearSingleSelect();
- mViewBinding.calendarView.scrollToCurrent();
-
- mViewBinding.tvCurrentTime.setText(curYear + "年" + curMonth + "月");
-
- }
-
- //hasLine : 0 代表乜有 1代表有
- private Calendar getSchemeCalendar(int year, int month, int day, int color, String text) {
- Calendar calendar = new Calendar();
- calendar.setYear(year);
- calendar.setMonth(month);
- calendar.setDay(day);
- calendar.setSchemeColor(color);//如果单独标记颜色、则会使用这个颜色
- calendar.setScheme(text);
- return calendar;
- }
-
- @Override
- protected void initData() {
-
- }
-
- @Override
- protected void initListener() {
- mViewBinding.ivExpand.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
-
-
- if (mViewBinding.calendarView.getWeekViewPager().getVisibility() == View.GONE) {
- mViewBinding.calendarView.getMonthViewPager().setVisibility(View.GONE);
- mViewBinding.calendarView.getWeekViewPager().setVisibility(View.VISIBLE);
-
- v.animate()
- .setDuration(100)
- .rotationX(180)
- .start();
- } else {
-
- mViewBinding.calendarView.getMonthViewPager().setVisibility(View.VISIBLE);
- mViewBinding.calendarView.getWeekViewPager().setVisibility(View.GONE);
- v.animate()
- .setDuration(100)
- .rotationX(360)
- .start();
- }
- }
- });
- }
- }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。