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
@Composable | |
fun OutlinedText( | |
text: String, | |
modifier: Modifier = Modifier, | |
textStyle: TextStyle = TextStyle.Default, | |
stroke: Stroke = Stroke(), | |
strokeColor: Color = Color.Transparent, | |
) { | |
var textLayoutResult: TextLayoutResult? by remember { | |
mutableStateOf(null) |
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
@Composable | |
fun CompareViewer() { | |
val density = LocalDensity.current | |
val separatorWidth: Dp = 1.dp | |
val separatorWidthPx = with(density) { separatorWidth.toPx() } | |
BoxWithConstraints(modifier = Modifier.fillMaxWidth()) { | |
val parentWidthDp = maxWidth | |
val parentWidthPx = with(density) { parentWidthDp.toPx() } | |
val initialOffsetX = parentWidthPx / 2 | |
var offsetX by remember { mutableStateOf(initialOffsetX) } |
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
fun Long.toUnits(units: Array<String>): String { | |
var num = this | |
var rem = 0L | |
var index = -1 | |
while ("$num".length > 4 && index < units.lastIndex) { | |
rem = num % 10000 | |
num /= 10000 | |
index += 1 | |
} | |
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
fun <T : ViewBinding> Fragment.viewBinding(viewBindingFactory: (View) -> T) = | |
FragmentViewBindingDelegate(this, viewBindingFactory) | |
class FragmentViewBindingDelegate<T : ViewBinding>( | |
val fragment: Fragment, | |
val viewBindingFactory: (View) -> T | |
) : ReadOnlyProperty<Fragment, T> { | |
private var binding: T? = null | |
private val viewLifecycleOwnerObserver = Observer<LifecycleOwner?> { |
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
enum class Fish { | |
TANAGO { | |
override val id: Int = 1 | |
override val fishName: String = "タナゴ" | |
}, | |
OIKAWA { | |
override val id: Int = 2 | |
override val fishName: String = "オイカワ" | |
}, | |
FUNA { |
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
val randomColor: Int by lazy { | |
val colorPatterns = arrayOf( | |
"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "b", "c", "d", "e", "f" | |
) | |
Color.parseColor(mutableListOf<String>() | |
.apply { repeat(6) { add(colorPatterns.random()) } } | |
.joinToString(separator = "", prefix = "#")) | |
} |
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
class LabelTextSpan( | |
@ColorInt private val labelColorInt: Int, | |
@ColorInt private val textColorInt: Int, | |
private val textSize: Float | |
) : ReplacementSpan() { | |
override fun draw( | |
canvas: Canvas, | |
text: CharSequence?, | |
start: Int, |
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
fun FragmentActivity.fullscreen(flag: Boolean) { | |
val attrs = window.attributes | |
attrs.flags = if (flag) | |
attrs.flags or WindowManager.LayoutParams.FLAG_FULLSCREEN else | |
attrs.flags or WindowManager.LayoutParams.FLAG_FULLSCREEN | |
window.attributes = attrs | |
} |
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
class FontMetricsSpan : ReplacementSpan() { | |
override fun draw( | |
canvas: Canvas, | |
text: CharSequence?, | |
start: Int, | |
end: Int, | |
x: Float, | |
top: Int, | |
y: Int, |
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
class CenteredImageSpan( | |
context: Context, | |
resourceId: Int | |
) : ImageSpan(context, resourceId) { | |
private val drawableRef = AtomicReference<Drawable?>() | |
private val cachedDrawable: Drawable | |
get() = drawableRef.get() ?: drawable.apply { | |
drawableRef.set(drawable) | |
} |
NewerOlder