Example usage for android.support.v4.graphics.drawable DrawableCompat setTint

List of usage examples for android.support.v4.graphics.drawable DrawableCompat setTint

Introduction

In this page you can find the example usage for android.support.v4.graphics.drawable DrawableCompat setTint.

Prototype

public static void setTint(Drawable drawable, int i) 

Source Link

Usage

From source file:io.github.importre.animatedicons.AnimatedButton.java

@SuppressLint("NewApi")
private void init(Context context) {
    if (isLollipop()) {
        offDrawable = context.getDrawable(getOffDrawable());
        onDrawable = context.getDrawable(getOnDrawable());
    } else {/* w w w.  j  a v a  2 s  .com*/
        Resources r = context.getResources();

        offDrawable = r.getDrawable(getOffDrawable());
        onDrawable = r.getDrawable(getOnDrawable());
        offDrawable = DrawableCompat.wrap(offDrawable);
        onDrawable = DrawableCompat.wrap(onDrawable);

        int color = r.getColor(R.color.ai_primary);
        DrawableCompat.setTint(offDrawable, color);
        DrawableCompat.setTint(onDrawable, color);
    }

    setScaleType(ScaleType.CENTER_INSIDE);

    if (isLollipop()) {
        setImageDrawable(!checked ? onDrawable : offDrawable);
    } else {
        setImageDrawable(checked ? onDrawable : offDrawable);
    }
}

From source file:com.github.rubensousa.bottomsheetbuilder.adapter.BottomSheetMenuItem.java

public BottomSheetMenuItem(MenuItem item, @ColorInt int textColor, @DrawableRes int background,
        @ColorInt int tintColor) {
    mMenuItem = item;/*from   ww w.j av  a2s.c  o  m*/
    mIcon = item.getIcon();
    mId = item.getItemId();
    mTitle = item.getTitle().toString();
    mTextColor = textColor;
    mBackground = background;
    mTintColor = tintColor;

    if (mTintColor != -1) {
        mIcon = DrawableCompat.wrap(mIcon);
        DrawableCompat.setTint(mIcon, mTintColor);
    }
}

From source file:com.kaliturin.blacklist.utils.Utils.java

/**
 * Sets the tint color of the drawable//from   w  w w  .java 2  s.  c o m
 **/
public static void setDrawableTint(Context context, Drawable drawable, @AttrRes int colorAttrRes) {
    int colorRes = getResourceId(context, colorAttrRes);
    int color = ContextCompat.getColor(context, colorRes);
    DrawableCompat.setTint(drawable, color);
}

From source file:com.schedjoules.eventdiscovery.framework.utils.TintedDrawable.java

/**
 * Decorated object is going to be a tinted version of the given drawable.
 *//*from  w  ww  .  j a  v  a 2 s  .  c  o m*/
public TintedDrawable(final Drawable drawable, final Color color) {
    super(new Factory<Drawable>() {
        @Override
        public Drawable create() {
            Drawable mutated = DrawableCompat.wrap(drawable).mutate();
            DrawableCompat.setTint(mutated, color.argb());
            return mutated;
        }
    });
}

From source file:io.github.hidroh.materialistic.MenuTintDelegate.java

/**
 * Callback that should be triggered after menu has been inflated
 * @param menu    inflated menu//from   w w  w  . j a v a2  s  .c o  m
 */
public void onOptionsMenuCreated(Menu menu) {
    for (int i = 0; i < menu.size(); i++) {
        Drawable drawable = menu.getItem(i).getIcon();
        if (drawable == null) {
            continue;
        }
        drawable = DrawableCompat.wrap(drawable);
        DrawableCompat.setTint(drawable, mTextColorPrimary);
    }
}

From source file:ca.rmen.android.scrumchatter.chart.ChartUtils.java

static void addLegendEntry(Context context, ViewGroup legendView, String name, int color) {
    TextView memberLegendEntry = new TextView(context);
    memberLegendEntry.setText(name);/*w w w .  j  a va2s.  co  m*/
    memberLegendEntry.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
            ViewGroup.LayoutParams.WRAP_CONTENT));
    memberLegendEntry.setPadding(0, 0,
            context.getResources().getDimensionPixelSize(R.dimen.chart_legend_entry_padding), 0);

    final Drawable icon;
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
        icon = ContextCompat.getDrawable(context, R.drawable.ic_legend_square);
        memberLegendEntry.setTextColor(color);
    } else {
        icon = ContextCompat.getDrawable(context, R.drawable.ic_legend_square).mutate();
        DrawableCompat.setTint(icon, color);
    }
    memberLegendEntry.setCompoundDrawablesWithIntrinsicBounds(icon, null, null, null);
    legendView.addView(memberLegendEntry);
}

From source file:com.gmail.tylerfilla.axon.ui.activity.HelpFOSSActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // Inflate and set content view
    setContentView(R.layout.activity_help_foss);

    // Find stuff
    Toolbar appBar = (Toolbar) findViewById(R.id.activity_help_foss_app_bar);
    RecyclerView list = (RecyclerView) findViewById(R.id.activity_help_foss_list);

    // Configure app bar
    setSupportActionBar(appBar);/*w  w w . j a  v a2 s . co  m*/

    // Display up button in app bar
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);

    // Apply dark tint to navigation icon
    // noinspection ConstantConditions
    Drawable navigationIcon = DrawableCompat.wrap(appBar.getNavigationIcon());
    DrawableCompat.setTint(navigationIcon, 0x8b000000);
    appBar.setNavigationIcon(navigationIcon);

    // Configure list
    list.setAdapter(new ListAdapter());
    list.setLayoutManager(new LinearLayoutManager(this));

    // Create list for licensed FOSS components
    fossComponents = new ArrayList<>();

    try {
        // Read components file into a buffer
        StringWriter componentFileBuffer = new StringWriter();
        IOUtils.copy(getAssets().open("foss/components.json"), componentFileBuffer, Charset.defaultCharset());

        // Parse component array
        JSONArray componentArray = (JSONArray) new JSONTokener(componentFileBuffer.toString()).nextValue();

        // Iterate over components
        for (int i = 0; i < componentArray.length(); i++) {
            JSONObject component = componentArray.getJSONObject(i);

            // Add component to list
            fossComponents.add(new FOSSComponent(component.getString("name"),
                    component.getString("licenseName"), component.getString("licenseTextURL")));
        }
    } catch (IOException e) {
        e.printStackTrace();
    } catch (JSONException e) {
        e.printStackTrace();
    }
}

From source file:galleryfinal.adapter.CommonBaseAdapter.java

protected Drawable createCheckIcon(int color, int resId) {
    Drawable checkIcon = ContextCompat.getDrawable(mContext, resId);
    // checkIcon = DrawableCompat.wrap(checkIcon);
    DrawableCompat.setTint(checkIcon, color);
    return checkIcon;
}

From source file:cn.finalteam.galleryfinal.adapter.CommonBaseAdapter.java

protected Drawable createCheckIcon(int color, int resId) {
    Drawable checkIcon = ContextCompat.getDrawable(mActivity, resId);
    checkIcon = DrawableCompat.wrap(checkIcon);
    DrawableCompat.setTint(checkIcon, color);
    return checkIcon;
}

From source file:com.doctoror.fuckoffmusicplayer.presentation.util.DrawableUtils.java

@Nullable
public static Drawable getTintedDrawable(@Nullable Drawable drawable, @ColorInt final int tint) {
    if (drawable != null) {
        drawable = DrawableCompat.wrap(drawable);
        DrawableCompat.setTint(drawable, tint);
    }//from  w w w . j  av a 2 s . co m
    return drawable;
}