1 package com.android.wallpaperpicker; 2 3 import android.view.View; 4 import android.view.ViewPropertyAnimator; 5 import android.view.animation.AccelerateInterpolator; 6 import android.view.animation.DecelerateInterpolator; 7 8 /** 9 * Callback that toggles the visibility of the target view when crop view is tapped. 10 */ 11 public class ToggleOnTapCallback implements CropView.TouchCallback { 12 13 private final View mViewtoToggle; 14 15 private ViewPropertyAnimator mAnim; 16 private boolean mIgnoreNextTap; 17 18 public ToggleOnTapCallback(View viewtoHide) { 19 mViewtoToggle = viewtoHide; 20 } 21 22 @Override 23 public void onTouchDown() { 24 if (mAnim != null) { 25 mAnim.cancel(); 26 } 27 if (mViewtoToggle.getAlpha() == 1f) { 28 mIgnoreNextTap = true; 29 } 30 31 mAnim = mViewtoToggle.animate(); 32 mAnim.alpha(0f) 33 .setDuration(150) 34 .withEndAction(new Runnable() { 35 public void run() { 36 mViewtoToggle.setVisibility(View.INVISIBLE); 37 } 38 }); 39 40 mAnim.setInterpolator(new AccelerateInterpolator(0.75f)); 41 mAnim.start(); 42 } 43 44 @Override 45 public void onTouchUp() { 46 mIgnoreNextTap = false; 47 } 48 49 @Override 50 public void onTap() { 51 boolean ignoreTap = mIgnoreNextTap; 52 mIgnoreNextTap = false; 53 if (!ignoreTap) { 54 if (mAnim != null) { 55 mAnim.cancel(); 56 } 57 mViewtoToggle.setVisibility(View.VISIBLE); 58 mAnim = mViewtoToggle.animate(); 59 mAnim.alpha(1f) 60 .setDuration(150) 61 .setInterpolator(new DecelerateInterpolator(0.75f)); 62 mAnim.start(); 63 } 64 } 65 } 66