use of org.androidannotations.holder.EFragmentHolder in project androidannotations by androidannotations.
the class ReceiverHandler method registerAndUnregisterReceiver.
private void registerAndUnregisterReceiver(HasReceiverRegistration holder, Receiver.RegisterAt registerAt, JFieldVar intentFilterField, JFieldVar receiverField, boolean local) {
JBlock registerBlock = null;
JBlock unregisterBlock = null;
if (holder instanceof HasActivityLifecycleMethods) {
HasActivityLifecycleMethods activityLifecycleMethods = (HasActivityLifecycleMethods) holder;
switch(registerAt) {
case OnCreateOnDestroy:
registerBlock = activityLifecycleMethods.getOnCreateAfterSuperBlock();
unregisterBlock = activityLifecycleMethods.getOnDestroyBeforeSuperBlock();
break;
case OnStartOnStop:
registerBlock = activityLifecycleMethods.getOnStartAfterSuperBlock();
unregisterBlock = activityLifecycleMethods.getOnStopBeforeSuperBlock();
break;
case OnResumeOnPause:
registerBlock = activityLifecycleMethods.getOnResumeAfterSuperBlock();
unregisterBlock = activityLifecycleMethods.getOnPauseBeforeSuperBlock();
break;
}
if (holder instanceof EFragmentHolder && registerAt == Receiver.RegisterAt.OnAttachOnDetach) {
EFragmentHolder fragmentHolder = (EFragmentHolder) holder;
registerBlock = fragmentHolder.getOnAttachAfterSuperBlock();
unregisterBlock = fragmentHolder.getOnDetachBeforeSuperBlock();
}
} else {
registerBlock = holder.getStartLifecycleAfterSuperBlock();
unregisterBlock = holder.getEndLifecycleBeforeSuperBlock();
}
IJExpression broadcastManager;
if (local) {
if (getProcessingEnvironment().getElementUtils().getTypeElement(CanonicalNameConstants.LOCAL_BROADCAST_MANAGER) == null) {
broadcastManager = getClasses().ANDROIDX_LOCAL_BROADCAST_MANAGER.staticInvoke("getInstance").arg(holder.getContextRef());
} else {
broadcastManager = getClasses().LOCAL_BROADCAST_MANAGER.staticInvoke("getInstance").arg(holder.getContextRef());
}
} else {
broadcastManager = holder.getContextRef();
}
registerBlock.invoke(broadcastManager, "registerReceiver").arg(receiverField).arg(intentFilterField);
unregisterBlock.invoke(broadcastManager, "unregisterReceiver").arg(receiverField);
}
use of org.androidannotations.holder.EFragmentHolder in project androidannotations by androidannotations.
the class AbstractFragmentByHandler method assignValue.
@Override
public void assignValue(JBlock targetBlock, IJAssignmentTarget fieldRef, EComponentWithViewSupportHolder holder, Element element, Element param) {
TypeMirror elementType = param.asType();
String typeQualifiedName = elementType.toString();
TypeElement nativeFragmentElement = annotationHelper.typeElementFromQualifiedName(CanonicalNameConstants.FRAGMENT);
boolean isNativeFragment = nativeFragmentElement != null && annotationHelper.isSubtype(elementType, nativeFragmentElement.asType());
String fieldName = element.getSimpleName().toString();
if (holder instanceof EFragmentHolder) {
boolean childFragment = annotationHelper.extractAnnotationParameter(element, "childFragment");
String fragmentManagerGetter = childFragment ? "getChildFragmentManager" : "getFragmentManager";
targetBlock.add(fieldRef.assign(cast(getJClass(typeQualifiedName), invoke(fragmentManagerGetter).invoke(findFragmentMethodName).arg(getFragmentId(element, fieldName)))));
} else {
JMethod findFragmentMethod = getFindFragmentMethod(isNativeFragment, holder);
targetBlock.add(fieldRef.assign(cast(getJClass(typeQualifiedName), invoke(findFragmentMethod).arg(getFragmentId(element, fieldName)))));
}
}
Aggregations