forked from yannecer/NCalendar
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
26 changed files
with
563 additions
and
172 deletions.
There are no files selected for viewing
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
app/src/main/java/com/necer/ncalendar/activity/TestStretchActivity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package com.necer.ncalendar.activity; | ||
|
||
import android.os.Bundle; | ||
import android.support.annotation.Nullable; | ||
import android.support.v7.app.AppCompatActivity; | ||
import android.view.View; | ||
|
||
import com.necer.calendar.Miui10Calendar; | ||
import com.necer.ncalendar.R; | ||
import com.necer.ncalendar.painter.StretchPainter; | ||
import com.necer.painter.InnerPainter; | ||
|
||
import java.util.Arrays; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
public class TestStretchActivity extends AppCompatActivity { | ||
|
||
@Override | ||
protected void onCreate(@Nullable Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
setContentView(R.layout.activity_stretch); | ||
|
||
Miui10Calendar miui10Calendar = findViewById(R.id.miui10Calendar); | ||
miui10Calendar.setMonthStretchEnable(true); | ||
|
||
|
||
List<String> pointList = Arrays.asList("2019-07-01", "2019-07-19", "2019-07-25", "2019-05-23", "2019-01-01", "2018-12-23"); | ||
|
||
InnerPainter innerPainter = (InnerPainter) miui10Calendar.getCalendarPainter(); | ||
innerPainter.setPointList(pointList); | ||
|
||
|
||
Map<String, String> strMap = new HashMap<>(); | ||
strMap.put("2019-07-01", "测试"); | ||
strMap.put("2019-07-19", "测试1"); | ||
strMap.put("2019-07-25", "测试2"); | ||
strMap.put("2019-08-25", "测试3"); | ||
strMap.put("2019-08-28", "测试4"); | ||
strMap.put("2019-11-26", "测试5"); | ||
innerPainter.setStretchStrMap(strMap); | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
app/src/main/java/com/necer/ncalendar/painter/StretchPainter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package com.necer.ncalendar.painter; | ||
|
||
import android.content.Context; | ||
import android.graphics.Canvas; | ||
import android.graphics.Color; | ||
import android.graphics.Paint; | ||
import android.graphics.RectF; | ||
import android.text.TextUtils; | ||
|
||
import com.necer.painter.CalendarPainter; | ||
import com.necer.utils.CalendarUtil; | ||
|
||
import org.joda.time.LocalDate; | ||
|
||
import java.util.List; | ||
|
||
public class StretchPainter implements CalendarPainter { | ||
protected Paint mTextPaint; | ||
protected Paint mBgPaint; | ||
|
||
public StretchPainter(Context context) { | ||
mBgPaint = getPaint(); | ||
mTextPaint = getPaint(); | ||
mBgPaint.setColor(Color.parseColor("#ff7575")); | ||
mTextPaint.setTextSize(CalendarUtil.dp2px(context, 10)); | ||
mTextPaint.setColor(Color.parseColor("#000000")); | ||
} | ||
|
||
|
||
@Override | ||
public void onDrawToday(Canvas canvas, RectF rectF, LocalDate localDate, List<LocalDate> selectedDateList) { | ||
canvas.drawRect(rectF, mBgPaint); | ||
canvas.drawText(localDate.getDayOfMonth() + "", rectF.centerX(), getBaseLineY(rectF), mTextPaint); | ||
} | ||
|
||
@Override | ||
public void onDrawCurrentMonthOrWeek(Canvas canvas, RectF rectF, LocalDate localDate, List<LocalDate> selectedDateList) { | ||
canvas.drawRect(rectF, mBgPaint); | ||
canvas.drawText(localDate.getDayOfMonth() + "", rectF.centerX(), getBaseLineY(rectF), mTextPaint); | ||
} | ||
|
||
@Override | ||
public void onDrawLastOrNextMonth(Canvas canvas, RectF rectF, LocalDate localDate, List<LocalDate> selectedDateList) { | ||
canvas.drawRect(rectF, mBgPaint); | ||
canvas.drawText(localDate.getDayOfMonth() + "", rectF.centerX(), getBaseLineY(rectF), mTextPaint); | ||
} | ||
|
||
@Override | ||
public void onDrawDisableDate(Canvas canvas, RectF rectF, LocalDate localDate) { | ||
canvas.drawRect(rectF, mBgPaint); | ||
canvas.drawText(localDate.getDayOfMonth() + "", rectF.centerX(), getBaseLineY(rectF), mTextPaint); | ||
} | ||
|
||
private Paint getPaint() { | ||
Paint paint = new Paint(); | ||
paint.setAntiAlias(true); | ||
paint.setDither(true); | ||
paint.setTextAlign(Paint.Align.CENTER); | ||
return paint; | ||
} | ||
|
||
private int getBaseLineY(RectF rectF) { | ||
Paint.FontMetrics fontMetrics = mTextPaint.getFontMetrics(); | ||
float top = fontMetrics.top; | ||
float bottom = fontMetrics.bottom; | ||
int baseLineY = (int) (rectF.centerY() - top / 2 - bottom / 2); | ||
return baseLineY; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<?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"> | ||
|
||
|
||
<com.necer.calendar.Miui10Calendar | ||
android:id="@+id/miui10Calendar" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent"> | ||
|
||
|
||
<android.support.v4.widget.NestedScrollView | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent"> | ||
|
||
<LinearLayout | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
android:background="#cccccc" | ||
android:orientation="vertical"> | ||
|
||
<TextView | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
android:gravity="center" | ||
android:padding="15dp" | ||
android:text="测试月日历拉伸" | ||
android:textColor="#ffffff" | ||
android:textSize="18sp" /> | ||
|
||
</LinearLayout> | ||
|
||
</android.support.v4.widget.NestedScrollView> | ||
|
||
|
||
</com.necer.calendar.Miui10Calendar> | ||
|
||
</LinearLayout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.