在说这篇文章之前我们先了解下自定义考勤统计一 的内容,以及他的参考文献,这样就更容易了解这篇文章了。

看下效果图:

分析下效果图:

1.功能是:筛选日期,检索考勤统计列表,点击列表条目进入考勤统计日历,但是有一点要注意:统计列表筛选的开始月份与统计日历要一样,就是说统计列表月份与统计日历月份要联动,一致。

2.点击统计日历进行月份翻页。

3.还有一点:不管是统计列表还是统计日历都是根据筛选的开始日历而定的,当开始日期被选择 点击确定才有效,取消无效;结束日期被选择无效。

这篇文章对pickerview 日历日期选择不做介绍,在后面的文章会单独介绍;只针对翻页日历进行介绍。

看下代码:以统计中 “我的” 为例:

StatisticsAttendanceActivity.java

/*** 统计界面*/
public class StatisticsAttendanceActivity extends BaseActivity {private FactoryWaitDialog waitDialog;private ImageView iv_back;private ImageView iv_date_left;private ImageView iv_date_right;private TextView tv_title;private TextView tv_date_top;private CalendarView calendar_view;private TextView tv_late;private TextView tv_leave_early;private TextView tv_lack;private TextView tv_off_work;private TextView tv_absent;private TextView tv_out_work;private RecyclerView recycleview;private String yearMonth;private String yearMonthDay;private String queryId;private Calendar calendar;private String start_timeYm;private String start_timeYmd;private boolean ischoose_start_calander;private Date mchoose_date;@Overridepublic int getLayoutResId() {return R.layout.activity_statistics_attendance;}@Overrideprotected void initView() {waitDialog = new FactoryWaitDialog(activity, false, null);calendar = Calendar.getInstance();iv_back = (ImageView) findViewById(R.id.iv_back);iv_date_left = (ImageView) findViewById(R.id.iv_date_left);iv_date_right = (ImageView) findViewById(R.id.iv_date_right);tv_title = (TextView) findViewById(R.id.tv_title);tv_date_top = (TextView) findViewById(R.id.tv_date_top);calendar_view = (CalendarView) findViewById(R.id.calendar_view);tv_late = (TextView) findViewById(R.id.tv_late);tv_leave_early = (TextView) findViewById(R.id.tv_leave_early);tv_lack = (TextView) findViewById(R.id.tv_lack);tv_off_work = (TextView) findViewById(R.id.tv_off_work);tv_absent = (TextView) findViewById(R.id.tv_absent);tv_out_work = (TextView) findViewById(R.id.tv_out_work);recycleview = (RecyclerView) findViewById(R.id.recycleview);recycleview.setLayoutManager(new LinearLayoutManager(activity, LinearLayoutManager.VERTICAL, false));}@Overrideprotected void initListener() {iv_back.setOnClickListener(this);iv_date_left.setOnClickListener(this);iv_date_right.setOnClickListener(this);}@Overrideprotected void initData() {iv_back.setVisibility(View.VISIBLE);tv_title.setText("统计");Intent intent = getIntent();queryId = intent.getStringExtra("id");start_timeYm = intent.getStringExtra("start_timeYm");//查询的开始年月start_timeYmd = intent.getStringExtra("start_timeYmd");//查询的开始年月日ischoose_start_calander = intent.getBooleanExtra("choose_start_calander", false);mchoose_date = new Date(intent.getLongExtra("mchoose_date", 0));//查询的Date数据if (ischoose_start_calander) {yearMonth = start_timeYm;yearMonthDay = start_timeYmd;} else {yearMonth = DateUtils.currentYM();//当前年月yearMonthDay = DateUtils.currentYMD();//当前年月日}tv_date_top.setText(yearMonthDay);getMonthAttendance();}private void getMonthAttendance() {waitDialog.show();ServiceApi.getMonthAttendance(SpUtils.getUserId(activity), yearMonth, queryId, new MyString2Callback() {@Overridepublic void onError(Call call, Exception e) {waitDialog.dismiss();ToastUtils.showServiceDataErrorToast();}@Overridepublic void onResponse(Call call, String s) {waitDialog.dismiss();CalendarDataBean calendarDataBean = new Gson().fromJson(s, CalendarDataBean.class);if (calendarDataBean.code == 0) {List<CalendarDataBean.ListCodeBean> datas = calendarDataBean.listCode;calendar_view.setData(datas, new CalendarAdapter.OnItemChooseListener() {@Overridepublic void onItemChoose(String chooseDay) {waitDialog.show();tv_date_top.setText(chooseDay);getDayAttendanceList(chooseDay);}}, yearMonthDay);tv_late.setText("迟到  :  " + calendarDataBean.countCode.lateAttenCount);tv_leave_early.setText("早退  :  " + calendarDataBean.countCode.earlyAtenCount);tv_lack.setText("缺卡  :  " + calendarDataBean.countCode.singleAttenCount);tv_off_work.setText("请假  :  " + calendarDataBean.countCode.approAttenCount);tv_absent.setText("旷工  :  " + calendarDataBean.countCode.workAttenCount);tv_out_work.setText("外勤  :  " + calendarDataBean.countCode.outAttenCount);getDayAttendanceList(yearMonthDay);} else {ToastUtils.showToast(calendarDataBean.msg);}}});}/*** 获取某天的出勤** @param ymd*/private void getDayAttendanceList(String ymd) {ServiceApi.getDayAttendanceList(SpUtils.getUserId(activity), ymd, queryId, new MyString2Callback() {@Overridepublic void onError(Call call, Exception e) {waitDialog.dismiss();}@Overridepublic void onResponse(Call call, String s) {AttendanceDayListBean attendanceDayListBean = new Gson().fromJson(s, AttendanceDayListBean.class);if (attendanceDayListBean.code == 0) {AttendanceDayListAdapter attendanceDayListAdapter = new AttendanceDayListAdapter(activity, attendanceDayListBean.approvingList, attendanceDayListBean.attendanceList);recycleview.setAdapter(attendanceDayListAdapter);} else {ToastUtils.showToast(attendanceDayListBean.msg);}waitDialog.dismiss();}});}@Overridepublic void onClick(View view) {super.onClick(view);switch (view.getId()) {case R.id.iv_back:finish();break;case R.id.iv_date_right:if (ischoose_start_calander) { //是否查询 ,在查询月份的基础上左右翻页
//                   yearMonth = start_timeYm;  //查询的开始年月
//                   yearMonthDay = start_timeYmd; //查询的开始年月日
//                    mchoose_date                 //查询的Date数据//将Date对象设置给Calendar对象的方法calendar.setTime(mchoose_date);calendar.add(Calendar.MONTH, +1);//getTime()将当前Calendar对象转换为Date对象yearMonth = DateUtils.getTimeYM(calendar.getTime());mchoose_date = DateUtils.Str2DateYM(yearMonth);//判断不同格式的日期 是否是同一天if (checkDateEquals(yearMonth, DateUtils.currentYM())) {yearMonthDay = DateUtils.currentYMD();tv_date_top.setText(DateUtils.currentYMD());} else {yearMonthDay = yearMonth + "-01";tv_date_top.setText(yearMonth + "-01");}getMonthAttendance();} else {//在当前月份的基础上左右翻页calendar.add(Calendar.MONTH, +1);yearMonth = DateUtils.getTimeYM(calendar.getTime());//判断不同格式的日期 是否是同一天if (checkDateEquals(yearMonth, DateUtils.currentYM())) {yearMonthDay = DateUtils.currentYMD();tv_date_top.setText(DateUtils.currentYMD());} else {yearMonthDay = yearMonth + "-01";tv_date_top.setText(yearMonth + "-01");}getMonthAttendance();}break;case R.id.iv_date_left:if (ischoose_start_calander) { //是否查询 ,在查询月份的基础上左右翻页//将Date对象设置给Calendar对象的方法calendar.setTime(mchoose_date);calendar.add(Calendar.MONTH, -1);//getTime()将当前Calendar对象转换为Date对象yearMonth = DateUtils.getTimeYM(calendar.getTime());mchoose_date = DateUtils.Str2DateYM(yearMonth);//判断不同格式的日期 是否是同一天if (checkDateEquals(yearMonth, DateUtils.currentYM())) {yearMonthDay = DateUtils.currentYMD();tv_date_top.setText(DateUtils.currentYMD());} else {yearMonthDay = yearMonth + "-01";tv_date_top.setText(yearMonth + "-01");}getMonthAttendance();} else {//在当前月份的基础上左右翻页calendar.add(Calendar.MONTH, -1);yearMonth = DateUtils.getTimeYM(calendar.getTime());if (checkDateEquals(yearMonth, DateUtils.currentYM())) {yearMonthDay = DateUtils.currentYMD();tv_date_top.setText(DateUtils.currentYMD());} else {yearMonthDay = yearMonth + "-01";tv_date_top.setText(yearMonth + "-01");}getMonthAttendance();}break;}}/*** 判断不同格式的日期 是否是同一天** @param year_month1* @param year_month2* @return*/private boolean checkDateEquals(String year_month1, String year_month2) {String[] ym1 = year_month1.split("-");String[] ym2 = year_month2.split("-");String year1 = ym1[0];String month1 = ym1[1];String year2 = ym2[0];String month2 = ym2[1];if (year1.equals(year2) && month1.equals(month2)) {return true;} else {return false;}}
}

这里我只介绍效果图的第一点介绍:统计列表筛选的开始月份与统计日历要一样,就是说统计列表月份与统计日历月份要联动,一致。也就是点击列表进入日历月份一致,月份翻页无错误。

那么主要的就是点击拉列表条目模块和左右翻页模块了。

点击列表表条目进入翻页日历:

            case R.id.ll1:case R.id.ll2:if(ischoose_start_calander){Intent intent = new Intent(getActivity(), StatisticsAttendanceActivity.class);intent.putExtra("id",SpUtils.getUserId(getActivity()));intent.putExtra("start_timeYm",start_timeYm);//年月intent.putExtra("start_timeYmd",start_day);//年月日intent.putExtra("choose_start_calander",ischoose_start_calander);//是否选择日期intent.putExtra("mchoose_date",mchoose_date.getTime());//选择日期时的开始DategetActivity().startActivity(intent);}else {Intent intent = new Intent(getActivity(), StatisticsAttendanceActivity.class);intent.putExtra("id",SpUtils.getUserId(getActivity()));intent.putExtra("choose_start_calander",ischoose_start_calander);getActivity().startActivity(intent);}

ischoose_start_calander:是否选择日期(筛选查询的日期,开始日期)

start_timeYm:日期年月

start_day:年月日

mchoose_data.getTime() :选择日期时的开始Data.

左右翻页模块:

           case R.id.iv_date_right:if (ischoose_start_calander) { //是否查询 ,在查询月份的基础上左右翻页
//                   yearMonth = start_timeYm;  //查询的开始年月
//                   yearMonthDay = start_timeYmd; //查询的开始年月日
//                    mchoose_date                 //查询的Date数据//将Date对象设置给Calendar对象的方法calendar.setTime(mchoose_date);calendar.add(Calendar.MONTH, +1);//getTime()将当前Calendar对象转换为Date对象yearMonth = DateUtils.getTimeYM(calendar.getTime());mchoose_date = DateUtils.Str2DateYM(yearMonth);//判断不同格式的日期 是否是同一天if (checkDateEquals(yearMonth, DateUtils.currentYM())) {yearMonthDay = DateUtils.currentYMD();tv_date_top.setText(DateUtils.currentYMD());} else {yearMonthDay = yearMonth + "-01";tv_date_top.setText(yearMonth + "-01");}getMonthAttendance();} else {//在当前月份的基础上左右翻页calendar.add(Calendar.MONTH, +1);yearMonth = DateUtils.getTimeYM(calendar.getTime());//判断不同格式的日期 是否是同一天if (checkDateEquals(yearMonth, DateUtils.currentYM())) {yearMonthDay = DateUtils.currentYMD();tv_date_top.setText(DateUtils.currentYMD());} else {yearMonthDay = yearMonth + "-01";tv_date_top.setText(yearMonth + "-01");}getMonthAttendance();}break;case R.id.iv_date_left:if (ischoose_start_calander) { //是否查询 ,在查询月份的基础上左右翻页//将Date对象设置给Calendar对象的方法calendar.setTime(mchoose_date);calendar.add(Calendar.MONTH, -1);//getTime()将当前Calendar对象转换为Date对象yearMonth = DateUtils.getTimeYM(calendar.getTime());mchoose_date = DateUtils.Str2DateYM(yearMonth);//判断不同格式的日期 是否是同一天if (checkDateEquals(yearMonth, DateUtils.currentYM())) {yearMonthDay = DateUtils.currentYMD();tv_date_top.setText(DateUtils.currentYMD());} else {yearMonthDay = yearMonth + "-01";tv_date_top.setText(yearMonth + "-01");}getMonthAttendance();} else {//在当前月份的基础上左右翻页calendar.add(Calendar.MONTH, -1);yearMonth = DateUtils.getTimeYM(calendar.getTime());if (checkDateEquals(yearMonth, DateUtils.currentYM())) {yearMonthDay = DateUtils.currentYMD();tv_date_top.setText(DateUtils.currentYMD());} else {yearMonthDay = yearMonth + "-01";tv_date_top.setText(yearMonth + "-01");}getMonthAttendance();}break;}

如果我们不要求月份的一致,没有查月份的筛选,只有当月的日历,然后进行翻页,我们只需要:

              //在当前月份的基础上左右翻页calendar.add(Calendar.MONTH, +1);yearMonth = DateUtils.getTimeYM(calendar.getTime());//判断不同格式的日期 是否是同一天if (checkDateEquals(yearMonth, DateUtils.currentYM())) {yearMonthDay = DateUtils.currentYMD();tv_date_top.setText(DateUtils.currentYMD());} else {yearMonthDay = yearMonth + "-01";tv_date_top.setText(yearMonth + "-01");}getMonthAttendance();}

如果要求有列表查询,并且月份一致,主要注意这部分:

              if (ischoose_start_calander) { //是否查询 ,在查询月份的基础上左右翻页
//                   yearMonth = start_timeYm;  //查询的开始年月
//                   yearMonthDay = start_timeYmd; //查询的开始年月日
//                    mchoose_date                 //查询的Date数据//将Date对象设置给Calendar对象的方法calendar.setTime(mchoose_date);calendar.add(Calendar.MONTH, +1);//getTime()将当前Calendar对象转换为Date对象yearMonth = DateUtils.getTimeYM(calendar.getTime());mchoose_date = DateUtils.Str2DateYM(yearMonth);//判断不同格式的日期 是否是同一天if (checkDateEquals(yearMonth, DateUtils.currentYM())) {yearMonthDay = DateUtils.currentYMD();tv_date_top.setText(DateUtils.currentYMD());} else {yearMonthDay = yearMonth + "-01";tv_date_top.setText(yearMonth + "-01");}getMonthAttendance();}

看下布局:activity_statistics_attendance.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="match_parent"android:layout_height="match_parent"android:orientation="vertical"><include layout="@layout/titlebar_blue" /><RelativeLayoutandroid:layout_width="match_parent"android:layout_height="36dp"><ImageViewandroid:id="@+id/iv_date_left"android:layout_width="wrap_content"android:layout_height="match_parent"android:layout_centerVertical="true"android:layout_toLeftOf="@+id/tv_date_top"android:paddingLeft="10dp"android:paddingRight="10dp"android:src="@drawable/arrow_blue_left" /><TextViewandroid:id="@+id/tv_date_top"android:layout_width="wrap_content"android:layout_height="36dp"android:layout_centerInParent="true"android:layout_marginLeft="15dp"android:layout_marginRight="15dp"android:gravity="center"android:text=""android:textColor="@color/titlebar_bg_blue"android:textSize="15sp" /><ImageViewandroid:id="@+id/iv_date_right"android:layout_width="wrap_content"android:layout_height="match_parent"android:layout_centerVertical="true"android:layout_toRightOf="@+id/tv_date_top"android:paddingLeft="10dp"android:paddingRight="10dp"android:src="@drawable/arrow_blue_right" /></RelativeLayout><包名.oa.CalendarViewandroid:id="@+id/calendar_view"android:layout_width="match_parent"android:layout_height="wrap_content"></包名.oa.CalendarView><LinearLayoutandroid:layout_width="match_parent"android:layout_height="wrap_content"android:layout_marginBottom="8dp"android:layout_marginLeft="10dp"android:layout_marginRight="10dp"android:layout_marginTop="5dp"android:orientation="horizontal"><TextViewandroid:id="@+id/tv_late"android:layout_width="80dp"android:layout_height="wrap_content"android:drawableLeft="@drawable/p_late_big"android:drawablePadding="6dp"android:text="迟到:  0"android:textColor="@color/tv_33"android:textSize="13sp" /><Viewandroid:layout_width="0dp"android:layout_height="match_parent"android:layout_weight="1" /><TextViewandroid:id="@+id/tv_leave_early"android:layout_width="80dp"android:layout_height="wrap_content"android:drawableLeft="@drawable/p_earlyleave_big"android:drawablePadding="6dp"android:text="早退:  0"android:textColor="@color/tv_33"android:textSize="13sp" /><Viewandroid:layout_width="0dp"android:layout_height="match_parent"android:layout_weight="1" /><TextViewandroid:id="@+id/tv_lack"android:layout_width="80dp"android:layout_height="wrap_content"android:drawableLeft="@drawable/p_lack_big"android:drawablePadding="6dp"android:text="缺卡:  0"android:textColor="@color/tv_33"android:textSize="13sp" /></LinearLayout><LinearLayoutandroid:layout_width="match_parent"android:layout_height="wrap_content"android:layout_marginBottom="5dp"android:layout_marginLeft="10dp"android:layout_marginRight="10dp"android:orientation="horizontal"><TextViewandroid:id="@+id/tv_off_work"android:layout_width="80dp"android:layout_height="wrap_content"android:drawableLeft="@drawable/p_offday_big"android:drawablePadding="6dp"android:text="请假:  0"android:textColor="@color/tv_33"android:textSize="13sp" /><Viewandroid:layout_width="0dp"android:layout_height="match_parent"android:layout_weight="1" /><TextViewandroid:id="@+id/tv_absent"android:layout_width="80dp"android:layout_height="wrap_content"android:drawableLeft="@drawable/p_absent_big"android:drawablePadding="6dp"android:text="旷工:  0"android:textColor="@color/tv_33"android:textSize="13sp" /><Viewandroid:layout_width="0dp"android:layout_height="match_parent"android:layout_weight="1" /><TextViewandroid:id="@+id/tv_out_work"android:layout_width="80dp"android:layout_height="wrap_content"android:drawableLeft="@drawable/p_outwork_big"android:drawablePadding="6dp"android:text="外勤:  0"android:textColor="@color/tv_33"android:textSize="13sp" /></LinearLayout><android.support.v7.widget.RecyclerViewandroid:id="@+id/recycleview"android:layout_width="match_parent"android:layout_height="wrap_content"android:background="@color/bg_gray"android:paddingBottom="10dp"></android.support.v7.widget.RecyclerView>
</LinearLayout>

CalendarView.java

/***/
public class CalendarView extends LinearLayout {private RecyclerView recyclerview;public CalendarView(Context context) {this(context,null);}public CalendarView(Context context, AttributeSet attrs) {super(context, attrs);initView(context);}public CalendarView(Context context, AttributeSet attrs, int defStyleAttr) {super(context, attrs, defStyleAttr);}private void initView(Context context) {View view = LayoutInflater.from(context).inflate(R.layout.view_calendar,null);recyclerview = (RecyclerView) view.findViewById(R.id.recyclerview);addView(view);recyclerview.setLayoutManager(new GridLayoutManager(context,7));}public void setData(List<CalendarDataBean.ListCodeBean> data,CalendarAdapter.OnItemChooseListener onItemChooseListener,String currentYMD){CalendarAdapter calendarAdapter = new CalendarAdapter(getContext(), data,currentYMD);calendarAdapter.setOnItemChooseListener(onItemChooseListener);recyclerview.setAdapter(calendarAdapter);invalidate();}}

view_calendar.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"android:orientation="vertical" android:layout_width="match_parent"android:layout_height="match_parent"><Viewandroid:layout_width="match_parent"android:layout_height="1dp"android:background="@color/bg_gray"/><LinearLayoutandroid:layout_width="match_parent"android:orientation="horizontal"android:paddingLeft="5dp"android:paddingRight="5dp"android:layout_height="30dp"><TextViewandroid:layout_width="0dp"android:layout_weight="1"android:layout_height="match_parent"android:text="日"android:gravity="center"android:textColor="@color/tv_44"android:textSize="14sp"/><TextViewandroid:layout_width="0dp"android:layout_weight="1"android:layout_height="match_parent"android:text="一"android:gravity="center"android:textColor="@color/tv_44"android:textSize="14sp"/><TextViewandroid:layout_width="0dp"android:layout_weight="1"android:layout_height="match_parent"android:text="二"android:gravity="center"android:textColor="@color/tv_44"android:textSize="14sp"/><TextViewandroid:layout_width="0dp"android:layout_weight="1"android:layout_height="match_parent"android:text="三"android:gravity="center"android:textColor="@color/tv_44"android:textSize="14sp"/><TextViewandroid:layout_width="0dp"android:layout_weight="1"android:layout_height="match_parent"android:text="四"android:gravity="center"android:textColor="@color/tv_44"android:textSize="14sp"/><TextViewandroid:layout_width="0dp"android:layout_weight="1"android:layout_height="match_parent"android:text="五"android:gravity="center"android:textColor="@color/tv_44"android:textSize="14sp"/><TextViewandroid:layout_width="0dp"android:layout_weight="1"android:layout_height="match_parent"android:text="六"android:gravity="center"android:textColor="@color/tv_44"android:textSize="14sp"/></LinearLayout><Viewandroid:layout_width="match_parent"android:layout_height="1dp"android:background="@color/bg_gray"/><包名.view.AutoFitRecycleViewandroid:id="@+id/recyclerview"android:layout_marginLeft="5dp"android:layout_marginRight="5dp"android:layout_width="match_parent"android:layout_height="wrap_content"></包名.view.AutoFitRecycleView>
</LinearLayout>

CalendarAdapter.java

public class CalendarAdapter extends RecyclerView.Adapter<CalendarAdapter.Holder> {private Context activity;private List<CalendarDataBean.ListCodeBean> datas;private String currentYMD;private String chooseDay;private final int firstDayOfWeek;public CalendarAdapter(Context activity, List<CalendarDataBean.ListCodeBean> datas,String currentYMD) {this.activity = activity;this.datas = datas;this.currentYMD = currentYMD;chooseDay = currentYMD;String[] date = currentYMD.split("-");int year = Integer.parseInt(date[0]);int month = Integer.parseInt(date[1]);//先得出 第"1"天是周几firstDayOfWeek = DateUtils.getFirstDayWeek(year, month, 1);}@Overridepublic Holder onCreateViewHolder(ViewGroup parent, int viewType) {View view = LayoutInflater.from(activity).inflate(R.layout.item_calendar, parent, false);return new Holder(view);}@Overridepublic void onBindViewHolder(Holder holder, final int position) {if (position >= firstDayOfWeek) {if ("1".equals(datas.get(position - firstDayOfWeek).timeStatus)) {//当天if ((DateUtils.currentYMD()).equals(datas.get(position - firstDayOfWeek).day)) {holder.iv_bg_day.setVisibility(View.VISIBLE);} else {holder.iv_bg_day.setVisibility(View.INVISIBLE);}//是否选中if (chooseDay.equals(datas.get(position - firstDayOfWeek).day)){holder.iv_bg.setImageResource(R.drawable.bg_choose);holder.iv_bg.setVisibility(View.VISIBLE);}else {//是否签到if ("1".equals(datas.get(position - firstDayOfWeek).status)) {holder.iv_bg.setImageResource(R.drawable.bg_sign);holder.iv_bg.setVisibility(View.VISIBLE);} else {holder.iv_bg.setVisibility(View.INVISIBLE);}}//是否早退if ("1".equals(datas.get(position - firstDayOfWeek).earlyStatus)) {holder.fv_flags.setLeaveEarly(true);} else {holder.fv_flags.setLeaveEarly(false);}//是否缺卡if ("1".equals(datas.get(position - firstDayOfWeek).singleStatus)) {holder.fv_flags.setLack(true);} else {holder.fv_flags.setLack(false);}//是否旷工if ("1".equals(datas.get(position - firstDayOfWeek).workStatus)) {holder.fv_flags.setAbsent(true);} else {holder.fv_flags.setAbsent(false);}//是否请假if ("1".equals(datas.get(position - firstDayOfWeek).approvingStatus)) {holder.fv_flags.setDayOff(true);} else {holder.fv_flags.setDayOff(false);}//是否迟到if ("1".equals(datas.get(position - firstDayOfWeek).lateStatus)) {holder.fv_flags.setLate(true);} else {holder.fv_flags.setLate(false);}//是否外勤if ("1".equals(datas.get(position - firstDayOfWeek).outStatus)) {holder.fv_flags.setOutWork(true);} else {holder.fv_flags.setOutWork(false);}holder.rl_item.setClickable(true);holder.rl_item.setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View v) {chooseDay = datas.get(position-firstDayOfWeek).day;notifyDataSetChanged();if (onItemChooseListener!=null) {onItemChooseListener.onItemChoose(chooseDay);}}});} else {holder.rl_item.setClickable(false);}holder.tv_num.setText((position - firstDayOfWeek + 1) + "");}else {holder.tv_num.setText("");holder.fv_flags.clear();holder.iv_bg.setVisibility(View.INVISIBLE);holder.iv_bg_day.setVisibility(View.INVISIBLE);}}@Overridepublic int getItemCount() {return datas.size() + firstDayOfWeek;}public class Holder extends RecyclerView.ViewHolder {private final RelativeLayout rl_item;private final ImageView iv_bg;private final ImageView iv_bg_day;private final TextView tv_num;private final FlagsView fv_flags;public Holder(View itemView) {super(itemView);rl_item = (RelativeLayout) itemView.findViewById(R.id.rl_item);iv_bg = (ImageView) itemView.findViewById(R.id.iv_bg);iv_bg_day = (ImageView) itemView.findViewById(R.id.iv_bg_day);tv_num = (TextView) itemView.findViewById(R.id.tv_num);fv_flags = (FlagsView) itemView.findViewById(R.id.fv_flags);}}public interface OnItemChooseListener{void onItemChoose(String chooseDay);}private OnItemChooseListener onItemChooseListener;public void setOnItemChooseListener(OnItemChooseListener onItemChooseListener) {this.onItemChooseListener = onItemChooseListener;}
}

item_calendar.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="match_parent"android:layout_centerHorizontal="true"android:layout_height="wrap_content"><RelativeLayoutandroid:id="@+id/rl_item"android:layout_width="wrap_content"android:layout_centerInParent="true"android:layout_height="wrap_content"><ImageViewandroid:id="@+id/iv_bg"android:layout_width="30dp"android:layout_height="30dp"android:src="@drawable/bg_sign"android:scaleType="center"android:visibility="invisible"/><ImageViewandroid:id="@+id/iv_bg_day"android:layout_width="30dp"android:layout_height="30dp"android:src="@drawable/circle_day"android:visibility="invisible"android:scaleType="center"/><TextViewandroid:id="@+id/tv_num"android:layout_width="30dp"android:layout_height="30dp"android:gravity="center"android:textColor="#000000"android:textSize="12sp"android:layout_centerHorizontal="true"android:text="12"/><包名.oa.FlagsViewandroid:id="@+id/fv_flags"android:layout_width="wrap_content"android:layout_height="10dp"android:layout_centerHorizontal="true"android:layout_below="@+id/iv_bg"android:layout_marginTop="2dp"/></RelativeLayout></RelativeLayout>

DateUtils.java

public class DateUtils {/*** 通过年份和月份 得到当月的日子个数** @param year* @param month* @return*/public static int getMonthDays(int year, int month) {
//        month++;switch (month) {case 1:case 3:case 5:case 7:case 8:case 10:case 12:return 31;case 4:case 6:case 9:case 11:return 30;case 2:if (((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0)) {return 29;} else {return 28;}default:return -1;}}/*** 返回当前月份几号位于周几** @param year  年份* @param month 月份,传入系统获取的,不需要正常的* @return 日:0 一:1      二:2      三:3      四:4      五:5      六:6*/public static int getFirstDayWeek(int year, int month,int day) {Calendar calendar = Calendar.getInstance();calendar.set(year, month-1, day);return calendar.get(Calendar.DAY_OF_WEEK)-1;}/*** 根据列明获取周** @param* @return*/public static String getWeekName(int year, int month,int day) {int column = getFirstDayWeek(year, month, day);switch (column) {case 0:return "周日";case 1:return "周一";case 2:return "周二";case 3:return "周三";case 4:return "周四";case 5:return "周五";case 6:return "周六";default:return "";}}/*** 得到日期字符串* @param date* @return  年月日时分秒*/public static String getTime(Date date) {SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm");return format.format(date);}/*** 得到日期字符串* @param date* @return  年月日*/public static String getTimeYMD(Date date) {SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");return format.format(date);}/*** 得到日期字符串* @param date 年月* @return*/public static String getTimeYM(Date date){SimpleDateFormat format = new SimpleDateFormat("yyyy-MM");return format.format(date);}/*** 得到日期字符串* @param date 年* @return*/public static String getTimeY(Date date){SimpleDateFormat format = new SimpleDateFormat("yyyy");return format.format(date);}/*** 获取当前年月日字符串* @return*/public static String currentYMD(){SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");return format.format(new Date());}/*** 获取当前年月日字符串* @return*/public static String currentYMD2(){SimpleDateFormat format = new SimpleDateFormat("yyyy-M-d");return format.format(new Date());}/*** 获取当前年月字符串** @return*/public static String currentYM(){SimpleDateFormat format = new SimpleDateFormat("yyyy-MM");return format.format(new Date());}/*** 获取当前年月字符串** @return*/public static String currentYM2(){SimpleDateFormat format = new SimpleDateFormat("yyyy-M");return format.format(new Date());}/*** 通过日期字符串获取日期对象* @param dateStr* @return*/public static Date Str2DateYMD(String dateStr)  {SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");Date date ;try{date = format.parse(dateStr);}catch (Exception e){Log.d("DateUtils.Str2DateYMD()","Str2DateYMD() returned: " + e.toString() );date = new Date();}return date;}public static Date Str2DateYM(String dateStr){SimpleDateFormat format = new SimpleDateFormat("yyyy-MM");Date date ;try{date = format.parse(dateStr);}catch (Exception e){Log.d("DateUtils.Str2DateYMD()","Str2DateYMD() returned: " + e.toString() );date = new Date();}return date;}/*** 获取当前所在月份* @return*/public static int getToday_MONTH(){Calendar calendar = Calendar.getInstance();calendar.setTime(new Date());return calendar.get(Calendar.MONTH);}/*** 获取当前所在天* @return*/public static int getToday_DAY(){Calendar calendar = Calendar.getInstance();calendar.setTime(new Date());return calendar.get(Calendar.DAY_OF_MONTH);}
}

自定义考勤统计日历(二)相关推荐

  1. 自定义考勤统计日历(一)

    在APP中实现日历的操作对于很多人来说或许都不太容易,因为根据要求的不同,日历的样式和显示的功能也不太一样,特别是对于一些初写代码,不太熟练写自定义接口的朋友,比如说我. 我们也会在网上经常看到一些日 ...

  2. 仿钉钉考勤统计页面的日历组件,通过日历展示每日考勤打卡情况,支持在日历上打两种不同类型的点,大致适配各种分辨率效果图

    原文链接:uniapp : 仿钉钉考勤统计页面的日历组件,通过日历展示每日考勤打卡情况,支持在日历上打两种不同类型的点,大致适配各种分辨率 - northwest - 博客园 (cnblogs.com ...

  3. 根据需求定制日历-二

    根据需求定制日历-二 使用引导 项目地址 demo下载地址 把相关类拷贝到自己项目目录里 在XML 布局文件中引入相关 CalendarView <?xml version="1.0& ...

  4. 基于QT的人脸识别考勤管理系统【二】

    前言: 上一篇我们实现了考勤管理系统的用户考勤打卡系统https://blog.csdn.net/qq_42449351/article/details/99716413,这一篇我将为大家带来这个系统 ...

  5. moran指数 r语言_白话空间统计之二十五:空间权重矩阵(四)R语言中的空间权重矩阵(2):不同空间关系对莫兰指数的影响...

    原标题:白话空间统计之二十五:空间权重矩阵(四)R语言中的空间权重矩阵(2):不同空间关系对莫兰指数的影响 上一篇,讲了R语言中的空间权重矩阵的结构,这一节讲讲R语言里面空间权重矩阵的自定义. 与Ar ...

  6. XamarinAndroid组件教程设置自定义子元素动画(二)

    XamarinAndroid组件教程设置自定义子元素动画(二) (9)打开MainActivity.cs文件,为RecylerView的子元素设置添加和删除时的透明动画效果.代码如下: --using ...

  7. 如何访问自定义键值的二维数组

    2019独角兽企业重金招聘Python工程师标准>>> <?php//访问自定义键值的二维数组$products = array(array('name'=>'apple ...

  8. NYOJ 240 小明的调查统计(二)

    小明的调查统计(二) 时间限制:1000 ms  |  内存限制:65535 KB 难度:1 描述 最近小明他们社团对理工全校每个班级进行了一次社会调查,他们对每同学的数学成绩进行了统计.小明的任务是 ...

  9. Android Gradle 自定义Task详解二:进阶

    转载请标明出处:http://blog.csdn.net/zhaoyanjun6/article/details/78523958 本文出自[赵彦军的博客] 系列目录 Android Gradle使用 ...

最新文章

  1. 调试JavaScript/VB Script脚本程序(IE篇)
  2. Android SystemProperties系统属性分析
  3. 怎么寻回执行页内操作时的错误磁盘的数据
  4. java 文件的编码 问题
  5. js_md5加密和base64的加密解密
  6. WCF发布到IIS 7.0,并以https访问
  7. 关于 API 定义 安全
  8. 使用rsync 实现服务器文件同步
  9. 教你自定义百度网盘分享密码 提取码
  10. python sorted lambda_详解python中的lambda与sorted函数
  11. 良心到难以置信的网站推(转自b站up主lks)
  12. Rasa 3.x 学习系列-Rasa 3.1+ ElasticSearch 8.2.0 对话机器人实战六
  13. 今天是10月24日程序员节,祝所有程序员节日快乐!
  14. html中siblings方法,siblings()
  15. bc伐木机器人_1+X | 工业机器人操作编程平台(HB-CZBC-C10)
  16. 经纪业务部负责人是什么工作
  17. python俄罗斯方块编程思路_少儿编程分享:手把手教你用Python编写俄罗斯方块(十)...
  18. 星际无限高级合伙人培训大会在深圳南山举行
  19. 最常用的linux命令大全(建议收藏)
  20. HTML案例--西式甜品网

热门文章

  1. k8s单节点无法启动pod
  2. Excel学习笔记之基础篇
  3. 从淘宝网买衣服, 感受淘宝
  4. 我不想在做桌面运维了、我想做linux运维、我也要运维高薪
  5. JAVA求班级男女生比例_java编程:给你一个班级的名单,随机分成6个组的问题解决办法...
  6. 计算机图形学(第四版)-第一个画线例子- 读书笔记P30
  7. Deliberated Domain Bridging for Domain Adaptive Semantic Segmentation
  8. excel应用技巧:F功能键诸多应用汇总
  9. 【今日头条2019,笔试题】机器人跳跃问题
  10. 阿里云数据盘挂载完整过程