Skip to content

Instantly share code, notes, and snippets.


Grégory Lureau glureau

View GitHub Profile
View KspTestSample.kt
class ExportCompilerTest {
fun classWithOneVal() {
import deezer.kmp.Export
class BasicClass(val id: String)
View ThemeColorPreview.kt
package com.glureau
import android.content.res.Configuration.UI_MODE_NIGHT_NO
import android.content.res.Configuration.UI_MODE_NIGHT_YES
import androidx.compose.material.MaterialTheme
View FrameRadarView (v0.1)
package glureau.frameradar
import android.content.Context
import android.util.AttributeSet
import android.view.View
import java.util.*
View GoogleSheet : export links and texts separately from a rich text
View medium_atvasis_providesAutoSizeConfiguration.kt
* Storage of AutoSizeConfiguration
* 1 - We cannot setTextSize without disabling autosize (or use Reflection but way more fragile...)
* 2 - Disabling autosize reset all values and attrs is not re-parsed so data is lost.
* Due to these 2 reasons, we need a way to keep track of the previous values to restore them when required.
* The solution is to store in a static map a weak reference of the view and an AutoSizeConfiguration data class.
* So if there is no data available (first usage or first view destroyed and recreated),
* we store the attributes in our data class, and if there is already a data class, we re-use them.
View medium_atvasis_adjustSizeToFit.kt
* Method to adjust (auto-size) the text size AND the images height.
* This approach is based on width and lines instead of height, so you can use layout_heigt="wrap_content"
* and the TextView height will adapt to the best font size (instead of hardcoded heights).
* Idea of improvements: use layout_height value if hardcoded, and use current behaviour for match_parent or wrap_content.
* /!\ WARNING /!\
* You can define the min/max/granularity of autoSize with the standard appCompat definitions BUT you have to define the type to uniform.
* app:autoSizeTextType="uniform"
* app:autoSizeMaxTextSize="500sp"
View medium_atvasis_alignImageToText.kt
interface DrawableHeightComputeMode {
fun computeHeight(textPaint: TextPaint, text: CharSequence): Int
fun TextView.alignImageToText(textPaint: TextPaint, drawableHeightComputer: DrawableHeightComputeMode) {
(text as? SpannedString)?.getSpans(0, text.length, {
val drawable = it.drawable
val ratio = drawable.intrinsicWidth.toFloat() / drawable.intrinsicHeight
val fontHeight = drawableHeightComputer.computeHeight(textPaint, text)
val drawableWidth = truncate(fontHeight * ratio).toInt()
private boolean suggestedSizeFitsInSpace(int suggestedSizeInPx, RectF availableSpace) {
CharSequence text = mTextView.getText();
TransformationMethod transformationMethod = mTextView.getTransformationMethod();
if (transformationMethod != null) {
CharSequence transformedText = transformationMethod.getTransformation(text, mTextView);
if (transformedText != null) {
text = transformedText;
View medium_atvasis_reflection.kt
* Remapping auto-size functionalities from AppCompatTextViewAutoSizeHelper.
fun AppCompatTextView.autoSizeTextAvailableSizes(): IntArray =
invokeAndReturnWithDefault(this, "getAutoSizeTextAvailableSizes", IntArray(0))
* Copied from AppCompatTextViewAutoSizeHelper but adapted to AppCompatTextView.
View medium_atvasis_imagespan.kt
class MediumActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
tv3.text = "FOR <picto> DEVS"
val drawable = ContextCompat.getDrawable(this, R.drawable.medium_logo_lowres)!!.apply {
setBounds(0, 0, intrinsicWidth, intrinsicHeight)