// Path: app/src/main/java/com/zhihu/android/app/mirror/util/AnimUtils.java
// public class AnimUtils {
//     public static final int DURATION = 300; // ms
// 
//     public static void showViewAlphaAnim(final View view, TimeInterpolator interpolator, final boolean visible) {
//         if (visible && view.getVisibility() == View.VISIBLE
//                 || !visible && view.getVisibility() != View.VISIBLE) {
//             return;
//         }
// 
//         float fromAlpha = visible ? 0.0F : 1.0F;
//         float toAlpha = visible ? 1.0F : 0.0F;
//         view.setAlpha(fromAlpha);
//         view.setVisibility(View.VISIBLE);
//         view.animate().alpha(toAlpha)
//                 .setDuration(DURATION)
//                 .setInterpolator(interpolator)
//                 .setListener(new AnimatorListenerAdapter() {
//                     @Override
//                     public void onAnimationEnd(Animator animator) {
//                         if (visible) {
//                             view.setAlpha(1.0F);
//                             view.setVisibility(View.VISIBLE);
//                         } else {
//                             view.setAlpha(0.0F);
//                             view.setVisibility(View.INVISIBLE);
//                         }
//                     }
//                 })
//                 .start();
//     }
// }
// 
// Path: app/src/main/java/com/zhihu/android/app/mirror/util/DisplayUtils.java
// public class DisplayUtils {
//     public static float getScreenDensity(Context context) {
//         return context.getResources().getDisplayMetrics().density;
//     }
// 
//     public static int getScreenWidth(Context context) {
//         WindowManager manager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
//         Display display = manager.getDefaultDisplay();
//         Point point = new Point();
//         display.getSize(point);
//         return point.x;
//     }
// 
//     public static int getScreenHeight(Context context) {
//         WindowManager manager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
//         Display display = manager.getDefaultDisplay();
//         Point point = new Point();
//         display.getSize(point);
//         return point.y;
//     }
// 
//     public static int getStatusBarHeight(Context context) {
//         int statusBarHeight = 0;
// 
//         int resourceId = context.getResources().getIdentifier("status_bar_height", "dimen", "android");
//         if (resourceId > 0) {
//             statusBarHeight = context.getResources().getDimensionPixelSize(resourceId);
//         }
// 
//         return statusBarHeight;
//     }
// 
//     public static int getNavigationBarHeight(Context context) {
//         int navigationBarHeight = 0;
// 
//         int resourceId = context.getResources().getIdentifier("navigation_bar_height", "dimen", "android");
//         if (resourceId > 0) {
//             navigationBarHeight = context.getResources().getDimensionPixelSize(resourceId);
//         }
// 
//         return navigationBarHeight;
//     }
// 
//     public static int dp2px(Context context, float dp) {
//         return (int) (getScreenDensity(context) * dp + 0.5F);
//     }
// 
//     public static int sp2px(Context context, float sp) {
//         return (int) (context.getResources().getDisplayMetrics().scaledDensity * sp + 0.5F);
//     }
// 
//     public static void requestImmersiveStickyMode(Activity activity) {
//         activity.getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE
//                 | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
//                 | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
//                 | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
//                 | View.SYSTEM_UI_FLAG_FULLSCREEN
//                 | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);
//     }
// 
//     public static void clearImmersiveStickyMode(Activity activity) {
//         activity.getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_VISIBLE);
//     }
// }


import com.davemorrissey.labs.subscaleview.SubsamplingScaleImageView;
import java.math.BigDecimal;
import com.zhihu.android.app.mirror.R;
import com.zhihu.android.app.mirror.util.AnimUtils;
import com.zhihu.android.app.mirror.util.DisplayUtils;
import android.animation.ObjectAnimator;
import android.animation.ValueAnimator;
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.PointF;
import android.support.annotation.NonNull;
import android.support.v4.view.animation.PathInterpolatorCompat;
import android.util.AttributeSet;
import android.view.GestureDetector;
import android.view.MotionEvent;
import android.view.View;
/*
 * Mirror - Yet another Sketch Mirror App for Android.
 * Copyright (C) 2016 Zhihu Inc.
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU 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 General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package com.zhihu.android.app.mirror.widget;





// https://github.com/nickbutcher/plaid/blob/master/app/src/main/java/io/plaidapp/ui/widget/ElasticDragDismissFrameLayout.java
public class ArtboardView extends SubsamplingScaleImageView implements View.OnTouchListener {
    public interface ArtboardViewCallback {
        void onDrag(ArtboardView view, float dragDismissDistance, float dragTo);
        void onDragDismiss(ArtboardView view, boolean isDragDown);
    }

    private float mDragDismissDistance;
    private float mDragElacticity;

    private ObjectAnimator mTransYAnim;
    private float mActionDownY;
    private float mDragDistance;
    private boolean mIsDragDown; // drag direction to screen bottom

    private ArtboardViewCallback mCallback;
    private GestureDetector mGestureDetector;

    public ArtboardView(Context context) {
        super(context);
        init(null);
    }

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

    private void init(AttributeSet attrs) {
// Path: app/src/main/java/com/zhihu/android/app/mirror/util/AnimUtils.java
// public class AnimUtils {
//     public static final int DURATION = 300; // ms
// 
//     public static void showViewAlphaAnim(final View view, TimeInterpolator interpolator, final boolean visible) {
//         if (visible && view.getVisibility() == View.VISIBLE
//                 || !visible && view.getVisibility() != View.VISIBLE) {
//             return;
//         }
// 
//         float fromAlpha = visible ? 0.0F : 1.0F;
//         float toAlpha = visible ? 1.0F : 0.0F;
//         view.setAlpha(fromAlpha);
//         view.setVisibility(View.VISIBLE);
//         view.animate().alpha(toAlpha)
//                 .setDuration(DURATION)
//                 .setInterpolator(interpolator)
//                 .setListener(new AnimatorListenerAdapter() {
//                     @Override
//                     public void onAnimationEnd(Animator animator) {
//                         if (visible) {
//                             view.setAlpha(1.0F);
//                             view.setVisibility(View.VISIBLE);
//                         } else {
//                             view.setAlpha(0.0F);
//                             view.setVisibility(View.INVISIBLE);
//                         }
//                     }
//                 })
//                 .start();
//     }
// }
// 
// Path: app/src/main/java/com/zhihu/android/app/mirror/util/DisplayUtils.java
// public class DisplayUtils {
//     public static float getScreenDensity(Context context) {
//         return context.getResources().getDisplayMetrics().density;
//     }
// 
//     public static int getScreenWidth(Context context) {
//         WindowManager manager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
//         Display display = manager.getDefaultDisplay();
//         Point point = new Point();
//         display.getSize(point);
//         return point.x;
//     }
// 
//     public static int getScreenHeight(Context context) {
//         WindowManager manager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
//         Display display = manager.getDefaultDisplay();
//         Point point = new Point();
//         display.getSize(point);
//         return point.y;
//     }
// 
//     public static int getStatusBarHeight(Context context) {
//         int statusBarHeight = 0;
// 
//         int resourceId = context.getResources().getIdentifier("status_bar_height", "dimen", "android");
//         if (resourceId > 0) {
//             statusBarHeight = context.getResources().getDimensionPixelSize(resourceId);
//         }
// 
//         return statusBarHeight;
//     }
// 
//     public static int getNavigationBarHeight(Context context) {
//         int navigationBarHeight = 0;
// 
//         int resourceId = context.getResources().getIdentifier("navigation_bar_height", "dimen", "android");
//         if (resourceId > 0) {
//             navigationBarHeight = context.getResources().getDimensionPixelSize(resourceId);
//         }
// 
//         return navigationBarHeight;
//     }
// 
//     public static int dp2px(Context context, float dp) {
//         return (int) (getScreenDensity(context) * dp + 0.5F);
//     }
// 
//     public static int sp2px(Context context, float sp) {
//         return (int) (context.getResources().getDisplayMetrics().scaledDensity * sp + 0.5F);
//     }
// 
//     public static void requestImmersiveStickyMode(Activity activity) {
//         activity.getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE
//                 | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
//                 | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
//                 | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
//                 | View.SYSTEM_UI_FLAG_FULLSCREEN
//                 | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);
//     }
// 
//     public static void clearImmersiveStickyMode(Activity activity) {
//         activity.getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_VISIBLE);
//     }
// }


// Path: app/src/main/java/com/zhihu/android/app/mirror/widget/ArtboardView.java
import com.davemorrissey.labs.subscaleview.SubsamplingScaleImageView;
import java.math.BigDecimal;
import com.zhihu.android.app.mirror.R;
import com.zhihu.android.app.mirror.util.AnimUtils;
import com.zhihu.android.app.mirror.util.DisplayUtils;
import android.animation.ObjectAnimator;
import android.animation.ValueAnimator;
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.PointF;
import android.support.annotation.NonNull;
import android.support.v4.view.animation.PathInterpolatorCompat;
import android.util.AttributeSet;
import android.view.GestureDetector;
import android.view.MotionEvent;
import android.view.View;

/*
 * Mirror - Yet another Sketch Mirror App for Android.
 * Copyright (C) 2016 Zhihu Inc.
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU 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 General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package com.zhihu.android.app.mirror.widget;





// https://github.com/nickbutcher/plaid/blob/master/app/src/main/java/io/plaidapp/ui/widget/ElasticDragDismissFrameLayout.java
public class ArtboardView extends SubsamplingScaleImageView implements View.OnTouchListener {
    public interface ArtboardViewCallback {
        void onDrag(ArtboardView view, float dragDismissDistance, float dragTo);
        void onDragDismiss(ArtboardView view, boolean isDragDown);
    }

    private float mDragDismissDistance;
    private float mDragElacticity;

    private ObjectAnimator mTransYAnim;
    private float mActionDownY;
    private float mDragDistance;
    private boolean mIsDragDown; // drag direction to screen bottom

    private ArtboardViewCallback mCallback;
    private GestureDetector mGestureDetector;

    public ArtboardView(Context context) {
        super(context);
        init(null);
    }

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

    private void init(AttributeSet attrs) {
        mDragDismissDistance = DisplayUtils.dp2px(getContext(), 112.0F);