0
0
mirror of https://github.com/ankidroid/Anki-Android.git synced 2024-09-20 03:52:15 +02:00

Enable DrawAllocation lint check

This commit is contained in:
lukstbit 2022-06-02 08:58:36 +03:00 committed by Mike Hardy
parent 45613be1f4
commit e0ba632e13
3 changed files with 23 additions and 13 deletions

View File

@ -23,6 +23,7 @@ import android.graphics.Rect
import android.util.AttributeSet
import android.view.View
import com.ichi2.anki.Statistics.ChartFragment
import com.ichi2.utils.KotlinCleanup
import com.wildplot.android.rendering.PlotSheet
import com.wildplot.android.rendering.graphics.wrapper.GraphicsWrap
import timber.log.Timber
@ -31,6 +32,10 @@ class ChartView : View {
private var mFragment: ChartFragment? = null
private var mPlotSheet: PlotSheet? = null
private var mDataIsSet = false
@KotlinCleanup("is this really needed?")
private val drawingBoundsRect = Rect()
private val paint = Paint(Paint.LINEAR_TEXT_FLAG)
private val graphicsWrap = GraphicsWrap()
// The following constructors are needed for the layout inflater
constructor(context: Context?) : super(context) {
@ -49,17 +54,16 @@ class ChartView : View {
// Timber.d("drawing chart");
if (mDataIsSet) {
// Paint paint = new Paint(Paint.LINEAR_TEXT_FLAG | Paint.ANTI_ALIAS_FLAG);
val paint = Paint(Paint.LINEAR_TEXT_FLAG)
paint.isAntiAlias = true
paint.style = Paint.Style.STROKE
val g = GraphicsWrap(canvas, paint)
val field = Rect()
getDrawingRect(field)
if (mPlotSheet != null) {
mPlotSheet!!.paint(g)
} else {
super.onDraw(canvas)
paint.apply {
reset()
isAntiAlias = true
style = Paint.Style.STROKE
}
graphicsWrap.paint = paint
graphicsWrap.canvas = canvas
drawingBoundsRect.setEmpty()
getDrawingRect(drawingBoundsRect)
mPlotSheet?.paint(graphicsWrap) ?: super.onDraw(canvas)
} else {
super.onDraw(canvas)
}

View File

@ -22,11 +22,17 @@ import android.graphics.RectF
import android.graphics.Typeface
/**
* Wrapper of swing/awt graphics class for android use
* Wrapper of swing/awt graphics class for android use.
*
* NOTE: for performance reasons(usage in onDraw) this class has declared dependencies on Paint and
* Canvas which must be manually supplied before using any of its properties/methods.
*
* @author Michael Goldbach
*/
class GraphicsWrap(private val canvas: Canvas, val paint: Paint) {
class GraphicsWrap {
lateinit var canvas: Canvas
lateinit var paint: Paint
var stroke: StrokeWrap
get() = StrokeWrap(paint.strokeWidth)
set(stroke) {

View File

@ -60,6 +60,7 @@
<issue id="TextFields" severity="fatal" />
<issue id="LogConditional" severity="fatal" />
<issue id="ImplicitSamInstance" severity="fatal" />
<issue id="DrawAllocation" severity="fatal" />
<!-- this is new with AGP7.1+, does not appear to create value -->
<issue id="IntentFilterUniqueDataAttributes" severity="ignore" />
@ -212,7 +213,6 @@
<issue id="TrustAllX509TrustManager" severity="ignore" />
<issue id="InvalidImeActionId" severity="ignore" />
<issue id="InvalidPackage" severity="ignore" />
<issue id="DrawAllocation" severity="ignore" />
<issue id="UseSparseArrays" severity="ignore" />
<issue id="UseValueOf" severity="ignore" />
<issue id="JavascriptInterface" severity="ignore" />