From 72e6acdcadabd4e6208302a7454e19599a44798c Mon Sep 17 00:00:00 2001 From: Mateusz Konieczny Date: Fri, 4 Feb 2022 17:15:38 +0100 Subject: [PATCH 01/39] proof of concept for placing laurel leaf --- .../streetcomplete/user/ProfileFragment.kt | 46 +++++++++++++++++++ app/src/main/res/drawable/ic_laurel_leaf.xml | 13 ++++++ res/graphics/laurel_leaf.svg | 22 +++++++++ 3 files changed, 81 insertions(+) create mode 100644 app/src/main/res/drawable/ic_laurel_leaf.xml create mode 100644 res/graphics/laurel_leaf.svg diff --git a/app/src/main/java/de/westnordost/streetcomplete/user/ProfileFragment.kt b/app/src/main/java/de/westnordost/streetcomplete/user/ProfileFragment.kt index 7962199f31..183f0b8b08 100644 --- a/app/src/main/java/de/westnordost/streetcomplete/user/ProfileFragment.kt +++ b/app/src/main/java/de/westnordost/streetcomplete/user/ProfileFragment.kt @@ -2,10 +2,17 @@ package de.westnordost.streetcomplete.user import android.content.Context import android.content.Intent +import android.content.res.Resources import android.graphics.Bitmap import android.graphics.BitmapFactory +import android.graphics.Canvas +import android.graphics.ColorFilter +import android.graphics.Paint +import android.graphics.PixelFormat +import android.graphics.drawable.Drawable import android.os.Bundle import android.view.View +import androidx.core.graphics.withRotation import androidx.core.net.toUri import androidx.core.view.isGone import androidx.fragment.app.Fragment @@ -21,6 +28,7 @@ import de.westnordost.streetcomplete.data.user.achievements.AchievementsSource import de.westnordost.streetcomplete.data.user.statistics.StatisticsSource import de.westnordost.streetcomplete.databinding.FragmentProfileBinding import de.westnordost.streetcomplete.ktx.createBitmap +import de.westnordost.streetcomplete.ktx.getBitmapDrawable import de.westnordost.streetcomplete.ktx.tryStartActivity import de.westnordost.streetcomplete.ktx.viewBinding import de.westnordost.streetcomplete.ktx.viewLifecycleScope @@ -155,10 +163,48 @@ class ProfileFragment : Fragment(R.layout.fragment_profile) { binding.daysActiveText.text = daysActive.toString() } + class LaurelWreath(var resources: Resources) : Drawable() { + private val redPaint: Paint = Paint().apply { setARGB(255, 255, 0, 0) } + + private val antiAliasPaint: Paint = Paint().apply { + isAntiAlias = true + isFilterBitmap = true + } + + override fun draw(canvas: Canvas) { + // Get the drawable's bounds + val width: Int = bounds.width() + val height: Int = bounds.height() + val radius: Float = Math.min(width, height).toFloat() / 2f + + // Draw a red circle in the center + canvas.drawCircle((width / 2).toFloat(), (height / 2).toFloat(), radius, redPaint) + + val bitmap = resources.getBitmapDrawable(R.drawable.ic_laurel_leaf) + canvas.withRotation(100f, width / 2f, height / 2f) { + canvas.drawBitmap(bitmap.bitmap, 0f, 0f, antiAliasPaint) + } + } + + override fun setAlpha(alpha: Int) { + // This method is required + } + + override fun setColorFilter(colorFilter: ColorFilter?) { + // This method is required + } + + override fun getOpacity(): Int = + // Must be PixelFormat.UNKNOWN, TRANSLUCENT, TRANSPARENT, or OPAQUE + PixelFormat.OPAQUE + } + + private fun updateGlobalRankText() { val rank = statisticsSource.rank binding.globalRankContainer.isGone = rank <= 0 || statisticsSource.getSolvedCount() <= 100 binding.globalRankText.text = "#$rank" + binding.globalRankText.background = LaurelWreath(resources) } private suspend fun updateLocalRankText() { diff --git a/app/src/main/res/drawable/ic_laurel_leaf.xml b/app/src/main/res/drawable/ic_laurel_leaf.xml new file mode 100644 index 0000000000..f2995c0f16 --- /dev/null +++ b/app/src/main/res/drawable/ic_laurel_leaf.xml @@ -0,0 +1,13 @@ + + + diff --git a/res/graphics/laurel_leaf.svg b/res/graphics/laurel_leaf.svg new file mode 100644 index 0000000000..8410da76aa --- /dev/null +++ b/res/graphics/laurel_leaf.svg @@ -0,0 +1,22 @@ + + + + + + + + + From 8c2db12d241c9109f8410fa17c72a6bb5f31dd7c Mon Sep 17 00:00:00 2001 From: Mateusz Konieczny Date: Sat, 5 Feb 2022 07:07:38 +0100 Subject: [PATCH 02/39] extra code with some unexpected failures --- .../streetcomplete/user/ProfileFragment.kt | 34 ++- app/src/main/res/layout/fragment_profile.xml | 203 ++++++++++++++++++ 2 files changed, 234 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/de/westnordost/streetcomplete/user/ProfileFragment.kt b/app/src/main/java/de/westnordost/streetcomplete/user/ProfileFragment.kt index 183f0b8b08..89fe8a58da 100644 --- a/app/src/main/java/de/westnordost/streetcomplete/user/ProfileFragment.kt +++ b/app/src/main/java/de/westnordost/streetcomplete/user/ProfileFragment.kt @@ -163,7 +163,12 @@ class ProfileFragment : Fragment(R.layout.fragment_profile) { binding.daysActiveText.text = daysActive.toString() } - class LaurelWreath(var resources: Resources) : Drawable() { + /* + 100 and more: fully grown wreath with all pretty elements + 99 to 1: may be losing elements as it gets smaller + 0 and lower: no decorative styling at all + */ + class LaurelWreath(val resources: Resources, val percentageOfGrowth: Int) : Drawable() { private val redPaint: Paint = Paint().apply { setARGB(255, 255, 0, 0) } private val antiAliasPaint: Paint = Paint().apply { @@ -182,7 +187,10 @@ class ProfileFragment : Fragment(R.layout.fragment_profile) { val bitmap = resources.getBitmapDrawable(R.drawable.ic_laurel_leaf) canvas.withRotation(100f, width / 2f, height / 2f) { - canvas.drawBitmap(bitmap.bitmap, 0f, 0f, antiAliasPaint) + canvas.drawBitmap(bitmap.bitmap, 0f, 10f, antiAliasPaint) + } + canvas.withRotation(100-180f, width / 2f, height / 2f) { + canvas.drawBitmap(bitmap.bitmap, 0f, height - 10f, antiAliasPaint) } } @@ -204,7 +212,27 @@ class ProfileFragment : Fragment(R.layout.fragment_profile) { val rank = statisticsSource.rank binding.globalRankContainer.isGone = rank <= 0 || statisticsSource.getSolvedCount() <= 100 binding.globalRankText.text = "#$rank" - binding.globalRankText.background = LaurelWreath(resources) + binding.globalRankText.background = LaurelWreath(resources, 1001 - rank) + } + + private fun updatePlaceholderRanksTexts() { + binding.placeholder1Text.text = "100%" + binding.placeholder1Text.background = LaurelWreath(resources, 100) + + binding.placeholder2Text.text = "90%" + binding.placeholder2Text.background = LaurelWreath(resources, 90) + + binding.placeholder3Text.text = "50%" + binding.placeholder3Text.background = LaurelWreath(resources, 50) + + binding.placeholder4Text.text = "30%" + binding.placeholder4Text.background = LaurelWreath(resources, 30) + + binding.placeholder5Text.text = "10%" + binding.placeholder5Text.background = LaurelWreath(resources, 10) + + binding.placeholder6Text.text = "0%" + binding.placeholder6Text.background = LaurelWreath(resources, 0) } private suspend fun updateLocalRankText() { diff --git a/app/src/main/res/layout/fragment_profile.xml b/app/src/main/res/layout/fragment_profile.xml index 047ae606d9..59888b368d 100644 --- a/app/src/main/res/layout/fragment_profile.xml +++ b/app/src/main/res/layout/fragment_profile.xml @@ -259,6 +259,209 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + From bb49e68c3ae10cae4386873303d036786c68d898 Mon Sep 17 00:00:00 2001 From: Mateusz Konieczny Date: Mon, 7 Feb 2022 01:50:27 +0100 Subject: [PATCH 03/39] proof of concept of nonterrible laurel wreaths --- .../streetcomplete/user/ProfileFragment.kt | 173 ++++++++++++++++-- app/src/main/res/drawable/ic_laurel_leaf.xml | 12 +- .../res/drawable/ic_laurel_leaf_ending.xml | 20 ++ .../res/drawable/ic_laurel_leaf_rotated.xml | 20 ++ app/src/main/res/layout/fragment_profile.xml | 38 ++-- app/src/main/res/values/colors.xml | 2 + res/graphics/laurel_leaf.svg | 38 +++- res/graphics/laurel_leaf_ending.svg | 58 ++++++ res/graphics/laurel_leaf_rotated.svg | 58 ++++++ 9 files changed, 365 insertions(+), 54 deletions(-) create mode 100644 app/src/main/res/drawable/ic_laurel_leaf_ending.xml create mode 100644 app/src/main/res/drawable/ic_laurel_leaf_rotated.xml create mode 100644 res/graphics/laurel_leaf_ending.svg create mode 100644 res/graphics/laurel_leaf_rotated.svg diff --git a/app/src/main/java/de/westnordost/streetcomplete/user/ProfileFragment.kt b/app/src/main/java/de/westnordost/streetcomplete/user/ProfileFragment.kt index ebe3d692a2..655a6374ed 100644 --- a/app/src/main/java/de/westnordost/streetcomplete/user/ProfileFragment.kt +++ b/app/src/main/java/de/westnordost/streetcomplete/user/ProfileFragment.kt @@ -2,15 +2,18 @@ package de.westnordost.streetcomplete.user import android.content.Context import android.content.Intent -import android.content.res.Resources import android.graphics.Bitmap import android.graphics.BitmapFactory import android.graphics.Canvas +import android.graphics.Color.BLUE import android.graphics.ColorFilter import android.graphics.Paint import android.graphics.PixelFormat +import android.graphics.RectF +import android.graphics.drawable.BitmapDrawable import android.graphics.drawable.Drawable import android.os.Bundle +import android.util.Log import android.view.View import androidx.core.graphics.withRotation import androidx.core.net.toUri @@ -114,6 +117,7 @@ class ProfileFragment : Fragment(R.layout.fragment_profile) { updateGlobalRankText() updateLocalRankText() updateAchievementLevelsText() + updatePlaceholderRanksTexts() } } @@ -158,13 +162,107 @@ class ProfileFragment : Fragment(R.layout.fragment_profile) { binding.daysActiveText.text = daysActive.toString() } + class LaurelWreathInitialAttempt(val bitmap: BitmapDrawable) : Drawable() { + private val redPaint: Paint = Paint().apply { setARGB(255, 255, 0, 0) } + private val yellowPaint: Paint = Paint().apply { setARGB(255, 255, 255, 0) } + private val orangePaint: Paint = Paint().apply { setARGB(255, 255, 155, 0) } + private val bluePaint: Paint = Paint().apply { setARGB(255, 0, 0, 255) } + + private val antiAliasPaint: Paint = Paint().apply { + isAntiAlias = true + isFilterBitmap = true + } + + override fun draw(canvas: Canvas) { + // Get the drawable's bounds + val width: Int = bounds.width() + val height: Int = bounds.height() + val radius: Float = Math.min(width, height).toFloat() / 2f + + // Draw a red circle in the center + canvas.drawCircle((width / 2).toFloat(), (height / 2).toFloat(), radius, redPaint) + + val imageWith = bitmap.intrinsicWidth //width is the same as intrinsicWidth + val imageHeight = bitmap.intrinsicHeight //width is the same as intrinsicWidth + + val n = 30f + val smallCircleRadius = 10f + /* + for(i in 0..n.toInt()) { + canvas.withRotation(i * 360.0f/n, width / 2f, height / 2f) { + canvas.drawCircle(width /2f, smallCircleRadius, smallCircleRadius, orangePaint) + } + } + */ + canvas.drawCircle(width /2f, smallCircleRadius * 3, smallCircleRadius, bluePaint) + + //canvas.drawCircle((width/2).toFloat(), (height/2).toFloat(), smallCircleRadius, yellowPaint) + + /* + val offset = width / 2f + val imageInternalOffset = imageWith/2f // drawBitmap takes lower-upper corner of bitmap, we care about bitmap center + canvas.withRotation(0f, width / 2f, height / 2f) { + canvas.drawBitmap(bitmap.bitmap, offset - imageInternalOffset, height/2f, antiAliasPaint) + } + + canvas.withRotation(180f, width / 2f, height / 2f) { + canvas.drawBitmap(bitmap.bitmap, width - offset - imageInternalOffset, height/2f, antiAliasPaint) + } + */ + + for(i in 0..n.toInt()) { + val offset = width / 2f + val imageInternalOffset = imageWith/2f // drawBitmap takes lower-upper corner of bitmap, we care about bitmap center + canvas.withRotation(i * 360.0f/n + 0f, width / 2f, height / 2f) { + canvas.drawBitmap(bitmap.bitmap, offset - imageInternalOffset, height/10f * 1.5f, antiAliasPaint) + } + + canvas.withRotation(i * 360.0f/n + 180f, width / 2f, height / 2f) { + canvas.drawBitmap(bitmap.bitmap, width - offset - imageInternalOffset, height/10f * 8.5f, antiAliasPaint) + } + } + + // https://stackoverflow.com/questions/11131954/how-to-draw-arc-between-two-points-on-the-canvas + // https://thoughtbot.com/blog/android-canvas-drawarc-method-a-visual-guide + // + val rect = RectF(0f, 0f, 80f, 80f) + val paint = Paint() + paint.apply { + strokeWidth = 5f + style = Paint.Style.STROKE + color = BLUE + } + canvas.drawArc(rect, 0f, -180f, true, paint) + + + + Log.wtf("AAAAA", "Redraw happened!") + } + + override fun setAlpha(alpha: Int) { + // This method is required + } + + override fun setColorFilter(colorFilter: ColorFilter?) { + // This method is required + } + + override fun getOpacity(): Int = + // Must be PixelFormat.UNKNOWN, TRANSLUCENT, TRANSPARENT, or OPAQUE + PixelFormat.OPAQUE + } + /* 100 and more: fully grown wreath with all pretty elements 99 to 1: may be losing elements as it gets smaller 0 and lower: no decorative styling at all */ - class LaurelWreath(val resources: Resources, val percentageOfGrowth: Int) : Drawable() { + class LaurelWreath(val bitmap: BitmapDrawable, val endingBitmap: BitmapDrawable, val percentageOfGrowth: Int) : Drawable() { private val redPaint: Paint = Paint().apply { setARGB(255, 255, 0, 0) } + private val niceSubtleGreen: Paint = Paint().apply { setARGB(255, 186, 209, 154) } + private val yellowPaint: Paint = Paint().apply { setARGB(255, 255, 255, 0) } + private val orangePaint: Paint = Paint().apply { setARGB(255, 255, 155, 0) } + private val bluePaint: Paint = Paint().apply { setARGB(255, 0, 0, 255) } private val antiAliasPaint: Paint = Paint().apply { isAntiAlias = true @@ -178,15 +276,53 @@ class ProfileFragment : Fragment(R.layout.fragment_profile) { val radius: Float = Math.min(width, height).toFloat() / 2f // Draw a red circle in the center - canvas.drawCircle((width / 2).toFloat(), (height / 2).toFloat(), radius, redPaint) - - val bitmap = resources.getBitmapDrawable(R.drawable.ic_laurel_leaf) - canvas.withRotation(100f, width / 2f, height / 2f) { - canvas.drawBitmap(bitmap.bitmap, 0f, 10f, antiAliasPaint) + canvas.drawCircle((width / 2).toFloat(), (height / 2).toFloat(), radius, niceSubtleGreen) + + val imageWith = bitmap.intrinsicWidth //width is the same as intrinsicWidth + val imageHeight = bitmap.intrinsicHeight //width is the same as intrinsicWidth + + val imageWithEnding = endingBitmap.intrinsicWidth //width is the same as intrinsicWidth + val imageHeightEnding = endingBitmap.intrinsicHeight //width is the same as intrinsicWidth + + val n = 10f + + val offset = width / 2f + val imageInternalOffset = imageWith/2f // drawBitmap takes lower-upper corner of bitmap, we care about bitmap center + val endingImageInternalOffset = imageWith/2f // drawBitmap takes lower-upper corner of bitmap, we care about bitmap center + val reach = ((n-2)*percentageOfGrowth/100).toInt() + for(i in 0..reach) { + // https://web.archive.org/web/20210201203811/https://stackoverflow.com/questions/36493977/flip-a-bitmap-image-horizontally-or-vertically + val offsetFromBorder = height/12f + // https://developer.android.com/reference/kotlin/androidx/core/graphics/package-summary#(android.graphics.Canvas).withRotation(kotlin.Float,kotlin.Float,kotlin.Float,kotlin.Function1) + + if(i == reach) { + // left side + canvas.withRotation(i * 180.0f/n - 180f, width / 2f, height / 2f) { + canvas.drawBitmap(endingBitmap.bitmap, offset - endingImageInternalOffset, offsetFromBorder, antiAliasPaint) + } + + // right side + canvas.withRotation(i * 180.0f/n, width / 2f, height / 2f) { + canvas.drawBitmap(endingBitmap.bitmap, offset - endingImageInternalOffset, offsetFromBorder, antiAliasPaint) + } + } else { + // left side + canvas.withRotation(i * 180.0f/n - 180f, width / 2f, height / 2f) { + canvas.drawBitmap(bitmap.bitmap, offset - imageInternalOffset, offsetFromBorder, antiAliasPaint) + } + + // right side + canvas.withRotation(i * 180.0f/n, width / 2f, height / 2f) { + canvas.drawBitmap(bitmap.bitmap, offset - imageInternalOffset, offsetFromBorder, antiAliasPaint) + } + } } - canvas.withRotation(100-180f, width / 2f, height / 2f) { - canvas.drawBitmap(bitmap.bitmap, 0f, height - 10f, antiAliasPaint) + val smallCircleRadius = width /10f + canvas.drawCircle(smallCircleRadius * 2, smallCircleRadius * 2, smallCircleRadius, bluePaint) + canvas.withRotation(20.0f, width / 2f, height / 2f) { + canvas.drawCircle(smallCircleRadius * 2, smallCircleRadius * 2, smallCircleRadius, yellowPaint) } + canvas.drawBitmap(endingBitmap.bitmap, width/2f, height*0.8f, antiAliasPaint) } override fun setAlpha(alpha: Int) { @@ -207,27 +343,32 @@ class ProfileFragment : Fragment(R.layout.fragment_profile) { val rank = statisticsSource.rank binding.globalRankContainer.isGone = rank <= 0 || statisticsSource.getSolvedCount() <= 100 binding.globalRankText.text = "#$rank" - binding.globalRankText.background = LaurelWreath(resources, 1001 - rank) + val bitmap = resources.getBitmapDrawable(R.drawable.ic_laurel_leaf) + val endingBitmap = resources.getBitmapDrawable(R.drawable.ic_laurel_leaf_ending) + binding.globalRankText.background = LaurelWreath(bitmap, endingBitmap,1001 - rank) } private fun updatePlaceholderRanksTexts() { + val bitmap = resources.getBitmapDrawable(R.drawable.ic_laurel_leaf) binding.placeholder1Text.text = "100%" - binding.placeholder1Text.background = LaurelWreath(resources, 100) + binding.placeholder1Text.background = LaurelWreathInitialAttempt(bitmap) + val bitmap_experimental = resources.getBitmapDrawable(R.drawable.ic_laurel_leaf_rotated) + val endingBitmap = resources.getBitmapDrawable(R.drawable.ic_laurel_leaf_ending) binding.placeholder2Text.text = "90%" - binding.placeholder2Text.background = LaurelWreath(resources, 90) + binding.placeholder2Text.background = LaurelWreath(bitmap_experimental, endingBitmap, 90) binding.placeholder3Text.text = "50%" - binding.placeholder3Text.background = LaurelWreath(resources, 50) + binding.placeholder3Text.background = LaurelWreath(bitmap_experimental, endingBitmap, 50) binding.placeholder4Text.text = "30%" - binding.placeholder4Text.background = LaurelWreath(resources, 30) + binding.placeholder4Text.background = LaurelWreath(bitmap_experimental, endingBitmap, 30) binding.placeholder5Text.text = "10%" - binding.placeholder5Text.background = LaurelWreath(resources, 10) + binding.placeholder5Text.background = LaurelWreath(bitmap_experimental, endingBitmap, 10) binding.placeholder6Text.text = "0%" - binding.placeholder6Text.background = LaurelWreath(resources, 0) + binding.placeholder6Text.background = LaurelWreath(bitmap_experimental, endingBitmap, 0) } private suspend fun updateLocalRankText() { diff --git a/app/src/main/res/drawable/ic_laurel_leaf.xml b/app/src/main/res/drawable/ic_laurel_leaf.xml index f2995c0f16..029005fdd5 100644 --- a/app/src/main/res/drawable/ic_laurel_leaf.xml +++ b/app/src/main/res/drawable/ic_laurel_leaf.xml @@ -1,12 +1,12 @@ + android:width="3.4150012dp" + android:height="12.12272dp" + android:viewportWidth="3.4150012" + android:viewportHeight="12.12272"> diff --git a/app/src/main/res/drawable/ic_laurel_leaf_ending.xml b/app/src/main/res/drawable/ic_laurel_leaf_ending.xml new file mode 100644 index 0000000000..c3a004aab4 --- /dev/null +++ b/app/src/main/res/drawable/ic_laurel_leaf_ending.xml @@ -0,0 +1,20 @@ + + + + diff --git a/app/src/main/res/drawable/ic_laurel_leaf_rotated.xml b/app/src/main/res/drawable/ic_laurel_leaf_rotated.xml new file mode 100644 index 0000000000..4759f33bba --- /dev/null +++ b/app/src/main/res/drawable/ic_laurel_leaf_rotated.xml @@ -0,0 +1,20 @@ + + + + diff --git a/app/src/main/res/layout/fragment_profile.xml b/app/src/main/res/layout/fragment_profile.xml index 59888b368d..04075e3ef9 100644 --- a/app/src/main/res/layout/fragment_profile.xml +++ b/app/src/main/res/layout/fragment_profile.xml @@ -266,11 +266,9 @@ #fff #0fff + #006a00 + #888 @color/accent diff --git a/res/graphics/laurel_leaf.svg b/res/graphics/laurel_leaf.svg index 8410da76aa..19c1cfc6f1 100644 --- a/res/graphics/laurel_leaf.svg +++ b/res/graphics/laurel_leaf.svg @@ -2,21 +2,45 @@ + + transform="translate(78.346572,19.766431)"> + style="fill:#006a00;fill-opacity:1;stroke:none;stroke-width:0.14293px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1" + d="m -76.687853,-7.643711 c 0.125429,-1.0071428 0.175912,-1.2176663 0.577968,-1.737491 0.812961,-1.051092 1.164715,-3.42843 1.178147,-4.729231 0.0199,-1.927066 -1.74638,-5.655998 -1.74638,-5.655998 0,0 0.07357,1.32769 -0.372823,2.513849 -0.341396,0.907161 -0.84985,2.019042 -0.981101,2.686258 -0.268927,1.367071 -0.424232,2.312581 -0.2227,3.673234 0.259887,1.7546323 0.949599,1.2861924 1.170163,2.0390936 0.115502,0.394269 0.08992,1.2122391 0.08992,1.2122391 z" + id="path959" + sodipodi:nodetypes="csscscsscc" /> diff --git a/res/graphics/laurel_leaf_ending.svg b/res/graphics/laurel_leaf_ending.svg new file mode 100644 index 0000000000..59b0fee7b1 --- /dev/null +++ b/res/graphics/laurel_leaf_ending.svg @@ -0,0 +1,58 @@ + + + + + + + + + + + + + diff --git a/res/graphics/laurel_leaf_rotated.svg b/res/graphics/laurel_leaf_rotated.svg new file mode 100644 index 0000000000..b5036802aa --- /dev/null +++ b/res/graphics/laurel_leaf_rotated.svg @@ -0,0 +1,58 @@ + + + + + + + + + + + + + From d3f8157d1b3b67ce5185257c95be7a6217432e12 Mon Sep 17 00:00:00 2001 From: Mateusz Konieczny Date: Mon, 7 Feb 2022 15:48:51 +0100 Subject: [PATCH 04/39] first laurel wreath that is actually nice --- .../westnordost/streetcomplete/ktx/Bitmap.kt | 9 + .../streetcomplete/user/ProfileFragment.kt | 175 ++++-------------- app/src/main/res/drawable/ic_laurel_leaf.xml | 13 -- .../res/drawable/ic_laurel_leaf_stalk.xml | 13 ++ app/src/main/res/layout/fragment_profile.xml | 9 +- res/graphics/laurel_leaf.svg | 46 ----- .../laurel_leaf_ending.svg | 0 .../laurel_leaf_rotated.svg | 0 .../laurel_wreath/laurel_leaf_stalk.svg | 49 +++++ 9 files changed, 114 insertions(+), 200 deletions(-) create mode 100644 app/src/main/java/de/westnordost/streetcomplete/ktx/Bitmap.kt delete mode 100644 app/src/main/res/drawable/ic_laurel_leaf.xml create mode 100644 app/src/main/res/drawable/ic_laurel_leaf_stalk.xml delete mode 100644 res/graphics/laurel_leaf.svg rename res/graphics/{ => laurel_wreath}/laurel_leaf_ending.svg (100%) rename res/graphics/{ => laurel_wreath}/laurel_leaf_rotated.svg (100%) create mode 100644 res/graphics/laurel_wreath/laurel_leaf_stalk.svg diff --git a/app/src/main/java/de/westnordost/streetcomplete/ktx/Bitmap.kt b/app/src/main/java/de/westnordost/streetcomplete/ktx/Bitmap.kt new file mode 100644 index 0000000000..bdde1597cd --- /dev/null +++ b/app/src/main/java/de/westnordost/streetcomplete/ktx/Bitmap.kt @@ -0,0 +1,9 @@ +package de.westnordost.streetcomplete.ktx + +import android.graphics.Bitmap +import android.graphics.Matrix + +fun Bitmap.flipHorizontally(): Bitmap { + val matrix = Matrix().apply { postScale(-1f, 1f, width/2f, width/2f) } + return Bitmap.createBitmap(this, 0, 0, width, height, matrix, true) +} diff --git a/app/src/main/java/de/westnordost/streetcomplete/user/ProfileFragment.kt b/app/src/main/java/de/westnordost/streetcomplete/user/ProfileFragment.kt index 655a6374ed..41ce3f1b44 100644 --- a/app/src/main/java/de/westnordost/streetcomplete/user/ProfileFragment.kt +++ b/app/src/main/java/de/westnordost/streetcomplete/user/ProfileFragment.kt @@ -2,18 +2,16 @@ package de.westnordost.streetcomplete.user import android.content.Context import android.content.Intent +import android.content.res.Resources import android.graphics.Bitmap import android.graphics.BitmapFactory import android.graphics.Canvas -import android.graphics.Color.BLUE import android.graphics.ColorFilter import android.graphics.Paint import android.graphics.PixelFormat -import android.graphics.RectF import android.graphics.drawable.BitmapDrawable import android.graphics.drawable.Drawable import android.os.Bundle -import android.util.Log import android.view.View import androidx.core.graphics.withRotation import androidx.core.net.toUri @@ -29,6 +27,7 @@ import de.westnordost.streetcomplete.data.user.achievements.AchievementsSource import de.westnordost.streetcomplete.data.user.statistics.StatisticsSource import de.westnordost.streetcomplete.databinding.FragmentProfileBinding import de.westnordost.streetcomplete.ktx.createBitmap +import de.westnordost.streetcomplete.ktx.flipHorizontally import de.westnordost.streetcomplete.ktx.getBitmapDrawable import de.westnordost.streetcomplete.ktx.tryStartActivity import de.westnordost.streetcomplete.ktx.viewBinding @@ -162,102 +161,16 @@ class ProfileFragment : Fragment(R.layout.fragment_profile) { binding.daysActiveText.text = daysActive.toString() } - class LaurelWreathInitialAttempt(val bitmap: BitmapDrawable) : Drawable() { - private val redPaint: Paint = Paint().apply { setARGB(255, 255, 0, 0) } - private val yellowPaint: Paint = Paint().apply { setARGB(255, 255, 255, 0) } - private val orangePaint: Paint = Paint().apply { setARGB(255, 255, 155, 0) } - private val bluePaint: Paint = Paint().apply { setARGB(255, 0, 0, 255) } - - private val antiAliasPaint: Paint = Paint().apply { - isAntiAlias = true - isFilterBitmap = true - } - - override fun draw(canvas: Canvas) { - // Get the drawable's bounds - val width: Int = bounds.width() - val height: Int = bounds.height() - val radius: Float = Math.min(width, height).toFloat() / 2f - - // Draw a red circle in the center - canvas.drawCircle((width / 2).toFloat(), (height / 2).toFloat(), radius, redPaint) - - val imageWith = bitmap.intrinsicWidth //width is the same as intrinsicWidth - val imageHeight = bitmap.intrinsicHeight //width is the same as intrinsicWidth - - val n = 30f - val smallCircleRadius = 10f - /* - for(i in 0..n.toInt()) { - canvas.withRotation(i * 360.0f/n, width / 2f, height / 2f) { - canvas.drawCircle(width /2f, smallCircleRadius, smallCircleRadius, orangePaint) - } - } - */ - canvas.drawCircle(width /2f, smallCircleRadius * 3, smallCircleRadius, bluePaint) - - //canvas.drawCircle((width/2).toFloat(), (height/2).toFloat(), smallCircleRadius, yellowPaint) - - /* - val offset = width / 2f - val imageInternalOffset = imageWith/2f // drawBitmap takes lower-upper corner of bitmap, we care about bitmap center - canvas.withRotation(0f, width / 2f, height / 2f) { - canvas.drawBitmap(bitmap.bitmap, offset - imageInternalOffset, height/2f, antiAliasPaint) - } - - canvas.withRotation(180f, width / 2f, height / 2f) { - canvas.drawBitmap(bitmap.bitmap, width - offset - imageInternalOffset, height/2f, antiAliasPaint) - } - */ - - for(i in 0..n.toInt()) { - val offset = width / 2f - val imageInternalOffset = imageWith/2f // drawBitmap takes lower-upper corner of bitmap, we care about bitmap center - canvas.withRotation(i * 360.0f/n + 0f, width / 2f, height / 2f) { - canvas.drawBitmap(bitmap.bitmap, offset - imageInternalOffset, height/10f * 1.5f, antiAliasPaint) - } - - canvas.withRotation(i * 360.0f/n + 180f, width / 2f, height / 2f) { - canvas.drawBitmap(bitmap.bitmap, width - offset - imageInternalOffset, height/10f * 8.5f, antiAliasPaint) - } - } - - // https://stackoverflow.com/questions/11131954/how-to-draw-arc-between-two-points-on-the-canvas - // https://thoughtbot.com/blog/android-canvas-drawarc-method-a-visual-guide - // - val rect = RectF(0f, 0f, 80f, 80f) - val paint = Paint() - paint.apply { - strokeWidth = 5f - style = Paint.Style.STROKE - color = BLUE - } - canvas.drawArc(rect, 0f, -180f, true, paint) - - - - Log.wtf("AAAAA", "Redraw happened!") - } - - override fun setAlpha(alpha: Int) { - // This method is required - } - - override fun setColorFilter(colorFilter: ColorFilter?) { - // This method is required - } - - override fun getOpacity(): Int = - // Must be PixelFormat.UNKNOWN, TRANSLUCENT, TRANSPARENT, or OPAQUE - PixelFormat.OPAQUE - } - /* 100 and more: fully grown wreath with all pretty elements 99 to 1: may be losing elements as it gets smaller 0 and lower: no decorative styling at all */ - class LaurelWreath(val bitmap: BitmapDrawable, val endingBitmap: BitmapDrawable, val percentageOfGrowth: Int) : Drawable() { + class LaurelWreath(val resources: Resources, private val percentageOfGrowth: Int) : Drawable() { + val laurelLeafOnStalk = resources.getBitmapDrawable(R.drawable.ic_laurel_leaf_rotated) + val laurelStalk = resources.getBitmapDrawable(R.drawable.ic_laurel_leaf_stalk) + val horizontalEndingLeaf = resources.getBitmapDrawable(R.drawable.ic_laurel_leaf_ending) + private val redPaint: Paint = Paint().apply { setARGB(255, 255, 0, 0) } private val niceSubtleGreen: Paint = Paint().apply { setARGB(255, 186, 209, 154) } private val yellowPaint: Paint = Paint().apply { setARGB(255, 255, 255, 0) } @@ -278,51 +191,44 @@ class ProfileFragment : Fragment(R.layout.fragment_profile) { // Draw a red circle in the center canvas.drawCircle((width / 2).toFloat(), (height / 2).toFloat(), radius, niceSubtleGreen) - val imageWith = bitmap.intrinsicWidth //width is the same as intrinsicWidth - val imageHeight = bitmap.intrinsicHeight //width is the same as intrinsicWidth + val imageWith = laurelLeafOnStalk.intrinsicWidth //width is the same as intrinsicWidth + val imageHeight = laurelLeafOnStalk.intrinsicHeight //width is the same as intrinsicWidth - val imageWithEnding = endingBitmap.intrinsicWidth //width is the same as intrinsicWidth - val imageHeightEnding = endingBitmap.intrinsicHeight //width is the same as intrinsicWidth + val imageWithEnding = horizontalEndingLeaf.intrinsicWidth //width is the same as intrinsicWidth + val imageHeightEnding = horizontalEndingLeaf.intrinsicHeight //width is the same as intrinsicWidth + //TODO - ending image should have the same size as a regular one - val n = 10f + val n = 11f val offset = width / 2f val imageInternalOffset = imageWith/2f // drawBitmap takes lower-upper corner of bitmap, we care about bitmap center val endingImageInternalOffset = imageWith/2f // drawBitmap takes lower-upper corner of bitmap, we care about bitmap center - val reach = ((n-2)*percentageOfGrowth/100).toInt() + val reach = ((n-1)*percentageOfGrowth/100).toInt() + for(i in 0..reach) { // https://web.archive.org/web/20210201203811/https://stackoverflow.com/questions/36493977/flip-a-bitmap-image-horizontally-or-vertically val offsetFromBorder = height/12f // https://developer.android.com/reference/kotlin/androidx/core/graphics/package-summary#(android.graphics.Canvas).withRotation(kotlin.Float,kotlin.Float,kotlin.Float,kotlin.Function1) + var bitmap = laurelLeafOnStalk.bitmap if(i == reach) { - // left side - canvas.withRotation(i * 180.0f/n - 180f, width / 2f, height / 2f) { - canvas.drawBitmap(endingBitmap.bitmap, offset - endingImageInternalOffset, offsetFromBorder, antiAliasPaint) - } - - // right side - canvas.withRotation(i * 180.0f/n, width / 2f, height / 2f) { - canvas.drawBitmap(endingBitmap.bitmap, offset - endingImageInternalOffset, offsetFromBorder, antiAliasPaint) - } - } else { - // left side - canvas.withRotation(i * 180.0f/n - 180f, width / 2f, height / 2f) { - canvas.drawBitmap(bitmap.bitmap, offset - imageInternalOffset, offsetFromBorder, antiAliasPaint) - } - - // right side - canvas.withRotation(i * 180.0f/n, width / 2f, height / 2f) { - canvas.drawBitmap(bitmap.bitmap, offset - imageInternalOffset, offsetFromBorder, antiAliasPaint) - } + bitmap = horizontalEndingLeaf.bitmap + } else if (i == 0 ) { + bitmap = laurelStalk.bitmap + } + + val flippedBitmap = bitmap.flipHorizontally() + // left side + canvas.withRotation(i * 180.0f/n, width / 2f, height / 2f) { + canvas.drawBitmap(bitmap, offset - endingImageInternalOffset, height*0.78f, antiAliasPaint) + } + + canvas.withRotation(-i * 180.0f/n, width / 2f, height / 2f) { + canvas.drawBitmap(flippedBitmap, offset - endingImageInternalOffset, height*0.78f, antiAliasPaint) } } - val smallCircleRadius = width /10f - canvas.drawCircle(smallCircleRadius * 2, smallCircleRadius * 2, smallCircleRadius, bluePaint) - canvas.withRotation(20.0f, width / 2f, height / 2f) { - canvas.drawCircle(smallCircleRadius * 2, smallCircleRadius * 2, smallCircleRadius, yellowPaint) - } - canvas.drawBitmap(endingBitmap.bitmap, width/2f, height*0.8f, antiAliasPaint) + //val smallCircleRadius = width /10f + //canvas.drawCircle(smallCircleRadius * 2, height - smallCircleRadius * 2, smallCircleRadius, bluePaint) } override fun setAlpha(alpha: Int) { @@ -343,32 +249,27 @@ class ProfileFragment : Fragment(R.layout.fragment_profile) { val rank = statisticsSource.rank binding.globalRankContainer.isGone = rank <= 0 || statisticsSource.getSolvedCount() <= 100 binding.globalRankText.text = "#$rank" - val bitmap = resources.getBitmapDrawable(R.drawable.ic_laurel_leaf) - val endingBitmap = resources.getBitmapDrawable(R.drawable.ic_laurel_leaf_ending) - binding.globalRankText.background = LaurelWreath(bitmap, endingBitmap,1001 - rank) + binding.globalRankText.background = LaurelWreath(resources,1001 - rank) } private fun updatePlaceholderRanksTexts() { - val bitmap = resources.getBitmapDrawable(R.drawable.ic_laurel_leaf) binding.placeholder1Text.text = "100%" - binding.placeholder1Text.background = LaurelWreathInitialAttempt(bitmap) + binding.placeholder1Text.background = LaurelWreath(resources, 100) - val bitmap_experimental = resources.getBitmapDrawable(R.drawable.ic_laurel_leaf_rotated) - val endingBitmap = resources.getBitmapDrawable(R.drawable.ic_laurel_leaf_ending) binding.placeholder2Text.text = "90%" - binding.placeholder2Text.background = LaurelWreath(bitmap_experimental, endingBitmap, 90) + binding.placeholder2Text.background = LaurelWreath(resources, 90) binding.placeholder3Text.text = "50%" - binding.placeholder3Text.background = LaurelWreath(bitmap_experimental, endingBitmap, 50) + binding.placeholder3Text.background = LaurelWreath(resources, 50) binding.placeholder4Text.text = "30%" - binding.placeholder4Text.background = LaurelWreath(bitmap_experimental, endingBitmap, 30) + binding.placeholder4Text.background = LaurelWreath(resources, 30) binding.placeholder5Text.text = "10%" - binding.placeholder5Text.background = LaurelWreath(bitmap_experimental, endingBitmap, 10) + binding.placeholder5Text.background = LaurelWreath(resources, 10) binding.placeholder6Text.text = "0%" - binding.placeholder6Text.background = LaurelWreath(bitmap_experimental, endingBitmap, 0) + binding.placeholder6Text.background = LaurelWreath(resources, 0) } private suspend fun updateLocalRankText() { diff --git a/app/src/main/res/drawable/ic_laurel_leaf.xml b/app/src/main/res/drawable/ic_laurel_leaf.xml deleted file mode 100644 index 029005fdd5..0000000000 --- a/app/src/main/res/drawable/ic_laurel_leaf.xml +++ /dev/null @@ -1,13 +0,0 @@ - - - diff --git a/app/src/main/res/drawable/ic_laurel_leaf_stalk.xml b/app/src/main/res/drawable/ic_laurel_leaf_stalk.xml new file mode 100644 index 0000000000..dfc04dd7c1 --- /dev/null +++ b/app/src/main/res/drawable/ic_laurel_leaf_stalk.xml @@ -0,0 +1,13 @@ + + + diff --git a/app/src/main/res/layout/fragment_profile.xml b/app/src/main/res/layout/fragment_profile.xml index 04075e3ef9..39c1f9527d 100644 --- a/app/src/main/res/layout/fragment_profile.xml +++ b/app/src/main/res/layout/fragment_profile.xml @@ -275,7 +275,7 @@ app:autoSizeTextType="uniform" app:autoSizeMaxTextSize="22dp" app:autoSizeMinTextSize="12dp" - android:textColor="@color/background" + android:textColor="@color/rank_text" tools:text="123"/> + - - - - - - - - - diff --git a/res/graphics/laurel_leaf_ending.svg b/res/graphics/laurel_wreath/laurel_leaf_ending.svg similarity index 100% rename from res/graphics/laurel_leaf_ending.svg rename to res/graphics/laurel_wreath/laurel_leaf_ending.svg diff --git a/res/graphics/laurel_leaf_rotated.svg b/res/graphics/laurel_wreath/laurel_leaf_rotated.svg similarity index 100% rename from res/graphics/laurel_leaf_rotated.svg rename to res/graphics/laurel_wreath/laurel_leaf_rotated.svg diff --git a/res/graphics/laurel_wreath/laurel_leaf_stalk.svg b/res/graphics/laurel_wreath/laurel_leaf_stalk.svg new file mode 100644 index 0000000000..2a8644bb5f --- /dev/null +++ b/res/graphics/laurel_wreath/laurel_leaf_stalk.svg @@ -0,0 +1,49 @@ + + + + + + + + + + From 6140ad148459e3fa35ef3caaa1f69a1e49c62da9 Mon Sep 17 00:00:00 2001 From: Mateusz Konieczny Date: Thu, 10 Feb 2022 20:34:39 +0100 Subject: [PATCH 05/39] abandoned night mode attempt --- .../streetcomplete/user/ProfileFragment.kt | 31 +++++++++++------ app/src/main/res/layout/fragment_profile.xml | 34 +++++++------------ app/src/main/res/values-night/colors.xml | 3 ++ app/src/main/res/values/colors.xml | 5 +-- 4 files changed, 39 insertions(+), 34 deletions(-) diff --git a/app/src/main/java/de/westnordost/streetcomplete/user/ProfileFragment.kt b/app/src/main/java/de/westnordost/streetcomplete/user/ProfileFragment.kt index 41ce3f1b44..ea3df31cdb 100644 --- a/app/src/main/java/de/westnordost/streetcomplete/user/ProfileFragment.kt +++ b/app/src/main/java/de/westnordost/streetcomplete/user/ProfileFragment.kt @@ -9,10 +9,10 @@ import android.graphics.Canvas import android.graphics.ColorFilter import android.graphics.Paint import android.graphics.PixelFormat -import android.graphics.drawable.BitmapDrawable import android.graphics.drawable.Drawable import android.os.Bundle import android.view.View +import androidx.core.content.ContextCompat.getColor import androidx.core.graphics.withRotation import androidx.core.net.toUri import androidx.core.view.isGone @@ -166,13 +166,22 @@ class ProfileFragment : Fragment(R.layout.fragment_profile) { 99 to 1: may be losing elements as it gets smaller 0 and lower: no decorative styling at all */ - class LaurelWreath(val resources: Resources, private val percentageOfGrowth: Int) : Drawable() { + class LaurelWreath(val resources: Resources, context: Context, private val percentageOfGrowth: Int) : Drawable() { val laurelLeafOnStalk = resources.getBitmapDrawable(R.drawable.ic_laurel_leaf_rotated) val laurelStalk = resources.getBitmapDrawable(R.drawable.ic_laurel_leaf_stalk) val horizontalEndingLeaf = resources.getBitmapDrawable(R.drawable.ic_laurel_leaf_ending) + // TODO: supporting night mode would be nice + // but how can I get color from colour resources? + // all + // Paint().apply { ResourcesCompat.getColor(resources, R.color.rank_background, null) } + // Paint().apply { ContextCompat.getColor(context, R.color.rank_background) } + // Paint().apply { context.resources.getColor(R.color.rank_background) } + // Paint().apply { R.color.rank_background } + // give black + private val redPaint: Paint = Paint().apply { setARGB(255, 255, 0, 0) } - private val niceSubtleGreen: Paint = Paint().apply { setARGB(255, 186, 209, 154) } + private val rankBackgroundPaint: Paint = Paint().apply { setARGB(255, 186, 209, 154) } private val yellowPaint: Paint = Paint().apply { setARGB(255, 255, 255, 0) } private val orangePaint: Paint = Paint().apply { setARGB(255, 255, 155, 0) } private val bluePaint: Paint = Paint().apply { setARGB(255, 0, 0, 255) } @@ -189,7 +198,7 @@ class ProfileFragment : Fragment(R.layout.fragment_profile) { val radius: Float = Math.min(width, height).toFloat() / 2f // Draw a red circle in the center - canvas.drawCircle((width / 2).toFloat(), (height / 2).toFloat(), radius, niceSubtleGreen) + canvas.drawCircle((width / 2).toFloat(), (height / 2).toFloat(), radius, rankBackgroundPaint) val imageWith = laurelLeafOnStalk.intrinsicWidth //width is the same as intrinsicWidth val imageHeight = laurelLeafOnStalk.intrinsicHeight //width is the same as intrinsicWidth @@ -249,27 +258,27 @@ class ProfileFragment : Fragment(R.layout.fragment_profile) { val rank = statisticsSource.rank binding.globalRankContainer.isGone = rank <= 0 || statisticsSource.getSolvedCount() <= 100 binding.globalRankText.text = "#$rank" - binding.globalRankText.background = LaurelWreath(resources,1001 - rank) + binding.globalRankText.background = LaurelWreath(resources, context!!, 1001 - rank) } private fun updatePlaceholderRanksTexts() { binding.placeholder1Text.text = "100%" - binding.placeholder1Text.background = LaurelWreath(resources, 100) + binding.placeholder1Text.background = LaurelWreath(resources, context!!, 100) binding.placeholder2Text.text = "90%" - binding.placeholder2Text.background = LaurelWreath(resources, 90) + binding.placeholder2Text.background = LaurelWreath(resources, context!!, 90) binding.placeholder3Text.text = "50%" - binding.placeholder3Text.background = LaurelWreath(resources, 50) + binding.placeholder3Text.background = LaurelWreath(resources, context!!, 50) binding.placeholder4Text.text = "30%" - binding.placeholder4Text.background = LaurelWreath(resources, 30) + binding.placeholder4Text.background = LaurelWreath(resources, context!!, 30) binding.placeholder5Text.text = "10%" - binding.placeholder5Text.background = LaurelWreath(resources, 10) + binding.placeholder5Text.background = LaurelWreath(resources, context!!, 10) binding.placeholder6Text.text = "0%" - binding.placeholder6Text.background = LaurelWreath(resources, 0) + binding.placeholder6Text.background = LaurelWreath(resources, context!!, 0) } private suspend fun updateLocalRankText() { diff --git a/app/src/main/res/layout/fragment_profile.xml b/app/src/main/res/layout/fragment_profile.xml index 39c1f9527d..92d2096d06 100644 --- a/app/src/main/res/layout/fragment_profile.xml +++ b/app/src/main/res/layout/fragment_profile.xml @@ -128,18 +128,17 @@ - #70808b + #bdd19a + #006a00 + #44f diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml index f2eaed4550..423df5d086 100644 --- a/app/src/main/res/values/colors.xml +++ b/app/src/main/res/values/colors.xml @@ -23,8 +23,6 @@ #fff #0fff - #006a00 - #888 @color/accent @@ -80,6 +78,9 @@ #AA335D #655555 + #006a00 + #bdd19a + #22f From f4f1abe125c45939987e8567b3b470576d32b7bb Mon Sep 17 00:00:00 2001 From: Mateusz Konieczny Date: Sat, 2 Jul 2022 19:59:42 +0200 Subject: [PATCH 06/39] Revert "abandoned night mode attempt" This reverts commit 6140ad148459e3fa35ef3caaa1f69a1e49c62da9. --- .../streetcomplete/user/ProfileFragment.kt | 31 ++++++----------- app/src/main/res/layout/fragment_profile.xml | 34 ++++++++++++------- app/src/main/res/values-night/colors.xml | 3 -- app/src/main/res/values/colors.xml | 5 ++- 4 files changed, 34 insertions(+), 39 deletions(-) diff --git a/app/src/main/java/de/westnordost/streetcomplete/user/ProfileFragment.kt b/app/src/main/java/de/westnordost/streetcomplete/user/ProfileFragment.kt index ea3df31cdb..41ce3f1b44 100644 --- a/app/src/main/java/de/westnordost/streetcomplete/user/ProfileFragment.kt +++ b/app/src/main/java/de/westnordost/streetcomplete/user/ProfileFragment.kt @@ -9,10 +9,10 @@ import android.graphics.Canvas import android.graphics.ColorFilter import android.graphics.Paint import android.graphics.PixelFormat +import android.graphics.drawable.BitmapDrawable import android.graphics.drawable.Drawable import android.os.Bundle import android.view.View -import androidx.core.content.ContextCompat.getColor import androidx.core.graphics.withRotation import androidx.core.net.toUri import androidx.core.view.isGone @@ -166,22 +166,13 @@ class ProfileFragment : Fragment(R.layout.fragment_profile) { 99 to 1: may be losing elements as it gets smaller 0 and lower: no decorative styling at all */ - class LaurelWreath(val resources: Resources, context: Context, private val percentageOfGrowth: Int) : Drawable() { + class LaurelWreath(val resources: Resources, private val percentageOfGrowth: Int) : Drawable() { val laurelLeafOnStalk = resources.getBitmapDrawable(R.drawable.ic_laurel_leaf_rotated) val laurelStalk = resources.getBitmapDrawable(R.drawable.ic_laurel_leaf_stalk) val horizontalEndingLeaf = resources.getBitmapDrawable(R.drawable.ic_laurel_leaf_ending) - // TODO: supporting night mode would be nice - // but how can I get color from colour resources? - // all - // Paint().apply { ResourcesCompat.getColor(resources, R.color.rank_background, null) } - // Paint().apply { ContextCompat.getColor(context, R.color.rank_background) } - // Paint().apply { context.resources.getColor(R.color.rank_background) } - // Paint().apply { R.color.rank_background } - // give black - private val redPaint: Paint = Paint().apply { setARGB(255, 255, 0, 0) } - private val rankBackgroundPaint: Paint = Paint().apply { setARGB(255, 186, 209, 154) } + private val niceSubtleGreen: Paint = Paint().apply { setARGB(255, 186, 209, 154) } private val yellowPaint: Paint = Paint().apply { setARGB(255, 255, 255, 0) } private val orangePaint: Paint = Paint().apply { setARGB(255, 255, 155, 0) } private val bluePaint: Paint = Paint().apply { setARGB(255, 0, 0, 255) } @@ -198,7 +189,7 @@ class ProfileFragment : Fragment(R.layout.fragment_profile) { val radius: Float = Math.min(width, height).toFloat() / 2f // Draw a red circle in the center - canvas.drawCircle((width / 2).toFloat(), (height / 2).toFloat(), radius, rankBackgroundPaint) + canvas.drawCircle((width / 2).toFloat(), (height / 2).toFloat(), radius, niceSubtleGreen) val imageWith = laurelLeafOnStalk.intrinsicWidth //width is the same as intrinsicWidth val imageHeight = laurelLeafOnStalk.intrinsicHeight //width is the same as intrinsicWidth @@ -258,27 +249,27 @@ class ProfileFragment : Fragment(R.layout.fragment_profile) { val rank = statisticsSource.rank binding.globalRankContainer.isGone = rank <= 0 || statisticsSource.getSolvedCount() <= 100 binding.globalRankText.text = "#$rank" - binding.globalRankText.background = LaurelWreath(resources, context!!, 1001 - rank) + binding.globalRankText.background = LaurelWreath(resources,1001 - rank) } private fun updatePlaceholderRanksTexts() { binding.placeholder1Text.text = "100%" - binding.placeholder1Text.background = LaurelWreath(resources, context!!, 100) + binding.placeholder1Text.background = LaurelWreath(resources, 100) binding.placeholder2Text.text = "90%" - binding.placeholder2Text.background = LaurelWreath(resources, context!!, 90) + binding.placeholder2Text.background = LaurelWreath(resources, 90) binding.placeholder3Text.text = "50%" - binding.placeholder3Text.background = LaurelWreath(resources, context!!, 50) + binding.placeholder3Text.background = LaurelWreath(resources, 50) binding.placeholder4Text.text = "30%" - binding.placeholder4Text.background = LaurelWreath(resources, context!!, 30) + binding.placeholder4Text.background = LaurelWreath(resources, 30) binding.placeholder5Text.text = "10%" - binding.placeholder5Text.background = LaurelWreath(resources, context!!, 10) + binding.placeholder5Text.background = LaurelWreath(resources, 10) binding.placeholder6Text.text = "0%" - binding.placeholder6Text.background = LaurelWreath(resources, context!!, 0) + binding.placeholder6Text.background = LaurelWreath(resources, 0) } private suspend fun updateLocalRankText() { diff --git a/app/src/main/res/layout/fragment_profile.xml b/app/src/main/res/layout/fragment_profile.xml index 92d2096d06..39c1f9527d 100644 --- a/app/src/main/res/layout/fragment_profile.xml +++ b/app/src/main/res/layout/fragment_profile.xml @@ -128,17 +128,18 @@ + #70808b - #bdd19a - #006a00 - #44f diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml index 423df5d086..f2eaed4550 100644 --- a/app/src/main/res/values/colors.xml +++ b/app/src/main/res/values/colors.xml @@ -23,6 +23,8 @@ #fff #0fff + #006a00 + #888 @color/accent @@ -78,9 +80,6 @@ #AA335D #655555 - #006a00 - #bdd19a - #22f From 5b2535ab730f9e991100d4e381b4ec530d70a64e Mon Sep 17 00:00:00 2001 From: Mateusz Konieczny Date: Sat, 2 Jul 2022 20:56:24 +0200 Subject: [PATCH 07/39] ktlint terror --- .../screens/user/profile/ProfileFragment.kt | 37 +++++++++---------- 1 file changed, 18 insertions(+), 19 deletions(-) diff --git a/app/src/main/java/de/westnordost/streetcomplete/screens/user/profile/ProfileFragment.kt b/app/src/main/java/de/westnordost/streetcomplete/screens/user/profile/ProfileFragment.kt index 92c39c62ab..3aa7a57a86 100644 --- a/app/src/main/java/de/westnordost/streetcomplete/screens/user/profile/ProfileFragment.kt +++ b/app/src/main/java/de/westnordost/streetcomplete/screens/user/profile/ProfileFragment.kt @@ -189,27 +189,27 @@ class ProfileFragment : Fragment(R.layout.fragment_profile) { // Draw a red circle in the center canvas.drawCircle((width / 2).toFloat(), (height / 2).toFloat(), radius, niceSubtleGreen) - val imageWith = laurelLeafOnStalk.intrinsicWidth //width is the same as intrinsicWidth - val imageHeight = laurelLeafOnStalk.intrinsicHeight //width is the same as intrinsicWidth + val imageWith = laurelLeafOnStalk.intrinsicWidth // width is the same as intrinsicWidth + val imageHeight = laurelLeafOnStalk.intrinsicHeight // width is the same as intrinsicWidth - val imageWithEnding = horizontalEndingLeaf.intrinsicWidth //width is the same as intrinsicWidth - val imageHeightEnding = horizontalEndingLeaf.intrinsicHeight //width is the same as intrinsicWidth - //TODO - ending image should have the same size as a regular one + val imageWithEnding = horizontalEndingLeaf.intrinsicWidth // width is the same as intrinsicWidth + val imageHeightEnding = horizontalEndingLeaf.intrinsicHeight // width is the same as intrinsicWidth + // TODO - ending image should have the same size as a regular one val n = 11f val offset = width / 2f - val imageInternalOffset = imageWith/2f // drawBitmap takes lower-upper corner of bitmap, we care about bitmap center - val endingImageInternalOffset = imageWith/2f // drawBitmap takes lower-upper corner of bitmap, we care about bitmap center - val reach = ((n-1)*percentageOfGrowth/100).toInt() + val imageInternalOffset = imageWith / 2f // drawBitmap takes lower-upper corner of bitmap, we care about bitmap center + val endingImageInternalOffset = imageWith / 2f // drawBitmap takes lower-upper corner of bitmap, we care about bitmap center + val reach = ((n - 1) * percentageOfGrowth / 100).toInt() - for(i in 0..reach) { + for (i in 0..reach) { // https://web.archive.org/web/20210201203811/https://stackoverflow.com/questions/36493977/flip-a-bitmap-image-horizontally-or-vertically - val offsetFromBorder = height/12f + val offsetFromBorder = height / 12f // https://developer.android.com/reference/kotlin/androidx/core/graphics/package-summary#(android.graphics.Canvas).withRotation(kotlin.Float,kotlin.Float,kotlin.Float,kotlin.Function1) var bitmap = laurelLeafOnStalk.bitmap - if(i == reach) { + if (i == reach) { bitmap = horizontalEndingLeaf.bitmap } else if (i == 0 ) { bitmap = laurelStalk.bitmap @@ -217,16 +217,16 @@ class ProfileFragment : Fragment(R.layout.fragment_profile) { val flippedBitmap = bitmap.flipHorizontally() // left side - canvas.withRotation(i * 180.0f/n, width / 2f, height / 2f) { - canvas.drawBitmap(bitmap, offset - endingImageInternalOffset, height*0.78f, antiAliasPaint) + canvas.withRotation(i * 180.0f / n, width / 2f, height / 2f) { + canvas.drawBitmap(bitmap, offset - endingImageInternalOffset, height * 0.78f, antiAliasPaint) } - canvas.withRotation(-i * 180.0f/n, width / 2f, height / 2f) { - canvas.drawBitmap(flippedBitmap, offset - endingImageInternalOffset, height*0.78f, antiAliasPaint) + canvas.withRotation(-i * 180.0f / n, width / 2f, height / 2f) { + canvas.drawBitmap(flippedBitmap, offset - endingImageInternalOffset, height * 0.78f, antiAliasPaint) } } - //val smallCircleRadius = width /10f - //canvas.drawCircle(smallCircleRadius * 2, height - smallCircleRadius * 2, smallCircleRadius, bluePaint) + // val smallCircleRadius = width /10f + // canvas.drawCircle(smallCircleRadius * 2, height - smallCircleRadius * 2, smallCircleRadius, bluePaint) } override fun setAlpha(alpha: Int) { @@ -242,12 +242,11 @@ class ProfileFragment : Fragment(R.layout.fragment_profile) { PixelFormat.OPAQUE } - private fun updateGlobalRankText() { val rank = statisticsSource.rank binding.globalRankContainer.isGone = rank <= 0 || statisticsSource.getEditCount() <= 100 binding.globalRankText.text = "#$rank" - binding.globalRankText.background = LaurelWreath(resources,1001 - rank) + binding.globalRankText.background = LaurelWreath(resources, 1001 - rank) } private fun updatePlaceholderRanksTexts() { From 03c21f7f9756dcce84b59a17f7a063303bf8720a Mon Sep 17 00:00:00 2001 From: Mateusz Konieczny Date: Sat, 2 Jul 2022 21:05:43 +0200 Subject: [PATCH 08/39] try to fix leading leaf offset on left side --- .../main/res/drawable/ic_laurel_leaf_ending.xml | 8 ++++---- .../laurel_wreath/laurel_leaf_ending.svg | 16 +++++++++------- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/app/src/main/res/drawable/ic_laurel_leaf_ending.xml b/app/src/main/res/drawable/ic_laurel_leaf_ending.xml index c3a004aab4..22efc63829 100644 --- a/app/src/main/res/drawable/ic_laurel_leaf_ending.xml +++ b/app/src/main/res/drawable/ic_laurel_leaf_ending.xml @@ -1,17 +1,17 @@ + android:viewportHeight="14.774"> + height="12.77374mm" + inkscape:showpageshadow="2" + inkscape:deskcolor="#d1d1d1" /> + sodipodi:nodetypes="csscsaccc" /> From 2b117ffc588b84d55f1326efb435a1611031ced2 Mon Sep 17 00:00:00 2001 From: Mateusz Konieczny Date: Sat, 2 Jul 2022 21:38:23 +0200 Subject: [PATCH 09/39] uniformify drawable sizes so rotations will be predictable --- .../res/drawable/ic_laurel_leaf_rotated.xml | 12 ++-- .../res/drawable/ic_laurel_leaf_stalk.xml | 12 ++-- .../laurel_wreath/laurel_leaf_ending.svg | 4 +- .../laurel_leaf_ending_with_fill.svg | 67 +++++++++++++++++++ .../laurel_wreath/laurel_leaf_rotated.svg | 48 +++++++------ .../laurel_leaf_rotated_test.svg | 67 +++++++++++++++++++ .../laurel_wreath/laurel_leaf_stalk.svg | 24 ++++--- .../laurel_wreath/laurel_leaf_stalk_color.svg | 51 ++++++++++++++ .../laurel_wreath/laurel_leaf_stalk_test.svg | 58 ++++++++++++++++ 9 files changed, 297 insertions(+), 46 deletions(-) create mode 100644 res/graphics/laurel_wreath/laurel_leaf_ending_with_fill.svg create mode 100644 res/graphics/laurel_wreath/laurel_leaf_rotated_test.svg create mode 100644 res/graphics/laurel_wreath/laurel_leaf_stalk_color.svg create mode 100644 res/graphics/laurel_wreath/laurel_leaf_stalk_test.svg diff --git a/app/src/main/res/drawable/ic_laurel_leaf_rotated.xml b/app/src/main/res/drawable/ic_laurel_leaf_rotated.xml index 4759f33bba..aacbebf520 100644 --- a/app/src/main/res/drawable/ic_laurel_leaf_rotated.xml +++ b/app/src/main/res/drawable/ic_laurel_leaf_rotated.xml @@ -1,17 +1,17 @@ + android:width="16.7dp" + android:height="14.774dp" + android:viewportWidth="16.7" + android:viewportHeight="14.774"> + android:width="16.7dp" + android:height="14.774dp" + android:viewportWidth="16.7" + android:viewportHeight="14.774"> diff --git a/res/graphics/laurel_wreath/laurel_leaf_ending.svg b/res/graphics/laurel_wreath/laurel_leaf_ending.svg index 81f574c5d0..344e358746 100644 --- a/res/graphics/laurel_wreath/laurel_leaf_ending.svg +++ b/res/graphics/laurel_wreath/laurel_leaf_ending.svg @@ -24,8 +24,8 @@ inkscape:document-units="mm" showgrid="false" inkscape:zoom="11.313709" - inkscape:cx="27.046834" - inkscape:cy="39.553785" + inkscape:cx="27.046833" + inkscape:cy="39.642172" inkscape:window-width="1920" inkscape:window-height="1140" inkscape:window-x="0" diff --git a/res/graphics/laurel_wreath/laurel_leaf_ending_with_fill.svg b/res/graphics/laurel_wreath/laurel_leaf_ending_with_fill.svg new file mode 100644 index 0000000000..6b5a61f549 --- /dev/null +++ b/res/graphics/laurel_wreath/laurel_leaf_ending_with_fill.svg @@ -0,0 +1,67 @@ + + + + + + + + + + + + + + diff --git a/res/graphics/laurel_wreath/laurel_leaf_rotated.svg b/res/graphics/laurel_wreath/laurel_leaf_rotated.svg index b5036802aa..dfd70f84cc 100644 --- a/res/graphics/laurel_wreath/laurel_leaf_rotated.svg +++ b/res/graphics/laurel_wreath/laurel_leaf_rotated.svg @@ -2,13 +2,13 @@ + height="12.77374mm" + inkscape:showpageshadow="2" + inkscape:deskcolor="#d1d1d1" /> - + id="g3728" + transform="translate(-2.593532)"> + + + + - diff --git a/res/graphics/laurel_wreath/laurel_leaf_rotated_test.svg b/res/graphics/laurel_wreath/laurel_leaf_rotated_test.svg new file mode 100644 index 0000000000..db9441ee92 --- /dev/null +++ b/res/graphics/laurel_wreath/laurel_leaf_rotated_test.svg @@ -0,0 +1,67 @@ + + + + + + + + + + + + + + diff --git a/res/graphics/laurel_wreath/laurel_leaf_stalk.svg b/res/graphics/laurel_wreath/laurel_leaf_stalk.svg index 2a8644bb5f..97f71c4a7c 100644 --- a/res/graphics/laurel_wreath/laurel_leaf_stalk.svg +++ b/res/graphics/laurel_wreath/laurel_leaf_stalk.svg @@ -2,13 +2,13 @@ + height="12.77374mm" + inkscape:showpageshadow="2" + inkscape:deskcolor="#d1d1d1" /> + x="-80.811401" + y="-9.1130161" /> diff --git a/res/graphics/laurel_wreath/laurel_leaf_stalk_color.svg b/res/graphics/laurel_wreath/laurel_leaf_stalk_color.svg new file mode 100644 index 0000000000..440ebffcba --- /dev/null +++ b/res/graphics/laurel_wreath/laurel_leaf_stalk_color.svg @@ -0,0 +1,51 @@ + + + + + + + + + + diff --git a/res/graphics/laurel_wreath/laurel_leaf_stalk_test.svg b/res/graphics/laurel_wreath/laurel_leaf_stalk_test.svg new file mode 100644 index 0000000000..95da1640ad --- /dev/null +++ b/res/graphics/laurel_wreath/laurel_leaf_stalk_test.svg @@ -0,0 +1,58 @@ + + + + + + + + + + + From c49444fe89b42e05a8b2dff90852014d8c71c389 Mon Sep 17 00:00:00 2001 From: Mateusz Konieczny Date: Sun, 3 Jul 2022 13:42:03 +0200 Subject: [PATCH 10/39] shorten stalk on leaf ending to eliminate artefact --- .../screens/user/profile/ProfileFragment.kt | 16 ++++++++-------- .../main/res/drawable/ic_laurel_leaf_ending.xml | 6 +++--- .../laurel_wreath/laurel_leaf_ending.svg | 17 +++++++---------- 3 files changed, 18 insertions(+), 21 deletions(-) diff --git a/app/src/main/java/de/westnordost/streetcomplete/screens/user/profile/ProfileFragment.kt b/app/src/main/java/de/westnordost/streetcomplete/screens/user/profile/ProfileFragment.kt index 3aa7a57a86..9e68865136 100644 --- a/app/src/main/java/de/westnordost/streetcomplete/screens/user/profile/ProfileFragment.kt +++ b/app/src/main/java/de/westnordost/streetcomplete/screens/user/profile/ProfileFragment.kt @@ -253,17 +253,17 @@ class ProfileFragment : Fragment(R.layout.fragment_profile) { binding.placeholder1Text.text = "100%" binding.placeholder1Text.background = LaurelWreath(resources, 100) - binding.placeholder2Text.text = "90%" - binding.placeholder2Text.background = LaurelWreath(resources, 90) + binding.placeholder2Text.text = "2%" + binding.placeholder2Text.background = LaurelWreath(resources, 2) - binding.placeholder3Text.text = "50%" - binding.placeholder3Text.background = LaurelWreath(resources, 50) + binding.placeholder3Text.text = "10%" + binding.placeholder3Text.background = LaurelWreath(resources, 10) - binding.placeholder4Text.text = "30%" - binding.placeholder4Text.background = LaurelWreath(resources, 30) + binding.placeholder4Text.text = "6%" + binding.placeholder4Text.background = LaurelWreath(resources, 6) - binding.placeholder5Text.text = "10%" - binding.placeholder5Text.background = LaurelWreath(resources, 10) + binding.placeholder5Text.text = "1%" + binding.placeholder5Text.background = LaurelWreath(resources, 1) binding.placeholder6Text.text = "0%" binding.placeholder6Text.background = LaurelWreath(resources, 0) diff --git a/app/src/main/res/drawable/ic_laurel_leaf_ending.xml b/app/src/main/res/drawable/ic_laurel_leaf_ending.xml index 22efc63829..584f27c970 100644 --- a/app/src/main/res/drawable/ic_laurel_leaf_ending.xml +++ b/app/src/main/res/drawable/ic_laurel_leaf_ending.xml @@ -4,14 +4,14 @@ android:viewportWidth="16.7" android:viewportHeight="14.774"> - + style="fill-opacity:0.244816;fill-rule:evenodd;stroke:#065006;stroke-width:0.713252" + d="m -80.255721,-9.0989532 h 10.748108 v 0.047938 h -10.748108 z" /> + transform="matrix(0.82701863,1.0718167,1.0718167,-0.82701863,3.2514067,61.5102)"> From 3cea77e123c1a977922af341cb4869b0f88d4da6 Mon Sep 17 00:00:00 2001 From: Mateusz Konieczny Date: Sun, 3 Jul 2022 13:51:54 +0200 Subject: [PATCH 11/39] more stringent testing of renderings --- .../screens/user/profile/ProfileFragment.kt | 70 ++++++-- app/src/main/res/layout/fragment_profile.xml | 163 ++++++++++++++++++ 2 files changed, 214 insertions(+), 19 deletions(-) diff --git a/app/src/main/java/de/westnordost/streetcomplete/screens/user/profile/ProfileFragment.kt b/app/src/main/java/de/westnordost/streetcomplete/screens/user/profile/ProfileFragment.kt index 9e68865136..edd0f03b30 100644 --- a/app/src/main/java/de/westnordost/streetcomplete/screens/user/profile/ProfileFragment.kt +++ b/app/src/main/java/de/westnordost/streetcomplete/screens/user/profile/ProfileFragment.kt @@ -37,6 +37,7 @@ import org.koin.android.ext.android.inject import org.koin.core.qualifier.named import java.io.File import java.util.Locale +import kotlin.random.Random /** Shows the user profile: username, avatar, star count and a hint regarding unpublished changes */ class ProfileFragment : Fragment(R.layout.fragment_profile) { @@ -161,8 +162,8 @@ class ProfileFragment : Fragment(R.layout.fragment_profile) { /* 100 and more: fully grown wreath with all pretty elements - 99 to 1: may be losing elements as it gets smaller - 0 and lower: no decorative styling at all + 99 to 10: may be losing elements as it gets smaller + below: no decorative styling at all */ class LaurelWreath(val resources: Resources, private val percentageOfGrowth: Int) : Drawable() { val laurelLeafOnStalk = resources.getBitmapDrawable(R.drawable.ic_laurel_leaf_rotated) @@ -189,6 +190,10 @@ class ProfileFragment : Fragment(R.layout.fragment_profile) { // Draw a red circle in the center canvas.drawCircle((width / 2).toFloat(), (height / 2).toFloat(), radius, niceSubtleGreen) + if(percentageOfGrowth < 10) { + return + } + val imageWith = laurelLeafOnStalk.intrinsicWidth // width is the same as intrinsicWidth val imageHeight = laurelLeafOnStalk.intrinsicHeight // width is the same as intrinsicWidth @@ -250,23 +255,50 @@ class ProfileFragment : Fragment(R.layout.fragment_profile) { } private fun updatePlaceholderRanksTexts() { - binding.placeholder1Text.text = "100%" - binding.placeholder1Text.background = LaurelWreath(resources, 100) - - binding.placeholder2Text.text = "2%" - binding.placeholder2Text.background = LaurelWreath(resources, 2) - - binding.placeholder3Text.text = "10%" - binding.placeholder3Text.background = LaurelWreath(resources, 10) - - binding.placeholder4Text.text = "6%" - binding.placeholder4Text.background = LaurelWreath(resources, 6) - - binding.placeholder5Text.text = "1%" - binding.placeholder5Text.background = LaurelWreath(resources, 1) - - binding.placeholder6Text.text = "0%" - binding.placeholder6Text.background = LaurelWreath(resources, 0) + var percent : Int + percent = 100 + binding.placeholder1Text.text = "$percent" + binding.placeholder1Text.background = LaurelWreath(resources, percent) + + percent = 90 + Random.nextInt(10) + binding.placeholder2Text.text = "$percent" + binding.placeholder2Text.background = LaurelWreath(resources, percent) + + percent = 80 + Random.nextInt(10) + binding.placeholder3Text.text = "$percent" + binding.placeholder3Text.background = LaurelWreath(resources, percent) + + percent = 70 + Random.nextInt(10) + binding.placeholder4Text.text = "$percent" + binding.placeholder4Text.background = LaurelWreath(resources, percent) + + percent = 60 + Random.nextInt(10) + binding.placeholder5Text.text = "$percent" + binding.placeholder5Text.background = LaurelWreath(resources, percent) + + percent = 50 + Random.nextInt(10) + binding.placeholder6Text.text = "$percent" + binding.placeholder6Text.background = LaurelWreath(resources, percent) + + percent = 40 + Random.nextInt(10) + binding.placeholder7Text.text = "$percent" + binding.placeholder7Text.background = LaurelWreath(resources, percent) + + percent = 30 + Random.nextInt(10) + binding.placeholder8Text.text = "$percent" + binding.placeholder8Text.background = LaurelWreath(resources, percent) + + percent = 20 + Random.nextInt(10) + binding.placeholder9Text.text = "$percent" + binding.placeholder9Text.background = LaurelWreath(resources, percent) + + percent = 10 + Random.nextInt(10) + binding.placeholder10Text.text = "$percent" + binding.placeholder10Text.background = LaurelWreath(resources, percent) + + percent = 0 + Random.nextInt(10) + binding.placeholder11Text.text = "$percent" + binding.placeholder11Text.background = LaurelWreath(resources, percent) } private suspend fun updateLocalRankText() { diff --git a/app/src/main/res/layout/fragment_profile.xml b/app/src/main/res/layout/fragment_profile.xml index bab0359d49..ac6cf6e919 100644 --- a/app/src/main/res/layout/fragment_profile.xml +++ b/app/src/main/res/layout/fragment_profile.xml @@ -451,6 +451,169 @@ android:text="Placeholder 6"/> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + From 27e73b712cd3b9cd54c07bd831e7d9dd1aece055 Mon Sep 17 00:00:00 2001 From: Mateusz Konieczny Date: Sun, 3 Jul 2022 14:20:33 +0200 Subject: [PATCH 12/39] drop dead code and fix typo --- .../screens/user/profile/ProfileFragment.kt | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-) diff --git a/app/src/main/java/de/westnordost/streetcomplete/screens/user/profile/ProfileFragment.kt b/app/src/main/java/de/westnordost/streetcomplete/screens/user/profile/ProfileFragment.kt index edd0f03b30..502a1466bd 100644 --- a/app/src/main/java/de/westnordost/streetcomplete/screens/user/profile/ProfileFragment.kt +++ b/app/src/main/java/de/westnordost/streetcomplete/screens/user/profile/ProfileFragment.kt @@ -170,11 +170,7 @@ class ProfileFragment : Fragment(R.layout.fragment_profile) { val laurelStalk = resources.getBitmapDrawable(R.drawable.ic_laurel_leaf_stalk) val horizontalEndingLeaf = resources.getBitmapDrawable(R.drawable.ic_laurel_leaf_ending) - private val redPaint: Paint = Paint().apply { setARGB(255, 255, 0, 0) } private val niceSubtleGreen: Paint = Paint().apply { setARGB(255, 186, 209, 154) } - private val yellowPaint: Paint = Paint().apply { setARGB(255, 255, 255, 0) } - private val orangePaint: Paint = Paint().apply { setARGB(255, 255, 155, 0) } - private val bluePaint: Paint = Paint().apply { setARGB(255, 0, 0, 255) } private val antiAliasPaint: Paint = Paint().apply { isAntiAlias = true @@ -194,23 +190,16 @@ class ProfileFragment : Fragment(R.layout.fragment_profile) { return } - val imageWith = laurelLeafOnStalk.intrinsicWidth // width is the same as intrinsicWidth + val imageWidth = laurelLeafOnStalk.intrinsicWidth // width is the same as intrinsicWidth val imageHeight = laurelLeafOnStalk.intrinsicHeight // width is the same as intrinsicWidth - val imageWithEnding = horizontalEndingLeaf.intrinsicWidth // width is the same as intrinsicWidth - val imageHeightEnding = horizontalEndingLeaf.intrinsicHeight // width is the same as intrinsicWidth - // TODO - ending image should have the same size as a regular one - val n = 11f val offset = width / 2f - val imageInternalOffset = imageWith / 2f // drawBitmap takes lower-upper corner of bitmap, we care about bitmap center - val endingImageInternalOffset = imageWith / 2f // drawBitmap takes lower-upper corner of bitmap, we care about bitmap center + val endingImageInternalOffset = imageWidth / 2f // drawBitmap takes lower-upper corner of bitmap, we care about bitmap center val reach = ((n - 1) * percentageOfGrowth / 100).toInt() for (i in 0..reach) { - // https://web.archive.org/web/20210201203811/https://stackoverflow.com/questions/36493977/flip-a-bitmap-image-horizontally-or-vertically - val offsetFromBorder = height / 12f // https://developer.android.com/reference/kotlin/androidx/core/graphics/package-summary#(android.graphics.Canvas).withRotation(kotlin.Float,kotlin.Float,kotlin.Float,kotlin.Function1) var bitmap = laurelLeafOnStalk.bitmap From 7f2585a2878d90848776f6f3f084cc4717c23ea9 Mon Sep 17 00:00:00 2001 From: Mateusz Konieczny Date: Sun, 3 Jul 2022 14:37:48 +0200 Subject: [PATCH 13/39] start applying styling to real ranks --- .../screens/user/profile/ProfileFragment.kt | 18 +++++++++++++++--- app/src/main/res/layout/fragment_profile.xml | 16 ++++++++-------- 2 files changed, 23 insertions(+), 11 deletions(-) diff --git a/app/src/main/java/de/westnordost/streetcomplete/screens/user/profile/ProfileFragment.kt b/app/src/main/java/de/westnordost/streetcomplete/screens/user/profile/ProfileFragment.kt index 502a1466bd..09cf77dcd8 100644 --- a/app/src/main/java/de/westnordost/streetcomplete/screens/user/profile/ProfileFragment.kt +++ b/app/src/main/java/de/westnordost/streetcomplete/screens/user/profile/ProfileFragment.kt @@ -36,6 +36,8 @@ import kotlinx.coroutines.withContext import org.koin.android.ext.android.inject import org.koin.core.qualifier.named import java.io.File +import java.lang.Math.max +import java.lang.Math.min import java.util.Locale import kotlin.random.Random @@ -158,6 +160,7 @@ class ProfileFragment : Fragment(R.layout.fragment_profile) { val daysActive = statisticsSource.daysActive binding.daysActiveContainer.isGone = daysActive <= 0 binding.daysActiveText.text = daysActive.toString() + binding.daysActiveText.background = LaurelWreath(resources, min(daysActive, 100)) } /* @@ -240,7 +243,12 @@ class ProfileFragment : Fragment(R.layout.fragment_profile) { val rank = statisticsSource.rank binding.globalRankContainer.isGone = rank <= 0 || statisticsSource.getEditCount() <= 100 binding.globalRankText.text = "#$rank" - binding.globalRankText.background = LaurelWreath(resources, 1001 - rank) + val scMapperCountIn2022 = 45000 + val rankEnoughForFullMarks = 1000 + val rankEnoughToStartGrowingReward = 8000 // TODO: tweak this based on actual numbers! + val ranksAboveThreshold = max(rankEnoughToStartGrowingReward - rank, 0) + val scaledRank = (ranksAboveThreshold * 100.0 / (rankEnoughToStartGrowingReward - rankEnoughForFullMarks)).toInt() + binding.globalRankText.background = LaurelWreath(resources, min(scaledRank, 100)) } private fun updatePlaceholderRanksTexts() { @@ -299,8 +307,11 @@ class ProfileFragment : Fragment(R.layout.fragment_profile) { val shouldShow = statistics.rank != null && statistics.rank > 0 && statistics.count > 50 val countryLocale = Locale("", statistics.countryCode) binding.localRankContainer.isGone = !shouldShow - binding.localRankText.text = "#${statistics.rank}" - binding.localRankLabel.text = getString(R.string.user_profile_local_rank, countryLocale.displayCountry) + if(shouldShow) { + binding.localRankText.text = "#${statistics.rank}" + binding.localRankLabel.text = getString(R.string.user_profile_local_rank, countryLocale.displayCountry) + binding.localRankText.background = LaurelWreath(resources, min(100 - statistics.rank!!, 100)) + } } } @@ -308,6 +319,7 @@ class ProfileFragment : Fragment(R.layout.fragment_profile) { val levels = withContext(Dispatchers.IO) { achievementsSource.getAchievements().sumOf { it.second } } binding.achievementLevelsContainer.isGone = levels <= 0 binding.achievementLevelsText.text = "$levels" + binding.achievementLevelsText.background = LaurelWreath(resources, min(levels / 2, 100)) } private fun openUrl(url: String): Boolean { diff --git a/app/src/main/res/layout/fragment_profile.xml b/app/src/main/res/layout/fragment_profile.xml index ac6cf6e919..3f883b724c 100644 --- a/app/src/main/res/layout/fragment_profile.xml +++ b/app/src/main/res/layout/fragment_profile.xml @@ -128,8 +128,8 @@ Date: Mon, 4 Jul 2022 14:23:26 +0200 Subject: [PATCH 14/39] avoid merging decoration with text could happen with for example ranking where long position such as #10000 may qualify for noticeable decoration --- app/src/main/res/layout/fragment_profile.xml | 21 ++++++++++---------- app/src/main/res/values/colors.xml | 2 -- 2 files changed, 10 insertions(+), 13 deletions(-) diff --git a/app/src/main/res/layout/fragment_profile.xml b/app/src/main/res/layout/fragment_profile.xml index 3f883b724c..9f17ac0aec 100644 --- a/app/src/main/res/layout/fragment_profile.xml +++ b/app/src/main/res/layout/fragment_profile.xml @@ -275,7 +275,7 @@ app:autoSizeTextType="uniform" app:autoSizeMaxTextSize="22dp" app:autoSizeMinTextSize="12dp" - android:textColor="@color/rank_text" + android:textColor="@color/background" tools:text="123"/> - #fff #0fff - #006a00 - #888 @color/accent From 3117e03eb7140df8c21f63bc3c61af1bf7647855 Mon Sep 17 00:00:00 2001 From: Mateusz Konieczny Date: Mon, 4 Jul 2022 16:38:01 +0200 Subject: [PATCH 15/39] more encouraging scaling of active days for new mappers --- .../streetcomplete/screens/user/profile/ProfileFragment.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/de/westnordost/streetcomplete/screens/user/profile/ProfileFragment.kt b/app/src/main/java/de/westnordost/streetcomplete/screens/user/profile/ProfileFragment.kt index 09cf77dcd8..256d3096b3 100644 --- a/app/src/main/java/de/westnordost/streetcomplete/screens/user/profile/ProfileFragment.kt +++ b/app/src/main/java/de/westnordost/streetcomplete/screens/user/profile/ProfileFragment.kt @@ -160,7 +160,7 @@ class ProfileFragment : Fragment(R.layout.fragment_profile) { val daysActive = statisticsSource.daysActive binding.daysActiveContainer.isGone = daysActive <= 0 binding.daysActiveText.text = daysActive.toString() - binding.daysActiveText.background = LaurelWreath(resources, min(daysActive, 100)) + binding.daysActiveText.background = LaurelWreath(resources, min(daysActive + 20, 100)) } /* From 409ef51e7dbe9acfc8efa0ea542326685a507f0b Mon Sep 17 00:00:00 2001 From: Mateusz Konieczny Date: Mon, 4 Jul 2022 17:01:20 +0200 Subject: [PATCH 16/39] remove test graphics --- .../laurel_leaf_ending_with_fill.svg | 67 ------------------- .../laurel_leaf_rotated_test.svg | 67 ------------------- .../laurel_wreath/laurel_leaf_stalk_color.svg | 51 -------------- .../laurel_wreath/laurel_leaf_stalk_test.svg | 58 ---------------- 4 files changed, 243 deletions(-) delete mode 100644 res/graphics/laurel_wreath/laurel_leaf_ending_with_fill.svg delete mode 100644 res/graphics/laurel_wreath/laurel_leaf_rotated_test.svg delete mode 100644 res/graphics/laurel_wreath/laurel_leaf_stalk_color.svg delete mode 100644 res/graphics/laurel_wreath/laurel_leaf_stalk_test.svg diff --git a/res/graphics/laurel_wreath/laurel_leaf_ending_with_fill.svg b/res/graphics/laurel_wreath/laurel_leaf_ending_with_fill.svg deleted file mode 100644 index 6b5a61f549..0000000000 --- a/res/graphics/laurel_wreath/laurel_leaf_ending_with_fill.svg +++ /dev/null @@ -1,67 +0,0 @@ - - - - - - - - - - - - - - diff --git a/res/graphics/laurel_wreath/laurel_leaf_rotated_test.svg b/res/graphics/laurel_wreath/laurel_leaf_rotated_test.svg deleted file mode 100644 index db9441ee92..0000000000 --- a/res/graphics/laurel_wreath/laurel_leaf_rotated_test.svg +++ /dev/null @@ -1,67 +0,0 @@ - - - - - - - - - - - - - - diff --git a/res/graphics/laurel_wreath/laurel_leaf_stalk_color.svg b/res/graphics/laurel_wreath/laurel_leaf_stalk_color.svg deleted file mode 100644 index 440ebffcba..0000000000 --- a/res/graphics/laurel_wreath/laurel_leaf_stalk_color.svg +++ /dev/null @@ -1,51 +0,0 @@ - - - - - - - - - - diff --git a/res/graphics/laurel_wreath/laurel_leaf_stalk_test.svg b/res/graphics/laurel_wreath/laurel_leaf_stalk_test.svg deleted file mode 100644 index 95da1640ad..0000000000 --- a/res/graphics/laurel_wreath/laurel_leaf_stalk_test.svg +++ /dev/null @@ -1,58 +0,0 @@ - - - - - - - - - - - From fc049b13e31929ec6e325b527f341f437da1e8fe Mon Sep 17 00:00:00 2001 From: Mateusz Konieczny Date: Mon, 4 Jul 2022 17:01:46 +0200 Subject: [PATCH 17/39] tweak colors for background --- .../streetcomplete/screens/user/profile/ProfileFragment.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/de/westnordost/streetcomplete/screens/user/profile/ProfileFragment.kt b/app/src/main/java/de/westnordost/streetcomplete/screens/user/profile/ProfileFragment.kt index 256d3096b3..7982b731c7 100644 --- a/app/src/main/java/de/westnordost/streetcomplete/screens/user/profile/ProfileFragment.kt +++ b/app/src/main/java/de/westnordost/streetcomplete/screens/user/profile/ProfileFragment.kt @@ -173,7 +173,7 @@ class ProfileFragment : Fragment(R.layout.fragment_profile) { val laurelStalk = resources.getBitmapDrawable(R.drawable.ic_laurel_leaf_stalk) val horizontalEndingLeaf = resources.getBitmapDrawable(R.drawable.ic_laurel_leaf_ending) - private val niceSubtleGreen: Paint = Paint().apply { setARGB(255, 186, 209, 154) } + private val niceSubtleGreen: Paint = Paint().apply { setARGB(255, 177, 215, 147) } private val antiAliasPaint: Paint = Paint().apply { isAntiAlias = true From 8cbecf0b46ec9dc203f6d32f6fb53319d8a437f5 Mon Sep 17 00:00:00 2001 From: Mateusz Konieczny Date: Mon, 4 Jul 2022 17:12:45 +0200 Subject: [PATCH 18/39] tweak colors backround ranking bubbles to make text more visible on them --- .../streetcomplete/screens/user/profile/ProfileFragment.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/de/westnordost/streetcomplete/screens/user/profile/ProfileFragment.kt b/app/src/main/java/de/westnordost/streetcomplete/screens/user/profile/ProfileFragment.kt index 7982b731c7..e0399f92de 100644 --- a/app/src/main/java/de/westnordost/streetcomplete/screens/user/profile/ProfileFragment.kt +++ b/app/src/main/java/de/westnordost/streetcomplete/screens/user/profile/ProfileFragment.kt @@ -173,7 +173,7 @@ class ProfileFragment : Fragment(R.layout.fragment_profile) { val laurelStalk = resources.getBitmapDrawable(R.drawable.ic_laurel_leaf_stalk) val horizontalEndingLeaf = resources.getBitmapDrawable(R.drawable.ic_laurel_leaf_ending) - private val niceSubtleGreen: Paint = Paint().apply { setARGB(255, 177, 215, 147) } + private val niceSubtleGreen: Paint = Paint().apply { setARGB(255, 152, 184, 126) } private val antiAliasPaint: Paint = Paint().apply { isAntiAlias = true From 8bf90d2dca7040b0eb77d5fc73d58f562cd6f772 Mon Sep 17 00:00:00 2001 From: Mateusz Konieczny Date: Tue, 12 Jul 2022 20:47:13 +0200 Subject: [PATCH 19/39] note authorship --- res/graphics/authors.txt | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/res/graphics/authors.txt b/res/graphics/authors.txt index 69d811da26..a10ab6c0bc 100644 --- a/res/graphics/authors.txt +++ b/res/graphics/authors.txt @@ -195,6 +195,10 @@ lanes/ car4.svg car5.svg +laurel_wreath/ + laurel_leaf_rotated.svg CC0 Mateusz Konieczny (if even copyright is applicable here) + laurel_leaf_ending.svg CC0 Mateusz Konieczny (if even copyright is applicable here) + links/ link_neis_one.svg From 64eb57aafc25536b63ff862cc73bda1b4b57680f Mon Sep 17 00:00:00 2001 From: Mateusz Konieczny Date: Tue, 12 Jul 2022 20:48:22 +0200 Subject: [PATCH 20/39] make placeholders more clear --- .../screens/user/profile/ProfileFragment.kt | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/app/src/main/java/de/westnordost/streetcomplete/screens/user/profile/ProfileFragment.kt b/app/src/main/java/de/westnordost/streetcomplete/screens/user/profile/ProfileFragment.kt index e0399f92de..41af95c4ec 100644 --- a/app/src/main/java/de/westnordost/streetcomplete/screens/user/profile/ProfileFragment.kt +++ b/app/src/main/java/de/westnordost/streetcomplete/screens/user/profile/ProfileFragment.kt @@ -254,47 +254,47 @@ class ProfileFragment : Fragment(R.layout.fragment_profile) { private fun updatePlaceholderRanksTexts() { var percent : Int percent = 100 - binding.placeholder1Text.text = "$percent" + binding.placeholder1Text.text = "$percent%" binding.placeholder1Text.background = LaurelWreath(resources, percent) percent = 90 + Random.nextInt(10) - binding.placeholder2Text.text = "$percent" + binding.placeholder2Text.text = "$percent%" binding.placeholder2Text.background = LaurelWreath(resources, percent) percent = 80 + Random.nextInt(10) - binding.placeholder3Text.text = "$percent" + binding.placeholder3Text.text = "$percent%" binding.placeholder3Text.background = LaurelWreath(resources, percent) percent = 70 + Random.nextInt(10) - binding.placeholder4Text.text = "$percent" + binding.placeholder4Text.text = "$percent%" binding.placeholder4Text.background = LaurelWreath(resources, percent) percent = 60 + Random.nextInt(10) - binding.placeholder5Text.text = "$percent" + binding.placeholder5Text.text = "$percent%" binding.placeholder5Text.background = LaurelWreath(resources, percent) percent = 50 + Random.nextInt(10) - binding.placeholder6Text.text = "$percent" + binding.placeholder6Text.text = "$percent%" binding.placeholder6Text.background = LaurelWreath(resources, percent) percent = 40 + Random.nextInt(10) - binding.placeholder7Text.text = "$percent" + binding.placeholder7Text.text = "$percent%" binding.placeholder7Text.background = LaurelWreath(resources, percent) percent = 30 + Random.nextInt(10) - binding.placeholder8Text.text = "$percent" + binding.placeholder8Text.text = "$percent%" binding.placeholder8Text.background = LaurelWreath(resources, percent) percent = 20 + Random.nextInt(10) - binding.placeholder9Text.text = "$percent" + binding.placeholder9Text.text = "$percent%" binding.placeholder9Text.background = LaurelWreath(resources, percent) percent = 10 + Random.nextInt(10) - binding.placeholder10Text.text = "$percent" + binding.placeholder10Text.text = "$percent%" binding.placeholder10Text.background = LaurelWreath(resources, percent) percent = 0 + Random.nextInt(10) - binding.placeholder11Text.text = "$percent" + binding.placeholder11Text.text = "$percent%" binding.placeholder11Text.background = LaurelWreath(resources, percent) } From aca6ef3eacbc6ecf2aa89b69e22bf85696e63251 Mon Sep 17 00:00:00 2001 From: Mateusz Konieczny Date: Tue, 12 Jul 2022 20:49:07 +0200 Subject: [PATCH 21/39] ktlint terror --- .../streetcomplete/screens/user/profile/ProfileFragment.kt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/de/westnordost/streetcomplete/screens/user/profile/ProfileFragment.kt b/app/src/main/java/de/westnordost/streetcomplete/screens/user/profile/ProfileFragment.kt index 41af95c4ec..4982040e7b 100644 --- a/app/src/main/java/de/westnordost/streetcomplete/screens/user/profile/ProfileFragment.kt +++ b/app/src/main/java/de/westnordost/streetcomplete/screens/user/profile/ProfileFragment.kt @@ -189,7 +189,7 @@ class ProfileFragment : Fragment(R.layout.fragment_profile) { // Draw a red circle in the center canvas.drawCircle((width / 2).toFloat(), (height / 2).toFloat(), radius, niceSubtleGreen) - if(percentageOfGrowth < 10) { + if (percentageOfGrowth < 10) { return } @@ -252,7 +252,7 @@ class ProfileFragment : Fragment(R.layout.fragment_profile) { } private fun updatePlaceholderRanksTexts() { - var percent : Int + var percent: Int percent = 100 binding.placeholder1Text.text = "$percent%" binding.placeholder1Text.background = LaurelWreath(resources, percent) @@ -307,7 +307,7 @@ class ProfileFragment : Fragment(R.layout.fragment_profile) { val shouldShow = statistics.rank != null && statistics.rank > 0 && statistics.count > 50 val countryLocale = Locale("", statistics.countryCode) binding.localRankContainer.isGone = !shouldShow - if(shouldShow) { + if (shouldShow) { binding.localRankText.text = "#${statistics.rank}" binding.localRankLabel.text = getString(R.string.user_profile_local_rank, countryLocale.displayCountry) binding.localRankText.background = LaurelWreath(resources, min(100 - statistics.rank!!, 100)) From a0dc92a87806f0fd8afb0b5d428a63a3fe02ecff Mon Sep 17 00:00:00 2001 From: Mateusz Konieczny Date: Tue, 12 Jul 2022 20:51:19 +0200 Subject: [PATCH 22/39] drop misleading comment --- .../streetcomplete/screens/user/profile/ProfileFragment.kt | 1 - 1 file changed, 1 deletion(-) diff --git a/app/src/main/java/de/westnordost/streetcomplete/screens/user/profile/ProfileFragment.kt b/app/src/main/java/de/westnordost/streetcomplete/screens/user/profile/ProfileFragment.kt index 4982040e7b..da80dcdc41 100644 --- a/app/src/main/java/de/westnordost/streetcomplete/screens/user/profile/ProfileFragment.kt +++ b/app/src/main/java/de/westnordost/streetcomplete/screens/user/profile/ProfileFragment.kt @@ -186,7 +186,6 @@ class ProfileFragment : Fragment(R.layout.fragment_profile) { val height: Int = bounds.height() val radius: Float = Math.min(width, height).toFloat() / 2f - // Draw a red circle in the center canvas.drawCircle((width / 2).toFloat(), (height / 2).toFloat(), radius, niceSubtleGreen) if (percentageOfGrowth < 10) { From 412435c20d6e1a27d6986b3e5c2f19fdae0e2eb1 Mon Sep 17 00:00:00 2001 From: Mateusz Konieczny Date: Tue, 12 Jul 2022 20:52:16 +0200 Subject: [PATCH 23/39] further comment fixes --- .../streetcomplete/screens/user/profile/ProfileFragment.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/de/westnordost/streetcomplete/screens/user/profile/ProfileFragment.kt b/app/src/main/java/de/westnordost/streetcomplete/screens/user/profile/ProfileFragment.kt index da80dcdc41..3e4d50fd62 100644 --- a/app/src/main/java/de/westnordost/streetcomplete/screens/user/profile/ProfileFragment.kt +++ b/app/src/main/java/de/westnordost/streetcomplete/screens/user/profile/ProfileFragment.kt @@ -164,6 +164,7 @@ class ProfileFragment : Fragment(R.layout.fragment_profile) { } /* + Drawable providing decoration, suitable for a circular background 100 and more: fully grown wreath with all pretty elements 99 to 10: may be losing elements as it gets smaller below: no decorative styling at all @@ -217,12 +218,11 @@ class ProfileFragment : Fragment(R.layout.fragment_profile) { canvas.drawBitmap(bitmap, offset - endingImageInternalOffset, height * 0.78f, antiAliasPaint) } + // right side canvas.withRotation(-i * 180.0f / n, width / 2f, height / 2f) { canvas.drawBitmap(flippedBitmap, offset - endingImageInternalOffset, height * 0.78f, antiAliasPaint) } } - // val smallCircleRadius = width /10f - // canvas.drawCircle(smallCircleRadius * 2, height - smallCircleRadius * 2, smallCircleRadius, bluePaint) } override fun setAlpha(alpha: Int) { From 5528e67aa2ae1a5f4df0c6e9404dbc3e6fb3b13b Mon Sep 17 00:00:00 2001 From: Mateusz Konieczny Date: Tue, 12 Jul 2022 20:54:06 +0200 Subject: [PATCH 24/39] minor code refactoring --- .../streetcomplete/screens/user/profile/ProfileFragment.kt | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/de/westnordost/streetcomplete/screens/user/profile/ProfileFragment.kt b/app/src/main/java/de/westnordost/streetcomplete/screens/user/profile/ProfileFragment.kt index 3e4d50fd62..42821b808d 100644 --- a/app/src/main/java/de/westnordost/streetcomplete/screens/user/profile/ProfileFragment.kt +++ b/app/src/main/java/de/westnordost/streetcomplete/screens/user/profile/ProfileFragment.kt @@ -174,8 +174,6 @@ class ProfileFragment : Fragment(R.layout.fragment_profile) { val laurelStalk = resources.getBitmapDrawable(R.drawable.ic_laurel_leaf_stalk) val horizontalEndingLeaf = resources.getBitmapDrawable(R.drawable.ic_laurel_leaf_ending) - private val niceSubtleGreen: Paint = Paint().apply { setARGB(255, 152, 184, 126) } - private val antiAliasPaint: Paint = Paint().apply { isAntiAlias = true isFilterBitmap = true @@ -185,8 +183,9 @@ class ProfileFragment : Fragment(R.layout.fragment_profile) { // Get the drawable's bounds val width: Int = bounds.width() val height: Int = bounds.height() - val radius: Float = Math.min(width, height).toFloat() / 2f + val radius: Float = min(width, height).toFloat() / 2f + val niceSubtleGreen: Paint = Paint().apply { setARGB(255, 152, 184, 126) } canvas.drawCircle((width / 2).toFloat(), (height / 2).toFloat(), radius, niceSubtleGreen) if (percentageOfGrowth < 10) { From c3220a6d1f1e6df286fb931266ad772e8bdc8815 Mon Sep 17 00:00:00 2001 From: Mateusz Konieczny Date: Tue, 12 Jul 2022 21:11:56 +0200 Subject: [PATCH 25/39] explain code, tiny moving to more logical order --- .../screens/user/profile/ProfileFragment.kt | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/de/westnordost/streetcomplete/screens/user/profile/ProfileFragment.kt b/app/src/main/java/de/westnordost/streetcomplete/screens/user/profile/ProfileFragment.kt index 42821b808d..a48c4e33d4 100644 --- a/app/src/main/java/de/westnordost/streetcomplete/screens/user/profile/ProfileFragment.kt +++ b/app/src/main/java/de/westnordost/streetcomplete/screens/user/profile/ProfileFragment.kt @@ -200,7 +200,7 @@ class ProfileFragment : Fragment(R.layout.fragment_profile) { val offset = width / 2f val endingImageInternalOffset = imageWidth / 2f // drawBitmap takes lower-upper corner of bitmap, we care about bitmap center val reach = ((n - 1) * percentageOfGrowth / 100).toInt() - + val locationBetweenCenterAndEdge = 0.78f for (i in 0..reach) { // https://developer.android.com/reference/kotlin/androidx/core/graphics/package-summary#(android.graphics.Canvas).withRotation(kotlin.Float,kotlin.Float,kotlin.Float,kotlin.Function1) @@ -211,15 +211,15 @@ class ProfileFragment : Fragment(R.layout.fragment_profile) { bitmap = laurelStalk.bitmap } - val flippedBitmap = bitmap.flipHorizontally() // left side canvas.withRotation(i * 180.0f / n, width / 2f, height / 2f) { - canvas.drawBitmap(bitmap, offset - endingImageInternalOffset, height * 0.78f, antiAliasPaint) + canvas.drawBitmap(bitmap, offset - endingImageInternalOffset, height * locationBetweenCenterAndEdge, antiAliasPaint) } // right side + val flippedBitmap = bitmap.flipHorizontally() canvas.withRotation(-i * 180.0f / n, width / 2f, height / 2f) { - canvas.drawBitmap(flippedBitmap, offset - endingImageInternalOffset, height * 0.78f, antiAliasPaint) + canvas.drawBitmap(flippedBitmap, offset - endingImageInternalOffset, height * locationBetweenCenterAndEdge, antiAliasPaint) } } } From 90434fbd0e9d290ac311822eb110253a01a25804 Mon Sep 17 00:00:00 2001 From: Mateusz Konieczny Date: Tue, 12 Jul 2022 21:12:05 +0200 Subject: [PATCH 26/39] tweak reward scaling --- .../streetcomplete/screens/user/profile/ProfileFragment.kt | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/de/westnordost/streetcomplete/screens/user/profile/ProfileFragment.kt b/app/src/main/java/de/westnordost/streetcomplete/screens/user/profile/ProfileFragment.kt index a48c4e33d4..41ae5586af 100644 --- a/app/src/main/java/de/westnordost/streetcomplete/screens/user/profile/ProfileFragment.kt +++ b/app/src/main/java/de/westnordost/streetcomplete/screens/user/profile/ProfileFragment.kt @@ -238,12 +238,14 @@ class ProfileFragment : Fragment(R.layout.fragment_profile) { } private fun updateGlobalRankText() { + // note that global rank merges multiple people with the same score + // in case that 1000 people made 11 edits all will have the same rank (say, 3814) + // in case that 1000 people made 10 edits all will have the same rank (in this case - 3815) val rank = statisticsSource.rank binding.globalRankContainer.isGone = rank <= 0 || statisticsSource.getEditCount() <= 100 binding.globalRankText.text = "#$rank" - val scMapperCountIn2022 = 45000 val rankEnoughForFullMarks = 1000 - val rankEnoughToStartGrowingReward = 8000 // TODO: tweak this based on actual numbers! + val rankEnoughToStartGrowingReward = 3800 val ranksAboveThreshold = max(rankEnoughToStartGrowingReward - rank, 0) val scaledRank = (ranksAboveThreshold * 100.0 / (rankEnoughToStartGrowingReward - rankEnoughForFullMarks)).toInt() binding.globalRankText.background = LaurelWreath(resources, min(scaledRank, 100)) From 79861bba3b47cdab77ca849deb00e389de29bed1 Mon Sep 17 00:00:00 2001 From: Mateusz Konieczny Date: Tue, 12 Jul 2022 21:18:57 +0200 Subject: [PATCH 27/39] better describe what is going on --- .../screens/user/profile/ProfileFragment.kt | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/de/westnordost/streetcomplete/screens/user/profile/ProfileFragment.kt b/app/src/main/java/de/westnordost/streetcomplete/screens/user/profile/ProfileFragment.kt index 41ae5586af..14e8c597ae 100644 --- a/app/src/main/java/de/westnordost/streetcomplete/screens/user/profile/ProfileFragment.kt +++ b/app/src/main/java/de/westnordost/streetcomplete/screens/user/profile/ProfileFragment.kt @@ -192,13 +192,11 @@ class ProfileFragment : Fragment(R.layout.fragment_profile) { return } - val imageWidth = laurelLeafOnStalk.intrinsicWidth // width is the same as intrinsicWidth - val imageHeight = laurelLeafOnStalk.intrinsicHeight // width is the same as intrinsicWidth + val decorationSegmentImageWidth = laurelLeafOnStalk.intrinsicWidth // width is the same as intrinsicWidth val n = 11f val offset = width / 2f - val endingImageInternalOffset = imageWidth / 2f // drawBitmap takes lower-upper corner of bitmap, we care about bitmap center val reach = ((n - 1) * percentageOfGrowth / 100).toInt() val locationBetweenCenterAndEdge = 0.78f for (i in 0..reach) { @@ -213,13 +211,14 @@ class ProfileFragment : Fragment(R.layout.fragment_profile) { // left side canvas.withRotation(i * 180.0f / n, width / 2f, height / 2f) { - canvas.drawBitmap(bitmap, offset - endingImageInternalOffset, height * locationBetweenCenterAndEdge, antiAliasPaint) + // drawBitmap takes corner of the bitmap, we care about centering segments + canvas.drawBitmap(bitmap, offset - decorationSegmentImageWidth / 2f, height * locationBetweenCenterAndEdge, antiAliasPaint) } // right side val flippedBitmap = bitmap.flipHorizontally() canvas.withRotation(-i * 180.0f / n, width / 2f, height / 2f) { - canvas.drawBitmap(flippedBitmap, offset - endingImageInternalOffset, height * locationBetweenCenterAndEdge, antiAliasPaint) + canvas.drawBitmap(flippedBitmap, offset - decorationSegmentImageWidth / 2f, height * locationBetweenCenterAndEdge, antiAliasPaint) } } } From 6d01823b60ecd0804b77fc682d10a58aa04940f2 Mon Sep 17 00:00:00 2001 From: Mateusz Konieczny Date: Tue, 12 Jul 2022 21:21:25 +0200 Subject: [PATCH 28/39] drop inkscape cruft --- .../laurel_wreath/laurel_leaf_ending.svg | 29 +------------------ .../laurel_wreath/laurel_leaf_rotated.svg | 29 +------------------ .../laurel_wreath/laurel_leaf_stalk.svg | 26 ----------------- 3 files changed, 2 insertions(+), 82 deletions(-) diff --git a/res/graphics/laurel_wreath/laurel_leaf_ending.svg b/res/graphics/laurel_wreath/laurel_leaf_ending.svg index 0d69270492..ea26a737d6 100644 --- a/res/graphics/laurel_wreath/laurel_leaf_ending.svg +++ b/res/graphics/laurel_wreath/laurel_leaf_ending.svg @@ -7,34 +7,8 @@ viewBox="0 0 16.700001 14.77374" version="1.1" id="svg2717" - sodipodi:docname="laurel_leaf_ending.svg" - inkscape:version="1.2 (1:1.2+202206011327+fc4e4096c5)" - xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" - xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd" xmlns="http://www.w3.org/2000/svg" xmlns:svg="http://www.w3.org/2000/svg"> - + id="path959-6" /> diff --git a/res/graphics/laurel_wreath/laurel_leaf_rotated.svg b/res/graphics/laurel_wreath/laurel_leaf_rotated.svg index dfd70f84cc..ad967b3b52 100644 --- a/res/graphics/laurel_wreath/laurel_leaf_rotated.svg +++ b/res/graphics/laurel_wreath/laurel_leaf_rotated.svg @@ -7,34 +7,8 @@ viewBox="0 0 16.700001 14.77374" version="1.1" id="svg2717" - sodipodi:docname="laurel_leaf_rotated.svg" - inkscape:version="1.2 (1:1.2+202206011327+fc4e4096c5)" - xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" - xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd" xmlns="http://www.w3.org/2000/svg" xmlns:svg="http://www.w3.org/2000/svg"> - + id="path959" /> - Date: Tue, 12 Jul 2022 21:36:19 +0200 Subject: [PATCH 29/39] variables better explaining what is going on --- .../screens/user/profile/ProfileFragment.kt | 26 +++++++++---------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/app/src/main/java/de/westnordost/streetcomplete/screens/user/profile/ProfileFragment.kt b/app/src/main/java/de/westnordost/streetcomplete/screens/user/profile/ProfileFragment.kt index 14e8c597ae..03e9930848 100644 --- a/app/src/main/java/de/westnordost/streetcomplete/screens/user/profile/ProfileFragment.kt +++ b/app/src/main/java/de/westnordost/streetcomplete/screens/user/profile/ProfileFragment.kt @@ -181,12 +181,12 @@ class ProfileFragment : Fragment(R.layout.fragment_profile) { override fun draw(canvas: Canvas) { // Get the drawable's bounds - val width: Int = bounds.width() - val height: Int = bounds.height() - val radius: Float = min(width, height).toFloat() / 2f + val canvasWidth: Int = bounds.width() + val canvasHeight: Int = bounds.height() + val circleRadius: Float = min(canvasWidth, canvasHeight).toFloat() / 2f val niceSubtleGreen: Paint = Paint().apply { setARGB(255, 152, 184, 126) } - canvas.drawCircle((width / 2).toFloat(), (height / 2).toFloat(), radius, niceSubtleGreen) + canvas.drawCircle((canvasWidth / 2).toFloat(), (canvasHeight / 2).toFloat(), circleRadius, niceSubtleGreen) if (percentageOfGrowth < 10) { return @@ -194,31 +194,31 @@ class ProfileFragment : Fragment(R.layout.fragment_profile) { val decorationSegmentImageWidth = laurelLeafOnStalk.intrinsicWidth // width is the same as intrinsicWidth - val n = 11f + val regularSegmentCount = 11f - val offset = width / 2f - val reach = ((n - 1) * percentageOfGrowth / 100).toInt() + val circleCenterX = canvasWidth / 2f + val shownSegments = ((regularSegmentCount - 1) * percentageOfGrowth / 100).toInt() val locationBetweenCenterAndEdge = 0.78f - for (i in 0..reach) { + for (i in 0..shownSegments) { // https://developer.android.com/reference/kotlin/androidx/core/graphics/package-summary#(android.graphics.Canvas).withRotation(kotlin.Float,kotlin.Float,kotlin.Float,kotlin.Function1) var bitmap = laurelLeafOnStalk.bitmap - if (i == reach) { + if (i == shownSegments) { bitmap = horizontalEndingLeaf.bitmap } else if (i == 0 ) { bitmap = laurelStalk.bitmap } // left side - canvas.withRotation(i * 180.0f / n, width / 2f, height / 2f) { + canvas.withRotation(i * 180.0f / regularSegmentCount, canvasWidth / 2f, canvasHeight / 2f) { // drawBitmap takes corner of the bitmap, we care about centering segments - canvas.drawBitmap(bitmap, offset - decorationSegmentImageWidth / 2f, height * locationBetweenCenterAndEdge, antiAliasPaint) + canvas.drawBitmap(bitmap, circleCenterX - decorationSegmentImageWidth / 2f, canvasHeight * locationBetweenCenterAndEdge, antiAliasPaint) } // right side val flippedBitmap = bitmap.flipHorizontally() - canvas.withRotation(-i * 180.0f / n, width / 2f, height / 2f) { - canvas.drawBitmap(flippedBitmap, offset - decorationSegmentImageWidth / 2f, height * locationBetweenCenterAndEdge, antiAliasPaint) + canvas.withRotation(-i * 180.0f / regularSegmentCount, canvasWidth / 2f, canvasHeight / 2f) { + canvas.drawBitmap(flippedBitmap, circleCenterX - decorationSegmentImageWidth / 2f, canvasHeight * locationBetweenCenterAndEdge, antiAliasPaint) } } } From f81533c3e7df034315cd10399b1106d10678cefd Mon Sep 17 00:00:00 2001 From: Mateusz Konieczny Date: Tue, 12 Jul 2022 21:38:07 +0200 Subject: [PATCH 30/39] remove placeholders used for testing --- .../screens/user/profile/ProfileFragment.kt | 48 --- app/src/main/res/layout/fragment_profile.xml | 354 ------------------ 2 files changed, 402 deletions(-) diff --git a/app/src/main/java/de/westnordost/streetcomplete/screens/user/profile/ProfileFragment.kt b/app/src/main/java/de/westnordost/streetcomplete/screens/user/profile/ProfileFragment.kt index 03e9930848..9e7d25b58a 100644 --- a/app/src/main/java/de/westnordost/streetcomplete/screens/user/profile/ProfileFragment.kt +++ b/app/src/main/java/de/westnordost/streetcomplete/screens/user/profile/ProfileFragment.kt @@ -117,7 +117,6 @@ class ProfileFragment : Fragment(R.layout.fragment_profile) { updateGlobalRankText() updateLocalRankText() updateAchievementLevelsText() - updatePlaceholderRanksTexts() } } @@ -250,53 +249,6 @@ class ProfileFragment : Fragment(R.layout.fragment_profile) { binding.globalRankText.background = LaurelWreath(resources, min(scaledRank, 100)) } - private fun updatePlaceholderRanksTexts() { - var percent: Int - percent = 100 - binding.placeholder1Text.text = "$percent%" - binding.placeholder1Text.background = LaurelWreath(resources, percent) - - percent = 90 + Random.nextInt(10) - binding.placeholder2Text.text = "$percent%" - binding.placeholder2Text.background = LaurelWreath(resources, percent) - - percent = 80 + Random.nextInt(10) - binding.placeholder3Text.text = "$percent%" - binding.placeholder3Text.background = LaurelWreath(resources, percent) - - percent = 70 + Random.nextInt(10) - binding.placeholder4Text.text = "$percent%" - binding.placeholder4Text.background = LaurelWreath(resources, percent) - - percent = 60 + Random.nextInt(10) - binding.placeholder5Text.text = "$percent%" - binding.placeholder5Text.background = LaurelWreath(resources, percent) - - percent = 50 + Random.nextInt(10) - binding.placeholder6Text.text = "$percent%" - binding.placeholder6Text.background = LaurelWreath(resources, percent) - - percent = 40 + Random.nextInt(10) - binding.placeholder7Text.text = "$percent%" - binding.placeholder7Text.background = LaurelWreath(resources, percent) - - percent = 30 + Random.nextInt(10) - binding.placeholder8Text.text = "$percent%" - binding.placeholder8Text.background = LaurelWreath(resources, percent) - - percent = 20 + Random.nextInt(10) - binding.placeholder9Text.text = "$percent%" - binding.placeholder9Text.background = LaurelWreath(resources, percent) - - percent = 10 + Random.nextInt(10) - binding.placeholder10Text.text = "$percent%" - binding.placeholder10Text.background = LaurelWreath(resources, percent) - - percent = 0 + Random.nextInt(10) - binding.placeholder11Text.text = "$percent%" - binding.placeholder11Text.background = LaurelWreath(resources, percent) - } - private suspend fun updateLocalRankText() { val statistics = withContext(Dispatchers.IO) { statisticsSource.getCountryStatisticsOfCountryWithBiggestSolvedCount() diff --git a/app/src/main/res/layout/fragment_profile.xml b/app/src/main/res/layout/fragment_profile.xml index 9f17ac0aec..dac8aff562 100644 --- a/app/src/main/res/layout/fragment_profile.xml +++ b/app/src/main/res/layout/fragment_profile.xml @@ -259,360 +259,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - From 56958af8191113132752312b2301f93e72b2e08a Mon Sep 17 00:00:00 2001 From: Mateusz Konieczny Date: Wed, 13 Jul 2022 12:45:39 +0200 Subject: [PATCH 31/39] use drawArc --- .../screens/user/profile/ProfileFragment.kt | 17 +++++++++--- .../res/drawable/ic_laurel_leaf_rotated.xml | 7 ----- .../laurel_wreath/laurel_leaf_rotated.svg | 27 +++++-------------- .../laurel_wreath/laurel_leaf_stalk.svg | 25 ----------------- 4 files changed, 19 insertions(+), 57 deletions(-) delete mode 100644 res/graphics/laurel_wreath/laurel_leaf_stalk.svg diff --git a/app/src/main/java/de/westnordost/streetcomplete/screens/user/profile/ProfileFragment.kt b/app/src/main/java/de/westnordost/streetcomplete/screens/user/profile/ProfileFragment.kt index 9e7d25b58a..b27a28a23b 100644 --- a/app/src/main/java/de/westnordost/streetcomplete/screens/user/profile/ProfileFragment.kt +++ b/app/src/main/java/de/westnordost/streetcomplete/screens/user/profile/ProfileFragment.kt @@ -9,6 +9,7 @@ import android.graphics.Canvas import android.graphics.ColorFilter import android.graphics.Paint import android.graphics.PixelFormat +import android.graphics.RectF import android.graphics.drawable.Drawable import android.os.Bundle import android.view.View @@ -198,16 +199,24 @@ class ProfileFragment : Fragment(R.layout.fragment_profile) { val circleCenterX = canvasWidth / 2f val shownSegments = ((regularSegmentCount - 1) * percentageOfGrowth / 100).toInt() val locationBetweenCenterAndEdge = 0.78f - for (i in 0..shownSegments) { + for (i in 1..shownSegments) { // https://developer.android.com/reference/kotlin/androidx/core/graphics/package-summary#(android.graphics.Canvas).withRotation(kotlin.Float,kotlin.Float,kotlin.Float,kotlin.Function1) var bitmap = laurelLeafOnStalk.bitmap if (i == shownSegments) { bitmap = horizontalEndingLeaf.bitmap - } else if (i == 0 ) { - bitmap = laurelStalk.bitmap } - + val stalkPaint = Paint() + stalkPaint.isAntiAlias = true + stalkPaint.setARGB(255, 0, 106, 0) + stalkPaint.style = Paint.Style.STROKE + stalkPaint.strokeWidth = 3f + val stalkCircleSize = circleRadius * locationBetweenCenterAndEdge * 1.1f + val frame = RectF(canvasWidth.toFloat() / 2 - stalkCircleSize, canvasHeight.toFloat() / 2 - stalkCircleSize, canvasWidth.toFloat() / 2 + stalkCircleSize, canvasHeight.toFloat() / 2 + stalkCircleSize) + val stalkLengthInDegrees = 180f * percentageOfGrowth / 100f - 10f + canvas.drawArc(frame, 90f, stalkLengthInDegrees, false, stalkPaint ) + val upperLimitOfRightStalk = (90f - stalkLengthInDegrees + 360) % 360 + canvas.drawArc(frame, upperLimitOfRightStalk, stalkLengthInDegrees, false, stalkPaint ) // left side canvas.withRotation(i * 180.0f / regularSegmentCount, canvasWidth / 2f, canvasHeight / 2f) { // drawBitmap takes corner of the bitmap, we care about centering segments diff --git a/app/src/main/res/drawable/ic_laurel_leaf_rotated.xml b/app/src/main/res/drawable/ic_laurel_leaf_rotated.xml index aacbebf520..62a116f555 100644 --- a/app/src/main/res/drawable/ic_laurel_leaf_rotated.xml +++ b/app/src/main/res/drawable/ic_laurel_leaf_rotated.xml @@ -10,11 +10,4 @@ android:fillColor="#006a00" android:strokeColor="#00000000" android:strokeLineCap="butt"/> - diff --git a/res/graphics/laurel_wreath/laurel_leaf_rotated.svg b/res/graphics/laurel_wreath/laurel_leaf_rotated.svg index ad967b3b52..7822fa1ca9 100644 --- a/res/graphics/laurel_wreath/laurel_leaf_rotated.svg +++ b/res/graphics/laurel_wreath/laurel_leaf_rotated.svg @@ -12,26 +12,11 @@ - - - - - - + id="g1206" + transform="matrix(1.3537913,0,0,1.3537913,111.99498,24.530068)"> + diff --git a/res/graphics/laurel_wreath/laurel_leaf_stalk.svg b/res/graphics/laurel_wreath/laurel_leaf_stalk.svg deleted file mode 100644 index aef17dd800..0000000000 --- a/res/graphics/laurel_wreath/laurel_leaf_stalk.svg +++ /dev/null @@ -1,25 +0,0 @@ - - - - - - - - - From 6d342302928f9b6e45b5bba0a217f7866f242f2a Mon Sep 17 00:00:00 2001 From: Mateusz Konieczny Date: Wed, 13 Jul 2022 17:24:10 +0200 Subject: [PATCH 32/39] move LaurelWreath to a separate file --- .../screens/user/profile/ProfileFragment.kt | 93 +----------------- .../streetcomplete/view/LaurelWreath.kt | 94 +++++++++++++++++++ 2 files changed, 95 insertions(+), 92 deletions(-) create mode 100644 app/src/main/java/de/westnordost/streetcomplete/view/LaurelWreath.kt diff --git a/app/src/main/java/de/westnordost/streetcomplete/screens/user/profile/ProfileFragment.kt b/app/src/main/java/de/westnordost/streetcomplete/screens/user/profile/ProfileFragment.kt index b27a28a23b..d0cab30b04 100644 --- a/app/src/main/java/de/westnordost/streetcomplete/screens/user/profile/ProfileFragment.kt +++ b/app/src/main/java/de/westnordost/streetcomplete/screens/user/profile/ProfileFragment.kt @@ -2,18 +2,10 @@ package de.westnordost.streetcomplete.screens.user.profile import android.content.Context import android.content.Intent -import android.content.res.Resources import android.graphics.Bitmap import android.graphics.BitmapFactory -import android.graphics.Canvas -import android.graphics.ColorFilter -import android.graphics.Paint -import android.graphics.PixelFormat -import android.graphics.RectF -import android.graphics.drawable.Drawable import android.os.Bundle import android.view.View -import androidx.core.graphics.withRotation import androidx.core.net.toUri import androidx.core.view.isGone import androidx.fragment.app.Fragment @@ -25,12 +17,11 @@ import de.westnordost.streetcomplete.data.user.UserUpdater import de.westnordost.streetcomplete.data.user.achievements.AchievementsSource import de.westnordost.streetcomplete.data.user.statistics.StatisticsSource import de.westnordost.streetcomplete.databinding.FragmentProfileBinding -import de.westnordost.streetcomplete.ktx.flipHorizontally import de.westnordost.streetcomplete.util.ktx.createBitmap -import de.westnordost.streetcomplete.util.ktx.getBitmapDrawable import de.westnordost.streetcomplete.util.ktx.tryStartActivity import de.westnordost.streetcomplete.util.ktx.viewLifecycleScope import de.westnordost.streetcomplete.util.viewBinding +import de.westnordost.streetcomplete.view.LaurelWreath import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.launch import kotlinx.coroutines.withContext @@ -40,7 +31,6 @@ import java.io.File import java.lang.Math.max import java.lang.Math.min import java.util.Locale -import kotlin.random.Random /** Shows the user profile: username, avatar, star count and a hint regarding unpublished changes */ class ProfileFragment : Fragment(R.layout.fragment_profile) { @@ -163,87 +153,6 @@ class ProfileFragment : Fragment(R.layout.fragment_profile) { binding.daysActiveText.background = LaurelWreath(resources, min(daysActive + 20, 100)) } - /* - Drawable providing decoration, suitable for a circular background - 100 and more: fully grown wreath with all pretty elements - 99 to 10: may be losing elements as it gets smaller - below: no decorative styling at all - */ - class LaurelWreath(val resources: Resources, private val percentageOfGrowth: Int) : Drawable() { - val laurelLeafOnStalk = resources.getBitmapDrawable(R.drawable.ic_laurel_leaf_rotated) - val laurelStalk = resources.getBitmapDrawable(R.drawable.ic_laurel_leaf_stalk) - val horizontalEndingLeaf = resources.getBitmapDrawable(R.drawable.ic_laurel_leaf_ending) - - private val antiAliasPaint: Paint = Paint().apply { - isAntiAlias = true - isFilterBitmap = true - } - - override fun draw(canvas: Canvas) { - // Get the drawable's bounds - val canvasWidth: Int = bounds.width() - val canvasHeight: Int = bounds.height() - val circleRadius: Float = min(canvasWidth, canvasHeight).toFloat() / 2f - - val niceSubtleGreen: Paint = Paint().apply { setARGB(255, 152, 184, 126) } - canvas.drawCircle((canvasWidth / 2).toFloat(), (canvasHeight / 2).toFloat(), circleRadius, niceSubtleGreen) - - if (percentageOfGrowth < 10) { - return - } - - val decorationSegmentImageWidth = laurelLeafOnStalk.intrinsicWidth // width is the same as intrinsicWidth - - val regularSegmentCount = 11f - - val circleCenterX = canvasWidth / 2f - val shownSegments = ((regularSegmentCount - 1) * percentageOfGrowth / 100).toInt() - val locationBetweenCenterAndEdge = 0.78f - for (i in 1..shownSegments) { - // https://developer.android.com/reference/kotlin/androidx/core/graphics/package-summary#(android.graphics.Canvas).withRotation(kotlin.Float,kotlin.Float,kotlin.Float,kotlin.Function1) - - var bitmap = laurelLeafOnStalk.bitmap - if (i == shownSegments) { - bitmap = horizontalEndingLeaf.bitmap - } - val stalkPaint = Paint() - stalkPaint.isAntiAlias = true - stalkPaint.setARGB(255, 0, 106, 0) - stalkPaint.style = Paint.Style.STROKE - stalkPaint.strokeWidth = 3f - val stalkCircleSize = circleRadius * locationBetweenCenterAndEdge * 1.1f - val frame = RectF(canvasWidth.toFloat() / 2 - stalkCircleSize, canvasHeight.toFloat() / 2 - stalkCircleSize, canvasWidth.toFloat() / 2 + stalkCircleSize, canvasHeight.toFloat() / 2 + stalkCircleSize) - val stalkLengthInDegrees = 180f * percentageOfGrowth / 100f - 10f - canvas.drawArc(frame, 90f, stalkLengthInDegrees, false, stalkPaint ) - val upperLimitOfRightStalk = (90f - stalkLengthInDegrees + 360) % 360 - canvas.drawArc(frame, upperLimitOfRightStalk, stalkLengthInDegrees, false, stalkPaint ) - // left side - canvas.withRotation(i * 180.0f / regularSegmentCount, canvasWidth / 2f, canvasHeight / 2f) { - // drawBitmap takes corner of the bitmap, we care about centering segments - canvas.drawBitmap(bitmap, circleCenterX - decorationSegmentImageWidth / 2f, canvasHeight * locationBetweenCenterAndEdge, antiAliasPaint) - } - - // right side - val flippedBitmap = bitmap.flipHorizontally() - canvas.withRotation(-i * 180.0f / regularSegmentCount, canvasWidth / 2f, canvasHeight / 2f) { - canvas.drawBitmap(flippedBitmap, circleCenterX - decorationSegmentImageWidth / 2f, canvasHeight * locationBetweenCenterAndEdge, antiAliasPaint) - } - } - } - - override fun setAlpha(alpha: Int) { - // This method is required - } - - override fun setColorFilter(colorFilter: ColorFilter?) { - // This method is required - } - - override fun getOpacity(): Int = - // Must be PixelFormat.UNKNOWN, TRANSLUCENT, TRANSPARENT, or OPAQUE - PixelFormat.OPAQUE - } - private fun updateGlobalRankText() { // note that global rank merges multiple people with the same score // in case that 1000 people made 11 edits all will have the same rank (say, 3814) diff --git a/app/src/main/java/de/westnordost/streetcomplete/view/LaurelWreath.kt b/app/src/main/java/de/westnordost/streetcomplete/view/LaurelWreath.kt new file mode 100644 index 0000000000..44edcb8b1a --- /dev/null +++ b/app/src/main/java/de/westnordost/streetcomplete/view/LaurelWreath.kt @@ -0,0 +1,94 @@ +package de.westnordost.streetcomplete.view + +import android.content.res.Resources +import android.graphics.Canvas +import android.graphics.ColorFilter +import android.graphics.Paint +import android.graphics.PixelFormat +import android.graphics.RectF +import android.graphics.drawable.Drawable +import androidx.core.graphics.withRotation +import de.westnordost.streetcomplete.R +import de.westnordost.streetcomplete.ktx.flipHorizontally +import de.westnordost.streetcomplete.util.ktx.getBitmapDrawable + +/* +Drawable providing decoration, suitable for a circular background +100 and more: fully grown wreath with all pretty elements +99 to 10: may be losing elements as it gets smaller +below: no decorative styling at all + */ +class LaurelWreath(val resources: Resources, private val percentageOfGrowth: Int) : Drawable() { + val laurelLeafOnStalk = resources.getBitmapDrawable(R.drawable.ic_laurel_leaf_rotated) + val laurelStalk = resources.getBitmapDrawable(R.drawable.ic_laurel_leaf_stalk) + val horizontalEndingLeaf = resources.getBitmapDrawable(R.drawable.ic_laurel_leaf_ending) + + private val antiAliasPaint: Paint = Paint().apply { + isAntiAlias = true + isFilterBitmap = true + } + + override fun draw(canvas: Canvas) { + // Get the drawable's bounds + val canvasWidth: Int = bounds.width() + val canvasHeight: Int = bounds.height() + val circleRadius: Float = Math.min(canvasWidth, canvasHeight).toFloat() / 2f + + val niceSubtleGreen: Paint = Paint().apply { setARGB(255, 152, 184, 126) } + canvas.drawCircle((canvasWidth / 2).toFloat(), (canvasHeight / 2).toFloat(), circleRadius, niceSubtleGreen) + + if (percentageOfGrowth < 10) { + return + } + + val decorationSegmentImageWidth = laurelLeafOnStalk.intrinsicWidth // width is the same as intrinsicWidth + + val regularSegmentCount = 11f + + val circleCenterX = canvasWidth / 2f + val shownSegments = ((regularSegmentCount - 1) * percentageOfGrowth / 100).toInt() + val locationBetweenCenterAndEdge = 0.78f + for (i in 1..shownSegments) { + // https://developer.android.com/reference/kotlin/androidx/core/graphics/package-summary#(android.graphics.Canvas).withRotation(kotlin.Float,kotlin.Float,kotlin.Float,kotlin.Function1) + + var bitmap = laurelLeafOnStalk.bitmap + if (i == shownSegments) { + bitmap = horizontalEndingLeaf.bitmap + } + val stalkPaint = Paint() + stalkPaint.isAntiAlias = true + stalkPaint.setARGB(255, 0, 106, 0) + stalkPaint.style = Paint.Style.STROKE + stalkPaint.strokeWidth = 3f + val stalkCircleSize = circleRadius * locationBetweenCenterAndEdge * 1.1f + val frame = RectF(canvasWidth.toFloat() / 2 - stalkCircleSize, canvasHeight.toFloat() / 2 - stalkCircleSize, canvasWidth.toFloat() / 2 + stalkCircleSize, canvasHeight.toFloat() / 2 + stalkCircleSize) + val stalkLengthInDegrees = 180f * percentageOfGrowth / 100f - 10f + canvas.drawArc(frame, 90f, stalkLengthInDegrees, false, stalkPaint ) + val upperLimitOfRightStalk = (90f - stalkLengthInDegrees + 360) % 360 + canvas.drawArc(frame, upperLimitOfRightStalk, stalkLengthInDegrees, false, stalkPaint ) + // left side + canvas.withRotation(i * 180.0f / regularSegmentCount, canvasWidth / 2f, canvasHeight / 2f) { + // drawBitmap takes corner of the bitmap, we care about centering segments + canvas.drawBitmap(bitmap, circleCenterX - decorationSegmentImageWidth / 2f, canvasHeight * locationBetweenCenterAndEdge, antiAliasPaint) + } + + // right side + val flippedBitmap = bitmap.flipHorizontally() + canvas.withRotation(-i * 180.0f / regularSegmentCount, canvasWidth / 2f, canvasHeight / 2f) { + canvas.drawBitmap(flippedBitmap, circleCenterX - decorationSegmentImageWidth / 2f, canvasHeight * locationBetweenCenterAndEdge, antiAliasPaint) + } + } + } + + override fun setAlpha(alpha: Int) { + // This method is required + } + + override fun setColorFilter(colorFilter: ColorFilter?) { + // This method is required + } + + override fun getOpacity(): Int = + // Must be PixelFormat.UNKNOWN, TRANSLUCENT, TRANSPARENT, or OPAQUE + PixelFormat.OPAQUE +} From ca8a9b98cda5e7986960a272d6736305bc47a10e Mon Sep 17 00:00:00 2001 From: Mateusz Konieczny Date: Sat, 22 Oct 2022 14:13:46 +0200 Subject: [PATCH 33/39] set to private as needed --- .../java/de/westnordost/streetcomplete/view/LaurelWreath.kt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/de/westnordost/streetcomplete/view/LaurelWreath.kt b/app/src/main/java/de/westnordost/streetcomplete/view/LaurelWreath.kt index 44edcb8b1a..b6815f9cb4 100644 --- a/app/src/main/java/de/westnordost/streetcomplete/view/LaurelWreath.kt +++ b/app/src/main/java/de/westnordost/streetcomplete/view/LaurelWreath.kt @@ -19,9 +19,9 @@ Drawable providing decoration, suitable for a circular background below: no decorative styling at all */ class LaurelWreath(val resources: Resources, private val percentageOfGrowth: Int) : Drawable() { - val laurelLeafOnStalk = resources.getBitmapDrawable(R.drawable.ic_laurel_leaf_rotated) - val laurelStalk = resources.getBitmapDrawable(R.drawable.ic_laurel_leaf_stalk) - val horizontalEndingLeaf = resources.getBitmapDrawable(R.drawable.ic_laurel_leaf_ending) + private val laurelLeafOnStalk = resources.getBitmapDrawable(R.drawable.ic_laurel_leaf_rotated) + private val laurelStalk = resources.getBitmapDrawable(R.drawable.ic_laurel_leaf_stalk) + private val horizontalEndingLeaf = resources.getBitmapDrawable(R.drawable.ic_laurel_leaf_ending) private val antiAliasPaint: Paint = Paint().apply { isAntiAlias = true From 4d2cbbe1c43bbf6d08a8d2e9b82e83f05f131156 Mon Sep 17 00:00:00 2001 From: Mateusz Konieczny Date: Sat, 22 Oct 2022 14:14:37 +0200 Subject: [PATCH 34/39] stalk is drawn with arc --- .../main/java/de/westnordost/streetcomplete/view/LaurelWreath.kt | 1 - 1 file changed, 1 deletion(-) diff --git a/app/src/main/java/de/westnordost/streetcomplete/view/LaurelWreath.kt b/app/src/main/java/de/westnordost/streetcomplete/view/LaurelWreath.kt index b6815f9cb4..68648915c9 100644 --- a/app/src/main/java/de/westnordost/streetcomplete/view/LaurelWreath.kt +++ b/app/src/main/java/de/westnordost/streetcomplete/view/LaurelWreath.kt @@ -20,7 +20,6 @@ below: no decorative styling at all */ class LaurelWreath(val resources: Resources, private val percentageOfGrowth: Int) : Drawable() { private val laurelLeafOnStalk = resources.getBitmapDrawable(R.drawable.ic_laurel_leaf_rotated) - private val laurelStalk = resources.getBitmapDrawable(R.drawable.ic_laurel_leaf_stalk) private val horizontalEndingLeaf = resources.getBitmapDrawable(R.drawable.ic_laurel_leaf_ending) private val antiAliasPaint: Paint = Paint().apply { From 6625df7abd33b1d97f167b401ab3954551c572f7 Mon Sep 17 00:00:00 2001 From: Mateusz Konieczny Date: Sat, 22 Oct 2022 14:19:44 +0200 Subject: [PATCH 35/39] cosmetic rename --- .../screens/user/profile/ProfileFragment.kt | 10 +++++----- .../view/{LaurelWreath.kt => LaurelWreathDrawable.kt} | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) rename app/src/main/java/de/westnordost/streetcomplete/view/{LaurelWreath.kt => LaurelWreathDrawable.kt} (97%) diff --git a/app/src/main/java/de/westnordost/streetcomplete/screens/user/profile/ProfileFragment.kt b/app/src/main/java/de/westnordost/streetcomplete/screens/user/profile/ProfileFragment.kt index d0cab30b04..7bf5e9f0d5 100644 --- a/app/src/main/java/de/westnordost/streetcomplete/screens/user/profile/ProfileFragment.kt +++ b/app/src/main/java/de/westnordost/streetcomplete/screens/user/profile/ProfileFragment.kt @@ -21,7 +21,7 @@ import de.westnordost.streetcomplete.util.ktx.createBitmap import de.westnordost.streetcomplete.util.ktx.tryStartActivity import de.westnordost.streetcomplete.util.ktx.viewLifecycleScope import de.westnordost.streetcomplete.util.viewBinding -import de.westnordost.streetcomplete.view.LaurelWreath +import de.westnordost.streetcomplete.view.LaurelWreathDrawable import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.launch import kotlinx.coroutines.withContext @@ -150,7 +150,7 @@ class ProfileFragment : Fragment(R.layout.fragment_profile) { val daysActive = statisticsSource.daysActive binding.daysActiveContainer.isGone = daysActive <= 0 binding.daysActiveText.text = daysActive.toString() - binding.daysActiveText.background = LaurelWreath(resources, min(daysActive + 20, 100)) + binding.daysActiveText.background = LaurelWreathDrawable(resources, min(daysActive + 20, 100)) } private fun updateGlobalRankText() { @@ -164,7 +164,7 @@ class ProfileFragment : Fragment(R.layout.fragment_profile) { val rankEnoughToStartGrowingReward = 3800 val ranksAboveThreshold = max(rankEnoughToStartGrowingReward - rank, 0) val scaledRank = (ranksAboveThreshold * 100.0 / (rankEnoughToStartGrowingReward - rankEnoughForFullMarks)).toInt() - binding.globalRankText.background = LaurelWreath(resources, min(scaledRank, 100)) + binding.globalRankText.background = LaurelWreathDrawable(resources, min(scaledRank, 100)) } private suspend fun updateLocalRankText() { @@ -179,7 +179,7 @@ class ProfileFragment : Fragment(R.layout.fragment_profile) { if (shouldShow) { binding.localRankText.text = "#${statistics.rank}" binding.localRankLabel.text = getString(R.string.user_profile_local_rank, countryLocale.displayCountry) - binding.localRankText.background = LaurelWreath(resources, min(100 - statistics.rank!!, 100)) + binding.localRankText.background = LaurelWreathDrawable(resources, min(100 - statistics.rank!!, 100)) } } } @@ -188,7 +188,7 @@ class ProfileFragment : Fragment(R.layout.fragment_profile) { val levels = withContext(Dispatchers.IO) { achievementsSource.getAchievements().sumOf { it.second } } binding.achievementLevelsContainer.isGone = levels <= 0 binding.achievementLevelsText.text = "$levels" - binding.achievementLevelsText.background = LaurelWreath(resources, min(levels / 2, 100)) + binding.achievementLevelsText.background = LaurelWreathDrawable(resources, min(levels / 2, 100)) } private fun openUrl(url: String): Boolean { diff --git a/app/src/main/java/de/westnordost/streetcomplete/view/LaurelWreath.kt b/app/src/main/java/de/westnordost/streetcomplete/view/LaurelWreathDrawable.kt similarity index 97% rename from app/src/main/java/de/westnordost/streetcomplete/view/LaurelWreath.kt rename to app/src/main/java/de/westnordost/streetcomplete/view/LaurelWreathDrawable.kt index 68648915c9..40c234b665 100644 --- a/app/src/main/java/de/westnordost/streetcomplete/view/LaurelWreath.kt +++ b/app/src/main/java/de/westnordost/streetcomplete/view/LaurelWreathDrawable.kt @@ -18,7 +18,7 @@ Drawable providing decoration, suitable for a circular background 99 to 10: may be losing elements as it gets smaller below: no decorative styling at all */ -class LaurelWreath(val resources: Resources, private val percentageOfGrowth: Int) : Drawable() { +class LaurelWreathDrawable(val resources: Resources, private val percentageOfGrowth: Int) : Drawable() { private val laurelLeafOnStalk = resources.getBitmapDrawable(R.drawable.ic_laurel_leaf_rotated) private val horizontalEndingLeaf = resources.getBitmapDrawable(R.drawable.ic_laurel_leaf_ending) From 33619fb09696cfd35e4036787a3a05d2222b144e Mon Sep 17 00:00:00 2001 From: Mateusz Konieczny Date: Sat, 22 Oct 2022 19:07:38 +0200 Subject: [PATCH 36/39] refactor, subtler stalk, draw arc once --- .../view/LaurelWreathDrawable.kt | 29 ++++++++++--------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/app/src/main/java/de/westnordost/streetcomplete/view/LaurelWreathDrawable.kt b/app/src/main/java/de/westnordost/streetcomplete/view/LaurelWreathDrawable.kt index 40c234b665..5b181a0a79 100644 --- a/app/src/main/java/de/westnordost/streetcomplete/view/LaurelWreathDrawable.kt +++ b/app/src/main/java/de/westnordost/streetcomplete/view/LaurelWreathDrawable.kt @@ -21,6 +21,7 @@ below: no decorative styling at all class LaurelWreathDrawable(val resources: Resources, private val percentageOfGrowth: Int) : Drawable() { private val laurelLeafOnStalk = resources.getBitmapDrawable(R.drawable.ic_laurel_leaf_rotated) private val horizontalEndingLeaf = resources.getBitmapDrawable(R.drawable.ic_laurel_leaf_ending) + private val niceSubtleGreen: Paint = Paint().apply { setARGB(255, 152, 184, 126) } private val antiAliasPaint: Paint = Paint().apply { isAntiAlias = true @@ -28,12 +29,10 @@ class LaurelWreathDrawable(val resources: Resources, private val percentageOfGro } override fun draw(canvas: Canvas) { - // Get the drawable's bounds val canvasWidth: Int = bounds.width() val canvasHeight: Int = bounds.height() val circleRadius: Float = Math.min(canvasWidth, canvasHeight).toFloat() / 2f - val niceSubtleGreen: Paint = Paint().apply { setARGB(255, 152, 184, 126) } canvas.drawCircle((canvasWidth / 2).toFloat(), (canvasHeight / 2).toFloat(), circleRadius, niceSubtleGreen) if (percentageOfGrowth < 10) { @@ -47,24 +46,26 @@ class LaurelWreathDrawable(val resources: Resources, private val percentageOfGro val circleCenterX = canvasWidth / 2f val shownSegments = ((regularSegmentCount - 1) * percentageOfGrowth / 100).toInt() val locationBetweenCenterAndEdge = 0.78f + + val stalkPaint = Paint() + stalkPaint.isAntiAlias = true + stalkPaint.setARGB(255, 0, 106, 0) + stalkPaint.style = Paint.Style.STROKE + stalkPaint.strokeWidth = 2.5f + val stalkCircleSize = circleRadius * locationBetweenCenterAndEdge * 1.1f + val frame = RectF(canvasWidth.toFloat() / 2 - stalkCircleSize, canvasHeight.toFloat() / 2 - stalkCircleSize, canvasWidth.toFloat() / 2 + stalkCircleSize, canvasHeight.toFloat() / 2 + stalkCircleSize) + val stalkLengthInDegrees = 180f * percentageOfGrowth / 100f - 15f + canvas.drawArc(frame, 90f, stalkLengthInDegrees, false, stalkPaint ) + val upperLimitOfRightStalk = (90f - stalkLengthInDegrees + 360) % 360 + canvas.drawArc(frame, upperLimitOfRightStalk, stalkLengthInDegrees, false, stalkPaint ) + for (i in 1..shownSegments) { // https://developer.android.com/reference/kotlin/androidx/core/graphics/package-summary#(android.graphics.Canvas).withRotation(kotlin.Float,kotlin.Float,kotlin.Float,kotlin.Function1) - var bitmap = laurelLeafOnStalk.bitmap if (i == shownSegments) { bitmap = horizontalEndingLeaf.bitmap } - val stalkPaint = Paint() - stalkPaint.isAntiAlias = true - stalkPaint.setARGB(255, 0, 106, 0) - stalkPaint.style = Paint.Style.STROKE - stalkPaint.strokeWidth = 3f - val stalkCircleSize = circleRadius * locationBetweenCenterAndEdge * 1.1f - val frame = RectF(canvasWidth.toFloat() / 2 - stalkCircleSize, canvasHeight.toFloat() / 2 - stalkCircleSize, canvasWidth.toFloat() / 2 + stalkCircleSize, canvasHeight.toFloat() / 2 + stalkCircleSize) - val stalkLengthInDegrees = 180f * percentageOfGrowth / 100f - 10f - canvas.drawArc(frame, 90f, stalkLengthInDegrees, false, stalkPaint ) - val upperLimitOfRightStalk = (90f - stalkLengthInDegrees + 360) % 360 - canvas.drawArc(frame, upperLimitOfRightStalk, stalkLengthInDegrees, false, stalkPaint ) + // left side canvas.withRotation(i * 180.0f / regularSegmentCount, canvasWidth / 2f, canvasHeight / 2f) { // drawBitmap takes corner of the bitmap, we care about centering segments From 47127286ff8aaf97704b0c68120bf25bfd03db64 Mon Sep 17 00:00:00 2001 From: Mateusz Konieczny Date: Sat, 22 Oct 2022 19:09:19 +0200 Subject: [PATCH 37/39] switch to double-sided leaf --- .../view/LaurelWreathDrawable.kt | 2 +- .../res/drawable/ic_laurel_leaf_ending.xml | 4 ++-- .../res/drawable/ic_laurel_leaf_rotated.xml | 9 ++++++- .../laurel_wreath/laurel_leaf_ending.svg | 6 ++--- .../laurel_wreath/laurel_leaf_rotated.svg | 24 ++++++++++++++----- 5 files changed, 32 insertions(+), 13 deletions(-) diff --git a/app/src/main/java/de/westnordost/streetcomplete/view/LaurelWreathDrawable.kt b/app/src/main/java/de/westnordost/streetcomplete/view/LaurelWreathDrawable.kt index 5b181a0a79..1799ece5af 100644 --- a/app/src/main/java/de/westnordost/streetcomplete/view/LaurelWreathDrawable.kt +++ b/app/src/main/java/de/westnordost/streetcomplete/view/LaurelWreathDrawable.kt @@ -52,7 +52,7 @@ class LaurelWreathDrawable(val resources: Resources, private val percentageOfGro stalkPaint.setARGB(255, 0, 106, 0) stalkPaint.style = Paint.Style.STROKE stalkPaint.strokeWidth = 2.5f - val stalkCircleSize = circleRadius * locationBetweenCenterAndEdge * 1.1f + val stalkCircleSize = circleRadius * locationBetweenCenterAndEdge * 0.96f val frame = RectF(canvasWidth.toFloat() / 2 - stalkCircleSize, canvasHeight.toFloat() / 2 - stalkCircleSize, canvasWidth.toFloat() / 2 + stalkCircleSize, canvasHeight.toFloat() / 2 + stalkCircleSize) val stalkLengthInDegrees = 180f * percentageOfGrowth / 100f - 15f canvas.drawArc(frame, 90f, stalkLengthInDegrees, false, stalkPaint ) diff --git a/app/src/main/res/drawable/ic_laurel_leaf_ending.xml b/app/src/main/res/drawable/ic_laurel_leaf_ending.xml index 584f27c970..78dc60110e 100644 --- a/app/src/main/res/drawable/ic_laurel_leaf_ending.xml +++ b/app/src/main/res/drawable/ic_laurel_leaf_ending.xml @@ -5,13 +5,13 @@ android:viewportHeight="14.774"> + + transform="translate(82.870944,16.405536)"> + id="path959-6-6" /> diff --git a/res/graphics/laurel_wreath/laurel_leaf_rotated.svg b/res/graphics/laurel_wreath/laurel_leaf_rotated.svg index 7822fa1ca9..4d060ccd0f 100644 --- a/res/graphics/laurel_wreath/laurel_leaf_rotated.svg +++ b/res/graphics/laurel_wreath/laurel_leaf_rotated.svg @@ -12,11 +12,23 @@ - + id="g46517" + transform="matrix(1,0,0,0.616835,0,-0.00538884)"> + + + + + + From f8cf200b6b058b557efab69b1f7eb916b27889f2 Mon Sep 17 00:00:00 2001 From: Mateusz Konieczny Date: Sun, 23 Oct 2022 17:55:04 +0200 Subject: [PATCH 38/39] stop showing stalk of laurel wreath I like it, others do not like it :( --- .../streetcomplete/view/LaurelWreathDrawable.kt | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/app/src/main/java/de/westnordost/streetcomplete/view/LaurelWreathDrawable.kt b/app/src/main/java/de/westnordost/streetcomplete/view/LaurelWreathDrawable.kt index 1799ece5af..216712ba20 100644 --- a/app/src/main/java/de/westnordost/streetcomplete/view/LaurelWreathDrawable.kt +++ b/app/src/main/java/de/westnordost/streetcomplete/view/LaurelWreathDrawable.kt @@ -5,7 +5,6 @@ import android.graphics.Canvas import android.graphics.ColorFilter import android.graphics.Paint import android.graphics.PixelFormat -import android.graphics.RectF import android.graphics.drawable.Drawable import androidx.core.graphics.withRotation import de.westnordost.streetcomplete.R @@ -47,18 +46,6 @@ class LaurelWreathDrawable(val resources: Resources, private val percentageOfGro val shownSegments = ((regularSegmentCount - 1) * percentageOfGrowth / 100).toInt() val locationBetweenCenterAndEdge = 0.78f - val stalkPaint = Paint() - stalkPaint.isAntiAlias = true - stalkPaint.setARGB(255, 0, 106, 0) - stalkPaint.style = Paint.Style.STROKE - stalkPaint.strokeWidth = 2.5f - val stalkCircleSize = circleRadius * locationBetweenCenterAndEdge * 0.96f - val frame = RectF(canvasWidth.toFloat() / 2 - stalkCircleSize, canvasHeight.toFloat() / 2 - stalkCircleSize, canvasWidth.toFloat() / 2 + stalkCircleSize, canvasHeight.toFloat() / 2 + stalkCircleSize) - val stalkLengthInDegrees = 180f * percentageOfGrowth / 100f - 15f - canvas.drawArc(frame, 90f, stalkLengthInDegrees, false, stalkPaint ) - val upperLimitOfRightStalk = (90f - stalkLengthInDegrees + 360) % 360 - canvas.drawArc(frame, upperLimitOfRightStalk, stalkLengthInDegrees, false, stalkPaint ) - for (i in 1..shownSegments) { // https://developer.android.com/reference/kotlin/androidx/core/graphics/package-summary#(android.graphics.Canvas).withRotation(kotlin.Float,kotlin.Float,kotlin.Float,kotlin.Function1) var bitmap = laurelLeafOnStalk.bitmap From 91a1e78eda50992bad7a3ce4f4b2bbc236aa82a5 Mon Sep 17 00:00:00 2001 From: Mateusz Konieczny Date: Mon, 24 Oct 2022 19:14:33 +0200 Subject: [PATCH 39/39] better names --- .../view/LaurelWreathDrawable.kt | 20 +++++++++---------- ...af_rotated.xml => ic_laurel_leaf_pair.xml} | 0 ...af_rotated.svg => ic_laurel_leaf_pair.svg} | 0 3 files changed, 10 insertions(+), 10 deletions(-) rename app/src/main/res/drawable/{ic_laurel_leaf_rotated.xml => ic_laurel_leaf_pair.xml} (100%) rename res/graphics/laurel_wreath/{laurel_leaf_rotated.svg => ic_laurel_leaf_pair.svg} (100%) diff --git a/app/src/main/java/de/westnordost/streetcomplete/view/LaurelWreathDrawable.kt b/app/src/main/java/de/westnordost/streetcomplete/view/LaurelWreathDrawable.kt index 216712ba20..db612443e2 100644 --- a/app/src/main/java/de/westnordost/streetcomplete/view/LaurelWreathDrawable.kt +++ b/app/src/main/java/de/westnordost/streetcomplete/view/LaurelWreathDrawable.kt @@ -18,7 +18,7 @@ Drawable providing decoration, suitable for a circular background below: no decorative styling at all */ class LaurelWreathDrawable(val resources: Resources, private val percentageOfGrowth: Int) : Drawable() { - private val laurelLeafOnStalk = resources.getBitmapDrawable(R.drawable.ic_laurel_leaf_rotated) + private val pairOflaurelLeafs = resources.getBitmapDrawable(R.drawable.ic_laurel_leaf_pair) private val horizontalEndingLeaf = resources.getBitmapDrawable(R.drawable.ic_laurel_leaf_ending) private val niceSubtleGreen: Paint = Paint().apply { setARGB(255, 152, 184, 126) } @@ -38,31 +38,31 @@ class LaurelWreathDrawable(val resources: Resources, private val percentageOfGro return } - val decorationSegmentImageWidth = laurelLeafOnStalk.intrinsicWidth // width is the same as intrinsicWidth + val decorationSegmentImageWidth = pairOflaurelLeafs.intrinsicWidth // width is the same as intrinsicWidth - val regularSegmentCount = 11f + val maximumDecorationSegmentCount = 11f val circleCenterX = canvasWidth / 2f - val shownSegments = ((regularSegmentCount - 1) * percentageOfGrowth / 100).toInt() - val locationBetweenCenterAndEdge = 0.78f + val shownSegments = ((maximumDecorationSegmentCount - 1) * percentageOfGrowth / 100).toInt() + val howDistantIsDecorationFromCircleCenter = 0.78f for (i in 1..shownSegments) { // https://developer.android.com/reference/kotlin/androidx/core/graphics/package-summary#(android.graphics.Canvas).withRotation(kotlin.Float,kotlin.Float,kotlin.Float,kotlin.Function1) - var bitmap = laurelLeafOnStalk.bitmap + var bitmap = pairOflaurelLeafs.bitmap if (i == shownSegments) { bitmap = horizontalEndingLeaf.bitmap } // left side - canvas.withRotation(i * 180.0f / regularSegmentCount, canvasWidth / 2f, canvasHeight / 2f) { + canvas.withRotation(i * 180.0f / maximumDecorationSegmentCount, canvasWidth / 2f, canvasHeight / 2f) { // drawBitmap takes corner of the bitmap, we care about centering segments - canvas.drawBitmap(bitmap, circleCenterX - decorationSegmentImageWidth / 2f, canvasHeight * locationBetweenCenterAndEdge, antiAliasPaint) + canvas.drawBitmap(bitmap, circleCenterX - decorationSegmentImageWidth / 2f, canvasHeight * howDistantIsDecorationFromCircleCenter, antiAliasPaint) } // right side val flippedBitmap = bitmap.flipHorizontally() - canvas.withRotation(-i * 180.0f / regularSegmentCount, canvasWidth / 2f, canvasHeight / 2f) { - canvas.drawBitmap(flippedBitmap, circleCenterX - decorationSegmentImageWidth / 2f, canvasHeight * locationBetweenCenterAndEdge, antiAliasPaint) + canvas.withRotation(-i * 180.0f / maximumDecorationSegmentCount, canvasWidth / 2f, canvasHeight / 2f) { + canvas.drawBitmap(flippedBitmap, circleCenterX - decorationSegmentImageWidth / 2f, canvasHeight * howDistantIsDecorationFromCircleCenter, antiAliasPaint) } } } diff --git a/app/src/main/res/drawable/ic_laurel_leaf_rotated.xml b/app/src/main/res/drawable/ic_laurel_leaf_pair.xml similarity index 100% rename from app/src/main/res/drawable/ic_laurel_leaf_rotated.xml rename to app/src/main/res/drawable/ic_laurel_leaf_pair.xml diff --git a/res/graphics/laurel_wreath/laurel_leaf_rotated.svg b/res/graphics/laurel_wreath/ic_laurel_leaf_pair.svg similarity index 100% rename from res/graphics/laurel_wreath/laurel_leaf_rotated.svg rename to res/graphics/laurel_wreath/ic_laurel_leaf_pair.svg