Search in sources :

Example 6 with AnimatedVectorDrawable

use of android.graphics.drawable.AnimatedVectorDrawable in project plaid by nickbutcher.

the class PlayerSheet method showDown.

private void showDown() {
    if (dismissState == DISMISS_DOWN)
        return;
    dismissState = DISMISS_DOWN;
    final AnimatedVectorDrawable closeToDown = (AnimatedVectorDrawable) ContextCompat.getDrawable(this, R.drawable.avd_close_to_down);
    close.setImageDrawable(closeToDown);
    closeToDown.start();
}
Also used : AnimatedVectorDrawable(android.graphics.drawable.AnimatedVectorDrawable)

Example 7 with AnimatedVectorDrawable

use of android.graphics.drawable.AnimatedVectorDrawable in project muzei by romannurik.

the class MuzeiActivity method updateUiMode.

private void updateUiMode() {
    // TODO: this should really just use fragment transactions and transitions
    int newUiMode = UI_MODE_INTRO;
    if (mWallpaperActive) {
        newUiMode = UI_MODE_TUTORIAL;
        if (mSeenTutorial) {
            newUiMode = UI_MODE_ART_DETAIL;
        }
    }
    if (mUiMode == newUiMode) {
        return;
    }
    // Crossfade between main containers
    final View oldContainerView = getMainContainerForUiMode(mUiMode);
    final View newContainerView = getMainContainerForUiMode(newUiMode);
    if (oldContainerView != null) {
        oldContainerView.animate().alpha(0).setDuration(1000).withEndAction(new Runnable() {

            @Override
            public void run() {
                oldContainerView.setVisibility(View.GONE);
            }
        });
    }
    if (newContainerView != null) {
        if (newContainerView.getAlpha() == 1) {
            newContainerView.setAlpha(0);
        }
        newContainerView.setVisibility(View.VISIBLE);
        newContainerView.animate().alpha(1).setDuration(1000).withEndAction(null);
    }
    // Special work
    if (newUiMode == UI_MODE_INTRO) {
        FirebaseAnalytics.getInstance(this).logEvent(FirebaseAnalytics.Event.TUTORIAL_BEGIN, null);
        final View activateButton = findViewById(R.id.activate_muzei_button);
        activateButton.setAlpha(0);
        final AnimatedMuzeiLogoFragment logoFragment = (AnimatedMuzeiLogoFragment) getFragmentManager().findFragmentById(R.id.animated_logo_fragment);
        logoFragment.reset();
        logoFragment.setOnFillStartedCallback(new Runnable() {

            @Override
            public void run() {
                activateButton.animate().alpha(1f).setDuration(500);
            }
        });
        mHandler.postDelayed(new Runnable() {

            @Override
            public void run() {
                logoFragment.start();
            }
        }, 1000);
    }
    if (mUiMode == UI_MODE_INTRO || newUiMode == UI_MODE_INTRO) {
        FragmentManager fm = getSupportFragmentManager();
        Fragment demoFragment = fm.findFragmentById(R.id.demo_view_container);
        if (newUiMode == UI_MODE_INTRO && demoFragment == null) {
            fm.beginTransaction().add(R.id.demo_view_container, MuzeiRendererFragment.createInstance(true, true)).commit();
        } else if (newUiMode != UI_MODE_INTRO && demoFragment != null) {
            fm.beginTransaction().remove(demoFragment).commit();
        }
    }
    if (newUiMode == UI_MODE_TUTORIAL) {
        float animateDistance = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 100, getResources().getDisplayMetrics());
        View mainTextView = findViewById(R.id.tutorial_main_text);
        mainTextView.setAlpha(0);
        mainTextView.setTranslationY(-animateDistance / 5);
        View subTextView = findViewById(R.id.tutorial_sub_text);
        subTextView.setAlpha(0);
        subTextView.setTranslationY(-animateDistance / 5);
        final View affordanceView = findViewById(R.id.tutorial_icon_affordance);
        affordanceView.setAlpha(0);
        affordanceView.setTranslationY(animateDistance);
        View iconTextView = findViewById(R.id.tutorial_icon_text);
        iconTextView.setAlpha(0);
        iconTextView.setTranslationY(animateDistance);
        AnimatorSet set = new AnimatorSet();
        set.setStartDelay(500);
        set.setDuration(250);
        set.playTogether(ObjectAnimator.ofFloat(mainTextView, View.ALPHA, 1f), ObjectAnimator.ofFloat(subTextView, View.ALPHA, 1f));
        set.start();
        set = new AnimatorSet();
        set.setStartDelay(2000);
        // Bug in older versions where set.setInterpolator didn't work
        Interpolator interpolator = new OvershootInterpolator();
        ObjectAnimator a1 = ObjectAnimator.ofFloat(affordanceView, View.TRANSLATION_Y, 0);
        ObjectAnimator a2 = ObjectAnimator.ofFloat(iconTextView, View.TRANSLATION_Y, 0);
        ObjectAnimator a3 = ObjectAnimator.ofFloat(mainTextView, View.TRANSLATION_Y, 0);
        ObjectAnimator a4 = ObjectAnimator.ofFloat(subTextView, View.TRANSLATION_Y, 0);
        a1.setInterpolator(interpolator);
        a2.setInterpolator(interpolator);
        a3.setInterpolator(interpolator);
        a4.setInterpolator(interpolator);
        set.setDuration(500).playTogether(ObjectAnimator.ofFloat(affordanceView, View.ALPHA, 1f), ObjectAnimator.ofFloat(iconTextView, View.ALPHA, 1f), a1, a2, a3, a4);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            set.addListener(new AnimatorListenerAdapter() {

                @Override
                public void onAnimationEnd(Animator animation) {
                    ImageView emanateView = (ImageView) findViewById(R.id.tutorial_icon_emanate);
                    AnimatedVectorDrawable avd = (AnimatedVectorDrawable) getResources().getDrawable(R.drawable.avd_tutorial_icon_emanate, getTheme());
                    emanateView.setImageDrawable(avd);
                    avd.start();
                }
            });
        }
        set.start();
    }
    if (newUiMode == UI_MODE_ART_DETAIL) {
        FirebaseAnalytics.getInstance(this).logEvent(FirebaseAnalytics.Event.TUTORIAL_COMPLETE, null);
    }
    mPanScaleProxyView.setVisibility(newUiMode == UI_MODE_ART_DETAIL ? View.VISIBLE : View.GONE);
    mUiMode = newUiMode;
    maybeUpdateArtDetailOpenedClosed();
}
Also used : OvershootInterpolator(android.view.animation.OvershootInterpolator) ObjectAnimator(android.animation.ObjectAnimator) AnimatorSet(android.animation.AnimatorSet) ImageView(android.widget.ImageView) View(android.view.View) AnimatedMuzeiLoadingSpinnerView(com.google.android.apps.muzei.util.AnimatedMuzeiLoadingSpinnerView) TextView(android.widget.TextView) PanScaleProxyView(com.google.android.apps.muzei.util.PanScaleProxyView) AnimatedMuzeiLogoFragment(com.google.android.apps.muzei.util.AnimatedMuzeiLogoFragment) Fragment(android.support.v4.app.Fragment) AnimatedMuzeiLogoFragment(com.google.android.apps.muzei.util.AnimatedMuzeiLogoFragment) MuzeiRendererFragment(com.google.android.apps.muzei.render.MuzeiRendererFragment) AnimatedVectorDrawable(android.graphics.drawable.AnimatedVectorDrawable) FragmentManager(android.support.v4.app.FragmentManager) Animator(android.animation.Animator) ObjectAnimator(android.animation.ObjectAnimator) AnimatorListenerAdapter(android.animation.AnimatorListenerAdapter) Interpolator(android.view.animation.Interpolator) OvershootInterpolator(android.view.animation.OvershootInterpolator) ImageView(android.widget.ImageView)

Example 8 with AnimatedVectorDrawable

use of android.graphics.drawable.AnimatedVectorDrawable in project platform_frameworks_base by android.

the class LockIcon method update.

public void update(boolean force) {
    boolean visible = isShown() && KeyguardUpdateMonitor.getInstance(mContext).isDeviceInteractive();
    if (visible) {
        mTrustDrawable.start();
    } else {
        mTrustDrawable.stop();
    }
    // TODO: Real icon for facelock.
    int state = getState();
    boolean anyFingerprintIcon = state == STATE_FINGERPRINT || state == STATE_FINGERPRINT_ERROR;
    boolean useAdditionalPadding = anyFingerprintIcon;
    boolean trustHidden = anyFingerprintIcon;
    if (state != mLastState || mDeviceInteractive != mLastDeviceInteractive || mScreenOn != mLastScreenOn || force) {
        boolean isAnim = true;
        int iconRes = getAnimationResForTransition(mLastState, state, mLastDeviceInteractive, mDeviceInteractive, mLastScreenOn, mScreenOn);
        if (iconRes == R.drawable.lockscreen_fingerprint_draw_off_animation) {
            anyFingerprintIcon = true;
            useAdditionalPadding = true;
            trustHidden = true;
        } else if (iconRes == R.drawable.trusted_state_to_error_animation) {
            anyFingerprintIcon = true;
            useAdditionalPadding = false;
            trustHidden = true;
        } else if (iconRes == R.drawable.error_to_trustedstate_animation) {
            anyFingerprintIcon = true;
            useAdditionalPadding = false;
            trustHidden = false;
        }
        if (iconRes == -1) {
            iconRes = getIconForState(state, mScreenOn, mDeviceInteractive);
            isAnim = false;
        }
        Drawable icon = mContext.getDrawable(iconRes);
        final AnimatedVectorDrawable animation = icon instanceof AnimatedVectorDrawable ? (AnimatedVectorDrawable) icon : null;
        int iconHeight = getResources().getDimensionPixelSize(R.dimen.keyguard_affordance_icon_height);
        int iconWidth = getResources().getDimensionPixelSize(R.dimen.keyguard_affordance_icon_width);
        if (!anyFingerprintIcon && (icon.getIntrinsicHeight() != iconHeight || icon.getIntrinsicWidth() != iconWidth)) {
            icon = new IntrinsicSizeDrawable(icon, iconWidth, iconHeight);
        }
        setPaddingRelative(0, 0, 0, useAdditionalPadding ? getResources().getDimensionPixelSize(R.dimen.fingerprint_icon_additional_padding) : 0);
        setRestingAlpha(anyFingerprintIcon ? 1f : KeyguardAffordanceHelper.SWIPE_RESTING_ALPHA_AMOUNT);
        setImageDrawable(icon);
        String contentDescription = getResources().getString(anyFingerprintIcon ? R.string.accessibility_unlock_button_fingerprint : R.string.accessibility_unlock_button);
        setContentDescription(contentDescription);
        mHasFingerPrintIcon = anyFingerprintIcon;
        if (animation != null && isAnim) {
            animation.forceAnimationOnUI();
            animation.start();
        }
        mLastState = state;
        mLastDeviceInteractive = mDeviceInteractive;
        mLastScreenOn = mScreenOn;
    }
    // Hide trust circle when fingerprint is running.
    boolean trustManaged = mUnlockMethodCache.isTrustManaged() && !trustHidden;
    mTrustDrawable.setTrustManaged(trustManaged);
    updateClickability();
}
Also used : InsetDrawable(android.graphics.drawable.InsetDrawable) AnimatedVectorDrawable(android.graphics.drawable.AnimatedVectorDrawable) Drawable(android.graphics.drawable.Drawable) AnimatedVectorDrawable(android.graphics.drawable.AnimatedVectorDrawable)

Example 9 with AnimatedVectorDrawable

use of android.graphics.drawable.AnimatedVectorDrawable in project platform_frameworks_base by android.

the class ExpandableIndicator method setExpanded.

public void setExpanded(boolean expanded) {
    if (expanded == mExpanded)
        return;
    mExpanded = expanded;
    final int res = getDrawableResourceId(!mExpanded);
    // workaround to reset drawable
    final AnimatedVectorDrawable avd = (AnimatedVectorDrawable) getContext().getDrawable(res).getConstantState().newDrawable();
    setImageDrawable(avd);
    avd.forceAnimationOnUI();
    avd.start();
    setContentDescription(getContentDescription(expanded));
}
Also used : AnimatedVectorDrawable(android.graphics.drawable.AnimatedVectorDrawable)

Example 10 with AnimatedVectorDrawable

use of android.graphics.drawable.AnimatedVectorDrawable in project platform_frameworks_base by android.

the class AnimatedVectorDrawableDupPerf method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    ScrollView scrollView = new ScrollView(this);
    GridLayout container = new GridLayout(this);
    scrollView.addView(container);
    container.setColumnCount(5);
    Resources res = this.getResources();
    container.setBackgroundColor(0xFF888888);
    AnimatedVectorDrawable[] d = new AnimatedVectorDrawable[icon.length];
    long time = android.os.SystemClock.elapsedRealtimeNanos();
    for (int i = 0; i < icon.length; i++) {
        d[i] = create(res, icon[i]);
    }
    time = android.os.SystemClock.elapsedRealtimeNanos() - time;
    TextView t = new TextView(this);
    DecimalFormat df = new DecimalFormat("#.##");
    t.setText("avgL=" + df.format(time / (icon.length * 1000000.)) + " ms");
    container.addView(t);
    time = android.os.SystemClock.elapsedRealtimeNanos();
    for (int i = 0; i < icon.length; i++) {
        Button button = new Button(this);
        button.setWidth(200);
        button.setBackgroundResource(icon[i]);
        container.addView(button);
    }
    setContentView(scrollView);
    time = android.os.SystemClock.elapsedRealtimeNanos() - time;
    t = new TextView(this);
    t.setText("avgS=" + df.format(time / (icon.length * 1000000.)) + " ms");
    container.addView(t);
}
Also used : GridLayout(android.widget.GridLayout) ScrollView(android.widget.ScrollView) Button(android.widget.Button) DecimalFormat(java.text.DecimalFormat) TextView(android.widget.TextView) Resources(android.content.res.Resources) AnimatedVectorDrawable(android.graphics.drawable.AnimatedVectorDrawable)

Aggregations

AnimatedVectorDrawable (android.graphics.drawable.AnimatedVectorDrawable)56 Drawable (android.graphics.drawable.Drawable)18 TextView (android.widget.TextView)9 Resources (android.content.res.Resources)8 Button (android.widget.Button)8 GridLayout (android.widget.GridLayout)8 ScrollView (android.widget.ScrollView)8 SuppressLint (android.annotation.SuppressLint)5 ColorDrawable (android.graphics.drawable.ColorDrawable)5 InsetDrawable (android.graphics.drawable.InsetDrawable)5 ImageView (android.widget.ImageView)5 Paint (android.graphics.Paint)4 Animatable2 (android.graphics.drawable.Animatable2)4 BitmapDrawable (android.graphics.drawable.BitmapDrawable)4 LayerDrawable (android.graphics.drawable.LayerDrawable)4 AttributeSet (android.util.AttributeSet)4 IOException (java.io.IOException)4 DecimalFormat (java.text.DecimalFormat)4 XmlPullParser (org.xmlpull.v1.XmlPullParser)4 XmlPullParserException (org.xmlpull.v1.XmlPullParserException)4