...
This commit is contained in:
parent
4226235569
commit
29d47c1162
@ -1,6 +1,7 @@
|
||||
package com.example.calrendarview
|
||||
|
||||
import android.content.Context
|
||||
import android.content.res.TypedArray
|
||||
import android.util.AttributeSet
|
||||
import android.util.Log
|
||||
import android.view.LayoutInflater
|
||||
@ -9,6 +10,7 @@ import android.view.ViewGroup
|
||||
import androidx.constraintlayout.widget.ConstraintLayout
|
||||
|
||||
abstract class BaseCustomViews : ConstraintLayout {
|
||||
protected val TAG = this:: class.simpleName
|
||||
constructor(context: Context) : super(context){appyAttrs(context,null)}
|
||||
constructor(context: Context, attrs: AttributeSet?) : super(context, attrs){appyAttrs(context,attrs)}
|
||||
constructor(context: Context, attrs: AttributeSet?, defStyleAttr: Int) : super(
|
||||
@ -27,12 +29,15 @@ abstract class BaseCustomViews : ConstraintLayout {
|
||||
var layouId : Int = -1
|
||||
open fun appyAttrs(context: Context?, attrs: AttributeSet?) {
|
||||
context?.let {
|
||||
val typedArray = it.obtainStyledAttributes(attrs, R.styleable.BaseCustomViews)
|
||||
layouId = typedArray.getResourceId(R.styleable.BaseCustomViews_item_layout,R.layout.item_day)
|
||||
initLayout(it)
|
||||
onTypedArray(it,it.obtainStyledAttributes(attrs, R.styleable.BaseCustomViews))
|
||||
}
|
||||
}
|
||||
|
||||
open fun onTypedArray(context: Context, typedArray : TypedArray) {
|
||||
layouId = typedArray.getResourceId(R.styleable.BaseCustomViews_item_layout,R.layout.item_day)
|
||||
initLayout(context)
|
||||
}
|
||||
|
||||
fun initLayout(context: Context?) {
|
||||
createdLayout(LayoutInflater.from(context).inflate(layouId, this, true))
|
||||
}
|
||||
|
||||
@ -1,24 +1,79 @@
|
||||
package com.example.calrendarview
|
||||
|
||||
import android.content.Context
|
||||
import android.content.res.TypedArray
|
||||
import android.graphics.Canvas
|
||||
import android.graphics.Color
|
||||
import android.util.AttributeSet
|
||||
import android.util.Log
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.TextView
|
||||
import androidx.core.view.children
|
||||
import com.example.calrendarview.model.DayInfo
|
||||
|
||||
class DayView : BaseCustomViews {
|
||||
|
||||
constructor(context: Context) : super(context)
|
||||
constructor(context: Context, attrs: AttributeSet?) : super(context, attrs)
|
||||
constructor(context: Context, attrs: AttributeSet?, defStyleAttr: Int) : super(context, attrs, defStyleAttr)
|
||||
constructor(context: Context, attrs: AttributeSet?, defStyleAttr: Int, defStyleRes: Int) : super(context, attrs, defStyleAttr, defStyleRes)
|
||||
constructor(context: Context, attrs: AttributeSet?, defStyleAttr: Int) : super(
|
||||
context,
|
||||
attrs,
|
||||
defStyleAttr
|
||||
)
|
||||
|
||||
constructor(
|
||||
context: Context,
|
||||
attrs: AttributeSet?,
|
||||
defStyleAttr: Int,
|
||||
defStyleRes: Int
|
||||
) : super(context, attrs, defStyleAttr, defStyleRes)
|
||||
|
||||
override fun appyAttrs(context: Context?, attrs: AttributeSet?) {
|
||||
super.appyAttrs(context, attrs)
|
||||
var dayInfo: DayInfo? = null
|
||||
set(value) {
|
||||
field = value
|
||||
displayDayNumber()
|
||||
}
|
||||
|
||||
var numOfDayView : TextView? = null
|
||||
var numberOfday : Int = -1
|
||||
set(value) {
|
||||
Log.e(TAG, "numOfDayView 2 (${R.id.day_num}) Id >>>> ${value}")
|
||||
field = value
|
||||
numOfDayView = findViewById<TextView>(field)
|
||||
Log.e(TAG, "numOfDayView >>>> 3 ${numOfDayView}")
|
||||
}
|
||||
|
||||
// override fun appyAttrs(context: Context?, attrs: AttributeSet?) {
|
||||
// context?.let {
|
||||
// Log.e(TAG, "numOfDayView >>>> ${numOfDayView}")
|
||||
// var typedArray = it.obtainStyledAttributes(attrs, R.styleable.BaseCustomViews)
|
||||
// layouId = typedArray.getResourceId(R.styleable.BaseCustomViews_item_layout,R.layout.item_day).apply {
|
||||
// Log.e(TAG, "layouId 0 (${R.layout.item_day} Id >>>> ${this}")
|
||||
// }
|
||||
// initLayout(context)
|
||||
//
|
||||
// }
|
||||
// }
|
||||
|
||||
override fun onTypedArray(context: Context, typedArray: TypedArray) {
|
||||
super.onTypedArray(context, typedArray)
|
||||
numberOfday = typedArray.getResourceId(R.styleable.BaseCustomViews_numOfDayId, R.id.day_num).apply {
|
||||
Log.e(TAG, "numOfDayView 1 (${R.id.day_num}) Id >>>> ${this}")
|
||||
}
|
||||
displayDayNumber()
|
||||
}
|
||||
|
||||
override fun createdLayout(view: View) {
|
||||
super.createdLayout(view)
|
||||
(view as? ViewGroup)?.let {
|
||||
it.children.forEach { Log.e(TAG,"child is ${it}") }
|
||||
}
|
||||
}
|
||||
|
||||
fun displayDayNumber() {
|
||||
//todo 오늘 의 날짜를 표시
|
||||
numOfDayView?.text = dayInfo?.getDayOfNum()?.toString() ?: "TEST"
|
||||
Log.e(TAG, "numOfDayView?.text >>>> 4 ${numOfDayView?.text}")
|
||||
}
|
||||
|
||||
fun displayDayOfWeek() {
|
||||
@ -29,11 +84,14 @@ class DayView : BaseCustomViews {
|
||||
return false
|
||||
}
|
||||
|
||||
|
||||
override fun draw(canvas: Canvas) {
|
||||
canvas.drawColor(Color.CYAN)
|
||||
super.draw(canvas)
|
||||
|
||||
override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) {
|
||||
super.onMeasure(widthMeasureSpec, heightMeasureSpec)
|
||||
Log.e(TAG,"View >>> ${this}")
|
||||
}
|
||||
|
||||
// override fun draw(canvas: Canvas) {
|
||||
// super.draw(canvas)
|
||||
// canvas.drawColor(Color.CYAN)
|
||||
// }
|
||||
|
||||
}
|
||||
|
||||
@ -2,7 +2,7 @@ package com.example.calrendarview.model
|
||||
|
||||
|
||||
interface DayInfo {
|
||||
fun getDayOfNum()
|
||||
fun getDayOfWeek()
|
||||
fun isToday()
|
||||
fun getDayOfNum() : Int
|
||||
fun getDayOfWeek() : Int
|
||||
fun isToday() : Boolean
|
||||
}
|
||||
@ -3,12 +3,15 @@
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||
<TextView
|
||||
android:id="@+id/day_num"
|
||||
android:gravity="right|top"
|
||||
android:textSize="20dp"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:layout_constraintRight_toRightOf="parent"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"/>
|
||||
|
||||
|
||||
|
||||
<ImageView
|
||||
android:src="@android:drawable/btn_dialog"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
android:layout_width="200dp"
|
||||
android:layout_height="200dp"/>
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
@ -2,14 +2,16 @@
|
||||
<resources>
|
||||
|
||||
<attr name="item_layout" format="reference"/>
|
||||
|
||||
<attr name="numOfDayId" format="reference"/>
|
||||
|
||||
<declare-styleable name="BaseCustomViews">
|
||||
<attr name="item_layout"/>
|
||||
<attr name="numOfDayId"/>
|
||||
</declare-styleable>
|
||||
|
||||
<declare-styleable name="DayView">
|
||||
<attr name="item_layout"/>
|
||||
<attr name="numOfDayId"/>
|
||||
</declare-styleable>
|
||||
|
||||
<declare-styleable name="MonthView">
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user