Search in sources :

Example 21 with AnimatedVectorDrawable

use of android.graphics.drawable.AnimatedVectorDrawable in project android_frameworks_base by AOSPA.

the class LockIcon method update.

public void update(boolean force) {
    boolean visible = isShown() && KeyguardUpdateMonitor.getInstance(mContext).isDeviceInteractive();
    if (visible) {
        mTrustDrawable.start();
    } else {
        mTrustDrawable.stop();
    }
    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();
        }
        if (iconRes == R.drawable.lockscreen_fingerprint_draw_off_animation) {
            removeCallbacks(mDrawOffTimeout);
            postDelayed(mDrawOffTimeout, FP_DRAW_OFF_TIMEOUT);
        } else {
            removeCallbacks(mDrawOffTimeout);
        }
        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 22 with AnimatedVectorDrawable

use of android.graphics.drawable.AnimatedVectorDrawable in project android_frameworks_base by ResurrectionRemix.

the class VolumeDialog method updateExpandButtonH.

private void updateExpandButtonH() {
    if (D.BUG)
        Log.d(TAG, "updateExpandButtonH");
    mExpandButton.setClickable(!mExpandButtonAnimationRunning);
    if (!(mExpandButtonAnimationRunning && isAttached())) {
        final int res = mExpanded ? R.drawable.ic_volume_collapse_animation : R.drawable.ic_volume_expand_animation;
        if (hasTouchFeature()) {
            mExpandButton.setImageResource(res);
        } else {
            // if there is no touch feature, show the volume ringer instead
            mExpandButton.setImageResource(R.drawable.ic_volume_ringer);
            // remove gray background emphasis
            mExpandButton.setBackgroundResource(0);
        }
        mExpandButton.setContentDescription(mContext.getString(mExpanded ? R.string.accessibility_volume_collapse : R.string.accessibility_volume_expand));
    }
    if (mExpandButtonAnimationRunning) {
        final Drawable d = mExpandButton.getDrawable();
        if (d instanceof AnimatedVectorDrawable) {
            // workaround to reset drawable
            final AnimatedVectorDrawable avd = (AnimatedVectorDrawable) d.getConstantState().newDrawable();
            mExpandButton.setImageDrawable(avd);
            avd.start();
            mHandler.postDelayed(new Runnable() {

                @Override
                public void run() {
                    mExpandButtonAnimationRunning = false;
                    updateExpandButtonH();
                    rescheduleTimeoutH();
                }
            }, mExpandButtonAnimationDuration);
        }
    }
}
Also used : ColorDrawable(android.graphics.drawable.ColorDrawable) Drawable(android.graphics.drawable.Drawable) AnimatedVectorDrawable(android.graphics.drawable.AnimatedVectorDrawable) GradientDrawable(android.graphics.drawable.GradientDrawable) SuppressLint(android.annotation.SuppressLint) AnimatedVectorDrawable(android.graphics.drawable.AnimatedVectorDrawable)

Example 23 with AnimatedVectorDrawable

use of android.graphics.drawable.AnimatedVectorDrawable in project android_frameworks_base by ResurrectionRemix.

the class LockIcon method update.

public void update(boolean force) {
    boolean visible = isShown() && KeyguardUpdateMonitor.getInstance(mContext).isDeviceInteractive();
    if (visible) {
        mTrustDrawable.start();
    } else {
        mTrustDrawable.stop();
    }
    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();
        }
        if (iconRes == R.drawable.lockscreen_fingerprint_draw_off_animation) {
            removeCallbacks(mDrawOffTimeout);
            postDelayed(mDrawOffTimeout, FP_DRAW_OFF_TIMEOUT);
        } else {
            removeCallbacks(mDrawOffTimeout);
        }
        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 24 with AnimatedVectorDrawable

use of android.graphics.drawable.AnimatedVectorDrawable in project android_frameworks_base by ResurrectionRemix.

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 25 with AnimatedVectorDrawable

use of android.graphics.drawable.AnimatedVectorDrawable in project android_frameworks_base by ResurrectionRemix.

the class BatteryMeterDrawable method checkBatteryMeterDrawableValid.

private void checkBatteryMeterDrawableValid(Resources res, int style) {
    final int resId = getBatteryDrawableResourceForStyle(style);
    final Drawable batteryDrawable;
    try {
        batteryDrawable = res.getDrawable(resId, null);
    } catch (Resources.NotFoundException e) {
        throw new BatteryMeterDrawableException(res.getResourceName(resId) + " is an " + "invalid drawable", e);
    }
    // Check that the drawable is a LayerDrawable
    if (!(batteryDrawable instanceof LayerDrawable)) {
        throw new BatteryMeterDrawableException("Expected a LayerDrawable but received a " + batteryDrawable.getClass().getSimpleName());
    }
    final LayerDrawable layerDrawable = (LayerDrawable) batteryDrawable;
    final Drawable frame = layerDrawable.findDrawableByLayerId(R.id.battery_frame);
    final Drawable level = layerDrawable.findDrawableByLayerId(R.id.battery_fill);
    // Now, check that the required layers exist and are of the correct type
    if (frame == null) {
        throw new BatteryMeterDrawableException("Missing battery_frame drawble");
    }
    if (level != null) {
        // Check that the level drawable is an AnimatedVectorDrawable
        if (!(level instanceof AnimatedVectorDrawable)) {
            throw new BatteryMeterDrawableException("Expected a AnimatedVectorDrawable " + "but received a " + level.getClass().getSimpleName());
        }
        // Make sure we can stop-motion animate the level drawable
        try {
            StopMotionVectorDrawable smvd = new StopMotionVectorDrawable(level);
            smvd.setCurrentFraction(0.5f);
        } catch (Exception e) {
            throw new BatteryMeterDrawableException("Unable to perform stop motion on " + "battery_fill drawable", e);
        }
    } else {
        throw new BatteryMeterDrawableException("Missing battery_fill drawable");
    }
}
Also used : StopMotionVectorDrawable(org.cyanogenmod.graphics.drawable.StopMotionVectorDrawable) LayerDrawable(android.graphics.drawable.LayerDrawable) LayerDrawable(android.graphics.drawable.LayerDrawable) AnimatedVectorDrawable(android.graphics.drawable.AnimatedVectorDrawable) Drawable(android.graphics.drawable.Drawable) BitmapDrawable(android.graphics.drawable.BitmapDrawable) StopMotionVectorDrawable(org.cyanogenmod.graphics.drawable.StopMotionVectorDrawable) Resources(android.content.res.Resources) Paint(android.graphics.Paint) 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