This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Database(private context: Context) { | |
| val helper: SQLiteOpenHelper by lazy { SQLiteOpenHelper(context,...-) } | |
| val observableProperty: Int by Delegates.observable { thisRef , newValue , oldValue -> doSomething()} | |
| val vetoableProperty: Int by Delegates.vetoable { _ , newValue , oldValue -> return if (oldValue < newValue) true else false } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //primera opción extener una funcin sobre [BaseObservable] que emita una [ObservableProperty] que emite el cambio y lo notifica | |
| // a los databinders para repintar | |
| inline fun <Param> BaseObservable.bindingParam(initialValue: Param, | |
| crossinline afterChange: (Param) -> Unit): ReadWriteProperty<BaseObservable, Param> = | |
| object : ObservableProperty<Param>(initialValue) { | |
| override fun afterChange(property: KProperty<*>, oldValue: Param, newValue: Param) { | |
| if (oldValue != newValue) { | |
| [email protected]() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //forma clásica extrapolada directamente de java | |
| //funcion estatica donde el primer parámetro es la vista y los n siguientes los especificados por le BindingAdapter | |
| @BindingAdapter("bind:url") | |
| fun loadUrl(imageView: ImageView, url: String) { | |
| Picasso.with(imageView.ctx).load(url).transform(CircleTransform()).into(imageView) | |
| } | |
| //opción alternativa | |
| @BindingAdapter("bind:url") | |
| fun ImageView.loadUrl(url: String) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| fun alphaWithBounceAnimator(): ReadWriteProperty<ImageView, Int> = | |
| object : ReadWriteProperty<ImageView, Int> { | |
| override fun getValue(thisRef: ImageView, property: KProperty<*>): Int { | |
| return thisRef.imageAlpha | |
| } | |
| override fun setValue(thisRef: ImageView, property: KProperty<*>, value: Int) { | |
| val animX = ObjectAnimator.ofFloat(thisRef, "scaleX", 1f, 2.5f, 1f) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| fun backgroundColorAnimator(): ReadWriteProperty<View, Int> = | |
| object : ReadWriteProperty<View, Int> { | |
| override fun getValue(thisRef: View, property: KProperty<*>): Int { | |
| return (thisRef.background as? ColorDrawable)?.color ?: 0 | |
| } | |
| override fun setValue(thisRef: View, property: KProperty<*>, value: Int) { | |
| ValueAnimator.ofObject(ArgbEvaluator(), getValue(thisRef, property), value).apply { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| fun List<Number>.getNearestNeighbors(posibleNeighbors: List<List<Number>>, numberOfNeighbors: Int): List<List<Double>> { | |
| return posibleNeighbors.mapIndexed { index, posibleNeighbor -> index to this.pearsonCorrelationWith(posibleNeighbor) } | |
| .sortedBy { it.second } | |
| .take(numberOfNeighbors) | |
| .map { posibleNeighbors[it.first].map { it.toDouble() } } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package com.pascalwelsch.extensions | |
| import android.app.Activity | |
| import android.content.Context | |
| import android.content.Intent | |
| import android.os.Build | |
| import android.os.Bundle | |
| /** | |
| * Extensions for simpler launching of Activities |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import android.content.Context | |
| import android.content.res.Resources | |
| import android.graphics.drawable.Drawable | |
| import android.support.annotation.AnyRes | |
| import android.support.v4.app.Fragment | |
| import android.support.v4.content.res.ResourcesCompat.* | |
| import android.view.View | |
| val Context.animations | |
| get() = ResourceMapper { resources.getAnimation(it) } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package be.brol | |
| import android.os.Binder | |
| import android.os.Bundle | |
| import android.support.v4.app.BundleCompat | |
| import android.support.v4.app.Fragment | |
| /** | |
| * Eases the Fragment.newInstance ceremony by marking the fragment's args with this delegate | |
| * Just write the property in newInstance and read it like any other property after the fragment has been created |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import android.content.ClipData | |
| import android.graphics.Paint | |
| import android.os.Build | |
| import android.os.Bundle | |
| import android.support.v4.view.* | |
| import android.support.v4.view.accessibility.AccessibilityNodeInfoCompat | |
| import android.support.v4.view.accessibility.AccessibilityNodeProviderCompat | |
| import android.view.* | |
| /** |