Skip to content

Instantly share code, notes, and snippets.

@cuub
cuub / FadeOutTextView.kt
Created September 17, 2019 16:11
Custom TextView that fades the final part of the text on the last line. maxLines attribute is required
import android.content.Context
import android.graphics.*
import android.support.v7.widget.AppCompatTextView
import android.text.Layout
import android.util.AttributeSet
class FadeOutTextView @JvmOverloads constructor(
context: Context,
attrs: AttributeSet? = null,
defStyleAttribute: Int = android.R.attr.textViewStyle
@cuub
cuub / LiveDataShotOnce.kt
Created September 17, 2019 16:01
A lifecycle-aware observable that sends the event only once to all observers. Similar o SingleLiveEvent but supporting multiple observers.
class LiveDataShotOnce<T> : MutableLiveData<T>() {
private val observerWrapperMap = WeakHashMap<Observer<in T>, ObserverWrapper<in T>>()
@MainThread
override fun observe(owner: LifecycleOwner, observer: Observer<in T>) {
val observerWrapper = ObserverWrapper(observer)
observerWrapperMap[observer] = observerWrapper
super.observe(owner, observerWrapper)
}
@cuub
cuub / PrintMe
Last active August 29, 2015 14:09
Helper class to print any object you want
/**
* <b>Helper class to print any object you want</b>
*/
public class PrintMe {
static StringBuilder result;
static String newLine = System.getProperty("line.separator");
static ConcurrentLinkedQueue<Object> objects = new ConcurrentLinkedQueue<Object>();
private PrintMe() {
}
private static final int PEEK_DRAWER_TIME_SECONDS = 2;
private long downTime;
private long eventTime;
private float x = 0.0f;
private float y = 100.0f;
private int metaState = 0;
protected void peekDrawer() {
downTime = SystemClock.uptimeMillis();
eventTime = SystemClock.uptimeMillis() + 100;