-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from YuriyBereguliak/develop
Develop - preparing to first release
- Loading branch information
Showing
35 changed files
with
659 additions
and
29 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 65 additions & 1 deletion
66
app/src/main/java/com/bereguliak/yuriy/hitchart/MainActivity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
2 changes: 1 addition & 1 deletion
2
.../by/hitchart/ExampleInstrumentedTest.java → ...by/heatchart/ExampleInstrumentedTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
hitchart/src/main/AndroidManifest.xml → heatchart/src/main/AndroidManifest.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"/> |
47 changes: 47 additions & 0 deletions
47
heatchart/src/main/java/com/by/heatchart/core/controller/BaseDrawController.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
13 changes: 13 additions & 0 deletions
13
heatchart/src/main/java/com/by/heatchart/core/controller/DrawController.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
} |
29 changes: 29 additions & 0 deletions
29
heatchart/src/main/java/com/by/heatchart/core/manager/BaseDrawManager.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
18 changes: 18 additions & 0 deletions
18
heatchart/src/main/java/com/by/heatchart/core/manager/DrawManager.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
} |
90 changes: 90 additions & 0 deletions
90
heatchart/src/main/java/com/by/heatchart/core/view/BaseChartView.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
Oops, something went wrong.