Quellcode durchsuchen

1.完成日期样式

wsad5123 vor 5 Jahren
Ursprung
Commit
ee6599f77c

+ 19 - 6
app/src/main/java/com/tongyu/luck/happywork/ui/activity/cclient/clock/ClockMonthStatisticsActivity.java

@@ -3,15 +3,16 @@ package com.tongyu.luck.happywork.ui.activity.cclient.clock;
 import android.graphics.Typeface;
 import android.os.Bundle;
 import android.support.v4.widget.NestedScrollView;
-import android.view.MotionEvent;
 import android.view.View;
 import android.widget.LinearLayout;
 import android.widget.RelativeLayout;
 import android.widget.TextView;
 
-import com.haibin.calendarview.CalendarLayout;
+import com.haibin.calendarview.Calendar;
 import com.haibin.calendarview.CalendarView;
+import com.prolificinteractive.materialcalendarview.MaterialCalendarView;
 import com.tongyu.luck.happywork.R;
+import com.tongyu.luck.happywork.ui.widget.calendar.ClockMonthView;
 import com.tongyu.luck.happywork.ui.base.BaseActivity;
 import com.tongyu.luck.happywork.ui.mvp.cclient.contacts.ClockMonthStatisticsContacts;
 import com.tongyu.luck.happywork.ui.mvp.cclient.presenter.ClockMonthStatisticsPresenter;
@@ -55,12 +56,12 @@ public class ClockMonthStatisticsActivity extends BaseActivity<ClockMonthStatist
     TextView tvMoney;
     @BindView(R.id.tv_no_record)
     TextView tvNoRecord;
-    @BindView(R.id.cv_date)
-    CalendarView cvDate;
-    @BindView(R.id.cl_date)
-    CalendarLayout clDate;
+    @BindView(R.id.mcv_work_time)
+    MaterialCalendarView mcvWorkTime;
     @BindView(R.id.nsl_parent)
     NestedScrollView nslParent;
+    @BindView(R.id.cv_clock_date)
+    CalendarView cvClockDate;
 
     @Override
     public int getLayoutId() {
@@ -85,6 +86,18 @@ public class ClockMonthStatisticsActivity extends BaseActivity<ClockMonthStatist
         tvWorkHourTotal.setTypeface(typeFace);
         tvLoss.setTypeface(typeFace);
         tvMoney.setTypeface(typeFace);
+
+        cvClockDate.setMonthView(ClockMonthView.class);
+
+        java.util.Calendar date = java.util.Calendar.getInstance();
+        Calendar calendar = new Calendar();
+        calendar.setYear(date.get(java.util.Calendar.YEAR));
+        calendar.setMonth(date.get(java.util.Calendar.MONTH));
+        calendar.setDay(date.get(java.util.Calendar.DAY_OF_MONTH));
+        calendar.setSchemeColor(getResources().getColor(R.color.text_orange_fd));
+        cvClockDate.addSchemeDate(calendar);
+        cvClockDate.setSelectSingleMode();
+
     }
 
 }

+ 110 - 0
app/src/main/java/com/tongyu/luck/happywork/ui/widget/calendar/ClockMonthView.java

@@ -0,0 +1,110 @@
+package com.tongyu.luck.happywork.ui.widget.calendar;
+
+import android.content.Context;
+import android.graphics.Canvas;
+import android.graphics.Paint;
+
+import com.haibin.calendarview.Calendar;
+import com.haibin.calendarview.MonthView;
+import com.tongyu.luck.happywork.R;
+import com.tongyu.luck.happywork.baselibrary.utils.PxUtils;
+
+public class ClockMonthView extends MonthView {
+    /**
+     * 自定义魅族标记的文本画笔
+     */
+    private Paint mTextPaint = new Paint();
+
+    /**
+     * 自定义魅族标记的圆形背景
+     */
+    private Paint mSchemeWhitePaint = new Paint();
+
+    public ClockMonthView(Context context) {
+        super(context);
+
+        mTextPaint.setTextSize(getResources().getDimension(R.dimen.px42_14sp));
+        mTextPaint.setColor(0xffffffff);
+        mTextPaint.setAntiAlias(true);
+        mTextPaint.setFakeBoldText(true);
+        mTextPaint.setStyle(Paint.Style.FILL);
+        mTextPaint.setTextAlign(Paint.Align.CENTER);
+
+        mSchemeWhitePaint.setAntiAlias(true);
+
+    }
+
+    /**
+     * 绘制选中的日子
+     *
+     * @param canvas    canvas
+     * @param calendar  日历日历calendar
+     * @param x         日历Card x起点坐标
+     * @param y         日历Card y起点坐标
+     * @param hasScheme hasScheme 非标记的日期
+     * @return 返回true 则会继续绘制onDrawScheme,因为这里背景色不是是互斥的,所以返回true,返回false,则点击scheme标记的日子,则不继续绘制onDrawScheme,自行选择即可
+     */
+    @Override
+    protected boolean onDrawSelected(Canvas canvas, Calendar calendar, int x, int y, boolean hasScheme) {
+        int cx = x + mItemWidth / 2;
+        int cy = y + mItemHeight / 2;
+
+        mSelectedPaint.setStyle(Paint.Style.FILL);
+        mSelectedPaint.setColor(getResources().getColor(R.color.blue_01));
+        canvas.drawCircle(cx, cy, PxUtils.dip2px(17.5f), mSelectedPaint);
+        return true;
+    }
+
+    /**
+     * 绘制标记的事件日子
+     *
+     * @param canvas   canvas
+     * @param calendar 日历calendar
+     * @param x        日历Card x起点坐标
+     * @param y        日历Card y起点坐标
+     */
+    @Override
+    protected void onDrawScheme(Canvas canvas, Calendar calendar, int x, int y) {
+        int cx = x + mItemWidth / 2;
+        int cy = y + mItemHeight / 2;
+        int schemeY = cy + PxUtils.dip2px(17.5f);
+
+        mSchemeWhitePaint.setColor(getResources().getColor(R.color.white));
+        canvas.drawCircle(cx, schemeY, PxUtils.dip2px(4), mSchemeWhitePaint);
+        mSchemeWhitePaint.setColor(calendar.getSchemeColor());
+        canvas.drawCircle(cx, schemeY, PxUtils.dip2px(3), mSchemeWhitePaint);
+    }
+
+    /**
+     * 绘制文本
+     *
+     * @param canvas     canvas
+     * @param calendar   日历calendar
+     * @param x          日历Card x起点坐标
+     * @param y          日历Card y起点坐标
+     * @param hasScheme  是否是标记的日期
+     * @param isSelected 是否选中
+     */
+    @Override
+    protected void onDrawText(Canvas canvas, Calendar calendar, int x, int y, boolean hasScheme, boolean isSelected) {
+        int cx = x + mItemWidth / 2;
+        if (isSelected) {//优先绘制选择的
+            canvas.drawText(String.valueOf(calendar.getDay()), cx, y + mTextBaseLine,
+                    mSelectTextPaint);
+        } else {//最好绘制普通文本
+            canvas.drawText(String.valueOf(calendar.getDay()), cx, y + mTextBaseLine, calendar.isCurrentMonth() ? mCurMonthTextPaint : mOtherMonthTextPaint);
+        }
+    }
+
+    /**
+     * dp转px
+     *
+     * @param context context
+     * @param dpValue dp
+     * @return px
+     */
+    private static int dipToPx(Context context, float dpValue) {
+        final float scale = context.getResources().getDisplayMetrics().density;
+        return (int) (dpValue * scale + 0.5f);
+    }
+}

+ 185 - 196
app/src/main/res/layout/activity_clock_month_statistics.xml

@@ -198,238 +198,227 @@
             android:layout_height="1dp"
             android:background="@color/view_line_color_gray" />
 
-        <com.haibin.calendarview.CalendarLayout
-            android:id="@+id/cl_date"
+        <com.haibin.calendarview.CalendarView
+            android:id="@+id/cv_clock_date"
+            android:layout_width="match_parent"
+            android:layout_height="372dp"
+            android:background="@color/white"
+            app:day_text_size="@dimen/px42_14sp"
+            app:month_view_show_mode="mode_all"
+            app:selected_text_color="@color/white"
+            app:week_text_color="@color/text_gray_99"
+            app:week_text_size="@dimen/px36_12sp" />
+
+        <com.prolificinteractive.materialcalendarview.MaterialCalendarView
+            android:id="@+id/mcv_work_time"
+            android:layout_width="match_parent"
+            android:layout_height="372dp"
+            android:background="@color/white"
+            android:visibility="gone"
+            app:mcv_arrowColor="@color/white"
+            app:mcv_dateTextAppearance="@style/Material_Date_Clock_TextStyle"
+            app:mcv_firstDayOfWeek="monday"
+            app:mcv_leftArrowMask="@color/transparent"
+            app:mcv_selectionColor="@color/text_blue_32"
+            app:mcv_selectionMode="multiple"
+            app:mcv_showOtherDates="all"
+            app:mcv_tileHeight="0dp"
+            app:mcv_weekDayTextAppearance="@style/Material_Date_Clock_Week_TextStyle" />
+
+        <LinearLayout
             android:layout_width="match_parent"
             android:layout_height="wrap_content"
-            android:orientation="vertical"
-            app:calendar_content_view_id="@+id/nsv"
-            app:default_status="shrink">
+            android:orientation="vertical">
 
-            <com.haibin.calendarview.CalendarView
-                android:id="@+id/cv_date"
+            <View
                 android:layout_width="match_parent"
-                android:layout_height="372dp"
-                android:background="@color/white" />
+                android:layout_height="1dp"
+                android:background="@color/view_line_color_gray" />
 
-            <android.support.v4.widget.NestedScrollView
-                android:id="@+id/nsv"
+            <LinearLayout
                 android:layout_width="match_parent"
-                android:layout_height="match_parent">
+                android:layout_height="wrap_content"
+                android:layout_marginTop="11dp"
+                android:layout_marginBottom="11dp"
+                android:background="@color/white"
+                android:orientation="vertical"
+                android:paddingLeft="20dp"
+                android:paddingTop="24dp"
+                android:paddingRight="20dp"
+                android:paddingBottom="48dp">
+
+                <TextView
+                    android:id="@+id/tv_rules"
+                    android:layout_width="wrap_content"
+                    android:layout_height="wrap_content"
+                    android:text="规则:自由上下班打卡 00:00-24:00
+当日打卡2次,工时10小时"
+                    android:textColor="@color/text_black_66"
+                    android:textSize="@dimen/px39_13sp" />
+
+                <TextView
+                    android:id="@+id/tv_no_record"
+                    android:layout_width="match_parent"
+                    android:layout_height="wrap_content"
+                    android:layout_marginTop="48dp"
+                    android:layout_marginBottom="48dp"
+                    android:gravity="center"
+                    android:text="@string/clock_day_no_record"
+                    android:textColor="@color/text_black"
+                    android:textSize="@dimen/px51_17sp"
+                    android:visibility="gone" />
 
                 <LinearLayout
+                    android:id="@+id/ll_clock_data"
                     android:layout_width="match_parent"
                     android:layout_height="wrap_content"
+                    android:layout_marginTop="33dp"
+                    android:layout_marginBottom="33dp"
                     android:orientation="vertical">
 
-                    <View
-                        android:layout_width="match_parent"
-                        android:layout_height="1dp"
-                        android:background="@color/view_line_color_gray" />
-
                     <LinearLayout
+                        android:id="@+id/ll_clock_in"
                         android:layout_width="match_parent"
-                        android:layout_height="wrap_content"
-                        android:layout_marginTop="11dp"
-                        android:layout_marginBottom="11dp"
-                        android:background="@color/white"
-                        android:orientation="vertical"
-                        android:paddingLeft="20dp"
-                        android:paddingTop="24dp"
-                        android:paddingRight="20dp"
-                        android:paddingBottom="48dp">
-
-                        <TextView
-                            android:id="@+id/tv_rules"
-                            android:layout_width="wrap_content"
-                            android:layout_height="wrap_content"
-                            android:text="规则:自由上下班打卡 00:00-24:00
-当日打卡2次,工时10小时"
-                            android:textColor="@color/text_black_66"
-                            android:textSize="@dimen/px39_13sp" />
+                        android:layout_height="79dp"
+                        android:orientation="horizontal">
 
-                        <TextView
-                            android:id="@+id/tv_no_record"
-                            android:layout_width="match_parent"
-                            android:layout_height="wrap_content"
-                            android:layout_marginTop="48dp"
-                            android:layout_marginBottom="48dp"
-                            android:gravity="center"
-                            android:text="@string/clock_day_no_record"
-                            android:textColor="@color/text_black"
-                            android:textSize="@dimen/px51_17sp"
-                            android:visibility="gone" />
+                        <RelativeLayout
+                            android:layout_width="8dp"
+                            android:layout_height="match_parent">
+
+                            <View
+                                android:id="@+id/v_clock_in_line"
+                                android:layout_width="1dp"
+                                android:layout_height="match_parent"
+                                android:layout_centerHorizontal="true"
+                                android:layout_marginTop="27dp"
+                                android:background="@color/text_gray_dd" />
+
+                            <View
+                                android:layout_width="8dp"
+                                android:layout_height="8dp"
+                                android:layout_marginTop="23dp"
+                                android:background="@drawable/corners_gray_bb_5dp" />
+
+                        </RelativeLayout>
 
                         <LinearLayout
-                            android:id="@+id/ll_clock_data"
                             android:layout_width="match_parent"
                             android:layout_height="wrap_content"
-                            android:layout_marginTop="33dp"
-                            android:layout_marginBottom="33dp"
+                            android:layout_gravity="center_vertical"
+                            android:layout_marginLeft="15dp"
                             android:orientation="vertical">
 
-                            <LinearLayout
-                                android:id="@+id/ll_clock_in"
+                            <TextView
+                                android:id="@+id/tv_clock_in_time"
                                 android:layout_width="match_parent"
-                                android:layout_height="79dp"
-                                android:orientation="horizontal">
-
-                                <RelativeLayout
-                                    android:layout_width="8dp"
-                                    android:layout_height="match_parent">
-
-                                    <View
-                                        android:id="@+id/v_clock_in_line"
-                                        android:layout_width="1dp"
-                                        android:layout_height="match_parent"
-                                        android:layout_centerHorizontal="true"
-                                        android:layout_marginTop="27dp"
-                                        android:background="@color/text_gray_dd" />
-
-                                    <View
-                                        android:layout_width="8dp"
-                                        android:layout_height="8dp"
-                                        android:layout_marginTop="23dp"
-                                        android:background="@drawable/corners_gray_bb_5dp" />
-
-                                </RelativeLayout>
-
-                                <LinearLayout
-                                    android:layout_width="match_parent"
-                                    android:layout_height="wrap_content"
-                                    android:layout_gravity="center_vertical"
-                                    android:layout_marginLeft="15dp"
-                                    android:orientation="vertical">
-
-                                    <TextView
-                                        android:id="@+id/tv_clock_in_time"
-                                        android:layout_width="match_parent"
-                                        android:layout_height="24dp"
-                                        android:gravity="center_vertical"
-                                        android:text="上班 08:28"
-                                        android:textColor="@color/text_black"
-                                        android:textSize="@dimen/px51_17sp" />
-
-                                    <TextView
-                                        android:id="@+id/tv_clock_in_time_local"
-                                        android:layout_width="match_parent"
-                                        android:layout_height="20dp"
-                                        android:layout_marginTop="5dp"
-                                        android:drawableLeft="@mipmap/ic_clock_local"
-                                        android:drawablePadding="5dp"
-                                        android:gravity="center_vertical"
-                                        android:text="无锡夏普电子元器件有限公司"
-                                        android:textColor="@color/text_black_66"
-                                        android:textSize="@dimen/px42_14sp" />
-                                </LinearLayout>
-                            </LinearLayout>
-
-                            <LinearLayout
-                                android:id="@+id/ll_clock_out"
+                                android:layout_height="24dp"
+                                android:gravity="center_vertical"
+                                android:text="上班 08:28"
+                                android:textColor="@color/text_black"
+                                android:textSize="@dimen/px51_17sp" />
+
+                            <TextView
+                                android:id="@+id/tv_clock_in_time_local"
                                 android:layout_width="match_parent"
-                                android:layout_height="79dp"
-                                android:orientation="horizontal">
-
-                                <RelativeLayout
-                                    android:layout_width="8dp"
-                                    android:layout_height="match_parent">
-
-                                    <View
-                                        android:layout_width="1dp"
-                                        android:layout_height="match_parent"
-                                        android:layout_centerHorizontal="true"
-                                        android:layout_marginBottom="52dp"
-                                        android:background="@color/text_gray_dd" />
-
-                                    <View
-                                        android:layout_width="8dp"
-                                        android:layout_height="8dp"
-                                        android:layout_marginTop="23dp"
-                                        android:background="@drawable/corners_gray_bb_5dp" />
-
-                                </RelativeLayout>
-
-                                <LinearLayout
-                                    android:layout_width="match_parent"
-                                    android:layout_height="wrap_content"
-                                    android:layout_gravity="center_vertical"
-                                    android:layout_marginLeft="15dp"
-                                    android:orientation="vertical">
-
-                                    <TextView
-                                        android:id="@+id/tv_clock_out_time"
-                                        android:layout_width="match_parent"
-                                        android:layout_height="24dp"
-                                        android:gravity="center_vertical"
-                                        android:text="下班 08:28"
-                                        android:textColor="@color/text_black"
-                                        android:textSize="@dimen/px51_17sp" />
-
-                                    <TextView
-                                        android:id="@+id/tv_clock_out_time_local"
-                                        android:layout_width="match_parent"
-                                        android:layout_height="20dp"
-                                        android:layout_marginTop="5dp"
-                                        android:drawableLeft="@mipmap/ic_clock_local"
-                                        android:drawablePadding="5dp"
-                                        android:gravity="center_vertical"
-                                        android:text="无锡夏普电子元器件有限公司"
-                                        android:textColor="@color/text_black_66"
-                                        android:textSize="@dimen/px42_14sp" />
-                                </LinearLayout>
-                            </LinearLayout>
+                                android:layout_height="20dp"
+                                android:layout_marginTop="5dp"
+                                android:drawableLeft="@mipmap/ic_clock_local"
+                                android:drawablePadding="5dp"
+                                android:gravity="center_vertical"
+                                android:text="无锡夏普电子元器件有限公司"
+                                android:textColor="@color/text_black_66"
+                                android:textSize="@dimen/px42_14sp" />
                         </LinearLayout>
+                    </LinearLayout>
+
+                    <LinearLayout
+                        android:id="@+id/ll_clock_out"
+                        android:layout_width="match_parent"
+                        android:layout_height="79dp"
+                        android:orientation="horizontal">
+
+                        <RelativeLayout
+                            android:layout_width="8dp"
+                            android:layout_height="match_parent">
+
+                            <View
+                                android:layout_width="1dp"
+                                android:layout_height="match_parent"
+                                android:layout_centerHorizontal="true"
+                                android:layout_marginBottom="52dp"
+                                android:background="@color/text_gray_dd" />
+
+                            <View
+                                android:layout_width="8dp"
+                                android:layout_height="8dp"
+                                android:layout_marginTop="23dp"
+                                android:background="@drawable/corners_gray_bb_5dp" />
+
+                        </RelativeLayout>
 
                         <LinearLayout
                             android:layout_width="match_parent"
                             android:layout_height="wrap_content"
-                            android:orientation="horizontal">
+                            android:layout_gravity="center_vertical"
+                            android:layout_marginLeft="15dp"
+                            android:orientation="vertical">
 
                             <TextView
-                                android:layout_width="0dp"
-                                android:layout_height="wrap_content"
-                                android:layout_weight="1"
-                                android:text="@string/clock_today_repay_title"
+                                android:id="@+id/tv_clock_out_time"
+                                android:layout_width="match_parent"
+                                android:layout_height="24dp"
+                                android:gravity="center_vertical"
+                                android:text="下班 08:28"
                                 android:textColor="@color/text_black"
-                                android:textSize="@dimen/px39_13sp" />
+                                android:textSize="@dimen/px51_17sp" />
 
                             <TextView
-                                android:id="@+id/tv_money"
-                                android:layout_width="wrap_content"
-                                android:layout_height="wrap_content"
-                                android:text="37.0"
-                                android:textColor="@color/blue_01"
-                                android:textSize="@dimen/px84_28sp" />
-
-                            <TextView
-                                android:layout_width="wrap_content"
-                                android:layout_height="wrap_content"
-                                android:layout_marginLeft="5dp"
-                                android:text="@string/yuan"
-                                android:textColor="@color/text_black"
-                                android:textSize="@dimen/px39_13sp"
-                                android:textStyle="bold" />
+                                android:id="@+id/tv_clock_out_time_local"
+                                android:layout_width="match_parent"
+                                android:layout_height="20dp"
+                                android:layout_marginTop="5dp"
+                                android:drawableLeft="@mipmap/ic_clock_local"
+                                android:drawablePadding="5dp"
+                                android:gravity="center_vertical"
+                                android:text="无锡夏普电子元器件有限公司"
+                                android:textColor="@color/text_black_66"
+                                android:textSize="@dimen/px42_14sp" />
                         </LinearLayout>
                     </LinearLayout>
                 </LinearLayout>
 
-            </android.support.v4.widget.NestedScrollView>
-        </com.haibin.calendarview.CalendarLayout>
-
-        <!--   <com.prolificinteractive.materialcalendarview.MaterialCalendarView
-               android:id="@+id/mcv_work_time"
-               android:layout_width="match_parent"
-               android:layout_height="372dp"
-               android:background="@color/white"
-               app:mcv_arrowColor="@color/white"
-               app:mcv_dateTextAppearance="@style/Material_Date_TextStyle"
-               app:mcv_firstDayOfWeek="monday"
-               app:mcv_headerTextAppearance="@style/Material_Date_TextStyle"
-               app:mcv_leftArrowMask="@color/transparent"
-               app:mcv_selectionColor="@color/text_blue_32"
-               app:mcv_selectionMode="multiple"
-               app:mcv_showOtherDates="all"
-               app:mcv_tileHeight="0dp"
-               app:mcv_weekDayTextAppearance="@style/Material_Date_Week_TextStyle" />-->
+                <LinearLayout
+                    android:layout_width="match_parent"
+                    android:layout_height="wrap_content"
+                    android:orientation="horizontal">
+
+                    <TextView
+                        android:layout_width="0dp"
+                        android:layout_height="wrap_content"
+                        android:layout_weight="1"
+                        android:text="@string/clock_today_repay_title"
+                        android:textColor="@color/text_black"
+                        android:textSize="@dimen/px39_13sp" />
+
+                    <TextView
+                        android:id="@+id/tv_money"
+                        android:layout_width="wrap_content"
+                        android:layout_height="wrap_content"
+                        android:text="37.0"
+                        android:textColor="@color/blue_01"
+                        android:textSize="@dimen/px84_28sp" />
+
+                    <TextView
+                        android:layout_width="wrap_content"
+                        android:layout_height="wrap_content"
+                        android:layout_marginLeft="5dp"
+                        android:text="@string/yuan"
+                        android:textColor="@color/text_black"
+                        android:textSize="@dimen/px39_13sp"
+                        android:textStyle="bold" />
+                </LinearLayout>
+            </LinearLayout>
+        </LinearLayout>
     </LinearLayout>
 </android.support.v4.widget.NestedScrollView>

+ 1 - 0
app/src/main/res/values/colors.xml

@@ -46,6 +46,7 @@
     <color name="text_orange_d">#FF7D0B</color>
     <color name="text_orange_e">#FF6630</color>
     <color name="text_orange_fe">#FE7235</color>
+    <color name="text_orange_fd">#FD7235</color>
     <color name="orange_light">#FFF4E5</color>
     <color name="text_gray">#cccccc</color>
     <color name="text_gray_d8">#d8d8d8</color>

+ 1 - 0
baselibrary/src/main/res/values/strings.xml

@@ -8,4 +8,5 @@
 
     <string name="permissions_install_app">请打开安装权限</string>
 
+
 </resources>