diff --git a/README.md b/README.md index b8b44fb..fc49701 100644 --- a/README.md +++ b/README.md @@ -87,9 +87,9 @@ allprojects { And add our dependency to your app `bundle.gradle`. ```gradle -implementation 'com.devrapid.jieyi:kotlinknifer:1.5.7' +implementation 'com.devrapid.jieyi:kotlinknifer:1.5.8' -implementation 'com.devrapid.jieyi:kotlinshaver:0.2.2' +implementation 'com.devrapid.jieyi:kotlinshaver:0.2.3' ``` Then you can use it!!! @@ -100,14 +100,14 @@ Then you can use it!!! com.devrapid.jieyi kotlinknifer - 1.5.7 + 1.5.8 pom com.devrapid.jieyi kotlinshaver - 0.2.2 + 0.2.3 pom ``` @@ -116,25 +116,25 @@ Then you can use it!!! ## kotlinknifer -1. Gson 2.8.2 -2. Glide 4.6.1 +1. Gson 2.8.5 +2. Glide 4.8.0 ## kotlinshaver -1. RxJava 2.1.10 -2. RxKotlin 2.2.0 +1. RxJava 2.2.1 +2. RxKotlin 2.3.0 If you'd not like to use them to your project, you can add the exclude as like below ```gradle -implementation('com.devrapid.jieyi:kotlinknifer:1.5.7', { +implementation('com.devrapid.jieyi:kotlinknifer:1.5.8', { exclude group: 'com.google.code.gson', module: 'gson' exclude group: 'com.github.bumptech.glide', module: 'glide' }) ``` ```gradle -implementation('com.devrapid.jieyi:kotlinshaverr:0.2.2', { +implementation('com.devrapid.jieyi:kotlinshaverr:0.2.3', { exclude group: 'io.reactivex.rxjava2', module: 'rxjava' exclude group: 'io.reactivex.rxjava2', module: 'rxkotlin' }) diff --git a/build.gradle b/build.gradle index 8bdcf69..bde582c 100644 --- a/build.gradle +++ b/build.gradle @@ -1,7 +1,7 @@ // Top-level build file where you can add configuration options common to all sub-projects/modules. buildscript { - ext.kotlin_version = '1.2.31' + ext.kotlin_version = '1.2.61' repositories { jcenter() google() @@ -12,7 +12,7 @@ buildscript { // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files - classpath "com.jfrog.bintray.gradle:gradle-bintray-plugin:1.7.3" + classpath "com.jfrog.bintray.gradle:gradle-bintray-plugin:1.8.0" classpath "com.github.dcendents:android-maven-gradle-plugin:1.5" classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" } diff --git a/gradle.properties b/gradle.properties index 3086c68..03a5cf1 100644 --- a/gradle.properties +++ b/gradle.properties @@ -18,7 +18,7 @@ proj_name=kotlinknifer proj_libname=KotlinKnifer proj_group=com.devrapid.jieyi proj_artifactid=kotlinknifer -proj_version=1.5.7 +proj_version=1.5.8 proj_description=For developing an Android conveniently and rapidly. proj_websiteurl=https://github.com/pokk/KotlinKnifer proj_issuetrackerurl=https://github.com/pokk/KotlinKnifer/issues @@ -36,4 +36,4 @@ developer_email=pokkbaby@gmail.com proj_kotlin_name=kotlinshaver proj_kotlin_libname=KotlinShaver proj_kotlin_artifactid=kotlinshaver -proj_kotlin_version=0.2.2 +proj_kotlin_version=0.2.3 diff --git a/kotlinknifer/build.gradle b/kotlinknifer/build.gradle index ac94396..646b84f 100644 --- a/kotlinknifer/build.gradle +++ b/kotlinknifer/build.gradle @@ -26,16 +26,16 @@ kotlin { dependencies { implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" // 'compile' can also import to the new project with this. - compile 'com.google.code.gson:gson:2.8.2' - compile 'com.github.bumptech.glide:glide:4.6.1' + compile 'com.google.code.gson:gson:2.8.5' + compile 'com.github.bumptech.glide:glide:4.8.0' // 'implementation' can't import to the new project. - implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:0.22.5' - implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core-common:0.22.5' - implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:0.22.5' - implementation 'org.jetbrains.anko:anko-commons:0.10.4' - implementation 'com.android.support:appcompat-v7:27.1.0' - implementation 'com.android.support:recyclerview-v7:27.1.0' - implementation 'com.android.support:palette-v7:27.1.0' + implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:0.25.0' + implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core-common:0.25.0' + implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:0.25.0' + implementation 'org.jetbrains.anko:anko-commons:0.10.5' + implementation 'com.android.support:appcompat-v7:27.1.1' + implementation 'com.android.support:recyclerview-v7:27.1.1' + implementation 'com.android.support:palette-v7:27.1.1' compile project(':kotlinshaver') } diff --git a/kotlinknifer/src/main/java/com/devrapid/kotlinknifer/EditText.kt b/kotlinknifer/src/main/java/com/devrapid/kotlinknifer/EditText.kt new file mode 100644 index 0000000..d8d1b3c --- /dev/null +++ b/kotlinknifer/src/main/java/com/devrapid/kotlinknifer/EditText.kt @@ -0,0 +1,35 @@ +package com.devrapid.kotlinknifer + +import android.graphics.PorterDuff.Mode.SRC_IN +import android.support.annotation.ColorInt +import android.support.annotation.DrawableRes +import android.support.v4.content.ContextCompat +import android.widget.EditText +import android.widget.TextView +import com.devrapid.kotlinshaver.accessible + +fun setCursorPointerColor(view: EditText, @ColorInt color: Int, @DrawableRes drawable: Int = -1) { + // Get the editor. + val editor = TextView::class.java.getDeclaredField("mEditor").accessible().get(view) + // Get all drawable's selection points. + val drawables = if (-1 == drawable) + listOf("mTextSelectHandleRes" // Selection cursor point. + , "mTextSelectHandleLeftRes" // Selection the highlight left cursor point. + , "mTextSelectHandleRightRes") // Selection the highlight right cursor point. + .asSequence() + .map { TextView::class.java.getDeclaredField(it).accessible() } // Get the drawables' field. + .map { it.getInt(view) } // Get the drawable resource id. + .map { requireNotNull(ContextCompat.getDrawable(view.context, it)) } // Get the drawable. + .map { it.setColorFilter(color, SRC_IN); it } // Change the color we set. + .toList() + else + (0..2).map { requireNotNull(ContextCompat.getDrawable(view.context, drawable)) } + // Get all handle fields. + val fields = listOf("mSelectHandleCenter" + , "mSelectHandleLeft" + , "mSelectHandleRight") + .map { editor.javaClass.getDeclaredField(it).accessible() } + fields.zip(drawables).forEach { (field, drawable) -> field.set(editor, drawable) } + + view.highlightColor = color +} diff --git a/kotlinshaver/build.gradle b/kotlinshaver/build.gradle index 5347279..908595c 100644 --- a/kotlinshaver/build.gradle +++ b/kotlinshaver/build.gradle @@ -3,11 +3,11 @@ apply plugin: 'kotlin' dependencies { implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" - implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:0.22.5' - implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core-common:0.22.5' + implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:0.25.0' + implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core-common:0.25.0' - compile 'io.reactivex.rxjava2:rxkotlin:2.2.0' - compile 'io.reactivex.rxjava2:rxjava:2.1.10' + compile 'io.reactivex.rxjava2:rxkotlin:2.3.0' + compile 'io.reactivex.rxjava2:rxjava:2.2.1' } sourceCompatibility = "1.8" @@ -115,4 +115,4 @@ bintray { } } } -} \ No newline at end of file +} diff --git a/kotlinshaver/src/main/java/com/devrapid/kotlinshaver/Casting.kt b/kotlinshaver/src/main/java/com/devrapid/kotlinshaver/Casting.kt new file mode 100644 index 0000000..9df1da3 --- /dev/null +++ b/kotlinshaver/src/main/java/com/devrapid/kotlinshaver/Casting.kt @@ -0,0 +1,13 @@ +package com.devrapid.kotlinshaver + +inline fun castOrNull(from: Any?) = from as? T +inline fun cast(from: Any?): T { + if (null == from) throw NullPointerException("Null object can't cast.") + + try { + return T::class.java.cast(from) + } + catch (castExcept: ClassCastException) { + throw ClassCastException("Class casting failed.") + } +} diff --git a/kotlinshaver/src/main/java/com/devrapid/kotlinshaver/Field.kt b/kotlinshaver/src/main/java/com/devrapid/kotlinshaver/Field.kt new file mode 100644 index 0000000..32ca079 --- /dev/null +++ b/kotlinshaver/src/main/java/com/devrapid/kotlinshaver/Field.kt @@ -0,0 +1,7 @@ +@file:Suppress("NOTHING_TO_INLINE") + +package com.devrapid.kotlinshaver + +import java.lang.reflect.Field + +inline fun Field.accessible() = apply { isAccessible = true } diff --git a/sample/build.gradle b/sample/build.gradle index 0950290..c731217 100644 --- a/sample/build.gradle +++ b/sample/build.gradle @@ -25,8 +25,8 @@ dependencies { androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { exclude group: 'com.android.support', module: 'support-annotations' }) - implementation 'com.android.support:appcompat-v7:27.1.0' - implementation 'com.android.support.constraint:constraint-layout:1.1.0-beta6' + implementation 'com.android.support:appcompat-v7:27.1.1' + implementation 'com.android.support.constraint:constraint-layout:2.0.0-alpha2' implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" implementation project(':kotlinknifer') // implementation "com.devrapid.jieyi:kotlinknifer:1.4.1"