From 4e8585fde51ceeb9764f798dc56fa066b68c86ed Mon Sep 17 00:00:00 2001 From: Thomas Horta Date: Fri, 1 Sep 2023 20:01:56 -0300 Subject: [PATCH 1/3] Update compileSdkVersion to 34 --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index 89b12acb..f40f379e 100644 --- a/build.gradle +++ b/build.gradle @@ -85,7 +85,7 @@ subprojects { ext { minSdkVersion = 24 - compileSdkVersion = 33 + compileSdkVersion = 34 targetSdkVersion = 33 } From 5e63b719d447a7071051364f9795e077764d3b9f Mon Sep 17 00:00:00 2001 From: Thomas Horta Date: Tue, 12 Sep 2023 16:38:38 -0300 Subject: [PATCH 2/3] Fix compilation errors for SDK 34 --- .../com/automattic/loop/photopicker/PhotoPickerActivity.java | 5 +++-- .../wordpress/stories/compose/ComposeLoopFrameActivity.kt | 4 +++- .../wordpress/stories/compose/VideoRecordingControlView.kt | 2 +- .../com/wordpress/stories/compose/text/TextSizeSlider.kt | 1 + 4 files changed, 8 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/com/automattic/loop/photopicker/PhotoPickerActivity.java b/app/src/main/java/com/automattic/loop/photopicker/PhotoPickerActivity.java index 3dc9ea47..d1d016ff 100644 --- a/app/src/main/java/com/automattic/loop/photopicker/PhotoPickerActivity.java +++ b/app/src/main/java/com/automattic/loop/photopicker/PhotoPickerActivity.java @@ -405,8 +405,9 @@ private class FlingGestureListener extends SimpleOnGestureListener { private static final int SWIPE_MIN_DISTANCE = 120; private static final int SWIPE_THRESHOLD_VELOCITY = 200; - @Override public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) { - if (e1 != null && e2 != null) { + @Override + public boolean onFling(@Nullable MotionEvent e1, @NonNull MotionEvent e2, float velocityX, float velocityY) { + if (e1 != null) { if (e2.getY() - e1.getY() > SWIPE_MIN_DISTANCE && Math.abs(velocityY) > SWIPE_THRESHOLD_VELOCITY) { // Top to bottom diff --git a/stories/src/main/java/com/wordpress/stories/compose/ComposeLoopFrameActivity.kt b/stories/src/main/java/com/wordpress/stories/compose/ComposeLoopFrameActivity.kt index 9f37b4ee..f05262ae 100644 --- a/stories/src/main/java/com/wordpress/stories/compose/ComposeLoopFrameActivity.kt +++ b/stories/src/main/java/com/wordpress/stories/compose/ComposeLoopFrameActivity.kt @@ -2292,7 +2292,9 @@ abstract class ComposeLoopFrameActivity : AppCompatActivity(), OnStoryFrameSelec } private inner class FlingGestureListener : GestureDetector.SimpleOnGestureListener() { - override fun onFling(e1: MotionEvent, e2: MotionEvent, velocityX: Float, velocityY: Float): Boolean { + override fun onFling(e1: MotionEvent?, e2: MotionEvent, velocityX: Float, velocityY: Float): Boolean { + if (e1 == null) return super.onFling(null, e2, velocityX, velocityY) + if (e1.y - e2.y > SWIPE_MIN_DISTANCE && abs(velocityY) > SWIPE_THRESHOLD_VELOCITY) { // Bottom to top val ycoordStart = e1.y diff --git a/stories/src/main/java/com/wordpress/stories/compose/VideoRecordingControlView.kt b/stories/src/main/java/com/wordpress/stories/compose/VideoRecordingControlView.kt index b5d564a4..f9bab230 100644 --- a/stories/src/main/java/com/wordpress/stories/compose/VideoRecordingControlView.kt +++ b/stories/src/main/java/com/wordpress/stories/compose/VideoRecordingControlView.kt @@ -61,7 +61,7 @@ class VideoRecordingControlView @JvmOverloads constructor( override fun onSizeChanged(w: Int, h: Int, oldw: Int, oldh: Int) { if (w != oldw || h != oldh) { - bitmap = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888)?.apply { + bitmap = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888).apply { eraseColor(Color.TRANSPARENT) viewCanvas = Canvas(this) } diff --git a/stories/src/main/java/com/wordpress/stories/compose/text/TextSizeSlider.kt b/stories/src/main/java/com/wordpress/stories/compose/text/TextSizeSlider.kt index 05fd6f47..5a4dfa30 100644 --- a/stories/src/main/java/com/wordpress/stories/compose/text/TextSizeSlider.kt +++ b/stories/src/main/java/com/wordpress/stories/compose/text/TextSizeSlider.kt @@ -29,6 +29,7 @@ class TextSizeSlider( }) } + @Suppress("DEPRECATION") fun update() { val fontSizeSp = (textView.textSize / resources.displayMetrics.scaledDensity).toInt() seekBar.progress = (fontSizeSp - TEXT_SIZE_SLIDER_MIN_VALUE) / TEXT_SIZE_SLIDER_STEP From b388ab59b9b232830719327b7871b124cb7dcaf2 Mon Sep 17 00:00:00 2001 From: Thomas Horta Date: Tue, 12 Sep 2023 16:40:30 -0300 Subject: [PATCH 3/3] Enhance TextSizeSlider update by using deriveDimension The new deriveDimension API introduced in Android 14 takes into account text specifics, such as font size multipliers set by the user in the system settings. The enhancement here uses this API when running on Android 14 while using the old (and now deprecated) scaledDensity calculation. --- .../stories/compose/text/TextSizeSlider.kt | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/stories/src/main/java/com/wordpress/stories/compose/text/TextSizeSlider.kt b/stories/src/main/java/com/wordpress/stories/compose/text/TextSizeSlider.kt index 5a4dfa30..50fec1b2 100644 --- a/stories/src/main/java/com/wordpress/stories/compose/text/TextSizeSlider.kt +++ b/stories/src/main/java/com/wordpress/stories/compose/text/TextSizeSlider.kt @@ -1,6 +1,7 @@ package com.wordpress.stories.compose.text import android.content.res.Resources +import android.os.Build import android.util.TypedValue import android.widget.SeekBar import android.widget.SeekBar.OnSeekBarChangeListener @@ -31,8 +32,17 @@ class TextSizeSlider( @Suppress("DEPRECATION") fun update() { - val fontSizeSp = (textView.textSize / resources.displayMetrics.scaledDensity).toInt() - seekBar.progress = (fontSizeSp - TEXT_SIZE_SLIDER_MIN_VALUE) / TEXT_SIZE_SLIDER_STEP + val fontSizeSp = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) { + // this takes into account text specifics (such as font size multipliers in system settings) + TypedValue.deriveDimension( + TypedValue.COMPLEX_UNIT_SP, + textView.textSize, + resources.displayMetrics + ) + } else { + (textView.textSize / resources.displayMetrics.scaledDensity) + } + seekBar.progress = (fontSizeSp.toInt() - TEXT_SIZE_SLIDER_MIN_VALUE) / TEXT_SIZE_SLIDER_STEP } companion object {