排班表实现-----Android

预约挂号界面实现-----Android

  • 预约界面
    • 界面设计
    • 界面实现
      • 一周数据展示
      • 日期切换联动一周数据展示

预约界面

界面设计

  1. 实现效果展示:
    排班表实现-----Android_第1张图片
    排班表实现-----Android_第2张图片

界面实现

一周数据展示

日期切换联动一周数据展示

  1. 主界面实现:SimpleCalendarView , CalendarTableView
  2. 布局文件:排班表实现-----Android_第3张图片

分两部分:头:左右切换日期 body: 利用canvas画出每天排班情况,通过CalendarTableView展示

	
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="195dp"
    android:orientation="vertical">

    <LinearLayout
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:weightSum="5"
        android:layout_height="40dp">
        <LinearLayout
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:gravity="right"
            android:layout_weight="0.5">
            <ImageView
                android:id="@+id/time_left_img"
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:paddingLeft="10dp"
                android:paddingRight="10dp"
                android:src="@drawable/ic_calendar_left" />
        LinearLayout>

        <TextView
            android:id="@+id/current_time_tv"
            android:layout_width="0dp"
            android:layout_weight="4"
            android:gravity="center"
            android:text="2019年04月03日 - 2019年04月09日"
            android:layout_height="match_parent"
            android:textColor="@color/black"
            android:textSize="15dp" />
        <LinearLayout
            android:gravity="left"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="0.5">
            <ImageView
                android:id="@+id/time_right_img"
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:paddingLeft="10dp"
                android:paddingRight="10dp"
                android:src="@drawable/ic_calendar_right" />
        LinearLayout>

    LinearLayout>

    <com.trustsource.dm.myview.CalendarTableView
        android:id="@+id/main_simple_view"
        android:layout_width="match_parent"
        android:layout_height="145dp" />


LinearLayout>
  1. 左右切换日期功能的实现:
	private void init() {

        View simpleCalendar = LayoutInflater.from(mContext).inflate(R.layout.simple_calendar_view, this);
        calendarTableView = (CalendarTableView) simpleCalendar.findViewById(R.id.main_simple_view);
        currentDateTv = (TextView) simpleCalendar.findViewById(R.id.current_time_tv);
        leftImg = (ImageView) simpleCalendar.findViewById(R.id.time_left_img);
        rightImg = (ImageView) simpleCalendar.findViewById(R.id.time_right_img);

        operateDatesLeft();
      
        //目前只显示一周内的,所以把左右点击事件屏蔽

        leftImg.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                if (operateNums > 0) {
                    operateNums--;
                    operateDatesLeft();
                }
            }
        });

        rightImg.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                if (operateNums<1) {
                    operateNums++;
                    operateDatesRight();
                }
            }
        });
    }
    //计算当前一周日期并显示在界面
    private void operateDatesLeft() {
        dateList.clear();
        dayList1.clear();
        dayList2.clear();//dayList2,dateList2用来表示点击下一页需要展示的数据
        dateList.addAll(TimeUtils.getFeatureDate(15));
        for (int i = 0;i<7;i++){
            dateList1.add(dateList.get(i));
        }
        for (String data:dateList1){
            dayList1.add(dateToWeek(data));
        }
        startDate = dateList.get(0);
        endDate = dateList.get(6);
        currentDateTv.setText(startDate + " - " + endDate);
        calendarTableView.setDateList(TimeUtils.dateListToDayList(dateList1));
        calendarTableView.setDayList(dayList1);
        flag = true;
        calendarTableView.setFlag(flag);
    }
    //计算当前一周日期并显示在界面
    private void operateDatesRight() {
        dateList.clear();
        dayList2.clear();
        dayList1.clear();
        dateList.addAll(TimeUtils.getFeatureDate(15));
        for (int i = 7;i<dateList.size();i++){
            dateList2.add(dateList.get(i));
        }
        for (String data:dateList2){
            dayList2.add(dateToWeek(data));
        }
        startDate = dateList.get(7);
        endDate = dateList.get(dateList.size()-1);
        currentDateTv.setText(startDate + " - " + endDate);
        calendarTableView.setDateList(TimeUtils.dateListToDayList(dateList2));
        calendarTableView.setDayList(dayList2);
        flag = false;
        calendarTableView.setFlag(flag);

    }

 /**
     * 日期转星期
     *
     * @param datetime
     * @return
     */
    public static String dateToWeek(String datetime) {
        SimpleDateFormat f = new SimpleDateFormat("yyyy年MM月dd日");
        String[] weekDays = { "日", "一", "二", "三", "四", "五", "六" };
        Calendar cal = Calendar.getInstance(); // 获得一个日历
        Date datet = null;
        try {
            datet = f.parse(datetime);
            cal.setTime(datet);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        int w = cal.get(Calendar.DAY_OF_WEEK) - 1; // 指示一个星期中的某天。
        if (w < 0)
            w = 0;
        return weekDays[w];
    }

CalendarTableView类

	package com.trustsource.dm.myview;

import android.content.Context;
import android.content.SharedPreferences;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;

import android.text.TextUtils;
import android.util.AttributeSet;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.widget.AdapterView;

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.trustsource.dm.entity.AppointScheduleEntity;
import com.trustsource.dm.myview.base.RowAndColumnEntity;

import java.lang.reflect.Type;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

/**
 * 简易日历表格布局
 */

public class CalendarTableView extends View {
    private String TAG = "CalendarTableView.class";
    private Paint paint;
    private DisplayMetrics mDisplayMetrics;
    //星期字体颜色  默认黑色
    private int mWeekdayColor = Color.parseColor("#000000");

    //线的颜色
    private int mLineColor = Color.parseColor("#EDEDED");

    //未选中布局颜色  默认白色
    private int mUnSelectColor = Color.parseColor("#FFFFFF");
    //选中布局颜色  默认蓝色
    private int mSelectColor = Color.parseColor("#5dacfa");

    //当前状态已满背景色
    private int mFullBGColor = Color.parseColor("#FFFFFF");

    //当前状态已满文字颜色
    private int mFullTextColor = Color.parseColor("#666666");

    private static final int NUM_COLUMNS = 8;
    private static final int NUM_ROWS = 3;
    private SharedPreferences sp;

    //每一格的宽度和高度
    private int mColumnSize, mRowSize;
    //用户选中的行和列数
    private int checkRow, checkColumn;
    //控件的总宽度和总高度
    private int width, height;
    //用来保存可以被选中的view的横纵坐标
    private List<RowAndColumnEntity> rowAndColumnList = new ArrayList<>();

    //上午数据列表
    private List<AppointScheduleEntity> amList = new ArrayList<>();
    //下午数据列表
    private List<AppointScheduleEntity> pmList = new ArrayList<>();


    private List<String> dayList = new ArrayList<>();
    private List<Integer> dateList = new ArrayList<>();
    private String[] timeString = new String[]{"上午", "下午"};
    private boolean flag ;





    public CalendarTableView(Context context,AttributeSet attrs) {
        super(context,attrs);
        sp = getContext().getSharedPreferences("dparams", Context.MODE_PRIVATE);
        String jsonamList = sp.getString("amList",null);

        String jsonpmList = sp.getString("pmList",null);

        if (jsonamList!=null){
            Gson gson = new Gson();
            Type type = new TypeToken<List<AppointScheduleEntity>>(){}.getType();
            // ListamList = new ArrayList<>();
            amList = gson.fromJson(jsonamList,type);
//            for (AppointScheduleEntity entity:amList){
//               String head = entity.getDoctorInfo().getUsername();
//                Log.d(TAG, "CalendarTableView: +_+++++++++++++++++++++++ceshishi"+head);
//            }

        }
        if (jsonpmList!=null){
            Gson gson = new Gson();
            Type type = new TypeToken<List<AppointScheduleEntity>>(){}.getType();
            pmList = gson.fromJson(jsonpmList,type);
//            String fixid = pmList.get(1).getFixid();
//            Log.d(TAG, "CalendarTableView: fixid"+fixid);
        }
   

    }

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        Log.d(TAG, "onMeasure: +++++++++++++++++++++++++++onMeasure");
        mDisplayMetrics = getResources().getDisplayMetrics();
        int widthSize = MeasureSpec.getSize(widthMeasureSpec);
        int widthMode = MeasureSpec.getMode(widthMeasureSpec);

        int heightSize = MeasureSpec.getSize(heightMeasureSpec);
        int heightMode = MeasureSpec.getMode(heightMeasureSpec);

        if (heightMode == MeasureSpec.AT_MOST) {
            heightSize = mDisplayMetrics.densityDpi * 30;
        }
        if (widthMode == MeasureSpec.AT_MOST) {
            widthSize = mDisplayMetrics.densityDpi * 300;
        }
        setMeasuredDimension(widthSize, heightSize);
    }



    @Override
    protected void onDraw(Canvas canvas) {
        Log.d(TAG, "onDraw: ++++++++++++++++++++++++++++++onDraw");
        paint = new Paint();
        //每次绘制清空已选
        rowAndColumnList.clear();
        initSize();
        //设置监测当前行数
       //int row = 0;
        //int row = 0;
        //行
       // for (int row = 0; row < 4; row++) {
            for (int j = 0; j < NUM_ROWS; j++) {
            //    for (int row = 0;row<3;row++){


                //进行画线
                paint.setColor(mLineColor);
                paint.setStrokeWidth(4);
                canvas.drawLine(0, mRowSize * j, width, mRowSize * j, paint);

                //因为第一行有些特殊,单独拿出来绘制第一行
                // boolean jresult = (j==0);
                //   int result = j;
                //   Log.d(TAG, "onDraw: jresult"+jresult+"j is "+j);
                if (j == 0) {
                   int row = 0;
                    //绘制列
                    for (int i = 0; i < NUM_COLUMNS; i++) {
                        //进行画格子左边的竖线
                        paint.setColor(mLineColor);
                        paint.setStrokeWidth(4);
                        canvas.drawLine(mColumnSize * i, 0, mColumnSize * i, mRowSize, paint);

                        paint.setColor(Color.parseColor("#f5f5f5"));

                        //绘制背景色矩形
                        int startRecX = mColumnSize * i;
                        int startRecY = 0;
                        int endRecX = startRecX + mColumnSize;
                        int endRecY = mRowSize;

                        canvas.drawRect(startRecX, startRecY, endRecX, endRecY, paint);

                        //第一格不设置任何信息
                        if (i != 0) {

                            String text = dayList.get(i - 1);
                            int fontWidth = (int) paint.measureText(text);
                            //设置文字居中
                            int startX = mColumnSize * i + (mColumnSize - fontWidth) / 2;
                            int startY = mRowSize / 2;

                            //设置星期
                            paint.setColor(mWeekdayColor);
                            paint.setTextSize(40);
                            canvas.drawText(text, startX, startY, paint);
                            Log.d(TAG, "onDraw: +++++星期" + text);

                            //设置底部日期
                            paint.setTextSize(35);
                            paint.setColor(Color.parseColor("#6f6f6f"));
                            int date = dateList.get(i - 1);
                            Log.d(TAG, "onDraw: date is +++++++++++" + date);
                            //获取文字宽度
                            fontWidth = (int) paint.measureText(date + "");
                            //设置文字居中
                            startX = mColumnSize * i + (mColumnSize - fontWidth) / 2;
                            canvas.drawText(date + "", startX, startY + mRowSize / 3, paint);
                        }
                    }
                }
                if (j == 1) {
                    //绘制第二行数据
                   int row = 1;
                    paint.setTextSize(40);
                    paint.setColor(mWeekdayColor);
                    String text = timeString[j - 1];
                    int fontWidth = (int) paint.measureText(text);
                    //设置文字居中
                    int startX = (mColumnSize - fontWidth) / 2;
                    int startY = (int) (mRowSize / 2 - (paint.ascent() + paint.descent()) / 2);
                    canvas.drawText(text, startX, startY + mRowSize * j, paint);
                    //绘制列
                    String curdate = null;
                    for (int i = 0; i < NUM_COLUMNS; i++) {
                        int startRecX = mColumnSize * i;
                        int startRecY = mRowSize * (row);
                        int endRecX = startRecX + mColumnSize;
                        int endRecY = startRecY + mRowSize;
                        //进行画格子左边的竖线
                        paint.setColor(mLineColor);
                        paint.setStrokeWidth(4);
                        canvas.drawLine(mColumnSize * i, mRowSize * (row), mColumnSize * i, mRowSize * row, paint);
                        if (amList != null && amList.size() > 0) {
                            if (flag==true){
                            Log.d(TAG, "onDraw: " + "开始绘图");

                            switch (i) {
                                case 1:
                                        if (amList.get(i-1).getFixflag().equals("1")&&amList.get(i-1).getSignnum()<amList.get(i-1).getSignmax()) {
                                            curdate = "true";
                                        }else {
                                            curdate = "null";
                                        }
                                    break;
                                case 2:
                                    if (amList.get(i-1).getFixflag().equals("1")&&amList.get(i-1).getSignnum()<amList.get(i-1).getSignmax()) {
                                        curdate = "true";
                                    }else {
                                        curdate = "null";
                                    }
                                    break;
                                case 3:
                                    if (amList.get(i-1).getFixflag().equals("1")&&amList.get(i-1).getSignnum()<amList.get(i-1).getSignmax()) {
                                        curdate = "true";
                                    }else {
                                        curdate = "null";
                                    }
                                    break;
                                case 4:
                                    if (amList.size()<5){
                                        curdate = "null";
                                    }else {
                                        Log.d(TAG, "onDraw: +" + dateToWeek(amList.get(i-1).getSigndate()));
                                        if (amList.get(i-1).getFixflag().equals("1")&&amList.get(i-1).getSignnum()<amList.get(i-1).getSignmax()) {
                                            Log.d(TAG, "fixflag: "+amList.get(i-1).getFixflag());
                                            curdate = "true";
                                        }else {
                                            curdate = "null";
                                        }
                                    }
                                    break;
                                case 5:
                                    if (amList.size()<5){
                                        curdate = "null";
                                    }else {
                                        Log.d(TAG, "onDraw: +" + dateToWeek(amList.get(i-1).getSigndate()));
                                        if (amList.get(i-1).getFixflag().equals("1")&&amList.get(i-1).getSignnum()<amList.get(i-1).getSignmax()) {
                                            Log.d(TAG, "fixflag: "+amList.get(i-1).getFixflag());
                                            curdate = "true";
                                        }else {
                                            curdate = "null";
                                        }
                                    }
                                    break;
                                case 6:
                                    if (amList.size()<5){
                                        curdate = "null";
                                    }else {
                                        Log.d(TAG, "onDraw: +" + dateToWeek(amList.get(i-1).getSigndate()));
                                        if (amList.get(i-1).getFixflag().equals("1")&&amList.get(i-1).getSignnum()<amList.get(i-1).getSignmax()) {
                                            Log.d(TAG, "fixflag: "+amList.get(i-1).getFixflag());
                                            curdate = "true";
                                        }else {
                                            curdate = "null";
                                        }
                                    }
                                    break;
                                case 7:
                                    if (amList.size()<5){
                                        curdate = "null";
                                    }else {
                                        Log.d(TAG, "onDraw: +" + dateToWeek(amList.get(i-1).getSigndate()));
                                        if (amList.get(i-1).getFixflag().equals("1")&&amList.get(i-1).getSignnum()<amList.get(i-1).getSignmax()) {
                                            Log.d(TAG, "fixflag: "+amList.get(i-1).getFixflag());
                                            curdate = "true";
                                        }else {
                                            curdate = "null";
                                        }
                                    }
                                    break;

                                }
                            }else{
                                switch (i) {
                                    case 1:
                                        if (amList.get(7).getFixflag().equals("1")&&amList.get(7).getSignnum()<amList.get(i-1).getSignmax()) {
                                           // Log.d(TAG, "fixflag: "+amList.get(7).getFixflag()+"signnum"+amList.get(7).getSignnum()+"signmax"+amList.get(i-1).getSignmax());
                                            curdate = "true";
                                        }else {
                                           // Log.d(TAG, "fixflag: "+amList.get(7).getFixflag()+"signnum"+amList.get(7).getSignnum()+"signmax"+amList.get(i-1).getSignmax());
                                            curdate = "null";
                                        }
                                        break;
                                    case 2:
                                        if (amList.get(8).getFixflag().equals("1")&&amList.get(8).getSignnum()<amList.get(i-1).getSignmax()) {
                                            Log.d(TAG, "fixflag: "+amList.get(8).getFixflag());
                                            curdate = "true";
                                        }else {
                                            curdate = "null";
                                        }
                                        break;
                                    case 3:
                                        if (amList.get(9).getFixflag().equals("1")&&amList.get(9).getSignnum()<amList.get(i-1).getSignmax()) {
                                            Log.d(TAG, "fixflag: "+amList.get(9).getFixflag());
                                            curdate = "true";
                                        }else {
                                            curdate = "null";
                                        }
                                        break;
                                    case 4:
                                        curdate = "null";
                                        break;
                                    case 5:
                                        curdate = "null";
                                        break;
                                    case 6:
                                        curdate = "null";
                                        break;
                                    case 7:
                                        curdate = "null";
                                        break;
                                }
                            }
                            if (TextUtils.isEmpty(curdate)) {
                                //为空的话表示当天不能被预约,背景设为白色
                                if (i != 0) {
                                    //绘制背景色白色矩形
                                    paint.setColor(mUnSelectColor);
                                    canvas.drawRect(startRecX, startRecY, endRecX, endRecY, paint);
                                }

                            } else {
                                /**
                                 * 这里用来判断数据是否可预约
                                 */
                                //   String datas[] = curData.split("\\|");
                                if (curdate.equals("true")) {
                                    //  if (datas[0].equals("true")) {
                                     Log.d(TAG, "row: _________________________"+row+"i is"+i);
                                    //保存可以被预约的项
                                    RowAndColumnEntity rowAndColumnEntity = new RowAndColumnEntity(row, i);
                                    rowAndColumnList.add(rowAndColumnEntity);
                                    //表示可以预约,绘制背景色红色矩形
                                    //绘制红色色矩形
                                    paint.setColor(mSelectColor);
                                    //选中之后绘制文字
                                    canvas.drawCircle((endRecX - startRecX) / 5 + startRecX + 38, (endRecY - startRecY) / 2 + startRecY, 55, paint);
                                    paint.setTextSize(30);
                                    paint.setColor(mUnSelectColor);
                                    paint.setFakeBoldText(true);
                                    canvas.drawText("预约", (endRecX - startRecX) / 5 + startRecX + 8, (endRecY - startRecY) / 2 + startRecY + 13, paint);
                                } else if (curdate.equals("null")){
                                    //当前已满
                                    //绘制背景色白色矩形
                                    paint.setColor(mUnSelectColor);
                                    canvas.drawRect(startRecX, startRecY, endRecX, endRecY, paint);
                                    paint.setTextSize(30);
                                    paint.setColor(mFullTextColor);
                                    canvas.drawText("无号", (endRecX - startRecX) / 5 + startRecX + 10,
                                            (endRecY - startRecY) / 2 + startRecY + 13, paint);
                                }else {
                                    paint.setColor(mUnSelectColor);
                                    canvas.drawRect(startRecX, startRecY, endRecX, endRecY, paint);
                                    paint.setTextSize(30);
                                    paint.setColor(mFullTextColor);
                                    canvas.drawText("已满", (endRecX - startRecX) / 5 + startRecX + 10,
                                            (endRecY - startRecY) / 2 + startRecY + 13, paint);
                                }
                            }

                        }

                    }

                }
                if (j == 2) {
                  int  row = 2;
                    paint.setTextSize(40);
                    paint.setColor(mWeekdayColor);
                    String text = timeString[j - 1];
                    int fontWidth = (int) paint.measureText(text);
                    //设置文字居中
                    int startX = (mColumnSize - fontWidth) / 2;
                    int startY = (int) (mRowSize / 2 - (paint.ascent() + paint.descent()) / 2);
                    canvas.drawText(text, startX, startY + mRowSize * j, paint);
                    //绘制列
                    String curdatep = null;
                    for (int i = 0; i < NUM_COLUMNS; i++) {
                        int startRecX = mColumnSize * i;
                        int startRecY = mRowSize * (row);
                        int endRecX = startRecX + mColumnSize;
                        int endRecY = startRecY + mRowSize;

                        //进行画格子左边的竖线
                        paint.setColor(mLineColor);
                        paint.setStrokeWidth(4);
                        canvas.drawLine(mColumnSize * i, mRowSize * (row), mColumnSize * i, mRowSize * row, paint);
                        if (pmList != null && pmList.size() > 0) {
                            if (flag==true){
                            switch (i) {
                                case 1:
                                    if (pmList.get(i-1).getFixflag().equals("1")&&pmList.get(i-1).getSignnum()<pmList.get(i-1).getSignmax()) {
                                        Log.d(TAG, "fixflag: "+pmList.get(i-1).getFixflag());
                                        curdatep = "true";
                                    }else {
                                        curdatep = "null";
                                    }
                                    break;
                                case 2:
                                    if (pmList.get(i-1).getFixflag().equals("1")&&pmList.get(i-1).getSignnum()<pmList.get(i-1).getSignmax()) {
                                        Log.d(TAG, "fixflag: "+pmList.get(i-1).getFixflag());
                                        curdatep = "true";
                                    }else {
                                        curdatep = "null";
                                    }
                                    break;
                                case 3:
                                    if (pmList.get(i-1).getFixflag().equals("1")&&pmList.get(i-1).getSignnum()<pmList.get(i-1).getSignmax()) {
                                        Log.d(TAG, "fixflaghahah: "+pmList.get(i-1).getFixflag()+"signnum"+pmList.get(i-1).getSignnum()+"signmax"+pmList.get(i-1).getSignmax()+"is 3");
                                        curdatep = "true";
                                    }else {
                                        Log.d(TAG, "fixflaghahah: "+pmList.get(i-1).getFixflag()+"signnum"+pmList.get(i-1).getSignnum()+"signmax"+pmList.get(i-1).getSignmax()+"is 3");
                                        curdatep = "null";
                                    }
                                    break;
                                case 4:
                                    if (pmList.size()<5){
                                        curdatep = "null";
                                    }else {
                                        if (pmList.get(i-1).getFixflag().equals("1")&&pmList.get(i-1).getSignnum()<pmList.get(i-1).getSignmax()) {
                                            Log.d(TAG, "fixflaghahah: "+pmList.get(i-1).getFixflag()+"signnum"+pmList.get(i-1).getSignnum()+"signmax"+pmList.get(i-1).getSignmax()+"is 4");
                                            curdatep = "true";
                                        }else {
                                            Log.d(TAG, "fixflaghahah: "+pmList.get(i-1).getFixflag()+"signnum"+pmList.get(i-1).getSignnum()+"signmax"+pmList.get(i-1).getSignmax()+"is 4");
                                            curdatep = "null";
                                        }
                                    }
                                    break;
                                case 5:
                                    if (pmList.size()<5){
                                        curdatep = "null";
                                    }else {
                                        if (pmList.get(i-1).getFixflag().equals("1")&&pmList.get(i-1).getSignnum()<pmList.get(i-1).getSignmax()) {
                                            Log.d(TAG, "fixflag: "+pmList.get(i-1).getFixflag());
                                            curdatep = "true";
                                        }else {
                                            curdatep = "null";
                                        }
                                    }
                                    break;
                                case 6:
                                    if (pmList.size()<5){
                                        curdatep = "null";
                                    }else {
                                        if (pmList.get(i-1).getFixflag().equals("1")&&pmList.get(i-1).getSignnum()<pmList.get(i-1).getSignmax()) {
                                            Log.d(TAG, "fixflag: "+pmList.get(i-1).getFixflag());
                                            curdatep = "true";
                                        }else {
                                            curdatep = "null";
                                        }
                                    }
                                    break;
                                case 7:
                                    if (pmList.size()<5){
                                        curdatep = "null";
                                    }else {
                                        if (pmList.get(i-1).getFixflag().equals("1")&&pmList.get(i-1).getSignnum()<pmList.get(i-1).getSignmax()) {
                                            Log.d(TAG, "fixflag: "+pmList.get(i-1).getFixflag());
                                            curdatep = "true";
                                        }else {
                                            curdatep = "null";
                                        }
                                    }
                                    break;
                                }
                            }else{
                                switch (i) {
                                    case 1:
                                        if (pmList.get(7).getFixflag().equals("1")&&pmList.get(7).getSignnum()<pmList.get(i-1).getSignmax()) {
                                            Log.d(TAG, "fixflag: "+pmList.get(i-1).getFixflag());
                                            curdatep = "true";
                                        }else {
                                            curdatep = "null";
                                        }
                                        break;
                                    case 2:
                                        if (pmList.get(8).getFixflag().equals("1")&&pmList.get(8).getSignnum()<pmList.get(i-1).getSignmax()) {
                                            Log.d(TAG, "fixflag: "+pmList.get(i-1).getFixflag());
                                            curdatep = "true";
                                        }else {
                                            curdatep = "null";
                                        }
                                        break;
                                    case 3:
                                        if (pmList.get(9).getFixflag().equals("1")&&pmList.get(9).getSignnum()<pmList.get(i-1).getSignmax()) {
                                            Log.d(TAG, "fixflag: "+pmList.get(i-1).getFixflag());
                                            curdatep = "true";
                                        }else {
                                            curdatep = "null";
                                        }
                                        break;
                                    case 4:
                                        curdatep = "null";
                                        break;
                                    case 5:
                                        curdatep = "null";
                                        break;
                                    case 6:
                                        curdatep = "null";
                                        break;
                                    case 7:
                                        curdatep = "null";
                                        break;
                            }
                        }
                        if (TextUtils.isEmpty(curdatep)) {
                            //为空的话表示当天不能被预约,背景设为白色
                            if (i != 0) {
                                //绘制背景色白色矩形
                                paint.setColor(mUnSelectColor);
                                canvas.drawRect(startRecX, startRecY, endRecX, endRecY, paint);
                            }

                        } else {
                            /**
                             * 这里用来判断数据是否可预约
                             */
                            //   String datas[] = curData.split("\\|");
                            if (curdatep.equals("true")) {
                                //  if (datas[0].equals("true")) {
                                // Log.d(TAG, "onDraw: _________________________"+row);
                                //保存可以被预约的项
                                RowAndColumnEntity rowAndColumnEntity = new RowAndColumnEntity(row, i);
                                rowAndColumnList.add(rowAndColumnEntity);
                                //表示可以预约,绘制背景色蓝色矩形
                                //绘制蓝色色矩形
                                paint.setColor(mSelectColor);
                                //选中之后绘制文字
                                canvas.drawCircle((endRecX - startRecX) / 5 + startRecX + 38, (endRecY - startRecY) / 2 + startRecY, 55, paint);
                                paint.setTextSize(30);
                                paint.setColor(mUnSelectColor);
                                paint.setFakeBoldText(true);
                                canvas.drawText("预约", (endRecX - startRecX) / 5 + startRecX + 8, (endRecY - startRecY) / 2 + startRecY + 13, paint);
                            } else if (curdatep.equals("null")){
                                //当前已满
                                //绘制背景色白色矩形
                                paint.setColor(mUnSelectColor);
                                canvas.drawRect(startRecX, startRecY, endRecX, endRecY, paint);
                                paint.setTextSize(30);
                                paint.setColor(mFullTextColor);
                                canvas.drawText("无号 ", (endRecX - startRecX) / 5 + startRecX + 10,
                                        (endRecY - startRecY) / 2 + startRecY + 13, paint);
                            }else {
                                //当前已满
                                //绘制背景色白色矩形
                                paint.setColor(mUnSelectColor);
                                canvas.drawRect(startRecX, startRecY, endRecX, endRecY, paint);
                                paint.setTextSize(30);
                                paint.setColor(mFullTextColor);
                                canvas.drawText("已满", (endRecX - startRecX) / 5 + startRecX + 10,
                                        (endRecY - startRecY) / 2 + startRecY + 13, paint);
                            }
                        }

                    }
                }

            }

            //进行画边界线
            paint.setColor(Color.parseColor("#5dacfa"));
            paint.setStrokeWidth(4);
            canvas.drawLine(0, 0, width, 0, paint);
            canvas.drawLine(0, 0, 0, height, paint);
            canvas.drawLine(width, 0, width, height, paint);
            canvas.drawLine(0, height, width, height, paint);
        }

    }
    /**
     * 初始化列宽行高
     */
    private void initSize() {
        width = getWidth();
        height = getHeight();
        mColumnSize = width / NUM_COLUMNS;
        mRowSize = height / NUM_ROWS;
    }

    //将日期列表传递过来
    public void setDateList(List<Integer> dateList) {
        this.dateList = dateList;
        clearCheckedItem();
        //通知刷新
        invalidate();
    }
    //将星期列表传递过来
    public void setDayList(List<String> dayList){
        this.dayList = dayList;
        clearCheckedItem();
        invalidate();
    }

    public void setFlag(boolean flags){
        this.flag = flags;
        clearCheckedItem();
        invalidate();
    }

    //用来获取用户点击屏幕的坐标
    private int downX = 0, downY = 0;

    @Override
    public boolean onTouchEvent(MotionEvent event) {
        int eventCode = event.getAction();
        switch (eventCode) {
            case MotionEvent.ACTION_DOWN:
                downX = (int) event.getX();
                downY = (int) event.getY();
                break;
            case MotionEvent.ACTION_MOVE:
                break;
            case MotionEvent.ACTION_UP:
                int upX = (int) event.getX();
                int upY = (int) event.getY();
                if (Math.abs(upX - downX) < 10 && Math.abs(upY - downY) < 10) {//点击事件
                    Log.d(TAG, "onTouchEvent: "+"x:"+(upX + downX) / 2+"y:"+(upY + downY) / 2);
                    doClickAction((upX + downX) / 2, (upY + downY) / 2);
                }
                break;
        }
        return true;
    }

 
    /**
     * 执行点击事件
     *
     * @param x
     * @param y
     */
    private void doClickAction(int x, int y) {
        int row = y / mRowSize;
        int column = x / mColumnSize;
        Log.d(TAG, "doClickAction: "+"row:"+row+"column"+column);

        //第一行和第一列都不能被点击
        if (row != 0 && column != 0 && checkIsContain(row, column)) {
            Log.d(TAG, "doClickActiondoClickAction: "+column);
            showConfirmDialog(row,column);
            //保存用户选中的item
           /*if (checkRow == row && checkColumn == column) {
                //返回当前选中的时间以及第几列
               onCalendarItemClickListener.itemClick(timeString[row - 1], column);
               Log.d(TAG, "doClickAction: ++++++++========"+timeString[row-1]+"dddddddddd"+column);
                //跳转之后进行清空操作
               clearCheckedItem();
           } else {
                setCheckedItem(row, column);
               Log.d(TAG, "doClickAction: +**********************row is "+row+"*****\"column is \""+column);
            }*/
        }
        invalidate();
    }

    private void showConfirmDialog(final int row, final int column){
        String apm = null;
        if (row==1){
            apm = "08:30~12:00";
            List<AppointScheduleEntity> stringList = new ArrayList<AppointScheduleEntity>();
            int restAmount = amList.get(column-1).getSignmax()-amList.get(column-1).getSignnum();
            String signdate = amList.get(column-1).getSigndate();
            String fixid = amList.get(column-1).getFixid();
            stringList.add(new AppointScheduleEntity(apm,restAmount,amList.get(column-1).getDoctorInfo(),signdate,fixid));
            final OptionBottomDialog optionBottomDialog = new OptionBottomDialog(getContext(), stringList);
            optionBottomDialog.setItemClickListener(new AdapterView.OnItemClickListener() {
                @Override
                public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                    optionBottomDialog.dismiss();
                }
            });
        }if (row==2){
            apm = "13:00~18:00";
            List<AppointScheduleEntity> stringList = new ArrayList<AppointScheduleEntity>();
            //Log.d(TAG, "showConfirmDialog: "+column);
            int restAmount = pmList.get(column-1).getSignmax()-pmList.get(column-1).getSignnum();
            Log.d(TAG, "showConfirmDialog: restAmount"+restAmount);
            String signdate = pmList.get(column-1).getSigndate();
            String fixid = pmList.get(column-1).getFixid();
            stringList.add(new AppointScheduleEntity(apm,restAmount,pmList.get(column-1).getDoctorInfo(),signdate,fixid));
            final OptionBottomDialog optionBottomDialog = new OptionBottomDialog(getContext(), stringList);
            optionBottomDialog.setItemClickListener(new AdapterView.OnItemClickListener() {
                @Override
                public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                    optionBottomDialog.dismiss();
                }
            });
        }


    }

    /**
     * 判断是否包含当前点击的坐标
     *
     * @param row    行
     * @param column 列
     * @return false  表示不 包含   ,true表示包含
     */
    private boolean checkIsContain(int row, int column) {
        for (RowAndColumnEntity rowAndColumnEntity : rowAndColumnList) {
            //包含就可以点击
            if (row == rowAndColumnEntity.getRowNum() && column == rowAndColumnEntity.getColumnNum()) {
                return true;
            }
        }
        return false;
    }

    /**
     *设置选中的项
     */
    private void setCheckedItem(int checkRow, int checkColumn) {
        this.checkRow = checkRow;
        this.checkColumn = checkColumn;
    }

    /**
     * 清除选中的项
     */
    private void clearCheckedItem() {
        this.checkRow = 0;
        this.checkColumn = 0;
    }

    public interface OnCalendarItemClickListener {
        void itemClick(String time, int column);
    }

    private OnCalendarItemClickListener onCalendarItemClickListener;

    public void setOnCalendarItemClickListener(OnCalendarItemClickListener onCalendarItemClickListener) {
        this.onCalendarItemClickListener = onCalendarItemClickListener;
    }

    /**
     * 日期转星期
     *
     * @param datetime
     * @return
     */
    public static int dateToWeek(String datetime) {
        SimpleDateFormat f = new SimpleDateFormat("yyyyMMdd");
        int[] weekDays = { 7,1,2,3,4,5,6 };
        Calendar cal = Calendar.getInstance(); // 获得一个日历
        Date datet = null;
        try {
            datet = f.parse(datetime);
            cal.setTime(datet);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        int w = cal.get(Calendar.DAY_OF_WEEK) - 1; // 指示一个星期中的某天。
        if (w < 0)
            w = 0;
        return weekDays[w];
    }
    public static String currdate(Date date){
        //date = new Date();
        SimpleDateFormat format = new SimpleDateFormat("yyyyMMdd");
        String  result = format.format(date);
        return result;
    }
    /**
     * 获取未来 第 past 天的日期
     * @param past
     * @return
     */
    public static String getFetureDate(int past) {
        Calendar calendar = Calendar.getInstance();
        calendar.set(Calendar.DAY_OF_YEAR, calendar.get(Calendar.DAY_OF_YEAR) + past);
        Date today = calendar.getTime();
        SimpleDateFormat format = new SimpleDateFormat("yyyyMMdd");
        String result = format.format(today);
        return result;
    }


    }


	<select id="querySignList" resultMap="SignResultMap" parameterType="Object">
	select tuser.userid expertuserid,
	       tuser.signdate signdate,
	       tuser.signap signap,
	       tuser.signmax signmax,
	       tfix.fixid fixid,
	       case when tfix.userid is null then '0' else '1' end fixflag,
	       nvl(tsign.signnum,0) signnum
	from 
	(
	  select userid,signdate,signap,signmax
	  from dm_sys_expertinfo e,
	      (select to_char(sysdate + level-1,'YYYY-MM-DD') signdate from dual
	        connect by level &lt;= (select to_number(dataname2) 
	                               from dm_param_static 
	                              where typecode = 'REGISTER' 
	                                and datacode = 'LIMIT_DAY' 
	                                and datacode2 = 'ALL')) tdate,
	      (select datacode2 signap,to_number(dataname2) signmax
	        from dm_param_static 
	       where typecode = 'REGISTER' 
	         and datacode = 'LIMIT_NUM') tln
	) tuser,
	(select userid,fix_date,fix_ap ,fixid
	  from dm_data_expert_fix fix
	 where fix_date &gt;=to_char(sysdate,'YYYY-MM-DD')
	   and fix_date &lt;= to_char((select sysdate + to_number(dataname2) 
	                      from dm_param_static 
	                     where typecode = 'REGISTER' 
	                       and datacode = 'LIMIT_DAY' 
	                       and datacode2 = 'ALL'),'YYYY-MM-DD')
	) tfix,
	(select userid_expert,f.fix_ap,f.fix_date,count(1) signnum
	   from dm_data_register_log l,
	        dm_data_expert_fix f
	  where l.fixid = f.fixid
	    and f.fix_date &gt;=to_char(sysdate,'YYYY-MM-DD')
	    and f.fix_date &lt;=to_char((select sysdate + to_number(dataname2) 
	                         from dm_param_static 
	                        where typecode = 'REGISTER' 
	                          and datacode = 'LIMIT_DAY' 
	                          and datacode2 = 'ALL'),'YYYY-MM-DD')
	    and l.CANCEL_TAG is null
	  group by userid_expert,f.fix_ap,f.fix_date
	) tsign
	where tuser.userid = tfix.userid(+)
	  and tuser.signdate = tfix.fix_date(+)
	  and tuser.signap = tfix.fix_ap(+)
	  and tuser.userid = tsign.userid_expert(+)
	  and tuser.signdate = tsign.fix_date(+)
	  and tuser.signap = tsign.fix_ap(+)
	<if test="expertuserid != null and expertuserid != ''" >
	  and tuser.userid =  #{expertuserid}
	</if>
	order by tuser.userid,
	       tuser.signdate,
	       tuser.signap
</select>

你可能感兴趣的:(android)