@Override protected void onFinishInflate() { super.onFinishInflate(); // Get the drawable mOriginalTextColor = getTextColors(); // Get the hover color Resources r = getResources(); mHoverColor = r.getColor(R.color.delete_target_hover_tint); mHoverPaint.setColorFilter(new PorterDuffColorFilter(mHoverColor, PorterDuff.Mode.SRC_ATOP)); mUninstallDrawable = (TransitionDrawable) r.getDrawable(R.drawable.uninstall_target_selector); mRemoveDrawable = (TransitionDrawable) r.getDrawable(R.drawable.remove_target_selector); mRemoveDrawable.setCrossFadeEnabled(true); mUninstallDrawable.setCrossFadeEnabled(true); // The current drawable is set to either the remove drawable or the uninstall drawable // and is initially set to the remove drawable, as set in the layout xml. mCurrentDrawable = (TransitionDrawable) getCompoundDrawables()[0]; // Remove the text in the Phone UI in landscape int orientation = getResources().getConfiguration().orientation; if (orientation == Configuration.ORIENTATION_LANDSCAPE) { if (!LauncherApplication.isScreenLarge()) { setText(""); } } }
public void run() { if (imageViewReused(photoToLoad)) return; if (bitmap != null) { if (FADE_IN_BITMAP) { final TransitionDrawable td = new TransitionDrawable( new Drawable[] { new ColorDrawable(android.R.color.transparent), new BitmapDrawable(mResources, bitmap) }); photoToLoad.imageView.setImageDrawable(td); td.startTransition(FADE_IN_TIME); } else { photoToLoad.imageView.setImageBitmap(bitmap); } // end if } else { try { photoToLoad.imageView.setImageResource(R.drawable.icon_book_big); } catch (Exception e) { e.printStackTrace(); } // photoToLoad.imageView.setImageResource(R.drawable.no_image); } // end if }
public void toggleLightControl(boolean on) { if (on) { // Update UI switch (mCurrentMode) { case R.id.mode_lightbulb: case R.id.mode_viewfinder: mDrawable.startTransition(200); break; case R.id.mode_lightswitch: mLightswitch.setChecked(true); break; } } else { // Update UI switch (mCurrentMode) { case R.id.mode_lightbulb: case R.id.mode_viewfinder: mDrawable.reverseTransition(300); break; case R.id.mode_lightswitch: mLightswitch.setChecked(false); break; } } }
public static Drawable fromDrawable( Drawable drawable, float radius, int border, int borderColor) { if (drawable != null) { if (drawable instanceof TransitionDrawable) { TransitionDrawable td = (TransitionDrawable) drawable; int num = td.getNumberOfLayers(); Drawable[] drawableList = new Drawable[num]; for (int i = 0; i < num; i++) { Drawable d = td.getDrawable(i); if (d instanceof ColorDrawable) { // TODO skip colordrawables for now drawableList[i] = d; } else { drawableList[i] = new RoundedDrawable( drawableToBitmap(td.getDrawable(i)), radius, border, borderColor); } } return new TransitionDrawable(drawableList); } Bitmap bm = drawableToBitmap(drawable); if (bm != null) { return new RoundedDrawable(bm, radius, border, borderColor); } else { Log.w(TAG, "Failed to create bitmap from drawable!"); } } return drawable; }
/** * Called when the processing is complete and the final bitmap should be set on the ImageView. * * @param imageView * @param bitmap */ private void setImageBitmap(ImageView imageView, Bitmap bitmap) { callback.invoke("success", 200); if (mFadeInBitmap) { // Transition drawable with a transparent drwabale and the final // bitmap final TransitionDrawable td = new TransitionDrawable( new Drawable[] { new ColorDrawable(android.R.color.transparent), new BitmapDrawable(mContext.getResources(), bitmap) }); // Set background to loading bitmap // imageView.setBackgroundDrawable(new BitmapDrawable(mContext // .getResources(), mLoadingBitmap)); imageView.setImageDrawable(td); // if (bitmap.getHeight() > imageView.getHeight()) { // imageView.setLayoutParams(new LinearLayout.LayoutParams(bitmap // .getWidth(), bitmap.getHeight())); // } else { // imageView.setLayoutParams(new LinearLayout.LayoutParams(bitmap // .getWidth(), imageView.getHeight())); // // } td.startTransition(FADE_IN_TIME); } else { // if (bitmap.getHeight() > imageView.getHeight()) { // imageView.setLayoutParams(new // RelativeLayout.LayoutParams(imageView // .getWidth(), WallPicActivity.itemheight)); // } imageView.setImageBitmap(bitmap); } }
public void testResetTransition() { MockCallBack cb = new MockCallBack(); mTransitionDrawable.setCallback(cb); // reset when there is no transition cb.reset(); mTransitionDrawable.resetTransition(); assertTrue(cb.hasCalledInvalidateDrawable()); // reset when there is a transition in progress makeTransitionInProgress(2000, 1000); cb.reset(); mTransitionDrawable.resetTransition(); assertTrue(cb.hasCalledInvalidateDrawable()); assertTransitionStart(COLOR0); assertTransitionEnd(COLOR0, 2000); // reset when there is a reverse transition in progress makeReverseTransitionInProgress(2000, 1000); cb.reset(); mTransitionDrawable.resetTransition(); assertTrue(cb.hasCalledInvalidateDrawable()); assertTransitionStart(COLOR0); assertTransitionEnd(COLOR0, 2000); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_transicion); ImageView imagen1 = (ImageView) findViewById(R.id.img1); TransitionDrawable mi_transicion = (TransitionDrawable) getResources().getDrawable(R.drawable.transicion); imagen1.setImageDrawable(mi_transicion); mi_transicion.startTransition(1000); btn = (Button) findViewById(R.id.btnAnimacion); btn.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { /*Intent miIntent= new Intent(Transicion.this, Animacion.class); Bundle miBundle=new Bundle(); miIntent.putExtras(miBundle); startActivity(miIntent);*/ Intent miIntent = new Intent(Transicion.this, Animacion.class); Bundle miBundle = new Bundle(); miIntent.putExtras(miBundle); startActivityForResult(miIntent, COD_RESPUESTA); } }); }
public void testStartTransition() { MockCallBack cb = new MockCallBack(); mTransitionDrawable.setCallback(cb); // start when there is no transition cb.reset(); mTransitionDrawable.startTransition(2000); assertTrue(cb.hasCalledInvalidateDrawable()); assertTransition(COLOR0, COLOR1, 2000); // start when there is a transition in progress makeTransitionInProgress(2000, 1000); cb.reset(); mTransitionDrawable.startTransition(2000); assertTrue(cb.hasCalledInvalidateDrawable()); assertTransition(COLOR0, COLOR1, 2000); // start when there is a reverse transition in progress makeReverseTransitionInProgress(2000, 1000); cb.reset(); mTransitionDrawable.startTransition(2000); assertTrue(cb.hasCalledInvalidateDrawable()); assertTransition(COLOR0, COLOR1, 2000); // should not accept negative duration mTransitionDrawable.startTransition(-1); }
/** * 改变ActionBar color * * @param newColor 颜色值 */ private void setActionBarcolor(int newColor) { // 改变ActionBar颜色如果ActionBar是可用的 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { Drawable colorDrawable = new ColorDrawable(newColor); Drawable bottomDrawable = getResources().getDrawable(R.drawable.abc_ab_share_pack_mtrl_alpha); LayerDrawable ld = new LayerDrawable(new Drawable[] {colorDrawable, bottomDrawable}); if (oldBackground == null) { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1) { ld.setCallback(drawableCallback); } else { getActionBar().setBackgroundDrawable(ld); } } else { TransitionDrawable td = new TransitionDrawable(new Drawable[] {oldBackground, ld}); // 解决了破碎ActionBarContainer可拉的处理 // pre-API 17 builds // https://github.com/android/platform_frameworks_base/commit/a7cc06d82e45918c37429a59b14545c6a57db4e4 if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1) { td.setCallback(drawableCallback); } else { getActionBar().setBackgroundDrawable(td); } td.startTransition(200); } } }
private void fadeOutBadge(final Runnable onAnimationComplete) { synchronized (lock) { if (!animationRunning // animation is already running, so shouldn't // start a new one && lastIncremented.get() != 0 // counter was reset, in which // case it would be // unintuitive for the badge // to fade && badgeTextView.getVisibility() == View.VISIBLE) { // animation isn't already showing, and the badge is visible animationRunning = true; badgeLinearLayout.setVisibility(View.VISIBLE); // show an animation for the badge with the textview and the // background linearlayout fading out Animation fadeOutAnimation = AnimationUtils.loadAnimation(context, android.R.anim.fade_out); fadeOutAnimation.setDuration(ANIMATION_TIME); fadeOutAnimation.setAnimationListener( new AnimationListener() { @Override public void onAnimationStart(Animation animation) {} @Override public void onAnimationRepeat(Animation animation) {} @Override public void onAnimationEnd(Animation animation) { synchronized (lock) { badgeTextView.setVisibility(View.INVISIBLE); // necessary to update again to set the history text // view correctly onAnimationComplete.run(); animationRunning = false; } } }); badgeTextView.setAnimation(fadeOutAnimation); fadeOutAnimation.start(); TransitionDrawable transitionDrawable = (TransitionDrawable) badgeLinearLayout.getBackground(); transitionDrawable.setCrossFadeEnabled(true); transitionDrawable.startTransition(ANIMATION_TIME); } else { // just don't show it - the animation might already be showing, // or maybe the badge is // already invisible badgeLinearLayout.setVisibility(View.INVISIBLE); badgeTextView.setVisibility(View.INVISIBLE); // this ensures that the history text view gets updated // properly, even if the user // exits the activity while the animation is in progress (e.g. // by going to the Settings) onAnimationComplete.run(); } } }
private void TimerOnFinish() { // Sync threads !! CurrentGame.AcquireLOCK(); isAnimating = true; SecondsLeft_TimeTrial = 0; CurrentGame.SetGameInfoText(); CurrentGame.Btn_Power.setEnabled(false); SetEnableControls(false, CurrentGame.GameBoard); ImageView[] availableCards = new ImageView[CurrentGame.RowSize * CurrentGame.ColumnSize]; int length = GetAvailableCards(availableCards); if (length == 1) { TransitionDrawable cross_fade = CreateTransitionDrawable( R.drawable.lock, R.drawable.card_destroyed, CurrentGame.mContext); ImageView card = availableCards[0]; card.getParent().requestChildFocus(card, card); card.setOnClickListener(null); card.setImageDrawable(cross_fade); cross_fade.startTransition(800); new CountDownTimer(800, 800) { @Override public void onTick(long milliSecondsToFinish) {} @Override public void onFinish() { // Sync threads !! CurrentGame.AcquireLOCK(); CurrentGame.GameTimer.cancel(); CurrentGame.postGameLogic(); SetEnableControls(true, CurrentGame.GameBoard); CurrentGame.Btn_Power.setEnabled(true); // Sync threads !! CurrentGame.ReleaseLOCK(); isAnimating = false; } }.start(); } else if (length == 2) { ShuffleCards(availableCards, length); } else if (length > 2) { if (CurrentGame.EffectiveClickCount % 2 == 0 && Math.random() <= .75) // Replace card 75% time for first card { ImageView[] selected_cards = SelectCardsRandomly(availableCards, length, POW_REPLACE); ReplaceCards(selected_cards, selected_cards.length); } else { ImageView[] selected_cards = SelectCardsRandomly(availableCards, length, POW_SHUFFLE); ShuffleCards(selected_cards, selected_cards.length); } } // Sync threads !! CurrentGame.ReleaseLOCK(); }
private void makeReverseTransitionInProgress(int duration, int delay) { mTransitionDrawable.resetTransition(); mTransitionDrawable.startTransition(2000); assertTransition(COLOR0, COLOR1, 2000); mTransitionDrawable.reverseTransition(duration); assertTransitionStart(COLOR1); assertTransitionInProgress(COLOR1, COLOR0, delay); }
// This boolean takes effect when the drawable is drawn and the effect can not be tested. public void testAccessCrossFadeEnabled() { assertFalse(mTransitionDrawable.isCrossFadeEnabled()); mTransitionDrawable.setCrossFadeEnabled(true); assertTrue(mTransitionDrawable.isCrossFadeEnabled()); mTransitionDrawable.setCrossFadeEnabled(false); assertFalse(mTransitionDrawable.isCrossFadeEnabled()); }
public void selectOffButton(Button button) { TransitionDrawable drawable = (TransitionDrawable) button.getBackground(); drawable.reverseTransition(100); ObjectAnimator colorAnim = ObjectAnimator.ofInt(button, "textColor", Color.BLACK, Color.WHITE); colorAnim.setDuration(100); colorAnim.setEvaluator(new ArgbEvaluator()); colorAnim.start(); }
void populateFrom( String date, boolean from_me, String from, String message, int delivery_status) { // Log.i(TAG, "populateFrom(" + from_me + ", " + from + ", " + message + ")"); getDateView().setText(date); TypedValue tv = new TypedValue(); if (from_me) { getTheme().resolveAttribute(R.attr.ChatMsgHeaderMeColor, tv, true); getDateView().setTextColor(tv.data); getFromView().setText(getString(R.string.chat_from_me)); getFromView().setTextColor(tv.data); } else { getTheme().resolveAttribute(R.attr.ChatMsgHeaderYouColor, tv, true); getDateView().setTextColor(tv.data); getFromView().setText(from + ":"); getFromView().setTextColor(tv.data); } switch (delivery_status) { case ChatConstants.DS_NEW: ColorDrawable layers[] = new ColorDrawable[2]; getTheme().resolveAttribute(R.attr.ChatNewMessageColor, tv, true); layers[0] = new ColorDrawable(tv.data); if (from_me) { // message stored for later transmission getTheme().resolveAttribute(R.attr.ChatStoredMessageColor, tv, true); layers[1] = new ColorDrawable(tv.data); } else { layers[1] = new ColorDrawable(0x00000000); } TransitionDrawable backgroundColorAnimation = new TransitionDrawable(layers); int l = mRowView.getPaddingLeft(); int t = mRowView.getPaddingTop(); int r = mRowView.getPaddingRight(); int b = mRowView.getPaddingBottom(); mRowView.setBackgroundDrawable(backgroundColorAnimation); mRowView.setPadding(l, t, r, b); backgroundColorAnimation.setCrossFadeEnabled(true); backgroundColorAnimation.startTransition(DELAY_NEWMSG); getIconView().setImageResource(R.drawable.ic_chat_msg_status_queued); break; case ChatConstants.DS_SENT_OR_READ: getIconView().setImageResource(R.drawable.ic_chat_msg_status_unread); mRowView.setBackgroundColor(0x00000000); // default is transparent break; case ChatConstants.DS_ACKED: getIconView().setImageResource(R.drawable.ic_chat_msg_status_ok); mRowView.setBackgroundColor(0x00000000); // default is transparent break; case ChatConstants.DS_FAILED: getIconView().setImageResource(R.drawable.ic_chat_msg_status_failed); mRowView.setBackgroundColor(0x30ff0000); // default is transparent break; } getMessageView().setText(message); getMessageView().setTextSize(TypedValue.COMPLEX_UNIT_SP, chatWindow.mChatFontSize); }
/** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); ImageView imagen = new ImageView(this); // ImageView imagen = (ImageView) findViewById(R.id.transicionId); setContentView(imagen); TransitionDrawable mi_transicion = (TransitionDrawable) getResources().getDrawable(R.drawable.transicion); imagen.setImageDrawable(mi_transicion); mi_transicion.startTransition(7000); }
/** * Called when the processing is complete and the final drawable should be set on the ImageView. * * @param imageView * @param drawable */ private void setImageDrawable(ImageView imageView, Drawable drawable) { if (mFadeInBitmap) { final TransitionDrawable td = new TransitionDrawable( new Drawable[] {new ColorDrawable(android.R.color.transparent), drawable}); // imageView.setBackgroundDrawable(new BitmapDrawable(mResources, mLoadingBitmap)); imageView.setImageDrawable(td); td.startTransition(FADE_IN_TIME); } else { imageView.setImageDrawable(drawable); } }
private void makeBadgeVisible() { synchronized (lock) { // show the badge, canceling the "fade out" animation if necessary TransitionDrawable transitionDrawable = (TransitionDrawable) badgeLinearLayout.getBackground(); transitionDrawable.resetTransition(); if (badgeTextView.getAnimation() != null) { badgeTextView.clearAnimation(); } badgeTextView.setVisibility(View.VISIBLE); badgeLinearLayout.setVisibility(View.VISIBLE); } }
private void setImage(View view, Drawable drawable, boolean crossfade) { if (view instanceof TextView) { // Cross-fading is not implemented for TextView since it's not in use. It would be easy to // add it, though. TextView textView = (TextView) view; textView.setCompoundDrawablesWithIntrinsicBounds(drawable, null, null, null); } else if (view instanceof ImageView) { ImageView imageView = (ImageView) view; if (crossfade) { Drawable existingDrawable = imageView.getDrawable(); if (existingDrawable == null) { Bitmap emptyImage; if (drawable.getIntrinsicWidth() > 0 && drawable.getIntrinsicHeight() > 0) { emptyImage = Bitmap.createBitmap( drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(), Bitmap.Config.ARGB_8888); } else { emptyImage = Bitmap.createBitmap(imageSizeDefault, imageSizeDefault, Bitmap.Config.ARGB_8888); } existingDrawable = new BitmapDrawable(context.getResources(), emptyImage); } else { // Try to get rid of old transitions try { TransitionDrawable tmp = (TransitionDrawable) existingDrawable; int layers = tmp.getNumberOfLayers(); existingDrawable = tmp.getDrawable(layers - 1); } catch (Exception e) { // Do nothing, just means that the drawable is a flat image } } if (!(((BitmapDrawable) existingDrawable) .getBitmap() .isRecycled())) { // We will flow through to the non-transition if the old image is // recycled... Yay 4.3 Drawable[] layers = new Drawable[] {existingDrawable, drawable}; TransitionDrawable transitionDrawable = new TransitionDrawable(layers); imageView.setImageDrawable(transitionDrawable); transitionDrawable.startTransition(250); return; } } imageView.setImageDrawable(drawable); return; } }
private TransitionDrawable createIconTransition(Drawable d, ImageView iView) { Resources res = getContext().getResources(); TransitionDrawable out = new TransitionDrawable( new Drawable[] { this.getContext().getResources().getDrawable(R.drawable.event_blank_image), d.getCurrent() }); out.setCrossFadeEnabled(true); iView.setImageDrawable(out); out.startTransition(500); return out; }
@Override public void onStart() { super.onStart(); if (hasServerChanged) { updateServerState(); } if (isLoggedIn()) logo.startTransition(0); else logo.resetTransition(); tabManager.showTab(); running = true; }
public void setBitmap(Bitmap bitmap) { // Make sure uri and original are consistently both null or both // non-null. if (bitmap == null) { mThumb = null; mThumbs = null; setImageDrawable(null); setVisibility(GONE); return; } LayoutParams param = getLayoutParams(); final int miniThumbWidth = param.width - getPaddingLeft() - getPaddingRight(); final int miniThumbHeight = param.height - getPaddingTop() - getPaddingBottom(); mThumb = ThumbnailUtils.extractThumbnail(bitmap, miniThumbWidth, miniThumbHeight); if (mThumbs == null || !mEnableAnimation) { mThumbs = new Drawable[2]; mThumbs[1] = new BitmapDrawable(getContext().getResources(), mThumb); setImageDrawable(mThumbs[1]); } else { mThumbs[0] = mThumbs[1]; mThumbs[1] = new BitmapDrawable(getContext().getResources(), mThumb); mThumbTransition = new TransitionDrawable(mThumbs); setImageDrawable(mThumbTransition); mThumbTransition.startTransition(500); } setVisibility(VISIBLE); }
public void animateCircularClip(int x, int y, boolean in, AnimatorListener listener) { if (mAnimator != null) { mAnimator.cancel(); } final int w = mDetail.getWidth() - x; final int h = mDetail.getHeight() - y; int innerR = 0; if (x < 0 || w < 0 || y < 0 || h < 0) { innerR = Math.abs(x); innerR = Math.min(innerR, Math.abs(y)); innerR = Math.min(innerR, Math.abs(w)); innerR = Math.min(innerR, Math.abs(h)); } int r = (int) Math.ceil(Math.sqrt(x * x + y * y)); r = (int) Math.max(r, Math.ceil(Math.sqrt(w * w + y * y))); r = (int) Math.max(r, Math.ceil(Math.sqrt(w * w + h * h))); r = (int) Math.max(r, Math.ceil(Math.sqrt(x * x + h * h))); if (in) { mAnimator = ViewAnimationUtils.createCircularReveal(mDetail, x, y, innerR, r); } else { mAnimator = ViewAnimationUtils.createCircularReveal(mDetail, x, y, r, innerR); } mAnimator.setDuration((long) (mAnimator.getDuration() * 1.5)); if (listener != null) { mAnimator.addListener(listener); } if (in) { mBackground.startTransition((int) (mAnimator.getDuration() * 0.6)); mAnimator.addListener(mVisibleOnStart); } else { mDetail.postDelayed(mReverseBackground, (long) (mAnimator.getDuration() * 0.65)); mAnimator.addListener(mGoneOnEnd); } mAnimator.start(); }
@Override public void onNewCurrentServer(Server server) { this.server = server; if (isLoggedIn()) { logo.startTransition(500); } else { logo.reverseTransition(500); } if (running) { tabManager.setServer(server); } else { this.hasServerChanged = true; } }
public void testDrawWithNUllCanvas() { try { mTransitionDrawable.draw(null); fail("The method should check whether the canvas is null."); } catch (NullPointerException e) { } }
@Override public void onResume() { // to fade the settings button ImageButton settingsButton = (ImageButton) getActivity().findViewById(R.id.button_settings); switch (mCurrentMode) { case R.id.mode_lightswitch: mLightswitch = (LightSwitch) getActivity().findViewById(R.id.button_lightswitch); mLightswitch.setChecked(false); if (mOn) mLightswitch.setChecked(true); mLightswitch.setOnCheckedChangeListener( new OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton button, boolean isChecked) { mListener.onLightControlClick(isChecked); } }); settingsButton.setAlpha(255); break; case R.id.mode_blackout: Button image = (Button) getActivity().findViewById(R.id.button_black); Animation fadeOut = AnimationUtils.loadAnimation(getActivity(), R.anim.fade_out); image.startAnimation(fadeOut); settingsButton.setAlpha(90); break; case R.id.mode_viewfinder: case R.id.mode_lightbulb: mBulb = (ImageButton) getActivity().findViewById(R.id.button_bulb); mDrawable = (TransitionDrawable) mBulb.getDrawable(); mDrawable.setCrossFadeEnabled(true); if (mOn) mDrawable.startTransition(0); settingsButton.setAlpha(255); break; } PreviewSurface surface = (PreviewSurface) getActivity().findViewById(R.id.surface); if (mCurrentMode == R.id.mode_viewfinder) { surface.setLayoutParams( new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT)); } else { surface.setLayoutParams(new LayoutParams(1, 1)); } super.onResume(); }
/** * Sets a {@link Bitmap} to an {@link ImageView} using a fade-in animation. If there is a {@link * Drawable} already set on the ImageView then use that as the image to fade from. Otherwise fade * in from a transparent Drawable. */ @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); } }
public void onDragExit(DragObject d) { super.onDragExit(d); if (!d.dragComplete) { mCurrentDrawable.resetTransition(); setTextColor(mOriginalTextColor); } }
/** * Called when the processing is complete and the final drawable should be set on the ImageView. * * @param imageView * @param drawable */ private void setImageDrawable(ImageView imageView, Drawable drawable) { if (mFadeInBitmap) { // Transition drawable with a transparent drawable and the final drawable final TransitionDrawable td = new TransitionDrawable( new Drawable[] {new ColorDrawable(android.R.color.transparent), drawable}); // Set background to loading bitmap // imageView.setBackgroundDrawable( // new BitmapDrawable(mResources, mLoadingBitmap)); imageView.setBackgroundDrawable(mResources.getDrawable(defaultRsId)); imageView.setImageDrawable(td); td.startTransition(FADE_IN_TIME); } else { imageView.setImageDrawable(drawable); } }
/** * Start a transition to the new image * * @param drawable the drawable to set */ public void setFadingImageDrawable(Drawable drawable) { Drawable currentDrawable = getDrawable(); if ((currentDrawable != null) && (currentDrawable instanceof TransitionDrawable)) { currentDrawable = ((TransitionDrawable) currentDrawable).getDrawable(1); } if (currentDrawable != null) { Drawable[] arrayDrawable = new Drawable[2]; arrayDrawable[0] = currentDrawable; arrayDrawable[1] = drawable; TransitionDrawable transitionDrawable = new TransitionDrawable(arrayDrawable); transitionDrawable.setCrossFadeEnabled(true); setImageDrawable(transitionDrawable); transitionDrawable.startTransition(transitionDurationMillis); } else { setImageDrawable(drawable); } }