<commit_before>/*
 * AndroidBottomSheet Copyright 2016 <NAME>
 *
 * This program is free software: you can redistribute it and/or modify it under the terms of the
 * GNU Lesser General Public License as published by the Free Software Foundation, either version 3
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
 * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License along with this program.
 * If not, see <http://www.gnu.org/licenses/>.
 */
package de.mrapp.android.bottomsheet.view;

import android.annotation.TargetApi;
import android.content.Context;
import android.os.Build;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.widget.LinearLayout;

import de.mrapp.android.bottomsheet.BottomSheet;
import de.mrapp.android.util.gesture.DragHelper;

/**
 * The root view of a {@link BottomSheet}, which can be dragged by the user.
 *
 * @author <NAME>
 * @since 1.0.0
 */
public class DraggableView extends LinearLayout {

    /**
     * The ratio between the view's height and the display's height, which is used to calculate the
     * initial height.
     */
    private static final float INITIAL_HEIGHT_RATIO = 9f / 16f;

    /**
     * An instance of the class {@link DragHelper}, which is used to recognize drag gestures.
     */
    private DragHelper dragHelper;

    /**
     * The view's maximum initial height in pixels.
     */
    private int initialHeight;

    /**
     * Initializes the view.
     */
    private void initialize() {
        dragHelper = new DragHelper(0);
        initialHeight =
                Math.round(getResources().getDisplayMetrics().heightPixels * INITIAL_HEIGHT_RATIO);
    }

    /**
     * Handles when a drag gesture is performed by the user.
     *
     * @param dragPosition
     *         The current vertical position of the drag gesture as a {@link Float} value
     * @return True, if the view has been moved by the drag gesture, false otherwise
     */
    private boolean handleDrag(final float dragPosition) {
        if (getAnimation() == null) {
            dragHelper.update(dragPosition);

            if (dragHelper.hasThresholdBeenReached()) {
                int left = getLeft();
                int right = getRight();
                int bottom = getBottom();
                int top = bottom - initialHeight + dragHelper.getDistance();
                top = Math.max(top, 0);
                top = Math.min(top, bottom);
                layout(left, top, right, bottom);
                return true;
            }
        }

        return false;
    }<commit_msg>The grid view is not scrolled before dragging the bottom sheet anymore.<commit_after>/*
 * AndroidBottomSheet Copyright 2016 <NAME>
 *
 * This program is free software: you can redistribute it and/or modify it under the terms of the
 * GNU Lesser General Public License as published by the Free Software Foundation, either version 3
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
 * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License along with this program.
 * If not, see <http://www.gnu.org/licenses/>.
 */
package de.mrapp.android.bottomsheet.view;

import android.annotation.TargetApi;
import android.content.Context;
import android.os.Build;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.widget.LinearLayout;

import de.mrapp.android.bottomsheet.BottomSheet;
import de.mrapp.android.util.gesture.DragHelper;

/**
 * The root view of a {@link BottomSheet}, which can be dragged by the user.
 *
 * @author <NAME>
 * @since 1.0.0
 */
public class DraggableView extends LinearLayout {

    /**
     * The ratio between the view's height and the display's height, which is used to calculate the
     * initial height.
     */
    private static final float INITIAL_HEIGHT_RATIO = 9f / 16f;

    /**
     * An instance of the class {@link DragHelper}, which is used to recognize drag gestures.
     */
    private DragHelper dragHelper;

    /**
     * The view's maximum initial height in pixels.
     */
    private int initialHeight;

    /**
     * Initializes the view.
     */
    private void initialize() {
        dragHelper = new DragHelper(0);
        initialHeight =
                Math.round(getResources().getDisplayMetrics().heightPixels * INITIAL_HEIGHT_RATIO);
    }

    /**
     * Handles when a drag gesture is performed by the user.
     *
     * @param dragPosition
     *         The current vertical position of the drag gesture as a {@link Float} value
     * @return True, if the view has been moved by the drag gesture, false otherwise
     */
    private boolean handleDrag(final float dragPosition) {
        if (getAnimation() == null) {
            dragHelper.update(dragPosition);

            if (dragHelper.hasThresholdBeenReached()) {
                int left = getLeft();
                int right = getRight();
                int bottom = getBottom();
                int top = bottom - initialHeight + dragHelper.getDistance();
                top = Math.max(top, 0);
                top = Math.min(top, bottom);
                layout(left, top, right, bottom);
            }

            return true;
        }

        return false;
    }
{'fraction_non_alphanumeric': 0.08436179205409974, 'fraction_numerical': 0.004395604395604396, 'mean_word_length': 2.6383763837638377, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5901163', 'n_tokens_mistral': 1562, 'n_tokens_neox': 1503, 'n_words': 597}