Skip to content

Commit

Permalink
新增滚动前一页下一页API,新增滚动到指定年月日API
Browse files Browse the repository at this point in the history
  • Loading branch information
huanghaibin-dev committed Dec 6, 2017
1 parent 0aa83db commit 2dbba60
Show file tree
Hide file tree
Showing 9 changed files with 833 additions and 17 deletions.
2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

40 changes: 28 additions & 12 deletions app/src/main/java/com/haibin/calendarviewproject/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import com.haibin.calendarview.Calendar;
import com.haibin.calendarview.CalendarLayout;
import com.haibin.calendarview.CalendarView;
import com.haibin.calendarview.LunarTest;
import com.haibin.calendarviewproject.base.activity.BaseActivity;
import com.haibin.calendarviewproject.colorful.ColorfulActivity;
import com.haibin.calendarviewproject.index.IndexActivity;
Expand All @@ -21,7 +22,7 @@
public class MainActivity extends BaseActivity implements
CalendarView.OnDateSelectedListener,
CalendarView.OnYearChangeListener,
View.OnClickListener{
View.OnClickListener {

TextView mTextMonthDay;

Expand Down Expand Up @@ -68,7 +69,7 @@ public void onClick(View v) {
}
});

mCalendarLayout = (CalendarLayout)findViewById(R.id.calendarLayout);
mCalendarLayout = (CalendarLayout) findViewById(R.id.calendarLayout);
mCalendarView.setOnYearChangeListener(this);
mCalendarView.setOnDateSelectedListener(this);
mTextYear.setText(String.valueOf(mCalendarView.getCurYear()));
Expand All @@ -83,25 +84,40 @@ protected void initData() {
final List<Calendar> schemes = new ArrayList<>();
final int year = mCalendarView.getCurYear();
final int month = mCalendarView.getCurMonth();
schemes.add(getSchemeCalendar(year, month, 3, 0xFF40db25,"假"));
schemes.add(getSchemeCalendar(year, month, 6, 0xFFe69138,"事"));
schemes.add(getSchemeCalendar(year, month, 9, 0xFFdf1356,"议"));
schemes.add(getSchemeCalendar(year, month, 13, 0xFFedc56d,"记"));
schemes.add(getSchemeCalendar(year, month, 14, 0xFFedc56d,"记"));
schemes.add(getSchemeCalendar(year, month, 15, 0xFFaacc44,"假"));
schemes.add(getSchemeCalendar(year, month, 18, 0xFFbc13f0,"记"));
schemes.add(getSchemeCalendar(year, month, 25, 0xFF13acf0,"假"));
schemes.add(getSchemeCalendar(year, month, 3, 0xFF40db25, "假"));
schemes.add(getSchemeCalendar(year, month, 6, 0xFFe69138, "事"));
schemes.add(getSchemeCalendar(year, month, 9, 0xFFdf1356, "议"));
schemes.add(getSchemeCalendar(year, month, 13, 0xFFedc56d, "记"));
schemes.add(getSchemeCalendar(year, month, 14, 0xFFedc56d, "记"));
schemes.add(getSchemeCalendar(year, month, 15, 0xFFaacc44, "假"));
schemes.add(getSchemeCalendar(year, month, 18, 0xFFbc13f0, "记"));
schemes.add(getSchemeCalendar(year, month, 25, 0xFF13acf0, "假"));
mCalendarView.setSchemeDate(schemes);
mCalendarLayout.postDelayed(new Runnable() {
@Override
public void run() {
//mCalendarView.scrollToCalendar(2004, 3, 13);
}
}, 5000);
findViewById(R.id.ll_flyme).setOnClickListener(this);
findViewById(R.id.ll_simple).setOnClickListener(this);
findViewById(R.id.ll_colorful).setOnClickListener(this);
findViewById(R.id.ll_index).setOnClickListener(this);
LunarTest st = new LunarTest();
st.JQtest(2006);
st.JQtest(2004);
st.JQtest(2015);
st.JQtest(2016);
st.JQtest(2018);
st.JQtest(2017);
st.JQtest(1918);
st.JQtest(2021);
}


@Override
public void onClick(View v) {
switch (v.getId()){
switch (v.getId()) {
case R.id.ll_flyme:
MeiZuActivity.show(this);
break;
Expand Down Expand Up @@ -130,7 +146,7 @@ private Calendar getSchemeCalendar(int year, int month, int day, int color, Stri
@SuppressLint("SetTextI18n")
@Override
public void onDateSelected(Calendar calendar) {
Log.e("onDateSelected"," -- " + calendar.toString());
Log.e("onDateSelected", " -- " + calendar.toString() + " - " + calendar.isCurrentDay());
mTextLunar.setVisibility(View.VISIBLE);
mTextYear.setVisibility(View.VISIBLE);
mTextMonthDay.setText(calendar.getMonth() + "月" + calendar.getDay() + "日");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,44 @@ public void scrollToCurrent() {
if (mDelegate.mDateChangeListener != null) {
mDelegate.mDateChangeListener.onDateChange(mDelegate.createCurrentDate());
}
}

/**
* 滚动到下一个月
*/
public void scrollToNext() {
if (mWeekPager.getVisibility() == VISIBLE) {
mWeekPager.setCurrentItem(mWeekPager.getCurrentItem() + 1);
} else {
mMonthPager.setCurrentItem(mMonthPager.getCurrentItem() + 1);
}

}

/**
* 滚动到上一个月
*/
public void scrollToPre() {
if (mWeekPager.getVisibility() == VISIBLE) {
mWeekPager.setCurrentItem(mWeekPager.getCurrentItem() - 1);
} else {
mMonthPager.setCurrentItem(mMonthPager.getCurrentItem() - 1);
}
}

/**
* 滚动到指定日期
*
* @param year year
* @param month month
* @param day day
*/
public void scrollToCalendar(int year, int month, int day) {
if (mWeekPager.getVisibility() == VISIBLE) {
mWeekPager.scrollToCalendar(year, month, day);
} else {
mMonthPager.scrollToCalendar(year, month, day);
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ private void init() {
mCurrentDate.setWeekend(Util.isWeekend(mCurrentDate));
mCurrentDate.setWeek(Util.getWeekFormCalendar(mCurrentDate));
mCurrentDate.setLunar(LunarCalendar.getLunarText(mCurrentDate));
mCurrentDate.setCurrentDay(true);
mCurrentWeekViewItem = Util.getWeekFromCalendarBetweenYearAndYear(mCurrentDate, mMinYear);
}

Expand Down
7 changes: 7 additions & 0 deletions calendarview/src/main/java/com/haibin/calendarview/Lunar.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.haibin.calendarview;

/**
* 农历计算公式
*/
public final class Lunar {
}
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ static int[] solarToLunar(int year, int month, int monthDay) {
* @return 传回天数
*/
private static int daysInMonth(int year, int month) {
return daysInMonth(year, month, false);
return daysInMonth(year, month, leapMonth(year) == month);
}

/**
Expand All @@ -317,7 +317,6 @@ private static int daysInMonth(int year, int month) {
* @param leap 当月是否是闰月
* @return 传回天数,如果闰月是错误的,返回0.
*/
@SuppressWarnings("all")
private static int daysInMonth(int year, int month, boolean leap) {
int leapMonth = leapMonth(year);
int offset = 0;
Expand Down Expand Up @@ -569,6 +568,7 @@ static String getLunarText(int year, int month, int day) {

/**
* 获取农历节日
*
* @param calendar calendar
* @return 获取农历节日
*/
Expand Down
Loading

0 comments on commit 2dbba60

Please sign in to comment.