Search in sources :

Example 41 with RippleDrawable

use of android.graphics.drawable.RippleDrawable in project NewPipe by TeamNewPipe.

the class PreferenceSearchResultHighlighter method doHighlight.

private static void doHighlight(final PreferenceSearchItem item, final PreferenceFragmentCompat prefsFragment) {
    final Preference prefResult = prefsFragment.findPreference(item.getKey());
    if (prefResult == null) {
        Log.w(TAG, "Preference '" + item.getKey() + "' not found on '" + prefsFragment + "'");
        return;
    }
    final RecyclerView recyclerView = prefsFragment.getListView();
    final RecyclerView.Adapter<?> adapter = recyclerView.getAdapter();
    if (adapter instanceof PreferenceGroup.PreferencePositionCallback) {
        final int position = ((PreferenceGroup.PreferencePositionCallback) adapter).getPreferenceAdapterPosition(prefResult);
        if (position != RecyclerView.NO_POSITION) {
            recyclerView.scrollToPosition(position);
            recyclerView.postDelayed(() -> {
                final RecyclerView.ViewHolder holder = recyclerView.findViewHolderForAdapterPosition(position);
                if (holder != null) {
                    final Drawable background = holder.itemView.getBackground();
                    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && background instanceof RippleDrawable) {
                        showRippleAnimation((RippleDrawable) background);
                        return;
                    }
                }
                highlightFallback(prefsFragment, prefResult);
            }, 200);
            return;
        }
    }
    highlightFallback(prefsFragment, prefResult);
}
Also used : Preference(androidx.preference.Preference) Drawable(android.graphics.drawable.Drawable) RippleDrawable(android.graphics.drawable.RippleDrawable) RecyclerView(androidx.recyclerview.widget.RecyclerView) RippleDrawable(android.graphics.drawable.RippleDrawable)

Example 42 with RippleDrawable

use of android.graphics.drawable.RippleDrawable in project MagicaSakura by Bilibili.

the class RippleDrawableInflateImpl method inflateDrawable.

@Override
public Drawable inflateDrawable(Context context, XmlPullParser parser, AttributeSet attrs) throws IOException, XmlPullParserException {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        final int innerDepth = parser.getDepth() + 1;
        int type;
        int depth;
        int markIndex = -1;
        int layerAttrUseCount = 0;
        int drawableUseCount = 0;
        int space = STEP;
        // L,T,R,B,S,E,id
        int[][] childLayersAttrs = new int[space][ATTRS.length];
        Drawable[] drawables = new Drawable[space];
        ColorStateList csl = DrawableUtils.getTintColorList(context, attrs, android.R.attr.color);
        if (csl == null) {
            return null;
        }
        while ((type = parser.next()) != XmlPullParser.END_DOCUMENT && ((depth = parser.getDepth()) >= innerDepth || type != XmlPullParser.END_TAG)) {
            if (type != XmlPullParser.START_TAG) {
                continue;
            }
            if (depth > innerDepth || !parser.getName().equals("item")) {
                continue;
            }
            if (layerAttrUseCount >= childLayersAttrs.length) {
                int[][] dstInt = new int[drawables.length + STEP][ATTRS.length];
                System.arraycopy(childLayersAttrs, 0, dstInt, 0, childLayersAttrs.length);
                childLayersAttrs = dstInt;
            }
            updateLayerAttrs(context, attrs, childLayersAttrs[layerAttrUseCount]);
            layerAttrUseCount++;
            Drawable drawable = DrawableUtils.getAttrDrawable(context, attrs, android.R.attr.drawable);
            if (DrawableUtils.getAttrResourceId(context, attrs, android.R.attr.id, 0) == android.R.id.mask) {
                markIndex = layerAttrUseCount - 1;
            }
            // element.
            if (drawable == null) {
                while ((type = parser.next()) == XmlPullParser.TEXT) {
                }
                if (type != XmlPullParser.START_TAG) {
                    throw new XmlPullParserException(parser.getPositionDescription() + ": <item> tag requires a 'drawable' attribute or " + "child tag defining a drawable");
                }
                drawable = DrawableUtils.createFromXmlInner(context, parser, attrs);
            } else {
                final ColorStateList cls = DrawableUtils.getTintColorList(context, attrs, R.attr.drawableTint);
                if (cls != null) {
                    drawable = ThemeUtils.tintDrawable(drawable, cls, DrawableUtils.getTintMode(context, attrs, R.attr.drawableTintMode));
                }
            }
            if (drawable != null) {
                if (drawableUseCount >= drawables.length) {
                    Drawable[] dst = new Drawable[drawables.length + STEP];
                    System.arraycopy(drawables, 0, dst, 0, drawables.length);
                    drawables = dst;
                }
                drawables[drawableUseCount] = drawable;
                drawableUseCount++;
            }
        }
        if (drawables[0] == null || drawableUseCount != layerAttrUseCount) {
            return null;
        } else {
            RippleDrawable rippleDrawable;
            rippleDrawable = new RippleDrawable(csl, null, markIndex >= 0 ? drawables[markIndex] : null);
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
                int radius = DrawableUtils.getAttrDimensionPixelSize(context, attrs, android.R.attr.radius, RippleDrawable.RADIUS_AUTO);
                rippleDrawable.setRadius(radius);
            }
            for (int i = 0; i < drawables.length; i++) {
                if (i == markIndex) {
                    continue;
                }
                addLayer(rippleDrawable, drawables[i]);
                int[] childLayersAttr = childLayersAttrs[i];
                if (childLayersAttr[0] != 0 || childLayersAttr[1] != 0 || childLayersAttr[2] != 0 || childLayersAttr[3] != 0) {
                    rippleDrawable.setLayerInset(i, childLayersAttr[0], childLayersAttr[1], childLayersAttr[2], childLayersAttr[3]);
                }
                if (childLayersAttr[4] != 0) {
                    rippleDrawable.setId(i, childLayersAttr[4]);
                }
            }
            return rippleDrawable;
        }
    }
    return null;
}
Also used : RippleDrawable(android.graphics.drawable.RippleDrawable) Drawable(android.graphics.drawable.Drawable) ColorStateList(android.content.res.ColorStateList) XmlPullParserException(org.xmlpull.v1.XmlPullParserException) RippleDrawable(android.graphics.drawable.RippleDrawable)

Example 43 with RippleDrawable

use of android.graphics.drawable.RippleDrawable in project PhoneProfiles by henrichg.

the class ColorChooserPreferenceFragmentX method onBindDialogView.

@Override
protected void onBindDialogView(View view) {
    super.onBindDialogView(view);
    int preselect = 0;
    for (int i = 0; i < preference.mColors.length; i++) {
        if (preference.mColors[i] == Integer.parseInt(preference.value)) {
            preselect = i;
            break;
        }
    }
    final GridLayout list = view.findViewById(R.id.dialog_color_chooser_grid);
    for (int i = 0; i < list.getChildCount(); i++) {
        FrameLayout child = (FrameLayout) list.getChildAt(i);
        child.setTag(i);
        child.setOnClickListener(this);
        child.getChildAt(0).setVisibility(preselect == i ? View.VISIBLE : View.GONE);
        Drawable selector = preference.createSelector(preference.mColors[i]);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            int[][] states = new int[][] { new int[] { -android.R.attr.state_pressed }, new int[] { android.R.attr.state_pressed } };
            int[] colors = new int[] { preference.shiftColor(preference.mColors[i]), preference.mColors[i] };
            ColorStateList rippleColors = new ColorStateList(states, colors);
            preference.setBackgroundCompat(child, new RippleDrawable(rippleColors, selector, null));
        } else {
            preference.setBackgroundCompat(child, selector);
        }
    }
}
Also used : GridLayout(androidx.gridlayout.widget.GridLayout) FrameLayout(android.widget.FrameLayout) RippleDrawable(android.graphics.drawable.RippleDrawable) Drawable(android.graphics.drawable.Drawable) ColorStateList(android.content.res.ColorStateList) SuppressLint(android.annotation.SuppressLint) RippleDrawable(android.graphics.drawable.RippleDrawable)

Example 44 with RippleDrawable

use of android.graphics.drawable.RippleDrawable in project FloatingActionButton by hannesa2.

the class Label method createFillDrawable.

@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private Drawable createFillDrawable() {
    StateListDrawable drawable = new StateListDrawable();
    drawable.addState(new int[] { android.R.attr.state_pressed }, createRectDrawable(mColorPressed));
    drawable.addState(new int[] {}, createRectDrawable(mColorNormal));
    if (Util.hasLollipop()) {
        RippleDrawable ripple = new RippleDrawable(new ColorStateList(new int[][] { {} }, new int[] { mColorRipple }), drawable, null);
        setOutlineProvider(new ViewOutlineProvider() {

            @Override
            public void getOutline(View view, Outline outline) {
                outline.setOval(0, 0, view.getWidth(), view.getHeight());
            }
        });
        setClipToOutline(true);
        mBackgroundDrawable = ripple;
        return ripple;
    }
    mBackgroundDrawable = drawable;
    return drawable;
}
Also used : ColorStateList(android.content.res.ColorStateList) Outline(android.graphics.Outline) StateListDrawable(android.graphics.drawable.StateListDrawable) ViewOutlineProvider(android.view.ViewOutlineProvider) AppCompatTextView(androidx.appcompat.widget.AppCompatTextView) View(android.view.View) RippleDrawable(android.graphics.drawable.RippleDrawable) TargetApi(android.annotation.TargetApi)

Example 45 with RippleDrawable

use of android.graphics.drawable.RippleDrawable in project FloatingActionButton by hannesa2.

the class Label method onActionDown.

@TargetApi(Build.VERSION_CODES.LOLLIPOP)
void onActionDown() {
    if (mUsingStyle) {
        mBackgroundDrawable = getBackground();
    }
    if (mBackgroundDrawable instanceof StateListDrawable) {
        StateListDrawable drawable = (StateListDrawable) mBackgroundDrawable;
        drawable.setState(new int[] { android.R.attr.state_pressed });
    } else if (Util.hasLollipop() && mBackgroundDrawable instanceof RippleDrawable) {
        RippleDrawable ripple = (RippleDrawable) mBackgroundDrawable;
        ripple.setState(new int[] { android.R.attr.state_enabled, android.R.attr.state_pressed });
        ripple.setHotspot(getMeasuredWidth() / 2, getMeasuredHeight() / 2);
        ripple.setVisible(true, true);
    }
// setPressed(true);
}
Also used : StateListDrawable(android.graphics.drawable.StateListDrawable) RippleDrawable(android.graphics.drawable.RippleDrawable) TargetApi(android.annotation.TargetApi)

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