Skip to content

Commit

Permalink
完善demo
Browse files Browse the repository at this point in the history
  • Loading branch information
yannecer committed Nov 8, 2019
1 parent 2100b25 commit 2e2bd02
Show file tree
Hide file tree
Showing 29 changed files with 810 additions and 256 deletions.
18 changes: 17 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
android:supportsRtl="true"
android:theme="@style/AppTheme"
tools:ignore="GoogleAppIndexingWarning">
<activity android:name=".TestAdapterCalendarActivity">
<activity android:name=".activity.MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

Expand Down Expand Up @@ -66,6 +66,22 @@
android:name=".TestActivity"
android:configChanges="orientation|screenSize|keyboardHidden" />

<activity
android:name=".TestAdapterCalendarActivity"
android:configChanges="orientation|screenSize|keyboardHidden" />

<activity
android:name=".activity.GeneralAdapterActivity"
android:configChanges="orientation|screenSize|keyboardHidden" />

<activity
android:name=".activity.TestAdapterActivity"
android:configChanges="orientation|screenSize|keyboardHidden" />

<activity
android:name=".activity.DingAdapterActivity"
android:configChanges="orientation|screenSize|keyboardHidden" />


</application>
</manifest>
117 changes: 0 additions & 117 deletions app/src/main/java/com/necer/ncalendar/TestAdapterCalendarActivity.java

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
package com.necer.ncalendar.activity;

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.BaseCalendar;
import com.necer.calendar.ICalendar;
import com.necer.entity.CalendarDate;
import com.necer.enumeration.CalendarType;
import com.necer.enumeration.SelectedModel;
import com.necer.listener.OnCalendarChangedListener;
import com.necer.ncalendar.R;
import com.necer.painter.CalendarAdapter;
import com.necer.utils.CalendarUtil;
import com.necer.view.ICalendarView;

import org.joda.time.LocalDate;

import java.util.List;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

public class DingAdapterActivity extends AppCompatActivity {


@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

setContentView(R.layout.activity_adapter);


ICalendar miui10Calendar = findViewById(R.id.miui10Calendar);
miui10Calendar.setCalendarAdapter(new DingAdapter());
miui10Calendar.setSelectedMode(SelectedModel.MULTIPLE);
miui10Calendar.setOnCalendarChangedListener(new OnCalendarChangedListener() {
@Override
public void onCalendarChange(BaseCalendar baseCalendar, int year, int month, LocalDate localDate) {
Log.e("onCalendarChange", "onCalendarChange:::" + localDate);
}
});

}


public static class DingAdapter extends CalendarAdapter {
@Override
public View getCalendarItemView(Context context) {
return LayoutInflater.from(context).inflate(R.layout.item_calendar, null);
}

@Override
public View getCalendarBackgroundView(Context context) {
return LayoutInflater.from(context).inflate(R.layout.bg_calendar, null);
}

@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);
if (totalDistance != 0) {
float i = (float) currentDistance / (float) totalDistance;
tv_bg.setAlpha(i);
tv_bg.setText(String.valueOf(localDate.getMonthOfYear()));

Log.e("onBindCalenww", "onBindCalendarBackgroundView:::" + localDate);
}
}
}

@Override
public void onBindToadyView(View view, LocalDate localDate, List<LocalDate> selectedDateList) {

View ll_content = view.findViewById(R.id.ll_content);

TextView tv_item = view.findViewById(R.id.tv_item);

tv_item.setText(String.valueOf(localDate.getDayOfMonth()));

setLunar(view, localDate, selectedDateList);

if (selectedDateList.contains(localDate)) {
tv_item.setTextColor(Color.WHITE);
ll_content.setBackgroundResource(R.drawable.bg_checked_ding);
} else {
tv_item.setTextColor(Color.BLACK);
ll_content.setBackgroundResource(R.drawable.bg_unchecked);
}
}

@Override
public void onBindCurrentMonthOrWeekView(View view, LocalDate localDate, List<LocalDate> selectedDateList) {

View ll_content = view.findViewById(R.id.ll_content);

TextView tv_item = view.findViewById(R.id.tv_item);
tv_item.setTextColor(Color.BLACK);
tv_item.setText(String.valueOf(localDate.getDayOfMonth()));

setLunar(view, localDate, selectedDateList);

if (selectedDateList.contains(localDate)) {
tv_item.setTextColor(Color.WHITE);
ll_content.setBackgroundResource(R.drawable.bg_checked_ding);
} else {
tv_item.setTextColor(Color.BLACK);
ll_content.setBackgroundResource(R.drawable.bg_unchecked);
}

}

@Override
public void onBindLastOrNextMonthView(View view, LocalDate localDate, List<LocalDate> selectedDateList) {
View ll_content = view.findViewById(R.id.ll_content);
TextView tv_item = view.findViewById(R.id.tv_item);
tv_item.setText(String.valueOf(localDate.getDayOfMonth()));
setLunar(view, localDate, selectedDateList);
if (selectedDateList.contains(localDate)) {
tv_item.setTextColor(Color.WHITE);
ll_content.setBackgroundResource(R.drawable.bg_checked_ding_last_next);
} else {
tv_item.setTextColor(Color.GRAY);
ll_content.setBackgroundResource(R.drawable.bg_unchecked);
}
}


private void setLunar(View view, LocalDate localDate, List<LocalDate> selectedDateList) {

TextView tv_lunar = view.findViewById(R.id.tv_lunar);
CalendarDate calendarDate = CalendarUtil.getCalendarDate(localDate);
tv_lunar.setText(calendarDate.lunar.lunarOnDrawStr);
if (selectedDateList.contains(localDate)) {
tv_lunar.setTextColor(Color.WHITE);
} else {
tv_lunar.setTextColor(Color.GRAY);
}
}
}

}
Loading

0 comments on commit 2e2bd02

Please sign in to comment.