Skip to content

Commit

Permalink
Update to Kotlin 1.3.40
Browse files Browse the repository at this point in the history
Fix Kotlin Lint warnings found after upgrading.
  • Loading branch information
ianhanniballake committed Jun 20, 2019
1 parent 70b97ee commit 012b2ea
Show file tree
Hide file tree
Showing 25 changed files with 89 additions and 71 deletions.
Expand Up @@ -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 {
Expand Down Expand Up @@ -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))
}
Expand Down
Expand Up @@ -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) {
Expand Down
Expand Up @@ -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

Expand All @@ -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)
}
2 changes: 1 addition & 1 deletion build.gradle
Expand Up @@ -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'
Expand Down
Expand Up @@ -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())
Expand Down
Expand Up @@ -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
Expand Down Expand Up @@ -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) }
Expand Down
Expand Up @@ -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
Expand Down
Expand Up @@ -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)
}
Expand Down
Expand Up @@ -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
Expand Down Expand Up @@ -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]}")
}
}
}
Expand Down
Expand Up @@ -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)
}
}
}
Expand Down
Expand Up @@ -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
Expand Down
Expand Up @@ -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) {
Expand Down Expand Up @@ -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])
}
}

Expand Down Expand Up @@ -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)
Expand Down
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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 {
Expand Down
Expand Up @@ -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) {

Expand Down Expand Up @@ -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
}
Expand Down
Expand Up @@ -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) {
Expand Down Expand Up @@ -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
}
Expand Down
Expand Up @@ -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) {
Expand Down Expand Up @@ -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)
}

////////////////////////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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()
Expand Down
Expand Up @@ -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)

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

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

val paintDrawable = PaintDrawable().apply {
shape = RectShape()
Expand All @@ -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)
}

Expand Down

0 comments on commit 012b2ea

Please sign in to comment.