Fix kotlinc warnings in EasterEgg.

- Remove unused parameters / method
- Wrap uses nullable bitmap with "?.let {" and sadly !! as it is
  in fact theoretically possible that bitmap becomes null due to a
  call from a different thread.
- Run ktlint autofix up.

Bug: 112638508
Test: make -j EasterEgg
Change-Id: Idab21176ec9e4e61751a87c4aeafe3966ed10a8c
This commit is contained in:
Aurimas Liutikas
2018-10-11 10:56:29 -07:00
parent 018f47a2b0
commit 455f588927
3 changed files with 30 additions and 40 deletions

View File

@@ -26,15 +26,16 @@ class CutoutAvoidingToolbar : LinearLayout {
private var _insets: WindowInsets? = null private var _insets: WindowInsets? = null
constructor(context: Context) : super(context) { constructor(context: Context) : super(context) {
init(null, 0)
} }
constructor(context: Context, attrs: AttributeSet) : super(context, attrs) { constructor(context: Context, attrs: AttributeSet) : super(context, attrs) {
init(attrs, 0)
} }
constructor(context: Context, attrs: AttributeSet, defStyle: Int) : super(context, attrs, defStyle) { constructor(
init(attrs, defStyle) context: Context,
attrs: AttributeSet,
defStyle: Int
) : super(context, attrs, defStyle) {
} }
override fun onSizeChanged(w: Int, h: Int, oldw: Int, oldh: Int) { override fun onSizeChanged(w: Int, h: Int, oldw: Int, oldh: Int) {
@@ -81,8 +82,4 @@ class CutoutAvoidingToolbar : LinearLayout {
requestLayout() requestLayout()
} }
} }
private fun init(attrs: AttributeSet?, defStyle: Int) {
}
} }

View File

@@ -17,7 +17,6 @@
package com.android.egg.paint package com.android.egg.paint
import android.content.Context import android.content.Context
import android.content.res.Resources
import android.graphics.* import android.graphics.*
import android.provider.Settings import android.provider.Settings
import android.util.AttributeSet import android.util.AttributeSet
@@ -26,7 +25,6 @@ import android.view.MotionEvent
import android.view.View import android.view.View
import android.view.WindowInsets import android.view.WindowInsets
import java.util.concurrent.TimeUnit import java.util.concurrent.TimeUnit
import android.util.Log
import android.provider.Settings.System import android.provider.Settings.System
import org.json.JSONObject import org.json.JSONObject
@@ -86,11 +84,11 @@ public class Painting : View, SpotFilter.Plotter {
} }
var bitmap: Bitmap? = null var bitmap: Bitmap? = null
var paperColor : Int = 0xFFFFFFFF.toInt() var paperColor: Int = 0xFFFFFFFF.toInt()
private var _paintCanvas: Canvas? = null private var _paintCanvas: Canvas? = null
private val _bitmapLock = Object() private val _bitmapLock = Object()
private var _drawPaint = Paint(Paint.ANTI_ALIAS_FLAG) private var _drawPaint = Paint(Paint.ANTI_ALIAS_FLAG)
private var _lastX = 0f private var _lastX = 0f
private var _lastY = 0f private var _lastY = 0f
@@ -113,7 +111,9 @@ public class Painting : View, SpotFilter.Plotter {
FADE_TO_BLACK_CF FADE_TO_BLACK_CF
synchronized(_bitmapLock) { synchronized(_bitmapLock) {
c.drawBitmap(bitmap, 0f, 0f, pt) bitmap?.let {
c.drawBitmap(bitmap!!, 0f, 0f, pt)
}
} }
invalidate() invalidate()
} }
@@ -122,18 +122,22 @@ public class Painting : View, SpotFilter.Plotter {
} }
constructor(context: Context) : super(context) { constructor(context: Context) : super(context) {
init(null, 0) init()
} }
constructor(context: Context, attrs: AttributeSet) : super(context, attrs) { constructor(context: Context, attrs: AttributeSet) : super(context, attrs) {
init(attrs, 0) init()
} }
constructor(context: Context, attrs: AttributeSet, defStyle: Int) : super(context, attrs, defStyle) { constructor(
init(attrs, defStyle) context: Context,
attrs: AttributeSet,
defStyle: Int
) : super(context, attrs, defStyle) {
init()
} }
private fun init(attrs: AttributeSet?, defStyle: Int) { private fun init() {
loadDevicePressureData() loadDevicePressureData()
} }
@@ -264,7 +268,7 @@ public class Painting : View, SpotFilter.Plotter {
super.onDraw(canvas) super.onDraw(canvas)
bitmap?.let { bitmap?.let {
canvas.drawBitmap(bitmap, 0f, 0f, _drawPaint); canvas.drawBitmap(bitmap!!, 0f, 0f, _drawPaint)
} }
} }
@@ -330,8 +334,8 @@ public class Painting : View, SpotFilter.Plotter {
} }
if (bits.width != oldBits.height || bits.height != oldBits.width) { if (bits.width != oldBits.height || bits.height != oldBits.width) {
matrix.postScale( matrix.postScale(
bits.width.toFloat()/oldBits.height, bits.width.toFloat() / oldBits.height,
bits.height.toFloat()/oldBits.width) bits.height.toFloat() / oldBits.width)
} }
c.matrix = matrix c.matrix = matrix
} }
@@ -350,9 +354,10 @@ public class Painting : View, SpotFilter.Plotter {
val invertPaint = Paint() val invertPaint = Paint()
invertPaint.colorFilter = INVERT_CF invertPaint.colorFilter = INVERT_CF
synchronized(_bitmapLock) { synchronized(_bitmapLock) {
_paintCanvas?.drawBitmap(bitmap, 0f, 0f, invertPaint) bitmap?.let {
_paintCanvas?.drawBitmap(bitmap!!, 0f, 0f, invertPaint)
}
} }
invalidate() invalidate()
} }
} }

View File

@@ -17,19 +17,10 @@
package com.android.egg.paint package com.android.egg.paint
import android.content.Context import android.content.Context
import android.graphics.Canvas
import android.graphics.Color
import android.graphics.Paint
import android.graphics.Rect
import android.graphics.drawable.Drawable
import android.text.TextPaint
import android.transition.ChangeBounds
import android.transition.Transition import android.transition.Transition
import android.transition.TransitionListenerAdapter import android.transition.TransitionListenerAdapter
import android.transition.TransitionManager
import android.util.AttributeSet import android.util.AttributeSet
import android.view.* import android.view.*
import android.view.animation.OvershootInterpolator
import android.widget.FrameLayout import android.widget.FrameLayout
class ToolbarView : FrameLayout { class ToolbarView : FrameLayout {
@@ -44,15 +35,16 @@ class ToolbarView : FrameLayout {
} }
constructor(context: Context) : super(context) { constructor(context: Context) : super(context) {
init(null, 0)
} }
constructor(context: Context, attrs: AttributeSet) : super(context, attrs) { constructor(context: Context, attrs: AttributeSet) : super(context, attrs) {
init(attrs, 0)
} }
constructor(context: Context, attrs: AttributeSet, defStyle: Int) : super(context, attrs, defStyle) { constructor(
init(attrs, defStyle) context: Context,
attrs: AttributeSet,
defStyle: Int
) : super(context, attrs, defStyle) {
} }
override fun onApplyWindowInsets(insets: WindowInsets?): WindowInsets { override fun onApplyWindowInsets(insets: WindowInsets?): WindowInsets {
@@ -70,8 +62,4 @@ class ToolbarView : FrameLayout {
return super.onApplyWindowInsets(insets) return super.onApplyWindowInsets(insets)
} }
private fun init(attrs: AttributeSet?, defStyle: Int) {
}
} }