Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Copyright (C) 2010-2011 eBusiness Information, Excilys Group Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed To in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
 
 package com.googlecode.androidannotations.processing;
 
 import java.util.List;
 
 

Author(s):
Benjamin Fellous
Pierre-Yves Ricau
Mathieu Boniface
 
 public class LongClickProcessor extends MultipleResIdsBasedProcessor implements ElementProcessor {
 
 	public LongClickProcessor(IRClass rClass) {
 		super(rClass);
 	}
 
 	public Class<? extends AnnotationgetTarget() {
 		return LongClick.class;
 	}
 
 	public void process(Element elementJCodeModel codeModelEBeansHolder activitiesHolder) {
 		EBeanHolder holder = activitiesHolder.getEnclosingActivityHolder(element);
 
 		String methodName = element.getSimpleName().toString();
 
 		ExecutableElement executableElement = (ExecutableElementelement;
 		List<? extends VariableElementparameters = executableElement.getParameters();
 		TypeMirror returnType = executableElement.getReturnType();
 		boolean returnMethodResult = returnType.getKind() != .;
 
 		boolean hasItemParameter = parameters.size() == 1;
 
 		LongClick annotation = element.getAnnotation(LongClick.class);
 		List<JFieldRefidsRefs = extractQualifiedIds(elementannotation.value(), "LongClicked"holder);
 
 		JDefinedClass listenerClass = codeModel.anonymousClass(holder.refClass("android.view.View.OnLongClickListener"));
 		JMethod listenerMethod = listenerClass.method(.codeModel.BOOLEAN"onLongClick");
 		JClass viewClass = holder.refClass("android.view.View");
 
 		JVar viewParam = listenerMethod.param(viewClass"view");
 
 		JBlock listenerMethodBody = listenerMethod.body();
 
 		JInvocation call = JExpr.invoke(methodName);
 
 		if (returnMethodResult) {
 			listenerMethodBody._return(call);
 		} else {
 			listenerMethodBody.add(call);
 			listenerMethodBody._return(.);
 		}
 
 		if (hasItemParameter) {
 			call.arg(viewParam);
 		}
 
 		for (JFieldRef idRef : idsRefs) {
 			JBlock block = holder.afterSetContentView.body().block();
 			JInvocation findViewById = JExpr.invoke("findViewById");
 
 			JVar view = block.decl(viewClass"view"findViewById.arg(idRef));
 			block._if(view.ne(JExpr._null()))._then().invoke(view"setOnLongClickListener").arg(JExpr._new(listenerClass));
 		}
	}
New to GrepCode? Check out our FAQ X