forked from yannecer/NCalendar
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
625 additions
and
138 deletions.
There are no files selected for viewing
56 changes: 56 additions & 0 deletions
56
app/src/main/java/com/necer/ncalendar/TestAdapterCalendarActivity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package com.necer.ncalendar; | ||
|
||
import android.content.Context; | ||
import android.graphics.Color; | ||
import android.os.Bundle; | ||
import android.view.LayoutInflater; | ||
import android.view.View; | ||
import android.widget.TextView; | ||
|
||
import com.necer.calendar.MonthCalendar; | ||
import com.necer.painter.CalendarAdapter; | ||
|
||
import org.joda.time.LocalDate; | ||
|
||
import androidx.annotation.Nullable; | ||
import androidx.appcompat.app.AppCompatActivity; | ||
|
||
public class TestAdapterCalendarActivity extends AppCompatActivity { | ||
|
||
@Override | ||
protected void onCreate(@Nullable Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
setContentView(R.layout.activity_month_adapter); | ||
|
||
|
||
MonthCalendar monthCalendar = findViewById(R.id.monthCalendar); | ||
|
||
monthCalendar.setCalendarAdapter(new TestAdapter()); | ||
} | ||
|
||
|
||
public static class TestAdapter extends CalendarAdapter { | ||
|
||
@Override | ||
public View getCalendarView(Context context) { | ||
View view = LayoutInflater.from(context).inflate(R.layout.item_calendar, null); | ||
return view; | ||
} | ||
|
||
@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")); | ||
|
||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:orientation="vertical" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent"> | ||
|
||
|
||
<com.necer.calendar.MonthCalendar | ||
android:id="@+id/monthCalendar" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent"/> | ||
|
||
</LinearLayout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?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="wrap_content"> | ||
|
||
<TextView | ||
android:id="@+id/tv_item" | ||
android:layout_width="wrap_content" | ||
android:text="asdf" | ||
android:layout_height="wrap_content"/> | ||
|
||
</LinearLayout> |
71 changes: 0 additions & 71 deletions
71
ncalendar/src/main/java/com/necer/adapter/BaseCalendarAdapter.java
This file was deleted.
Oops, something went wrong.
81 changes: 81 additions & 0 deletions
81
ncalendar/src/main/java/com/necer/adapter/BasePagerAdapter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
package com.necer.adapter; | ||
|
||
import android.content.Context; | ||
|
||
import androidx.viewpager.widget.PagerAdapter; | ||
|
||
import android.view.View; | ||
import android.view.ViewGroup; | ||
|
||
import com.necer.enumeration.CalendarBuild; | ||
import com.necer.utils.Attrs; | ||
import com.necer.view.CalendarView; | ||
import com.necer.view.ICalendarView; | ||
|
||
import org.joda.time.LocalDate; | ||
|
||
/** | ||
* Created by necer on 2017/8/25. | ||
* QQ群:127278900 | ||
*/ | ||
|
||
public abstract class BasePagerAdapter extends PagerAdapter { | ||
|
||
|
||
protected Context mContext; | ||
protected int mCount;//总页数 | ||
protected int mCurrIndex;//总页数 | ||
protected LocalDate mInitializeDate; | ||
protected int mFirstDayOfWeek; | ||
protected boolean mIsAllMonthSixLine; | ||
protected CalendarBuild mCalendarBuild; | ||
|
||
public BasePagerAdapter(Context context, CalendarBuild calendarBuild, LocalDate initializeDate, int count, int currIndex, int firstDayOfWeek, boolean isAllMonthSixLine) { | ||
this.mContext = context; | ||
this.mCalendarBuild = calendarBuild; | ||
this.mInitializeDate = initializeDate; | ||
this.mCount = count; | ||
this.mCurrIndex = currIndex; | ||
this.mFirstDayOfWeek = firstDayOfWeek; | ||
this.mIsAllMonthSixLine = isAllMonthSixLine; | ||
} | ||
|
||
// public BasePagerAdapter(Context context, LocalDate startDate, LocalDate endDate, LocalDate initializeDate, Attrs attrs) { | ||
// this.mContext = context; | ||
// this.mInitializeDate = initializeDate; | ||
// this.mCount = getIntervalCount(startDate, endDate, attrs.firstDayOfWeek) + 1; | ||
// this.mCurr = getIntervalCount(startDate, initializeDate, attrs.firstDayOfWeek); | ||
// this.mAttrs = attrs; | ||
// } | ||
|
||
@Override | ||
public int getCount() { | ||
return mCount; | ||
} | ||
|
||
|
||
@Override | ||
public boolean isViewFromObject(View view, Object object) { | ||
return view == object; | ||
} | ||
|
||
@Override | ||
public void destroyItem(ViewGroup container, int position, Object object) { | ||
container.removeView((View) object); | ||
} | ||
|
||
@Override | ||
public Object instantiateItem(ViewGroup container, int position) { | ||
ICalendarView iCalendarView = getCalendarView(container, position); | ||
((View) iCalendarView).setTag(position); | ||
container.addView((View) iCalendarView); | ||
return iCalendarView; | ||
} | ||
|
||
protected abstract ICalendarView getCalendarView(ViewGroup container, int position); | ||
|
||
protected abstract int getIntervalCount(LocalDate startDate, LocalDate endDate, int weekFirstDayType); | ||
|
||
|
||
} | ||
|
37 changes: 0 additions & 37 deletions
37
ncalendar/src/main/java/com/necer/adapter/MonthCalendarAdapter.java
This file was deleted.
Oops, something went wrong.
47 changes: 47 additions & 0 deletions
47
ncalendar/src/main/java/com/necer/adapter/MonthPagerAdapter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package com.necer.adapter; | ||
|
||
import android.content.Context; | ||
import android.view.ViewGroup; | ||
|
||
import com.necer.enumeration.CalendarBuild; | ||
import com.necer.utils.Attrs; | ||
import com.necer.utils.CalendarUtil; | ||
import com.necer.view.ICalendarView; | ||
import com.necer.view.MonthView; | ||
import com.necer.view.MonthView2; | ||
|
||
import org.joda.time.LocalDate; | ||
|
||
import java.util.List; | ||
|
||
/** | ||
* Created by necer on 2018/9/11. | ||
* qq群:127278900 | ||
*/ | ||
public class MonthPagerAdapter extends BasePagerAdapter { | ||
|
||
|
||
public MonthPagerAdapter(Context context, CalendarBuild calendarBuild, LocalDate initializeDate, int count, int currIndex, int firstDayOfWeek, boolean isAllMonthSixLine) { | ||
super(context, calendarBuild, initializeDate, count, currIndex, firstDayOfWeek, isAllMonthSixLine); | ||
} | ||
|
||
@Override | ||
protected ICalendarView getCalendarView(ViewGroup container, int position) { | ||
LocalDate localDate = mInitializeDate.plusMonths(position - mCurrIndex); | ||
List<LocalDate> dateList = CalendarUtil.getMonthCalendar(localDate, mFirstDayOfWeek, mIsAllMonthSixLine); | ||
|
||
// return new MonthView(mContext, container, localDate, dateList); | ||
|
||
if (mCalendarBuild == CalendarBuild.DRAW) { | ||
return new MonthView(mContext, container, localDate, dateList); | ||
} else { | ||
return new MonthView2(mContext, container, localDate, dateList); | ||
} | ||
// return new MonthView2(mContext, container, localDate, dateList); | ||
} | ||
|
||
@Override | ||
protected int getIntervalCount(LocalDate startDate, LocalDate endDate, int type) { | ||
return CalendarUtil.getIntervalMonths(startDate, endDate); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.