Skip to content

Instantly share code, notes, and snippets.

@ZacSweers
ZacSweers / OffsetsWithDirection.kt
Last active February 21, 2019 19:25
Observable stream of AppBarLayout offsets + scroll direction from https://twitter.com/pandanomic/status/898142281106022400
/*
* Here we want to get the appbar offset changes paired with the direction it's moving and
* using RxBinding's great `offsetChanges` API to make an rx Observable of this. The first
* part buffers two while skipping one at a time and emits y delta pairs (cur and prev). Second
* part is just a simple map to pair the offset with the resolved scroll direction comparing
* to the previous offset. This gives us a nice stream of (offset, direction) emissions.
*
* Note that the filter() is important if you manipulate child views of the ABL. If any child
* view requests layout again, it will trigger an emission from the offset listener with the
* same value as before, potentially causing measure/layout/draw thrashing if your logic
@adavis
adavis / CommonExtensions.kt
Last active April 2, 2024 20:51
Common Android Extensions in Kotlin
fun View.visible() {
visibility = View.VISIBLE
}
fun View.invisible() {
visibility = View.INVISIBLE
}
fun View.gone() {
visibility = View.GONE
@Aeonitis
Aeonitis / Android - Screen Overlay Detected Resolution
Last active October 28, 2023 06:05
Resolve Android 'Screen Overlay Detected' issue
Message of Issue: "Screen overlay detected - To change this permission setting you first have to turn off the screen overlay from Settings > Apps"
Scope of issue: This only applies to Android M (6.0/API v23) Or Over
Explanation: Other apps installed on the users device may be utilizing a screen overlay on your phone (e.g. Twilight, Red Moon, etc...)
Screen overlays are virtual layers that cover part or all of screen while another app is in the foreground.
It may be dangerous for android to allow you to to change a sensitive setting while an overlay is active because you may prone to 'tap-jacking'
(i.e. a malicious application displays a fake user interface that seems like it can be interacted with, but actually passes interaction events such as finger taps to a hidden user interface behind it.).
Therefore to improve security, android doesn't allow you to change sensitive settings while an active overlay is detected, unless the user permits the app to do so.
Source: https://commonsware.com/blog/2016/03/24/
@android10
android10 / AndroidApplication.java
Created July 20, 2016 09:56
Android: how to know if your app is completely hidden
public class AndroidApplication extends MultiDexApplication {
public static final String TAG = AndroidApplication.class.getSimpleName();
@Override
public void onCreate() {
super.onCreate();
registerComponentCallbacks(new ComponentCallback());
}
private class ComponentCallback implements ComponentCallbacks2 {
@gabrielemariotti
gabrielemariotti / README.md
Last active February 24, 2021 10:52
How to manage the support libraries in a multi-module projects. Thanks to Fernando Cejas (http://fernandocejas.com/)

Centralize the support libraries dependencies in gradle

Working with multi-modules project, it is very useful to centralize the dependencies, especially the support libraries.

A very good way is to separate gradle build files, defining something like:

root
  --gradleScript
 ----dependencies.gradle
@pyricau
pyricau / OomExceptionHandler.java
Created May 6, 2015 17:18
Dump the heap on OutOfMemoryError crashes in your debug builds.
import android.content.Context;
import android.os.Debug;
import java.io.File;
public class OomExceptionHandler implements Thread.UncaughtExceptionHandler {
private static final String FILENAME = "out-of-memory.hprof";
public static void install(Context context) {
Thread.UncaughtExceptionHandler defaultHandler = Thread.getDefaultUncaughtExceptionHandler();
@dustin-graham
dustin-graham / ApiService.java
Created February 15, 2015 06:17
Infinite Scrolling Android RecyclerView with RxJava
public static Observable<List<String>> paginatedThings(final Observable<Void> onNextObservable) {
return Observable.create(new Observable.OnSubscribe<List<String>>() {
@Override
public void call(final Subscriber<? super List<String>> subscriber) {
onNextObservable.subscribe(new Observer<Void>() {
int latestPage = -1;
@Override
public void onCompleted() {
subscriber.onCompleted();
@joshskeen
joshskeen / gist:0b4a26e3b3d2b01e7130
Last active February 23, 2017 11:14
nested webservice calls: RxJava vs Callbacks
package com.joshskeen.rxjava_example.model;
import java.util.ArrayList;
import java.util.List;
import de.greenrobot.event.EventBus;
import retrofit.Callback;
import retrofit.RetrofitError;
import retrofit.client.Response;
import rx.Observable;