Android Open Source - android-image-crop-library Horizontal Handle Helper






From Project

Back to project page android-image-crop-library.

License

The source code is released under:

Apache License

If you think the Android project android-image-crop-library listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

/*
 * Copyright 2013, Edmodo, Inc. //w ww.  j  av a2s . com
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this work except in compliance with the License.
 * You may obtain a copy of the License in the LICENSE file, or at:
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" 
 * BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language 
 * governing permissions and limitations under the License. 
 */

package com.edmodo.cropper.cropwindow.handle;

import android.graphics.Rect;

import com.edmodo.cropper.cropwindow.edge.Edge;
import com.edmodo.cropper.util.AspectRatioUtil;

/**
 * Handle helper class to handle horizontal handles (i.e. top and bottom
 * handles).
 */
class HorizontalHandleHelper extends HandleHelper {

    // Member Variables ////////////////////////////////////////////////////////

    private Edge mEdge;

    // Constructor /////////////////////////////////////////////////////////////

    HorizontalHandleHelper(Edge edge) {
        super(edge, null);
        mEdge = edge;
    }

    // HandleHelper Methods ////////////////////////////////////////////////////

    @Override
    void updateCropWindow(float x,
                          float y,
                          float targetAspectRatio,
                          Rect imageRect,
                          float snapRadius) {

        // Adjust this Edge accordingly.
        mEdge.adjustCoordinate(x, y, imageRect, snapRadius, targetAspectRatio);

        float left = Edge.LEFT.getCoordinate();
        float top = Edge.TOP.getCoordinate();
        float right = Edge.RIGHT.getCoordinate();
        float bottom = Edge.BOTTOM.getCoordinate();

        // After this Edge is moved, our crop window is now out of proportion.
        final float targetWidth = AspectRatioUtil.calculateWidth(top, bottom, targetAspectRatio);
        final float currentWidth = right - left;

        // Adjust the crop window so that it maintains the given aspect ratio by
        // moving the adjacent edges symmetrically in or out.
        final float difference = targetWidth - currentWidth;
        final float halfDifference = difference / 2;
        left -= halfDifference;
        right += halfDifference;

        Edge.LEFT.setCoordinate(left);
        Edge.RIGHT.setCoordinate(right);

        // Check if we have gone out of bounds on the sides, and fix.
        if (Edge.LEFT.isOutsideMargin(imageRect, snapRadius) && !mEdge.isNewRectangleOutOfBounds(Edge.LEFT,
                                                                                                 imageRect,
                                                                                                 targetAspectRatio)) {
            final float offset = Edge.LEFT.snapToRect(imageRect);
            Edge.RIGHT.offset(-offset);
            mEdge.adjustCoordinate(targetAspectRatio);

        }
        if (Edge.RIGHT.isOutsideMargin(imageRect, snapRadius) && !mEdge.isNewRectangleOutOfBounds(Edge.RIGHT,
                                                                                                  imageRect,
                                                                                                  targetAspectRatio)) {
            final float offset = Edge.RIGHT.snapToRect(imageRect);
            Edge.LEFT.offset(-offset);
            mEdge.adjustCoordinate(targetAspectRatio);
        }
    }
}




Java Source Code List

co.kr.keypin.util.MediaUriFinder.java
co.kr.keypin.util.PhotoCropActivity.java
co.kr.keypin.util.PhotoTakerUtils.java
co.kr.keypin.util.PhotoTaker.java
com.edmodo.cropper.CropImageView.java
com.edmodo.cropper.cropwindow.CropOverlayView.java
com.edmodo.cropper.cropwindow.edge.EdgePair.java
com.edmodo.cropper.cropwindow.edge.Edge.java
com.edmodo.cropper.cropwindow.handle.CenterHandleHelper.java
com.edmodo.cropper.cropwindow.handle.CornerHandleHelper.java
com.edmodo.cropper.cropwindow.handle.HandleHelper.java
com.edmodo.cropper.cropwindow.handle.Handle.java
com.edmodo.cropper.cropwindow.handle.HorizontalHandleHelper.java
com.edmodo.cropper.cropwindow.handle.VerticalHandleHelper.java
com.edmodo.cropper.util.AspectRatioUtil.java
com.edmodo.cropper.util.HandleUtil.java
com.edmodo.cropper.util.ImageViewUtil.java
com.edmodo.cropper.util.PaintUtil.java