Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,23 @@ plugins {
}

android {
compileSdkVersion 30
buildToolsVersion "30.0.3"

compileSdk 34
buildToolsVersion '34.0.0'
namespace 'otus.homework.customview'
defaultConfig {
applicationId "otus.homework.customview"
minSdkVersion 23
targetSdkVersion 30
targetSdkVersion 34
versionCode 1
versionName "1.0"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}

buildFeatures {
viewBinding = true
}

buildTypes {
release {
minifyEnabled false
Expand All @@ -39,6 +43,7 @@ dependencies {
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'com.google.android.material:material:1.3.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
implementation 'com.google.code.gson:gson:2.10.1'
testImplementation 'junit:junit:4.+'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
Expand Down
3 changes: 2 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.CustomView">
<activity android:name=".MainActivity">
<activity android:name=".MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

Expand Down
33 changes: 33 additions & 0 deletions app/src/main/java/otus/homework/customview/Extensions.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package otus.homework.customview

import android.content.Context
import android.graphics.Canvas
import android.text.StaticLayout
import android.util.TypedValue
import androidx.core.graphics.withTranslation


/**
* Context Extension для конвертирования значения в пиксели.
* @property dp - значение density-independent pixels
*/
fun Context.dpToPx(dp: Int): Float {
return dp.toFloat() * this.resources.displayMetrics.density
}

/**
* Context Extension для конвертирования значения размера шрифта в пиксели.
* @property sp - значение scale-independent pixels
*/
fun Context.spToPx(sp: Int): Float {
return TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, sp.toFloat(), this.resources.displayMetrics);
}

/**
* StaticLayout Extension для удобства отрисовки текста.
*/
fun StaticLayout.draw(canvas: Canvas, x: Float, y: Float) {
canvas.withTranslation(x, y) {
draw(this)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package otus.homework.customview.LineChart
import java.util.ArrayDeque

internal class ColorRandomizer {

private val colorsList = listOf(
-0xbbcca, -0x16e19d, -0x63d850, -0x98c549,
-0xc0ae4b, -0xde690d, -0xfc560c, -0xff432c,
-0xff6978, -0xb350b0, -0x743cb6, -0x3223c7,
-0x14c5, -0x3ef9, -0x6800, -0xa8de,
-0x86aab8, -0x616162, -0x9f8275, -0xcccccd
)
private var colors = ArrayDeque(colorsList)

val color: Int
get() {
if (colors.size == 0) {
colors = ArrayDeque(colorsList.shuffled())
}
return colors.pop()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package otus.homework.customview.LineChart

import android.graphics.PointF

data class LineGraphItem(
val points: List<PointF>,
val color: Int
)
Loading