Skip to content

Instantly share code, notes, and snippets.

Avatar

Francesco Sardo frankiesardo

View GitHub Profile
@frankiesardo
frankiesardo / QuickReturn.java
Last active Dec 14, 2015
A refactored version of LarsWerkman's QuickReturnListView. It should provide an easier to use API and an easier to understand library.
View QuickReturn.java
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 Dec 18, 2015
An Android Button that automatically enables itself when the internet connectivity is on and disables when is off.
View NetworkButton.java
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 Dec 20, 2015
Annotation Processing and Code Generation
View Icicle.java
@Target(ElementType.FIELD)
@Retention(RetentionPolicy.SOURCE)
public @interface Icicle { }
View EnclosingClass.java
Element fieldParentClass = element.getEnclosingElement();
Name fieldName = element.getSimpleName();
TypeMirror fieldType = element.asType();
View HelperGeneration.java
for (Map.Entry<TypeElement, Set<? extends Element>> entry : elementsByContainingClass.entrySet()) {
generateHelperWithClass(entry.getKey()).andElements(entry.getValue());
}
View HelperInvocation.java
Class<?> helper = Class.forName(helperClassName);
Method helperMethod = helper.getMethod(methodName, classOfTheObjectToHelp, Bundle.class);
helperMethod.invoke(null, objectToHelp, bundle);
View IcicleAssigner.java
class IcicleAssigner {
private final Types typeUtils;
private final Elements elementUtils;
public IcicleAssigner(Types typeUtils, Elements elementUtils) {
this.typeUtils = typeUtils;
this.elementUtils = elementUtils;
}
View Modifiers.java
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");
}
View Processor.java
public void process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
for (TypeElement annotation : annotations) {
Set<? extends Element> elements = roundEnv.getElementsAnnotatedWith(annotation);
}
}
View build.gradle
apply plugin: 'java'
apply plugin: 'idea'
configurations {
provided
}
idea.module {
scopes.PROVIDED.plus += configurations.provided
}