Skip to content

Instantly share code, notes, and snippets.

View FireZenk's full-sized avatar
🌍
Improving the world

Jorge Garrido FireZenk

🌍
Improving the world
View GitHub Profile
PublishSubject<Long> animationTimer;
Subscription animationSubscription;
animationSubscription = Observable.interval(1, TimeUnit.SECONDS)
.observeOn(AndroidSchedulers.mainThread())
.subscribeOn(Schedulers.newThread())
.subscribe(animationTimer = PublishSubject.create());
@FireZenk
FireZenk / Foreground.java
Created September 29, 2016 12:28
Foreground: listen app's became background or foreground changes
package org.firezenk.utils;
import android.app.Activity;
import android.app.Application;
import android.content.Context;
import android.os.Bundle;
import android.os.Handler;
import android.util.Log;
import java.util.List;
onTrimMemory(int level)
case ComponentCallbacks2.TRIM_MEMORY_RUNNING_LOW:
case ComponentCallbacks2.TRIM_MEMORY_RUNNING_CRITICAL:
private static final int DEFAULT_THRESHOLD_PERCENTAGE = 10;
fun totalMemorySize(): Long {
val path: File = Environment.getDataDirectory()
val stat: StatFs = StatFs(path.getPath())
return stat.getBlockCountLong() * stat.getBlockSizeLong()
}
fun isLowMemory(): Boolean {
val memoryLimit: Long = (getTotalInternalMemorySize() * DEFAULT_THRESHOLD_PERCENTAGE) / 100;
return availableMemorySize() <= tenPercentLimit;
}
fun availableMemorySize(): Long {
val path: File = Environment.getDataDirectory()
val stat: StatFs = StatFs(path.getPath())
return stat.getAvailableBlocksLong() * stat.getBlockSizeLong()
}
package {{lowerCase package}}.{{lowerCase feature}};
public class {{properCase feature}}PresenterImpl implements {{properCase feature}}Presenter, {{properCase feature}}Interactor.On{{properCase feature}}FinishedListener {
private {{properCase feature}}View {{lowerCase feature}}View;
private {{properCase feature}}Interactor {{lowerCase feature}}Interactor;
public {{properCase feature}}PresenterImpl({{properCase feature}}View {{lowerCase feature}}View) {
this.{{lowerCase feature}}View = {{lowerCase feature}}View;
this.{{lowerCase feature}}Interactor = new {{properCase feature}}InteractorImpl();
plop.addHelper('lowerCase', (text) => text.toLowerCase());