Goooler 2023-02-26 04:30:52 +08:00 committed by GitHub
commit 2da7bc5bc8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 53 additions and 49 deletions

View file

@ -26,6 +26,7 @@ import androidx.annotation.ColorInt
import androidx.annotation.Dimension
import androidx.appcompat.widget.AppCompatImageView
import androidx.core.content.ContextCompat
import androidx.core.content.res.use
import com.keylesspalace.tusky.R
import kotlin.math.max
@ -95,49 +96,49 @@ class GraphView @JvmOverloads constructor(
}
private fun initFromXML(attr: AttributeSet?) {
val a = context.obtainStyledAttributes(attr, R.styleable.GraphView)
primaryLineColor = ContextCompat.getColor(
context,
a.getResourceId(
R.styleable.GraphView_primaryLineColor,
R.color.tusky_blue,
context.obtainStyledAttributes(attr, R.styleable.GraphView).use { a ->
primaryLineColor = ContextCompat.getColor(
context,
a.getResourceId(
R.styleable.GraphView_primaryLineColor,
R.color.tusky_blue,
)
)
)
secondaryLineColor = ContextCompat.getColor(
context,
a.getResourceId(
R.styleable.GraphView_secondaryLineColor,
R.color.tusky_red,
secondaryLineColor = ContextCompat.getColor(
context,
a.getResourceId(
R.styleable.GraphView_secondaryLineColor,
R.color.tusky_red,
)
)
)
lineWidth = a.getDimensionPixelSize(
R.styleable.GraphView_lineWidth,
R.dimen.graph_line_thickness
).toFloat()
lineWidth = a.getDimensionPixelSize(
R.styleable.GraphView_lineWidth,
R.dimen.graph_line_thickness
).toFloat()
graphColor = ContextCompat.getColor(
context,
a.getResourceId(
R.styleable.GraphView_graphColor,
R.color.colorBackground,
graphColor = ContextCompat.getColor(
context,
a.getResourceId(
R.styleable.GraphView_graphColor,
R.color.colorBackground,
)
)
)
metaColor = ContextCompat.getColor(
context,
a.getResourceId(
R.styleable.GraphView_metaColor,
R.color.dividerColor,
metaColor = ContextCompat.getColor(
context,
a.getResourceId(
R.styleable.GraphView_metaColor,
R.color.dividerColor,
)
)
)
proportionalTrending = a.getBoolean(
R.styleable.GraphView_proportionalTrending,
proportionalTrending,
)
proportionalTrending = a.getBoolean(
R.styleable.GraphView_proportionalTrending,
proportionalTrending,
)
}
primaryLinePaint = Paint(Paint.ANTI_ALIAS_FLAG).apply {
color = primaryLineColor
@ -170,8 +171,6 @@ class GraphView @JvmOverloads constructor(
strokeWidth = 0f
style = Paint.Style.STROKE
}
a.recycle()
}
private fun initializeVertices() {