// Path: app/src/main/java/io/github/marktony/espresso/interfaze/OnFastScrollStateChangeListener.java
// public interface OnFastScrollStateChangeListener {
// 
//     /**
//      * Called when fast scrolling begins
//      */
//     void onFastScrollStart();
// 
//     /**
//      * Called when fast scrolling ends
//      */
//     void onFastScrollStop();
// 
// 
// }
// 
// Path: app/src/main/java/io/github/marktony/espresso/util/DensityUtil.java
// public class DensityUtil {
// 
//     public static int getScreenHeight(Context context) {
//         DisplayMetrics displayMetrics = new DisplayMetrics();
//         ((Activity) context).getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
//         return displayMetrics.heightPixels;
//     }
// 
//     public static int getScreenWidth(Context context) {
//         DisplayMetrics displayMetrics = new DisplayMetrics();
//         ((Activity) context).getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
//         return displayMetrics.widthPixels;
//     }
// 
//     public static int getScreenHeightWithDecorations(Context context) {
//         int heightPixes;
//         WindowManager windowManager = ((Activity) context).getWindowManager();
//         Display display = windowManager.getDefaultDisplay();
//         Point realSize = new Point();
//         try {
//             Display.class.getMethod("getRealSize", Point.class).invoke(display, realSize);
//         } catch (NoSuchMethodException e) {
//             e.printStackTrace();
//         } catch (IllegalAccessException e) {
//             e.printStackTrace();
//         } catch (InvocationTargetException e) {
//             e.printStackTrace();
//         }
//         heightPixes = realSize.y;
//         return heightPixes;
//     }
// 
//     public static int dip2px(Context context, float dpVale) {
//         final float scale = context.getResources().getDisplayMetrics().density;
//         return (int) (dpVale * scale + 0.5f);
//     }
// 
//     public static int getStatusBarHeight(Context context) {
//         Resources resources = context.getResources();
//         int resourcesId = resources.getIdentifier("status_bar_height", "dimen", "android");
//         int height = resources.getDimensionPixelSize(resourcesId);
//         return height;
//     }
// 
//     /**
//      * Converts sp to px
//      *
//      * @param context Context
//      * @param sp  the value in sp
//      * @return int
//      */
//     public static int dip2sp(Context context, float sp) {
//         return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, sp, context.getResources().getDisplayMetrics());
//     }
// 
//     public static int px2dip(Context context, float pxValue) {
//         final float scale = context.getResources().getDisplayMetrics().density;
//         return (int) (pxValue / scale + 0.5f);
//     }
// 
// }


import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.animation.ObjectAnimator;
import android.content.Context;
import android.content.res.Resources;
import android.content.res.TypedArray;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Point;
import android.graphics.Rect;
import android.graphics.Typeface;
import android.support.annotation.ColorInt;
import android.support.v4.content.ContextCompat;
import android.support.v4.view.animation.FastOutLinearInInterpolator;
import android.support.v4.view.animation.LinearOutSlowInInterpolator;
import android.support.v7.widget.RecyclerView;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewConfiguration;
import io.github.marktony.espresso.R;
import io.github.marktony.espresso.interfaze.OnFastScrollStateChangeListener;
import io.github.marktony.espresso.util.DensityUtil;
/*
 *  Copyright(c) 2017 lizhaotailang
 *
 * 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 io.github.marktony.espresso.component;



/**
 * Created by lizhaotailang on 2017/3/24.
 */

public class FastScroller {

    private static final int DEFAULT_AUTO_HIDE_DELAY = 1500;

    private FastScrollRecyclerView mRecyclerView;
    private FastScrollPopup mPopup;

    private int mThumbHeight;
    private int mWidth;

    private Paint mThumb;
    private Paint mTrack;

    private Rect mTmpRect = new Rect();
    private Rect mInvalidateRect = new Rect();
    private Rect mInvalidateTmpRect = new Rect();

    // The inset is the buffer around which a point will still register as a click on the scrollbar
    private int mTouchInset;

    // This is the offset from the top of the scrollbar when the user first starts touching.  To
    // prevent jumping, this offset is applied as the user scrolls.
    private int mTouchOffset;

    private Point mThumbPosition = new Point(-1, -1);
    private Point mOffset = new Point(0, 0);

    private boolean mIsDragging;

    private Animator mAutoHideAnimator;
    private boolean mAnimatingShow;
    private int mAutoHideDelay = DEFAULT_AUTO_HIDE_DELAY;
    private boolean mAutoHideEnabled = true;
    private final Runnable mHideRunnable;

    public FastScroller(Context context, FastScrollRecyclerView recyclerView, AttributeSet attrs) {

        Resources resources = context.getResources();

        mRecyclerView = recyclerView;
        mPopup = new FastScrollPopup(resources, recyclerView);

// Path: app/src/main/java/io/github/marktony/espresso/interfaze/OnFastScrollStateChangeListener.java
// public interface OnFastScrollStateChangeListener {
// 
//     /**
//      * Called when fast scrolling begins
//      */
//     void onFastScrollStart();
// 
//     /**
//      * Called when fast scrolling ends
//      */
//     void onFastScrollStop();
// 
// 
// }
// 
// Path: app/src/main/java/io/github/marktony/espresso/util/DensityUtil.java
// public class DensityUtil {
// 
//     public static int getScreenHeight(Context context) {
//         DisplayMetrics displayMetrics = new DisplayMetrics();
//         ((Activity) context).getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
//         return displayMetrics.heightPixels;
//     }
// 
//     public static int getScreenWidth(Context context) {
//         DisplayMetrics displayMetrics = new DisplayMetrics();
//         ((Activity) context).getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
//         return displayMetrics.widthPixels;
//     }
// 
//     public static int getScreenHeightWithDecorations(Context context) {
//         int heightPixes;
//         WindowManager windowManager = ((Activity) context).getWindowManager();
//         Display display = windowManager.getDefaultDisplay();
//         Point realSize = new Point();
//         try {
//             Display.class.getMethod("getRealSize", Point.class).invoke(display, realSize);
//         } catch (NoSuchMethodException e) {
//             e.printStackTrace();
//         } catch (IllegalAccessException e) {
//             e.printStackTrace();
//         } catch (InvocationTargetException e) {
//             e.printStackTrace();
//         }
//         heightPixes = realSize.y;
//         return heightPixes;
//     }
// 
//     public static int dip2px(Context context, float dpVale) {
//         final float scale = context.getResources().getDisplayMetrics().density;
//         return (int) (dpVale * scale + 0.5f);
//     }
// 
//     public static int getStatusBarHeight(Context context) {
//         Resources resources = context.getResources();
//         int resourcesId = resources.getIdentifier("status_bar_height", "dimen", "android");
//         int height = resources.getDimensionPixelSize(resourcesId);
//         return height;
//     }
// 
//     /**
//      * Converts sp to px
//      *
//      * @param context Context
//      * @param sp  the value in sp
//      * @return int
//      */
//     public static int dip2sp(Context context, float sp) {
//         return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, sp, context.getResources().getDisplayMetrics());
//     }
// 
//     public static int px2dip(Context context, float pxValue) {
//         final float scale = context.getResources().getDisplayMetrics().density;
//         return (int) (pxValue / scale + 0.5f);
//     }
// 
// }


// Path: app/src/main/java/io/github/marktony/espresso/component/FastScroller.java
import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.animation.ObjectAnimator;
import android.content.Context;
import android.content.res.Resources;
import android.content.res.TypedArray;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Point;
import android.graphics.Rect;
import android.graphics.Typeface;
import android.support.annotation.ColorInt;
import android.support.v4.content.ContextCompat;
import android.support.v4.view.animation.FastOutLinearInInterpolator;
import android.support.v4.view.animation.LinearOutSlowInInterpolator;
import android.support.v7.widget.RecyclerView;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewConfiguration;
import io.github.marktony.espresso.R;
import io.github.marktony.espresso.interfaze.OnFastScrollStateChangeListener;
import io.github.marktony.espresso.util.DensityUtil;

/*
 *  Copyright(c) 2017 lizhaotailang
 *
 * 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 io.github.marktony.espresso.component;



/**
 * Created by lizhaotailang on 2017/3/24.
 */

public class FastScroller {

    private static final int DEFAULT_AUTO_HIDE_DELAY = 1500;

    private FastScrollRecyclerView mRecyclerView;
    private FastScrollPopup mPopup;

    private int mThumbHeight;
    private int mWidth;

    private Paint mThumb;
    private Paint mTrack;

    private Rect mTmpRect = new Rect();
    private Rect mInvalidateRect = new Rect();
    private Rect mInvalidateTmpRect = new Rect();

    // The inset is the buffer around which a point will still register as a click on the scrollbar
    private int mTouchInset;

    // This is the offset from the top of the scrollbar when the user first starts touching.  To
    // prevent jumping, this offset is applied as the user scrolls.
    private int mTouchOffset;

    private Point mThumbPosition = new Point(-1, -1);
    private Point mOffset = new Point(0, 0);

    private boolean mIsDragging;

    private Animator mAutoHideAnimator;
    private boolean mAnimatingShow;
    private int mAutoHideDelay = DEFAULT_AUTO_HIDE_DELAY;
    private boolean mAutoHideEnabled = true;
    private final Runnable mHideRunnable;

    public FastScroller(Context context, FastScrollRecyclerView recyclerView, AttributeSet attrs) {

        Resources resources = context.getResources();

        mRecyclerView = recyclerView;
        mPopup = new FastScrollPopup(resources, recyclerView);

        mThumbHeight = DensityUtil.dip2px(context, 48);