-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
*.iml | ||
.gradle | ||
/local.properties | ||
/.idea/caches | ||
/.idea/libraries | ||
/.idea/modules.xml | ||
/.idea/workspace.xml | ||
/.idea/navEditor.xml | ||
/.idea/assetWizardSettings.xml | ||
.DS_Store | ||
/build | ||
/captures | ||
.externalNativeBuild | ||
.cxx | ||
local.properties |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/build |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
plugins { | ||
alias(libs.plugins.android.library) | ||
alias(libs.plugins.jetbrains.kotlin.android) | ||
id("maven-publish") | ||
} | ||
|
||
android { | ||
namespace = "com.kevintorch.androidktx" | ||
compileSdk = 34 | ||
|
||
defaultConfig { | ||
minSdk = 21 | ||
|
||
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" | ||
consumerProguardFiles("consumer-rules.pro") | ||
} | ||
|
||
buildTypes { | ||
release { | ||
isMinifyEnabled = false | ||
proguardFiles( | ||
getDefaultProguardFile("proguard-android-optimize.txt"), | ||
"proguard-rules.pro" | ||
) | ||
} | ||
} | ||
compileOptions { | ||
sourceCompatibility = JavaVersion.VERSION_1_8 | ||
targetCompatibility = JavaVersion.VERSION_1_8 | ||
} | ||
kotlinOptions { | ||
jvmTarget = "1.8" | ||
} | ||
} | ||
|
||
dependencies { | ||
|
||
implementation(libs.androidx.core.ktx) | ||
// implementation(libs.androidx.appcompat) | ||
implementation(libs.material) | ||
} | ||
|
||
afterEvaluate { | ||
publishing { | ||
publications { | ||
register<MavenPublication>("release") { | ||
groupId = "com.github.kevintorch" | ||
artifactId = "Kandroid-ktx" | ||
version = "1.0.0" | ||
|
||
from(components["release"]) | ||
} | ||
} | ||
} | ||
} | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# Add project specific ProGuard rules here. | ||
# You can control the set of applied configuration files using the | ||
# proguardFiles setting in build.gradle. | ||
# | ||
# For more details, see | ||
# http://developer.android.com/guide/developing/tools/proguard.html | ||
|
||
# If your project uses WebView with JS, uncomment the following | ||
# and specify the fully qualified class name to the JavaScript interface | ||
# class: | ||
#-keepclassmembers class fqcn.of.javascript.interface.for.webview { | ||
# public *; | ||
#} | ||
|
||
# Uncomment this to preserve the line number information for | ||
# debugging stack traces. | ||
#-keepattributes SourceFile,LineNumberTable | ||
|
||
# If you keep the line number information, uncomment this to | ||
# hide the original source file name. | ||
#-renamesourcefileattribute SourceFile |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package com.kevintorch.androidktx | ||
|
||
import androidx.test.platform.app.InstrumentationRegistry | ||
import androidx.test.ext.junit.runners.AndroidJUnit4 | ||
|
||
import org.junit.Test | ||
import org.junit.runner.RunWith | ||
|
||
import org.junit.Assert.* | ||
|
||
/** | ||
* Instrumented test, which will execute on an Android device. | ||
* | ||
* See [testing documentation](http://d.android.com/tools/testing). | ||
*/ | ||
@RunWith(AndroidJUnit4::class) | ||
class ExampleInstrumentedTest { | ||
@Test | ||
fun useAppContext() { | ||
// Context of the app under test. | ||
val appContext = InstrumentationRegistry.getInstrumentation().targetContext | ||
assertEquals("com.kevintorch.androidktx.test", appContext.packageName) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"> | ||
|
||
</manifest> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package com.kevintorch.androidktx | ||
|
||
import android.content.Context | ||
import android.view.View | ||
import android.view.ViewGroup | ||
import android.widget.ArrayAdapter | ||
import androidx.annotation.IdRes | ||
import androidx.annotation.LayoutRes | ||
|
||
fun <T> Context.arrayAdapter( | ||
@LayoutRes resource: Int = -1, | ||
@IdRes textViewResourceId: Int = 0, | ||
objects: MutableList<T> = mutableListOf(), | ||
idSelector: (T?, position: Int) -> Long = { _, position -> position.toLong() }, | ||
viewCreator: (ArrayAdapter<T>.(position: Int, convertView: View?, parent: ViewGroup) -> View)? = null, | ||
): ArrayAdapter<T> { | ||
return object : ArrayAdapter<T>(this, resource, textViewResourceId, objects) { | ||
override fun getView(position: Int, convertView: View?, parent: ViewGroup): View { | ||
return if (viewCreator != null) { | ||
viewCreator(position, convertView, parent) | ||
} else { | ||
super.getView(position, convertView, parent) | ||
} | ||
} | ||
|
||
override fun getItemId(position: Int): Long { | ||
return idSelector(getItem(position), position) | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
package com.kevintorch.androidktx | ||
|
||
fun Boolean?.isTrue(): Boolean = this == true | ||
fun Boolean?.isFalse(): Boolean = this == false |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package com.kevintorch.androidktx | ||
|
||
fun <E> MutableList<E>.appendAll(collection: Collection<E>): MutableList<E> { | ||
addAll(collection) | ||
return this | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package com.kevintorch.androidktx | ||
|
||
import android.content.Context | ||
import android.content.res.ColorStateList | ||
import android.graphics.drawable.ColorDrawable | ||
import androidx.annotation.AttrRes | ||
import androidx.annotation.ColorInt | ||
import androidx.annotation.ColorRes | ||
import androidx.core.content.ContextCompat | ||
import androidx.core.content.res.ResourcesCompat | ||
|
||
@ColorInt | ||
fun Context.getColorInt(@ColorRes color: Int): Int = ContextCompat.getColor(this, color) | ||
|
||
fun Int.toColorDrawable(): ColorDrawable = ColorDrawable(this) | ||
|
||
fun Context.colorDrawableFrom(@ColorRes color: Int): ColorDrawable = | ||
getColorInt(color).toColorDrawable() | ||
|
||
fun Context.getColorStateList(color: Int): ColorStateList? = | ||
ResourcesCompat.getColorStateList(resources, color, theme) | ||
|
||
@ColorInt | ||
fun Context.getColorAttr(@AttrRes colorAttr: Int): Int { | ||
val a = obtainStyledAttributes(null, intArrayOf(colorAttr)) | ||
try { | ||
return a.getColor(0, 0) | ||
} finally { | ||
a.recycle() | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package com.kevintorch.androidktx | ||
|
||
import android.app.Application | ||
import android.content.Context | ||
import android.graphics.drawable.Drawable | ||
import android.view.LayoutInflater | ||
import androidx.annotation.DrawableRes | ||
import androidx.appcompat.content.res.AppCompatResources | ||
|
||
val Context.layoutInflator get() = LayoutInflater.from(this) | ||
|
||
inline fun <reified App : Application> Context.getApplication(): App? = applicationContext as? App | ||
|
||
fun Context.getCompatDrawable(@DrawableRes drawable: Int): Drawable? = | ||
AppCompatResources.getDrawable(applicationContext, drawable) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package com.kevintorch.androidktx | ||
|
||
fun lerp( | ||
outputMin: Float, | ||
outputMax: Float, | ||
inputMin: Float, | ||
inputMax: Float, | ||
value: Float | ||
): Float { | ||
return if (value <= inputMin) { | ||
outputMin | ||
} else { | ||
if (value >= inputMax) outputMax else lerp( | ||
outputMin, outputMax, | ||
(value - inputMin) / (inputMax - inputMin) | ||
) | ||
} | ||
} | ||
|
||
fun lerp(startValue: Float, endValue: Float, fraction: Float): Float { | ||
return startValue + fraction * (endValue - startValue) | ||
} | ||
|
||
fun lerp(startValue: Int, endValue: Int, fraction: Float): Int { | ||
return startValue + Math.round(fraction * (endValue - startValue).toFloat()) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
package com.kevintorch.androidktx | ||
|
||
val IntRange.size: Int get() = last - first |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package com.kevintorch.androidktx | ||
|
||
fun String.findContentDispositionValue(name: String): String? { | ||
val regex = """$name\s*=\s*"(.+?)"""".toRegex() | ||
val match = regex.find(this) | ||
return match?.groupValues?.get(1) | ||
} |