Search in sources :

Example 1 with JFieldRef

use of com.helger.jcodemodel.JFieldRef in project androidannotations by androidannotations.

the class ViewByIdHandler method assignValue.

@Override
public void assignValue(JBlock targetBlock, IJAssignmentTarget fieldRef, EComponentWithViewSupportHolder holder, Element element, Element param) {
    TypeMirror uiFieldTypeMirror = param.asType();
    JFieldRef idRef = annotationHelper.extractOneAnnotationFieldRef(element, IRClass.Res.ID, true);
    AbstractJClass viewClass = codeModelHelper.typeMirrorToJClass(uiFieldTypeMirror);
    IJAssignmentTarget viewHolderTarget = null;
    if (element.getKind() == ElementKind.FIELD) {
        viewHolderTarget = fieldRef;
    }
    FoundViewHolder viewHolder = holder.getFoundViewHolder(idRef, viewClass, viewHolderTarget);
    if (!viewHolder.getRef().equals(viewHolderTarget)) {
        targetBlock.add(fieldRef.assign(viewHolder.getOrCastRef(viewClass)));
    }
}
Also used : JFieldRef(com.helger.jcodemodel.JFieldRef) TypeMirror(javax.lang.model.type.TypeMirror) IJAssignmentTarget(com.helger.jcodemodel.IJAssignmentTarget) FoundViewHolder(org.androidannotations.holder.FoundViewHolder) AbstractJClass(com.helger.jcodemodel.AbstractJClass)

Example 2 with JFieldRef

use of com.helger.jcodemodel.JFieldRef in project androidannotations by androidannotations.

the class OptionsItemHandler method process.

@Override
public void process(Element element, HasOptionsMenu holder) {
    String methodName = element.getSimpleName().toString();
    ExecutableElement executableElement = (ExecutableElement) element;
    List<? extends VariableElement> parameters = executableElement.getParameters();
    TypeMirror returnType = executableElement.getReturnType();
    boolean returnMethodResult = returnType.getKind() != TypeKind.VOID;
    boolean hasItemParameter = parameters.size() == 1;
    List<JFieldRef> idsRefs = annotationHelper.extractAnnotationFieldRefs(element, IRClass.Res.ID, true);
    JBlock block = holder.getOnOptionsItemSelectedMiddleBlock();
    IJExpression ifExpr = holder.getOnOptionsItemSelectedItemId().eq(idsRefs.get(0));
    for (int i = 1; i < idsRefs.size(); i++) {
        ifExpr = ifExpr.cor(holder.getOnOptionsItemSelectedItemId().eq(idsRefs.get(i)));
    }
    JBlock itemIfBody = block._if(ifExpr)._then();
    JInvocation methodCall = invoke(methodName);
    if (returnMethodResult) {
        itemIfBody._return(methodCall);
    } else {
        itemIfBody.add(methodCall);
        itemIfBody._return(TRUE);
    }
    if (hasItemParameter) {
        methodCall.arg(holder.getOnOptionsItemSelectedItem());
    }
}
Also used : JFieldRef(com.helger.jcodemodel.JFieldRef) TypeMirror(javax.lang.model.type.TypeMirror) ExecutableElement(javax.lang.model.element.ExecutableElement) JBlock(com.helger.jcodemodel.JBlock) IJExpression(com.helger.jcodemodel.IJExpression) JInvocation(com.helger.jcodemodel.JInvocation)

Example 3 with JFieldRef

use of com.helger.jcodemodel.JFieldRef in project androidannotations by androidannotations.

the class OptionsMenuItemHandler method assignValue.

@Override
public void assignValue(JBlock targetBlock, IJAssignmentTarget fieldRef, HasOptionsMenu holder, Element element, Element param) {
    JVar menuParam = holder.getOnCreateOptionsMenuMenuParam();
    JFieldRef idsRef = annotationHelper.extractOneAnnotationFieldRef(element, IRClass.Res.ID, true);
    targetBlock.add(fieldRef.assign(menuParam.invoke("findItem").arg(idsRef)));
}
Also used : JFieldRef(com.helger.jcodemodel.JFieldRef) JVar(com.helger.jcodemodel.JVar)

Example 4 with JFieldRef

use of com.helger.jcodemodel.JFieldRef in project androidannotations by androidannotations.

the class PageScrolledHandler method process.

@Override
public void process(Element element, EComponentWithViewSupportHolder holder) throws Exception {
    String methodName = element.getSimpleName().toString();
    ExecutableElement executableElement = (ExecutableElement) element;
    List<? extends VariableElement> parameters = executableElement.getParameters();
    int positionParameterPosition = -1;
    int positionOffsetParameterPosition = -1;
    int positionOffsetPixelsParameterPosition = -1;
    int viewPagerParameterPosition = -1;
    int numberOfIntParameters = 0;
    TypeMirror viewPagerParameterType = null;
    for (int i = 0; i < parameters.size(); i++) {
        VariableElement parameter = parameters.get(i);
        TypeMirror parameterType = parameter.asType();
        if (parameterType.getKind() == TypeKind.INT || CanonicalNameConstants.INTEGER.equals(parameterType.toString())) {
            if (numberOfIntParameters == 0 && positionOffsetParameterPosition == -1) {
                positionParameterPosition = i;
            } else {
                positionOffsetPixelsParameterPosition = i;
            }
            numberOfIntParameters++;
        } else if (parameterType.getKind() == TypeKind.FLOAT || CanonicalNameConstants.FLOAT.equals(parameterType.toString())) {
            positionOffsetParameterPosition = i;
        } else {
            if (isViewPagerParameter(parameterType)) {
                viewPagerParameterPosition = i;
                viewPagerParameterType = parameterType;
            }
        }
    }
    List<JFieldRef> idsRefs = annotationHelper.extractAnnotationFieldRefs(element, IRClass.Res.ID, true);
    for (JFieldRef idRef : idsRefs) {
        PageChangeHolder pageChangeHolder = holder.getPageChangeHolder(idRef, viewPagerParameterType, hasAddOnPageChangeListenerMethod());
        JBlock methodBody = pageChangeHolder.getPageScrolledBody();
        IJExpression activityRef = holder.getGeneratedClass().staticRef("this");
        JInvocation pageScrollCall = methodBody.invoke(activityRef, methodName);
        for (int i = 0; i < parameters.size(); i++) {
            if (i == positionParameterPosition) {
                JVar positionParam = pageChangeHolder.getPageScrolledPositionParam();
                pageScrollCall.arg(positionParam);
            } else if (i == positionOffsetParameterPosition) {
                JVar pageScrolledPositionOffsetParam = pageChangeHolder.getPageScrolledPositionOffsetParam();
                pageScrollCall.arg(pageScrolledPositionOffsetParam);
            } else if (i == positionOffsetPixelsParameterPosition) {
                JVar pageScrolledPositionOffsetPixelsParam = pageChangeHolder.getPageScrolledPositionOffsetPixelsParam();
                pageScrollCall.arg(pageScrolledPositionOffsetPixelsParam);
            } else if (i == viewPagerParameterPosition) {
                JVar viewParameter = pageChangeHolder.getViewPagerVariable();
                pageScrollCall.arg(viewParameter);
            }
        }
    }
}
Also used : JFieldRef(com.helger.jcodemodel.JFieldRef) ExecutableElement(javax.lang.model.element.ExecutableElement) IJExpression(com.helger.jcodemodel.IJExpression) PageChangeHolder(org.androidannotations.holder.PageChangeHolder) JInvocation(com.helger.jcodemodel.JInvocation) VariableElement(javax.lang.model.element.VariableElement) TypeMirror(javax.lang.model.type.TypeMirror) JBlock(com.helger.jcodemodel.JBlock) JVar(com.helger.jcodemodel.JVar)

Example 5 with JFieldRef

use of com.helger.jcodemodel.JFieldRef in project androidannotations by androidannotations.

the class SeekBarProgressChangeHandler method process.

@Override
public void process(Element element, EComponentWithViewSupportHolder holder) throws Exception {
    String methodName = element.getSimpleName().toString();
    ExecutableElement executableElement = (ExecutableElement) element;
    List<? extends VariableElement> parameters = executableElement.getParameters();
    int seekBarViewParameterPosition = -1;
    int progressParameterPosition = -1;
    int fromUserParameterPosition = -1;
    for (int i = 0; i < parameters.size(); i++) {
        VariableElement parameter = parameters.get(i);
        TypeMirror parameterType = parameter.asType();
        if (CanonicalNameConstants.SEEKBAR.equals(parameterType.toString())) {
            seekBarViewParameterPosition = i;
        } else if (parameterType.getKind() == TypeKind.INT || CanonicalNameConstants.INTEGER.equals(parameterType.toString())) {
            progressParameterPosition = i;
        } else if (parameterType.getKind() == TypeKind.BOOLEAN || CanonicalNameConstants.BOOLEAN.equals(parameterType.toString())) {
            fromUserParameterPosition = i;
        }
    }
    List<JFieldRef> idsRefs = annotationHelper.extractAnnotationFieldRefs(element, IRClass.Res.ID, true);
    for (JFieldRef idRef : idsRefs) {
        OnSeekBarChangeListenerHolder onSeekBarChangeListenerHolder = holder.getOnSeekBarChangeListenerHolder(idRef);
        JBlock methodBody = onSeekBarChangeListenerHolder.getOnProgressChangedBody();
        IJExpression activityRef = holder.getGeneratedClass().staticRef("this");
        JInvocation textChangeCall = methodBody.invoke(activityRef, methodName);
        for (int i = 0; i < parameters.size(); i++) {
            if (i == seekBarViewParameterPosition) {
                JVar seekBarViewParameter = onSeekBarChangeListenerHolder.getOnProgressChangedSeekBarParam();
                textChangeCall.arg(seekBarViewParameter);
            } else if (i == progressParameterPosition) {
                JVar progressParameter = onSeekBarChangeListenerHolder.getOnProgressChangedProgressParam();
                textChangeCall.arg(progressParameter);
            } else if (i == fromUserParameterPosition) {
                JVar fromUserParameter = onSeekBarChangeListenerHolder.getOnProgressChangedFromUserParam();
                textChangeCall.arg(fromUserParameter);
            }
        }
    }
}
Also used : OnSeekBarChangeListenerHolder(org.androidannotations.holder.OnSeekBarChangeListenerHolder) JFieldRef(com.helger.jcodemodel.JFieldRef) ExecutableElement(javax.lang.model.element.ExecutableElement) IJExpression(com.helger.jcodemodel.IJExpression) JInvocation(com.helger.jcodemodel.JInvocation) VariableElement(javax.lang.model.element.VariableElement) TypeMirror(javax.lang.model.type.TypeMirror) JBlock(com.helger.jcodemodel.JBlock) JVar(com.helger.jcodemodel.JVar)

Aggregations

JFieldRef (com.helger.jcodemodel.JFieldRef)33 JBlock (com.helger.jcodemodel.JBlock)19 JVar (com.helger.jcodemodel.JVar)16 IJExpression (com.helger.jcodemodel.IJExpression)15 TypeMirror (javax.lang.model.type.TypeMirror)15 JInvocation (com.helger.jcodemodel.JInvocation)14 ExecutableElement (javax.lang.model.element.ExecutableElement)10 VariableElement (javax.lang.model.element.VariableElement)7 AbstractJClass (com.helger.jcodemodel.AbstractJClass)6 JMethod (com.helger.jcodemodel.JMethod)5 JDefinedClass (com.helger.jcodemodel.JDefinedClass)3 JFieldVar (com.helger.jcodemodel.JFieldVar)3 PageChangeHolder (org.androidannotations.holder.PageChangeHolder)3 TextWatcherHolder (org.androidannotations.holder.TextWatcherHolder)3 IJAssignmentTarget (com.helger.jcodemodel.IJAssignmentTarget)2 DataBound (org.androidannotations.annotations.DataBound)2 DefaultRes (org.androidannotations.annotations.sharedpreferences.DefaultRes)2 DefaultString (org.androidannotations.annotations.sharedpreferences.DefaultString)2 BundleHelper (org.androidannotations.helper.BundleHelper)2 FoundPreferenceHolder (org.androidannotations.holder.FoundPreferenceHolder)2