|
|
@ -2,9 +2,11 @@ package cc.niushuai.dididone.ui.calendar; |
|
|
|
|
|
|
|
|
|
|
|
import android.os.Bundle; |
|
|
|
import android.os.Bundle; |
|
|
|
import android.util.Log; |
|
|
|
import android.util.Log; |
|
|
|
|
|
|
|
import android.view.Gravity; |
|
|
|
import android.view.LayoutInflater; |
|
|
|
import android.view.LayoutInflater; |
|
|
|
import android.view.View; |
|
|
|
import android.view.View; |
|
|
|
import android.view.ViewGroup; |
|
|
|
import android.view.ViewGroup; |
|
|
|
|
|
|
|
import android.widget.LinearLayout; |
|
|
|
import android.widget.TextView; |
|
|
|
import android.widget.TextView; |
|
|
|
|
|
|
|
|
|
|
|
import androidx.annotation.NonNull; |
|
|
|
import androidx.annotation.NonNull; |
|
|
@ -20,6 +22,7 @@ import com.necer.utils.CalendarUtil; |
|
|
|
|
|
|
|
|
|
|
|
import org.joda.time.LocalDate; |
|
|
|
import org.joda.time.LocalDate; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import cc.niushuai.dididone.R; |
|
|
|
import cc.niushuai.dididone.databinding.FragmentCalendarBinding; |
|
|
|
import cc.niushuai.dididone.databinding.FragmentCalendarBinding; |
|
|
|
|
|
|
|
|
|
|
|
public class CalendarFragment extends Fragment { |
|
|
|
public class CalendarFragment extends Fragment { |
|
|
@ -53,26 +56,54 @@ public class CalendarFragment extends Fragment { |
|
|
|
binding.miui10Calendar.setOnCalendarChangedListener(new OnCalendarChangedListener() { |
|
|
|
binding.miui10Calendar.setOnCalendarChangedListener(new OnCalendarChangedListener() { |
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public void onCalendarChange(BaseCalendar baseCalendar, int year, int month, LocalDate localDate, DateChangeBehavior dateChangeBehavior) { |
|
|
|
public void onCalendarChange(BaseCalendar baseCalendar, int year, int month, LocalDate localDate, DateChangeBehavior dateChangeBehavior) { |
|
|
|
binding.tvResult.setText(year + "年" + month + "月" + " 当前页面选中 " + localDate); |
|
|
|
Log.d(getTag(), " 当前选中 " + localDate); |
|
|
|
Log.d(getTag(), " 当前页面选中 " + localDate); |
|
|
|
|
|
|
|
Log.d(getTag(), " dateChangeBehavior " + dateChangeBehavior); |
|
|
|
CalendarDate calendarDate = CalendarUtil.getCalendarDate(localDate); |
|
|
|
|
|
|
|
Lunar lunar = calendarDate.lunar; |
|
|
|
Log.e(getTag(), "baseCalendar::" + baseCalendar); |
|
|
|
String lunarDate = lunar.chineseEra + "年" + lunar.lunarMonthStr + lunar.lunarDayStr; |
|
|
|
if (localDate != null) { |
|
|
|
|
|
|
|
CalendarDate calendarDate = CalendarUtil.getCalendarDate(localDate); |
|
|
|
|
|
|
|
Lunar lunar = calendarDate.lunar; |
|
|
|
|
|
|
|
binding.tvData.setText(localDate.toString("yyyy年MM月dd日")); |
|
|
|
|
|
|
|
binding.tvDesc.setText(lunar.chineseEra + lunar.animals + "年" + lunar.lunarMonthStr + lunar.lunarDayStr); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
binding.tvData.setText(""); |
|
|
|
|
|
|
|
binding.tvData.setText(""); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
add2Top(localDate.toString(), lunarDate); |
|
|
|
|
|
|
|
} |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void add2Top(String localDate, String lunarDate) { |
|
|
|
|
|
|
|
// 外层layout 白色背景 存在边距
|
|
|
|
|
|
|
|
LinearLayout itemLinearLayout = new LinearLayout(getContext()); |
|
|
|
|
|
|
|
LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, 175); |
|
|
|
|
|
|
|
layoutParams.setMargins(25, 20, 25, 15); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
itemLinearLayout.setLayoutParams(layoutParams); |
|
|
|
|
|
|
|
itemLinearLayout.setPadding(15, 15, 15, 5); |
|
|
|
|
|
|
|
itemLinearLayout.setBackgroundResource(R.drawable.bg_miui10); |
|
|
|
|
|
|
|
itemLinearLayout.setOrientation(LinearLayout.VERTICAL); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ViewGroup.LayoutParams textLayoutParams = new ViewGroup.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT); |
|
|
|
|
|
|
|
TextView dateTextView = new TextView(getContext()); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
dateTextView.setLayoutParams(textLayoutParams); |
|
|
|
|
|
|
|
dateTextView.setText(localDate); |
|
|
|
|
|
|
|
dateTextView.setTextColor(getResources().getColor(R.color._333333)); |
|
|
|
|
|
|
|
dateTextView.setTextSize(16); |
|
|
|
|
|
|
|
dateTextView.setGravity(Gravity.CENTER_VERTICAL); |
|
|
|
|
|
|
|
itemLinearLayout.addView(dateTextView); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// empty textview 占位view 撑大位置
|
|
|
|
|
|
|
|
itemLinearLayout.addView(new TextView(getContext())); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
TextView lunarDateTextView = new TextView(getContext()); |
|
|
|
|
|
|
|
lunarDateTextView.setLayoutParams(textLayoutParams); |
|
|
|
|
|
|
|
lunarDateTextView.setText(lunarDate); |
|
|
|
|
|
|
|
lunarDateTextView.setTextColor(getResources().getColor(R.color._666666)); |
|
|
|
|
|
|
|
lunarDateTextView.setTextSize(12); |
|
|
|
|
|
|
|
lunarDateTextView.setGravity(Gravity.BOTTOM); |
|
|
|
|
|
|
|
itemLinearLayout.addView(lunarDateTextView); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
binding.cCalendarCheckInList.addView(itemLinearLayout, 0); |
|
|
|
|
|
|
|
binding.cCalendarCheckInList.requestLayout(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public void onDestroyView() { |
|
|
|
public void onDestroyView() { |
|
|
|
super.onDestroyView(); |
|
|
|
super.onDestroyView(); |
|
|
|