List of usage examples for android.widget ImageView animate
public ViewPropertyAnimator animate()
From source file:com.vinay.volley.lazyload.ImageLoader.java
/** * Sets a {@link android.graphics.Bitmap} to an {@link android.widget.ImageView} using a fade-in animation. If there * is a {@link android.graphics.drawable.Drawable} already set on the ImageView then use that as the image to fade * from. Otherwise fade in from a transparent Drawable. *//*from w w w . j av a 2s. c o m*/ @TargetApi(Build.VERSION_CODES.HONEYCOMB_MR1) private static void setImageBitmap(final ImageView imageView, final Bitmap bitmap, Resources resources, boolean fadeIn) { // If we're fading in and on HC MR1+ if (fadeIn && hasHoneycombMR1()) { // Use ViewPropertyAnimator to run a simple fade in + fade out animation to update the // ImageView imageView.animate().scaleY(0.95f).scaleX(0.95f).alpha(0f) .setDuration(imageView.getDrawable() == null ? 0 : HALF_FADE_IN_TIME) .setListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { imageView.setImageBitmap(bitmap); imageView.animate().alpha(1f).scaleY(1f).scaleX(1f).setDuration(HALF_FADE_IN_TIME) .setListener(null); } }); } else if (fadeIn) { // Otherwise use a TransitionDrawable to fade in Drawable initialDrawable; if (imageView.getDrawable() != null) { initialDrawable = imageView.getDrawable(); } else { initialDrawable = transparentDrawable; } BitmapDrawable bitmapDrawable = new BitmapDrawable(resources, bitmap); // Use TransitionDrawable to fade in final TransitionDrawable td = new TransitionDrawable( new Drawable[] { initialDrawable, bitmapDrawable }); imageView.setImageDrawable(td); td.startTransition(ANIMATION_FADE_IN_TIME); } else { // No fade in, just set bitmap directly imageView.setImageBitmap(bitmap); } }
From source file:com.conferenceengineer.android.iosched.util.ImageLoader.java
/** * Sets a {@link android.graphics.Bitmap} to an {@link android.widget.ImageView} using a * fade-in animation. If there is a {@link android.graphics.drawable.Drawable} already set on * the ImageView then use that as the image to fade from. Otherwise fade in from a transparent * Drawable./* w w w. j a va 2 s.c o m*/ */ @TargetApi(Build.VERSION_CODES.HONEYCOMB_MR1) private static void setImageBitmap(final ImageView imageView, final Bitmap bitmap, Resources resources, boolean fadeIn) { // If we're fading in and on HC MR1+ if (fadeIn && UIUtils.hasHoneycombMR1()) { // Use ViewPropertyAnimator to run a simple fade in + fade out animation to update the // ImageView imageView.animate().scaleY(0.95f).scaleX(0.95f).alpha(0f) .setDuration(imageView.getDrawable() == null ? 0 : HALF_FADE_IN_TIME) .setListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { imageView.setImageBitmap(bitmap); imageView.animate().alpha(1f).scaleY(1f).scaleX(1f).setDuration(HALF_FADE_IN_TIME) .setListener(null); } }); } else if (fadeIn) { // Otherwise use a TransitionDrawable to fade in Drawable initialDrawable; if (imageView.getDrawable() != null) { initialDrawable = imageView.getDrawable(); } else { initialDrawable = transparentDrawable; } BitmapDrawable bitmapDrawable = new BitmapDrawable(resources, bitmap); // Use TransitionDrawable to fade in final TransitionDrawable td = new TransitionDrawable( new Drawable[] { initialDrawable, bitmapDrawable }); imageView.setImageDrawable(td); td.startTransition(UIUtils.ANIMATION_FADE_IN_TIME); } else { // No fade in, just set bitmap directly imageView.setImageBitmap(bitmap); } }
From source file:com.android.volley.cache.plus.SimpleImageLoader.java
/** * Sets a {@link android.graphics.Bitmap} to an {@link android.widget.ImageView} using a * fade-in animation. If there is a {@link android.graphics.drawable.Drawable} already set on * the ImageView then use that as the image to fade from. Otherwise fade in from a transparent * Drawable.//from w w w.ja v a2 s . c om */ @TargetApi(Build.VERSION_CODES.HONEYCOMB_MR1) private static void setImageBitmap(final ImageView imageView, final BitmapDrawable bitmapDrawable, Resources resources, boolean fadeIn) { // If we're fading in and on HC MR1+ if (fadeIn && Utils.hasHoneycombMR1()) { // Use ViewPropertyAnimator to run a simple fade in + fade out animation to update the // ImageView imageView.animate().scaleY(0.95f).scaleX(0.95f).alpha(0f) .setDuration(imageView.getDrawable() == null ? 0 : HALF_FADE_IN_TIME) .setListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { imageView.setImageDrawable(bitmapDrawable); imageView.animate().alpha(1f).scaleY(1f).scaleX(1f).setDuration(HALF_FADE_IN_TIME) .setListener(null); } }); } else if (fadeIn) { // Otherwise use a TransitionDrawable to fade in Drawable initialDrawable; if (imageView.getDrawable() != null) { initialDrawable = imageView.getDrawable(); } else { initialDrawable = transparentDrawable; } // Use TransitionDrawable to fade in final TransitionDrawable td = new TransitionDrawable( new Drawable[] { initialDrawable, bitmapDrawable }); imageView.setImageDrawable(td); td.startTransition(Utils.ANIMATION_FADE_IN_TIME); } else { // No fade in, just set bitmap directly imageView.setImageDrawable(bitmapDrawable); } }
From source file:com.android.volley.cache.SimpleImageLoader.java
/** * Sets a {@link android.graphics.Bitmap} to an {@link android.widget.ImageView} using a * fade-in animation. If there is a {@link android.graphics.drawable.Drawable} already set on * the ImageView then use that as the image to fade from. Otherwise fade in from a transparent * Drawable./* w w w . jav a 2s . com*/ */ @TargetApi(Build.VERSION_CODES.HONEYCOMB_MR1) private static void setImageBitmap(final ImageView imageView, final Bitmap bitmap, Resources resources, boolean fadeIn) { // If we're fading in and on HC MR1+ if (fadeIn && Utils.hasHoneycombMR1()) { // Use ViewPropertyAnimator to run a simple fade in + fade out animation to update the // ImageView imageView.animate().scaleY(0.95f).scaleX(0.95f).alpha(0f) .setDuration(imageView.getDrawable() == null ? 0 : HALF_FADE_IN_TIME) .setListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { imageView.setImageBitmap(bitmap); imageView.animate().alpha(1f).scaleY(1f).scaleX(1f).setDuration(HALF_FADE_IN_TIME) .setListener(null); } }); } else if (fadeIn) { // Otherwise use a TransitionDrawable to fade in Drawable initialDrawable; if (imageView.getDrawable() != null) { initialDrawable = imageView.getDrawable(); } else { initialDrawable = transparentDrawable; } BitmapDrawable bitmapDrawable = new BitmapDrawable(resources, bitmap); // Use TransitionDrawable to fade in final TransitionDrawable td = new TransitionDrawable( new Drawable[] { initialDrawable, bitmapDrawable }); imageView.setImageDrawable(td); td.startTransition(Utils.ANIMATION_FADE_IN_TIME); } else { // No fade in, just set bitmap directly imageView.setImageBitmap(bitmap); } }
From source file:com.google.android.apps.forscience.whistlepunk.intro.TutorialActivity.java
private void finishTutorial() { // Need to mark ourselves as done and finish. SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this); preferences.edit().putInt(KEY_TUTORIAL_VERSION_SEEN, TUTORIAL_VERSION).apply(); ImageView view = (ImageView) findViewById(R.id.logo); view.animate().scaleXBy(3).scaleYBy(3).alpha(.1f).setDuration(500).setStartDelay(50) .setInterpolator(new AccelerateInterpolator()).setListener(new Animator.AnimatorListener() { @Override/*from w w w .jav a2 s. c o m*/ public void onAnimationStart(Animator animation) { } @Override public void onAnimationEnd(Animator animation) { launchOrFinish(); } @Override public void onAnimationCancel(Animator animation) { } @Override public void onAnimationRepeat(Animator animation) { } }).start(); }
From source file:com.github.antoniodisanto92.swipeselector.SwipeAdapter.java
private void animate(float alpha, ImageView button) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) { button.animate().alpha(alpha).setDuration(120).start(); } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR1) { ObjectAnimator.ofFloat(button, "alpha", alpha == 1 ? 0 : alpha, alpha == 1 ? alpha : 0).setDuration(120) .start();/*from w w w . j a v a 2 s .c om*/ } else { setAlpha(alpha, button); } }
From source file:edu.uark.spARK.SwipeDismissListViewTouchListener.java
@Override public boolean onTouch(View view, MotionEvent motionEvent) { if (mViewWidth < 2) { mViewWidth = mListView.getWidth(); }/*from w w w.java2 s . com*/ switch (motionEvent.getActionMasked()) { case MotionEvent.ACTION_DOWN: { mPaused = false; longClickActive = false; // if (mPaused) { // return false; // } // TODO: ensure this is a finger, and set a flag // Find the child view that was touched (perform a hit test) Rect rect = new Rect(); int childCount = mListView.getChildCount(); int[] listViewCoords = new int[2]; mListView.getLocationOnScreen(listViewCoords); int x = (int) motionEvent.getRawX() - listViewCoords[0]; int y = (int) motionEvent.getRawY() - listViewCoords[1]; View child; //ignore header views for (int i = 1; i < childCount; i++) { child = mListView.getChildAt(i); child.getHitRect(rect); if (rect.contains(x, y)) { mDownView = child; break; } } if (mDownView != null) { mDownView = mDownView.findViewById(R.id.table); mDownX = motionEvent.getRawX(); //TODO: really need to figure out why npe is happening here try { mDownPosition = mListView.getPositionForView(mDownView); } catch (NullPointerException npe) { //why does this keep happening? npe.printStackTrace(); } if (mCallbacks.canDismiss(mDownPosition)) { mVelocityTracker = VelocityTracker.obtain(); mVelocityTracker.addMovement(motionEvent); } else { mDownView = null; } } view.onTouchEvent(motionEvent); return true; } case MotionEvent.ACTION_UP: { if (longClickActive) { RelativeLayout darkenTop = (RelativeLayout) mListView.getRootView() .findViewById(R.id.darkenScreenTop); ImageView darkenBottom = (ImageView) mListView.getRootView().findViewById(R.id.darkenScreenBottom); darkenTop.animate().alpha(0).setDuration(mAnimationTime).setListener(null); darkenBottom.animate().alpha(0).setDuration(mAnimationTime).setListener(null); if (mVelocityTracker == null) { break; } float deltaX = motionEvent.getRawX() - mDownX; mVelocityTracker.addMovement(motionEvent); mVelocityTracker.computeCurrentVelocity(1000); float velocityX = mVelocityTracker.getXVelocity(); float absVelocityX = Math.abs(velocityX); float absVelocityY = Math.abs(mVelocityTracker.getYVelocity()); boolean dismiss = false; boolean dismissRight = false; if (Math.abs(deltaX) > mViewWidth / 2) { dismiss = true; dismissRight = deltaX > 0; } else if (mMinFlingVelocity <= absVelocityX && absVelocityX <= mMaxFlingVelocity && absVelocityY < absVelocityX) { // dismiss only if flinging in the same direction as dragging dismiss = (velocityX < 0) == (deltaX < 0); dismissRight = mVelocityTracker.getXVelocity() > 0; } if (dismiss) { // dismiss dismiss(mDownView, mDownPosition, dismissRight); } else { // cancel mDownView.animate().translationX(0).alpha(1).setDuration(mAnimationTime).setListener(null); } mVelocityTracker.recycle(); mVelocityTracker = null; mDownX = 0; mDownView = null; mDownPosition = ListView.INVALID_POSITION; mSwiping = false; } break; } case MotionEvent.ACTION_CANCEL: { longClickActive = false; mPaused = false; RelativeLayout darkenTop = (RelativeLayout) mListView.getRootView().findViewById(R.id.darkenScreenTop); ImageView darkenBottom = (ImageView) mListView.getRootView().findViewById(R.id.darkenScreenBottom); darkenTop.animate().alpha(0).setDuration(mAnimationTime).setListener(null); darkenBottom.animate().alpha(0).setDuration(mAnimationTime).setListener(null); if (mVelocityTracker == null) { break; } if (mDownView != null) { // cancel mDownView.animate().translationX(0).alpha(1).setDuration(mAnimationTime).setListener(null); } mVelocityTracker.recycle(); mVelocityTracker = null; mDownX = 0; mDownView = null; mDownPosition = ListView.INVALID_POSITION; mSwiping = false; break; } case MotionEvent.ACTION_MOVE: { if (mVelocityTracker == null || mPaused) { break; } if (longClickActive) { mVelocityTracker.addMovement(motionEvent); float deltaX = motionEvent.getRawX() - mDownX; //the if statement is allowing the listview to scroll until a sufficient deltaX is made, while we want swiping immediately // if (Math.abs(deltaX) > mSlop) { mSwiping = true; mListView.requestDisallowInterceptTouchEvent(true); // Cancel ListView's touch (un-highlighting the item) which is not what we want MotionEvent cancelEvent = MotionEvent.obtain(motionEvent); cancelEvent.setAction(MotionEvent.ACTION_CANCEL | (motionEvent.getActionIndex() << MotionEvent.ACTION_POINTER_INDEX_SHIFT)); mListView.onTouchEvent(cancelEvent); cancelEvent.recycle(); // } if (mSwiping) { mDownView.setTranslationX(deltaX); //we don't want the alpha to change // mDownView.setAlpha(Math.max(0.15f, Math.min(1f, // 1f - 2f * Math.abs(deltaX) / mViewWidth))); return true; } } break; } } return false; }
From source file:ca.zadrox.dota2esportticker.ui.LiveContentView.java
@Override public void setPlayerItem(int playerSlot, int itemSlot, int resId) { ImageView imageView = (ImageView) mPlayerLayouts[playerSlot].findViewById(itemViewIds[itemSlot]); switch (resId) { case 0:/*w w w .j a v a2 s .com*/ imageView.animate().setDuration(200).alpha(0).setInterpolator(new AccelerateInterpolator()); default: imageView.setImageResource(resId); imageView.animate().setDuration(200).alpha(1).setInterpolator(new DecelerateInterpolator()); } }
From source file:com.rnd.snapsplit.view.OcrCaptureFragment.java
private void createNewThread() { t = new Thread() { @Override/*from www . ja va2 s . c o m*/ public void run() { try { while (shouldContinue) { Thread.sleep(1); if (getActivity() == null) { return; } getActivity().runOnUiThread(new Runnable() { @Override public void run() { if (mGraphicOverlay.amountItem != null) { final ImageView upArrow = (ImageView) getView().findViewById(R.id.arrow_up); upArrow.animate().rotation(180).setDuration(500).start(); rotationAngle = 180; TextView amountTV = (TextView) getView().findViewById(R.id.text_amount_value); String amount = mGraphicOverlay.amountItem.getTextBlock().getValue(); amount = amount.replaceAll("\\s+", ""); amount = amount.replaceAll("[$]", ""); amountTV.setText(amount); RelativeLayout box = (RelativeLayout) getView() .findViewById(R.id.recognition_box); box.setVisibility(View.VISIBLE); Animation slide_up = AnimationUtils .loadAnimation(getActivity().getApplicationContext(), R.anim.slide_up); box.startAnimation(slide_up); onPause(); t.interrupt(); } } }); } } catch (InterruptedException e) { } } }; }
From source file:fr.shywim.antoinedaniel.ui.fragment.SoundPagerFragment.java
private void openFab(View fab) { if (mFabIsOpen) return;/*w ww . jav a 2 s .co m*/ mFabIsOpen = true; ImageView icSettings = (ImageView) fab.findViewById(R.id.fab_settings_icon); ImageView icClose = (ImageView) fab.findViewById(R.id.fab_settings_icon_close); View root = (View) fab.getParent(); View fabMiniLoop = root.findViewById(R.id.fab_mini_loop); View fabMiniLoopHint = root.findViewById(R.id.fab_mini_loop_hint); View fabMiniDownloaded = root.findViewById(R.id.fab_mini_downloaded); View fabMiniDownloadedHint = root.findViewById(R.id.fab_mini_downloaded_hint); icSettings.animate().rotation(360).alpha(0).setDuration(250); icClose.animate().rotation(360).alpha(1).setDuration(250); fabMiniLoop.clearAnimation(); ((View) fabMiniLoop.getParent()).setVisibility(View.VISIBLE); fabMiniLoop.animate().scaleX(1).scaleY(1).setListener(null).setDuration(150); fabMiniLoopHint.animate().alpha(1).setDuration(150); fabMiniDownloaded.clearAnimation(); ((View) fabMiniDownloaded.getParent()).setVisibility(View.VISIBLE); fabMiniDownloaded.animate().scaleX(1).scaleY(1).setListener(null).setStartDelay(100).setDuration(150); fabMiniDownloadedHint.animate().alpha(1).setStartDelay(100).setDuration(150); if (PrefUtils.getShowOnlyDownloaded(mActivity)) { setFabMiniChecked(fabMiniDownloaded); } else { setFabMiniUnchecked(fabMiniDownloaded); } if (SoundUtils.isLoopingSet()) { setFabMiniChecked(fabMiniLoop); } else { setFabMiniUnchecked(fabMiniLoop); } }