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:com.negusoft.greenmatter.drawable.CompoundDrawableWrapper.java

@Override
public void setTint(int tint) {
    for (Drawable d : mSecondaryDrawables)
        DrawableCompat.setTint(d, tint);
    super.setTint(tint);
}

From source file:android.support.v7.graphics.drawable.DrawableWrapper.java

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

From source file:com.android.projectz.teamrocket.thebusapp.adapters.MainRecyclerAdapter.java

@Override
public void onBindViewHolder(final MainRecyclerAdapter.ViewHolder holder, final int position) {
    int lastPosition = -1;
    if (position > lastPosition) {
        Animation animation = AnimationUtils.loadAnimation(context,
                (position > lastPosition) ? R.anim.up_from_bottom : R.anim.down_from_top);
        holder.itemView.startAnimation(animation);
        lastPosition = position;//from   www . j a  va 2s .c om
    }

    if (SharedPreferencesUtils.getSelectedTheme(context).equals("ThemeDark")) {
        holder.cardView.setBackgroundColor(ContextCompat.getColor(context, R.color.cardview_dark_background));
        holder.txtTitle.setTextColor(ContextCompat.getColor(context, android.R.color.primary_text_dark));
        holder.txtSubtitle.setTextColor(ContextCompat.getColor(context, android.R.color.secondary_text_dark));
        holder.txtOther.setTextColor(ContextCompat.getColor(context, android.R.color.secondary_text_dark));
        image = DrawableCompat.wrap(ContextCompat.getDrawable(context, R.drawable.ic_arrow_row));
        DrawableCompat.setTint(image, context.getResources().getColor(R.color.iconDark));
    } else {
        holder.cardView.setBackgroundColor(ContextCompat.getColor(context, R.color.cardview_light_background));
        holder.txtTitle.setTextColor(ContextCompat.getColor(context, android.R.color.primary_text_light));
        holder.txtSubtitle.setTextColor(ContextCompat.getColor(context, android.R.color.secondary_text_light));
        holder.txtOther.setTextColor(ContextCompat.getColor(context, android.R.color.secondary_text_light));
        image = DrawableCompat.wrap(ContextCompat.getDrawable(context, R.drawable.ic_arrow_row));
        DrawableCompat.setTint(image, context.getResources().getColor(R.color.iconLight));
    }

    holder.txtTitle.setText(myObjects.get(position).getTextTitle());
    holder.txtSubtitle.setText(myObjects.get(position).getTextSubtitle());
    holder.txtOther.setText(myObjects.get(position).getTextOther());
    holder.imageView.setImageResource(myObjects.get(position).getImageId());
    holder.arrowRow.setImageDrawable(image);

    //ascoltatore del *tap* sulla card
    holder.relativeLayout.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Toast.makeText(context, "Loading...", Toast.LENGTH_SHORT).show();
            Intent intent = new Intent(context, DetailViewerActivity.class);
            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_MULTIPLE_TASK); //senza di esso va in crash, perch bisogna creare l'intent come se fosse una nuova activity
            intent.putExtra("title", myObjects.get(position).getTextTitle());
            intent.putExtra("subtitle", myObjects.get(position).getTextSubtitle());
            intent.putExtra("other", myObjects.get(position).getTextOther());
            intent.putExtra("fermataId", myObjects.get(position).getFermataId());
            ArrayList<String> holderData = new ArrayList<String>();
            holderData.add(myObjects.get(position).getTextTitle());
            holderData.add(myObjects.get(position).getTextSubtitle());
            holderData.add(myObjects.get(position).getTextOther());
            intent.putStringArrayListExtra("holderData", holderData);
            context.startActivity(intent);
        }
    });

    //MainActivity.recyclerView.scrollToPosition(myObjects.get(position).isNear != -1 ? position : null);
}

From source file:com.keylesspalace.tusky.view.ProgressImageView.java

@Override
protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);

    float angle = (progress / 100f) * 360 - 90;
    float halfWidth = canvas.getWidth() / 2;
    float halfHeight = canvas.getHeight() / 2;
    progressRect.set(halfWidth * 0.75f, halfHeight * 0.75f, halfWidth * 1.25f, halfHeight * 1.25f);
    biggerRect.set(progressRect);//from w w  w  . ja  va  2s  .co m
    int margin = 8;
    biggerRect.set(progressRect.left - margin, progressRect.top - margin, progressRect.right + margin,
            progressRect.bottom + margin);
    canvas.saveLayer(biggerRect, null, Canvas.ALL_SAVE_FLAG);
    if (progress != -1) {
        canvas.drawOval(progressRect, circlePaint);
        canvas.drawArc(biggerRect, angle, 360 - angle - 90, true, clearPaint);
    }
    canvas.restore();

    int circleRadius = Utils.dpToPx(getContext(), 14);
    int circleMargin = Utils.dpToPx(getContext(), 14);

    int circleY = canvas.getHeight() - circleMargin - circleRadius / 2;
    int circleX = canvas.getWidth() - circleMargin - circleRadius / 2;

    canvas.drawCircle(circleX, circleY, circleRadius, markBgPaint);

    captionDrawable.setBounds(canvas.getWidth() - circleMargin - circleRadius,
            canvas.getHeight() - circleMargin - circleRadius, canvas.getWidth() - circleMargin,
            canvas.getHeight() - circleMargin);
    DrawableCompat.setTint(captionDrawable, Color.WHITE);
    captionDrawable.draw(canvas);
}

From source file:com.nadmm.airports.utils.UiUtils.java

static public Drawable getTintedDrawable(Context context, int resid, int color) {
    // Get a mutable copy of the drawable so each can be set to a different color
    String key = String.format(Locale.US, "%d:%d", resid, color);
    Drawable d = getDrawableFromCache(key);
    if (d == null) {
        d = ResourcesCompat.getDrawable(context.getResources(), resid, null).mutate();
        DrawableCompat.setTint(d, color);
        putDrawableIntoCache(key, d);/*from w  ww  .  j a v a 2 s . c  om*/
    }
    return d;
}

From source file:despotoski.nikola.github.com.bottomnavigationlayout.BottomTabletNavigationView.java

private void applyColorFilters() {
    if (isSelected()) {
        DrawableCompat.setTint(mTopDrawable, mTextActiveColorFilter);
    } else {//from   www  .java2s .  com
        DrawableCompat.setTintList(mTopDrawable, null);
    }
}

From source file:com.tomeokin.lspush.biz.home.UriDialogFragment.java

@SuppressLint("InflateParams")
@NonNull/*from   w  w w  .j  av  a 2 s.  c  o  m*/
@Override
protected BaseDialogFragment.Builder config(@NonNull BaseDialogFragment.Builder builder) {
    View view = LayoutInflater.from(getContext()).inflate(R.layout.dialog_add_link, null);
    builder.addCustomMessageView(view);

    final View content = getActivity().getWindow().findViewById(Window.ID_ANDROID_CONTENT);
    final FrameLayout container = builder.getCustomViewHolder();
    ViewGroup.LayoutParams lp = container.getLayoutParams();
    lp.width = content.getWidth() / 6 * 5;
    container.setLayoutParams(lp);

    mUrlField = (EditText) view.findViewById(R.id.url_field);

    mNextButton = (TextView) view.findViewById(R.id.next_button);
    mNextButton.setTextColor(Color.BLACK);
    mNextButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            getUrlInfo();
        }
    });
    mNextButton.setOnEditorActionListener(new TextView.OnEditorActionListener() {
        @Override
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            if (actionId == EditorInfo.IME_ACTION_NEXT && isAvailableCheck()
                    && isValidWebUri(mUrlField.getText())) {
                getUrlInfo();
                return true;
            }

            return false;
        }
    });
    Drawable clear = getContext().getDrawable(R.drawable.search_clear);
    DrawableCompat.setTint(clear, ContextCompat.getColor(getContext(), R.color.blue_5_whiteout));
    mNextButton.setCompoundDrawables(null, null, clear, null);
    mProgressBar = (ProgressBar) view.findViewById(R.id.next_progress);

    final String text = ClipboardUtils.getText(getContext());
    if (!TextUtils.isEmpty(text) && isValidWebUri(text)) {
        mUrlField.setText(text);
        activeNextButton();
    } else {
        disableNextButton();
    }

    return builder;
}

From source file:eu.faircode.netguard.AdapterAccess.java

@Override
public void bindView(final View view, final Context context, final Cursor cursor) {
    // Get values
    final int version = cursor.getInt(colVersion);
    final int protocol = cursor.getInt(colProtocol);
    final String daddr = cursor.getString(colDaddr);
    final int dport = cursor.getInt(colDPort);
    long time = cursor.getLong(colTime);
    int allowed = cursor.getInt(colAllowed);
    int block = cursor.getInt(colBlock);
    int count = cursor.getInt(colCount);
    long sent = cursor.isNull(colSent) ? -1 : cursor.getLong(colSent);
    long received = cursor.isNull(colReceived) ? -1 : cursor.getLong(colReceived);
    int connections = cursor.isNull(colConnections) ? -1 : cursor.getInt(colConnections);

    // Get views/*from ww w  .j a v  a  2 s  .c  om*/
    TextView tvTime = view.findViewById(R.id.tvTime);
    ImageView ivBlock = view.findViewById(R.id.ivBlock);
    final TextView tvDest = view.findViewById(R.id.tvDest);
    LinearLayout llTraffic = view.findViewById(R.id.llTraffic);
    TextView tvConnections = view.findViewById(R.id.tvConnections);
    TextView tvTraffic = view.findViewById(R.id.tvTraffic);

    // Set values
    tvTime.setText(new SimpleDateFormat("dd HH:mm").format(time));
    if (block < 0)
        ivBlock.setImageDrawable(null);
    else {
        ivBlock.setImageResource(block > 0 ? R.drawable.host_blocked : R.drawable.host_allowed);
        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
            Drawable wrap = DrawableCompat.wrap(ivBlock.getDrawable());
            DrawableCompat.setTint(wrap, block > 0 ? colorOff : colorOn);
        }
    }

    String dest = Util.getProtocolName(protocol, version, true) + " " + daddr + (dport > 0 ? "/" + dport : "")
            + (count > 1 ? " ?" + count : "");
    SpannableString span = new SpannableString(dest);
    span.setSpan(new UnderlineSpan(), 0, dest.length(), 0);
    tvDest.setText(span);

    if (Util.isNumericAddress(daddr))
        new AsyncTask<String, Object, String>() {
            @Override
            protected void onPreExecute() {
                ViewCompat.setHasTransientState(tvDest, true);
            }

            @Override
            protected String doInBackground(String... args) {
                try {
                    return InetAddress.getByName(args[0]).getHostName();
                } catch (UnknownHostException ignored) {
                    return args[0];
                }
            }

            @Override
            protected void onPostExecute(String addr) {
                tvDest.setText(Util.getProtocolName(protocol, version, true) + " >" + addr
                        + (dport > 0 ? "/" + dport : ""));
                ViewCompat.setHasTransientState(tvDest, false);
            }
        }.execute(daddr);

    if (allowed < 0)
        tvDest.setTextColor(colorText);
    else if (allowed > 0)
        tvDest.setTextColor(colorOn);
    else
        tvDest.setTextColor(colorOff);

    llTraffic.setVisibility(connections > 0 || sent > 0 || received > 0 ? View.VISIBLE : View.GONE);
    if (connections > 0)
        tvConnections.setText(context.getString(R.string.msg_count, connections));

    if (sent > 1024 * 1204 * 1024L || received > 1024 * 1024 * 1024L)
        tvTraffic.setText(context.getString(R.string.msg_gb, (sent > 0 ? sent / (1024 * 1024 * 1024f) : 0),
                (received > 0 ? received / (1024 * 1024 * 1024f) : 0)));
    else if (sent > 1204 * 1024L || received > 1024 * 1024L)
        tvTraffic.setText(context.getString(R.string.msg_mb, (sent > 0 ? sent / (1024 * 1024f) : 0),
                (received > 0 ? received / (1024 * 1024f) : 0)));
    else
        tvTraffic.setText(context.getString(R.string.msg_kb, (sent > 0 ? sent / 1024f : 0),
                (received > 0 ? received / 1024f : 0)));
}

From source file:com.master.metehan.filtereagle.AdapterAccess.java

@Override
public void bindView(final View view, final Context context, final Cursor cursor) {
    // Get values
    final long id = cursor.getLong(colID);
    final int version = cursor.getInt(colVersion);
    final int protocol = cursor.getInt(colProtocol);
    final String daddr = cursor.getString(colDaddr);
    final int dport = cursor.getInt(colDPort);
    long time = cursor.getLong(colTime);
    int allowed = cursor.getInt(colAllowed);
    int block = cursor.getInt(colBlock);
    long sent = cursor.isNull(colSent) ? -1 : cursor.getLong(colSent);
    long received = cursor.isNull(colReceived) ? -1 : cursor.getLong(colReceived);
    int connections = cursor.isNull(colConnections) ? -1 : cursor.getInt(colConnections);

    // Get views/*from  www .  j  a va 2  s .  c  om*/
    TextView tvTime = (TextView) view.findViewById(R.id.tvTime);
    ImageView ivBlock = (ImageView) view.findViewById(R.id.ivBlock);
    final TextView tvDest = (TextView) view.findViewById(R.id.tvDest);
    LinearLayout llTraffic = (LinearLayout) view.findViewById(R.id.llTraffic);
    TextView tvConnections = (TextView) view.findViewById(R.id.tvConnections);
    TextView tvTraffic = (TextView) view.findViewById(R.id.tvTraffic);

    // Set values
    tvTime.setText(new SimpleDateFormat("dd HH:mm").format(time));
    if (block < 0)
        ivBlock.setImageDrawable(null);
    else {
        ivBlock.setImageResource(block > 0 ? R.drawable.host_blocked : R.drawable.host_allowed);
        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
            Drawable wrap = DrawableCompat.wrap(ivBlock.getDrawable());
            DrawableCompat.setTint(wrap, block > 0 ? colorOff : colorOn);
        }
    }

    tvDest.setText(
            Util.getProtocolName(protocol, version, true) + " " + daddr + (dport > 0 ? "/" + dport : ""));

    if (Util.isNumericAddress(daddr) && tvDest.getTag() == null)
        new AsyncTask<String, Object, String>() {
            @Override
            protected void onPreExecute() {
                tvDest.setTag(id);
            }

            @Override
            protected String doInBackground(String... args) {
                try {
                    return InetAddress.getByName(args[0]).getHostName();
                } catch (UnknownHostException ignored) {
                    return args[0];
                }
            }

            @Override
            protected void onPostExecute(String addr) {
                Object tag = tvDest.getTag();
                if (tag != null && (Long) tag == id)
                    tvDest.setText(Util.getProtocolName(protocol, version, true) + " >" + addr
                            + (dport > 0 ? "/" + dport : ""));
                tvDest.setTag(null);
            }
        }.execute(daddr);

    if (allowed < 0)
        tvDest.setTextColor(colorText);
    else if (allowed > 0)
        tvDest.setTextColor(colorOn);
    else
        tvDest.setTextColor(colorOff);

    llTraffic.setVisibility(connections > 0 || sent > 0 || received > 0 ? View.VISIBLE : View.GONE);
    if (connections > 0)
        tvConnections.setText(context.getString(R.string.msg_count, connections));

    if (sent > 1024 * 1204 * 1024L || received > 1024 * 1024 * 1024L)
        tvTraffic.setText(context.getString(R.string.msg_gb, (sent > 0 ? sent / (1024 * 1024 * 1024f) : 0),
                (received > 0 ? received / (1024 * 1024 * 1024f) : 0)));
    else if (sent > 1204 * 1024L || received > 1024 * 1024L)
        tvTraffic.setText(context.getString(R.string.msg_mb, (sent > 0 ? sent / (1024 * 1024f) : 0),
                (received > 0 ? received / (1024 * 1024f) : 0)));
    else
        tvTraffic.setText(context.getString(R.string.msg_kb, (sent > 0 ? sent / 1024f : 0),
                (received > 0 ? received / 1024f : 0)));
}

From source file:android_network.hetnet.vpn_service.AdapterAccess.java

@Override
public void bindView(final View view, final Context context, final Cursor cursor) {
    // Get values
    final long id = cursor.getLong(colID);
    final int version = cursor.getInt(colVersion);
    final int protocol = cursor.getInt(colProtocol);
    final String daddr = cursor.getString(colDaddr);
    final int dport = cursor.getInt(colDPort);
    long time = cursor.getLong(colTime);
    int allowed = cursor.getInt(colAllowed);
    int block = cursor.getInt(colBlock);
    long sent = cursor.isNull(colSent) ? -1 : cursor.getLong(colSent);
    long received = cursor.isNull(colReceived) ? -1 : cursor.getLong(colReceived);
    int connections = cursor.isNull(colConnections) ? -1 : cursor.getInt(colConnections);

    // Get views//from   w  ww  . j a v a2 s. com
    TextView tvTime = (TextView) view.findViewById(R.id.tvTime);
    ImageView ivBlock = (ImageView) view.findViewById(R.id.ivBlock);
    final TextView tvDest = (TextView) view.findViewById(R.id.tvDest);
    LinearLayout llTraffic = (LinearLayout) view.findViewById(R.id.llTraffic);
    TextView tvConnections = (TextView) view.findViewById(R.id.tvConnections);
    TextView tvTraffic = (TextView) view.findViewById(R.id.tvTraffic);

    // Set values
    tvTime.setText(new SimpleDateFormat("dd HH:mm").format(time));
    if (block < 0)
        ivBlock.setImageDrawable(null);
    else {
        ivBlock.setImageResource(block > 0 ? R.drawable.host_blocked : R.drawable.host_allowed);
        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
            Drawable wrap = DrawableCompat.wrap(ivBlock.getDrawable());
            DrawableCompat.setTint(wrap, block > 0 ? colorOff : colorOn);
        }
    }

    tvDest.setText(
            Util.getProtocolName(protocol, version, true) + " " + daddr + (dport > 0 ? "/" + dport : ""));

    if (Util.isNumericAddress(daddr))
        new AsyncTask<String, Object, String>() {
            @Override
            protected void onPreExecute() {
                ViewCompat.setHasTransientState(tvDest, true);
            }

            @Override
            protected String doInBackground(String... args) {
                try {
                    return InetAddress.getByName(args[0]).getHostName();
                } catch (UnknownHostException ignored) {
                    return args[0];
                }
            }

            @Override
            protected void onPostExecute(String addr) {
                tvDest.setText(Util.getProtocolName(protocol, version, true) + " >" + addr
                        + (dport > 0 ? "/" + dport : ""));
                ViewCompat.setHasTransientState(tvDest, false);
            }
        }.execute(daddr);

    if (allowed < 0)
        tvDest.setTextColor(colorText);
    else if (allowed > 0)
        tvDest.setTextColor(colorOn);
    else
        tvDest.setTextColor(colorOff);

    llTraffic.setVisibility(connections > 0 || sent > 0 || received > 0 ? View.VISIBLE : View.GONE);
    if (connections > 0)
        tvConnections.setText(context.getString(R.string.msg_count, connections));

    if (sent > 1024 * 1204 * 1024L || received > 1024 * 1024 * 1024L)
        tvTraffic.setText(context.getString(R.string.msg_gb, (sent > 0 ? sent / (1024 * 1024 * 1024f) : 0),
                (received > 0 ? received / (1024 * 1024 * 1024f) : 0)));
    else if (sent > 1204 * 1024L || received > 1024 * 1024L)
        tvTraffic.setText(context.getString(R.string.msg_mb, (sent > 0 ? sent / (1024 * 1024f) : 0),
                (received > 0 ? received / (1024 * 1024f) : 0)));
    else
        tvTraffic.setText(context.getString(R.string.msg_kb, (sent > 0 ? sent / 1024f : 0),
                (received > 0 ? received / 1024f : 0)));
}