Skip to content

Commit

Permalink
Remove needless SDK version checks
Browse files Browse the repository at this point in the history
  • Loading branch information
Gowsky committed Feb 23, 2025
1 parent 5097c3c commit c5b0f99
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 59 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2024 by Patryk Goworowski and Patrick Michalik.
* Copyright 2025 by Patryk Goworowski and Patrick Michalik.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -17,7 +17,6 @@
package com.patrykandpatrick.vico.core.common

import android.graphics.Canvas
import android.os.Build
import kotlin.math.roundToInt

internal inline fun Canvas.inClip(
Expand All @@ -33,31 +32,7 @@ internal inline fun Canvas.inClip(
restoreToCount(clipRestoreCount)
}

internal fun Canvas.saveLayer(): Int =
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
saveLayer(0f, 0f, width.toFloat(), height.toFloat(), null)
} else {
@Suppress("DEPRECATION")
saveLayer(0f, 0f, width.toFloat(), height.toFloat(), null, Canvas.ALL_SAVE_FLAG)
}
internal fun Canvas.saveLayer(): Int = saveLayer(0f, 0f, width.toFloat(), height.toFloat(), null)

internal fun Canvas.saveLayer(opacity: Float): Int =
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
saveLayerAlpha(
0f,
0f,
width.toFloat(),
height.toFloat(),
(opacity * MAX_HEX_VALUE).roundToInt(),
)
} else {
@Suppress("DEPRECATION")
saveLayerAlpha(
0f,
0f,
width.toFloat(),
height.toFloat(),
(opacity * MAX_HEX_VALUE).roundToInt(),
Canvas.ALL_SAVE_FLAG,
)
}
saveLayerAlpha(0f, 0f, width.toFloat(), height.toFloat(), (opacity * MAX_HEX_VALUE).roundToInt())
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2024 by Patryk Goworowski and Patrick Michalik.
* Copyright 2025 by Patryk Goworowski and Patrick Michalik.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -16,39 +16,10 @@

package com.patrykandpatrick.vico.core.common

import android.os.Build
import android.text.Spannable
import android.text.SpannableStringBuilder

internal fun SpannableStringBuilder.appendCompat(
text: CharSequence,
what: Any,
flags: Int,
): SpannableStringBuilder =
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
append(text, what, flags)
} else {
append(text, 0, text.length)
setSpan(what, length - text.length, length, flags)
this
}

internal fun <T> Iterable<T>.transformToSpannable(
separator: CharSequence = ", ",
prefix: CharSequence = "",
postfix: CharSequence = "",
limit: Int = -1,
truncated: CharSequence = ELLIPSIS,
transform: SpannableStringBuilder.(T) -> Unit,
): Spannable {
val buffer = SpannableStringBuilder()
buffer.append(prefix)
var count = 0
for (element in this) {
if (++count > 1) buffer.append(separator)
if (limit < 0 || count <= limit) buffer.transform(element) else break
}
if (limit in 0..<count) buffer.append(truncated)
buffer.append(postfix)
return buffer
}
): SpannableStringBuilder = append(text, what, flags)

0 comments on commit c5b0f99

Please sign in to comment.