This commit is contained in:
JUNGGWAN KIM 2024-11-29 17:52:58 +09:00
parent 29d47c1162
commit fb444ee292
9 changed files with 227 additions and 72 deletions

View File

@ -72,7 +72,7 @@ class DayView : BaseCustomViews {
}
fun displayDayNumber() {
numOfDayView?.text = dayInfo?.getDayOfNum()?.toString() ?: "TEST"
numOfDayView?.text = dayInfo?.getNumOfDay()?.toString() ?: "TEST"
Log.e(TAG, "numOfDayView?.text >>>> 4 ${numOfDayView?.text}")
}

View File

@ -1,11 +1,18 @@
package com.example.calrendarview
import android.content.Context
import android.content.res.TypedArray
import android.os.Build
import android.util.AttributeSet
import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.widget.TextView
import androidx.annotation.RequiresApi
import com.example.calrendarview.model.CalendarFactory
import com.example.calrendarview.model.DayInfo
@RequiresApi(Build.VERSION_CODES.O)
class MonthView : BaseCustomViews {
constructor(context: Context) : super(context)
constructor(context: Context, attrs: AttributeSet?) : super(context, attrs)
@ -23,8 +30,42 @@ class MonthView : BaseCustomViews {
initChildViews()
}
fun initChildViews() {
var dayInfo: DayInfo? = null
set(value) {
field = value
displayDayNumber()
}
var numberOfday : Int = -1
set(value) {
field = value
numOfDayView = findViewById<TextView>(field)
}
var numOfDayView : TextView? = null
override fun onTypedArray(context: Context, typedArray: TypedArray) {
super.onTypedArray(context, typedArray)
numberOfday = typedArray.getResourceId(R.styleable.BaseCustomViews_numOfDayId, R.id.day_num)
displayDayNumber()
}
fun initChildViews(): Array<DayView?> {
//todo : 7 * numberOfRow 의 차일드 뷰를 만든다.
val infos = CalendarFactory().getBeansOfThisWeek()
val childrens = Array<DayView?>(numberOfRow) {
val dayView = inflate(context, R.layout.item_day, this) as? DayView
dayView?.dayInfo = infos[it]
addView(dayView)
return@Array dayView
}
return childrens
}
fun displayDayNumber() {
numOfDayView?.text = dayInfo?.getNumOfDay()?.toString() ?: "TEST"
Log.e(TAG, "numOfDayView?.text >>>> 4 ${numOfDayView?.text}")
}
fun displyMonthOfNumber() {

View File

@ -0,0 +1,39 @@
package com.example.calrendarview.model
import android.os.Build
import androidx.annotation.RequiresApi
import java.time.LocalDate
@RequiresApi(Build.VERSION_CODES.O)
class CalendarBean: DayInfo {
constructor(date: LocalDate) {
this.day = date
}
constructor(y: Int, m: Int, d: Int) {
this.day = LocalDate.of(y, m , d)
}
private val today: LocalDate = LocalDate.now()
private val day: LocalDate
override fun getNumOfDay(): Int = this.day.dayOfMonth
override fun getMonth(): Int = this.day.monthValue
override fun getYear(): Int = this.day.year
override fun getDayOfWeek(): String = this.day.dayOfWeek.toString()
override fun isToday(): Boolean = day.isEqual(today)
fun getNumOfToday(): Int = this.today.dayOfMonth
fun getMonthOfToday(): Int = this.today.monthValue
fun getYearOfToday(): Int = this.today.year
fun getTodayOfWeek(): String = this.today.dayOfWeek.toString()
}

View File

@ -0,0 +1,27 @@
package com.example.calrendarview.model
import android.os.Build
import androidx.annotation.RequiresApi
import java.time.DayOfWeek
import java.time.LocalDate
import java.time.YearMonth
import java.time.temporal.TemporalAdjuster
import java.time.temporal.TemporalAdjusters
@RequiresApi(Build.VERSION_CODES.O)
class CalendarFactory {
fun getBeansOfWeek(date: LocalDate): Array<CalendarBean> {
val startDate = date.with(TemporalAdjusters.previousOrSame(DayOfWeek.SUNDAY))
return Array<CalendarBean>(7) {
CalendarBean(startDate.plusDays(it.toLong()))
}
}
fun getBeansOfThisWeek(): Array<CalendarBean> = getBeansOfWeek(LocalDate.now())
fun getBeansOfMonth(y: Int, m:Int): Array<CalendarBean> {
val daysInMonth = YearMonth.of(y, m).lengthOfMonth()
return Array<CalendarBean>(daysInMonth) {
CalendarBean(y, m, it + 1)
}
}
}

View File

@ -2,7 +2,9 @@ package com.example.calrendarview.model
interface DayInfo {
fun getDayOfNum() : Int
fun getDayOfWeek() : Int
fun getNumOfDay() : Int
fun getMonth(): Int
fun getYear(): Int
fun getDayOfWeek() : String
fun isToday() : Boolean
}

View File

@ -10,11 +10,11 @@
</declare-styleable>
<declare-styleable name="DayView">
<attr name="item_layout"/>
<attr name="numOfDayId"/>
<!-- <attr name="item_layout"/>-->
<!-- <attr name="numOfDayId"/>-->
</declare-styleable>
<declare-styleable name="MonthView">
<attr name="item_layout"/>
<!-- <attr name="item_layout"/>-->
</declare-styleable>
</resources>

View File

@ -3,35 +3,34 @@ package com.example.accountbook.calendar2.example
import android.os.Bundle
import android.util.Log
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.children
import com.example.accountbook.R
import com.example.accountbook.calendar2.CalendarLayoutListener
import com.example.accountbook.calendar2.CalendarManager
import com.example.accountbook.calendar2.CalendarPagerAdapter
import com.example.accountbook.databinding.CalendarActivityExampleBinding
import com.example.accountbook.databinding.ExDayViewBinding
import com.example.calrendarview.DayView
import com.example.calrendarview.model.CalendarBean
import com.example.calrendarview.model.CalendarFactory
import com.example.calrendarview.model.DayInfo
class ActivityCalendarEx: AppCompatActivity() {
// member
private var bind: CalendarActivityExampleBinding? = null
lateinit var bind: CalendarActivityExampleBinding
// AppCompatActivity
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
bind = CalendarActivityExampleBinding.inflate(this.layoutInflater)
bind?.let {
setContentView(it.root)
it.calendarLayoutEx.listener = object: CalendarLayoutListener {
override fun onCreatedViewPager() {
it.calendarLayoutEx.viewPager?.adapter = CalendarPagerAdapter(this@ActivityCalendarEx).apply {
this.layoutId = R.layout.calendar_pager_example
}
}
}
it.root.setOnClickListener{
}
}
// for (i in 0 until 7) {
val infos = CalendarFactory().getBeansOfThisWeek()
bind.otherViews.numberOfRow = 7
// (bind.otherViews.getChildAt(i) as? DayView)?.dayInfo = infos.get(i)
// }
setContentView(bind.root)
}
override fun onStart() {

View File

@ -3,62 +3,68 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto">
<TextView
android:id="@+id/otherViewEx"
android:background="#eeeeee"
<com.example.calrendarview.MonthView
android:id="@+id/otherViews"
android:layout_width="match_parent"
android:layout_height="30dp"
android:layout_height="wrap_content"
app:layout_constraintTop_toTopOf="parent"
android:text="otherView"
android:gravity="center"
app:item_layout="@layout/ex_day_view"
app:numOfDayId="@id/ex_text_day"
/>
<com.example.accountbook.calendar2.CalendarLayout
android:id="@+id/calendarLayoutEx"
android:background="#dddddd"
android:layout_width="match_parent"
android:layout_height="0dp"
app:layout_constraintTop_toBottomOf="@id/otherViewEx"
app:layout_constraintBottom_toBottomOf="parent"
>
<!-- app:calendarId="@id/calendarViewPager"-->
<!-- <com.example.accountbook.calendar2.CalendarLayout-->
<!-- android:id="@+id/calendarLayoutEx"-->
<!-- android:background="#dddddd"-->
<!-- android:layout_width="match_parent"-->
<!-- android:layout_height="0dp"-->
<!-- app:layout_constraintTop_toBottomOf="@id/otherViewEx"-->
<!-- app:layout_constraintBottom_toBottomOf="parent"-->
<!-- >-->
<androidx.viewpager2.widget.ViewPager2
android:id="@+id/test1"
android:background="#9acd32"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_constraintTop_toTopOf="parent"
/>
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/test2"
android:layout_width="match_parent"
android:layout_height="50dp"
app:layout_constraintTop_toTopOf="parent"
>
<TextView
android:background="#a8a800"
android:layout_width="match_parent"
android:layout_height="30dp"
android:text="test"
android:gravity="center"
app:layout_constraintTop_toTopOf="parent"/>
</androidx.constraintlayout.widget.ConstraintLayout>
<!-- <TextView-->
<!-- android:id="@+id/subViewEx"-->
<!--&lt;!&ndash; app:calendarId="@id/calendarViewPager"&ndash;&gt;-->
<!--&lt;!&ndash; >&ndash;&gt;-->
<!-- <androidx.viewpager2.widget.ViewPager2-->
<!-- android:id="@+id/test1"-->
<!-- android:background="#9acd32"-->
<!-- android:layout_width="match_parent"-->
<!-- android:background="@color/material_dynamic_primary50"-->
<!-- android:layout_height="30dp"-->
<!-- android:layout_height="match_parent"-->
<!-- app:layout_constraintTop_toTopOf="parent"-->
<!-- android:text="subView"-->
<!-- android:gravity="center"-->
<!-- />-->
<!-- <androidx.recyclerview.widget.RecyclerView-->
<!-- android:id="@+id/calendar"-->
<!-- android:background="#cccccc"-->
<!-- <androidx.constraintlayout.widget.ConstraintLayout-->
<!-- android:id="@+id/test2"-->
<!-- android:layout_width="match_parent"-->
<!-- android:layout_height="0dp"-->
<!-- app:layout_constraintTop_toBottomOf="@id/subViewEx"-->
<!-- app:layout_constraintBottom_toBottomOf="parent"-->
<!-- />-->
</com.example.accountbook.calendar2.CalendarLayout>
<!-- android:layout_height="50dp"-->
<!-- app:layout_constraintTop_toTopOf="parent"-->
<!-- >-->
<!-- <TextView-->
<!-- android:background="#a8a800"-->
<!-- android:layout_width="match_parent"-->
<!-- android:layout_height="30dp"-->
<!-- android:text="test"-->
<!-- android:gravity="center"-->
<!-- app:layout_constraintTop_toTopOf="parent"/>-->
<!-- </androidx.constraintlayout.widget.ConstraintLayout>-->
<!--&lt;!&ndash; <TextView&ndash;&gt;-->
<!--&lt;!&ndash; android:id="@+id/subViewEx"&ndash;&gt;-->
<!--&lt;!&ndash; android:layout_width="match_parent"&ndash;&gt;-->
<!--&lt;!&ndash; android:background="@color/material_dynamic_primary50"&ndash;&gt;-->
<!--&lt;!&ndash; android:layout_height="30dp"&ndash;&gt;-->
<!--&lt;!&ndash; app:layout_constraintTop_toTopOf="parent"&ndash;&gt;-->
<!--&lt;!&ndash; android:text="subView"&ndash;&gt;-->
<!--&lt;!&ndash; android:gravity="center"&ndash;&gt;-->
<!--&lt;!&ndash; />&ndash;&gt;-->
<!--&lt;!&ndash; <androidx.recyclerview.widget.RecyclerView&ndash;&gt;-->
<!--&lt;!&ndash; android:id="@+id/calendar"&ndash;&gt;-->
<!--&lt;!&ndash; android:background="#cccccc"&ndash;&gt;-->
<!--&lt;!&ndash; android:layout_width="match_parent"&ndash;&gt;-->
<!--&lt;!&ndash; android:layout_height="0dp"&ndash;&gt;-->
<!--&lt;!&ndash; app:layout_constraintTop_toBottomOf="@id/subViewEx"&ndash;&gt;-->
<!--&lt;!&ndash; app:layout_constraintBottom_toBottomOf="parent"&ndash;&gt;-->
<!--&lt;!&ndash; />&ndash;&gt;-->
<!-- </com.example.accountbook.calendar2.CalendarLayout>-->
<!-- <com.example.calrendarview.DayView-->
<!-- android:id="@+id/test"-->
<!-- android:layout_width="match_parent"-->
<!-- android:layout_height="match_parent"-->
<!-- app:item_layout="@layout/activity_writer"-->
<!-- app:numOfDayId="@id/text_write_title"/>-->
</androidx.constraintlayout.widget.ConstraintLayout>

View File

@ -0,0 +1,41 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:paddingVertical="10dp"
android:paddingHorizontal="5dp"
>
<TextView
android:id="@+id/ex_text_day"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintTop_toTopOf="parent"
android:gravity="end|center_vertical"
android:text="01일"
android:textSize="15dp"
/>
<TextView
android:id="@+id/ex_text_day_view_01"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintTop_toBottomOf="@id/ex_text_day"
android:gravity="end|center_vertical"
android:text="ex_text_day"
android:textSize="12dp"
android:background="#9acd32"
android:layout_marginTop="5dp"
/>
<TextView
android:id="@+id/ex_text_day_view_02"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintTop_toBottomOf="@id/ex_text_day_view_01"
android:gravity="end|center_vertical"
android:text="ex_text_day"
android:textSize="12dp"
android:background="#dda0dd"
android:layout_marginTop="5dp"
/>
</androidx.constraintlayout.widget.ConstraintLayout>