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:org.gateshipone.odyssey.fragments.ArtistAlbumsFragment.java

/**
 * Initialize the options menu.//from   w  w  w  .  j  ava2 s  .  co m
 * Be sure to call {@link #setHasOptionsMenu} before.
 *
 * @param menu         The container for the custom options menu.
 * @param menuInflater The inflater to instantiate the layout.
 */
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater menuInflater) {
    // Inflate the menu; this adds items to the action bar if it is present.
    menuInflater.inflate(R.menu.options_menu_artist_albums_fragment, menu);

    // get tint color
    int tintColor = ThemeUtils.getThemeColor(getContext(), R.attr.odyssey_color_text_accent);

    Drawable drawable = menu.findItem(R.id.action_add_artist_albums).getIcon();
    drawable = DrawableCompat.wrap(drawable);
    DrawableCompat.setTint(drawable, tintColor);
    menu.findItem(R.id.action_add_artist_albums).setIcon(drawable);

    super.onCreateOptionsMenu(menu, menuInflater);
}

From source file:com.freshdigitable.udonroad.StatusDetailFragment.java

@Override
public void onStart() {
    super.onStart();

    final long statusId = getStatusId();
    statusRequestWorker.open();/*from w  w  w.j  a va  2 s .com*/
    final TypedCache<Status> statusCache = statusRequestWorker.getCache();
    final Status status = statusCache.find(statusId);
    if (status == null) {
        Toast.makeText(getContext(), "status is not found", Toast.LENGTH_SHORT).show();
        return;
    }

    final StatusDetailView statusView = binding.statusView;
    StatusViewImageHelper.load(status, statusView);
    final User user = StatusViewImageHelper.getBindingUser(status);

    final ImageView icon = statusView.getIcon();
    final OnUserIconClickedListener userIconClickedListener = createUserIconClickedListener();
    icon.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            userIconClickedListener.onUserIconClicked(view, user);
        }
    });
    statusView.getUserName().setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            userIconClickedListener.onUserIconClicked(icon, user);
        }
    });
    statusView.getMediaContainer().setOnMediaClickListener(new OnMediaClickListener() {
        @Override
        public void onMediaClicked(View view, int index) {
            MediaViewActivity.start(view.getContext(), status, index);
        }
    });

    setTintList(binding.sdFav.getDrawable(), R.color.selector_fav_icon);
    binding.sdFav.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            if (status.isFavorited()) {
                statusRequestWorker.destroyFavorite(statusId);
            } else {
                statusRequestWorker.createFavorite(statusId);
            }
        }
    });
    setTintList(binding.sdRetweet.getDrawable(), R.color.selector_rt_icon);
    binding.sdRetweet.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            if (status.isRetweeted()) {
                statusRequestWorker.destroyRetweet(statusId);
            } else {
                statusRequestWorker.retweetStatus(statusId);
            }
        }
    });
    DrawableCompat.setTint(binding.sdReply.getDrawable(),
            ContextCompat.getColor(getContext(), R.color.twitter_action_normal));
    binding.sdReply.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            setupInput(TweetInputFragment.TYPE_REPLY);
        }
    });
    setTintList(binding.sdQuote.getDrawable(), R.color.twitter_action_normal);
    binding.sdQuote.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            setupInput(TweetInputFragment.TYPE_QUOTE);
        }
    });

    subscription = statusCache.observeById(statusId).subscribe(new Action1<Status>() {
        @Override
        public void call(Status status) {
            binding.statusView.bindStatus(status);
            binding.sdFav.setActivated(status.isFavorited());
            binding.sdRetweet.setActivated(status.isRetweeted());
        }
    });

    final Status bindingStatus = StatusViewImageHelper.getBindingStatus(status);
    if (bindingStatus.getURLEntities().length < 1) {
        return;
    }
    if (twitterCard != null) {
        setupTwitterCard(twitterCard);
    } else {
        TwitterCardFetcher.observeFetch(bindingStatus.getURLEntities()[0].getExpandedURL())
                .observeOn(AndroidSchedulers.mainThread()).subscribe(new Action1<TwitterCard>() {
                    @Override
                    public void call(final TwitterCard twitterCard) {
                        setupTwitterCard(twitterCard);
                    }
                }, new Action1<Throwable>() {
                    @Override
                    public void call(Throwable throwable) {
                        Log.e(TAG, "card fetch: ", throwable);
                    }
                });
    }
}

From source file:com.nextgis.maplibui.util.ControlHelper.java

public static Drawable tintDrawable(Drawable drawable, int color) {
    if (drawable == null)
        return null;

    drawable = DrawableCompat.wrap(drawable);
    DrawableCompat.setTint(drawable, color);
    return drawable;
}

From source file:com.android.systemui.qs.QSPanelTopView.java

public void setDropIcon(int resourceId, int colorResourceId) {
    mDropTargetIcon.setImageResource(resourceId);
    final Drawable drawable = mDropTargetIcon.getDrawable();

    DrawableCompat.setTintMode(drawable, PorterDuff.Mode.SRC_ATOP);
    DrawableCompat.setTint(drawable, mContext.getColor(colorResourceId));

    if (drawable instanceof Animatable) {
        ((Animatable) drawable).start();
    }//  ww w  .j  av  a 2  s  .  c om
}

From source file:com.nerderylabs.android.nerdalert.ui.fragment.MainFragment.java

private void initializeNametag() {
    final EditText nameEditText = (EditText) view.findViewById(R.id.my_name);
    final EditText taglineEditText = (EditText) view.findViewById(R.id.my_tagline);
    final ImageView photoImageView = (ImageView) view.findViewById(R.id.my_photo);

    // restore state
    nameEditText.setText(myInfo.getName());
    taglineEditText.setText(myInfo.getTagline());
    if (myInfo.getBitmap() != null) {
        photoImageView.setImageDrawable(new BitmapDrawable(getResources(), myInfo.getBitmap()));
    } else {//from  w w w . j a  v a 2s.c  o  m
        Drawable photo = ContextCompat.getDrawable(getContext(), R.drawable.ic_contact_photo);
        DrawableCompat.setTint(photo, ContextCompat.getColor(getContext(), R.color.color_nametag));
        photoImageView.setImageDrawable(photo);
    }

    // listen for focus change
    View.OnFocusChangeListener focusListener = new View.OnFocusChangeListener() {
        @Override
        public void onFocusChange(View v, boolean hasFocus) {
            if (!hasFocus) {
                persistNametagValues((TextView) v);
            }
        }
    };

    // listen for the done key
    EditText.OnEditorActionListener doneListener = new EditText.OnEditorActionListener() {
        @Override
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            if (actionId == EditorInfo.IME_ACTION_DONE) {
                persistNametagValues(v);
            }
            return false;
        }
    };

    // open profile contact card when user's photo is tapped
    ImageView.OnClickListener imageClickListener = new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent intent = new Intent(Intent.ACTION_EDIT);
            intent.setDataAndType(ContactsContract.Profile.CONTENT_URI,
                    ContactsContract.Contacts.CONTENT_ITEM_TYPE);

            // In Android 4.0 (API version 14) and later, a problem in the contacts app causes
            // incorrect navigation.To work around this problem in Android 4.0.3 (API version
            // 15) and later, add the extended data key finishActivityOnSaveCompleted to the
            // intent, with a value of true.
            intent.putExtra("finishActivityOnSaveCompleted", true);

            startActivity(intent);
        }
    };

    nameEditText.setOnEditorActionListener(doneListener);
    taglineEditText.setOnEditorActionListener(doneListener);

    nameEditText.setOnFocusChangeListener(focusListener);
    taglineEditText.setOnFocusChangeListener(focusListener);

    photoImageView.setOnClickListener(imageClickListener);

}

From source file:com.justplay1.shoppist.features.search.SearchFragment.java

private void updateNavigationIcon() {
    Context context = searchView.getContext();
    Drawable drawable = ContextCompat.getDrawable(getContext(), R.drawable.ic_arrow_back);
    drawable = DrawableCompat.wrap(drawable);
    DrawableCompat.setTint(drawable, ViewUtils.getThemeAttrColor(context, R.attr.colorControlNormal));
    searchView.setIcon(drawable);/*  www. j ava 2  s  .  c o m*/
}

From source file:com.github.shareme.gwsmaterialuikit.library.material.drawable.PaddingDrawable.java

@Override
public void setTint(int tint) {
    if (mDrawable != null)
        DrawableCompat.setTint(mDrawable, tint);
}

From source file:com.google.android.apps.forscience.whistlepunk.metadata.TriggerHelper.java

public static void populateAutoTextViews(TextView autoTextView, String autoText, int drawableId,
        Resources res) {/*from ww  w.j  a va2  s .c  o m*/
    autoTextView.setText(autoText);
    autoTextView
            .setContentDescription(res.getString(R.string.trigger_label_icon_content_description, autoText));
    Drawable drawable = res.getDrawable(drawableId);
    DrawableCompat.setTint(drawable.mutate(), res.getColor(R.color.text_color_light_grey));
    autoTextView.setCompoundDrawablesRelativeWithIntrinsicBounds(drawable, null, null, null);
}

From source file:com.appsimobile.appsii.hotspotmanager.HotspotSettingsFragment.java

@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);

    mOkButton = view.findViewById(R.id.ok_button);
    mHotspotTitleView = (EditText) view.findViewById(R.id.hotspot_title);

    mDragSortListView = (DragSortListView) view.findViewById(R.id.sort_list_view);
    mReorderController.configure(mDragSortListView);

    mDefaultPage = view.findViewById(R.id.default_page);
    mDefaultPageIconView = (ImageView) view.findViewById(R.id.default_page_icon);
    mDefaultPageValueView = (TextView) view.findViewById(R.id.default_page_value);

    Drawable drawable = DrawableCompat.wrap(mDefaultPageIconView.getDrawable());
    DrawableCompat.setTint(drawable, 0xFF666666);
    mDefaultPageIconView.setImageDrawable(drawable);

    mOkButton.setOnClickListener(this);
    mDefaultPage.setOnClickListener(this);
}

From source file:com.fondesa.recyclerviewdivider.RecyclerViewDivider.java

@SuppressWarnings("ConstantConditions")
@Override//from  w w w  .  j ava 2  s  . c  o m
public void onDraw(Canvas c, RecyclerView parent, RecyclerView.State state) {
    final RecyclerView.Adapter adapter = parent.getAdapter();
    final int listSize;

    // if the divider isn't a simple space, it will be drawn
    if (mType == TYPE_SPACE || adapter == null || (listSize = adapter.getItemCount()) == 0)
        return;

    int left;
    int top;
    int right;
    int bottom;

    final int orientation = RecyclerViewDividerUtils.getOrientation(parent);
    final int spanCount = RecyclerViewDividerUtils.getSpanCount(parent);
    int childCount = parent.getChildCount();
    for (int i = 0; i < childCount; i++) {
        final View child = parent.getChildAt(i);
        int itemPosition = parent.getChildAdapterPosition(child);
        final int groupIndex = RecyclerViewDividerUtils.getGroupIndex(parent, itemPosition);
        final int groupCount = RecyclerViewDividerUtils.getGroupCount(parent, listSize);

        Drawable divider = mDrawableFactory.drawableForItem(groupCount, groupIndex);
        @VisibilityFactory.Show
        int showDivider = mVisibilityFactory.displayDividerForItem(groupCount, groupIndex);

        if (divider == null || showDivider == VisibilityFactory.SHOW_NONE)
            continue;

        final int spanSize = RecyclerViewDividerUtils.getSpanSize(parent, itemPosition);

        int lineAccumulatedSpan = RecyclerViewDividerUtils.getAccumulatedSpanInLine(parent, spanSize,
                itemPosition, groupIndex);

        final int margin = mMarginFactory.marginSizeForItem(groupCount, groupIndex);
        int size = mSizeFactory.sizeForItem(divider, orientation, groupCount, groupIndex);
        if (mTintFactory != null) {
            final int tint = mTintFactory.tintForItem(groupCount, groupIndex);
            Drawable wrappedDrawable = DrawableCompat.wrap(divider);
            DrawableCompat.setTint(wrappedDrawable, tint);
            divider = wrappedDrawable;
        }

        final RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child.getLayoutParams();

        int halfSize = size < 2 ? size : size / 2;

        size = showDivider == VisibilityFactory.SHOW_ITEMS_ONLY ? 0 : size;
        halfSize = showDivider == VisibilityFactory.SHOW_GROUP_ONLY ? 0 : halfSize;

        final int childBottom = child.getBottom();
        final int childTop = child.getTop();
        final int childRight = child.getRight();
        final int childLeft = child.getLeft();

        // if the last element in the span doesn't complete the span count, its size will be full, not the half
        // halfSize * 2 is used instead of size to handle the case Show.ITEMS_ONLY in which size will be == 0
        final int lastElementInSpanSize = itemPosition == listSize - 1 ? halfSize * 2 : halfSize;

        final boolean useCellMargin = margin == 0;

        int marginToAddBefore, marginToAddAfter;
        marginToAddBefore = marginToAddAfter = 0;

        if (orientation == RecyclerView.VERTICAL) {
            if (spanCount > 1 && spanSize < spanCount) {
                top = childTop + margin;
                // size is added to draw filling point between horizontal and vertical dividers
                bottom = childBottom - margin;

                if (useCellMargin) {
                    if (groupIndex > 0) {
                        top -= params.topMargin;
                    }
                    if (groupIndex < groupCount - 1 || size > 0) {
                        bottom += params.bottomMargin;
                    }
                    bottom += size;
                }

                if (lineAccumulatedSpan == spanSize) {
                    // first element in the group
                    left = childRight + margin + params.rightMargin;
                    right = left + lastElementInSpanSize;

                    setBoundsAndDraw(divider, c, left, top, right, bottom);

                    if (useCellMargin) {
                        marginToAddAfter = params.rightMargin;
                    }
                } else if (lineAccumulatedSpan == spanCount) {
                    // last element in the group
                    right = childLeft - margin - params.leftMargin;
                    left = right - halfSize;

                    setBoundsAndDraw(divider, c, left, top, right, bottom);

                    if (useCellMargin) {
                        marginToAddBefore = params.leftMargin;
                    }
                } else {
                    // element in the middle
                    // left half divider
                    right = childLeft - margin - params.leftMargin;
                    left = right - halfSize;

                    setBoundsAndDraw(divider, c, left, top, right, bottom);

                    // right half divider
                    left = childRight + margin + params.rightMargin;
                    right = left + lastElementInSpanSize;

                    setBoundsAndDraw(divider, c, left, top, right, bottom);

                    if (useCellMargin) {
                        marginToAddAfter = params.rightMargin;
                        marginToAddBefore = params.leftMargin;
                    }
                }
            }

            // draw bottom divider
            top = childBottom + params.bottomMargin;
            bottom = top + size;
            left = childLeft + margin - marginToAddBefore;
            right = childRight - margin + marginToAddAfter;

            setBoundsAndDraw(divider, c, left, top, right, bottom);

        } else {
            if (spanCount > 1 && spanSize < spanCount) {
                left = childLeft + margin;
                // size is added to draw filling point between horizontal and vertical dividers
                right = childRight - margin;
                if (useCellMargin) {
                    if (groupIndex > 0) {
                        left -= params.leftMargin;
                    }
                    if (groupIndex < groupCount - 1 || size > 0) {
                        right += params.rightMargin;
                    }
                    right += size;
                }

                if (lineAccumulatedSpan == spanSize) {
                    // first element in the group
                    top = childBottom + margin + params.bottomMargin;
                    bottom = top + lastElementInSpanSize;

                    setBoundsAndDraw(divider, c, left, top, right, bottom);

                    if (useCellMargin) {
                        marginToAddAfter = params.bottomMargin;
                    }
                } else if (lineAccumulatedSpan == spanCount) {
                    // last element in the group
                    bottom = childTop - margin - params.topMargin;
                    top = bottom - halfSize;

                    setBoundsAndDraw(divider, c, left, top, right, bottom);

                    if (useCellMargin) {
                        marginToAddBefore = params.topMargin;
                    }
                } else {
                    // element in the middle
                    // top half divider
                    bottom = childTop - margin - params.topMargin;
                    top = bottom - halfSize;

                    divider.setBounds(left, top, right, bottom);
                    divider.draw(c);

                    // bottom half divider
                    top = childBottom + margin + params.bottomMargin;
                    bottom = top + lastElementInSpanSize;

                    setBoundsAndDraw(divider, c, left, top, right, bottom);

                    if (useCellMargin) {
                        marginToAddAfter = params.bottomMargin;
                        marginToAddBefore = params.topMargin;
                    }
                }
            }

            // draw right divider
            bottom = childBottom - margin + marginToAddAfter;
            top = childTop + margin - marginToAddBefore;
            left = childRight + params.rightMargin;
            right = left + size;

            setBoundsAndDraw(divider, c, left, top, right, bottom);
        }
    }
}