...
This commit is contained in:
parent
29d47c1162
commit
fb444ee292
@ -72,7 +72,7 @@ class DayView : BaseCustomViews {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun displayDayNumber() {
|
fun displayDayNumber() {
|
||||||
numOfDayView?.text = dayInfo?.getDayOfNum()?.toString() ?: "TEST"
|
numOfDayView?.text = dayInfo?.getNumOfDay()?.toString() ?: "TEST"
|
||||||
Log.e(TAG, "numOfDayView?.text >>>> 4 ${numOfDayView?.text}")
|
Log.e(TAG, "numOfDayView?.text >>>> 4 ${numOfDayView?.text}")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,11 +1,18 @@
|
|||||||
package com.example.calrendarview
|
package com.example.calrendarview
|
||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
|
import android.content.res.TypedArray
|
||||||
|
import android.os.Build
|
||||||
import android.util.AttributeSet
|
import android.util.AttributeSet
|
||||||
|
import android.util.Log
|
||||||
|
import android.view.LayoutInflater
|
||||||
import android.view.View
|
import android.view.View
|
||||||
|
import android.widget.TextView
|
||||||
|
import androidx.annotation.RequiresApi
|
||||||
|
import com.example.calrendarview.model.CalendarFactory
|
||||||
import com.example.calrendarview.model.DayInfo
|
import com.example.calrendarview.model.DayInfo
|
||||||
|
|
||||||
|
@RequiresApi(Build.VERSION_CODES.O)
|
||||||
class MonthView : BaseCustomViews {
|
class MonthView : BaseCustomViews {
|
||||||
constructor(context: Context) : super(context)
|
constructor(context: Context) : super(context)
|
||||||
constructor(context: Context, attrs: AttributeSet?) : super(context, attrs)
|
constructor(context: Context, attrs: AttributeSet?) : super(context, attrs)
|
||||||
@ -23,8 +30,42 @@ class MonthView : BaseCustomViews {
|
|||||||
initChildViews()
|
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 의 차일드 뷰를 만든다.
|
//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() {
|
fun displyMonthOfNumber() {
|
||||||
|
|||||||
@ -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()
|
||||||
|
|
||||||
|
}
|
||||||
@ -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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -2,7 +2,9 @@ package com.example.calrendarview.model
|
|||||||
|
|
||||||
|
|
||||||
interface DayInfo {
|
interface DayInfo {
|
||||||
fun getDayOfNum() : Int
|
fun getNumOfDay() : Int
|
||||||
fun getDayOfWeek() : Int
|
fun getMonth(): Int
|
||||||
|
fun getYear(): Int
|
||||||
|
fun getDayOfWeek() : String
|
||||||
fun isToday() : Boolean
|
fun isToday() : Boolean
|
||||||
}
|
}
|
||||||
@ -10,11 +10,11 @@
|
|||||||
</declare-styleable>
|
</declare-styleable>
|
||||||
|
|
||||||
<declare-styleable name="DayView">
|
<declare-styleable name="DayView">
|
||||||
<attr name="item_layout"/>
|
<!-- <attr name="item_layout"/>-->
|
||||||
<attr name="numOfDayId"/>
|
<!-- <attr name="numOfDayId"/>-->
|
||||||
</declare-styleable>
|
</declare-styleable>
|
||||||
|
|
||||||
<declare-styleable name="MonthView">
|
<declare-styleable name="MonthView">
|
||||||
<attr name="item_layout"/>
|
<!-- <attr name="item_layout"/>-->
|
||||||
</declare-styleable>
|
</declare-styleable>
|
||||||
</resources>
|
</resources>
|
||||||
@ -3,35 +3,34 @@ package com.example.accountbook.calendar2.example
|
|||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
import androidx.appcompat.app.AppCompatActivity
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
|
import androidx.core.view.children
|
||||||
import com.example.accountbook.R
|
import com.example.accountbook.R
|
||||||
import com.example.accountbook.calendar2.CalendarLayoutListener
|
import com.example.accountbook.calendar2.CalendarLayoutListener
|
||||||
import com.example.accountbook.calendar2.CalendarManager
|
import com.example.accountbook.calendar2.CalendarManager
|
||||||
import com.example.accountbook.calendar2.CalendarPagerAdapter
|
import com.example.accountbook.calendar2.CalendarPagerAdapter
|
||||||
import com.example.accountbook.databinding.CalendarActivityExampleBinding
|
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() {
|
class ActivityCalendarEx: AppCompatActivity() {
|
||||||
// member
|
// member
|
||||||
private var bind: CalendarActivityExampleBinding? = null
|
lateinit var bind: CalendarActivityExampleBinding
|
||||||
|
|
||||||
|
|
||||||
// AppCompatActivity
|
// AppCompatActivity
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
bind = CalendarActivityExampleBinding.inflate(this.layoutInflater)
|
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() {
|
override fun onStart() {
|
||||||
|
|||||||
@ -3,62 +3,68 @@
|
|||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
xmlns:app="http://schemas.android.com/apk/res-auto">
|
xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||||
<TextView
|
<com.example.calrendarview.MonthView
|
||||||
android:id="@+id/otherViewEx"
|
android:id="@+id/otherViews"
|
||||||
android:background="#eeeeee"
|
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="30dp"
|
android:layout_height="wrap_content"
|
||||||
app:layout_constraintTop_toTopOf="parent"
|
app:layout_constraintTop_toTopOf="parent"
|
||||||
android:text="otherView"
|
app:item_layout="@layout/ex_day_view"
|
||||||
android:gravity="center"
|
app:numOfDayId="@id/ex_text_day"
|
||||||
/>
|
/>
|
||||||
<com.example.accountbook.calendar2.CalendarLayout
|
|
||||||
android:id="@+id/calendarLayoutEx"
|
<!-- <com.example.accountbook.calendar2.CalendarLayout-->
|
||||||
android:background="#dddddd"
|
<!-- android:id="@+id/calendarLayoutEx"-->
|
||||||
android:layout_width="match_parent"
|
<!-- android:background="#dddddd"-->
|
||||||
android:layout_height="0dp"
|
<!-- android:layout_width="match_parent"-->
|
||||||
app:layout_constraintTop_toBottomOf="@id/otherViewEx"
|
<!-- android:layout_height="0dp"-->
|
||||||
app:layout_constraintBottom_toBottomOf="parent"
|
<!-- app:layout_constraintTop_toBottomOf="@id/otherViewEx"-->
|
||||||
>
|
<!-- app:layout_constraintBottom_toBottomOf="parent"-->
|
||||||
<!-- app:calendarId="@id/calendarViewPager"-->
|
|
||||||
<!-- >-->
|
<!-- >-->
|
||||||
<androidx.viewpager2.widget.ViewPager2
|
<!--<!– app:calendarId="@id/calendarViewPager"–>-->
|
||||||
android:id="@+id/test1"
|
<!--<!– >–>-->
|
||||||
android:background="#9acd32"
|
<!-- <androidx.viewpager2.widget.ViewPager2-->
|
||||||
android:layout_width="match_parent"
|
<!-- android:id="@+id/test1"-->
|
||||||
android:layout_height="match_parent"
|
<!-- android:background="#9acd32"-->
|
||||||
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"-->
|
|
||||||
<!-- android:layout_width="match_parent"-->
|
<!-- android:layout_width="match_parent"-->
|
||||||
<!-- android:background="@color/material_dynamic_primary50"-->
|
<!-- android:layout_height="match_parent"-->
|
||||||
<!-- android:layout_height="30dp"-->
|
|
||||||
<!-- app:layout_constraintTop_toTopOf="parent"-->
|
<!-- app:layout_constraintTop_toTopOf="parent"-->
|
||||||
<!-- android:text="subView"-->
|
|
||||||
<!-- android:gravity="center"-->
|
|
||||||
<!-- />-->
|
<!-- />-->
|
||||||
<!-- <androidx.recyclerview.widget.RecyclerView-->
|
<!-- <androidx.constraintlayout.widget.ConstraintLayout-->
|
||||||
<!-- android:id="@+id/calendar"-->
|
<!-- android:id="@+id/test2"-->
|
||||||
<!-- android:background="#cccccc"-->
|
|
||||||
<!-- android:layout_width="match_parent"-->
|
<!-- android:layout_width="match_parent"-->
|
||||||
<!-- android:layout_height="0dp"-->
|
<!-- android:layout_height="50dp"-->
|
||||||
<!-- app:layout_constraintTop_toBottomOf="@id/subViewEx"-->
|
<!-- app:layout_constraintTop_toTopOf="parent"-->
|
||||||
<!-- app:layout_constraintBottom_toBottomOf="parent"-->
|
<!-- >-->
|
||||||
<!-- />-->
|
<!-- <TextView-->
|
||||||
</com.example.accountbook.calendar2.CalendarLayout>
|
<!-- 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"–>-->
|
||||||
|
<!--<!– android:layout_width="match_parent"–>-->
|
||||||
|
<!--<!– android:background="@color/material_dynamic_primary50"–>-->
|
||||||
|
<!--<!– android:layout_height="30dp"–>-->
|
||||||
|
<!--<!– app:layout_constraintTop_toTopOf="parent"–>-->
|
||||||
|
<!--<!– android:text="subView"–>-->
|
||||||
|
<!--<!– android:gravity="center"–>-->
|
||||||
|
<!--<!– />–>-->
|
||||||
|
<!--<!– <androidx.recyclerview.widget.RecyclerView–>-->
|
||||||
|
<!--<!– android:id="@+id/calendar"–>-->
|
||||||
|
<!--<!– android:background="#cccccc"–>-->
|
||||||
|
<!--<!– 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>-->
|
||||||
|
<!-- <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>
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||||
41
app/src/main/res/layout/ex_day_view.xml
Normal file
41
app/src/main/res/layout/ex_day_view.xml
Normal 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>
|
||||||
Loading…
x
Reference in New Issue
Block a user