Skip to content

Instantly share code, notes, and snippets.

View Takhion's full-sized avatar

Eugenio Marletti Takhion

View GitHub Profile
@Takhion
Takhion / AndroidManifest.xml
Created June 1, 2015 16:34
Task killer for Android
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<application>
<activity android:name=".TaskKiller"/>
</application>
@Takhion
Takhion / WindowAware.java
Created June 3, 2015 09:33
RecyclerView that calls onAttachedToWindow/onDetachedFromWindow on its adapter
public interface WindowAware {
public void onAttachedToWindow();
public void onDetachedFromWindow();
}
@Takhion
Takhion / styles.xml
Created June 3, 2015 15:16
Custom dialog Activity style
<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:tools="http://schemas.android.com/tools">
<style name="CustomDialog" parent="@style/Base.Theme.AppCompat.Light.Dialog.FixedSize">
<item name="android:windowCloseOnTouchOutside">false</item>
<item name="android:windowBackground">@android:color/transparent</item>
<item name="android:windowIsFloating">false</item>
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowClipToOutline">false</item>
@Takhion
Takhion / RetainedObservableActivity.java
Last active September 30, 2016 16:05
Simplest way to retain an active Observable during configuration changes
package me.eugeniomarletti.example;
import android.app.Activity;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.widget.Toast;
import rx.Observable;
import rx.Subscriber;
import rx.Subscription;
import android.animation.TimeInterpolator;
/**
* Interpolator that produces a decaying sine wave oscillating around zero.
*/
public class ShakeInterpolator implements TimeInterpolator {
private static final double AMP, FREQ = 5, DECAY = 6;
static {
@Takhion
Takhion / Test.kt
Created January 22, 2017 15:52
Flat `use` in Kotlin
fun test() {
val lines = use {
val a = File("path1").reader().use
val b = File("path2").reader().use
val c = File("path3").reader().use
a.readLines() + b.readLines() + c.readLines()
}
}
fun test() {
val item1 = Item(GameObject())
val item2 = Item(GameObject())
assert(ItemStack(setOf(item1, item2)) is ItemStack)
assert(ItemStack(setOf(item1)) is Item)
assert(ItemStack(emptySet()) is Empty)
}
class ItemStack private constructor(val items: Set<Item>) : Elem() {
companion object {
import rx.Observable
import rx.subjects.BehaviorSubject
import SingletonObservable.ItemWrapper
/**
* Represents the current subscription status (either 'unsubscribed' or 'subscribed') of a [SingletonObservable].
* The index starts at [SingletonObservable.firstSubscriptionIndex] as 'unsubscribed', and every subsequent value alternates between the two states.
* Use [SingletonObservable.isSubscribed] to calculate the status for a specific [SubscriptionIndex].
*
* Note that a subscription index is constant for the lifetime of a stream, which is completed by the first time either one of
@Takhion
Takhion / demo.dart
Last active August 11, 2022 11:09
[Flutter] TextSelectionLayout (see https://stackoverflow.com/a/46244263/1306903)
// animated GIF: https://i.stack.imgur.com/mHOIc.gif
// see https://stackoverflow.com/a/46244263/1306903
import 'package:flutter/material.dart';
import 'ink_text_selection_layout.dart';
class Demo extends StatelessWidget {
@override
Widget build(context) => inkTextSelectionLayout(
@Takhion
Takhion / SharedPreferencesPropertyDelegate.kt
Created October 13, 2017 07:58
Shared Preferences Kotlin property delegate with injected provider
import android.app.Activity
import kotlin.reflect.KProperty
interface SharedPreferencesWriter //TODO
interface SharedPreferencesWriterProvider {
val sharedPreferencesWriter: SharedPreferencesWriter
fun <T> prefs() = SharedPreferencesPropertyDelegate<T>()
}