List of usage examples for android.animation ObjectAnimator ofFloat
public static <T> ObjectAnimator ofFloat(T target, Property<T, Float> xProperty, Property<T, Float> yProperty, Path path)
Path
using two properties. From source file:com.flexible.flexibleadapter.AnimatorAdapter.java
/** * Item will slide from Bottom of the screen to its natural position.<br/> * Ignored if LEFT, RIGHT, TOP or BOTTOM animators were already added. * <p><b>Note:</b> Only 1 animator of the same compatible type can be added per time.<br/> * Incompatible with LEFT, RIGHT, TOP, BOTTOM animators.</p> * * @param animators user defined list/*ww w . jav a2s . c om*/ * @param view itemView to animate * @since 5.0.0-b1 * @deprecated Use {@link }. */ @Deprecated public void addSlideInFromBottomAnimator(@NonNull List<Animator> animators, @NonNull View view) { if (animatorsUsed.contains(AnimatorEnum.SLIDE_IN_LEFT) || animatorsUsed.contains(AnimatorEnum.SLIDE_IN_RIGHT) || animatorsUsed.contains(AnimatorEnum.SLIDE_IN_TOP) || animatorsUsed.contains(AnimatorEnum.SLIDE_IN_BOTTOM)) return; animators.add(ObjectAnimator.ofFloat(view, "translationY", mRecyclerView.getMeasuredHeight() >> 1, 0)); animatorsUsed.add(AnimatorEnum.SLIDE_IN_BOTTOM); }
From source file:com.aliyun.homeshell.Folder.java
public void showSelectApps(int[] pos) { if (mRunningAnimatorSet != null) { if (!mRunningIsShow) { mRunningAnimatorSet.end();/*from www . jav a 2 s .c o m*/ } else { return; } } if (mAppsSelectView == null) { mAppsSelectView = (FolderAppsSelectView) LayoutInflater.from(getContext()) .inflate(R.layout.folder_apps_select, null); mAppsSelectView.init(this, mInfo, mLauncher); mLauncher.getDragLayer().addView(mAppsSelectView); } mAppsSelectView.initSelectedState(mInfo); mAppsSelectView.setScaleX(0); mAppsSelectView.setScaleY(0); mAppsSelectView.setPivotX(pos[0]); mAppsSelectView.setPivotY(pos[1]); ObjectAnimator visToInvis = ObjectAnimator.ofFloat(this, "alpha", 1, 0); visToInvis.setDuration(mAnimatorDuration); ObjectAnimator invisToVisX = ObjectAnimator.ofFloat(mAppsSelectView, "scaleX", 0, 1); invisToVisX.setDuration(mAnimatorDuration); ObjectAnimator invisToVisY = ObjectAnimator.ofFloat(mAppsSelectView, "scaleY", 0, 1); invisToVisY.setDuration(mAnimatorDuration); List<Animator> animList = new ArrayList<Animator>(); animList.add(visToInvis); animList.add(invisToVisX); animList.add(invisToVisY); final AnimatorSet as = new AnimatorSet(); as.setInterpolator(new LinearInterpolator()); as.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationStart(Animator animator) { mAppsSelectView.setVisibility(View.VISIBLE); mRunningAnimatorSet = as; mRunningIsShow = true; } @Override public void onAnimationEnd(Animator animator) { mRunningAnimatorSet = null; mRunningIsShow = false; Folder.this.setVisibility(View.INVISIBLE); mAppsSelectView.setVisibility(View.VISIBLE); DisplayMetrics metric = new DisplayMetrics(); mLauncher.getWindowManager().getDefaultDisplay().getMetrics(metric); int width = metric.widthPixels; int height = metric.heightPixels; mAppsSelectView.setPivotX(width / 2); mAppsSelectView.setPivotY(height / 2); mAppsSelectView.setFocusableInTouchMode(true); mAppsSelectView.setFocusable(true); mAppsSelectView.requestFocus(); } }); as.playTogether(animList); as.start(); }
From source file:com.btmura.android.reddit.app.AbstractBrowserActivity.java
private AnimatorSet newExpandLeftAnimator() { ObjectAnimator slTransX = ObjectAnimator.ofFloat(leftContainer, "translationX", -leftWidth, 0); ObjectAnimator tlTransX = ObjectAnimator.ofFloat(rightContainer, "translationX", -leftWidth, 0); AnimatorSet as = new AnimatorSet(); as.setDuration(durationMs).play(slTransX).with(tlTransX); as.addListener(new AnimatorListenerAdapter() { @Override//from w w w . j a v a2s. co m public void onAnimationStart(Animator animation) { leftContainer.setLayerType(View.LAYER_TYPE_HARDWARE, null); leftContainer.setVisibility(View.VISIBLE); rightContainer.setLayerType(View.LAYER_TYPE_HARDWARE, null); rightContainer.setVisibility(View.VISIBLE); thingContainer.setVisibility(View.GONE); } @Override public void onAnimationEnd(Animator animation) { leftContainer.setLayerType(View.LAYER_TYPE_NONE, null); rightContainer.setLayerType(View.LAYER_TYPE_NONE, null); } }); return as; }
From source file:graphic.expand_graphic.ExpandingListView.java
/** * This method expands the view that was clicked and animates all the views * around it to make room for the expanding view. There are several steps * required to do this which are outlined below. * <p/>/*from ww w .j a v a2 s . co m*/ * 1. Store the current top and bottom bounds of each visible item in the * listview. 2. Update the layout parameters of the selected view. In the * context of this method, the view should be originally collapsed and set * to some custom height. The layout parameters are updated so as to wrap * the content of the additional text that is to be displayed. * <p/> * After invoking a layout to take place, the listview will order all the * items such that there is space for each view. This layout will be * independent of what the bounds of the items were prior to the layout so * two pre-draw passes will be made. This is necessary because after the * layout takes place, some views that were visible before the layout may * now be off bounds but a reference to these views is required so the * animation completes as intended. * <p/> * 3. The first predraw pass will set the bounds of all the visible items to * their original location before the layout took place and then force * another layout. Since the bounds of the cells cannot be set directly, the * method setSelectionFromTop can be used to achieve a very similar effect. * 4. The expanding view's bounds are animated to what the final values * should be from the original bounds. 5. The bounds above the expanding * view are animated upwards while the bounds below the expanding view are * animated downwards. 6. The extra text is faded in as its contents become * visible throughout the animation process. * <p/> * It is important to note that the listview is disabled during the * animation because the scrolling behaviour is unpredictable if the bounds * of the items within the listview are not constant during the scroll. */ private void expandView(final View view) { /* Store the original top and bottom bounds of all the cells. */ final int oldTop = view.getTop(); final int oldBottom = view.getBottom(); final HashMap<View, int[]> oldCoordinates = new HashMap<View, int[]>(); int childCount = getChildCount(); for (int i = 0; i < childCount; i++) { View v = getChildAt(i); ViewCompat.setHasTransientState(v, true); oldCoordinates.put(v, new int[] { v.getTop(), v.getBottom() }); } /* Update the layout so the extra content becomes visible. */ final View expandingLayout = view.findViewById(R.id.expanding_layout); expandingLayout.setVisibility(View.VISIBLE); /* * Add an onPreDraw Listener to the listview. onPreDraw will get invoked * after onLayout and onMeasure have run but before anything has been * drawn. This means that the final post layout properties for all the * items have already been determined, but still have not been rendered * onto the screen. */ final ViewTreeObserver observer = getViewTreeObserver(); observer.addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() { @Override public boolean onPreDraw() { /* Determine if this is the first or second pass. */ if (!mShouldRemoveObserver) { mShouldRemoveObserver = true; /* * Calculate what the parameters should be for * setSelectionFromTop. The ListView must be offset in a * way, such that after the animation takes place, all the * cells that remain visible are rendered completely by the * ListView. */ int newTop = view.getTop(); int newBottom = view.getBottom(); int newHeight = newBottom - newTop; int oldHeight = oldBottom - oldTop; int delta = newHeight - oldHeight; mTranslate = getTopAndBottomTranslations(oldTop, oldBottom, delta, true); int currentTop = view.getTop(); int futureTop = oldTop - mTranslate[0]; int firstChildStartTop = getChildAt(0).getTop(); int firstVisiblePosition = getFirstVisiblePosition(); int deltaTop = currentTop - futureTop; int i; int childCount = getChildCount(); for (i = 0; i < childCount; i++) { View v = getChildAt(i); int height = v.getBottom() - Math.max(0, v.getTop()); if (deltaTop - height > 0) { firstVisiblePosition++; deltaTop -= height; } else { break; } } if (i > 0) { firstChildStartTop = 0; } setSelectionFromTop(firstVisiblePosition, firstChildStartTop - deltaTop); /* * Request another layout to update the layout parameters of * the cells. */ requestLayout(); /* * Return false such that the ListView does not redraw its * contents on this layout but only updates all the * parameters associated with its children. */ return false; } /* * Remove the predraw listener so this method does not keep * getting called. */ mShouldRemoveObserver = false; observer.removeOnPreDrawListener(this); int yTranslateTop = mTranslate[0]; int yTranslateBottom = mTranslate[1]; ArrayList<Animator> animations = new ArrayList<Animator>(); int index = indexOfChild(view); /* * Loop through all the views that were on the screen before the * cell was expanded. Some cells will still be children of the * ListView while others will not. The cells that remain * children of the ListView simply have their bounds animated * appropriately. The cells that are no longer children of the * ListView also have their bounds animated, but must also be * added to a list of views which will be drawn in dispatchDraw. */ for (View v : oldCoordinates.keySet()) { int[] old = oldCoordinates.get(v); v.setTop(old[0]); v.setBottom(old[1]); if (v.getParent() == null) { mViewsToDraw.add(v); int delta = old[0] < oldTop ? -yTranslateTop : yTranslateBottom; animations.add(getAnimation(v, delta, delta)); } else { int i = indexOfChild(v); if (v != view) { int delta = i > index ? yTranslateBottom : -yTranslateTop; animations.add(getAnimation(v, delta, delta)); } ViewCompat.setHasTransientState(v, false); } } /* Adds animation for expanding the cell that was clicked. */ animations.add(getAnimation(view, -yTranslateTop, yTranslateBottom)); /* Adds an animation for fading in the extra content. */ animations.add(ObjectAnimator.ofFloat(view.findViewById(R.id.expanding_layout), View.ALPHA, 0, 1)); /* Disabled the ListView for the duration of the animation. */ setEnabled(false); setClickable(false); /* * Play all the animations created above together at the same * time. */ AnimatorSet s = new AnimatorSet(); s.playTogether(animations); s.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { viewObject.setExpanded(true); setEnabled(true); setClickable(true); if (mViewsToDraw.size() > 0) { for (View v : mViewsToDraw) { ViewCompat.setHasTransientState(v, false); } } mViewsToDraw.clear(); } }); s.start(); return true; } }); }
From source file:com.flexible.flexibleadapter.AnimatorAdapter.java
/** * Item will scale.<br/>//from ww w. j av a 2s. c o m * Ignored if SCALE animator was already added. * <p><b>Note:</b> Only 1 animator of the same compatible type can be added per time.<br/> * Incompatible with LEFT, RIGHT, BOTTOM animators.<br/> * * @param animators user defined list * @param view itemView to animate * @param scaleFrom initial scale value * @since 5.0.0-b1 * @deprecated Use {@link }. */ @Deprecated public void addScaleInAnimator(@NonNull List<Animator> animators, @NonNull View view, @FloatRange(from = 0.0, to = 1.0) float scaleFrom) { if (animatorsUsed.contains(AnimatorEnum.SCALE)) return; animators.add(ObjectAnimator.ofFloat(view, "scaleX", scaleFrom, 1f)); animators.add(ObjectAnimator.ofFloat(view, "scaleY", scaleFrom, 1f)); animatorsUsed.add(AnimatorEnum.SCALE); }
From source file:com.bartoszlipinski.viewpropertyobjectanimator.ViewPropertyObjectAnimator.java
@SuppressLint("NewApi") public ObjectAnimator get() { if (hasView()) { Collection<PropertyValuesHolder> holders = mPropertyHoldersMap.values(); ObjectAnimator animator = ObjectAnimator.ofPropertyValuesHolder(mView.get(), holders.toArray(new PropertyValuesHolder[holders.size()])); if (mWithLayer) { animator.addListener(new AnimatorListenerAdapter() { int mCurrentLayerType = View.LAYER_TYPE_NONE; @Override/*from ww w . j a va 2 s . co m*/ public void onAnimationStart(Animator animation) { if (hasView()) { View view = mView.get(); mCurrentLayerType = view.getLayerType(); view.setLayerType(View.LAYER_TYPE_HARDWARE, null); if (ViewCompat.isAttachedToWindow(view)) { view.buildLayer(); } } } @Override public void onAnimationEnd(Animator animation) { if (hasView()) { mView.get().setLayerType(mCurrentLayerType, null); } } }); } if (mStartDelay != -1) { animator.setStartDelay(mStartDelay); } if (mDuration != -1) { animator.setDuration(mDuration); } if (mInterpolator != null) { animator.setInterpolator(mInterpolator); } for (Animator.AnimatorListener listener : mListeners) { animator.addListener(listener); } if (mMarginListener != null) { animator.addUpdateListener(mMarginListener); } if (mDimensionListener != null) { animator.addUpdateListener(mDimensionListener); } if (mPaddingListener != null) { animator.addUpdateListener(mPaddingListener); } if (mScrollListener != null) { animator.addUpdateListener(mScrollListener); } if (mPercentListener != null) { animator.addUpdateListener(mPercentListener); } for (ValueAnimator.AnimatorUpdateListener listener : mUpdateListeners) { animator.addUpdateListener(listener); } if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { for (Animator.AnimatorPauseListener listener : mPauseListeners) { animator.addPauseListener(listener); } } return animator; } return ObjectAnimator.ofFloat(null, View.ALPHA, 1, 1); }
From source file:com.waz.zclient.pages.main.profile.camera.CameraFragment.java
private void showPreview(ImageAsset imageAsset, boolean bitmapFromCamera) { if (LayoutSpec.isTablet(getActivity())) { ViewUtils.lockCurrentOrientation(getActivity(), getControllerFactory().getOrientationController().getLastKnownOrientation()); }/*from ww w . j av a 2s .c o m*/ pictureFromCamera = bitmapFromCamera; if (bitmapFromCamera) { cameraPreview.setVisibility(View.GONE); } int duration = getResources().getInteger(R.integer.camera__preview__ainmation__duration); previewProgressBar.setVisibility(View.GONE); new Handler().postDelayed(new Runnable() { @Override public void run() { if (cameraBottomControl != null) { cameraBottomControl.setControlState(ControlState.DIALOG_APPROVE_SELECTION); } } }, duration); previewImageView.setImageAsset(imageAsset); final IConversation currentConversation = getStoreFactory().getConversationStore().getCurrentConversation(); if (currentConversation != null && cameraContext == CameraContext.MESSAGE) { previewTargetConversation.setText(currentConversation.getName()); previewTargetConversationContainer.setVisibility(View.VISIBLE); } else { previewTargetConversationContainer.setVisibility(View.GONE); } ObjectAnimator.ofFloat(previewImageView, View.ALPHA, 0, 1).setDuration(duration).start(); cameraState = CameraState.IDLE; }
From source file:android.support.v17.leanback.app.OnboardingSupportFragment.java
private Animator createAnimator(View view, boolean fadeIn, int slideDirection, long startDelay) { boolean isLtr = getView().getLayoutDirection() == View.LAYOUT_DIRECTION_LTR; boolean slideRight = (isLtr && slideDirection == Gravity.END) || (!isLtr && slideDirection == Gravity.START) || slideDirection == Gravity.RIGHT; Animator fadeAnimator;/* w w w. j a v a 2 s.co m*/ Animator slideAnimator; if (fadeIn) { fadeAnimator = ObjectAnimator.ofFloat(view, View.ALPHA, 0.0f, 1.0f); slideAnimator = ObjectAnimator.ofFloat(view, View.TRANSLATION_X, slideRight ? sSlideDistance : -sSlideDistance, 0); fadeAnimator.setInterpolator(HEADER_APPEAR_INTERPOLATOR); slideAnimator.setInterpolator(HEADER_APPEAR_INTERPOLATOR); } else { fadeAnimator = ObjectAnimator.ofFloat(view, View.ALPHA, 1.0f, 0.0f); slideAnimator = ObjectAnimator.ofFloat(view, View.TRANSLATION_X, 0, slideRight ? sSlideDistance : -sSlideDistance); fadeAnimator.setInterpolator(HEADER_DISAPPEAR_INTERPOLATOR); slideAnimator.setInterpolator(HEADER_DISAPPEAR_INTERPOLATOR); } fadeAnimator.setDuration(HEADER_ANIMATION_DURATION_MS); fadeAnimator.setTarget(view); slideAnimator.setDuration(HEADER_ANIMATION_DURATION_MS); slideAnimator.setTarget(view); AnimatorSet animator = new AnimatorSet(); animator.playTogether(fadeAnimator, slideAnimator); if (startDelay > 0) { animator.setStartDelay(startDelay); } return animator; }
From source file:com.waz.zclient.pages.main.profile.camera.CameraFragment.java
private void dismissPreview() { previewProgressBar.setVisibility(View.GONE); int animationDuration = getResources().getInteger(R.integer.camera__control__ainmation__duration); ObjectAnimator.ofFloat(previewImageView, View.ALPHA, 1, 0).setDuration(animationDuration).start(); new Handler().postDelayed(new Runnable() { @Override//from w w w .ja va 2s .c om public void run() { if (previewImageViewContainer != null && previewImageView != null) { previewImageViewContainer.setVisibility(View.GONE); previewImageView.setImageDrawable(null); } } }, animationDuration); showCameraFeed(); }
From source file:com.btmura.android.reddit.app.AbstractBrowserActivity.java
private AnimatorSet newCollapseRightAnimator() { ObjectAnimator tcTransX = ObjectAnimator.ofFloat(thingContainer, "translationX", leftWidth, 0); AnimatorSet as = new AnimatorSet(); as.setDuration(durationMs).play(tcTransX); as.addListener(new AnimatorListenerAdapter() { @Override//from w ww . j a v a 2s . co m public void onAnimationStart(Animator animation) { if (leftContainer != null) { leftContainer.setVisibility(View.GONE); } rightContainer.setVisibility(View.VISIBLE); thingContainer.setLayerType(View.LAYER_TYPE_HARDWARE, null); thingContainer.setVisibility(View.VISIBLE); } @Override public void onAnimationEnd(Animator animation) { thingContainer.setLayerType(View.LAYER_TYPE_NONE, null); } }); return as; }