Skip to content

Instantly share code, notes, and snippets.

View frankiesardo's full-sized avatar

Francesco Sardo frankiesardo

View GitHub Profile
@frankiesardo
frankiesardo / QuickReturn.java
Last active December 14, 2015 22:49
A refactored version of LarsWerkman's QuickReturnListView. It should provide an easier to use API and an easier to understand library.
public class QuickReturn {
private final static int ANIMATION_DURATION_MILLIS = 250;
private final ListView listView;
private final View quickReturnView;
private final View headerPlaceholder;
private int itemCount;
private int itemOffsetY[];
@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);
}
@frankiesardo
frankiesardo / Icicle.java
Last active December 20, 2015 23:08
Annotation Processing and Code Generation
@Target(ElementType.FIELD)
@Retention(RetentionPolicy.SOURCE)
public @interface Icicle { }
Element fieldParentClass = element.getEnclosingElement();
Name fieldName = element.getSimpleName();
TypeMirror fieldType = element.asType();
for (Map.Entry<TypeElement, Set<? extends Element>> entry : elementsByContainingClass.entrySet()) {
generateHelperWithClass(entry.getKey()).andElements(entry.getValue());
}
Class<?> helper = Class.forName(helperClassName);
Method helperMethod = helper.getMethod(methodName, classOfTheObjectToHelp, Bundle.class);
helperMethod.invoke(null, objectToHelp, bundle);
class IcicleAssigner {
private final Types typeUtils;
private final Elements elementUtils;
public IcicleAssigner(Types typeUtils, Elements elementUtils) {
this.typeUtils = typeUtils;
this.elementUtils = elementUtils;
}
if (element.getModifiers().contains(Modifier.FINAL) ||
element.getModifiers().contains(Modifier.STATIC) ||
element.getModifiers().contains(Modifier.PRIVATE)) {
error(element, "Field must not be private, static or final");
}
public void process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
for (TypeElement annotation : annotations) {
Set<? extends Element> elements = roundEnv.getElementsAnnotatedWith(annotation);
}
}
apply plugin: 'java'
apply plugin: 'idea'
configurations {
provided
}
idea.module {
scopes.PROVIDED.plus += configurations.provided
}