List of usage examples for android.support.v4.view ViewPropertyAnimatorCompat cancel
public void cancel()
From source file:android.support.v7.internal.view.ViewPropertyAnimatorCompatSet.java
public void cancel() { if (!mIsStarted) { return;/*w w w .j a v a 2 s . c om*/ } for (ViewPropertyAnimatorCompat animator : mAnimators) { animator.cancel(); } mIsStarted = false; }
From source file:vc908.stickerfactory.ui.advancedrecyclerview.draggable.BaseDraggableItemDecorator.java
protected void moveToDefaultPosition(View targetView, boolean animate) { final int curTranslationY = (int) (ViewCompat.getTranslationY(targetView)); final int halfItemHeight = targetView.getHeight() / 2; final float translationProportion = (halfItemHeight > 0) ? Math.abs((float) curTranslationY / halfItemHeight) : 0;/* w ww . j av a2s . c om*/ final float t = 1.0f - Math.min(translationProportion, 1.0f); final int animDuration = (int) (mReturnToDefaultPositionDuration * (1.0f - (t * t)) + 0.5f); if (supportsViewPropertyAnimation() && animate && (animDuration > RETURN_TO_DEFAULT_POS_ANIMATE_THRESHOLD_MSEC) && (Math.abs(curTranslationY) > mReturnToDefaultPositionAnimateThreshold)) { final ViewPropertyAnimatorCompat animator = ViewCompat.animate(targetView); animator.cancel(); animator.setDuration(animDuration); animator.setInterpolator(mReturnToDefaultPositionInterpolator); animator.translationY(0.0f); animator.setListener(new ViewPropertyAnimatorListener() { @Override public void onAnimationStart(View view) { } @Override public void onAnimationEnd(View view) { animator.setListener(null); ViewCompat.setTranslationY(view, 0); // invalidate explicitly to refresh other decorations if (view.getParent() instanceof RecyclerView) { ViewCompat.postInvalidateOnAnimation((RecyclerView) view.getParent()); } } @Override public void onAnimationCancel(View view) { } }); animator.start(); } else { ViewCompat.setTranslationY(targetView, 0); } }
From source file:com.github.shareme.gwsmaterialuikit.library.advancerv.draggable.BaseDraggableItemDecorator.java
protected void moveToDefaultPosition(View targetView, boolean animate) { final int curTranslationX = (int) (ViewCompat.getTranslationX(targetView)); final int curTranslationY = (int) (ViewCompat.getTranslationY(targetView)); final int halfItemWidth = targetView.getWidth() / 2; final int halfItemHeight = targetView.getHeight() / 2; final float translationProportionX = (halfItemWidth > 0) ? Math.abs((float) curTranslationX / halfItemWidth) : 0;//from w w w .j a v a 2s . c o m final float translationProportionY = (halfItemHeight > 0) ? Math.abs((float) curTranslationY / halfItemHeight) : 0; final float tx = 1.0f - Math.min(translationProportionX, 1.0f); final float ty = 1.0f - Math.min(translationProportionY, 1.0f); final int animDurationX = (int) (mReturnToDefaultPositionDuration * (1.0f - (tx * tx)) + 0.5f); final int animDurationY = (int) (mReturnToDefaultPositionDuration * (1.0f - (ty * ty)) + 0.5f); final int animDuration = Math.max(animDurationX, animDurationY); final int maxAbsTranslation = Math.max(Math.abs(curTranslationX), Math.abs(curTranslationY)); if (supportsViewPropertyAnimation() && animate && (animDuration > RETURN_TO_DEFAULT_POS_ANIMATE_THRESHOLD_MSEC) && (maxAbsTranslation > mReturnToDefaultPositionAnimateThreshold)) { final ViewPropertyAnimatorCompat animator = ViewCompat.animate(targetView); animator.cancel(); animator.setDuration(animDuration); animator.setInterpolator(mReturnToDefaultPositionInterpolator); animator.translationX(0.0f); animator.translationY(0.0f); animator.setListener(new ViewPropertyAnimatorListener() { @Override public void onAnimationStart(View view) { } @Override public void onAnimationEnd(View view) { animator.setListener(null); ViewCompat.setTranslationX(view, 0); ViewCompat.setTranslationY(view, 0); // invalidate explicitly to refresh other decorations if (view.getParent() instanceof RecyclerView) { ViewCompat.postInvalidateOnAnimation((RecyclerView) view.getParent()); } } @Override public void onAnimationCancel(View view) { } }); animator.start(); } else { ViewCompat.setTranslationX(targetView, 0); ViewCompat.setTranslationY(targetView, 0); } }
From source file:ren.qinc.markdowneditors.base.BaseActivity.java
/** * ???ActionMode??// ww w .j av a2 s . c om * * @param activity * @param mode */ private void fixActionModeCallback(AppCompatActivity activity, ActionMode mode) { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) return; if (!(mode instanceof StandaloneActionMode)) return; try { final Field mCallbackField = mode.getClass().getDeclaredField("mCallback"); mCallbackField.setAccessible(true); final Object mCallback = mCallbackField.get(mode); final Field mWrappedField = mCallback.getClass().getDeclaredField("mWrapped"); mWrappedField.setAccessible(true); final ActionMode.Callback mWrapped = (ActionMode.Callback) mWrappedField.get(mCallback); final Field mDelegateField = AppCompatActivity.class.getDeclaredField("mDelegate"); mDelegateField.setAccessible(true); final Object mDelegate = mDelegateField.get(activity); mCallbackField.set(mode, new ActionMode.Callback() { @Override public boolean onCreateActionMode(android.support.v7.view.ActionMode mode, Menu menu) { return mWrapped.onCreateActionMode(mode, menu); } @Override public boolean onPrepareActionMode(android.support.v7.view.ActionMode mode, Menu menu) { return mWrapped.onPrepareActionMode(mode, menu); } @Override public boolean onActionItemClicked(android.support.v7.view.ActionMode mode, MenuItem item) { return mWrapped.onActionItemClicked(mode, item); } @Override public void onDestroyActionMode(final android.support.v7.view.ActionMode mode) { Class mDelegateClass = mDelegate.getClass().getSuperclass(); Window mWindow = null; PopupWindow mActionModePopup = null; Runnable mShowActionModePopup = null; ActionBarContextView mActionModeView = null; AppCompatCallback mAppCompatCallback = null; ViewPropertyAnimatorCompat mFadeAnim = null; android.support.v7.view.ActionMode mActionMode = null; Field mFadeAnimField = null; Field mActionModeField = null; while (mDelegateClass != null) { try { if (TextUtils.equals("AppCompatDelegateImplV7", mDelegateClass.getSimpleName())) { Field mActionModePopupField = mDelegateClass.getDeclaredField("mActionModePopup"); mActionModePopupField.setAccessible(true); mActionModePopup = (PopupWindow) mActionModePopupField.get(mDelegate); Field mShowActionModePopupField = mDelegateClass .getDeclaredField("mShowActionModePopup"); mShowActionModePopupField.setAccessible(true); mShowActionModePopup = (Runnable) mShowActionModePopupField.get(mDelegate); Field mActionModeViewField = mDelegateClass.getDeclaredField("mActionModeView"); mActionModeViewField.setAccessible(true); mActionModeView = (ActionBarContextView) mActionModeViewField.get(mDelegate); mFadeAnimField = mDelegateClass.getDeclaredField("mFadeAnim"); mFadeAnimField.setAccessible(true); mFadeAnim = (ViewPropertyAnimatorCompat) mFadeAnimField.get(mDelegate); mActionModeField = mDelegateClass.getDeclaredField("mActionMode"); mActionModeField.setAccessible(true); mActionMode = (android.support.v7.view.ActionMode) mActionModeField.get(mDelegate); } else if (TextUtils.equals("AppCompatDelegateImplBase", mDelegateClass.getSimpleName())) { Field mAppCompatCallbackField = mDelegateClass .getDeclaredField("mAppCompatCallback"); mAppCompatCallbackField.setAccessible(true); mAppCompatCallback = (AppCompatCallback) mAppCompatCallbackField.get(mDelegate); Field mWindowField = mDelegateClass.getDeclaredField("mWindow"); mWindowField.setAccessible(true); mWindow = (Window) mWindowField.get(mDelegate); } mDelegateClass = mDelegateClass.getSuperclass(); } catch (NoSuchFieldException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } } if (mActionModePopup != null) { mWindow.getDecorView().removeCallbacks(mShowActionModePopup); } if (mActionModeView != null) { if (mFadeAnim != null) { mFadeAnim.cancel(); } mFadeAnim = ViewCompat.animate(mActionModeView).alpha(0.0F); final PopupWindow mActionModePopupFinal = mActionModePopup; final ActionBarContextView mActionModeViewFinal = mActionModeView; final ViewPropertyAnimatorCompat mFadeAnimFinal = mFadeAnim; final AppCompatCallback mAppCompatCallbackFinal = mAppCompatCallback; final android.support.v7.view.ActionMode mActionModeFinal = mActionMode; final Field mFadeAnimFieldFinal = mFadeAnimField; final Field mActionModeFieldFinal = mActionModeField; mFadeAnim.setListener(new ViewPropertyAnimatorListenerAdapter() { public void onAnimationEnd(View view) { mActionModeViewFinal.setVisibility(View.GONE); if (mActionModePopupFinal != null) { mActionModePopupFinal.dismiss(); } else if (mActionModeViewFinal.getParent() instanceof View) { ViewCompat.requestApplyInsets((View) mActionModeViewFinal.getParent()); } mActionModeViewFinal.removeAllViews(); mFadeAnimFinal.setListener((ViewPropertyAnimatorListener) null); try { if (mFadeAnimFieldFinal != null) { mFadeAnimFieldFinal.set(mDelegate, null); } } catch (IllegalAccessException e) { e.printStackTrace(); } mWrapped.onDestroyActionMode(mode); if (mAppCompatCallbackFinal != null) { mAppCompatCallbackFinal.onSupportActionModeFinished(mActionModeFinal); } try { if (mActionModeFieldFinal != null) { mActionModeFieldFinal.set(mDelegate, null); } } catch (IllegalAccessException e) { e.printStackTrace(); } } }); } } }); } catch (NoSuchFieldException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } }