<commit_before>/*
 * Copyright (C) 2017 Hazuki
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License 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 jp.hazuki.yuzubrowser.webkit;

import android.annotation.TargetApi;
import android.content.Context;
import android.graphics.Canvas;
import android.net.Uri;
import android.support.v4.view.MotionEventCompat;
import android.support.v4.view.NestedScrollingChild;
import android.support.v4.view.NestedScrollingChildHelper;
import android.support.v4.view.ViewCompat;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View;
import android.webkit.CookieManager;
import android.webkit.WebView;

import jp.hazuki.yuzubrowser.utils.DisplayUtils;
import jp.hazuki.yuzubrowser.utils.view.MultiTouchGestureDetector;

public class NormalWebView extends WebView implements CustomWebView, NestedScrollingChild {
    private long id = System.currentTimeMillis();

    private MultiTouchGestureDetector mGestureDetector;
    private OnScrollChangedListener mOnScrollChangedListener;
    private View mTitleBar;

    private int firstY;
    private int mLastY;
    private ScrollController mScrollController;
    private final int[] mScrollOffset = new int[2];
    private final int[] mScrollConsumed = new int[2];
    private int mNestedOffsetY;
    private NestedScrollingChildHelper mChildHelper;
    private boolean firstScroll = true;
    private CustomWebViewClient webViewClient;
    private boolean doubleTapFling;

    private boolean scrollExcessPlay;
    private final int scrollExcessPlayDistance;

    public NormalWebView(Context context) {
        this(context, null);
    }

    public NormalWebView(Context context, AttributeSet attrs) {
        this(context, attrs, android.R.attr.webViewStyle);
    }

    public NormalWebView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        scrollExcessPlayDistance = DisplayUtils.convertDpToPx(context, 14);
        mChildHelper = new NestedScrollingChildHelper(this);
        setNestedScrollingEnabled(true);
    }

    @Override
    protected void onDraw(Canvas c) {
        super.onDraw(c);
    }

    @Override
    public CustomWebBackForwardList copyMyBackForwardList() {
        return new CustomWebBackForwardList(copyBackForwardList());
    }

    @Override
    public void setMyWebChromeClient(CustomWebChromeClient client) {
        setWebChromeClient(client);
    }

    @Override
    public void setMyWebViewClient(CustomWebViewClient client) {
        webViewClient = client;
        setWebViewClient(client);
    }

    @Override
    public void setOnMyCreateContextMenuListener(CustomOnCreateContextMenuListener webContextMenuListener) {
        setOnCreateContextMenuListener(webContextMenuListener);
    }

    @Override
    public View getView() {
        return this;
    }

    @Override
    public WebView getWebView() {
        return this;
    }

    @Override
    public void setSwipeEnable(boolean enable) {
    }

    @Override
    public boolean getSwipeEnable() {
        return false;
    }

    @Override
    public void setGestureDetector(MultiTouchGestureDetector d) {
        mGestureDetector = d;
    }

    @Override
    public void setOnCustomWebViewStateChangeListener(OnWebStateChangeListener l) {
        //do nothing
    }

    @Override
    public boolean setEmbeddedTitleBarMethod(View view) {
        if (mTitleBar != view) {
            if (mTitleBar != null) {
                removeView(mTitleBar);
            }
            if (view != null) {
                addView(view, new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT, 0, 0));
                view.setTranslationX(getScrollX());//can move X
            }
            mTitleBar = view;
        }
        return true;
    }

    @Override
    protected void onScrollChanged(int l, int t, int oldl, int oldt) {
        super.onScrollChanged(l, t, oldl, oldt);
        if (mOnScrollChangedListener != null)
            mOnScrollChangedListener.onScrollChanged(l, t, oldl, oldt);
        if (mTitleBar != null)
            mTitleBar.setTranslationX(l);//can move X
    }

    @Override
    public boolean notifyFindDialogDismissedMethod() {

        return false;
    }

    @Override
    public boolean setOverScrollModeMethod(int arg) {<commit_msg>fix IllegalStateException<commit_after>/*
 * Copyright (C) 2017 Hazuki
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License 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 jp.hazuki.yuzubrowser.webkit;

import android.annotation.TargetApi;
import android.content.Context;
import android.graphics.Canvas;
import android.net.Uri;
import android.support.v4.view.MotionEventCompat;
import android.support.v4.view.NestedScrollingChild;
import android.support.v4.view.NestedScrollingChildHelper;
import android.support.v4.view.ViewCompat;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.webkit.CookieManager;
import android.webkit.WebView;

import jp.hazuki.yuzubrowser.utils.DisplayUtils;
import jp.hazuki.yuzubrowser.utils.view.MultiTouchGestureDetector;

public class NormalWebView extends WebView implements CustomWebView, NestedScrollingChild {
    private long id = System.currentTimeMillis();

    private MultiTouchGestureDetector mGestureDetector;
    private OnScrollChangedListener mOnScrollChangedListener;
    private View mTitleBar;

    private int firstY;
    private int mLastY;
    private ScrollController mScrollController;
    private final int[] mScrollOffset = new int[2];
    private final int[] mScrollConsumed = new int[2];
    private int mNestedOffsetY;
    private NestedScrollingChildHelper mChildHelper;
    private boolean firstScroll = true;
    private CustomWebViewClient webViewClient;
    private boolean doubleTapFling;

    private boolean scrollExcessPlay;
    private final int scrollExcessPlayDistance;

    public NormalWebView(Context context) {
        this(context, null);
    }

    public NormalWebView(Context context, AttributeSet attrs) {
        this(context, attrs, android.R.attr.webViewStyle);
    }

    public NormalWebView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        scrollExcessPlayDistance = DisplayUtils.convertDpToPx(context, 14);
        mChildHelper = new NestedScrollingChildHelper(this);
        setNestedScrollingEnabled(true);
    }

    @Override
    protected void onDraw(Canvas c) {
        super.onDraw(c);
    }

    @Override
    public CustomWebBackForwardList copyMyBackForwardList() {
        return new CustomWebBackForwardList(copyBackForwardList());
    }

    @Override
    public void setMyWebChromeClient(CustomWebChromeClient client) {
        setWebChromeClient(client);
    }

    @Override
    public void setMyWebViewClient(CustomWebViewClient client) {
        webViewClient = client;
        setWebViewClient(client);
    }

    @Override
    public void setOnMyCreateContextMenuListener(CustomOnCreateContextMenuListener webContextMenuListener) {
        setOnCreateContextMenuListener(webContextMenuListener);
    }

    @Override
    public View getView() {
        return this;
    }

    @Override
    public WebView getWebView() {
        return this;
    }

    @Override
    public void setSwipeEnable(boolean enable) {
    }

    @Override
    public boolean getSwipeEnable() {
        return false;
    }

    @Override
    public void setGestureDetector(MultiTouchGestureDetector d) {
        mGestureDetector = d;
    }

    @Override
    public void setOnCustomWebViewStateChangeListener(OnWebStateChangeListener l) {
        //do nothing
    }

    @Override
    public boolean setEmbeddedTitleBarMethod(View view) {
        if (mTitleBar != view) {
            if (mTitleBar != null) {
                removeView(mTitleBar);
            }
            if (view != null) {
                if (view.getParent() != null) {
                    ((ViewGroup) view.getParent()).removeView(view);
                }
                addView(view, new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT, 0, 0));
                view.setTranslationX(getScrollX());//can move X
            }
            mTitleBar = view;
        }
        return true;
    }

    @Override
    protected void onScrollChanged(int l, int t, int oldl, int oldt) {
        super.onScrollChanged(l, t, oldl, oldt);
        if (mOnScrollChangedListener != null)
            mOnScrollChangedListener.onScrollChanged(l, t, oldl, oldt);
        if (mTitleBar != null)
            mTitleBar.setTranslationX(l);//can move X
    }

    @Override
    public boolean notifyFindDialogDismissedMethod() {

        return false;
    }

    @Override
    public boolean setOverScrollModeMethod(int arg) {
{'fraction_non_alphanumeric': 0.07622448979591837, 'fraction_numerical': 0.003673469387755102, 'mean_word_length': 3.2227488151658767, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '1792115', 'n_tokens_mistral': 2774, 'n_tokens_neox': 2682, 'n_words': 702}