Skip to content
Permalink
Browse files

drawing

  • Loading branch information...
migellal committed Apr 10, 2017
1 parent f6403fa commit 33b397b57a009a4c6f2fb8d3013361e1b7a28088
@@ -1,5 +1,6 @@
package pl.digitalzombielab.dayviewdemo

import android.graphics.Color
import android.os.Bundle
import android.support.v7.app.AppCompatActivity
import android.support.v7.widget.Toolbar
@@ -18,6 +19,8 @@ class MainActivity : AppCompatActivity() {
setSupportActionBar(toolbar)

dayView.date = Date()
dayView.cardBackgroundColor = Color.YELLOW
//dayView.borderColor = Color.GREEN
}

override fun onCreateOptionsMenu(menu: Menu): Boolean {
@@ -6,7 +6,7 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.0'
classpath 'com.android.tools.build:gradle:2.3.1'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"

// NOTE: Do not place your application dependencies here; they belong
@@ -1,5 +1,6 @@
package pl.digitalzombielab.dayview

import android.annotation.SuppressLint
import android.content.Context
import android.graphics.Canvas
import android.graphics.Color
@@ -17,16 +18,53 @@ import java.util.*

class DayView : View {

private var barPaint = Paint()
private var textDayPaint = Paint()
private var textMonthPaint = Paint()
private var backgroundPaint = Paint()
private var borderPaint = Paint()
private var day = String()
private var month = String()

var barColor = -12627531
set(value) {
field = value
barPaint.color = value
invalidate()
}
var textColor = -16777216
set(value) {
field = value
textDayPaint.color = value
textMonthPaint.color = value
invalidate()
}
var cardBackgroundColor = -1
set(value) {
field = value
backgroundPaint.color = value
invalidate()
}
var borderColor = -2302756
set(value) {
field = value
borderPaint.color = value
invalidate()
}
var date = Date()
set(value) {
field = value
day = date.day.toString()
month = date.month.toString()
invalidate()
}

private val paint = Paint()
private val rect = Rect()

constructor(ctx: Context) : super(ctx)
constructor(ctx: Context) : super(ctx) {
init()
}

constructor(ctx: Context, attrs: AttributeSet) : super(ctx, attrs) {
val a = context.theme.obtainStyledAttributes(
attrs,
@@ -44,14 +82,37 @@ class DayView : View {
} finally {
a.recycle()
}
init()
}

private fun init() {
backgroundPaint.color = cardBackgroundColor
borderPaint.color = borderColor
barPaint.color = barColor
textDayPaint.color = textColor
textMonthPaint.color = textColor
backgroundPaint.style = Paint.Style.FILL
borderPaint.style = Paint.Style.STROKE
borderPaint.strokeWidth = 10F
barPaint.style = Paint.Style.FILL

}

@SuppressLint("NewApi")
override fun onDraw(canvas: Canvas?) {
super.onDraw(canvas)
paint.color = Color.WHITE
paint.style = Paint.Style.FILL
canvas?.drawPaint(paint)
drawTextCenter(canvas, paint, System.currentTimeMillis().toString())
canvas?.drawPaint(backgroundPaint)
canvas?.drawRect(50F, 50F, 300F, 300F, borderPaint)
canvas?.drawRect(80F, 80F, 350F, 350F, barPaint)
canvas?.drawRoundRect(400F, 400F, 800F, 1000F, 50F, 50F, barPaint)
}

override fun onSizeChanged(xNew: Int, yNew: Int, xOld: Int, yOld: Int) {
super.onSizeChanged(xNew, yNew, xOld, yOld)
}

override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec)
}

private fun drawTextCenter(canvas: Canvas?, paint: Paint, text: String) {

0 comments on commit 33b397b

Please sign in to comment.
You can’t perform that action at this time.