Skip to content

Instantly share code, notes, and snippets.

View webserveis's full-sized avatar

Webserveis webserveis

View GitHub Profile
@webserveis
webserveis / JaroWinklerScore.java
Last active February 8, 2022 10:50
String similary algoritms
public class JaroWinklerScore {
/**
* Applies the Jaro-Winkler distance algorithm to the given strings, providing information about the
* similarity of them.
*
* @param s1 The first string that gets compared. May be <code>null</node> or empty.
* @param s2 The second string that gets compared. May be <code>null</node> or empty.
* @return The Jaro-Winkler score (between 0.0 and 1.0), with a higher value indicating larger similarity.
*
* @author Thomas Trojer <[email protected]>
@webserveis
webserveis / UseCase.kt
Created April 22, 2020 15:33 — forked from DenysZP/UseCase.kt
The implementation of the base UseCase with kotlin coroutines.
import kotlinx.coroutines.*
import kotlin.coroutines.CoroutineContext
abstract class UseCase<T, Params : Any> {
private lateinit var parentJob: Job
private lateinit var params: Params
private var isAttachedToLifecycle = false
private val backgroundContext: CoroutineContext = Dispatchers.IO
private val foregroundContext: CoroutineContext = Dispatchers.Main
@webserveis
webserveis / readme.md
Last active April 15, 2020 20:29
Storage Acces Android Kotlin

Abrir selector de archivos

private val PICK_FILE_REQUEST_CODE = 0x100
...
fun openFilePicker() {
   val intent = Intent(Intent.ACTION_GET_CONTENT)
   intent.type = "*/*"
   //intent.type = "text/plain"
   //intent.type = "text/html"
@webserveis
webserveis / PassCodeDotsIndicator.kt
Created April 15, 2020 11:23
Component PassCodeDotsIndicator
class PassCodeDotsIndicator @JvmOverloads constructor(
context: Context,
attrs: AttributeSet? = null,
defStyleAttr: Int = 0
) : LinearLayout(context, attrs, defStyleAttr) {
annotation class IndicatorType {
@IntDef(FIXED, FILL, FILL_WITH_ANIMATION)
@Retention(AnnotationRetention.SOURCE)
annotation class override
@webserveis
webserveis / BluetoothHelper.kt
Last active June 23, 2020 08:29
Bluetooth Helper implement bluetooth in your Android app
package com.webserveis.mqtthomepresence.helpers
import android.bluetooth.BluetoothAdapter
import android.bluetooth.BluetoothDevice
import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import android.content.IntentFilter
import android.util.Log
@webserveis
webserveis / AndroidLogKotlin.xml
Last active March 31, 2020 13:45
Live template Android Log Kotlin
<templateSet group="AndroidLogKotlin">
<template name="logm" value="android.util.Log.d(TAG, $FORMAT$)" description="Log method name and its arguments" toReformat="true" toShortenFQNames="true">
<variable name="FORMAT" expression="groovyScript(&quot;def params = _2.collect {it + ' = [$' + it + ']'}.join(', '); return '\&quot;' + _1 + '() called' + (params.empty ? '' : ' with: ' + params) + '\&quot;'&quot;, kotlinFunctionName(), functionParameters())" defaultValue="" alwaysStopAt="false" />
<context>
<option name="KOTLIN_STATEMENT" value="true" />
</context>
</template>
<template name="logd" value="android.util.Log.d(TAG, &quot;$METHOD_NAME$: $content$&quot;)" description="Log.d(String)" toReformat="true" toShortenFQNames="true">
<variable name="METHOD_NAME" expression="kotlinFunctionName()" defaultValue="" alwaysStopAt="false" />
<variable name="content" expression="" defaultValue="" alwaysStopAt="true" />
@webserveis
webserveis / BaseViewHolder.kt
Created March 26, 2020 14:02
Empty View for Android's RecyclerView
import android.view.View
import androidx.recyclerview.widget.RecyclerView
abstract class BaseViewHolder<T>(itemView: View) : RecyclerView.ViewHolder(itemView) {
abstract fun bind(item: T)
}
@webserveis
webserveis / MainActivity.kt
Created February 26, 2020 12:14
Foreground Services en Kotlin
package com.webserveis.testservices
import android.os.Bundle
import android.view.Menu
import android.view.MenuItem
import androidx.appcompat.app.AppCompatActivity
import kotlinx.android.synthetic.main.activity_main.*
class MainActivity : AppCompatActivity() {

Para cambiar el tinte de los iconos añadidos a un lado de un TextView

JAVA: Compatible Api < 23

private void setTextViewDrawableColor(@RecentlyNonNull TextView textView,@ColorRes int color) {
        for (Drawable drawable : textView.getCompoundDrawablesRelative()) {
            if (drawable != null) {
                drawable.setColorFilter(new PorterDuffColorFilter(ContextCompat.getColor(textView.getContext(),color), PorterDuff.Mode.SRC_IN));
            }
        }
@webserveis
webserveis / gist:c0d61834232fec7790a4a736813c7b75
Last active December 29, 2022 12:36 — forked from menht/gist:2698877
Install and Uninstall Android applications with Intents

In android source code can get

<activity android:name=".PackageInstallerActivity">
    <intent-filter>
        <action android:name="android.intent.action.VIEW" />
        <category android:name="android.intent.category.DEFAULT" />
        <data android:scheme="content" />
        <data android:scheme="file" />