<commit_before>package com.github.nikolaymakhonin.android_app_example.helpers;

import android.content.Context;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View;

import com.github.florent37.materialviewpager.MaterialViewPagerAnimator;
import com.github.florent37.materialviewpager.MaterialViewPagerHeader;
import com.github.florent37.materialviewpager.MaterialViewPagerHelper;
import com.github.ksoichiro.android.observablescrollview.ObservableScrollView;

public class MaterialScrollView extends ObservableScrollView {

    public MaterialScrollView(Context context) {
        super(context);
        init();
    }

    public MaterialScrollView(Context context, AttributeSet attrs) {
        super(context, attrs);
        init();
    }

    public MaterialScrollView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        init();
    }

    private void init() {
    }

    private MaterialViewPagerAnimator _pagerAnimator;
    private MaterialViewPagerAnimator getPagerAnimator() {
        if (_pagerAnimator == null) {
            _pagerAnimator = MaterialViewPagerHelper.getAnimator(getContext());
        }
        return _pagerAnimator;
    }

    private int getHeaderHeight() {
        //TODO: get current Header height
        return 110;
    }

    private int getMaxHeaderHeight() {
        return getPagerAnimator().getHeaderHeight();
    }

    private int getScrollMax() {
        return Math.round(getPagerAnimator().scrollMax - getHeaderHeight());
    }

    @Override
    public boolean onTouchEvent(MotionEvent event) {
        if (isMaxScroll()) {
            return false;
        }
        return super.onTouchEvent(event);
    }

    @Override
    public boolean onInterceptTouchEvent(MotionEvent ev) {
        if (isMaxScroll()) {
            return false;
        }
        return super.onInterceptTouchEvent(ev);
    }

    @Override
    public boolean onGenericMotionEvent(MotionEvent event) {
        if (isMaxScroll()) {
            return false;
        }
        return super.onGenericMotionEvent(event);
    }

    @Override
    protected void onScrollChanged(int x, int y, int oldX, int oldY) {
        super.onScrollChanged(x, y, oldX, oldY);

        if (isMaxScroll()) {
            scrollVerticallyTo(getScrollMax());
        }
    }

    private boolean isMaxScroll() {
        int scrollY = getCurrentScrollY();
        int scrollMax = getScrollMax();

        return scrollY >= scrollMax;
    }

//    @Override
//    public void scrollVerticallyTo(int y) {
//        int prevHeaderHeight = getHeaderHeight();
//        int prevScrollY = getScrollY();
//
//        super.scrollVerticallyTo(y);
//
//        int newHeaderHeight = getHeaderHeight();
//        int newScrollY = getScrollY();
//
//        int deltaHeight = newHeaderHeight - prevHeaderHeight;
//        int deltaScroll = newScrollY - prevScrollY;
//
//        if (deltaHeight != deltaScroll) {
//            super.scrollVerticallyTo(deltaScroll - deltaHeight);
//        }
//    }
}
<commit_msg>AAE-8 Add simple google map with current user position.<commit_after>package com.github.nikolaymakhonin.android_app_example.helpers;

import android.content.Context;
import android.util.AttributeSet;
import android.view.MotionEvent;

import com.github.florent37.materialviewpager.MaterialViewPagerAnimator;
import com.github.florent37.materialviewpager.MaterialViewPagerHelper;
import com.github.ksoichiro.android.observablescrollview.ObservableScrollView;

public class MaterialScrollView extends ObservableScrollView {

    public MaterialScrollView(Context context) {
        super(context);
        init();
    }

    public MaterialScrollView(Context context, AttributeSet attrs) {
        super(context, attrs);
        init();
    }

    public MaterialScrollView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        init();
    }

    private void init() {
    }

    private MaterialViewPagerAnimator _pagerAnimator;
    private MaterialViewPagerAnimator getPagerAnimator() {
        if (_pagerAnimator == null) {
            _pagerAnimator = MaterialViewPagerHelper.getAnimator(getContext());
        }
        return _pagerAnimator;
    }

    private int getHeaderHeight() {
        //TODO: get current Header height
        return 110;
    }

    private int getMaxHeaderHeight() {
        return getPagerAnimator().getHeaderHeight();
    }

    private int getScrollMax() {
        return Math.round(getPagerAnimator().scrollMax - getHeaderHeight());
    }

    @Override
    public boolean onTouchEvent(MotionEvent event) {
        return onMouseEvent(event);
    }

    @Override
    public boolean onInterceptTouchEvent(MotionEvent event) {
        return onMouseEvent(event);
    }

    @Override
    public boolean onGenericMotionEvent(MotionEvent event) {
        return onMouseEvent(event);
    }

    @Override
    protected void onScrollChanged(int x, int y, int oldX, int oldY) {
        super.onScrollChanged(x, y, oldX, oldY);

        if (isMaxScroll()) {
            scrollVerticallyTo(getScrollMax());
        }
    }

    private boolean isMaxScroll() {
        int scrollY = getCurrentScrollY();
        int scrollMax = getScrollMax();

        return scrollY >= scrollMax;
    }

    private float _lastMotionX;
    private float _lastMotionY;

    private boolean onMouseEvent(MotionEvent event) {
        switch (event.getAction()) {
            case MotionEvent.ACTION_MOVE:
                float x = event.getX();
                float y = event.getY();

                float dy = y - _lastMotionY;
                if (dy < 0) {
                    scrollVerticallyTo(Math.round(getCurrentScrollY() - dy));
                }

                _lastMotionX = x;
                _lastMotionY = y;
                break;
            case MotionEvent.ACTION_DOWN:
                _lastMotionX = event.getX();
                _lastMotionY = event.getY();
                break;
        }

        return false;
    }
}

{'fraction_non_alphanumeric': 0.0908195105928724, 'fraction_numerical': 0.0029561504352110363, 'mean_word_length': 2.522267206477733, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '6446228', 'n_tokens_mistral': 1731, 'n_tokens_neox': 1662, 'n_words': 360}