|
|
@@ -40,11 +40,16 @@ public class CalendarView extends View implements View.OnTouchListener {
|
|
|
init();
|
|
|
}
|
|
|
|
|
|
+ public int getDownIndex() {
|
|
|
+ return downIndex;
|
|
|
+ }
|
|
|
+
|
|
|
private void init() {
|
|
|
//获取当前日期对象
|
|
|
- curDate = today = new Date();
|
|
|
+ downDate = curDate = today = new Date();
|
|
|
calendar = Calendar.getInstance();
|
|
|
calendar.setTime(curDate);
|
|
|
+ downIndex = calendar.get(Calendar.DAY_OF_MONTH);
|
|
|
surface = new Surface();
|
|
|
surface.density = getResources().getDisplayMetrics().density;
|
|
|
setBackgroundColor(surface.bgColor);
|
|
|
@@ -82,7 +87,6 @@ public class CalendarView extends View implements View.OnTouchListener {
|
|
|
|
|
|
@Override
|
|
|
protected void onDraw(Canvas canvas) {
|
|
|
- // 画框
|
|
|
float weekTextY = surface.monthHeight + surface.weekHeight * 3 / 4f;
|
|
|
for (int i = 0; i < surface.weekText.length; i++) {
|
|
|
float weekTextX = i
|
|
|
@@ -117,6 +121,8 @@ public class CalendarView extends View implements View.OnTouchListener {
|
|
|
if (todayIndex != -1 && i == todayIndex) {
|
|
|
color = surface.todayNumberColor;
|
|
|
drawCellText(canvas, i, "今", color);
|
|
|
+ if (downDate == null)
|
|
|
+ drawCellBg(canvas, i, surface.cellDownColor);
|
|
|
} else {
|
|
|
drawCellText(canvas, i, date[i] + "", color);
|
|
|
}
|
|
|
@@ -223,13 +229,6 @@ public class CalendarView extends View implements View.OnTouchListener {
|
|
|
private void drawCellBg(Canvas canvas, int index, int color) {
|
|
|
int x = getXByIndex(index);
|
|
|
int y = getYByIndex(index);
|
|
|
-// surface.cellBgPaint.setColor(color);
|
|
|
-// float left = surface.cellWidth * (x - 1) + surface.borderWidth;
|
|
|
-// float top = surface.monthHeight + surface.weekHeight + (y - 1)
|
|
|
-// * surface.cellHeight + surface.borderWidth;
|
|
|
-// canvas.drawRect(left, top, left + surface.cellWidth
|
|
|
-// - surface.borderWidth, top + surface.cellHeight
|
|
|
-// - surface.borderWidth, surface.cellBgPaint);
|
|
|
float cellY = surface.monthHeight + surface.weekHeight + (y - 1)
|
|
|
* surface.cellHeight + //当前日期框最上方
|
|
|
surface.cellHeight * 9 / 16f;//当前框的中心Y
|
|
|
@@ -238,14 +237,13 @@ public class CalendarView extends View implements View.OnTouchListener {
|
|
|
float radius = Math.min(surface.cellHeight, surface.cellWidth) * (3 / 8f);//获取最短的长度的
|
|
|
// 绘制圆,参数一是中心点的x轴,参数二是中心点的y轴,参数三是半径,参数四是paint对象;
|
|
|
canvas.drawCircle(cellX, cellY, radius, surface.cellBgPaint);
|
|
|
-
|
|
|
}
|
|
|
|
|
|
private void drawDownOrSelectedBg(Canvas canvas) {
|
|
|
- // down and not up
|
|
|
if (downDate != null) {
|
|
|
drawCellBg(canvas, downIndex, surface.cellDownColor);
|
|
|
}
|
|
|
+
|
|
|
}
|
|
|
|
|
|
private boolean isLastMonth(int i) {
|
|
|
@@ -320,9 +318,8 @@ public class CalendarView extends View implements View.OnTouchListener {
|
|
|
private void setSelectedDateByCoor(float x, float y) {
|
|
|
if (y > surface.monthHeight + surface.weekHeight) {
|
|
|
int m = (int) (Math.floor(x / surface.cellWidth) + 1);
|
|
|
- int n = (int) (Math
|
|
|
- .floor((y - (surface.monthHeight + surface.weekHeight))
|
|
|
- / Float.valueOf(surface.cellHeight)) + 1);
|
|
|
+ int n = (int) (Math.floor((y - (surface.monthHeight + surface.weekHeight))
|
|
|
+ / Float.valueOf(surface.cellHeight)) + 1);
|
|
|
int index = (n - 1) * 7 + m - 1;
|
|
|
if (index < curStartIndex || curEndIndex <= index) return;
|
|
|
downIndex = index;
|