VictorChow/kotlin-android-lib


Kotlin extensions for android. 😏

Download


Step 1. Add the JitPack repository to your build file

Add it in your root settings.gradle at the end of repositories:

	dependencyResolutionManagement {
		repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
		repositories {
			mavenCentral()
			maven { url 'https://jitpack.io' }
		}
	}

Add it in your settings.gradle.kts at the end of repositories:

	dependencyResolutionManagement {
		repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
		repositories {
			mavenCentral()
			maven { url = uri("https://jitpack.io") }
		}
	}

Add to pom.xml

	<repositories>
		<repository>
		    <id>jitpack.io</id>
		    <url>https://jitpack.io</url>
		</repository>
	</repositories>

Add it in your build.sbt at the end of resolvers:

 
    resolvers += "jitpack" at "https://jitpack.io"
        
    

Add it in your project.clj at the end of repositories:

 
    :repositories [["jitpack" "https://jitpack.io"]]
        
    

Step 2. Add the dependency

	dependencies {
		implementation 'com.github.VictorChow:KotlinAndroidLib:2.0.0'
	}
	dependencies {
		implementation("com.github.VictorChow:KotlinAndroidLib:2.0.0")
	}
	<dependency>
	    <groupId>com.github.VictorChow</groupId>
	    <artifactId>KotlinAndroidLib</artifactId>
	    <version>2.0.0</version>
	</dependency>

                            
    libraryDependencies += "com.github.VictorChow" % "KotlinAndroidLib" % "2.0.0"
        
        

                            
    :dependencies [[com.github.VictorChow/KotlinAndroidLib "2.0.0"]]
        
        

Readme


KotlinAndroidLib

一些Android开发的扩展。

[点这查看所有支持的扩展API(readmore)]

2.x - AndroidX

1.x - Android Support

Usage

//初始化
Ext.with(application)

Gradle

allprojects {
    repositories {
        ...
        maven { url 'https://jitpack.io' }
    }
}
//依赖项
//org.jetbrains.kotlin:kotlin-stdlib-jdk7

2.x
dependencies {
    implementation 'com.github.VictorChow:kotlin-android-lib:2.0.0'
}

1.x
dependencies {
    implementation 'com.github.VictorChow:kotlin-android-lib:1.2.4'
}

Brief

ViewExt

//设置宽高
fun View.setWidth(value: Int)
fun View.setHeight(value: Int)
fun View.resize(width: Int, height: Int)
...

CommonExt

fun findColor(@ColorRes resId: Int) 
fun findDrawable(@DrawableRes resId: Int)
fun findColorStateList(@ColorRes resId: Int)
...

DisplayExt

val screenWidth: Int
val screenHeight: Int
val screenDensity: Float
...

DateTimeExt

fun Long.year()
fun Long.month()
fun Long.day()
...

StringExt

fun String.toast()
fun String.md5()
fun String.sha1()
...

ListenerExt

fun Animator.addListener {
    onStart { }
    onCancel { }
    onEnd { }
    onRepeat { }
}

fun Animator.addPauseListener {
    onPause { }
    onResume { }
}
...

ManagerExt

val connectivityManager
val alarmManager
val telephonyManager
val activityManager
...

SharedPreferencesExt

fun spSetInt(key: String, value: Int)
fun spGetInt(key: String, defaultValue: Int = 0)
...

BitmapExt

fun Bitmap.toBase64(): String
fun Bitmap.resize(w: Number, h: Number): Bitmap
...

FileExt

fun File.copy(dest: File)
fun File.copyDirectory(dest: File)
...

ToastExt

fun toast(msg: Any, isShort: Boolean = true) 

ActivityExt

fun Activity.goActivity<T>()
fun Activity.goActivity<T>(requestCode: Int)
...

FragmentExt (support.v4)

fun Fragment.goActivity<T>()
fun Fragment.goActivity<T>(requestCode: Int)
...

ActivityMgr

fun add(activity: Activity)
fun remove(activity: Activity)
fun removeAll()
...

ApiExt

fun aboveApi(api: Int, included: Boolean = false, block: () -> Unit)
fun belowApi(api: Int, included: Boolean = false, block: () -> Unit)

[点这查看所有支持的扩展API(readmore)]