Hi,
I’d like to enable AnnotationCreationListener with a toggle button pressed down, and disable it with the button released. It’s different from the Android sample code in Create Annotation Dynamically. I have a few questions when I’m trying to code. I’m not sure if my approach is on the right track. Please advise, thanks.
// insert button listener
insertAnnotationButton = findViewById(R.id.annotationInsertButton);
insertAnnotationButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
// TODO: add chartmodifier/annotationCreationModifier when button pressed down
if (insertAnnotationButton.isChecked()) {
annotationCreationModifier.setAnnotationType(???); // how to set type to vertical line annotation?
DefaultAnnotationFactory annotationFactory = new DefaultAnnotationFactory();
annotationFactory.setFactoryForAnnotationType(DefaultAnnotationFactory.VERTICAL_LINE_ANNOTATION, new IAnnotationFactory() {
@NonNull
@Override
public IAnnotation createAnnotation(@NonNull ISciChartSurface parentSurface, int annotationType) {
return sciChartBuilder.newVerticalLineAnnotation().withIsEditable(true).withStroke(1, White).withVerticalGravity(Gravity.FILL_VERTICAL).build();
}
});
annotationCreationModifier.setAnnotationFactory(annotationFactory);
annotationCreationModifier.setAnnotationCreationListener(new OnAnnotationCreatedListener() {
@Override
public void onAnnotationCreated(IAnnotation iAnnotation) {
// how to get X coordinate of the annotation and update my annotation variable
}
});
ecmSurface.getChartModifiers().add(sciChartBuilder.newModifierGroup().withModifier(annotationCreationModifier)..build());
} else {
// how to remove annotationCreationModifier from ChartModifiers?
ecmSurface.getChartModifiers().remove(???);
}
}
});
- Gang Xu asked 3 years ago
- You must login to post comments
Hi there,
You can enable/disable ChartModifiers using IsEnabled property.
annotationCreationModifier.setIsEnabled(false);
Best regards,
Yura
- Yura Khariton answered 3 years ago
- You must login to post comments
Hi Yura,
I’ve managed to make it work with your way. Thanks.
- Gang Xu answered 3 years ago
- You must login to post comments
Please login first to submit.