Skip to content

Instantly share code, notes, and snippets.

View Eduardo-Nunes's full-sized avatar

Eduardo Souza Nunes Eduardo-Nunes

View GitHub Profile
@Eduardo-Nunes
Eduardo-Nunes / MaskTextWatcher.kt
Last active February 4, 2020 19:04
Mast Text in Android without losing any char inputed
class MaskTextWatcher(private val mask: String) : TextWatcher {
private var isRunning = false
private var isDeleting = false
override fun beforeTextChanged(charSequence: CharSequence, start: Int, count: Int, after: Int) {
isDeleting = count > after
}
override fun onTextChanged(charSequence: CharSequence, start: Int, before: Int, count: Int) {}
@Eduardo-Nunes
Eduardo-Nunes / StringExt.kt
Created February 4, 2020 19:02
String with double spacing with Kotlin
fun String.doubleSpacing(): String {
var self = ""
this.forEachIndexed { index, character ->
self = if (index == 0) "$character" else "$self $character"
}
return self
}
boolean exit;
appBar.addOnOffsetChangedListener(new AppBarLayout.OnOffsetChangedListener() {
@Override
public void onOffsetChanged(AppBarLayout appBarLayout, int verticalOffset) {
Log.d("onOffsetChanged", "appbar verticalOffset: " + verticalOffset);
if (verticalOffset == 0 && !exit) {
AppBarLayout.LayoutParams params = (AppBarLayout.LayoutParams) collapsingToolbar.getLayoutParams();
open class DeactivatedViewPager(
context: Context,
attrs: AttributeSet? = null
) : ViewPager(context, attrs) {
var isPagingEnabled = false
override fun onTouchEvent(ev: MotionEvent?): Boolean {
if (ev?.action == MotionEvent.ACTION_UP) performClick()
return isPagingEnabled && super.onTouchEvent(ev)
@Eduardo-Nunes
Eduardo-Nunes / LazyObserver.kt
Last active June 30, 2020 17:24
Lifecycle observer lazy instance with Kotlin
import androidx.lifecycle.LifecycleOwner
import androidx.lifecycle.Observer
infix fun <T : Any?> LifecycleOwner.lazyObserver(func: (T) -> Unit): Lazy<Observer<T>> {
return lazyOf(Observer(func))
}
package com.mynuapp;
import android.app.AlertDialog;
import android.app.Service;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.location.Address;
import android.location.Geocoder;
@Eduardo-Nunes
Eduardo-Nunes / SimpleTimer.kt
Last active November 18, 2020 20:07
SimpleTimer for make repeatable tasks or not, in Android without break or stops MainThread
import java.util.Timer
import java.util.TimerTask
import kotlin.concurrent.timerTask
private const val DEFAULT_EXECUTION_RATE = 6000L
class SimpleTimer {
var executionRate = DEFAULT_EXECUTION_RATE
private var mTrigger: (() -> Unit)? = null