From 426d96c5899686b7a06ce6e23927dcc2807e1284 Mon Sep 17 00:00:00 2001 From: Leonard Dizon Date: Wed, 19 Oct 2022 00:18:34 +0800 Subject: [PATCH] Update compile and target SDK to 33 (Android 13) Main breaking change: the `MotionEvent` parameters on `GestureDetector.OnGestureListener` interface are now non-nullable. --- uhabits-android/build.gradle.kts | 4 ++-- .../common/views/FrequencyChartTest.kt | 8 +++++++- .../activities/common/views/ScoreChartTest.kt | 8 +++++++- .../isoron/platform/gui/AndroidDataView.kt | 20 +++++++++---------- .../common/views/ScrollableChart.kt | 2 +- 5 files changed, 27 insertions(+), 15 deletions(-) diff --git a/uhabits-android/build.gradle.kts b/uhabits-android/build.gradle.kts index 2cb5be48a..eaf2b81b4 100644 --- a/uhabits-android/build.gradle.kts +++ b/uhabits-android/build.gradle.kts @@ -42,13 +42,13 @@ kotlin { android { - compileSdk = 32 + compileSdk = 33 defaultConfig { versionCode = 20200 versionName = "2.2.0" minSdk = 28 - targetSdk = 32 + targetSdk = 33 applicationId = "org.isoron.uhabits" testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" } diff --git a/uhabits-android/src/androidTest/java/org/isoron/uhabits/activities/common/views/FrequencyChartTest.kt b/uhabits-android/src/androidTest/java/org/isoron/uhabits/activities/common/views/FrequencyChartTest.kt index 0c4225f99..390644283 100644 --- a/uhabits-android/src/androidTest/java/org/isoron/uhabits/activities/common/views/FrequencyChartTest.kt +++ b/uhabits-android/src/androidTest/java/org/isoron/uhabits/activities/common/views/FrequencyChartTest.kt @@ -18,6 +18,7 @@ */ package org.isoron.uhabits.activities.common.views +import android.view.MotionEvent import androidx.test.ext.junit.runners.AndroidJUnit4 import androidx.test.filters.MediumTest import org.isoron.uhabits.BaseViewTest @@ -52,7 +53,12 @@ class FrequencyChartTest : BaseViewTest() { @Test @Throws(Throwable::class) fun testRender_withDataOffset() { - view.onScroll(null, null, -dpToPixels(150), 0f) + view.onScroll( + MotionEvent.obtain(0L, 0L, MotionEvent.ACTION_SCROLL, 0f, 0f, 0), + MotionEvent.obtain(0L, 0L, MotionEvent.ACTION_SCROLL, 0f, 0f, 0), + -dpToPixels(150), + 0f + ) view.invalidate() assertRenders(view, BASE_PATH + "renderDataOffset.png") } diff --git a/uhabits-android/src/androidTest/java/org/isoron/uhabits/activities/common/views/ScoreChartTest.kt b/uhabits-android/src/androidTest/java/org/isoron/uhabits/activities/common/views/ScoreChartTest.kt index 4f504d8be..e82693461 100644 --- a/uhabits-android/src/androidTest/java/org/isoron/uhabits/activities/common/views/ScoreChartTest.kt +++ b/uhabits-android/src/androidTest/java/org/isoron/uhabits/activities/common/views/ScoreChartTest.kt @@ -18,6 +18,7 @@ */ package org.isoron.uhabits.activities.common.views +import android.view.MotionEvent import androidx.test.ext.junit.runners.AndroidJUnit4 import androidx.test.filters.MediumTest import org.isoron.uhabits.BaseViewTest @@ -63,7 +64,12 @@ class ScoreChartTest : BaseViewTest() { @Test @Throws(Throwable::class) fun testRender_withDataOffset() { - view.onScroll(null, null, -dpToPixels(150), 0f) + view.onScroll( + MotionEvent.obtain(0L, 0L, MotionEvent.ACTION_SCROLL, 0f, 0f, 0), + MotionEvent.obtain(0L, 0L, MotionEvent.ACTION_SCROLL, 0f, 0f, 0), + -dpToPixels(150), + 0f + ) view.invalidate() assertRenders(view, BASE_PATH + "renderDataOffset.png") } diff --git a/uhabits-android/src/main/java/org/isoron/platform/gui/AndroidDataView.kt b/uhabits-android/src/main/java/org/isoron/platform/gui/AndroidDataView.kt index 990314a06..f0dcd378a 100644 --- a/uhabits-android/src/main/java/org/isoron/platform/gui/AndroidDataView.kt +++ b/uhabits-android/src/main/java/org/isoron/platform/gui/AndroidDataView.kt @@ -44,21 +44,21 @@ class AndroidDataView( addUpdateListener(this@AndroidDataView) } - override fun onTouchEvent(event: MotionEvent?) = detector.onTouchEvent(event) - override fun onDown(e: MotionEvent?) = true - override fun onShowPress(e: MotionEvent?) = Unit + override fun onTouchEvent(event: MotionEvent) = detector.onTouchEvent(event) + override fun onDown(e: MotionEvent) = true + override fun onShowPress(e: MotionEvent) = Unit - override fun onSingleTapUp(e: MotionEvent?): Boolean { + override fun onSingleTapUp(e: MotionEvent): Boolean { return handleClick(e, true) } - override fun onLongPress(e: MotionEvent?) { + override fun onLongPress(e: MotionEvent) { handleClick(e) } override fun onScroll( - e1: MotionEvent?, - e2: MotionEvent?, + e1: MotionEvent, + e2: MotionEvent, dx: Float, dy: Float ): Boolean { @@ -79,8 +79,8 @@ class AndroidDataView( } override fun onFling( - e1: MotionEvent?, - e2: MotionEvent?, + e1: MotionEvent, + e2: MotionEvent, velocityX: Float, velocityY: Float ): Boolean { @@ -100,7 +100,7 @@ class AndroidDataView( return false } - override fun onAnimationUpdate(animation: ValueAnimator?) { + override fun onAnimationUpdate(animation: ValueAnimator) { if (!scroller.isFinished) { scroller.computeScrollOffset() updateDataOffset() diff --git a/uhabits-android/src/main/java/org/isoron/uhabits/activities/common/views/ScrollableChart.kt b/uhabits-android/src/main/java/org/isoron/uhabits/activities/common/views/ScrollableChart.kt index 509acc067..b69e491fe 100644 --- a/uhabits-android/src/main/java/org/isoron/uhabits/activities/common/views/ScrollableChart.kt +++ b/uhabits-android/src/main/java/org/isoron/uhabits/activities/common/views/ScrollableChart.kt @@ -116,7 +116,7 @@ abstract class ScrollableChart : View, GestureDetector.OnGestureListener, Animat return BundleSavedState(superState, bundle) } - override fun onScroll(e1: MotionEvent?, e2: MotionEvent?, dx: Float, dy: Float): Boolean { + override fun onScroll(e1: MotionEvent, e2: MotionEvent, dx: Float, dy: Float): Boolean { var dx = dx if (scrollerBucketSize == 0) return false if (abs(dx) > abs(dy)) {