Skip to content

Instantly share code, notes, and snippets.

@blundell
blundell / WatchFaceLifecycle-ExampleActivity.java
Last active August 29, 2015 14:03
Unofficial Base WatchFace Listener
public class ExampleActivity extends Activity implements WatchFaceLifecycle.Listener {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_my_layout);
WatchFaceLifecycle.attach(this, savedInstanceState, this);
}
@Override
@frankiesardo
frankiesardo / NetworkButton.java
Last active December 18, 2015 18:18
An Android Button that automatically enables itself when the internet connectivity is on and disables when is off.
public class NetworkButton extends Button {
// See Otto's sample application for how BusProvider works. Any mechanism
// for getting a singleton instance will work.
Bus bus = BusProvider.get();
public NetworkButton(Context context, AttributeSet attrs) {
super(context, attrs);
}
package com.example;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
public abstract class EndlessRecyclerViewOnScrollListener extends RecyclerView.OnScrollListener {
private int previousTotal = 0; // The total number of items in the dataset after the last load
private boolean loading = true; // True if we are still waiting for the last set of data to load.
private int visibleThreshold = 5; // The minimum amount of items to have below your current scroll position before loading more.
@b95505017
b95505017 / OkHttpDataSource.java
Last active February 15, 2016 08:48
Extend HttpDataSource of ExoPlayer, using Square's OkHttpClient + Facebook's Stetho
package com.google.android.exoplayer.demo;
import com.facebook.stetho.okhttp.StethoInterceptor;
import com.google.android.exoplayer.C;
import com.google.android.exoplayer.upstream.DataSpec;
import com.google.android.exoplayer.upstream.DefaultHttpDataSource;
import com.google.android.exoplayer.upstream.HttpDataSource;
import com.google.android.exoplayer.upstream.TransferListener;
import com.google.android.exoplayer.util.Assertions;
import com.google.android.exoplayer.util.Predicate;
@romainpiel
romainpiel / build.gradle
Created March 8, 2016 18:10
Start/stop genymotion devices just to run the tests
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.genymotion:plugin:1.0'
}
}
apply plugin: "genymotion"
final PublishRelay<String> refreshRelay = PublishRelay.create()
void refreshData() {
refreshRelay.call("refresh event")
}
Observable<Lce<Data>> getDataEventStream() {
return refreshRelay
.startWith("initial")
.switchMap { event ->
public void onAttach(View view) {
// Remember to clean the subscription!
repository.getDataEventStream().subscribe({ event ->
if (event.isLoading) {
view.showLoading(true)
} else if (event.hasError()) {
view.showError(event.getError())
} else {
view.showData(event.getData())
}
@vovkab
vovkab / android-memory-class
Last active June 12, 2017 09:46
Android device memory class
ActivityManager manager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
int memoryClass = manager.getMemoryClass();
48 - Samsung Nexus S
64 - Samsung Galaxy Nexus
Samsung S2
Samsung S3
128 - Samsung S4
@BrantApps
BrantApps / oceanlife-activity-fragment.graphml
Last active February 27, 2018 18:08
Degraph configuration file used within BrantApps/OceanLife to isolate and visualise package tangle. See http://blog.schauderhaft.de/degraph/ & https://github.com/schauder/degraph
output = oceanlife-activity-fragment.graphml
classpath = ../../../OceanLife/app/build/intermediates/classes/withAmazon/debug/com/brantapps/oceanlife/
# Don’t model dependencies
exclude = java*.**
exclude = android*.**
exclude = dagger*.**
exclude = rx*.**
exclude = okhttp*.**
exclude = org*.**
@sddamico
sddamico / LICENSE
Last active April 29, 2018 04:26
Exponential Backoff Transformer
Copyright (c) 2016 Stephen D'Amico
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE