use of com.android.tools.sherpa.animation.AnimatedDestroyCircle in project android by JetBrains.
the class MouseInteraction method mouseReleased.
/**
* Mouse release handling
*
* @param x mouse x coordinate
* @param y mouse y coordinate
*/
public void mouseReleased(int x, int y) {
for (ConstraintWidget widget : mWidgetsScene.getWidgets()) {
getDecorator(widget).setShowActions(true);
}
boolean longPress = false;
if (System.currentTimeMillis() - mPressTime > LONG_PRESS_THRESHOLD) {
longPress = true;
}
if (mMouseMode == MouseMode.INACTIVE) {
return;
}
if (mAutoConnect) {
// Auto-connect to candidates
for (SnapCandidate candidate : mWidgetMotion.getSnapCandidates()) {
if (!candidate.source.isConnectionAllowed(candidate.target.getOwner())) {
continue;
}
int margin = candidate.margin;
if (candidate.padding != 0) {
margin = candidate.padding;
}
margin = Math.abs(margin);
ConstraintWidget widget = candidate.source.getOwner();
widget.connect(candidate.source, candidate.target, margin, ConstraintAnchor.AUTO_CONSTRAINT_CREATOR);
mSelection.addModifiedWidget(candidate.source.getOwner());
}
// it's safer to do it this way)
for (ConstraintWidget widget : mSelection.getModifiedWidgets()) {
for (ConstraintAnchor anchor : widget.getAnchors()) {
if (!anchor.isConnected()) {
continue;
}
if (anchor.getConnectionCreator() != ConstraintAnchor.AUTO_CONSTRAINT_CREATOR) {
continue;
}
WidgetDecorator.getConstraintHandle(anchor).startLock();
}
}
}
mWidgetMotion.mouseReleased();
mWidgetResize.mouseReleased();
mSceneDraw.mouseReleased();
// First check anchors that are not guidelines, to deal with the case
// where we want to delete the connection
mClickListener.clearSelection();
mClickListener.find(mViewTransform.getSwingFX(x), mViewTransform.getSwingFY(y));
ConstraintAnchor anchor = mClickListener.getConstraintAnchor();
if (mSelection.getSelectedAnchor() != null && mSelection.getConnectionCandidateAnchor() == null && anchor == mSelection.getSelectedAnchor() && !longPress) {
// delete the anchor connection
if (mSelection.getSelectedAnchor().isConnected() && mSelection.getSelectedAnchor().getTarget() == mSelection.getSelectedAnchorInitialTarget()) {
ConstraintWidget widget = mSelection.getSelectedAnchor().getOwner();
ConstraintAnchor selectedAnchor = mSelection.getSelectedAnchor();
if (selectedAnchor.isVerticalAnchor()) {
widget.setVerticalBiasPercent(0.5f);
} else {
widget.setHorizontalBiasPercent(0.5f);
}
widget.resetAnchor(selectedAnchor);
ConstraintHandle selectedHandle = WidgetInteractionTargets.constraintHandle(selectedAnchor);
if (mSelection.getSelectedAnchor().getType() == ConstraintAnchor.Type.BASELINE) {
mSceneDraw.getChoreographer().addAnimation(new AnimatedDestroyLine(selectedHandle));
} else {
mSceneDraw.getChoreographer().addAnimation(new AnimatedDestroyCircle(selectedHandle));
}
mSelection.addModifiedWidget(widget);
}
}
// If we hit a widget, update the selection
ConstraintWidget widget = mClickListener.mHitWidget;
if (widget != null) {
if (mMouseMode == MouseMode.SELECT) {
if (!mSelection.contains(widget)) {
// replace the current selection
if (!(isShiftDown() || isControlDown())) {
mSelection.clear();
}
mSelection.add(widget);
} else if (isControlDown()) {
mSelection.remove(widget);
}
}
}
if (mSelection.isEmpty() && mSelection.getSelectedAnchor() == null) {
int x1 = Math.min(getStartPoint().x, getLastPoint().x);
int x2 = Math.max(getStartPoint().x, getLastPoint().x);
int y1 = Math.min(getStartPoint().y, getLastPoint().y);
int y2 = Math.max(getStartPoint().y, getLastPoint().y);
Rectangle selectionRect = new Rectangle();
selectionRect.setBounds(x1, y1, x2 - x1, y2 - y1);
if (selectionRect.width > 0 && selectionRect.height > 0) {
ArrayList<ConstraintWidget> selection = mWidgetsScene.findWidgets(mWidgetsScene.getRoot(), selectionRect.x, selectionRect.y, selectionRect.width, selectionRect.height);
for (ConstraintWidget w : selection) {
mSelection.add(w);
}
}
}
if (mSelection.getSelectedGuideline() != null) {
Rectangle head = mSelection.getSelectedGuideline().getHead();
if (head.contains(getStartPoint().x, getStartPoint().y)) {
Selection.Element element = mSelection.get(mSelection.getSelectedGuideline());
if (element != null) {
if (mSelection.getSelectedGuideline().getOrientation() == Guideline.VERTICAL) {
if (element.origin.x == mSelection.getSelectedGuideline().getDrawX()) {
mSelection.getSelectedGuideline().cyclePosition();
mSelection.addModifiedWidget(mSelection.getSelectedGuideline());
}
} else {
if (element.origin.y == mSelection.getSelectedGuideline().getDrawY()) {
mSelection.getSelectedGuideline().cyclePosition();
mSelection.addModifiedWidget(mSelection.getSelectedGuideline());
}
}
}
}
}
// give a chance to widgets to respond to a mouse press
for (Selection.Element selection : mSelection.getElements()) {
getDecorator(selection.widget).mouseRelease(x, y, mViewTransform, mSelection);
}
for (Selection.Element selection : mSelection.getElements()) {
selection.directionLocked = Selection.DIRECTION_UNLOCKED;
}
mSceneDraw.setCurrentUnderneathAnchor(null);
mMouseMode = MouseMode.INACTIVE;
mSelection.setSelectedAnchor(null);
mSelection.setSelectedResizeHandle(null);
mSelection.setConnectionCandidateAnchor(null);
mSelection.clearBounds();
// in case something did change...
mSelection.selectionHasChanged();
mLastMousePosition.setLocation(0, 0);
mSnapshot = null;
mMouseDown = false;
Animator.setAnimationEnabled(true);
}
Aggregations