RichUtils / pyxis.uzuki.live.richutilskt.utils / android.content.Context

Extensions for android.content.Context

alert

fun Context.alert(title: String? = "", message: String, positiveButton: String? = null, cancelable: Boolean = true, callback: DialogInterface.() -> Unit = {}): Builder

Display AlertDialog instantly

applyUnReadCount

fun Context.applyUnReadCount(count: Int): Unit

apply count of UnRead

bitmapToDrawable

fun Context.bitmapToDrawable(bitmap: Bitmap?): Drawable?

Bitmap to Drawable

checkNetwork

fun Context.checkNetwork(): Int

get network connection check

confirm

fun Context.confirm(title: String? = "", message: String, positiveButton: String? = null, negativeButton: String? = null, cancelable: Boolean = true, callback: DialogInterface.() -> Unit): Builder

Display AlertDialog instantly with confirm

copyText

fun Context.copyText(text: CharSequence): Unit

copy text to clipboard

dimen

fun Context.dimen(resource: Int): Int

get pixel size from DimenRes

dip2px

fun Context.dip2px(value: Int): Int
fun Context.dip2px(value: Float): Int

convert dip to px

downloadFile

fun Context.downloadFile(urlPath: String, name: String): Uri?

Download file from uri

getAndroidId

fun Context.getAndroidId(): String

get androidId of device

getContactsList

fun Context.getContactsList(): ArrayList<ContactItem>

load contact data from device

getIMEI

fun Context.getIMEI(): String

get IMEI of device

getKeyHash

fun Context.getKeyHash(): String

get key hash of application

getLine1Number

fun Context.getLine1Number(): String

get Line1Number (as know as PhoneNumber) of device

getStatusBarHeight

fun Context.getStatusBarHeight(): Int

get Height of status bar

getTextFromClipboard

fun Context.getTextFromClipboard(): String

get text of clipboard list

inflate

fun Context.inflate(layoutRes: Int, parent: ViewGroup? = null, attachToRoot: Boolean = false): View

inflate view

progress

fun Context.progress(title: String? = null, message: String): DialogInterface

Display ProgressDialog

px2dip

fun Context.px2dip(px: Int): Float

convert px to dip

px2sp

fun Context.px2sp(px: Int): Float

convert px to sp

reboot

fun Context.reboot(restartIntent: Intent = this.packageManager.getLaunchIntentForPackage(this.packageName)): Unit

Reboot application

removeUnReadCount

fun Context.removeUnReadCount(): Unit

remove count of UnRead

requestMediaScanner

fun Context.requestMediaScanner(url: String): Unit

Request MediaScanning

saveBitmapToFile

fun Context.saveBitmapToFile(bitmap: Bitmap): String?

Save Bitmap to file

selector

fun Context.selector(title: String? = "", items: List<CharSequence>, cancelable: Boolean = true, callback: (DialogInterface, Int) -> Unit): Builder
fun <T> Context.selector(title: String? = "", items: List<T>, cancelable: Boolean = true, callback: (DialogInterface, item: T, Int) -> Unit): Builder

Display SelectorDialog instantly

setTypeface

fun Context.setTypeface(layoutRes: Int, parent: ViewGroup? = null, isAttachedRoot: Boolean = false): View?
fun Context.setTypeface(view: ViewGroup, parent: ViewGroup? = null, isAttachedRoot: Boolean = false): View?

Set system font into ViewGroup

sp2px

fun Context.sp2px(value: Int): Int
fun Context.sp2px(value: Float): Int

convert sp to px

toast

fun Context.toast(message: String, length: Int = Toast.LENGTH_SHORT): Unit
fun Context.toast(message: Int, length: Int = Toast.LENGTH_SHORT): Unit

Display Toast Message

versionCode

fun Context.versionCode(): Int

get version code of this application

versionName

fun Context.versionName(): String

get version name of this application

vibrate

fun Context.vibrate(millSec: Long): Unit
fun Context.vibrate(pattern: LongArray, repeat: Int = -1): Unit

Vibrate need VIBRATE permission