File tree Expand file tree Collapse file tree
base/src/main/java/com/enginebai/base/extensions Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11package com.enginebai.base.extensions
22
33import android.content.Context
4+ import android.graphics.drawable.Drawable
45import android.view.View
56import android.view.inputmethod.InputMethodManager
7+ import androidx.annotation.ColorRes
8+ import androidx.annotation.DrawableRes
9+ import androidx.core.content.ContextCompat
610
711/* *
812 * Prevent multiple click in a short period of time. Default interval is 1500 milli-second.
@@ -109,3 +113,14 @@ fun View.px2sp(px: Float): Int {
109113fun View.sp2px (sp : Float ): Int {
110114 return (sp * resources.displayMetrics.scaledDensity + 0.5f ).toInt()
111115}
116+
117+ //
118+ // resources
119+ //
120+ fun View.getColor (@ColorRes resId : Int ) = ContextCompat .getColor(context, resId)
121+ fun View.getDrawable (@DrawableRes resId : Int ) = ContextCompat .getDrawable(context, resId)
122+ fun View.getDrawableWithIntrinsicSize (@DrawableRes resId : Int ): Drawable ? {
123+ return getDrawable(resId)?.apply {
124+ setBounds(0 , 0 , intrinsicWidth, intrinsicHeight)
125+ }
126+ }
You can’t perform that action at this time.
0 commit comments