Example usage for android.graphics.drawable LayerDrawable findDrawableByLayerId

List of usage examples for android.graphics.drawable LayerDrawable findDrawableByLayerId

Introduction

In this page you can find the example usage for android.graphics.drawable LayerDrawable findDrawableByLayerId.

Prototype

public Drawable findDrawableByLayerId(int id) 

Source Link

Document

Looks for a layer with the given ID and returns its Drawable .

Usage

From source file:com.pixby.texo.EditTools.ColorTool.java

private void drawBackground(View v) {
    int color = mSampleColors.get(v.getId());
    LayerDrawable layerDrawable = (LayerDrawable) v.getBackground();
    if (layerDrawable != null) {

        GradientDrawable shape = (GradientDrawable) layerDrawable.findDrawableByLayerId(R.id.color_fill);
        shape.setColorFilter(color, PorterDuff.Mode.MULTIPLY);

        shape = (GradientDrawable) layerDrawable.findDrawableByLayerId(R.id.color_focus);
        int alpha = v.hasFocus() ? 255 : 0;
        shape.setAlpha(alpha);// www .j a v a2 s. c  o m
    }
}

From source file:com.waz.zclient.ui.audiomessage.AudioMessageRecordingView.java

public void setAccentColor(int color) {
    Drawable drawable = recordingSeekBar.getProgressDrawable();
    if (drawable == null) {
        return;// w ww . jav  a 2  s  .c  om
    }
    if (drawable instanceof LayerDrawable) {
        LayerDrawable layerDrawable = (LayerDrawable) drawable;
        Drawable progress = layerDrawable.findDrawableByLayerId(android.R.id.progress);
        if (progress != null) {
            drawable = progress;
        }
    }
    drawable.setColorFilter(new LightingColorFilter(0xFF000000, color));
    drawable = recordingSeekBar.getThumb();
    drawable.setColorFilter(new LightingColorFilter(0xFF000000, color));
}

From source file:net.nurik.roman.formwatchface.CompanionWatchFaceConfigActivity.java

private void setupThemeList() {
    mThemeUiHolders.clear();//from ww w.  j  a va  2s . c  o  m
    mThemeItemContainer = (ViewGroup) findViewById(R.id.theme_list);
    LayoutInflater inflater = LayoutInflater.from(this);
    for (final Theme theme : Themes.THEMES) {
        ThemeUiHolder holder = new ThemeUiHolder();

        holder.theme = theme;
        holder.container = inflater.inflate(R.layout.config_theme_item, mThemeItemContainer, false);
        holder.button = (ImageButton) holder.container.findViewById(R.id.button);

        LayerDrawable bgDrawable = (LayerDrawable) getResources().getDrawable(R.drawable.theme_item_bg)
                .mutate();

        GradientDrawable gd = (GradientDrawable) bgDrawable.findDrawableByLayerId(R.id.color);
        gd.setColor(getResources().getColor(theme.midRes));
        holder.button.setBackground(bgDrawable);

        holder.button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                updateAndPersistTheme(theme);
            }
        });

        mThemeUiHolders.add(holder);
        mThemeItemContainer.addView(holder.container);
    }

    loadMuzei();
}

From source file:com.commit451.springy.CompanionWatchFaceConfigActivity.java

private void setupThemeList() {
    mThemeUiHolders.clear();//  www. j a va  2  s .c o m
    mThemeItemContainer = (ViewGroup) findViewById(R.id.theme_list);
    LayoutInflater inflater = LayoutInflater.from(this);
    for (final Themes.Theme theme : Themes.THEMES) {
        ThemeUiHolder holder = new ThemeUiHolder();

        holder.theme = theme;
        holder.container = inflater.inflate(R.layout.config_theme_item, mThemeItemContainer, false);
        holder.button = (ImageButton) holder.container.findViewById(R.id.button);

        LayerDrawable bgDrawable = (LayerDrawable) getResources().getDrawable(R.drawable.theme_item_bg)
                .mutate();

        GradientDrawable gd = (GradientDrawable) bgDrawable.findDrawableByLayerId(R.id.color);
        gd.setColor(theme.color);
        holder.button.setBackground(bgDrawable);

        holder.button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                updateAndPersistTheme(theme);
            }
        });

        mThemeUiHolders.add(holder);
        mThemeItemContainer.addView(holder.container);
    }

    loadMuzei();
}

From source file:com.crazymin2.retailstore.ui.BaseActivity.java

public void setBadgeCount(Context context, LayerDrawable icon, int count) {

    MenuCounterDrawable badge;// w  w  w  . j  a  v a2  s .  co m

    // Reuse drawable if possible
    Drawable reuse = icon.findDrawableByLayerId(R.id.ic_badge);
    if (reuse != null && reuse instanceof MenuCounterDrawable) {
        badge = (MenuCounterDrawable) reuse;
    } else {
        badge = new MenuCounterDrawable(context);
    }

    badge.setCount(count);
    icon.mutate();
    icon.setDrawableByLayerId(R.id.ic_badge, badge);
}

From source file:com.max.library.view.v7.AppCompatDrawableManager.java

public Drawable getDrawable(@NonNull Context context, @DrawableRes int resId, boolean failIfNotKnown) {
    // Let the InflateDelegates have a go first
    if (mDelegates != null) {
        for (int i = 0, count = mDelegates.size(); i < count; i++) {
            final InflateDelegate delegate = mDelegates.get(i);
            final Drawable result = delegate.onInflateDrawable(context, resId);
            if (result != null) {
                return result;
            }//from   ww w  .j a  va 2s.  com
        }
    }

    // The delegates failed so we'll carry on
    Drawable drawable = ContextCompat.getDrawable(context, resId);

    if (drawable != null) {
        if (Build.VERSION.SDK_INT >= 8) {
            // Mutate can cause NPEs on 2.1
            drawable = drawable.mutate();
        }

        final ColorStateList tintList = getTintList(context, resId);
        if (tintList != null) {
            // First wrap the Drawable and set the tint list
            drawable = DrawableCompat.wrap(drawable);
            DrawableCompat.setTintList(drawable, tintList);

            // If there is a blending mode specified for the drawable, use it
            final PorterDuff.Mode tintMode = getTintMode(resId);
            if (tintMode != null) {
                DrawableCompat.setTintMode(drawable, tintMode);
            }
        } else if (resId == R.drawable.abc_cab_background_top_material) {
            return new LayerDrawable(
                    new Drawable[] { getDrawable(context, R.drawable.abc_cab_background_internal_bg),
                            getDrawable(context, R.drawable.abc_cab_background_top_mtrl_alpha) });
        } else if (resId == com.max.library.R.drawable.abc_seekbar_track_material) {
            LayerDrawable ld = (LayerDrawable) drawable;
            setPorterDuffColorFilter(ld.findDrawableByLayerId(android.R.id.background),
                    getThemeAttrColor(context, R.attr.colorControlNormal), DEFAULT_MODE);
            setPorterDuffColorFilter(ld.findDrawableByLayerId(android.R.id.secondaryProgress),
                    getThemeAttrColor(context, R.attr.colorControlNormal), DEFAULT_MODE);
            setPorterDuffColorFilter(ld.findDrawableByLayerId(android.R.id.progress),
                    getThemeAttrColor(context, R.attr.colorControlActivated), DEFAULT_MODE);
        } else {
            final boolean tinted = tintDrawableUsingColorFilter(context, resId, drawable);
            if (!tinted && failIfNotKnown) {
                // If we didn't tint using a ColorFilter, and we're set to fail if we don't
                // know the id, return null
                drawable = null;
            }
        }
    }
    return drawable;
}

From source file:android.support.v7.widget.AppCompatDrawableManager.java

private Drawable tintDrawable(@NonNull Context context, @DrawableRes int resId, boolean failIfNotKnown,
        @NonNull Drawable drawable) {//w ww  .  j  av  a  2s  . co  m
    final ColorStateList tintList = getTintList(context, resId);
    if (tintList != null) {
        // First mutate the Drawable, then wrap it and set the tint list
        if (DrawableUtils.canSafelyMutateDrawable(drawable)) {
            drawable = drawable.mutate();
        }
        drawable = DrawableCompat.wrap(drawable);
        DrawableCompat.setTintList(drawable, tintList);

        // If there is a blending mode specified for the drawable, use it
        final PorterDuff.Mode tintMode = getTintMode(resId);
        if (tintMode != null) {
            DrawableCompat.setTintMode(drawable, tintMode);
        }
    } else if (resId == R.drawable.abc_seekbar_track_material) {
        LayerDrawable ld = (LayerDrawable) drawable;
        setPorterDuffColorFilter(ld.findDrawableByLayerId(android.R.id.background),
                getThemeAttrColor(context, R.attr.colorControlNormal), DEFAULT_MODE);
        setPorterDuffColorFilter(ld.findDrawableByLayerId(android.R.id.secondaryProgress),
                getThemeAttrColor(context, R.attr.colorControlNormal), DEFAULT_MODE);
        setPorterDuffColorFilter(ld.findDrawableByLayerId(android.R.id.progress),
                getThemeAttrColor(context, R.attr.colorControlActivated), DEFAULT_MODE);
    } else if (resId == R.drawable.abc_ratingbar_material
            || resId == R.drawable.abc_ratingbar_indicator_material
            || resId == R.drawable.abc_ratingbar_small_material) {
        LayerDrawable ld = (LayerDrawable) drawable;
        setPorterDuffColorFilter(ld.findDrawableByLayerId(android.R.id.background),
                getDisabledThemeAttrColor(context, R.attr.colorControlNormal), DEFAULT_MODE);
        setPorterDuffColorFilter(ld.findDrawableByLayerId(android.R.id.secondaryProgress),
                getThemeAttrColor(context, R.attr.colorControlActivated), DEFAULT_MODE);
        setPorterDuffColorFilter(ld.findDrawableByLayerId(android.R.id.progress),
                getThemeAttrColor(context, R.attr.colorControlActivated), DEFAULT_MODE);
    } else {
        final boolean tinted = tintDrawableUsingColorFilter(context, resId, drawable);
        if (!tinted && failIfNotKnown) {
            // If we didn't tint using a ColorFilter, and we're set to fail if we don't
            // know the id, return null
            drawable = null;
        }
    }
    return drawable;
}

From source file:org.cyanogenmod.theme.chooser.ChooserDetailFragment.java

private void refreshApplyButton() {
    //Default//from  ww w  .  j  a v a  2  s . co  m
    mApply.setText(R.string.apply);
    StateListDrawable d = (StateListDrawable) mApply.getBackground();
    LayerDrawable bg = (LayerDrawable) d
            .getStateDrawable(d.getStateDrawableIndex(new int[] { android.R.attr.state_enabled }));
    final ClipDrawable clip = (ClipDrawable) bg.findDrawableByLayerId(android.R.id.progress);
    clip.setLevel(0);

    //Determine whether the apply button should show "apply" or "update"
    if (mAppliedThemeCursor != null) {
        mAppliedThemeCursor.moveToPosition(-1);
        while (mAppliedThemeCursor.moveToNext()) {
            String component = mAppliedThemeCursor
                    .getString(mAppliedThemeCursor.getColumnIndex(MixnMatchColumns.COL_KEY));
            String pkg = mAppliedThemeCursor
                    .getString(mAppliedThemeCursor.getColumnIndex(MixnMatchColumns.COL_VALUE));

            // At least one component is set here for this theme
            if (pkg != null && mPkgName.equals(pkg)) {
                mApply.setText(R.string.update);
                break;
            }
        }
    }

    //Determine if the apply button's progress
    int progress = (mService == null) ? 0 : mService.getProgress();
    if (progress != 0) {
        clip.setLevel(progress * 100);
        mApply.setText(R.string.applying);
        mApply.setClickable(false);
    } else {
        mApply.setClickable(true);
    }
}

From source file:android.support.v7ox.widget.AppCompatDrawableManager.java

private Drawable tintDrawable(@NonNull Context context, @DrawableRes int resId, boolean failIfNotKnown,
        @NonNull Drawable drawable) {//from  w  ww . j  ava 2 s . c o m
    final ColorStateList tintList = getTintList(context, resId);
    if (tintList != null) {
        // First mutate the Drawable, then wrap it and set the tint list
        if (DrawableUtils.canSafelyMutateDrawable(drawable)) {
            drawable = drawable.mutate();
        }
        drawable = DrawableCompat.wrap(drawable);
        DrawableCompat.setTintList(drawable, tintList);

        // If there is a blending mode specified for the drawable, use it
        final PorterDuff.Mode tintMode = getTintMode(resId);
        if (tintMode != null) {
            DrawableCompat.setTintMode(drawable, tintMode);
        }
    } else if (resId == R.drawable.abc_cab_background_top_material_ox) {
        return new LayerDrawable(
                new Drawable[] { getDrawable(context, R.drawable.abc_cab_background_internal_bg_ox),
                        getDrawable(context, R.drawable.abc_cab_background_internal_bg_ox) });
    } else if (resId == R.drawable.abc_seekbar_track_material_ox) {
        LayerDrawable ld = (LayerDrawable) drawable;
        setPorterDuffColorFilter(ld.findDrawableByLayerId(android.R.id.background),
                ThemeUtils.getThemeAttrColor(context, R.attr.colorControlNormal_ox), DEFAULT_MODE);
        setPorterDuffColorFilter(ld.findDrawableByLayerId(android.R.id.secondaryProgress),
                ThemeUtils.getThemeAttrColor(context, R.attr.colorControlNormal_ox), DEFAULT_MODE);
        setPorterDuffColorFilter(ld.findDrawableByLayerId(android.R.id.progress),
                ThemeUtils.getThemeAttrColor(context, R.attr.colorControlActivated_ox), DEFAULT_MODE);
    } else if (resId == R.drawable.abc_ratingbar_indicator_material_ox
            || resId == R.drawable.abc_ratingbar_small_material_ox) {
        LayerDrawable ld = (LayerDrawable) drawable;
        setPorterDuffColorFilter(ld.findDrawableByLayerId(android.R.id.background),
                ThemeUtils.getDisabledThemeAttrColor(context, R.attr.colorControlNormal_ox), DEFAULT_MODE);
        setPorterDuffColorFilter(ld.findDrawableByLayerId(android.R.id.secondaryProgress),
                ThemeUtils.getThemeAttrColor(context, R.attr.colorControlActivated_ox), DEFAULT_MODE);
        setPorterDuffColorFilter(ld.findDrawableByLayerId(android.R.id.progress),
                ThemeUtils.getThemeAttrColor(context, R.attr.colorControlActivated_ox), DEFAULT_MODE);
    } else {
        final boolean tinted = tintDrawableUsingColorFilter(context, resId, drawable);
        if (!tinted && failIfNotKnown) {
            // If we didn't tint using a ColorFilter, and we're set to fail if we don't
            // know the id, return null
            drawable = null;
        }
    }
    return drawable;
}

From source file:it.ndorigatti.android.view.MulticolorProgressBar.java

/**
 * Update the progress colors/*  www .j a  v a2 s .c o m*/
 *
 * @param id
 * @param color
 */
private void doUpdateProgressColor(int id, int color) {
    LayerDrawable layerDrawable = (LayerDrawable) mStraightDrawable;
    LayerDrawable reverseLayerDrawable = (LayerDrawable) mReversedDrawable;
    Drawable mOverlayProgressDrawable = layerDrawable.findDrawableByLayerId(id);
    mOverlayProgressDrawable.setColorFilter(color, PorterDuff.Mode.SRC_ATOP);
    mOverlayProgressDrawable = reverseLayerDrawable.findDrawableByLayerId(id);
    mOverlayProgressDrawable.setColorFilter(color, PorterDuff.Mode.SRC_ATOP);
}