Skip to content

Commit

Permalink
新增两款demo
Browse files Browse the repository at this point in the history
  • Loading branch information
huanghaibin-dev committed Feb 8, 2018
1 parent 53f78a8 commit 464faeb
Show file tree
Hide file tree
Showing 14 changed files with 795 additions and 191 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ compile 'com.haibin:calendarview:3.2.2'
<img src="https://github.com/huanghaibin-dev/CalendarView/blob/master/app/src/main/assets/meizu.png" height="650"/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<img src="https://github.com/huanghaibin-dev/CalendarView/blob/master/app/src/main/assets/meizu_shrink.png" height="650"/>
### 下标和多彩风格
<img src="https://github.com/huanghaibin-dev/CalendarView/blob/master/app/src/main/assets/index_expand.png" height="650"/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<img src="https://github.com/huanghaibin-dev/CalendarView/blob/master/app/src/main/assets/color_expand.png" height="650"/>
### 进度条风格
<img src="https://github.com/huanghaibin-dev/CalendarView/blob/master/app/src/main/assets/progress_expand.png" height="650"/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<img src="https://github.com/huanghaibin-dev/CalendarView/blob/master/app/src/main/assets/progress_shrink.png" height="650"/>
### 星系图风格
<img src="https://github.com/huanghaibin-dev/CalendarView/blob/master/app/src/main/assets/solar_expand.png" height="650"/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<img src="https://github.com/huanghaibin-dev/CalendarView/blob/master/app/src/main/assets/solar_shrink.png" height="650"/>
### 快速年份月份切换
<img src="https://github.com/huanghaibin-dev/CalendarView/blob/master/app/src/main/assets/year_view.png" height="650"/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<img src="https://github.com/huanghaibin-dev/CalendarView/blob/master/app/src/main/assets/simple_expand.png" height="650"/>

Expand Down
4 changes: 4 additions & 0 deletions README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ compile 'com.haibin:calendarview:3.2.2'
###
<img src="https://github.com/huanghaibin-dev/CalendarView/blob/master/app/src/main/assets/index_expand.png" height="650"/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<img src="https://github.com/huanghaibin-dev/CalendarView/blob/master/app/src/main/assets/color_expand.png" height="650"/>
###
<img src="https://github.com/huanghaibin-dev/CalendarView/blob/master/app/src/main/assets/progress_expand.png" height="650"/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<img src="https://github.com/huanghaibin-dev/CalendarView/blob/master/app/src/main/assets/progress_shrink.png" height="650"/>
###
<img src="https://github.com/huanghaibin-dev/CalendarView/blob/master/app/src/main/assets/solar_expand.png" height="650"/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<img src="https://github.com/huanghaibin-dev/CalendarView/blob/master/app/src/main/assets/solar_shrink.png" height="650"/>
###
<img src="https://github.com/huanghaibin-dev/CalendarView/blob/master/app/src/main/assets/year_view.png" height="650"/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<img src="https://github.com/huanghaibin-dev/CalendarView/blob/master/app/src/main/assets/simple_expand.png" height="650"/>


Expand Down
1 change: 1 addition & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
<activity android:name=".simple.SimpleActivity" />
<activity android:name=".colorful.ColorfulActivity" />
<activity android:name=".solay.SolarActivity" />
<activity android:name=".progress.ProgressActivity"/>
<activity android:name=".my.MultiActivity" />
</application>

Expand Down
Binary file added app/src/main/assets/progress_expand.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/assets/progress_shrink.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/assets/solar_expand.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/assets/solar_shrink.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import com.haibin.calendarviewproject.index.IndexActivity;
import com.haibin.calendarviewproject.meizu.MeiZuActivity;
import com.haibin.calendarviewproject.my.MultiActivity;
import com.haibin.calendarviewproject.progress.ProgressActivity;
import com.haibin.calendarviewproject.simple.SimpleActivity;
import com.haibin.calendarviewproject.solay.SolarActivity;

Expand Down Expand Up @@ -109,6 +110,7 @@ protected void initData() {
findViewById(R.id.ll_colorful).setOnClickListener(this);
findViewById(R.id.ll_index).setOnClickListener(this);
findViewById(R.id.ll_solar_system).setOnClickListener(this);
findViewById(R.id.ll_progress).setOnClickListener(this);
findViewById(R.id.ll_multi).setOnClickListener(this);
}

Expand All @@ -131,6 +133,9 @@ public void onClick(View v) {
case R.id.ll_solar_system:
SolarActivity.show(this);
break;
case R.id.ll_progress:
ProgressActivity.show(this);
break;
case R.id.ll_multi:
MultiActivity.show(this);
break;
Expand Down
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));
}


}
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);
}
}
Loading

0 comments on commit 464faeb

Please sign in to comment.