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

The following examples show how to use android.graphics.drawable.TransitionDrawable#startTransition() . 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: FadeInNetworkImageView.java    From QuickLyric with GNU General Public License v3.0 6 votes vote down vote up
@SuppressWarnings("deprecation")
@Override
public void setImageBitmap(Bitmap bm) {
    Context context = getContext();
    if (context != null) {
        if (bm == null) {
            if (defaultShown && defaultImageCounter > 0)
                defaultImageCounter--;
            bm = ((BitmapDrawable) getResources().getDrawable(this.defaultImageResources[defaultImageCounter++ % defaultImageResources.length])).getBitmap();
            defaultShown = true;
        } else
            defaultShown = false;
        Resources resources = context.getResources();
        TransitionDrawable td = new TransitionDrawable(new Drawable[]{
                new ColorDrawable(resources.getColor(android.R.color.transparent)),
                new BitmapDrawable(context.getResources(), bm)
        });
        setImageDrawable(td);
        td.startTransition(FADE_IN_TIME_MS);
    }
}
 
Example 2
Source File: HomeSearch.java    From toktok-android with GNU General Public License v3.0 6 votes vote down vote up
@Override
protected void onFinishInflate() {
    mBackground = (TransitionDrawable) getBackground();
    mBackground.startTransition(500);

    mBase = this.findViewById(R.id.home_search_layout);
    mCardView = this.findViewById(R.id.home_search_bar);
    NestedScrollView mRecycler = this.findViewById(R.id.home_search_bar_recycler);

    Animation searchBarAnimation = AnimationUtils.loadAnimation(mCardView.getContext(), R.anim.abc_fade_in);
    mCardView.startAnimation(searchBarAnimation);

    mInput = this.findViewById(R.id.home_search_input);

    super.onFinishInflate();
}
 
Example 3
Source File: Timber2.java    From Muzesto with GNU General Public License v3.0 6 votes vote down vote up
@Override
protected void onPostExecute(Drawable result) {
    if (result != null) {
        if (mBlurredArt.getDrawable() != null) {
            final TransitionDrawable td =
                    new TransitionDrawable(new Drawable[]{
                            mBlurredArt.getDrawable(),
                            result
                    });
            mBlurredArt.setImageDrawable(td);
            td.startTransition(200);

        } else {
            mBlurredArt.setImageDrawable(result);
        }
    }
}
 
Example 4
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 5
Source File: DocumentsActivity.java    From FireFiles with Apache License 2.0 6 votes vote down vote up
private void changeActionBarColor() {

		int color = SettingsActivity.getPrimaryColor(this);
		Drawable colorDrawable = new ColorDrawable(color);

		if (oldBackground == null) {
            getSupportActionBar().setBackgroundDrawable(colorDrawable);
		} else {
			TransitionDrawable td = new TransitionDrawable(new Drawable[] { oldBackground, colorDrawable });
            getSupportActionBar().setBackgroundDrawable(td);
			td.startTransition(200);
		}

		oldBackground = colorDrawable;

        setUpStatusBar();
	}
 
Example 6
Source File: ImageLoader.java    From Yahala-Messenger with MIT License 6 votes vote down vote up
/**
 * Called when the processing is complete and the final bitmap should be set on the ImageView.
 *
 * @param imageView The ImageView to set the bitmap to.
 * @param bitmap    The new bitmap to set.
 */
private void setImageBitmap(CircleImageView imageView, Bitmap bitmap) {
    if (mFadeInBitmap) {
        // Transition drawable to fade from loading bitmap to final bitmap
        final TransitionDrawable td =
                new TransitionDrawable(new Drawable[]{
                        new ColorDrawable(android.R.color.transparent),
                        new BitmapDrawable(mResources, bitmap)
                });
        //imageView.setBackgroundDrawable(imageView.getDrawable());
        imageView.setImageDrawable(td);
        td.startTransition(FADE_IN_TIME);
    } else {
        imageView.setImageBitmap(bitmap);
    }
}
 
Example 7
Source File: ImageWorker.java    From bither-bitmap-sample with Apache License 2.0 6 votes vote down vote up
/**
 * 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) {
    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(mResources, bitmap)});
        // Set background to loading bitmap
        imageView.setBackgroundDrawable(new BitmapDrawable(mResources,
                mLoadingBitmap));

        imageView.setImageDrawable(td);
        td.startTransition(FADE_IN_TIME);
    } else {
        imageView.setImageBitmap(bitmap);
    }
}
 
Example 8
Source File: MainActivity.java    From android-art-res with Apache License 2.0 6 votes vote down vote up
@Override
public void onWindowFocusChanged(boolean hasFocus) {
    super.onWindowFocusChanged(hasFocus);
    if (hasFocus) {
        // test transition
        View v = findViewById(R.id.test_transition);
        TransitionDrawable drawable = (TransitionDrawable) v.getBackground();
        drawable.startTransition(1000);

        // test scale
        View testScale = findViewById(R.id.test_scale);
        ScaleDrawable testScaleDrawable = (ScaleDrawable) testScale.getBackground();
        testScaleDrawable.setLevel(10);

        // test clip
        ImageView testClip = (ImageView) findViewById(R.id.test_clip);
        ClipDrawable testClipDrawable = (ClipDrawable) testClip.getDrawable();
        testClipDrawable.setLevel(8000);
        
        // test custom drawable
        View testCustomDrawable = findViewById(R.id.test_custom_drawable);
        CustomDrawable customDrawable = new CustomDrawable(Color.parseColor("#0ac39e"));
        testCustomDrawable.setBackgroundDrawable(customDrawable);
    }
}
 
Example 9
Source File: ImageWorker.java    From vocefiscal-android with Apache License 2.0 6 votes vote down vote up
/**
 * 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.setImageDrawable(td);
        td.startTransition(FADE_IN_TIME);
    } else {
        imageView.setImageDrawable(drawable);
    }
}
 
Example 10
Source File: PagerSlidingTabStripActivity.java    From UltimateAndroid with Apache License 2.0 6 votes vote down vote up
private void changeColor(int newColor) {

        tabs.setBackgroundColor(newColor);
        mTintManager.setTintColor(newColor);
        // change ActionBar color just if an ActionBar is available

        Drawable colorDrawable = new ColorDrawable(newColor);
        Drawable bottomDrawable = new ColorDrawable(getResources().getColor(android.R.color.transparent));
        LayerDrawable ld = new LayerDrawable(new Drawable[]{colorDrawable, bottomDrawable});

        if (oldBackground == null) {
            getSupportActionBar().setBackgroundDrawable(ld);
        } else {
            TransitionDrawable td = new TransitionDrawable(new Drawable[]{oldBackground, ld});
            getSupportActionBar().setBackgroundDrawable(td);
            td.startTransition(200);
        }

        oldBackground = ld;
        currentColor = newColor;

    }
 
Example 11
Source File: ToolbarPhone.java    From delion with Apache License 2.0 5 votes vote down vote up
@Override
public void onUrlFocusChange(final boolean hasFocus) {
    super.onUrlFocusChange(hasFocus);

    triggerUrlFocusAnimation(hasFocus);

    TransitionDrawable shadowDrawable = (TransitionDrawable) mToolbarShadow.getDrawable();
    if (hasFocus) {
        dismissTabSwitcherCallout();
        shadowDrawable.startTransition(URL_FOCUS_CHANGE_ANIMATION_DURATION_MS);
    } else {
        shadowDrawable.reverseTransition(URL_FOCUS_CHANGE_ANIMATION_DURATION_MS);
    }
}
 
Example 12
Source File: MainActivity.java    From Color-O-Matic with GNU General Public License v3.0 5 votes vote down vote up
void updateToolbar(int oldColor, int newColor) {
    final TransitionDrawable transition = new TransitionDrawable(new ColorDrawable[]{
            new ColorDrawable(oldColor), new ColorDrawable(newColor)
    });

    if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        toolbar.setBackground(transition);
    } else {
        toolbar.setBackgroundDrawable(transition);
    }

    transition.startTransition(300);
}
 
Example 13
Source File: MusicUtils.java    From Rey-MusicPlayer with Apache License 2.0 5 votes vote down vote up
public static void animate(final ImageView imageView, Drawable drawable1, Drawable drawable2) {
    Drawable[] layers = new Drawable[2];
    layers[0] = drawable1;
    layers[1] = drawable2;

    TransitionDrawable transitionDrawable = new TransitionDrawable(layers);
    imageView.setImageDrawable(transitionDrawable);
    transitionDrawable.startTransition(5000);
}
 
Example 14
Source File: BottomBar.java    From Camera2 with Apache License 2.0 5 votes vote down vote up
/**
 * Animates bar to full width / length with video capture icon
 */
public void animateToFullSize(int resId)
{
    if (mDrawCircle && mAnimatedCircleDrawable != null)
    {
        mAnimatedCircleDrawable.animateToFullSize();
        mDrawCircle = false;
    }

    TransitionDrawable transitionDrawable = crossfadeDrawable(
            mShutterButton.getDrawable(),
            getResources().getDrawable(resId));
    mShutterButton.setImageDrawable(transitionDrawable);
    transitionDrawable.startTransition(CIRCLE_ANIM_DURATION_MS);
}
 
Example 15
Source File: ToolbarPhone.java    From delion with Apache License 2.0 5 votes vote down vote up
@Override
protected void handleFindToolbarStateChange(boolean showing) {
    setVisibility(showing ? View.GONE : View.VISIBLE);
    TransitionDrawable shadowDrawable = (TransitionDrawable) mToolbarShadow.getDrawable();
    if (showing) {
        shadowDrawable.startTransition(URL_FOCUS_CHANGE_ANIMATION_DURATION_MS);
    } else {
        shadowDrawable.reverseTransition(URL_FOCUS_CHANGE_ANIMATION_DURATION_MS);
    }
}
 
Example 16
Source File: ImageWorker.java    From android-tv-launcher with MIT License 5 votes vote down vote up
/**
 * 将图片设置到ImageView中.
 */
private void setImageBitmap(ImageView imageView, Bitmap bitmap)
{
    //当图片加载好的时候,设置一个跳转样式,从一个<透明图片>跳至<加载好的图片>,用时<FADE_IN_TIME><200ms>
    final Drawable[] layers = new Drawable[] {
            new ColorDrawable(android.R.color.transparent),
            new BitmapDrawable(mContext.getResources(), bitmap) };

    final TransitionDrawable transDrawable = new TransitionDrawable(layers);

    imageView.setImageDrawable(transDrawable);
    //开始展示.
    transDrawable.startTransition(FADE_IN_TIME);
}
 
Example 17
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 18
Source File: LoadImageView.java    From EhViewer with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onGetValue(@NonNull ImageBitmap value, int source) {
    Drawable drawable;
    try {
        drawable = new ImageDrawable(value);
    } catch (RecycledException e) {
        // The image might be recycled because it is removed from memory cache.
        Log.d(TAG, "The image is recycled", e);
        return false;
    }

    clearDrawable();

    if (Integer.MIN_VALUE != mOffsetX) {
        drawable = new PreciselyClipDrawable(drawable, mOffsetX, mOffsetY, mClipWidth, mClipHeight);
    }

    onPreSetImageDrawable(drawable, true);
    if ((source == Conaco.SOURCE_DISK || source == Conaco.SOURCE_NETWORK) && isShown()) {
        Drawable[] layers = new Drawable[2];
        layers[0] = new ColorDrawable(Color.TRANSPARENT);
        layers[1] = drawable;
        TransitionDrawable transitionDrawable = new TransitionDrawable(layers);
        setImageDrawable(transitionDrawable);
        transitionDrawable.startTransition(300);
    } else {
        setImageDrawable(drawable);
    }

    return true;
}
 
Example 19
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 20
Source File: DefaultImageLoadHandler.java    From cube-sdk with Apache License 2.0 4 votes vote down vote up
@Override
public void onLoadFinish(ImageTask imageTask, CubeImageView imageView, BitmapDrawable drawable) {

    if (imageView == null) {
        return;
    }

    Drawable d = drawable;
    if (drawable != null) {

        if (mResizeImageViewAfterLoad) {
            int w = drawable.getBitmap().getWidth();
            int h = drawable.getBitmap().getHeight();

            if (w > 0 && h > 0) {

                ViewGroup.LayoutParams lyp = imageView.getLayoutParams();
                if (lyp != null) {
                    lyp.width = w;
                    lyp.height = h;
                    imageView.setLayoutParams(lyp);
                }
            }
        }

        // RoundedDrawable will not recycle automatically when API level is lower than 11
        if ((mDisplayTag & DISPLAY_ROUNDED) == DISPLAY_ROUNDED && Version.hasHoneycomb()) {
            d = new RoundedDrawable(drawable.getBitmap(), mCornerRadius);
        }
        if ((mDisplayTag & DISPLAY_FADE_IN) == DISPLAY_FADE_IN) {
            int loadingColor = android.R.color.transparent;
            if (mLoadingColor != -1 && (mDisplayTag & DISPLAY_ROUNDED) != DISPLAY_ROUNDED) {
                loadingColor = mLoadingColor;
            }
            final TransitionDrawable td = new TransitionDrawable(new Drawable[]{new ColorDrawable(loadingColor), d});
            imageView.setImageDrawable(td);
            td.startTransition(200);
        } else {

            if (DEBUG) {
                Drawable oldDrawable = imageView.getDrawable();
                int w = 0, h = 0;
                if (oldDrawable != null) {
                    w = oldDrawable.getIntrinsicWidth();
                    h = oldDrawable.getIntrinsicHeight();
                }
                CLog.d(LOG_TAG, MSG_LOAD_FINISH,
                        imageTask, imageView, w, h, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight());
            }
            imageView.setImageDrawable(drawable);
        }
    }
}