Skip to content
Permalink
Browse files

Update to Kotlin 1.3.40

Fix Kotlin Lint warnings found after upgrading.
  • Loading branch information...
ianhanniballake committed Jun 20, 2019
1 parent 70b97ee commit 012b2eac8631f09b3b49d8b34a1ef38a3793f510
Showing with 89 additions and 71 deletions.
  1. +2 −1 android-client-common/src/main/java/com/google/android/apps/muzei/render/ImageLoader.kt
  2. +1 −2 android-client-common/src/main/java/com/google/android/apps/muzei/render/ImageUtil.kt
  3. +6 −2 android-client-common/src/main/java/com/google/android/apps/muzei/util/MathUtil.kt
  4. +1 −1 build.gradle
  5. +4 −6 legacy-standalone/src/main/java/com/google/android/apps/muzei/legacy/LegacySourceService.kt
  6. +0 −2 legacy-standalone/src/main/java/com/google/android/apps/muzei/legacy/SourceSettingsActivity.kt
  7. +1 −1 legacy-standalone/src/main/java/com/google/android/apps/muzei/sources/SourceSubscriberService.kt
  8. +1 −1 main/src/main/java/com/google/android/apps/muzei/ArtDetailFragment.kt
  9. +1 −2 main/src/main/java/com/google/android/apps/muzei/ChooseProviderFragment.kt
  10. +1 −1 main/src/main/java/com/google/android/apps/muzei/MuzeiWallpaperService.kt
  11. +1 −1 main/src/main/java/com/google/android/apps/muzei/browse/BrowseProviderViewModel.kt
  12. +6 −5 main/src/main/java/com/google/android/apps/muzei/render/GLPicture.kt
  13. +12 −7 main/src/main/java/com/google/android/apps/muzei/render/MuzeiBlurRenderer.kt
  14. +2 −1 main/src/main/java/com/google/android/apps/muzei/util/AnimatedMuzeiLoadingSpinnerView.kt
  15. +2 −1 main/src/main/java/com/google/android/apps/muzei/util/AnimatedMuzeiLogoView.kt
  16. +8 −6 main/src/main/java/com/google/android/apps/muzei/util/PanScaleProxyView.kt
  17. +4 −2 main/src/main/java/com/google/android/apps/muzei/util/ScrimUtil.kt
  18. +6 −6 main/src/main/java/com/google/android/apps/muzei/util/SvgPathParser.kt
  19. +2 −1 main/src/main/java/com/google/android/apps/muzei/util/TickingFloatAnimator.kt
  20. +5 −3 main/src/main/java/com/google/android/apps/muzei/widget/AppWidgetUpdateTask.kt
  21. +10 −8 source-gallery/src/main/java/com/google/android/apps/muzei/gallery/GallerySettingsActivity.kt
  22. +1 −1 source-single/src/main/java/com/google/android/apps/muzei/single/SingleArtProvider.kt
  23. +2 −2 wearable/src/main/java/com/google/android/apps/muzei/MuzeiWatchFace.kt
  24. +2 −2 ...e/src/main/java/com/google/android/apps/muzei/complications/ArtworkComplicationProviderService.kt
  25. +8 −6 wearable/src/main/java/com/google/android/apps/muzei/util/PanView.kt
@@ -31,6 +31,7 @@ import net.nurik.roman.muzei.androidclientcommon.BuildConfig
import java.io.FileNotFoundException
import java.io.IOException
import java.io.InputStream
import kotlin.math.max

fun InputStream.isValidImage(): Boolean {
val options = BitmapFactory.Options().apply {
@@ -105,7 +106,7 @@ sealed class ImageLoader {
BitmapFactory.Options().apply {
inPreferredConfig = Bitmap.Config.ARGB_8888
if (targetWidth != 0) {
inSampleSize = Math.max(
inSampleSize = max(
width.sampleSize(targetWidth),
height.sampleSize(targetHeight))
}
@@ -27,9 +27,8 @@ fun Bitmap?.darkness(): Float {
var totalLum = 0
var n = 0
var x: Int
var y: Int
var y = 0
var color: Int
y = 0
while (y < height) {
x = 0
while (x < width) {
@@ -16,7 +16,11 @@

package com.google.android.apps.muzei.util

fun Float.constrain(min: Float, max: Float): Float = Math.max(min, Math.min(max, this))
import kotlin.math.abs
import kotlin.math.max
import kotlin.math.min

fun Float.constrain(min: Float, max: Float): Float = max(min, min(max, this))

fun interpolate(x1: Float, x2: Float, f: Float): Float = x1 + (x2 - x1) * f

@@ -35,5 +39,5 @@ fun Int.roundMult4() = this + 2 and 0x03.inv()
// see http://stackoverflow.com/a/7446742/102703
fun Int.divideRoundUp(divisor: Int): Int {
val sign = (if (this > 0) 1 else -1) * if (divisor > 0) 1 else -1
return sign * (Math.abs(this) + Math.abs(divisor) - 1) / Math.abs(divisor)
return sign * (abs(this) + abs(divisor) - 1) / abs(divisor)
}
@@ -31,7 +31,7 @@ buildscript {
firebasePerfVersion = '18.0.0'
fragmentVersion = '1.1.0-beta01'
glideVersion = '4.9.0'
kotlinVersion = '1.3.31'
kotlinVersion = '1.3.40'
lifecycleVersion = '2.2.0-alpha01'
materialVersion = '1.1.0-alpha07'
multidexVersion = '2.0.1'
@@ -192,12 +192,10 @@ class LegacySourceService : Service(), LifecycleOwner {
database.sourceDao().getSourceComponentNames())
val resolveInfos = pm.queryIntentServices(queryIntent,
PackageManager.GET_META_DATA)
if (resolveInfos != null) {
for (ri in resolveInfos) {
existingSources.remove(ComponentName(ri.serviceInfo.packageName,
ri.serviceInfo.name))
updateSourceFromServiceInfo(ri.serviceInfo)
}
for (ri in resolveInfos) {
existingSources.remove(ComponentName(ri.serviceInfo.packageName,
ri.serviceInfo.name))
updateSourceFromServiceInfo(ri.serviceInfo)
}
// Delete sources in the database that have since been removed
database.sourceDao().deleteAll(existingSources.toTypedArray())
@@ -38,7 +38,6 @@ import android.os.Bundle
import android.util.Log
import android.view.View
import android.view.ViewGroup
import android.view.ViewPropertyAnimator
import android.widget.ArrayAdapter
import android.widget.TextView
import androidx.appcompat.app.AppCompatActivity
@@ -331,7 +330,6 @@ class SourceSettingsActivity : AppCompatActivity() {

internal inner class SourceView(var source: Source) {
lateinit var icon: Drawable
var animation: ViewPropertyAnimator? = null

fun toCharSequence() = buildSpannedString {
bold { append(source.label) }
@@ -46,7 +46,7 @@ class SourceSubscriberService : IntentService("SourceSubscriberService") {
return
}
// Handle API call from source
val token = intent.getStringExtra(EXTRA_TOKEN)
val token = intent.getStringExtra(EXTRA_TOKEN) ?: return
val state = intent.getBundleExtra(EXTRA_STATE)?.run {
SourceState.fromBundle(this)
} ?: return // If there's no state, there's nothing to change
@@ -255,7 +255,7 @@ class ArtDetailFragment : Fragment(), (Boolean) -> Unit {
// Ensure we have the latest insets
ViewCompat.requestApplyInsets(view)

scrimView = view.findViewById<View>(R.id.art_detail_scrim)
scrimView = view.findViewById(R.id.art_detail_scrim)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
scrimView.background = makeCubicGradientScrimDrawable(Gravity.TOP, 0x44)
}
@@ -42,7 +42,6 @@ import androidx.core.view.isVisible
import androidx.drawerlayout.widget.DrawerLayout
import androidx.fragment.app.Fragment
import androidx.fragment.app.viewModels
import androidx.lifecycle.observe
import androidx.navigation.fragment.findNavController
import androidx.recyclerview.widget.DiffUtil
import androidx.recyclerview.widget.ListAdapter
@@ -417,7 +416,7 @@ class ChooseProviderFragment : Fragment(R.layout.choose_provider_fragment) {
payloads[0] == PAYLOAD_DESCRIPTION -> holder.setDescription(getItem(position))
payloads[0] == PAYLOAD_CURRENT_IMAGE_URI -> holder.setImage(getItem(position))
payloads[0] == PAYLOAD_SELECTED -> holder.setSelected(getItem(position))
else -> IllegalArgumentException("Forgot to handle ${payloads[0]}")
else -> throw IllegalArgumentException("Forgot to handle ${payloads[0]}")
}
}
}
@@ -385,7 +385,7 @@ class MuzeiWallpaperService : GLWallpaperService(), LifecycleOwner {
delayedBlur = lifecycleScope.launch {
delay(TEMPORARY_FOCUS_DURATION_MILLIS)
queueEvent {
renderer.setIsBlurred(true, false)
renderer.setIsBlurred(isBlurred = true, artDetailMode = false)
}
}
}
@@ -36,7 +36,7 @@ import java.util.concurrent.Executors

class ProviderArtworkLiveData(
val context: Context,
val coroutineScope: CoroutineScope,
private val coroutineScope: CoroutineScope,
val contentUri: Uri
): MutableLiveData<List<Artwork>>() {
private val authority: String = contentUri.authority
@@ -22,6 +22,7 @@ import android.graphics.Rect
import android.opengl.GLES20
import com.google.android.apps.muzei.util.divideRoundUp
import java.nio.FloatBuffer
import kotlin.math.min

internal fun Bitmap.toGLPicture(): GLPicture? {
if (width == 0 || height == 0) {
@@ -98,7 +99,7 @@ internal class GLPicture @SuppressLint("CheckResult") internal constructor(
// Compute max texture size
val maxTextureSize = IntArray(1)
GLES20.glGetIntegerv(GLES20.GL_MAX_TEXTURE_SIZE, maxTextureSize, 0)
TILE_SIZE = Math.min(512, maxTextureSize[0])
TILE_SIZE = min(512, maxTextureSize[0])
}
}

@@ -174,16 +175,16 @@ internal class GLPicture @SuppressLint("CheckResult") internal constructor(
for (y in 0 until numRows) {
for (x in 0 until numColumns) {
// Pass in the vertex information
vertices[9] = Math.min(-1 + 2f * x.toFloat() * TILE_SIZE.toFloat() / width, 1f)
vertices[9] = min(-1 + 2f * x.toFloat() * TILE_SIZE.toFloat() / width, 1f)
vertices[3] = vertices[9]
vertices[0] = vertices[3] // left
vertices[16] = Math.min(-1 + 2f * (y + 1).toFloat() * TILE_SIZE.toFloat() / height, 1f)
vertices[16] = min(-1 + 2f * (y + 1).toFloat() * TILE_SIZE.toFloat() / height, 1f)
vertices[10] = vertices[16]
vertices[1] = vertices[10] // top
vertices[15] = Math.min(-1 + 2f * (x + 1).toFloat() * TILE_SIZE.toFloat() / width, 1f)
vertices[15] = min(-1 + 2f * (x + 1).toFloat() * TILE_SIZE.toFloat() / width, 1f)
vertices[12] = vertices[15]
vertices[6] = vertices[12] // right
vertices[13] = Math.min(-1 + 2f * y.toFloat() * TILE_SIZE.toFloat() / height, 1f)
vertices[13] = min(-1 + 2f * y.toFloat() * TILE_SIZE.toFloat() / height, 1f)
vertices[7] = vertices[13]
vertices[4] = vertices[7] // bottom
vertexBuffer.put(vertices)
@@ -39,6 +39,11 @@ import com.google.android.apps.muzei.util.roundMult4
import com.google.android.apps.muzei.util.uninterpolate
import javax.microedition.khronos.egl.EGLConfig
import javax.microedition.khronos.opengles.GL10
import kotlin.math.ceil
import kotlin.math.floor
import kotlin.math.max
import kotlin.math.min
import kotlin.math.sqrt

sealed class SwitchingPhotos(val viewportId: Int)
data class SwitchingPhotosInProgress(private val currentId: Int) : SwitchingPhotos(currentId)
@@ -323,7 +328,7 @@ class MuzeiBlurRenderer(
dimAmount = if (demoMode)
DEMO_DIM
else
(maxDim * (1 - DIM_RANGE + DIM_RANGE * Math.sqrt(darkness.toDouble()))).toInt()
(maxDim * (1 - DIM_RANGE + DIM_RANGE * sqrt(darkness.toDouble()))).toInt()
tempBitmap?.recycle()

// Create the GLPicture objects
@@ -356,8 +361,8 @@ class MuzeiBlurRenderer(
}
// Note that image width should be a multiple of 4 to avoid
// issues with RenderScript allocations.
val scaledHeight = Math.max(2, sampleSizeTargetHeight.floorEven())
val scaledWidth = Math.max(4, (scaledHeight * bitmapAspectRatio).toInt().roundMult4())
val scaledHeight = max(2, sampleSizeTargetHeight.floorEven())
val scaledWidth = max(4, (scaledHeight * bitmapAspectRatio).toInt().roundMult4())

// To blur, first load the entire bitmap region, but at a very large
// sample size that's appropriate for the final blurred image
@@ -414,14 +419,14 @@ class MuzeiBlurRenderer(
}

// Ensure the bitmap is as wide as the screen by applying zoom if necessary
val zoom = Math.max(1f, screenToBitmapAspectRatio)
val zoom = max(1f, screenToBitmapAspectRatio)

// Total scale factors in both zoom and scale due to aspect ratio.
val scaledBitmapToScreenAspectRatio = zoom / screenToBitmapAspectRatio

// At most pan across 1.8 screenfuls (2 screenfuls + some parallax)
// TODO: if we know the number of home screen pages, use that number here
val maxPanScreenWidths = Math.min(1.8f, scaledBitmapToScreenAspectRatio)
val maxPanScreenWidths = min(1.8f, scaledBitmapToScreenAspectRatio)

currentViewport.apply {
left = interpolate(-1f, 1f,
@@ -484,8 +489,8 @@ class MuzeiBlurRenderer(
Matrix.multiplyMM(mvpMatrix, 0, projectionMatrix, 0, mvpMatrix, 0)

val blurFrame = blurAnimator.currentValue
val lo = Math.floor(blurFrame.toDouble()).toInt()
val hi = Math.ceil(blurFrame.toDouble()).toInt()
val lo = floor(blurFrame.toDouble()).toInt()
val hi = ceil(blurFrame.toDouble()).toInt()

val localHiAlpha = blurFrame - lo
when {
@@ -31,6 +31,7 @@ import android.util.TypedValue
import android.view.View
import android.view.animation.LinearInterpolator
import java.text.ParseException
import kotlin.math.max

class AnimatedMuzeiLoadingSpinnerView @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null, defStyle: Int = 0) : View(context, attrs, defStyle) {

@@ -152,7 +153,7 @@ class AnimatedMuzeiLoadingSpinnerView @JvmOverloads constructor(context: Context
val pm = PathMeasure(path, true)
var len = pm.length
while (true) {
len = Math.max(len, pm.length)
len = max(len, pm.length)
if (!pm.nextContour()) {
break
}
@@ -34,6 +34,7 @@ import android.view.View
import android.view.animation.DecelerateInterpolator

import java.text.ParseException
import kotlin.math.max

class AnimatedMuzeiLogoView @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null, defStyle: Int = 0)
: View(context, attrs, defStyle) {
@@ -190,7 +191,7 @@ class AnimatedMuzeiLogoView @JvmOverloads constructor(context: Context, attrs: A
val pm = PathMeasure(path, true)
var len = pm.length
while (true) {
len = Math.max(len, pm.length)
len = max(len, pm.length)
if (!pm.nextContour()) {
break
}
@@ -30,6 +30,8 @@ import android.view.ScaleGestureDetector
import android.view.View
import android.widget.OverScroller
import androidx.core.view.GestureDetectorCompat
import kotlin.math.max
import kotlin.math.min

class PanScaleProxyView @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null, defStyle: Int = 0)
: View(context, attrs, defStyle) {
@@ -251,8 +253,8 @@ class PanScaleProxyView @JvmOverloads constructor(context: Context, attrs: Attri

override fun onSizeChanged(w: Int, h: Int, oldw: Int, oldh: Int) {
super.onSizeChanged(w, h, oldw, oldh)
currentWidth = Math.max(1, w)
currentHeight = Math.max(1, h)
currentWidth = max(1, w)
currentHeight = max(1, h)
}

////////////////////////////////////////////////////////////////////////////////////////////////
@@ -297,7 +299,7 @@ class PanScaleProxyView @JvmOverloads constructor(context: Context, attrs: Attri
if (bottom > 1) {
val requestedHeight = height()
bottom = 1f
top = Math.max(0f, bottom - requestedHeight)
top = max(0f, bottom - requestedHeight)
}
if (height() < minViewportWidthOrHeight) {
bottom = (bottom + top) / 2 + minViewportWidthOrHeight / 2
@@ -314,7 +316,7 @@ class PanScaleProxyView @JvmOverloads constructor(context: Context, attrs: Attri
if (right > 1) {
val requestedWidth = width()
right = 1f
left = Math.max(0f, right - requestedWidth)
left = max(0f, right - requestedWidth)
}
if (width() < minViewportWidthOrHeight) {
right = (right + left) / 2 + minViewportWidthOrHeight / 2
@@ -383,8 +385,8 @@ class PanScaleProxyView @JvmOverloads constructor(context: Context, attrs: Attri
*/
val curWidth = currentViewport.width()
val curHeight = currentViewport.height()
x = Math.max(0f, Math.min(x, 1 - curWidth))
y = Math.max(0f, Math.min(y, 1 - curHeight))
x = max(0f, min(x, 1 - curWidth))
y = max(0f, min(y, 1 - curHeight))

currentViewport.set(x, y, x + curWidth, y + curHeight)
triggerViewportChangedListener()
@@ -26,6 +26,8 @@ import android.graphics.drawable.ShapeDrawable
import android.graphics.drawable.shapes.RectShape
import android.util.LruCache
import android.view.Gravity
import kotlin.math.max
import kotlin.math.pow

private val cubicGradientScrimCache = LruCache<Int, Drawable>(10)

@@ -55,7 +57,7 @@ fun makeCubicGradientScrimDrawable(
return cachedGradient
}

numStops = Math.max(numStops, 2)
numStops = max(numStops, 2)

val paintDrawable = PaintDrawable().apply {
shape = RectShape()
@@ -65,7 +67,7 @@ fun makeCubicGradientScrimDrawable(

for (i in 0 until numStops) {
val x = i * 1f / (numStops - 1)
val opacity = Math.pow(x.toDouble(), 3.0).toFloat().constrain(0f, 1f)
val opacity = x.toDouble().pow(3.0).toFloat().constrain(0f, 1f)
stopColors[i] = Color.argb((alpha * opacity).toInt(), red, green, blue)
}

0 comments on commit 012b2ea

Please sign in to comment.
You can’t perform that action at this time.