Skip to content

Commit

Permalink
适配器功能开发完成
Browse files Browse the repository at this point in the history
  • Loading branch information
yannecer committed Nov 8, 2019
1 parent 19c9738 commit 2100b25
Show file tree
Hide file tree
Showing 21 changed files with 479 additions and 313 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,17 @@
import android.content.Context;
import android.graphics.Color;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;

import com.necer.calendar.Miui10Calendar;
import com.necer.calendar.MonthCalendar;
import com.necer.calendar.WeekCalendar;
import com.necer.enumeration.CalendarType;
import com.necer.painter.CalendarAdapter;
import com.necer.view.ICalendarView;

import org.joda.time.LocalDate;

Expand All @@ -30,10 +33,10 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
// MonthCalendar monthCalendar = findViewById(R.id.monthCalendar);
// monthCalendar.setCalendarAdapter(new TestAdapter());

// WeekCalendar weekCalendar = findViewById(R.id.weekCalendar);
// WeekCalendar weekCalendar = findViewById(R.id.weekCalendar);

//
// weekCalendar.setCalendarAdapter(new TestAdapter());
//
// weekCalendar.setCalendarAdapter(new TestAdapter());


Miui10Calendar miui10Calendar = findViewById(R.id.miui10Calendar);
Expand Down Expand Up @@ -62,7 +65,7 @@ public void onBindToadyView(View view, LocalDate localDate, List<LocalDate> sele
public void onBindCurrentMonthOrWeekView(View view, LocalDate localDate, List<LocalDate> selectedDateList) {
TextView tv_item = view.findViewById(R.id.tv_item);
tv_item.setText(String.valueOf(localDate.getDayOfMonth()));
tv_item.setBackgroundColor(selectedDateList.contains(localDate) ? Color.RED : Color.WHITE);
tv_item.setBackgroundColor(selectedDateList.contains(localDate) ? Color.RED : Color.TRANSPARENT);
}

@Override
Expand All @@ -75,22 +78,40 @@ public void onBindLastOrNextMonthView(View view, LocalDate localDate, List<Local
@Override
public void onBindDisableDateView(View view, LocalDate localDate) {


}

// @Override
// public void onBindToadyView(View view, LocalDate localDate, boolean isCheck) {
// TextView textView = view.findViewById(R.id.tv_item);
// textView.setText(localDate.getDayOfMonth()+"");
// view.setBackgroundColor(isCheck ? Color.parseColor("#ff00ff") : Color.parseColor("#ffffff"));
//
// }
//
// @Override
// public void onBindCurrentMonthOrWeekView(View view, LocalDate localDate, boolean isCheck) {
// TextView textView = view.findViewById(R.id.tv_item);
// textView.setText(localDate.getDayOfMonth()+"");
// view.setBackgroundColor(isCheck ? Color.parseColor("#ff00ff") : Color.parseColor("#ffffff"));
//
// }

@Override
public View getCalendarBackgroundView(Context context) {
//return super.getCalendarBackgroundView(context);

View view = LayoutInflater.from(context).inflate(R.layout.bg_calendar, null);
return view;
}

@Override
public void onBindCalendarBackgroundView(ICalendarView iCalendarView, View calendarBackgroundView, LocalDate localDate, int totalDistance, int currentDistance) {
super.onBindCalendarBackgroundView(iCalendarView, calendarBackgroundView, localDate, totalDistance, currentDistance);


if (iCalendarView.getCalendarType() == CalendarType.MONTH) {
TextView tv_bg = calendarBackgroundView.findViewById(R.id.tv_bg);
// int alphaColor = mAttrs.numberBackgroundAlphaColor * currentDistance / totalDistance;
if (totalDistance != 0) {

float i = (float)currentDistance / (float)totalDistance;


Log.e("currentDistance", "currentDistance:::" + i);

tv_bg.setAlpha(i);
tv_bg.setText(String.valueOf(localDate.getMonthOfYear()));

}

}

}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import com.necer.painter.CalendarPainter;
import com.necer.utils.CalendarUtil;
import com.necer.view.CalendarView;
import com.necer.view.ICalendarView;

import org.joda.time.LocalDate;

Expand Down Expand Up @@ -44,7 +45,7 @@ private Paint getPaint() {
}

@Override
public void onDrawCalendarBackground(CalendarView calendarView, Canvas canvas, RectF rectF, LocalDate localDate, int totalDistance, int currentDistance) {
public void onDrawCalendarBackground(ICalendarView calendarView, Canvas canvas, RectF rectF, LocalDate localDate, int totalDistance, int currentDistance) {

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import com.necer.painter.CalendarPainter;
import com.necer.utils.CalendarUtil;
import com.necer.view.CalendarView;
import com.necer.view.ICalendarView;

import org.joda.time.LocalDate;

Expand All @@ -29,7 +30,7 @@ public StretchPainter(Context context) {


@Override
public void onDrawCalendarBackground(CalendarView calendarView, Canvas canvas, RectF rectF, LocalDate localDate, int totalDistance, int currentDistance) {
public void onDrawCalendarBackground(ICalendarView calendarView, Canvas canvas, RectF rectF, LocalDate localDate, int totalDistance, int currentDistance) {

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import com.necer.painter.CalendarPainter;
import com.necer.utils.CalendarUtil;
import com.necer.view.CalendarView;
import com.necer.view.ICalendarView;

import org.joda.time.LocalDate;

Expand Down Expand Up @@ -70,7 +71,7 @@ private Paint getPaint() {


@Override
public void onDrawCalendarBackground(CalendarView calendarView, Canvas canvas, RectF rectF, LocalDate localDate, int totalDistance, int currentDistance) {
public void onDrawCalendarBackground(ICalendarView calendarView, Canvas canvas, RectF rectF, LocalDate localDate, int totalDistance, int currentDistance) {

}

Expand Down
8 changes: 7 additions & 1 deletion app/src/main/res/layout/activity_month_adapter.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
Expand All @@ -8,7 +9,12 @@
<com.necer.calendar.Miui10Calendar
android:id="@+id/miui10Calendar"
android:layout_width="match_parent"
android:layout_height="match_parent">
android:layout_height="match_parent"
app:defaultCalendar="week"
app:isShowNumberBackground="true"
app:numberBackgroundAlphaColor="100"
app:numberBackgroundTextSize="250sp"
app:numberBackgroundTextColor="#398FE9">

<androidx.core.widget.NestedScrollView
android:layout_width="match_parent"
Expand Down
15 changes: 15 additions & 0 deletions app/src/main/res/layout/bg_calendar.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:gravity="center"
android:layout_width="match_parent"
android:layout_height="match_parent">

<TextView
android:id="@+id/tv_bg"
android:layout_width="wrap_content"
android:textSize="50dp"
android:textStyle="bold"
android:layout_height="wrap_content"/>

</LinearLayout>
27 changes: 22 additions & 5 deletions ncalendar/src/main/java/com/necer/adapter/BasePagerAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@

import androidx.viewpager.widget.PagerAdapter;

import android.util.Log;
import android.view.View;
import android.view.ViewGroup;

import com.necer.calendar.BaseCalendar;
import com.necer.enumeration.CalendarBuild;
import com.necer.utils.Attrs;
import com.necer.enumeration.CalendarType;
import com.necer.view.CalendarView;
import com.necer.view.CalendarView2;
import com.necer.view.ICalendarView;

import org.joda.time.LocalDate;
Expand Down Expand Up @@ -57,14 +57,31 @@ public void destroyItem(ViewGroup container, int position, Object object) {

@Override
public Object instantiateItem(ViewGroup container, int position) {
ICalendarView iCalendarView = getCalendarView(container, position);
ICalendarView iCalendarView;
LocalDate pageInitializeDate = getPageInitializeDate(position);
if (mCalendar.getCalendarBuild() == CalendarBuild.DRAW) {
iCalendarView = new CalendarView(mContext, mCalendar, pageInitializeDate, getCalendarType());
} else {
iCalendarView = new CalendarView2(mContext, mCalendar, pageInitializeDate, getCalendarType());
}
((View) iCalendarView).setTag(position);
container.addView((View) iCalendarView);
return iCalendarView;
}

protected abstract ICalendarView getCalendarView(ViewGroup container, int position);

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

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


}
Expand Down
29 changes: 6 additions & 23 deletions ncalendar/src/main/java/com/necer/adapter/MonthPagerAdapter.java
Original file line number Diff line number Diff line change
@@ -1,15 +1,9 @@
package com.necer.adapter;

import android.content.Context;
import android.view.ViewGroup;

import com.necer.calendar.BaseCalendar;
import com.necer.enumeration.CalendarBuild;
import com.necer.enumeration.CalendarType;
import com.necer.helper.CalendarHelper;
import com.necer.view.CalendarView;
import com.necer.view.CalendarView2;
import com.necer.view.ICalendarView;

import org.joda.time.LocalDate;

Expand All @@ -24,24 +18,13 @@ public MonthPagerAdapter(Context context, BaseCalendar baseCalendar) {
}

@Override
protected ICalendarView getCalendarView(ViewGroup container, int position) {
protected LocalDate getPageInitializeDate(int position) {
LocalDate localDate = mInitializeDate.plusMonths(position - mPageCurrIndex);
return localDate;
}

// return new MonthView(mContext, container, localDate, dateList);


//Log.e("CalendarBuild::", "CalendarBuild:222::" + calendarBuild);
// Log.e("CalendarBuild::", "CalendarBuild:333::" + mCalendarBuild);

if (mCalendar.getCalendarBuild() == CalendarBuild.DRAW) {
// return new MonthView(mContext, container, localDate, dateList);

// return new CalendarView(mContext, container, localDate, dateList, CalendarType.MONTH);
return new CalendarView(mContext, new CalendarHelper((BaseCalendar) container, localDate, CalendarType.MONTH));
} else {
// return new MonthView2(mContext, container, localDate, dateList);
return new CalendarView2(mContext, new CalendarHelper((BaseCalendar) container, localDate, CalendarType.MONTH));
}
// return new MonthView2(mContext, container, localDate, dateList);
@Override
protected CalendarType getCalendarType() {
return CalendarType.MONTH;
}
}
27 changes: 6 additions & 21 deletions ncalendar/src/main/java/com/necer/adapter/WeekPagerAdapter.java
Original file line number Diff line number Diff line change
@@ -1,15 +1,9 @@
package com.necer.adapter;

import android.content.Context;
import android.view.ViewGroup;

import com.necer.calendar.BaseCalendar;
import com.necer.enumeration.CalendarBuild;
import com.necer.enumeration.CalendarType;
import com.necer.helper.CalendarHelper;
import com.necer.view.CalendarView;
import com.necer.view.CalendarView2;
import com.necer.view.ICalendarView;

import org.joda.time.LocalDate;

Expand All @@ -25,23 +19,14 @@ public WeekPagerAdapter(Context context, BaseCalendar baseCalendar) {
}

@Override
protected ICalendarView getCalendarView(ViewGroup container, int position) {
protected LocalDate getPageInitializeDate(int position) {
LocalDate localDate = mInitializeDate.plusDays((position - mPageCurrIndex) * 7);
// List<LocalDate> dateList = CalendarUtil.getWeekCalendar(localDate, mFirstDayOfWeek);
//return new CalendarView(mContext, container, localDate, dateList);

if (mCalendar.getCalendarBuild() == CalendarBuild.DRAW) {
// return new MonthView(mContext, container, localDate, dateList);

// return new CalendarView(mContext, container, localDate, dateList, CalendarType.MONTH);
return new CalendarView(mContext, new CalendarHelper((BaseCalendar) container, localDate, CalendarType.WEEK));
} else {
// return new MonthView2(mContext, container, localDate, dateList);
return new CalendarView2(mContext, new CalendarHelper((BaseCalendar) container, localDate, CalendarType.WEEK));
}

return localDate;
}

//return new CalendarView(mContext,new CalendarHelper((BaseCalendar) container,localDate, CalendarType.WEEK));
@Override
protected CalendarType getCalendarType() {
return CalendarType.WEEK;
}

}
Loading

0 comments on commit 2100b25

Please sign in to comment.