Java Code Examples for android.graphics.drawable.TransitionDrawable#setCrossFadeEnabled()

The following examples show how to use android.graphics.drawable.TransitionDrawable#setCrossFadeEnabled() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BaseFadeInNetworkImageView.java    From soas with Apache License 2.0 6 votes vote down vote up
@Override
public void setImageBitmap(Bitmap bitmap) {
    // For configureBounds to be called and quick set.
    super.setImageBitmap(bitmap);

    if (bitmap != null) {
        Resources res = getResources();
        Drawable[] layers = new Drawable[2];

        // Layer 0.
        layers[0] = res.getDrawable(R.drawable.default_photo);

        // Layer 1.
        // For masking the Bitmap after scale_type is used.
        layers[1] = new BitmapDrawable(res, clipBitmap(bitmap));

        TransitionDrawable transitionDrawable = new TransitionDrawable(layers);
        transitionDrawable.setCrossFadeEnabled(true);
        setImageDrawable(transitionDrawable);
        transitionDrawable.startTransition(400);
    }
}
 
Example 2
Source File: AsyncImageDownloadTask.java    From HomeGenie-Android with GNU General Public License v3.0 6 votes vote down vote up
private void setImage(ImageView imageView, Bitmap bitmap) {
    if (animate) {
        Resources resources = imageView.getResources();
        BitmapDrawable drawable = new BitmapDrawable(resources, bitmap);
        Drawable currentDrawable = imageView.getDrawable();
        if (currentDrawable != null) {
            Drawable[] arrayDrawable = new Drawable[2];
            arrayDrawable[0] = currentDrawable;
            arrayDrawable[1] = drawable;
            final TransitionDrawable transitionDrawable = new TransitionDrawable(arrayDrawable);
            transitionDrawable.setCrossFadeEnabled(true);
            imageView.setImageDrawable(transitionDrawable);
            transitionDrawable.startTransition(150);
        } else {
            imageView.setImageDrawable(drawable);
        }
    } else {
        imageView.setImageBitmap(bitmap);
    }
}
 
Example 3
Source File: InfoDropTarget.java    From TurboLauncher with Apache License 2.0 6 votes vote down vote up
@Override
protected void onFinishInflate() {
    super.onFinishInflate();

    mOriginalTextColor = getTextColors();

    // Get the hover color
    Resources r = getResources();
    mHoverColor = r.getColor(R.color.info_target_hover_tint);
    mDrawable = (TransitionDrawable) getCurrentDrawable();
    if (null != mDrawable) {
        mDrawable.setCrossFadeEnabled(true);
    }

    // Remove the text in the Phone UI in landscape
    int orientation = getResources().getConfiguration().orientation;
    if (orientation == Configuration.ORIENTATION_LANDSCAPE) {
        if (!LauncherAppState.getInstance().isScreenLarge()) {
            setText("");
        }
    }
}
 
Example 4
Source File: DexCrossFadeImageView.java    From DexMovingImageView with Apache License 2.0 6 votes vote down vote up
/**
 * 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);
    }
}
 
Example 5
Source File: FileViewModel.java    From Jockey with Apache License 2.0 6 votes vote down vote up
@Bindable
public Drawable getThumbnail() {
    if (mThumbnail == null) {
        mUsingDefaultArtwork = true;
        return mDefaultThumbnail;
    } else if (mUsingDefaultArtwork) {
        // If the default artwork was shown, but a replacement image was loaded later,
        // fade it in
        mUsingDefaultArtwork = false;
        TransitionDrawable crossFade = new TransitionDrawable(new Drawable[] {
                mDefaultThumbnail,
                mThumbnail
        });
        crossFade.setCrossFadeEnabled(true);
        crossFade.startTransition(getResources()
                .getInteger(R.integer.file_thumbnail_crossfade_duration_ms));
        return crossFade;
    } else {
        return mThumbnail;
    }
}
 
Example 6
Source File: SearchViewLayout.java    From Search-View-Layout with Apache License 2.0 5 votes vote down vote up
/***
 * Set the background colours of the searchview.
 * @param collapsedDrawable drawable for collapsed state, default transparent
 * @param expandedDrawable drawable for expanded state, default color.default_color_expanded
 */
public void setTransitionDrawables(Drawable collapsedDrawable, Drawable expandedDrawable) {
    this.mCollapsedDrawable = collapsedDrawable;
    this.mExpandedDrawable = expandedDrawable;

    mBackgroundTransition = new TransitionDrawable(new Drawable[]{mCollapsedDrawable, mExpandedDrawable});
    mBackgroundTransition.setCrossFadeEnabled(true);
    setBackgroundCompat();
    Utils.setPaddingAll(SearchViewLayout.this, 8);
}
 
Example 7
Source File: ColorTransitionImageDisplayer.java    From sketch with Apache License 2.0 5 votes vote down vote up
@Override
public void display(@NonNull SketchView sketchView, @NonNull Drawable newDrawable) {
    TransitionDrawable transitionDrawable = new TransitionDrawable(new Drawable[]{new ColorDrawable(color), newDrawable});
    sketchView.clearAnimation();
    sketchView.setImageDrawable(transitionDrawable);
    transitionDrawable.setCrossFadeEnabled(true);
    transitionDrawable.startTransition(duration);
}
 
Example 8
Source File: DeleteDropTarget.java    From LB-Launcher with Apache License 2.0 5 votes vote down vote up
@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);
    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) getCurrentDrawable();

    // Remove the text in the Phone UI in landscape
    int orientation = getResources().getConfiguration().orientation;
    if (orientation == Configuration.ORIENTATION_LANDSCAPE) {
        if (!LauncherAppState.getInstance().isScreenLarge()) {
            setText("");
        }
    }
}
 
Example 9
Source File: DrawableCrossFadeViewAnimation.java    From giffun with Apache License 2.0 5 votes vote down vote up
/**
 * Animates from the previous drawable to the current drawable in one of two ways.
 *
 * <ol>
 *     <li>Using the default animation provided in the constructor if the previous drawable is null</li>
 *     <li>Using the cross fade animation with the duration provided in the constructor if the previous
 *     drawable is non null</li>
 * </ol>
 *
 * @param current {@inheritDoc}
 * @param adapter  {@inheritDoc}
 * @return {@inheritDoc}
 */
@Override
public boolean animate(T current, ViewAdapter adapter) {
    Drawable previous = adapter.getCurrentDrawable();
    if (previous != null) {
        TransitionDrawable transitionDrawable = new TransitionDrawable(new Drawable[] { previous, current });
        transitionDrawable.setCrossFadeEnabled(true);
        transitionDrawable.startTransition(duration);
        adapter.setDrawable(transitionDrawable);
        return true;
    } else {
        defaultAnimation.animate(current, adapter);
        return false;
    }
}
 
Example 10
Source File: SnippetArticleViewHolder.java    From 365browser with Apache License 2.0 5 votes vote down vote up
private void fadeThumbnailIn(SnippetArticle snippet, Bitmap thumbnail, boolean owned) {
    mImageCallback = null;
    if (thumbnail == null) return; // Nothing to do, we keep the placeholder.

    // We need to crop and scale the downloaded bitmap, as the ImageView we set it on won't be
    // able to do so when using a TransitionDrawable (as opposed to the straight bitmap).
    // That's a limitation of TransitionDrawable, which doesn't handle layers of varying sizes.
    if (thumbnail.getHeight() != mThumbnailSize || thumbnail.getWidth() != mThumbnailSize) {
        // Resize the thumbnail. If we fully own the input bitmap (e.g. it isn't cached anywhere
        // else), recycle the input image in the process.
        thumbnail = ThumbnailUtils.extractThumbnail(thumbnail, mThumbnailSize, mThumbnailSize,
                owned ? ThumbnailUtils.OPTIONS_RECYCLE_INPUT : 0);
    }

    // Store the bitmap to skip the download task next time we display this snippet.
    snippet.setThumbnailBitmap(mUiDelegate.getReferencePool().put(thumbnail));

    // Cross-fade between the placeholder and the thumbnail. We cross-fade because the incoming
    // image may have transparency and we don't want the previous image showing up behind.
    Drawable[] layers = {mThumbnailView.getDrawable(),
            new BitmapDrawable(mThumbnailView.getResources(), thumbnail)};
    TransitionDrawable transitionDrawable = new TransitionDrawable(layers);
    mThumbnailView.setScaleType(ImageView.ScaleType.CENTER_CROP);
    mThumbnailView.setBackground(null);
    mThumbnailView.setImageDrawable(transitionDrawable);
    mThumbnailView.setTint(null);
    transitionDrawable.setCrossFadeEnabled(true);
    transitionDrawable.startTransition(FADE_IN_ANIMATION_TIME_MS);
}
 
Example 11
Source File: AlbumItemViewModel.java    From Jockey with Apache License 2.0 5 votes vote down vote up
private void setDrawableWithFade(Drawable start, Drawable end) {
    TransitionDrawable transition = new TransitionDrawable(new Drawable[]{start, end});
    transition.setCrossFadeEnabled(true);
    transition.startTransition(300);

    setDrawable(transition);
}
 
Example 12
Source File: DeleteDropTarget.java    From TurboLauncher with Apache License 2.0 5 votes vote down vote up
@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);
    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) getCurrentDrawable();

    // Remove the text in the Phone UI in landscape
    int orientation = getResources().getConfiguration().orientation;
    if (orientation == Configuration.ORIENTATION_LANDSCAPE) {
        if (!LauncherAppState.getInstance().isScreenLarge()) {
            setText("");
        }
    }
}
 
Example 13
Source File: ECardFlowLayout.java    From ECardFlow with MIT License 5 votes vote down vote up
private void startTrans(int targetPosition, ImageView targetImage, RecyclingBitmapDrawable startBp, RecyclingBitmapDrawable endBp) {
    if (endBp == null)
        endBp = loadBitmap(targetPosition);
    TransitionDrawable td = new TransitionDrawable(new Drawable[] {startBp, endBp});
    targetImage.setImageDrawable(td);
    td.setCrossFadeEnabled(true);
    td.startTransition(mSwitchAnimTime);
}
 
Example 14
Source File: BottomBar.java    From Camera2 with Apache License 2.0 5 votes vote down vote up
private TransitionDrawable crossfadeDrawable(Drawable from, Drawable to)
{
    Drawable[] arrayDrawable = new Drawable[2];
    arrayDrawable[0] = from;
    arrayDrawable[1] = to;
    TransitionDrawable transitionDrawable = new TransitionDrawable(arrayDrawable);
    transitionDrawable.setCrossFadeEnabled(true);
    return transitionDrawable;
}
 
Example 15
Source File: UARTActivity.java    From Android-nRF-Toolbox with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
/**
 * Updates the ActionBar background color depending on whether we are in edit mode or not.
 * 
 * @param editMode
 *            <code>true</code> to show edit mode, <code>false</code> otherwise
 * @param change
 *            if <code>true</code> the background will change with animation, otherwise immediately
 */
@SuppressLint("NewApi")
private void setEditMode(final boolean editMode, final boolean change) {
	this.editMode = editMode;
	configurationListener.setEditMode(editMode);
	if (!change) {
		final ColorDrawable color = new ColorDrawable();
		int darkColor = 0;
		if (editMode) {
			color.setColor(ContextCompat.getColor(this, R.color.orange));
			darkColor = ContextCompat.getColor(this, R.color.dark_orange);
		} else {
			color.setColor(ContextCompat.getColor(this, R.color.actionBarColor));
			darkColor = ContextCompat.getColor(this, R.color.actionBarColorDark);
		}
		getSupportActionBar().setBackgroundDrawable(color);

		// Since Lollipop the status bar color may also be changed
		if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
			getWindow().setStatusBarColor(darkColor);
	} else {
		final TransitionDrawable transition = (TransitionDrawable) getResources().getDrawable(
				editMode ? R.drawable.start_edit_mode : R.drawable.stop_edit_mode);
		transition.setCrossFadeEnabled(true);
		getSupportActionBar().setBackgroundDrawable(transition);
		transition.startTransition(200);

		// Since Lollipop the status bar color may also be changed
		if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
			final int colorFrom = ContextCompat.getColor(this, editMode ? R.color.actionBarColorDark : R.color.dark_orange);
			final int colorTo = ContextCompat.getColor(this, !editMode ? R.color.actionBarColorDark : R.color.dark_orange);

			final ValueAnimator anim = ValueAnimator.ofObject(new ArgbEvaluator(), colorFrom, colorTo);
			anim.setDuration(200);
			anim.addUpdateListener(animation -> getWindow().setStatusBarColor((Integer) animation.getAnimatedValue()));
			anim.start();
		}

		if (slider != null && editMode) {
			slider.closePane();
		}
	}
}
 
Example 16
Source File: ECardFlowLayout.java    From ECardFlow with MIT License 4 votes vote down vote up
private void jumpBgToTarget(final int targetPosition) {
    mCurPosition = targetPosition;
    if (isSwitching) {
        return;
    }
    isSwitching = true;
    final RecyclingBitmapDrawable newBitmap = loadBitmap(targetPosition);
    TransitionDrawable td = new TransitionDrawable(new Drawable[] {curBp, newBitmap});
    mBgImage.setImageDrawable(td);
    td.setCrossFadeEnabled(true);
    td.startTransition(mSwitchAnimTime);
    if (mBlurImage != null) {
        TransitionDrawable tdb = new TransitionDrawable(new Drawable[] {new BitmapDrawable(mContext.getResources(), curBlurBp),
                new BitmapDrawable(mContext.getResources(), blurBitmap(targetPosition))});
        mBlurImage.setImageDrawable(tdb);
        tdb.setCrossFadeEnabled(true);
        tdb.startTransition(mSwitchAnimTime);
    }
    mBgImage.postDelayed(new Runnable() {
        @Override
        public void run() {
            mThreadPool.execute(new Runnable() {
                @Override
                public void run() {
                    detachBitmap(nextBp);
                    detachBitmap(lastBp);
                    detachBitmap(curBp);
                    curBp = newBitmap;
                    nextBp = loadBitmap(targetPosition + 1);
                    lastBp = loadBitmap(targetPosition - 1);
                    if (mBlurImage != null) {
                        recycleBitmap(nextBlurBp);
                        recycleBitmap(lastBlurBp);
                        recycleBitmap(curBlurBp);
                        curBlurBp = blurBitmap(targetPosition);
                        nextBlurBp = blurBitmap(targetPosition + 1);
                        lastBlurBp = blurBitmap(targetPosition - 1);
                    }
                    sendMsg();
                }
            });
        }
    }, mSwitchAnimTime);
}
 
Example 17
Source File: CrossbowImage.java    From CrossBow with Apache License 2.0 4 votes vote down vote up
@VisibleForTesting
void setBitmap(Bitmap bitmap, boolean fromCache) {
    ImageView imageView = this.imageView.get();
    if (bitmap != null && imageView != null) {

        Resources resources = imageView.getResources();
        BitmapDrawable bitmapDrawable = new BitmapDrawable(resources, bitmap);
        ScaleTypeDrawable bitmapScale = new ScaleTypeDrawable(bitmapDrawable, this.scaleType, this.debug && fromCache);

        if (this.fade != DEFAULT && !fromCache) {

            //Do a fade with an animation drawable

            if (defaultDrawable != null) {
                ScaleTypeDrawable defaultScale = new ScaleTypeDrawable(defaultDrawable, this.preScaleType);

                Drawable[] layers = new Drawable[2];
                layers[0] = defaultScale;
                layers[1] = bitmapScale;

                TransitionDrawable animationDrawable = new TransitionDrawable(layers);
                imageView.setImageDrawable(animationDrawable);
                animationDrawable.setCrossFadeEnabled(true);
                animationDrawable.startTransition(this.fade);
            }
            else {
                AlphaAnimation alphaAnimation = new AlphaAnimation(0,1);
                alphaAnimation.setDuration(this.fade);
                imageView.setImageDrawable(bitmapScale);
                imageView.startAnimation(alphaAnimation);
            }
        }
        else {
            //just set the bitmap
            imageView.setImageDrawable(bitmapScale);
        }

        if (this.listener != null) {
            this.listener.onLoad(true, fromCache, bitmap, imageView);
        }
    }
}
 
Example 18
Source File: TransitionDrawableActivity.java    From coursera-android with MIT License 3 votes vote down vote up
@Override
public void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);

	setContentView(R.layout.main);
	
	TransitionDrawable transition = (TransitionDrawable) getResources()
			.getDrawable(R.drawable.shape_transition);

	transition.setCrossFadeEnabled(true);

	((ImageView) findViewById(R.id.image_view)).setImageDrawable(transition);
	
	transition.startTransition(5000);
}
 
Example 19
Source File: TransitionDrawableActivity.java    From coursera-android with MIT License 3 votes vote down vote up
@Override
public void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);

	setContentView(R.layout.main);
	
	TransitionDrawable transition = (TransitionDrawable) getResources()
			.getDrawable(R.drawable.shape_transition,null);

	transition.setCrossFadeEnabled(true);

	((ImageView) findViewById(R.id.image_view)).setImageDrawable(transition);
	
	transition.startTransition(5000);
}