forked from huanghaibin-dev/CalendarView
-
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
1 parent
53f78a8
commit 464faeb
Showing
14 changed files
with
795 additions
and
191 deletions.
There are no files selected for viewing
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
169 changes: 169 additions & 0 deletions
169
app/src/main/java/com/haibin/calendarviewproject/progress/ProgressActivity.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,169 @@ | ||
package com.haibin.calendarviewproject.progress; | ||
|
||
import android.annotation.SuppressLint; | ||
import android.content.Context; | ||
import android.content.Intent; | ||
import android.support.v7.widget.LinearLayoutManager; | ||
import android.view.View; | ||
import android.widget.RelativeLayout; | ||
import android.widget.TextView; | ||
|
||
import com.haibin.calendarview.Calendar; | ||
import com.haibin.calendarview.CalendarLayout; | ||
import com.haibin.calendarview.CalendarView; | ||
import com.haibin.calendarviewproject.Article; | ||
import com.haibin.calendarviewproject.ArticleAdapter; | ||
import com.haibin.calendarviewproject.R; | ||
import com.haibin.calendarviewproject.base.activity.BaseActivity; | ||
import com.haibin.calendarviewproject.colorful.ColorfulActivity; | ||
import com.haibin.calendarviewproject.group.GroupItemDecoration; | ||
import com.haibin.calendarviewproject.group.GroupRecyclerView; | ||
import com.haibin.calendarviewproject.index.IndexActivity; | ||
import com.haibin.calendarviewproject.simple.SimpleActivity; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class ProgressActivity extends BaseActivity implements | ||
CalendarView.OnDateSelectedListener, | ||
CalendarView.OnYearChangeListener, | ||
View.OnClickListener { | ||
|
||
TextView mTextMonthDay; | ||
|
||
TextView mTextYear; | ||
|
||
TextView mTextLunar; | ||
|
||
TextView mTextCurrentDay; | ||
|
||
CalendarView mCalendarView; | ||
|
||
RelativeLayout mRelativeTool; | ||
private int mYear; | ||
CalendarLayout mCalendarLayout; | ||
GroupRecyclerView mRecyclerView; | ||
|
||
public static void show(Context context) { | ||
context.startActivity(new Intent(context, ProgressActivity.class)); | ||
} | ||
|
||
|
||
@Override | ||
protected int getLayoutId() { | ||
return R.layout.activity_progress; | ||
} | ||
|
||
@SuppressLint("SetTextI18n") | ||
@Override | ||
protected void initView() { | ||
setStatusBarDarkMode(); | ||
mTextMonthDay = (TextView) findViewById(R.id.tv_month_day); | ||
mTextYear = (TextView) findViewById(R.id.tv_year); | ||
mTextLunar = (TextView) findViewById(R.id.tv_lunar); | ||
mRelativeTool = (RelativeLayout) findViewById(R.id.rl_tool); | ||
mCalendarView = (CalendarView) findViewById(R.id.calendarView); | ||
mTextCurrentDay = (TextView) findViewById(R.id.tv_current_day); | ||
mTextMonthDay.setOnClickListener(new View.OnClickListener() { | ||
@Override | ||
public void onClick(View v) { | ||
if (!mCalendarLayout.isExpand()) { | ||
mCalendarView.showYearSelectLayout(mYear); | ||
return; | ||
} | ||
mCalendarView.showYearSelectLayout(mYear); | ||
mTextLunar.setVisibility(View.GONE); | ||
mTextYear.setVisibility(View.GONE); | ||
mTextMonthDay.setText(String.valueOf(mYear)); | ||
} | ||
}); | ||
findViewById(R.id.fl_current).setOnClickListener(new View.OnClickListener() { | ||
@Override | ||
public void onClick(View v) { | ||
mCalendarView.scrollToCurrent(); | ||
} | ||
}); | ||
mCalendarLayout = (CalendarLayout) findViewById(R.id.calendarLayout); | ||
mCalendarView.setOnDateSelectedListener(this); | ||
mCalendarView.setOnYearChangeListener(this); | ||
mTextYear.setText(String.valueOf(mCalendarView.getCurYear())); | ||
mYear = mCalendarView.getCurYear(); | ||
mTextMonthDay.setText(mCalendarView.getCurMonth() + "月" + mCalendarView.getCurDay() + "日"); | ||
mTextLunar.setText("今日"); | ||
mTextCurrentDay.setText(String.valueOf(mCalendarView.getCurDay())); | ||
} | ||
|
||
@Override | ||
protected void initData() { | ||
List<Calendar> schemes = new ArrayList<>(); | ||
int year = mCalendarView.getCurYear(); | ||
int month = mCalendarView.getCurMonth(); | ||
|
||
schemes.add(getSchemeCalendar(year, month, 3, 0xFF40db25, "20")); | ||
schemes.add(getSchemeCalendar(year, month, 6, 0xFFe69138, "30")); | ||
schemes.add(getSchemeCalendar(year, month, 9, 0xFFdf1356, "33")); | ||
schemes.add(getSchemeCalendar(year, month, 12, 0xFFdf1356, "25")); | ||
schemes.add(getSchemeCalendar(year, month, 13, 0xFFedc56d, "50")); | ||
schemes.add(getSchemeCalendar(year, month, 14, 0xFFedc56d, "80")); | ||
schemes.add(getSchemeCalendar(year, month, 15, 0xFFaacc44, "20")); | ||
schemes.add(getSchemeCalendar(year, month, 18, 0xFFbc13f0, "70")); | ||
schemes.add(getSchemeCalendar(year, month, 25, 0xFF13acf0, "36")); | ||
schemes.add(getSchemeCalendar(year, month, 27, 0xFF13acf0, "95")); | ||
mCalendarView.setSchemeDate(schemes); | ||
|
||
mRecyclerView = (GroupRecyclerView) findViewById(R.id.recyclerView); | ||
mRecyclerView.setLayoutManager(new LinearLayoutManager(this)); | ||
mRecyclerView.addItemDecoration(new GroupItemDecoration<String, Article>()); | ||
mRecyclerView.setAdapter(new ArticleAdapter(this)); | ||
mRecyclerView.notifyDataSetChanged(); | ||
} | ||
|
||
|
||
@Override | ||
public void onClick(View v) { | ||
switch (v.getId()) { | ||
case R.id.ll_flyme: | ||
ProgressActivity.show(this); | ||
break; | ||
case R.id.ll_simple: | ||
SimpleActivity.show(this); | ||
break; | ||
case R.id.ll_colorful: | ||
ColorfulActivity.show(this); | ||
break; | ||
case R.id.ll_index: | ||
IndexActivity.show(this); | ||
break; | ||
} | ||
} | ||
|
||
private Calendar getSchemeCalendar(int year, int month, int day, int color, String text) { | ||
Calendar calendar = new Calendar(); | ||
calendar.setYear(year); | ||
calendar.setMonth(month); | ||
calendar.setDay(day); | ||
calendar.setSchemeColor(color);//如果单独标记颜色、则会使用这个颜色 | ||
calendar.setScheme(text); | ||
return calendar; | ||
} | ||
|
||
|
||
@SuppressLint("SetTextI18n") | ||
@Override | ||
public void onDateSelected(Calendar calendar, boolean isClick) { | ||
mTextLunar.setVisibility(View.VISIBLE); | ||
mTextYear.setVisibility(View.VISIBLE); | ||
mTextMonthDay.setText(calendar.getMonth() + "月" + calendar.getDay() + "日"); | ||
mTextYear.setText(String.valueOf(calendar.getYear())); | ||
mTextLunar.setText(calendar.getLunar()); | ||
mYear = calendar.getYear(); | ||
} | ||
|
||
|
||
@Override | ||
public void onYearChange(int year) { | ||
mTextMonthDay.setText(String.valueOf(year)); | ||
} | ||
|
||
|
||
} |
110 changes: 110 additions & 0 deletions
110
app/src/main/java/com/haibin/calendarviewproject/progress/ProgressMonthView.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,110 @@ | ||
package com.haibin.calendarviewproject.progress; | ||
|
||
import android.content.Context; | ||
import android.graphics.Canvas; | ||
import android.graphics.Paint; | ||
import android.graphics.RectF; | ||
|
||
import com.haibin.calendarview.Calendar; | ||
import com.haibin.calendarview.MonthView; | ||
|
||
/** | ||
* 精美进度风格 | ||
* Created by huanghaibin on 2018/2/8. | ||
*/ | ||
|
||
public class ProgressMonthView extends MonthView { | ||
|
||
private Paint mProgressPaint = new Paint(); | ||
private Paint mNoneProgressPaint = new Paint(); | ||
private int mRadius; | ||
|
||
public ProgressMonthView(Context context) { | ||
super(context); | ||
mProgressPaint.setAntiAlias(true); | ||
mProgressPaint.setStyle(Paint.Style.STROKE); | ||
mProgressPaint.setStrokeWidth(dipToPx(context, 2.2f)); | ||
mProgressPaint.setColor(0xBBf54a00); | ||
|
||
mNoneProgressPaint.setAntiAlias(true); | ||
mNoneProgressPaint.setStyle(Paint.Style.STROKE); | ||
mNoneProgressPaint.setStrokeWidth(dipToPx(context, 2.2f)); | ||
mNoneProgressPaint.setColor(0x90CfCfCf); | ||
} | ||
|
||
@Override | ||
protected void onPreviewHook() { | ||
mRadius = Math.min(mItemWidth, mItemHeight) / 11 * 4; | ||
|
||
} | ||
|
||
@Override | ||
protected boolean onDrawSelected(Canvas canvas, Calendar calendar, int x, int y, boolean hasScheme) { | ||
int cx = x + mItemWidth / 2; | ||
int cy = y + mItemHeight / 2; | ||
canvas.drawCircle(cx, cy, mRadius, mSelectedPaint); | ||
return false; | ||
} | ||
|
||
@Override | ||
protected void onDrawScheme(Canvas canvas, Calendar calendar, int x, int y) { | ||
int cx = x + mItemWidth / 2; | ||
int cy = y + mItemHeight / 2; | ||
|
||
int angle = getAngle(Integer.parseInt(calendar.getScheme())); | ||
|
||
RectF progressRectF = new RectF(cx - mRadius, cy - mRadius, cx + mRadius, cy + mRadius); | ||
canvas.drawArc(progressRectF, -90, angle, false, mProgressPaint); | ||
|
||
RectF noneRectF = new RectF(cx - mRadius, cy - mRadius, cx + mRadius, cy + mRadius); | ||
canvas.drawArc(noneRectF, angle - 90, 360 - angle, false, mNoneProgressPaint); | ||
|
||
} | ||
|
||
@Override | ||
protected void onDrawText(Canvas canvas, Calendar calendar, int x, int y, boolean hasScheme, boolean isSelected) { | ||
float baselineY = mTextBaseLine + y; | ||
int cx = x + mItemWidth / 2; | ||
|
||
if (isSelected) { | ||
canvas.drawText(String.valueOf(calendar.getDay()), | ||
cx, | ||
baselineY, | ||
mSelectTextPaint); | ||
} else if (hasScheme) { | ||
canvas.drawText(String.valueOf(calendar.getDay()), | ||
cx, | ||
baselineY, | ||
calendar.isCurrentDay() ? mCurDayTextPaint : | ||
calendar.isCurrentMonth() ? mSchemeTextPaint : mOtherMonthTextPaint); | ||
|
||
} else { | ||
canvas.drawText(String.valueOf(calendar.getDay()), cx, baselineY, | ||
calendar.isCurrentDay() ? mCurDayTextPaint : | ||
calendar.isCurrentMonth() ? mCurMonthTextPaint : mOtherMonthTextPaint); | ||
} | ||
} | ||
|
||
/** | ||
* 获取角度 | ||
* | ||
* @param progress 进度 | ||
* @return 获取角度 | ||
*/ | ||
private static int getAngle(int progress) { | ||
return (int) (progress * 3.6); | ||
} | ||
|
||
|
||
/** | ||
* 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); | ||
} | ||
} |
Oops, something went wrong.