DragController.java 文件源码

java
阅读 22 收藏 0 点赞 0 评论 0

项目:FlickLauncher 作者:
/**
 * Determines whether the user flung the current item to delete it.
 *
 * @return the vector at which the item was flung, or null if no fling was detected.
 */
private PointF isFlingingToDelete(DragSource source) {
    if (mFlingToDeleteDropTarget == null) return null;
    if (!source.supportsFlingToDelete()) return null;

    ViewConfiguration config = ViewConfiguration.get(mLauncher);
    mVelocityTracker.computeCurrentVelocity(1000, config.getScaledMaximumFlingVelocity());
    PointF vel = new PointF(mVelocityTracker.getXVelocity(), mVelocityTracker.getYVelocity());
    float theta = MAX_FLING_DEGREES + 1;
    if (mVelocityTracker.getYVelocity() < mFlingToDeleteThresholdVelocity) {
        // Do a quick dot product test to ensure that we are flinging upwards
        PointF upVec = new PointF(0f, -1f);
        theta = getAngleBetweenVectors(vel, upVec);
    } else if (mLauncher.getDeviceProfile().isVerticalBarLayout() &&
            mVelocityTracker.getXVelocity() < mFlingToDeleteThresholdVelocity) {
        // Remove icon is on left side instead of top, so check if we are flinging to the left.
        PointF leftVec = new PointF(-1f, 0f);
        theta = getAngleBetweenVectors(vel, leftVec);
    }
    if (theta <= Math.toRadians(MAX_FLING_DEGREES)) {
        return vel;
    }
    return null;
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号