List of usage examples for android.animation ObjectAnimator setDuration
@Override @NonNull public ObjectAnimator setDuration(long duration)
From source file:com.stanzione.licensesmanagement.ui.ContactRecyclerAdapter.java
@Override public void onBindViewHolder(final ViewHolder holder, int position) { final Contact currentContact = values.get(position); final int contactPosition = position; holder.contactListItemName.setText(currentContact.getFirstName() + " " + currentContact.getLastName()); holder.contactListItemTitle.setText(currentContact.getTitle()); holder.contactListItemCompanyName.setText(currentContact.getCompanyName()); holder.contactListItemEmail.setText(currentContact.getEmail()); holder.contactListItemTelNumber.setText(currentContact.getTelNumber()); if (showEdit) { holder.contactListItemRemoveIcon.setVisibility(View.VISIBLE); holder.contactListItemEditIcon.setVisibility(View.VISIBLE); //ObjectAnimator anim = ObjectAnimator.ofFloat(holder.companyListItemAddress, "alpha", 0f, 1f); //anim.setDuration(1000); //anim.start(); ObjectAnimator animEditIcon = ObjectAnimator.ofFloat(holder.contactListItemEditIcon, "translationX", holder.contactListItemEditIcon.getX(), originalEditIconPosition); animEditIcon.setDuration(500); animEditIcon.start();/* ww w . j a va 2 s . co m*/ ObjectAnimator animRemoveIcon = ObjectAnimator.ofFloat(holder.contactListItemRemoveIcon, "translationX", holder.contactListItemRemoveIcon.getX(), originalRemoveIconPosition); animRemoveIcon.setDuration(500); animRemoveIcon.setStartDelay(100); animRemoveIcon.start(); } else { if (isFirstLoad) { holder.contactListItemEditIcon.setVisibility(View.INVISIBLE); holder.contactListItemRemoveIcon.setVisibility(View.INVISIBLE); } else { holder.contactListItemEditIcon.setVisibility(View.VISIBLE); holder.contactListItemRemoveIcon.setVisibility(View.VISIBLE); } ObjectAnimator animEditIcon = ObjectAnimator.ofFloat(holder.contactListItemEditIcon, "translationX", originalEditIconPosition, originalEditIconPosition + 300); animEditIcon.setDuration(500); animEditIcon.setStartDelay(100); animEditIcon.start(); ObjectAnimator animRemoveIcon = ObjectAnimator.ofFloat(holder.contactListItemRemoveIcon, "translationX", originalRemoveIconPosition, originalRemoveIconPosition + 300); animRemoveIcon.setDuration(500); animRemoveIcon.start(); } holder.contactListItemEditIcon.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Log.d(TAG, "selectedContact ID: " + currentContact.getId()); activity.get().onContactToEdit(contactPosition); } }); holder.contactListItemRemoveIcon.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { AlertDialog.Builder builder = new AlertDialog.Builder(context); builder.setTitle("Remove Contact").setMessage("Are you sure you want to remove this Contact?") .setIcon(android.R.drawable.ic_dialog_alert) .setPositiveButton("Remove", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { Log.d(TAG, "Removing contact: " + currentContact.getId() + " - " + currentContact.getFirstName()); removeContact(contactPosition); } }).setNegativeButton("Cancel", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { // User cancelled the dialog } }); builder.create().show(); } }); holder.contactListRelativeLayout.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Log.d(TAG, "selectedContact ID: " + currentContact.getId()); activity.get().onContactSelected(contactPosition); } }); }
From source file:com.josecalles.porridge.widget.BottomSheet.java
@Override public void onStopNestedScroll(View child) { final int dragDisplacement = dragView.getTop() - dragViewTop; if (dragDisplacement == 0) return;/*from www. j a v a2 s .c o m*/ // check if we should perform a dismiss or settle back into place final boolean dismiss = lastNestedScrollWasDownward && dragDisplacement >= dragDismissDistance; // animate either back into place or to bottom ObjectAnimator settleAnim = ObjectAnimator.ofInt(dragViewOffsetHelper, ViewOffsetHelper.OFFSET_Y, dragView.getTop(), dismiss ? dragViewBottom : dragViewTop); settleAnim.setDuration(200L); settleAnim.setInterpolator( AnimationUtils.loadInterpolator(getContext(), android.R.interpolator.fast_out_slow_in)); if (dismiss) { settleAnim.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { dispatchDismissCallback(); } }); } settleAnim.start(); }
From source file:fr.tvbarthel.apps.cameracolorpicker.activities.MainActivity.java
/** * Make a subtle animation for a {@link com.melnykov.fab.FloatingActionButton} drawing attention to the button. * * @param fab the {@link com.melnykov.fab.FloatingActionButton} to animate. *///w ww . ja v a2 s . c o m private void animateFab(final FloatingActionButton fab) { fab.postDelayed(new Runnable() { @Override public void run() { // Play a subtle animation final long duration = 450; final ObjectAnimator scaleXAnimator = ObjectAnimator.ofFloat(fab, View.SCALE_X, 1f, 1.2f, 1f); scaleXAnimator.setDuration(duration); scaleXAnimator.setRepeatCount(1); final ObjectAnimator scaleYAnimator = ObjectAnimator.ofFloat(fab, View.SCALE_Y, 1f, 1.2f, 1f); scaleYAnimator.setDuration(duration); scaleYAnimator.setRepeatCount(1); scaleXAnimator.start(); scaleYAnimator.start(); final AnimatorSet animatorSet = new AnimatorSet(); animatorSet.play(scaleXAnimator).with(scaleYAnimator); animatorSet.start(); } }, 400); }
From source file:com.tr4android.support.extension.picker.time.RadialTimePickerView.java
@TargetApi(Build.VERSION_CODES.HONEYCOMB) private static ObjectAnimator getFadeOutAnimator(IntHolder target, int startAlpha, int endAlpha, InvalidateUpdateListener updateListener) { final ObjectAnimator animator = ObjectAnimator.ofInt(target, "value", startAlpha, endAlpha); animator.setDuration(FADE_OUT_DURATION); animator.addUpdateListener(updateListener); return animator; }
From source file:com.tr4android.support.extension.picker.time.RadialTimePickerView.java
@TargetApi(Build.VERSION_CODES.HONEYCOMB) private static ObjectAnimator getFadeInAnimator(IntHolder target, int startAlpha, int endAlpha, InvalidateUpdateListener updateListener) { final float delayMultiplier = 0.25f; final float transitionDurationMultiplier = 1f; final float totalDurationMultiplier = transitionDurationMultiplier + delayMultiplier; final int totalDuration = (int) (FADE_IN_DURATION * totalDurationMultiplier); final float delayPoint = (delayMultiplier * FADE_IN_DURATION) / totalDuration; final Keyframe kf0, kf1, kf2; kf0 = Keyframe.ofInt(0f, startAlpha); kf1 = Keyframe.ofInt(delayPoint, startAlpha); kf2 = Keyframe.ofInt(1f, endAlpha);/*from w ww . ja va 2 s .c om*/ final PropertyValuesHolder fadeIn = PropertyValuesHolder.ofKeyframe("value", kf0, kf1, kf2); final ObjectAnimator animator = ObjectAnimator.ofPropertyValuesHolder(target, fadeIn); animator.setDuration(totalDuration); animator.addUpdateListener(updateListener); return animator; }
From source file:comm.lib.photoview.PhotoViewActivity.java
private void toggleDownLoadToolbar(final View view) { // API 11/*from w w w . j a v a 2s. c om*/ if (Build.VERSION.SDK_INT >= 11) { if (view.getVisibility() == View.VISIBLE) { ObjectAnimator hideAnimator = ObjectAnimator.ofFloat(view, "translationY", view.getTranslationY(), view.getHeight()); hideAnimator.setDuration(400); hideAnimator.start(); hideAnimator.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { view.setVisibility(View.GONE); } }); } else { view.setVisibility(View.VISIBLE); ObjectAnimator showAnimator = ObjectAnimator.ofFloat(view, "translationY", view.getTranslationY(), 0); showAnimator.setDuration(400); showAnimator.start(); } } else { if (view.getVisibility() == View.VISIBLE) { view.setVisibility(View.GONE); } else { view.setVisibility(View.VISIBLE); } } }
From source file:com.android.tv.settings.dialog.old.BaseDialogFragment.java
public void performEntryTransition(final Activity activity, final ViewGroup contentView, int iconResourceId, Uri iconResourceUri, final ImageView icon, final TextView title, final TextView description, final TextView breadcrumb) { // Pull out the root layout of the dialog and set the background drawable, to be // faded in during the transition. final ViewGroup twoPane = (ViewGroup) contentView.getChildAt(0); twoPane.setVisibility(View.INVISIBLE); // If the appropriate data is embedded in the intent and there is an icon specified // in the content fragment, we animate the icon from its initial position to the final // position. Otherwise, we perform a simpler transition in which the ActionFragment // slides in and the ContentFragment text fields slide in. mIntroAnimationInProgress = true;//from ww w . java 2 s . c om List<TransitionImage> images = TransitionImage.readMultipleFromIntent(activity, activity.getIntent()); TransitionImageAnimation ltransitionAnimation = null; final Uri iconUri; final int color; if (images != null && images.size() > 0) { if (iconResourceId != 0) { iconUri = Uri.parse(UriUtils.getAndroidResourceUri(activity, iconResourceId)); } else if (iconResourceUri != null) { iconUri = iconResourceUri; } else { iconUri = null; } TransitionImage src = images.get(0); color = src.getBackground(); if (iconUri != null) { ltransitionAnimation = new TransitionImageAnimation(contentView); ltransitionAnimation.addTransitionSource(src); ltransitionAnimation.transitionDurationMs(ANIMATE_IN_DURATION).transitionStartDelayMs(0) .interpolator(new DecelerateInterpolator(1f)); } } else { iconUri = null; color = 0; } final TransitionImageAnimation transitionAnimation = ltransitionAnimation; // Fade out the old activity, and hard cut the new activity. activity.overridePendingTransition(R.anim.hard_cut_in, R.anim.fade_out); int bgColor = mFragment.getResources().getColor(R.color.dialog_activity_background); mBgDrawable.setColor(bgColor); mBgDrawable.setAlpha(0); twoPane.setBackground(mBgDrawable); // If we're animating the icon, we create a new ImageView in which to place the embedded // bitmap. We place it in the root layout to match its location in the previous activity. mShadowLayer = (FrameLayoutWithShadows) twoPane.findViewById(R.id.shadow_layout); if (transitionAnimation != null) { transitionAnimation.listener(new TransitionImageAnimation.Listener() { @Override public void onRemovedView(TransitionImage src, TransitionImage dst) { if (icon != null) { //want to make sure that users still see at least the source image // if the dst image is too large to finish downloading before the // animation is done. Check if the icon is not visible. This mean // BaseContentFragement have not finish downloading the image yet. if (icon.getVisibility() != View.VISIBLE) { icon.setImageDrawable(src.getBitmap()); int intrinsicWidth = icon.getDrawable().getIntrinsicWidth(); LayoutParams lp = icon.getLayoutParams(); lp.height = lp.width * icon.getDrawable().getIntrinsicHeight() / intrinsicWidth; icon.setVisibility(View.VISIBLE); } icon.setAlpha(1f); } if (mShadowLayer != null) { mShadowLayer.setShadowsAlpha(1f); } onIntroAnimationFinished(); } }); icon.setAlpha(0f); if (mShadowLayer != null) { mShadowLayer.setShadowsAlpha(0f); } } // We need to defer the remainder of the animation preparation until the first // layout has occurred, as we don't yet know the final location of the icon. twoPane.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { @Override public void onGlobalLayout() { twoPane.getViewTreeObserver().removeOnGlobalLayoutListener(this); // if we buildLayer() at this time, the texture is actually not created // delay a little so we can make sure all hardware layer is created before // animation, in that way we can avoid the jittering of start animation twoPane.postOnAnimationDelayed(mEntryAnimationRunnable, ANIMATE_DELAY); } final Runnable mEntryAnimationRunnable = new Runnable() { @Override public void run() { if (!mFragment.isAdded()) { // We have been detached before this could run, so just bail return; } twoPane.setVisibility(View.VISIBLE); final int secondaryDelay = SLIDE_IN_DISTANCE; // Fade in the activity background protection ObjectAnimator oa = ObjectAnimator.ofInt(mBgDrawable, "alpha", 255); oa.setDuration(ANIMATE_IN_DURATION); oa.setStartDelay(secondaryDelay); oa.setInterpolator(new DecelerateInterpolator(1.0f)); oa.start(); View actionFragmentView = activity.findViewById(mActionAreaId); boolean isRtl = ViewCompat.getLayoutDirection(contentView) == ViewCompat.LAYOUT_DIRECTION_RTL; int startDist = isRtl ? SLIDE_IN_DISTANCE : -SLIDE_IN_DISTANCE; int endDist = isRtl ? -actionFragmentView.getMeasuredWidth() : actionFragmentView.getMeasuredWidth(); // Fade in and slide in the ContentFragment TextViews from the start. prepareAndAnimateView(title, 0, startDist, secondaryDelay, ANIMATE_IN_DURATION, new DecelerateInterpolator(1.0f), false); prepareAndAnimateView(breadcrumb, 0, startDist, secondaryDelay, ANIMATE_IN_DURATION, new DecelerateInterpolator(1.0f), false); prepareAndAnimateView(description, 0, startDist, secondaryDelay, ANIMATE_IN_DURATION, new DecelerateInterpolator(1.0f), false); // Fade in and slide in the ActionFragment from the end. prepareAndAnimateView(actionFragmentView, 0, endDist, secondaryDelay, ANIMATE_IN_DURATION, new DecelerateInterpolator(1.0f), false); if (icon != null && transitionAnimation != null) { // now we get the icon view in place, update the transition target TransitionImage target = new TransitionImage(); target.setUri(iconUri); target.createFromImageView(icon); if (icon.getBackground() instanceof ColorDrawable) { ColorDrawable d = (ColorDrawable) icon.getBackground(); target.setBackground(d.getColor()); } transitionAnimation.addTransitionTarget(target); transitionAnimation.startTransition(); } else if (icon != null) { prepareAndAnimateView(icon, 0, startDist, secondaryDelay, ANIMATE_IN_DURATION, new DecelerateInterpolator(1.0f), true /* is the icon */); if (mShadowLayer != null) { mShadowLayer.setShadowsAlpha(0f); } } } }; }); }
From source file:io.plaidapp.ui.FilterAdapter.java
@Override public FilterViewHolder onCreateViewHolder(ViewGroup viewGroup, int viewType) { final FilterViewHolder holder = new FilterViewHolder( LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.filter_item, viewGroup, false)); holder.itemView.setOnClickListener(new View.OnClickListener() { @Override/*from www . ja va2s .c om*/ public void onClick(View v) { final int position = holder.getAdapterPosition(); if (position == RecyclerView.NO_POSITION) return; final Source filter = filters.get(position); if (isAuthorisedDribbbleSource(filter) && !DribbblePrefs.get(holder.itemView.getContext()).isLoggedIn()) { authoriser.requestDribbbleAuthorisation(holder.filterIcon, filter); } else { holder.itemView.setHasTransientState(true); ObjectAnimator fade = ObjectAnimator.ofInt(holder.filterIcon, ViewUtils.IMAGE_ALPHA, filter.active ? FILTER_ICON_DISABLED_ALPHA : FILTER_ICON_ENABLED_ALPHA); fade.setDuration(300); fade.setInterpolator(AnimationUtils.loadInterpolator(holder.itemView.getContext(), android.R.interpolator.fast_out_slow_in)); fade.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { holder.itemView.setHasTransientState(false); } }); fade.start(); filter.active = !filter.active; holder.filterName.setEnabled(filter.active); notifyItemChanged(position); SourceManager.updateSource(filter, holder.itemView.getContext()); dispatchFiltersChanged(filter); } } }); return holder; }
From source file:com.github.jokar.rxupload.widget.ProgressDownloadView.java
public void setPercentage(float newProgress) { if (newProgress < 0 || newProgress > 100) { throw new IllegalArgumentException("setPercentage not between 0 and 100"); }//from ww w .j a v a2 s . co m mState = State.STATE_WORKING; mTarget = newProgress; ObjectAnimator anim = ObjectAnimator.ofFloat(this, "progress", getProgress(), mTarget); anim.setInterpolator(new DecelerateInterpolator()); anim.setDuration((long) (ANIMATION_DURATION_BASE + Math.abs(mTarget * 10 - getProgress() * 10) / 2)); anim.start(); }
From source file:com.android.messaging.ui.conversationlist.ConversationListSwipeHelper.java
/** * Create and start an animator that animates the given view's translationX * from its current value to the value given by animateTo. *//*from w w w .j a v a2 s . c om*/ private ObjectAnimator getSwipeTranslationXAnimator(final ConversationListItemView itemView, final float animateTo, final long duration, final TimeInterpolator interpolator) { final ObjectAnimator animator = ObjectAnimator.ofFloat(itemView, "swipeTranslationX", animateTo); animator.setDuration(duration); animator.setInterpolator(interpolator); return animator; }