-
Notifications
You must be signed in to change notification settings - Fork 424
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Feature] Add getDimensionDp() and specify some missing return types.
- Loading branch information
Showing
5 changed files
with
117 additions
and
23 deletions.
There are no files selected for viewing
12 changes: 12 additions & 0 deletions
12
app/src/main/java/me/zhanghai/android/files/compat/TypedValueCompat.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
/* | ||
* Copyright (c) 2023 Hai Zhang <[email protected]> | ||
* All Rights Reserved. | ||
*/ | ||
|
||
package me.zhanghai.android.files.compat | ||
|
||
import android.util.TypedValue | ||
import androidx.core.util.TypedValueCompat | ||
|
||
val TypedValue.complexUnitCompat: Int | ||
get() = TypedValueCompat.getUnitFromComplexDimension(data) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
app/src/main/java/me/zhanghai/android/files/util/TypedValueExtensions.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/* | ||
* Copyright (c) 2023 Hai Zhang <[email protected]> | ||
* All Rights Reserved. | ||
*/ | ||
|
||
package me.zhanghai.android.files.util | ||
|
||
import android.util.TypedValue | ||
import java.util.concurrent.atomic.AtomicReference | ||
import kotlin.reflect.KClass | ||
|
||
inline fun <T> KClass<TypedValue>.useTemp(block: (TypedValue) -> T): T { | ||
val temp = TypedValue::class.obtainTemp() | ||
return try { | ||
block(temp) | ||
} finally { | ||
temp.releaseTemp() | ||
} | ||
} | ||
|
||
fun KClass<TypedValue>.obtainTemp(): TypedValue = tempTypedValue.getAndSet(null) ?: TypedValue() | ||
|
||
private val tempTypedValue = AtomicReference<TypedValue>() | ||
|
||
fun TypedValue.releaseTemp() { | ||
tempTypedValue.compareAndSet(null, this) | ||
} |