List of usage examples for android.animation ValueAnimator start
@Override public void start()
From source file:nl.eduvpn.app.fragment.HomeFragment.java
/** * Checks if the loading has finished./* w ww.j a v a 2 s . com*/ * If yes, it hides the loading animation. * If there were any errors, it will display a warning bar as well. * * @param adapter The adapter which the items are being loaded into. */ private synchronized void _checkLoadingFinished(final ProfileAdapter adapter) { _pendingInstanceCount--; if (_pendingInstanceCount <= 0 && _problematicInstances.size() == 0) { if (_loadingBar == null) { Log.d(TAG, "Layout has been destroyed already."); return; } float startHeight = _loadingBar.getHeight(); ValueAnimator animator = ValueAnimator.ofFloat(startHeight, 0); animator.setDuration(600); animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animation) { float fraction = animation.getAnimatedFraction(); float alpha = 1f - fraction; float height = (Float) animation.getAnimatedValue(); if (_loadingBar != null) { _loadingBar.setAlpha(alpha); _loadingBar.getLayoutParams().height = (int) height; _loadingBar.requestLayout(); } } }); animator.start(); } else if (_pendingInstanceCount <= 0) { if (_displayText == null) { Log.d(TAG, "Layout has been destroyed already."); return; } // There are some warnings _displayText.setText(R.string.could_not_fetch_all_profiles); _warningIcon.setVisibility(View.VISIBLE); _progressBar.setVisibility(View.GONE); _loadingBar.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // Display a dialog with all the warnings _currentDialog = ErrorDialog.show(getContext(), getString(R.string.warnings_list), getString(R.string.instance_access_warning_message), new ErrorDialog.InstanceWarningHandler() { @Override public List<Instance> getInstances() { return _problematicInstances; } @Override public void retryInstance(Instance instance) { _warningIcon.setVisibility(View.GONE); _progressBar.setVisibility(View.VISIBLE); _displayText.setText(R.string.loading_available_profiles); SavedAuthState savedAuthState = _historyService.getSavedToken(instance); if (savedAuthState == null) { // Should never happen _currentDialog = ErrorDialog.show(getContext(), R.string.error_dialog_title, R.string.data_removed); } else { // Retry _problematicInstances.remove(instance); _fillList(adapter, Collections.singletonList(savedAuthState)); } } @Override public void loginInstance(final Instance instance) { // Find the auth state for the instance and then retry AuthState authState = _historyService.getCachedAuthState(instance); _apiService.getJSON( instance.getSanitizedBaseURI() + Constants.API_DISCOVERY_POSTFIX, authState, new APIService.Callback<JSONObject>() { @Override public void onSuccess(JSONObject result) { try { DiscoveredAPI discoveredAPI = _serializerService .deserializeDiscoveredAPI(result); // Cache the result _historyService.cacheDiscoveredAPI( instance.getSanitizedBaseURI(), discoveredAPI); _problematicInstances.remove(instance); Activity activity = getActivity(); if (activity != null && !activity.isFinishing()) { _connectionService.initiateConnection(getActivity(), instance, discoveredAPI); } } catch (SerializerService.UnknownFormatException ex) { Log.e(TAG, "Error parsing discovered API!", ex); _currentDialog = ErrorDialog.show(getContext(), R.string.error_dialog_title, R.string.provider_incorrect_format); } } @Override public void onError(String errorMessage) { Log.e(TAG, "Error while fetching discovered API: " + errorMessage); DiscoveredAPI discoveredAPI = _historyService .getCachedDiscoveredAPI(instance.getSanitizedBaseURI()); Activity activity = getActivity(); if (discoveredAPI != null && activity != null && !activity.isFinishing()) { _connectionService.initiateConnection(activity, instance, discoveredAPI); } else { _currentDialog = ErrorDialog.show(getContext(), R.string.error_dialog_title, R.string.provider_not_found_retry); } } }); } @Override public void removeInstance(Instance instance) { _historyService.removeAllDataForInstance(instance); _problematicInstances.remove(instance); getActivity().runOnUiThread(() -> _checkLoadingFinished(adapter)); } }); } }); } }
From source file:net.osmand.plus.views.controls.SwipeDismissListViewTouchListener.java
/** * Animate the dismissed list item to zero-height and fire the dismiss callback when * all dismissed list item animations have completed. * * @param dismissView The view that has been slided out. * @param listItemView The list item view. This is the whole view of the list item, and not just * the part, that the user swiped. * @param dismissPosition The position of the view inside the list. */// w w w.j a v a2s .c om private void performDismiss(final View dismissView, final View listItemView, final int dismissPosition) { final ViewGroup.LayoutParams lp = listItemView.getLayoutParams(); final int originalLayoutHeight = lp.height; if (android.os.Build.VERSION.SDK_INT < 12) { mPendingDismisses.add(new PendingDismissData(dismissPosition, dismissView, listItemView)); finishDismiss(dismissView, originalLayoutHeight); } else { int originalHeight = listItemView.getHeight(); ValueAnimator animator = ValueAnimator.ofInt(originalHeight, 1).setDuration(mAnimationTime); animator.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { finishDismiss(dismissView, originalLayoutHeight); } }); animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator valueAnimator) { lp.height = (Integer) valueAnimator.getAnimatedValue(); listItemView.setLayoutParams(lp); } }); mPendingDismisses.add(new PendingDismissData(dismissPosition, dismissView, listItemView)); animator.start(); } }
From source file:com.roughike.bottombar.BottomBarTab.java
void updateWidth(float endWidth, boolean animated) { if (!animated) { getLayoutParams().width = (int) endWidth; if (!isActive && badge != null) { badge.adjustPositionAndSize(this); badge.show();/*from w w w . j av a 2s.c o m*/ } return; } float start = getWidth(); ValueAnimator animator = ValueAnimator.ofFloat(start, endWidth); animator.setDuration(150); animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animator) { ViewGroup.LayoutParams params = getLayoutParams(); if (params == null) return; params.width = Math.round((float) animator.getAnimatedValue()); setLayoutParams(params); } }); // Workaround to avoid using faulty onAnimationEnd() listener postDelayed(new Runnable() { @Override public void run() { if (!isActive && badge != null) { clearAnimation(); badge.adjustPositionAndSize(BottomBarTab.this); badge.show(); } } }, animator.getDuration()); animator.start(); }
From source file:com.alimuzaffar.lib.pin.PinEntryEditText.java
private void animatePopIn() { ValueAnimator va = ValueAnimator.ofFloat(1, getPaint().getTextSize()); va.setDuration(200);/* w w w.j av a 2 s . c om*/ va.setInterpolator(new OvershootInterpolator()); va.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animation) { mLastCharPaint.setTextSize((Float) animation.getAnimatedValue()); PinEntryEditText.this.invalidate(); } }); if (getText().length() == mMaxLength && mOnPinEnteredListener != null) { va.addListener(new Animator.AnimatorListener() { @Override public void onAnimationStart(Animator animation) { } @Override public void onAnimationEnd(Animator animation) { mOnPinEnteredListener.onPinEntered(getText()); } @Override public void onAnimationCancel(Animator animation) { } @Override public void onAnimationRepeat(Animator animation) { } }); } va.start(); }
From source file:com.liujs.library.view.refresh.BGAStickinessRefreshView.java
public void startRefreshing() { ValueAnimator animator = ValueAnimator.ofInt(mCurrentBottomHeight, 0); animator.setDuration(mStickinessRefreshViewHolder.getTopAnimDuration()); animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override//w w w . ja va 2 s .c o m public void onAnimationUpdate(ValueAnimator animation) { mCurrentBottomHeight = (int) animation.getAnimatedValue(); postInvalidate(); } }); animator.addListener(new Animator.AnimatorListener() { @Override public void onAnimationStart(Animator animation) { mIsRefreshing = true; if (mCurrentBottomHeight != 0) { mStickinessRefreshViewHolder.startChangeWholeHeaderViewPaddingTop(mCurrentBottomHeight); } else { mStickinessRefreshViewHolder.startChangeWholeHeaderViewPaddingTop( -(mTopSize + getPaddingTop() + getPaddingBottom())); } } @Override public void onAnimationEnd(Animator animation) { mIsRotating = true; startRotating(); } @Override public void onAnimationCancel(Animator animation) { } @Override public void onAnimationRepeat(Animator animation) { } }); animator.start(); }
From source file:com.huyn.demogroup.zoomageview.view.PhotoViewAttacher.java
private void reverseFromDrag() { final float translationY = mImageView.getTranslationY(); final float translationX = mImageView.getTranslationX(); final float startScale = mImageView.getScaleX(); ValueAnimator animator = ValueAnimator.ofFloat(0f, 1f); animator.setDuration(200);// w w w .j a va 2 s . c o m animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animation) { float value = (float) animation.getAnimatedValue(); float y = translationY * (1 - value); float x = translationX * (1 - value); float scale = startScale + (1 - startScale) * value; mImageView.setTranslationY(y); mImageView.setTranslationX(x); mImageView.setScaleY(scale); mImageView.setScaleX(scale); } }); animator.start(); if (translationY >= mDragToFinishDistance / 2 && mDragToFinishListener != null && mEnableDragToFinish) { //doReverse(); mDragToFinish = true; //mDragToFinishListener.onDismiss(); System.out.println("+++++++++change mDragToFinish:" + mDragToFinish); View parent = (View) mImageView.getParent(); if (parent instanceof PhotoLayout) ((PhotoLayout) parent).reverse(); } }
From source file:org.protocoderrunner.apprunner.api.PUI.java
@TargetApi(Build.VERSION_CODES.LOLLIPOP) @ProtocoderScript/*from w w w . ja v a2 s. c o m*/ @APIParam(params = { "View" }) public void reveal(final View v) { // previously invisible view // get the center for the clipping circle int cx = (v.getLeft() + v.getRight()) / 2; int cy = (v.getTop() + v.getBottom()) / 2; // get the final radius for the clipping circle int finalRadius = v.getWidth(); // create and start the animator for this view // (the start radius is zero) ValueAnimator anim = (ValueAnimator) ViewAnimationUtils.createCircularReveal(v, cx, cy, 0, finalRadius); anim.setDuration(1000); anim.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationStart(Animator animation) { super.onAnimationStart(animation); v.setVisibility(View.VISIBLE); } }); anim.start(); }
From source file:com.songcode.materialnotes.ui.NoteEditActivity.java
private void animateRevealHide(final View targetview, View startView) { if (isActionInsertOrEdit()) { int cx = startView.getLeft() + (startView.getWidth() / 2); //middle of button int cy = startView.getTop() + (startView.getHeight() / 2); //middle of button int radius = (int) Math.sqrt(Math.pow(cx, 2) + Math.pow(cy, 2)); //hypotenuse to top left Animator anim = ViewAnimationUtils.createCircularReveal(targetview, cx, cy, radius, 0); anim.addListener(new AnimatorListenerAdapter() { @Override//from www.j a v a 2 s . c o m public void onAnimationEnd(Animator animation) { super.onAnimationEnd(animation); targetview.setVisibility(View.INVISIBLE); } }); //anim.setInterpolator(new AccelerateInterpolator()); anim.setDuration(ANIM_DURATION); anim.start(); Integer colorTo = getResources().getColor(R.color.primaryColor); Integer colorFrom = getResources().getColor(android.R.color.white); ValueAnimator colorAnimation = ValueAnimator.ofObject(new ArgbEvaluator(), colorFrom, colorTo); colorAnimation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animator) { targetview.setBackgroundColor((Integer) animator.getAnimatedValue()); } }); colorAnimation.setInterpolator(new AccelerateInterpolator(2)); colorAnimation.setDuration(ANIM_DURATION); colorAnimation.start(); } else if (isActionActionView()) { mAnimBackGroudView.animate().scaleX(1).scaleY(1).alpha(1).translationY(0).setDuration(ANIM_DURATION) .setInterpolator(new AccelerateInterpolator()).start(); mNoteEditor.animate().alpha(0).setDuration(100).start(); } }
From source file:com.musenkishi.wally.activities.ImageDetailsActivity.java
/** * Animations animations animations.//from w w w .j a v a2 s .c om */ private void toggleZoomImage() { int animationDuration = 400; if (isInFullscreen()) { scrollView.smoothScrollTo(0, (Integer) scrollView.getTag()); photoViewAttacher.setScale(1.0f, true); } else { scrollView.setTag(scrollView.getScrollY()); scrollView.smoothScrollTo(0, 0); } if (getSupportActionBar() != null) { getToolbar().animate().translationY(isInFullscreen() ? 0.0f : -getToolbar().getMeasuredHeight()) .alpha(isInFullscreen() ? 1.0f : 0.0f).setDuration(500) .setInterpolator(new EaseInOutBezierInterpolator()).start(); } findViewById(R.id.image_details_protective_shadow).animate().alpha(isInFullscreen() ? 1.0f : 0.0f) .setDuration(500).setInterpolator(new EaseInOutBezierInterpolator()).start(); int minimumAllowedHeight = getToolbar().getMeasuredHeight() + getResources().getDimensionPixelSize(R.dimen.fab_padding_positive); if (imageSize.getHeight() < minimumAllowedHeight) { int topFrom; int topTo; if (isInFullscreen()) { topFrom = 0; topTo = getToolbar().getMeasuredHeight(); } else { topFrom = photoLayoutHolder.getPaddingTop(); topTo = 0; } ValueAnimator topValueAnimator = ValueAnimator.ofInt(topFrom, topTo); topValueAnimator.setDuration(animationDuration); topValueAnimator.setInterpolator(new EaseInOutBezierInterpolator()); topValueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator valueAnimator) { int val = (Integer) valueAnimator.getAnimatedValue(); photoLayoutHolder.setPadding(photoLayoutHolder.getPaddingLeft(), val, photoLayoutHolder.getPaddingRight(), photoLayoutHolder.getPaddingBottom()); } }); topValueAnimator.start(); } if (photoLayoutHolder.getTranslationY() > 0.0f) { photoLayoutHolder.animate().translationY(0.0f).setInterpolator(new EaseInOutBezierInterpolator()) .setDuration(animationDuration).start(); } WindowManager win = getWindowManager(); Display d = win.getDefaultDisplay(); int from = photoView.getMeasuredHeight(); int to = isInFullscreen() ? imageSize.getHeight() : d.getHeight(); ValueAnimator valueAnimator = ValueAnimator.ofInt(from, to); valueAnimator.setDuration(animationDuration); valueAnimator.setInterpolator(new EaseInOutBezierInterpolator()); valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator valueAnimator) { int val = (Integer) valueAnimator.getAnimatedValue(); RelativeLayout.LayoutParams toolbarParams = (RelativeLayout.LayoutParams) photoView .getLayoutParams(); toolbarParams.height = val; photoView.setLayoutParams(toolbarParams); } }); valueAnimator.addListener(new Animator.AnimatorListener() { @Override public void onAnimationStart(Animator animator) { } @Override public void onAnimationEnd(Animator animator) { photoViewAttacher.setZoomable(true); photoView.setZoomable(true); photoViewAttacher.setOnPhotoTapListener(new PhotoViewAttacher.OnPhotoTapListener() { @Override public void onPhotoTap(View view, float v, float v2) { toggleZoomImage(); } }); } @Override public void onAnimationCancel(Animator animator) { } @Override public void onAnimationRepeat(Animator animator) { } }); valueAnimator.start(); int scrollTo = isInFullscreen() ? 0 : d.getHeight(); scrollView.animate().y(scrollTo).setDuration(animationDuration) .setInterpolator(new EaseInOutBezierInterpolator()).start(); isInFullscreen = !isInFullscreen; }
From source file:org.odk.collect.android.views.ODKView.java
public void highlightWidget(FormIndex formIndex) { QuestionWidget qw = getQuestionWidget(formIndex); if (qw != null) { // postDelayed is needed because otherwise scrolling may not work as expected in case when // answers are validated during form finalization. new Handler().postDelayed(() -> { findViewById(R.id.odk_view_container).scrollTo(0, qw.getTop()); ValueAnimator va = new ValueAnimator(); if (Build.VERSION.SDK_INT > Build.VERSION_CODES.KITKAT) { va.setIntValues(getResources().getColor(R.color.red_500), getDrawingCacheBackgroundColor()); } else { // Avoid fading to black on certain devices and Android versions that may not support transparency TypedValue typedValue = new TypedValue(); getContext().getTheme().resolveAttribute(android.R.attr.windowBackground, typedValue, true); if (typedValue.type >= TypedValue.TYPE_FIRST_COLOR_INT && typedValue.type <= TypedValue.TYPE_LAST_COLOR_INT) { va.setIntValues(getResources().getColor(R.color.red_500), typedValue.data); } else { va.setIntValues(getResources().getColor(R.color.red_500), getDrawingCacheBackgroundColor()); }/*from w ww .j ava2 s .co m*/ } va.setEvaluator(new ArgbEvaluator()); va.addUpdateListener( valueAnimator -> qw.setBackgroundColor((int) valueAnimator.getAnimatedValue())); va.setDuration(2500); va.start(); }, 100); } }