Skip to content

Commit

Permalink
Merge pull request #1 from YuriyBereguliak/develop
Browse files Browse the repository at this point in the history
Develop - preparing to first release
  • Loading branch information
YuriyBereguliak authored Jan 22, 2019
2 parents 922fb2e + 1df6499 commit 84fcc35
Show file tree
Hide file tree
Showing 35 changed files with 659 additions and 29 deletions.
2 changes: 1 addition & 1 deletion .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,6 @@ dependencies {
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'

api project(':heatchart')
}
66 changes: 65 additions & 1 deletion app/src/main/java/com/bereguliak/yuriy/hitchart/MainActivity.kt
Original file line number Diff line number Diff line change
@@ -1,12 +1,76 @@
package com.bereguliak.yuriy.hitchart

import android.support.v7.app.AppCompatActivity
import android.os.Bundle
import android.support.v7.app.AppCompatActivity
import com.by.heatchart.data.index.IndexHeatChartDataEntry
import com.by.heatchart.data.index.IndexHeatChartDataSet
import com.by.heatchart.data.range.RangeHeatChartDataSet
import com.by.heatchart.data.range.RangeHeatChartEntry
import kotlinx.android.synthetic.main.activity_main.*

class MainActivity : AppCompatActivity() {

//region AppCompatActivity
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)

initFirstRangeChart()

initSecondCustomRangeChart()

initThirdIndexChart()
}
//endregion

//region Utility API
private fun initFirstRangeChart() {
val mutableListFirst = mutableListOf<RangeHeatChartEntry>()
with(mutableListFirst) {
add(RangeHeatChartEntry(0, 20))
add(RangeHeatChartEntry(10, 25))
add(RangeHeatChartEntry(12, 20))
add(RangeHeatChartEntry(15, 18))
add(RangeHeatChartEntry(35, 44))
add(RangeHeatChartEntry(40, 50))
add(RangeHeatChartEntry(43, 55))
add(RangeHeatChartEntry(45, 70))
add(RangeHeatChartEntry(80, 90))
add(RangeHeatChartEntry(85, 98))
add(RangeHeatChartEntry(88, 100))
}
topChartView.dataSet(RangeHeatChartDataSet(rangeData = mutableListFirst))
}

private fun initSecondCustomRangeChart() {
val mutableListWithColor = mutableListOf<RangeHeatChartEntry>()
with(mutableListWithColor) {
add(RangeHeatChartEntry(0, 20))
add(RangeHeatChartEntry(10, 25))
add(RangeHeatChartEntry(45, 70))
add(RangeHeatChartEntry(75, 90))
add(RangeHeatChartEntry(80, 90))
add(RangeHeatChartEntry(85, 95))
}

val dataSet = RangeHeatChartDataSet()
dataSet.parts = 100f
dataSet.rangeData = mutableListWithColor

secondChart.dataSet(dataSet)
}

private fun initThirdIndexChart() {
val mutableList = mutableListOf<IndexHeatChartDataEntry>()

with(mutableList) {
add(IndexHeatChartDataEntry(0, 2))
add(IndexHeatChartDataEntry(2, 1))
add(IndexHeatChartDataEntry(5, 6))
add(IndexHeatChartDataEntry(7, 3))
}

indexChartView.dataSet(IndexHeatChartDataSet(10f, mutableList))
}
//endregion
}
61 changes: 54 additions & 7 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
@@ -1,19 +1,66 @@
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">

<TextView
<com.by.heatchart.view.range.RangeHeatChartView
android:id="@+id/topChartView"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
android:layout_margin="8dp"
app:chartColor="@color/green"
app:chartFrameWidth="@dimen/chart_border_width"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toTopOf="@+id/guideline"/>

<android.support.constraint.Guideline
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/guideline"
android:orientation="horizontal"
app:layout_constraintGuide_percent="0.15"/>

<com.by.heatchart.view.range.RangeHeatChartView
android:id="@+id/secondChart"
android:layout_margin="8dp"
android:layout_width="0dp"
android:layout_height="0dp"
app:chartColor="@color/pink"
app:chartFrameWidth="@dimen/chart_border_width"
app:layout_constraintBottom_toTopOf="@+id/guideline2"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="@+id/guideline"/>

<android.support.constraint.Guideline
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"/>
android:id="@+id/guideline2"
android:orientation="horizontal"
app:layout_constraintGuide_percent="0.30"/>

<com.by.heatchart.view.index.IndexHeatChartView
android:id="@+id/indexChartView"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_margin="8dp"
app:chartFrameWidth="@dimen/chart_border_width"
app:chartFrameSeparatorWidth="@dimen/chart_separator_width"
app:layout_constraintBottom_toTopOf="@+id/guideline3"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="@+id/guideline2"/>

<android.support.constraint.Guideline
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/guideline3"
android:orientation="horizontal"
app:layout_constraintGuide_percent="0.45"/>
</android.support.constraint.ConstraintLayout>
2 changes: 2 additions & 0 deletions app/src/main/res/values/colors.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,6 @@
<color name="colorPrimary">#008577</color>
<color name="colorPrimaryDark">#00574B</color>
<color name="colorAccent">#D81B60</color>

<color name="pink">#40D81B60</color>
</resources>
2 changes: 1 addition & 1 deletion app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<resources>
<string name="app_name">HitChart</string>
<string name="app_name">HeatChart</string>
</resources>
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.by.hitchart;
package com.by.heatchart;

import android.content.Context;
import android.support.test.InstrumentationRegistry;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.by.hitchart"/>
package="com.by.heatchart"/>
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package com.by.heatchart.core.controller

import android.content.Context
import android.graphics.Canvas
import android.graphics.Paint
import android.graphics.Rect
import android.support.annotation.CallSuper
import com.by.heatchart.data.ChartData
import java.lang.ref.WeakReference

/**
* HitChart
* Created by Yuriy Bereguliak on 1/22/19.
*/
abstract class BaseDrawController<in T>(context: Context, private val chartData: ChartData) : DrawController<T> {

protected val contextReference = WeakReference(context)
private var framePaint = Paint()

init {
contextReference.get()?.let {
framePaint.style = Paint.Style.STROKE
framePaint.isAntiAlias = true
framePaint.strokeWidth = chartData.frameBorderWidth
framePaint.color = chartData.frameColor
}
}

//region BaseDrawController
protected fun drawFrame(canvas: Canvas) {
val rect = Rect()
rect.top = 0
rect.left = 0
rect.right = chartData.width
rect.bottom = chartData.height

canvas.drawRect(rect, framePaint)
}
//endregion

//region DrawController
@CallSuper
override fun release() {
contextReference.clear()
}
//endregion
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.by.heatchart.core.controller

import android.graphics.Canvas

/**
* HitChart
* Created by Yuriy Bereguliak on 1/22/19.
*/
interface DrawController<in T> {
fun draw(canvas: Canvas, data: T)

fun release()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.by.heatchart.core.manager

import com.by.heatchart.core.controller.DrawController
import com.by.heatchart.data.ChartData

/**
* HitChart
* Created by Yuriy Bereguliak on 1/22/19.
*/
abstract class BaseDrawManager<T> : DrawManager<T> {

protected val chart = ChartData()

protected val drawController: DrawController<T> by lazy {
initDrawController()
}

//region BaseDrawManager
abstract fun initDrawController(): DrawController<T>
//endregion

//region DrawManager
override fun chartData() = chart

override fun release() {
drawController.release()
}
//endregion
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.by.heatchart.core.manager

import android.graphics.Canvas
import com.by.heatchart.data.ChartData

/**
* ChartData
* Created by Yuriy Bereguliak on 1/18/19.
*/
interface DrawManager<in T> {
fun chartData(): ChartData

fun draw(canvas: Canvas)

fun dataSet(dataSet: T)

fun release()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
package com.by.heatchart.core.view

import android.content.Context
import android.graphics.Canvas
import android.support.v4.content.ContextCompat
import android.util.AttributeSet
import android.view.View
import com.by.heatchart.R
import com.by.heatchart.core.manager.DrawManager

/**
* HitChart
* Created by Yuriy Bereguliak on 1/22/19.
*/
abstract class BaseChartView<T>(context: Context, attrs: AttributeSet? = null) : View(context, attrs),
ChartViewController<T> {

private val chartManager: DrawManager<T> by lazy { initChartManager() }

init {
attrs?.let {
val typedArray = context.obtainStyledAttributes(it, R.styleable.BaseChartView)

chartManager.chartData().chartColor = typedArray.getColor(
R.styleable.BaseChartView_chartColor,
ContextCompat.getColor(context, R.color.blue)
)

chartManager.chartData().frameColor = typedArray.getColor(
R.styleable.BaseChartView_chartFrameColor,
ContextCompat.getColor(context, R.color.gray_400)
)

chartManager.chartData().backgroundColor = typedArray.getColor(
R.styleable.BaseChartView_chartBackgroundColor,
ContextCompat.getColor(context, R.color.gray_400)
)

chartManager.chartData().separatorColor = typedArray.getColor(
R.styleable.BaseChartView_chartSeparatorColor,
ContextCompat.getColor(context, R.color.gray_400)
)

chartManager.chartData().frameBorderWidth = typedArray.getDimension(
R.styleable.BaseChartView_chartFrameWidth,
context.resources.getDimension(R.dimen.chart_border_width)
)

chartManager.chartData().frameSeparatorWidth = typedArray.getDimension(
R.styleable.BaseChartView_chartFrameSeparatorWidth,
context.resources.getDimension(R.dimen.chart_separator_width)
)

typedArray.recycle()
}
}

//region BaseChartView
abstract fun initChartManager(): DrawManager<T>
//endregion

//region View
override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) {
val width = View.MeasureSpec.getSize(widthMeasureSpec)
val height = View.MeasureSpec.getSize(heightMeasureSpec)
chartManager.chartData().width = width
chartManager.chartData().height = height
setMeasuredDimension(width, height)
}

override fun onDraw(canvas: Canvas?) {
super.onDraw(canvas)
canvas?.let {
chartManager.draw(it)
}
}
//endregion

//region ChartViewController
override fun dataSet(dataSet: T) {
post {
chartManager.dataSet(dataSet)
}
}

override fun release() {
chartManager.release()
}
//endregion
}
Loading

0 comments on commit 84fcc35

Please sign in to comment.