Skip to content

Commit

Permalink
添加注释
Browse files Browse the repository at this point in the history
  • Loading branch information
yannecer committed Apr 1, 2020
1 parent 02c1eca commit 2c67665
Show file tree
Hide file tree
Showing 35 changed files with 381 additions and 167 deletions.
44 changes: 31 additions & 13 deletions ncalendar/src/main/java/com/necer/adapter/BasePagerAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import android.content.Context;

import androidx.annotation.NonNull;
import androidx.viewpager.widget.PagerAdapter;

import android.view.View;
Expand All @@ -17,21 +18,21 @@
import org.joda.time.LocalDate;

/**
* Created by necer on 2017/8/25.
* @author necer
* @date 2017/8/25
* QQ群:127278900
*/

public abstract class BasePagerAdapter extends PagerAdapter {


protected Context mContext;
protected int mPageSize;//总页数
protected int mPageCurrIndex;
protected LocalDate mInitializeDate;
private Context mContext;
private int mPageSize;
private int mPageCurrIndex;
private LocalDate mInitializeDate;

protected BaseCalendar mCalendar;
private BaseCalendar mCalendar;

public BasePagerAdapter(Context context, BaseCalendar baseCalendar) {
BasePagerAdapter(Context context, BaseCalendar baseCalendar) {
this.mContext = context;
this.mCalendar = baseCalendar;
this.mInitializeDate = baseCalendar.getInitializeDate();
Expand All @@ -46,17 +47,19 @@ public int getCount() {


@Override
public boolean isViewFromObject(View view, Object object) {
public boolean isViewFromObject(@NonNull View view, @NonNull Object object) {
return view == object;
}

@Override
public void destroyItem(ViewGroup container, int position, Object object) {
public void destroyItem(ViewGroup container, int position, @NonNull Object object) {
container.removeView((View) object);
}


@NonNull
@Override
public Object instantiateItem(ViewGroup container, int position) {
public Object instantiateItem(@NonNull ViewGroup container, int position) {
ICalendarView iCalendarView;
LocalDate pageInitializeDate = getPageInitializeDate(position);
if (mCalendar.getCalendarBuild() == CalendarBuild.DRAW) {
Expand All @@ -69,17 +72,32 @@ public Object instantiateItem(ViewGroup container, int position) {
return iCalendarView;
}


int getPageCurrIndex() {
return mPageCurrIndex;
}

LocalDate getInitializeDate() {
return mInitializeDate;
}

public BaseCalendar getCalendar() {
return mCalendar;
}


/**
* 每个页面的初始化日期
*
* @return
* @param position 当前的position
* @return 当前页面初始化的日期
*/
protected abstract LocalDate getPageInitializeDate(int position);

/**
* 获取是周日历还是月日历
*
* @return
* @return MONTH->月 WEEK->周
*/
protected abstract CalendarType getCalendarType();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,13 @@
import com.necer.view.CalendarView2;

import java.util.List;
/**
* @author necer
* QQ群:127278900
*/

public class GridCalendarAdapter extends BaseAdapter {


private List<View> viewList;

public GridCalendarAdapter(List<View> viewList) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
import org.joda.time.LocalDate;

/**
* Created by necer on 2018/9/11.
*
* @author necer
* @date 2018/9/11
* qq群:127278900
*/
public class MonthPagerAdapter extends BasePagerAdapter {
Expand All @@ -19,8 +21,7 @@ public MonthPagerAdapter(Context context, BaseCalendar baseCalendar) {

@Override
protected LocalDate getPageInitializeDate(int position) {
LocalDate localDate = mInitializeDate.plusMonths(position - mPageCurrIndex);
return localDate;
return getInitializeDate().plusMonths(position - getPageCurrIndex());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ public WeekPagerAdapter(Context context, BaseCalendar baseCalendar) {

@Override
protected LocalDate getPageInitializeDate(int position) {
LocalDate localDate = mInitializeDate.plusDays((position - mPageCurrIndex) * 7);
return localDate;
return getInitializeDate().plusDays((position - getPageCurrIndex()) * 7);
}

@Override
Expand Down
19 changes: 6 additions & 13 deletions ncalendar/src/main/java/com/necer/calendar/BaseCalendar.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@
import androidx.viewpager.widget.ViewPager;

/**
* Created by necer on 2018/9/11.
* @author necer
* @date 2018/9/11
* qq群:127278900
*/
public abstract class BaseCalendar extends ViewPager implements ICalendar {
Expand Down Expand Up @@ -109,6 +110,7 @@ public void onPageSelected(final int position) {
post(() -> drawView(position));
}

@Override
public void onPageScrollStateChanged(int state) {
if (state == ViewPager.SCROLL_STATE_DRAGGING) {
mDateChangeBehavior = DateChangeBehavior.PAGE;
Expand Down Expand Up @@ -254,7 +256,8 @@ protected void jump(LocalDate localDate, boolean isCheck, DateChangeBehavior dat
}
} else {
ICalendarView iCalendarView = findViewWithTag(getCurrentItem());
int indexOffset = getTwoDateCount(localDate, iCalendarView.getPagerInitialDate(), mFirstDayOfWeek);//得出两个页面相差几个
//得出两个页面相差几个
int indexOffset = getTwoDateCount(localDate, iCalendarView.getPagerInitialDate(), mFirstDayOfWeek);
if (isCheck) {
if (mCheckModel == CheckModel.MULTIPLE) {
if (!mTotalCheckedDateList.contains(localDate)) {
Expand Down Expand Up @@ -305,7 +308,7 @@ private void callBack() {
}

//单选
if (mOnCalendarChangedListener != null && !(mCheckModel == CheckModel.MULTIPLE) && getVisibility() == VISIBLE) {
if (mOnCalendarChangedListener != null && mCheckModel != CheckModel.MULTIPLE && getVisibility() == VISIBLE) {
mOnCalendarChangedListener.onCalendarChange(BaseCalendar.this, yearMonthLocalDate.getYear(), yearMonthLocalDate.getMonthOfYear(), currPagerCheckDateList.size() == 0 ? null : currPagerCheckDateList.get(0), mDateChangeBehavior);
}

Expand Down Expand Up @@ -407,16 +410,6 @@ public boolean isAvailable(LocalDate localDate) {
return !localDate.isBefore(mStartDate) && !localDate.isAfter(mEndDate);
}

//获取区间开始日期
public LocalDate getStartDate() {
return mStartDate;
}

//获取区间结束日期
public LocalDate getEndDate() {
return mEndDate;
}


public LocalDate getInitializeDate() {
return mInitializeDate;
Expand Down
6 changes: 4 additions & 2 deletions ncalendar/src/main/java/com/necer/calendar/EmuiCalendar.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@
import org.joda.time.LocalDate;

/**
* 华为日历
* Created by necer on 2018/11/14.
* 仿华为日历
*
* @author necer
* @date 2018/11/14
*/
public class EmuiCalendar extends NCalendar {
public EmuiCalendar(@NonNull Context context, @Nullable AttributeSet attrs) {
Expand Down
1 change: 1 addition & 0 deletions ncalendar/src/main/java/com/necer/calendar/IICalendar.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

/**
* 折叠日历特有的功能接口
* @author necer
*/
public interface IICalendar extends ICalendar {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
package com.necer.calendar;

import android.content.Context;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import android.util.AttributeSet;

import com.necer.enumeration.CalendarState;


/**
* Created by necer on 2018/11/12.
* 仿miui10日历
*
* @author necer
* @date 2018/11/12
*/
public class Miui10Calendar extends MiuiCalendar {

Expand Down
9 changes: 7 additions & 2 deletions ncalendar/src/main/java/com/necer/calendar/Miui9Calendar.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
package com.necer.calendar;

import android.content.Context;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import android.util.AttributeSet;

import com.necer.enumeration.CalendarState;

/**
* Created by necer on 2018/11/7.
* 仿miui9日历
*
* @author necer
* @date 2018/11/7
*/
public class Miui9Calendar extends MiuiCalendar {

Expand All @@ -21,7 +26,7 @@ protected float getGestureMonthUpOffset(float dy) {
float maxOffset;
if (calendarState == CalendarState.MONTH) {
//月 月日历有选中则选中为 中心点,如果没有选中则第一行
maxOffset = monthCalendar.getPivotDistanceFromTop() - Math.abs(monthCalendar.getY()); //结束位置
maxOffset = monthCalendar.getPivotDistanceFromTop() - Math.abs(monthCalendar.getY());
} else {
//周的情况,按照周的第一个数据为中心点
maxOffset = monthCalendar.getDistanceFromTop(weekCalendar.getFirstDate()) - Math.abs(monthCalendar.getY());
Expand Down
7 changes: 5 additions & 2 deletions ncalendar/src/main/java/com/necer/calendar/MiuiCalendar.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@


/**
* Created by necer on 2018/11/15.
* 仿miui日历抽象类
*
* @author necer
* @date 2018/11/12
*/
public abstract class MiuiCalendar extends NCalendar {

Expand All @@ -29,7 +32,7 @@ protected float getMonthCalendarAutoWeekEndY() {
float end;
if (calendarState == CalendarState.MONTH) {
//月 月日历有选中则选中为 中心点,如果没有选中则第一行
end = -monthCalendar.getPivotDistanceFromTop(); //结束位置
end = -monthCalendar.getPivotDistanceFromTop();
} else {
//周的情况,按照周的第一个数据为中心点
end = -monthCalendar.getDistanceFromTop(weekCalendar.getFirstDate());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@
import java.util.List;

/**
* Created by necer on 2018/9/11.
*
* @author necer
* @date 2018/9/11
* qq群:127278900
*/
public class MonthCalendar extends BaseCalendar {
Expand Down
33 changes: 24 additions & 9 deletions ncalendar/src/main/java/com/necer/calendar/NCalendar.java
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,9 @@ protected void gestureMove(float dy, int[] consumed) {
monthCalendar.setY(-getGestureMonthUpOffset(dy) + monthCalendarY);
childView.setY(-getGestureChildUpOffset(dy) + childViewY);

if (consumed != null) consumed[1] = (int) dy;
if (consumed != null) {
consumed[1] = (int) dy;
}
scrolling(dy);

} else if (dy < 0 && childViewY == monthHeight && monthCalendarY == 0 && isMonthStretchEnable) {
Expand All @@ -377,7 +379,9 @@ protected void gestureMove(float dy, int[] consumed) {
float childOffset = getOffset(-dy, stretchMonthHeight - childViewY);
childView.setY(childViewY + childOffset);

if (consumed != null) consumed[1] = (int) dy;
if (consumed != null) {
consumed[1] = (int) dy;
}
scrolling(dy);

} else if (dy > 0 && childViewY <= monthHeight && childViewY != weekHeight) {
Expand All @@ -391,7 +395,9 @@ protected void gestureMove(float dy, int[] consumed) {
monthCalendar.setY(-getGestureMonthUpOffset(dy) + monthCalendarY);
childView.setY(-getGestureChildUpOffset(dy) + childViewY);

if (consumed != null) consumed[1] = (int) dy;
if (consumed != null) {
consumed[1] = (int) dy;
}
scrolling(dy);

} else if (dy < 0 && childViewY <= monthHeight && childViewY >= weekHeight && (!isWeekHoldEnable || consumed == null) && (targetView == null || !targetView.canScrollVertically(-1))) {
Expand All @@ -404,7 +410,9 @@ protected void gestureMove(float dy, int[] consumed) {
monthCalendar.setY(getGestureMonthDownOffset(dy) + monthCalendarY);
childView.setY(getGestureChildDownOffset(dy) + childViewY);

if (consumed != null) consumed[1] = (int) dy;
if (consumed != null) {
consumed[1] = (int) dy;
}
scrolling(dy);

} else if (dy < 0 && childViewY >= monthHeight && childViewY <= stretchMonthHeight && monthCalendarY == 0 && isMonthStretchEnable) {
Expand All @@ -416,7 +424,9 @@ protected void gestureMove(float dy, int[] consumed) {
float childOffset = getOffset(-dy, stretchMonthHeight - childViewY);
childView.setY(childViewY + childOffset);

if (consumed != null) consumed[1] = (int) dy;
if (consumed != null) {
consumed[1] = (int) dy;
}
scrolling(dy);

} else if (dy > 0 && childViewY >= monthHeight && childViewY <= stretchMonthHeight && monthCalendarY == 0 && isMonthStretchEnable) {
Expand All @@ -428,7 +438,9 @@ protected void gestureMove(float dy, int[] consumed) {
float childOffset = getOffset(-dy, stretchMonthHeight - childViewY);
childView.setY(childViewY + childOffset);

if (consumed != null) consumed[1] = (int) dy;
if (consumed != null) {
consumed[1] = (int) dy;
}
scrolling(dy);
}

Expand All @@ -437,9 +449,12 @@ protected void gestureMove(float dy, int[] consumed) {

private float downY;
private float downX;
private float lastY;//上次的y
private float verticalY = 50.f;//竖直方向上滑动的临界值,大于这个值认为是竖直滑动
private boolean isFirstScroll = true; //第一次手势滑动,因为第一次滑动的偏移量大于verticalY,会出现猛的一划,这里只对第一次滑动做处理
//上次的y
private float lastY;
//竖直方向上滑动的临界值,大于这个值认为是竖直滑动
private float verticalY = 50.f;
//第一次手势滑动,因为第一次滑动的偏移量大于verticalY,会出现猛的一划,这里只对第一次滑动做处理
private boolean isFirstScroll = true;

@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
Expand Down
Loading

0 comments on commit 2c67665

Please sign in to comment.