Skip to content
Open
7 changes: 4 additions & 3 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
val compose_version by extra("1.0.1")
val kotlinCompilerExtensionVersion by extra("1.3.2")

repositories {
google()
mavenCentral()
}
dependencies {
classpath("com.android.tools.build:gradle:7.0.1")
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.5.21")
classpath("com.android.tools.build:gradle:7.3.1")
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.7.20")

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle.kts files
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Thu Jul 22 19:40:39 IST 2021
distributionBase=GRADLE_USER_HOME
distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5.1-bin.zip
distributionPath=wrapper/dists
zipStorePath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
32 changes: 20 additions & 12 deletions plot/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ ext {
apply(from = "publish.gradle")

android {
compileSdk = 30
compileSdk = 33

defaultConfig {
minSdk = 21
targetSdk = 30
targetSdk = 33
version = libVersion
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
}
Expand All @@ -45,24 +45,32 @@ android {
compose = true
}
composeOptions {
kotlinCompilerExtensionVersion = rootProject.extra["compose_version"] as String
kotlinCompilerExtensionVersion = rootProject.extra["kotlinCompilerExtensionVersion"] as String
}
lint {
isAbortOnError = true
isWarningsAsErrors = true
abortOnError = true
warningsAsErrors = true
}
namespace = "com.madrapps.plot"
}

dependencies {
implementation("androidx.core:core-ktx:1.6.0")
implementation("androidx.appcompat:appcompat:1.3.1")
implementation("com.google.android.material:material:1.4.0")
implementation("androidx.compose.ui:ui:${rootProject.extra["compose_version"]}")
implementation("androidx.compose.material:material:${rootProject.extra["compose_version"]}")
implementation("androidx.compose.ui:ui-tooling:${rootProject.extra["compose_version"]}")
implementation("androidx.core:core-ktx:1.9.0")
implementation("androidx.appcompat:appcompat:1.5.1")
implementation("com.google.android.material:material:1.7.0")

// Compose
val composeBom = platform("androidx.compose:compose-bom:2022.10.00")
implementation(composeBom)
androidTestImplementation(composeBom)
implementation("androidx.compose.material3:material3")
implementation("androidx.compose.ui:ui")
implementation("androidx.compose.ui:ui-tooling-preview")
debugImplementation("androidx.compose.ui:ui-tooling")
androidTestImplementation("androidx.compose.ui:ui-test-junit4")
implementation("androidx.activity:activity-compose:1.6.1")

testImplementation("junit:junit:4.13.2")
androidTestImplementation("androidx.test.ext:junit:1.1.3")
androidTestImplementation("androidx.test.espresso:espresso-core:3.4.0")
androidTestImplementation("androidx.compose.ui:ui-test-junit4:${rootProject.extra["compose_version"]}")
}
2 changes: 1 addition & 1 deletion plot/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest package="com.madrapps.plot" />
<manifest />
22 changes: 12 additions & 10 deletions plot/src/main/java/com/madrapps/plot/Gestures.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.madrapps.plot

import android.annotation.SuppressLint
import androidx.compose.foundation.gestures.awaitFirstDown
import androidx.compose.foundation.gestures.calculateCentroidSize
import androidx.compose.foundation.gestures.calculateZoom
Expand All @@ -13,18 +14,15 @@ import androidx.compose.ui.input.pointer.PointerInputChange
import androidx.compose.ui.input.pointer.PointerInputScope
import androidx.compose.ui.input.pointer.changedToUp
import androidx.compose.ui.input.pointer.changedToUpIgnoreConsumed
import androidx.compose.ui.input.pointer.consumeAllChanges
import androidx.compose.ui.input.pointer.consumeDownChange
import androidx.compose.ui.input.pointer.consumePositionChange
import androidx.compose.ui.input.pointer.isOutOfBounds
import androidx.compose.ui.input.pointer.positionChange
import androidx.compose.ui.input.pointer.positionChangeConsumed
import androidx.compose.ui.input.pointer.positionChanged
import kotlinx.coroutines.TimeoutCancellationException
import kotlinx.coroutines.withTimeout
import kotlin.coroutines.cancellation.CancellationException
import kotlin.math.abs

@SuppressLint("ReturnFromAwaitPointerEventScope", "MultipleAwaitPointerEventScopes")
@SuppressWarnings("LoopWithTooManyJumpStatements")
internal suspend fun PointerInputScope.detectDragZoomGesture(
isZoomAllowed: Boolean = false,
Expand All @@ -47,7 +45,7 @@ internal suspend fun PointerInputScope.detectDragZoomGesture(

do {
val event = awaitPointerEvent()
val canceled = event.changes.any { it.positionChangeConsumed() }
val canceled = event.changes.any { it.isConsumed }
if (event.changes.size == 1) {
break
} else if (event.changes.size == 2) {
Expand All @@ -72,7 +70,7 @@ internal suspend fun PointerInputScope.detectDragZoomGesture(
}
event.changes.forEach {
if (it.positionChanged()) {
it.consumeAllChanges()
it.consume()
}
}
}
Expand All @@ -93,13 +91,13 @@ internal suspend fun PointerInputScope.detectDragZoomGesture(
if (
drag(drag.id) {
onDrag(it, it.positionChange())
it.consumePositionChange()
if (it.positionChange() != Offset.Zero) it.consume()
}
) {
// consume up if we quit drag gracefully with the up
currentEvent.changes.forEach {
if (it.changedToUp()) {
it.consumeDownChange()
if (it.pressed != it.previousPressed) it.consume()
}
}
onDragEnd()
Expand Down Expand Up @@ -136,7 +134,11 @@ private suspend fun PointerInputScope.awaitLongPressOrCancellation(
}

if (
event.changes.any { it.consumed.downChange || it.isOutOfBounds(size) }
event.changes.any { it.isConsumed || it.isOutOfBounds(
size,
extendedTouchPadding
)
}
) {
finished = true // Canceled
}
Expand All @@ -145,7 +147,7 @@ private suspend fun PointerInputScope.awaitLongPressOrCancellation(
// the existing pointer event because it comes after the Main pass we checked
// above.
val consumeCheck = awaitPointerEvent(PointerEventPass.Final)
if (consumeCheck.changes.any { it.positionChangeConsumed() }) {
if (consumeCheck.changes.any { it.isConsumed }) {
finished = true
}
if (!event.isPointerUp(currentDown.id)) {
Expand Down
12 changes: 6 additions & 6 deletions plot/src/main/java/com/madrapps/plot/line/Components.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.madrapps.plot.line

import androidx.compose.material.MaterialTheme
import androidx.compose.material.Text
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.geometry.Rect
Expand Down Expand Up @@ -288,8 +288,8 @@ data class LinePlot(
text = value.string(),
maxLines = 1,
overflow = TextOverflow.Ellipsis,
style = MaterialTheme.typography.caption,
color = MaterialTheme.colors.onSurface
style = MaterialTheme.typography.labelMedium,
color = MaterialTheme.colorScheme.onSurface
)
if (value > max) {
break
Expand Down Expand Up @@ -322,8 +322,8 @@ data class LinePlot(
text = value.string(),
maxLines = 1,
overflow = TextOverflow.Ellipsis,
style = MaterialTheme.typography.caption,
color = MaterialTheme.colors.onSurface
style = MaterialTheme.typography.labelMedium,
color = MaterialTheme.colorScheme.onSurface
)
}
}
Expand Down
4 changes: 2 additions & 2 deletions plot/src/main/java/com/madrapps/plot/line/LineGraph.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.wrapContentHeight
import androidx.compose.foundation.layout.wrapContentWidth
import androidx.compose.material.MaterialTheme
import androidx.compose.material3.MaterialTheme
import androidx.compose.runtime.Composable
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.runtime.mutableStateOf
Expand Down Expand Up @@ -74,7 +74,7 @@ fun LineGraph(
val xZoom = remember { mutableStateOf(globalXScale) }
val rowHeight = remember { mutableStateOf(0f) }
val columnWidth = remember { mutableStateOf(0f) }
val bgColor = MaterialTheme.colors.surface
val bgColor = MaterialTheme.colorScheme.surface

val lines = plot.lines
val xUnit = plot.xAxis.unit
Expand Down
37 changes: 20 additions & 17 deletions sample/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ plugins {
}

android {
compileSdk = 30
compileSdk = 33
buildToolsVersion = "30.0.3"

defaultConfig {
applicationId = "com.madrapps.plot"
minSdk = 21
targetSdk = 30
targetSdk = 33
versionCode = 1
versionName = "0.1.0"

Expand All @@ -35,37 +35,40 @@ android {
}
kotlinOptions {
jvmTarget = "1.8"
useIR = true
}
buildFeatures {
compose = true
}
composeOptions {
kotlinCompilerExtensionVersion = rootProject.extra["compose_version"] as String
kotlinCompilerExtensionVersion = rootProject.extra["kotlinCompilerExtensionVersion"] as String
}
lint {
isAbortOnError = true
isWarningsAsErrors = true
abortOnError = true
warningsAsErrors = true
}
namespace = "com.madrapps.sample"
}

dependencies {
// implementation(project(mapOf("path" to ":plot")))
implementation("com.github.madrapps:plot:0.1.1")

implementation("androidx.core:core-ktx:1.6.0")
implementation("androidx.appcompat:appcompat:1.3.1")
implementation("com.google.android.material:material:1.4.0")
implementation("androidx.compose.ui:ui:${rootProject.extra["compose_version"]}")
implementation("androidx.compose.material:material:${rootProject.extra["compose_version"]}")
implementation("androidx.compose.ui:ui-tooling:${rootProject.extra["compose_version"]}")
implementation("androidx.lifecycle:lifecycle-runtime-ktx:2.3.1")
implementation("androidx.activity:activity-compose:1.3.1")
implementation("androidx.activity:activity-ktx:1.3.1")
implementation("androidx.compose.runtime:runtime-livedata:${rootProject.extra["compose_version"]}")
implementation("androidx.core:core-ktx:1.9.0")
implementation("androidx.appcompat:appcompat:1.5.1")
implementation("com.google.android.material:material:1.7.0")

// Compose
val composeBom = platform("androidx.compose:compose-bom:2022.10.00")
implementation(composeBom)
androidTestImplementation(composeBom)
implementation("androidx.compose.material3:material3")
implementation("androidx.compose.ui:ui")
implementation("androidx.compose.ui:ui-tooling-preview")
debugImplementation("androidx.compose.ui:ui-tooling")
androidTestImplementation("androidx.compose.ui:ui-test-junit4")
implementation("androidx.activity:activity-compose:1.6.1")

testImplementation("junit:junit:4.13.2")
androidTestImplementation("androidx.test.ext:junit:1.1.3")
androidTestImplementation("androidx.test.espresso:espresso-core:3.4.0")
androidTestImplementation("androidx.compose.ui:ui-test-junit4:${rootProject.extra["compose_version"]}")
}
4 changes: 1 addition & 3 deletions sample/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.madrapps.sample">
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

<application
android:allowBackup="false"
Expand All @@ -12,7 +11,6 @@
<activity
android:name="com.madrapps.sample.MainActivity"
android:exported="true"
android:label="@string/app_name"
android:theme="@style/Theme.Plot.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package com.madrapps.sample.linegraph
import androidx.compose.foundation.Canvas
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.material.MaterialTheme
import androidx.compose.material.Text
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
Expand Down Expand Up @@ -38,7 +38,7 @@ internal fun LineGraph3(lines: List<List<DataPoint>>) {
androidx.compose.foundation.layout.Column {
val isMajor = value % 4 == 0f
val radius = if (isMajor) 6f else 3f
val color = MaterialTheme.colors.onSurface
val color = MaterialTheme.colorScheme.onSurface
Canvas(
modifier = Modifier
.align(Alignment.CenterHorizontally)
Expand All @@ -55,7 +55,7 @@ internal fun LineGraph3(lines: List<List<DataPoint>>) {
text = DecimalFormat("#.#").format(value),
maxLines = 1,
overflow = TextOverflow.Ellipsis,
style = MaterialTheme.typography.caption,
style = MaterialTheme.typography.labelMedium,
color = color
)
}
Expand Down
14 changes: 7 additions & 7 deletions sample/src/main/java/com/madrapps/sample/linegraph/LineGraph4.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.width
import androidx.compose.material.MaterialTheme
import androidx.compose.material.Surface
import androidx.compose.material.Text
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Surface
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
Expand Down Expand Up @@ -69,7 +69,7 @@ internal fun LineGraph4(lines: List<List<DataPoint>>, modifier: Modifier) {
Text(
modifier = Modifier.padding(vertical = 8.dp),
text = "Score at $x:00 hrs",
style = MaterialTheme.typography.subtitle1,
style = MaterialTheme.typography.headlineMedium,
color = Color.Gray
)
ScoreRow("Today", value[1].y, Color.Blue)
Expand All @@ -81,7 +81,7 @@ internal fun LineGraph4(lines: List<List<DataPoint>>, modifier: Modifier) {
}
}
val padding = 16.dp
MaterialTheme(colors = MaterialTheme.colors.copy(surface = Color.White)) {
MaterialTheme(colorScheme = MaterialTheme.colorScheme.copy(surface = Color.White)) {
LineGraph(
plot = LinePlot(
listOf(
Expand Down Expand Up @@ -150,7 +150,7 @@ private fun ScoreRow(title: String, value: Float, color: Color) {
)
Text(
text = title,
style = MaterialTheme.typography.subtitle1,
style = MaterialTheme.typography.headlineMedium,
color = Color.DarkGray
)
}
Expand All @@ -159,7 +159,7 @@ private fun ScoreRow(title: String, value: Float, color: Color) {
.padding(end = 8.dp)
.align(Alignment.CenterEnd),
text = formatted,
style = MaterialTheme.typography.subtitle2,
style = MaterialTheme.typography.headlineSmall,
color = Color.DarkGray
)
}
Expand Down
2 changes: 1 addition & 1 deletion sample/src/main/java/com/madrapps/sample/ui/theme/Shape.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.madrapps.sample.ui.theme

import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.Shapes
import androidx.compose.material3.Shapes
import androidx.compose.ui.unit.dp

val Shapes = Shapes(
Expand Down
Loading