Skip to content

Commit

Permalink
miui9
Browse files Browse the repository at this point in the history
  • Loading branch information
yannecer committed Nov 8, 2018
1 parent 2caea27 commit ce71e38
Show file tree
Hide file tree
Showing 10 changed files with 355 additions and 49 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.

Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ public void onYearMonthChanged(BaseCalendar baseCalendar,int year, int month) {
}
});

/*
monthcalendar.setOnDateChangedListener(new OnDateChangedListener() {
@Override
Expand All @@ -112,6 +113,7 @@ public void onDateChanged(BaseCalendar baseCalendar, LocalDate localDate) {
});
*/



Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,14 @@
import android.support.annotation.Nullable;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;


import org.joda.time.DateTime;

import necer.ncalendardemo.R;
import necer.ncalendardemo.adapter.AAAdapter;

/**
* Created by necer on 2018/11/7.
Expand All @@ -27,6 +30,11 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
supportActionBar.hide();
}

RecyclerView recyclerView = findViewById(R.id.recyclerView);

recyclerView.setLayoutManager(new LinearLayoutManager(this));
AAAdapter aaAdapter = new AAAdapter(this);
recyclerView.setAdapter(aaAdapter);



Expand Down
14 changes: 11 additions & 3 deletions app/src/main/res/layout/activity_miui9.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,17 @@
<com.necer.calendar.Miui9Calendar
android:layout_width="match_parent"
app:calendarHeight="300dp"
android:layout_marginLeft="50dp"
android:layout_marginRight="50dp"
android:layout_height="match_parent"/>
android:layout_marginTop="50dp"
android:layout_height="match_parent">


<android.support.v7.widget.RecyclerView
android:id="@+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent"/>


</com.necer.calendar.Miui9Calendar>


</LinearLayout>
59 changes: 41 additions & 18 deletions calendar/src/main/java/com/necer/calendar/BaseCalendar.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,17 @@
import android.support.annotation.Nullable;
import android.support.v4.view.ViewPager;
import android.util.AttributeSet;

import com.necer.R;
import com.necer.adapter.BaseCalendarAdapter;
import com.necer.listener.OnDateChangedListener;
import com.necer.listener.OnYearMonthChangedListener;
import com.necer.utils.Attrs;
import com.necer.utils.Util;
import com.necer.view.BaseCalendarView;

import org.joda.time.LocalDate;

import java.util.ArrayList;
import java.util.List;

Expand All @@ -26,9 +29,9 @@ public abstract class BaseCalendar extends ViewPager {
protected int mCalendarSize;
private BaseCalendarAdapter calendarAdapter;
private Attrs attrs;
private BaseCalendarView mCurrView;//当前显示的页面
private BaseCalendarView mLastView;//当前显示的页面的上一个页面
private BaseCalendarView mNextView;//当前显示的页面的下一个页面
protected BaseCalendarView mCurrView;//当前显示的页面
protected BaseCalendarView mLastView;//当前显示的页面的上一个页面
protected BaseCalendarView mNextView;//当前显示的页面的下一个页面

protected LocalDate mSelectDate;//日历上面点击选中的日期,包含点击选中和翻页选中
protected LocalDate mOnClickDate;//专值点击选中的日期
Expand Down Expand Up @@ -73,8 +76,8 @@ public BaseCalendar(@NonNull Context context, @Nullable AttributeSet attributeSe
attrs.holidayColor = ta.getColor(R.styleable.NCalendar_holidayColor, getResources().getColor(R.color.holidayColor));
attrs.workdayColor = ta.getColor(R.styleable.NCalendar_workdayColor, getResources().getColor(R.color.workdayColor));
attrs.backgroundColor = ta.getColor(R.styleable.NCalendar_backgroundColor, getResources().getColor(R.color.white));
attrs.firstDayOfWeek = ta.getInt(R.styleable.NCalendar_firstDayOfWeek,Attrs.SUNDAY);
attrs.pointLocation = ta.getInt(R.styleable.NCalendar_pointLocation,Attrs.UP);
attrs.firstDayOfWeek = ta.getInt(R.styleable.NCalendar_firstDayOfWeek, Attrs.SUNDAY);
attrs.pointLocation = ta.getInt(R.styleable.NCalendar_pointLocation, Attrs.UP);
attrs.defaultCalendar = ta.getInt(R.styleable.NCalendar_defaultCalendar, Attrs.MONTH);
attrs.holidayLocation = ta.getInt(R.styleable.NCalendar_holidayLocation, Attrs.TOP_RIGHT);

Expand All @@ -99,10 +102,12 @@ public BaseCalendar(@NonNull Context context, @Nullable AttributeSet attributeSe

addOnPageChangeListener(new OnPageChangeListener() {
@Override
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {}
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
}

@Override
public void onPageScrollStateChanged(int state) {}
public void onPageScrollStateChanged(int state) {
}

@Override
public void onPageSelected(final int position) {
Expand Down Expand Up @@ -147,7 +152,7 @@ private void reDraw(int position) {
//年月回调
onYearMonthChanged(mSelectDate.getYear(), mSelectDate.getMonthOfYear());
//日期回调
onDateChanged(mSelectDate);
onDateChanged(mSelectDate, isDraw);
}

public void setPointList(List<String> list) {
Expand All @@ -167,15 +172,17 @@ public void setPointList(List<String> list) {
}

//刷新页面
protected void notifyView(LocalDate currectSelectDate,boolean isDraw) {
protected void notifyView(LocalDate currectSelectDate, boolean isDraw) {
this.mSelectDate = currectSelectDate;
mCurrView.setSelectDate(currectSelectDate, mPointList,isDraw);
if (mCurrView != null) {
mCurrView.setSelectDate(currectSelectDate, mPointList, isDraw);
}

if (mLastView != null) {
mLastView.setSelectDate(getLastSelectDate(currectSelectDate), mPointList,isDraw);
mLastView.setSelectDate(getLastSelectDate(currectSelectDate), mPointList, isDraw);
}
if (mNextView != null) {
mNextView.setSelectDate(getNextSelectDate(currectSelectDate), mPointList,isDraw);
mNextView.setSelectDate(getNextSelectDate(currectSelectDate), mPointList, isDraw);
}
}

Expand Down Expand Up @@ -207,6 +214,7 @@ protected void notifyView(LocalDate currectSelectDate,boolean isDraw) {

/**
* 重绘当前页面时,获取上个月选中的日期
*
* @return
*/
protected abstract LocalDate getLastSelectDate(LocalDate currectSelectDate);
Expand All @@ -222,54 +230,69 @@ protected void notifyView(LocalDate currectSelectDate,boolean isDraw) {

/**
* 日历上面选中的日期,有选中圈的才会回调
*
* @param localDate
*/
protected abstract void onSelcetDate(LocalDate localDate);

/**
* 年份和月份变化回调,点击和翻页都会回调,不管有没有日期选中
*
* @param year
* @param month
*/
public void onYearMonthChanged(int year, int month){
public void onYearMonthChanged(int year, int month) {
if (onYearMonthChangedListener != null && (year != mLaseYear || month != mLastMonth)) {
mLaseYear = year;
mLastMonth = month;
onYearMonthChangedListener.onYearMonthChanged(this,year, month);
onYearMonthChangedListener.onYearMonthChanged(this, year, month);
}
}

/**
* 任何操作都会回调
*
* @param localDate
* @param isDraw 页面是否选中
*/
public void onDateChanged(LocalDate localDate) {
public void onDateChanged(LocalDate localDate, boolean isDraw) {
if (onDateChangedListener != null) {
onDateChangedListener.onDateChanged(this,localDate);
onDateChangedListener.onDateChanged(this, localDate, isDraw);
}
}

public void setOnYearMonthChangeListener(OnYearMonthChangedListener onYearMonthChangedListener) {
this.onYearMonthChangedListener = onYearMonthChangedListener;
}

public void setOnDateChangedListener(OnDateChangedListener onDateChangedListener) {
this.onDateChangedListener = onDateChangedListener;
}


/**
* 跳转日期
*
* @param formatDate
*/
public void jumpDate(String formatDate) {
LocalDate jumpDate = new LocalDate(formatDate);
mOnClickDate = jumpDate;
int num = getTwoDateNum(mSelectDate,jumpDate , attrs.firstDayOfWeek);
int num = getTwoDateNum(mSelectDate, jumpDate, attrs.firstDayOfWeek);
setCurrentItem(getCurrentItem() + num, Math.abs(num) == 1);
notifyView(jumpDate,true);
notifyView(jumpDate, true);
}


//
protected void jumpDate(LocalDate localDate, boolean isDraw) {
if (mSelectDate != null) {
int num = getTwoDateNum(mSelectDate, localDate, attrs.firstDayOfWeek);
setCurrentItem(getCurrentItem() + num, Math.abs(num) == 1);
notifyView(localDate, isDraw);
}
}


protected Attrs getAttrs() {
return attrs;
Expand Down
Loading

0 comments on commit ce71e38

Please sign in to comment.