Or say, how can I prevent movement of HorizontalLineAnnotation when dragging the grip of X1(typically the left grip)?
- zhengyang qu asked 6 years ago
- You must login to post comments
Hi Zhengyang,
You can do this by customizing HozizontalLineAnnotation. There you can override several methods which return IAnnotationAdornerAction depending on where you touched annotation:
class CustomHorizontalLineAnnotation extends HorizontalLineAnnotation {
public CustomHorizontalLineAnnotation(Context context) {
super(context);
}
@Override
protected IAnnotationPlacementStrategy initPlacementStrategy(CoordinateSystem newCoordinateSystem) {
return new CustomPlacementStrategy(this, true);
}
private static class CustomPlacementStrategy extends HorizontalLineAnnotation.CartesianAnnotationPlacementStrategy {
protected CustomPlacementStrategy(HorizontalLineAnnotation annotation, boolean clipAdornerToAnnotationSurface) {
super(annotation, clipAdornerToAnnotationSurface);
}
@Override
protected IAnnotationAdornerAction createAdornerActionForResizingGripWithIndex(int resizingGripIndex, int resizingGripXOffset, int resizingGripYOffset) {
// this is action which is used when you drag resizing grip
// by default it resizes line annotation
// to disable action return null
// return super.createAdornerActionForResizingGripWithIndex(resizingGripIndex, resizingGripXOffset, resizingGripYOffset);
return null;
}
@Override
protected IAnnotationAdornerAction createAdornerActionForAnnotationHit() {
// this is action which is used when you drag line itself
// by default it drags line without resizing
return super.createAdornerActionForAnnotationHit();
}
@Override
protected IAnnotationAdornerAction createAdornerActionForAnnotationLabel(AnnotationLabel label) {
// this is action which is used when you drag annotation label
// by default it drags line
return super.createAdornerActionForAnnotationLabel(label);
}
}
}
You can disable those actions by returning null or empty IAnnotationAdornerAction implementation when you need it.
Is this suitable for your needs?
Best regards,
Yura
- Yura Khariton answered 6 years ago
- last edited 6 years ago
- Thanks, I will have a try. Currently I wrote a stateful OnAnnotationDragListener to reset Y coordinate of the horizontal line.
- You must login to post comments
Well, I think I need to re-implement one more interface to satisfy my need. Code below prevents movement when dragging left grip of a Horizontal Line (will not affect resizing).
class CustomHorizontalLineAnnotation extends HorizontalLineAnnotation {
class CustomAnnotationAdornerAction implements IAnnotationAdornerAction {
private final AnnotationBase annotation;
private final int index;
private float x;
private float y;
public CustomAnnotationAdornerAction(AnnotationBase var1, int var2, float var3) {
annotation = var1;
index = var2;
x = var3;
}
public void onAdornerDragStarted(float xStartPoint, float yStartPoint) {
x += xStartPoint;
y = getYAxis().getCoordinate(annotation.getY1());
}
public void onAdornerDragDelta(float horizontalOffset, float verticalOffset) {
x += horizontalOffset;
annotation.moveBasePointTo(x, y, index);
}
public void onAdornedDragEnded() {
}
}
public CustomHorizontalLineAnnotation(Context context) {
super(context);
}
@Override
protected IAnnotationPlacementStrategy initPlacementStrategy(CoordinateSystem newCoordinateSystem) {
return new CustomPlacementStrategy(this, true);
}
private class CustomPlacementStrategy extends HorizontalLineAnnotation.CartesianAnnotationPlacementStrategy {
protected CustomPlacementStrategy(HorizontalLineAnnotation annotation, boolean clipAdornerToAnnotationSurface) {
super(annotation, clipAdornerToAnnotationSurface);
}
@Override
protected IAnnotationAdornerAction createAdornerActionForResizingGripWithIndex(int resizingGripIndex, int resizingGripXOffset, int resizingGripYOffset) {
// this is action which is used when you drag resizing grip
// by default it resizes line annotation
// to disable action return null
return new CustomAnnotationAdornerAction(this.annotation, resizingGripIndex, resizingGripXOffset);
}
@Override
protected IAnnotationAdornerAction createAdornerActionForAnnotationHit() {
// this is action which is used when you drag line itself
// by default it drags line without resizing
return super.createAdornerActionForAnnotationHit();
}
@Override
protected IAnnotationAdornerAction createAdornerActionForAnnotationLabel(AnnotationLabel label) {
// this is action which is used when you drag annotation label
// by default it drags line
return super.createAdornerActionForAnnotationLabel(label);
}
}
}
- zhengyang qu answered 6 years ago
- I think this could be done more easily.
- You must login to post comments
Please login first to submit.