Search in sources :

Example 91 with RippleDrawable

use of android.graphics.drawable.RippleDrawable in project Slide by ccrama.

the class Peek method forceRippleAnimation.

private void forceRippleAnimation(View view, MotionEvent event) {
    Drawable background = view.getBackground();
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && background instanceof RippleDrawable) {
        final RippleDrawable rippleDrawable = (RippleDrawable) background;
        rippleDrawable.setState(new int[] { android.R.attr.state_pressed, android.R.attr.state_enabled });
        rippleDrawable.setHotspot(event.getX(), event.getY());
        new Handler().postDelayed(new Runnable() {

            @Override
            public void run() {
                rippleDrawable.setState(new int[] {});
            }
        }, 300);
    }
}
Also used : Drawable(android.graphics.drawable.Drawable) RippleDrawable(android.graphics.drawable.RippleDrawable) Handler(android.os.Handler) RippleDrawable(android.graphics.drawable.RippleDrawable)

Example 92 with RippleDrawable

use of android.graphics.drawable.RippleDrawable in project android_packages_apps_Dialer by LineageOS.

the class Bubble method update.

private void update() {
    RippleDrawable backgroundRipple = (RippleDrawable) context.getResources().getDrawable(R.drawable.bubble_ripple_circle, context.getTheme());
    int primaryTint = ColorUtils.compositeColors(context.getColor(R.color.bubble_primary_background_darken), currentInfo.getPrimaryColor());
    backgroundRipple.getDrawable(0).setTint(primaryTint);
    viewHolder.getPrimaryButton().setBackground(backgroundRipple);
    setBackgroundDrawable(viewHolder.getFirstButton(), primaryTint);
    setBackgroundDrawable(viewHolder.getSecondButton(), primaryTint);
    setBackgroundDrawable(viewHolder.getThirdButton(), primaryTint);
    int numButtons = currentInfo.getActions().size();
    viewHolder.getThirdButton().setVisibility(numButtons < 3 ? View.GONE : View.VISIBLE);
    viewHolder.getSecondButton().setVisibility(numButtons < 2 ? View.GONE : View.VISIBLE);
    viewHolder.getPrimaryIcon().setImageIcon(currentInfo.getPrimaryIcon());
    updatePrimaryIconAnimation();
    viewHolder.getExpandedView().setBackgroundTintList(ColorStateList.valueOf(currentInfo.getPrimaryColor()));
    updateButtonStates();
}
Also used : SuppressLint(android.annotation.SuppressLint) RippleDrawable(android.graphics.drawable.RippleDrawable)

Example 93 with RippleDrawable

use of android.graphics.drawable.RippleDrawable in project android_packages_apps_Dialer by MoKee.

the class CallButtonFragment method compoundBackgroundDrawable.

/**
 * Generate a RippleDrawable which will be the background for a compound button, i.e.
 * a button with pressed and unpressed states. The unpressed state will be the same color
 * as the rest of the call card, the pressed state will be the dark version of that color.
 */
private RippleDrawable compoundBackgroundDrawable(MaterialPalette palette) {
    Resources res = getResources();
    ColorStateList rippleColor = ColorStateList.valueOf(res.getColor(R.color.incall_accent_color));
    StateListDrawable stateListDrawable = new StateListDrawable();
    addSelectedAndFocused(res, stateListDrawable);
    addFocused(res, stateListDrawable);
    addSelected(res, stateListDrawable, palette);
    addUnselected(res, stateListDrawable, palette);
    return new RippleDrawable(rippleColor, stateListDrawable, null);
}
Also used : ColorStateList(android.content.res.ColorStateList) Resources(android.content.res.Resources) StateListDrawable(android.graphics.drawable.StateListDrawable) RippleDrawable(android.graphics.drawable.RippleDrawable)

Example 94 with RippleDrawable

use of android.graphics.drawable.RippleDrawable in project android_packages_apps_Dialer by MoKee.

the class CallButtonFragment method updateColors.

public void updateColors() {
    MaterialPalette themeColors = InCallPresenter.getInstance().getThemeColors();
    if (mCurrentThemeColors != null && mCurrentThemeColors.equals(themeColors)) {
        return;
    }
    CompoundButton[] compoundButtons = { mAudioButton, mMuteButton, mShowDialpadButton, mHoldButton, mSwitchCameraButton, mPauseVideoButton, mCallRecordButton };
    for (CompoundButton button : compoundButtons) {
        // Before applying background color, uncheck the button and re apply the
        // saved checked state after background is changed. This is to fix
        // an issue where button checked state is displayed wrongly after updating colors.
        boolean isChecked = button.isChecked();
        if (isChecked)
            Log.d(this, "updateColors: button:" + button + " is in checked state");
        button.setChecked(false);
        final LayerDrawable layers = (LayerDrawable) button.getBackground();
        final RippleDrawable btnCompoundDrawable = compoundBackgroundDrawable(themeColors);
        layers.setDrawableByLayerId(R.id.compoundBackgroundItem, btnCompoundDrawable);
        button.setChecked(isChecked);
        button.requestLayout();
    }
    ImageButton[] normalButtons = { mSwapButton, mChangeToVideoButton, mChangeToVoiceButton, mAddCallButton, mMergeButton, mBlindTransferButton, mAssuredTransferButton, mConsultativeTransferButton, mOverflowButton };
    for (ImageButton button : normalButtons) {
        final LayerDrawable layers = (LayerDrawable) button.getBackground();
        final RippleDrawable btnDrawable = backgroundDrawable(themeColors);
        layers.setDrawableByLayerId(R.id.backgroundItem, btnDrawable);
        button.requestLayout();
    }
    mCurrentThemeColors = themeColors;
}
Also used : ImageButton(android.widget.ImageButton) LayerDrawable(android.graphics.drawable.LayerDrawable) CompoundButton(android.widget.CompoundButton) MaterialPalette(com.android.contacts.common.util.MaterialColorMapUtils.MaterialPalette) RippleDrawable(android.graphics.drawable.RippleDrawable)

Example 95 with RippleDrawable

use of android.graphics.drawable.RippleDrawable in project incubator-weex by apache.

the class WXComponent method prepareBackgroundRipple.

private Drawable prepareBackgroundRipple() {
    try {
        if (getStyles() != null && getStyles().getPesudoResetStyles() != null) {
            Map<String, Object> resetStyles = getStyles().getPesudoResetStyles();
            Object bgColor = resetStyles.get(Constants.Name.BACKGROUND_COLOR);
            int colorInt = Color.TRANSPARENT;
            if (bgColor != null) {
                colorInt = WXResourceUtils.getColor(bgColor.toString(), Color.TRANSPARENT);
                if (colorInt == Color.TRANSPARENT) {
                    return null;
                }
            }
            Object bg = resetStyles.get(Constants.Name.BACKGROUND_COLOR + Constants.PSEUDO.ACTIVE);
            if (bg == null) {
                return null;
            }
            int rippleColor = WXResourceUtils.getColor(bg.toString(), colorInt);
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                ColorStateList colorStateList = new ColorStateList(new int[][] { new int[] {} }, new int[] { rippleColor });
                return new RippleDrawable(colorStateList, new ColorDrawable(colorInt), null) {

                    @Override
                    @SuppressLint("CanvasSize")
                    public void draw(@NonNull Canvas canvas) {
                        if (mBackgroundDrawable != null) {
                            Path border = mBackgroundDrawable.getContentPath(new RectF(0, 0, canvas.getWidth(), canvas.getHeight()));
                            canvas.clipPath(border);
                        }
                        super.draw(canvas);
                    }
                };
            }
        }
    } catch (Throwable t) {
        WXLogUtils.w("Exception on create ripple: ", t);
    }
    return null;
}
Also used : Path(android.graphics.Path) RectF(android.graphics.RectF) ColorDrawable(android.graphics.drawable.ColorDrawable) NonNull(android.support.annotation.NonNull) Canvas(android.graphics.Canvas) ColorStateList(android.content.res.ColorStateList) IWXObject(org.apache.weex.common.IWXObject) SuppressLint(android.annotation.SuppressLint) Point(android.graphics.Point) RippleDrawable(android.graphics.drawable.RippleDrawable)

Aggregations

RippleDrawable (android.graphics.drawable.RippleDrawable)115 StateListDrawable (android.graphics.drawable.StateListDrawable)60 Drawable (android.graphics.drawable.Drawable)49 ColorStateList (android.content.res.ColorStateList)47 GradientDrawable (android.graphics.drawable.GradientDrawable)30 TargetApi (android.annotation.TargetApi)26 ShapeDrawable (android.graphics.drawable.ShapeDrawable)23 View (android.view.View)21 Paint (android.graphics.Paint)20 ColorDrawable (android.graphics.drawable.ColorDrawable)20 SuppressLint (android.annotation.SuppressLint)15 TextView (android.widget.TextView)15 FrameLayout (android.widget.FrameLayout)12 LayerDrawable (android.graphics.drawable.LayerDrawable)11 ImageView (android.widget.ImageView)11 RLottieDrawable (org.telegram.ui.Components.RLottieDrawable)11 CombinedDrawable (org.telegram.ui.Components.CombinedDrawable)10 ScamDrawable (org.telegram.ui.Components.ScamDrawable)10 Outline (android.graphics.Outline)9 BitmapDrawable (android.graphics.drawable.BitmapDrawable)9