File tree Expand file tree Collapse file tree 1 file changed +15
-0
lines changed
base/src/main/java/com/enginebai/base/extensions Expand file tree Collapse file tree 1 file changed +15
-0
lines changed Original file line number Diff line number Diff line change 1
1
package com.enginebai.base.extensions
2
2
3
3
import android.content.Context
4
+ import android.graphics.drawable.Drawable
4
5
import android.view.View
5
6
import android.view.inputmethod.InputMethodManager
7
+ import androidx.annotation.ColorRes
8
+ import androidx.annotation.DrawableRes
9
+ import androidx.core.content.ContextCompat
6
10
7
11
/* *
8
12
* 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 {
109
113
fun View.sp2px (sp : Float ): Int {
110
114
return (sp * resources.displayMetrics.scaledDensity + 0.5f ).toInt()
111
115
}
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