Example usage for android.widget TextView getResources

List of usage examples for android.widget TextView getResources

Introduction

In this page you can find the example usage for android.widget TextView getResources.

Prototype

public Resources getResources() 

Source Link

Document

Returns the resources associated with this view.

Usage

From source file:Main.java

public static void setTextColor(int color, TextView... views) {
    for (TextView view : views) {
        view.setTextColor(view.getResources().getColor(color));
    }//from  w  w  w.  j  ava2 s.  c o  m
}

From source file:Main.java

public static void setValue(TextView v, int resid) {
    String titls = v.getResources().getString(resid);
    v.setText(titls);/*ww w  . j av  a  2s .  c  o m*/
}

From source file:Main.java

public static void setTextViewAttributes(TextView textView, int size, int colorRes) {
    textView.setTextSize(TypedValue.COMPLEX_UNIT_PX, size);
    textView.setTextColor(textView.getResources().getColor(colorRes));
}

From source file:io.github.guaidaodl.espresso.CustomViewMatchers.java

/**
 * Returns a matcher that matches the descendant of {@link TextView} that is displaying
 * text with the color associated with given color resource id.
 *
 * @param colorRes the color resource which the text view's text should be.
 *//*ww w .  ja  v  a 2s.c  om*/
@NonNull
public static Matcher<View> withTextColor(@ColorRes final int colorRes) {
    return new BoundedMatcher<View, TextView>(TextView.class) {
        private Integer expectedColor = -1;
        private String expectedColorName = null;

        @Override
        public void describeTo(Description description) {
            description.appendText("with color from resource id : ").appendValue(colorRes);

            if (expectedColorName != null) {
                description.appendText("[").appendText(expectedColorName).appendText("]");
            }

            if (expectedColor != -1) {
                description.appendValue(" value: ").appendText(ColorFormat.toHexFormat(expectedColor));

            }
        }

        @Override
        protected boolean matchesSafely(TextView textView) {
            if (expectedColor == -1) {
                try {
                    //noinspection deprecation
                    expectedColor = textView.getResources().getColor(colorRes);
                    expectedColorName = textView.getResources().getResourceEntryName(colorRes);
                } catch (Resources.NotFoundException ignore) {
                }
            }

            int actualColor = textView.getCurrentTextColor();

            return expectedColor != null && expectedColor == actualColor;
        }
    };
}

From source file:nl.sebastiaanschool.contact.app.gui.GrabBag.java

/**
 * Apply a vector drawable, using backwards compatibility as needed. This throws an exception
 * if your {@code resId} is actually a bitmap drawable.
 *//*from  w  ww. j a v  a2  s  .c  o m*/
public static void applyVectorDrawableLeft(TextView view, @DrawableRes int resId) {
    if (Build.VERSION.SDK_INT >= 21) {
        view.setCompoundDrawablesRelativeWithIntrinsicBounds(resId, 0, 0, 0);
        view.getCompoundDrawablesRelative()[0].setTint(ResourcesCompat.getColor(view.getResources(),
                R.color.sebastiaan_blue, view.getContext().getTheme()));
    } else {
        final Context context = view.getContext();
        final Drawable drawable = loadVectorDrawable(context, resId);
        if (Build.VERSION.SDK_INT >= 17) {
            view.setCompoundDrawablesRelativeWithIntrinsicBounds(drawable, null, null, null);
        } else {
            view.setCompoundDrawablesWithIntrinsicBounds(drawable, null, null, null);
        }
    }
}

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

static public void setTextViewDrawable(TextView tv, int resid) {
    String key = String.format(Locale.US, "%d", resid);
    Drawable d = getDrawableFromCache(key);
    if (d == null) {
        Resources res = tv.getResources();
        d = ResourcesCompat.getDrawable(res, resid, null);
        putDrawableIntoCache(key, d);/*  w  ww.j  a v  a2  s. c o  m*/
    }
    setTextViewDrawable(tv, d.mutate());
}

From source file:org.comixwall.pffw.Utils.java

/**
 * Update the status image and text.//from  w  ww  . j  a v a2 s .co  m
 * Used by process status views.
 *
 * @param status "0" for running, "1" for stopped.
 * @param iv ImageView to update.
 * @param tv TextView to update.
 * @param proc Process name.
 */
static void updateStatusViews(String status, ImageView iv, TextView tv, String proc) {
    int image;
    int text;

    if (status.equals("0")) {
        image = R.drawable.pass;
        text = R.string.proc_is_running;
    } else {
        image = R.drawable.block;
        text = R.string.proc_is_not_running;
    }

    iv.setImageResource(image);
    tv.setText(String.format(tv.getResources().getString(text), proc));
}

From source file:org.runbuddy.tomahawk.adapters.ViewHolder.java

private static void setTextViewEnabled(TextView textView, boolean enabled, boolean isSecondary) {
    if (textView != null && textView.getResources() != null) {
        int colorResId;
        if (enabled) {
            if (isSecondary) {
                colorResId = R.color.secondary_textcolor;
            } else {
                colorResId = R.color.primary_textcolor;
            }//from w  ww . j  a v a 2  s .c  o  m
        } else {
            colorResId = R.color.disabled;
        }
        textView.setTextColor(textView.getResources().getColor(colorResId));
    }
}

From source file:org.tomahawk.tomahawk_android.utils.AdapterUtils.java

private static TextView setTextViewEnabled(TextView textView, boolean enabled, boolean isSecondary,
        boolean isHighlighted) {
    if (textView != null && textView.getResources() != null) {
        int colorResId;
        if (enabled) {
            if (isSecondary) {
                if (isHighlighted) {
                    colorResId = R.color.secondary_textcolor_inverted;
                } else {
                    colorResId = R.color.secondary_textcolor;
                }/*from  ww  w .  j a  v a 2s .c  o  m*/
            } else {
                if (isHighlighted) {
                    colorResId = R.color.primary_textcolor_inverted;
                } else {
                    colorResId = R.color.primary_textcolor;
                }
            }
        } else {
            colorResId = R.color.disabled;
        }
        textView.setTextColor(textView.getResources().getColor(colorResId));
    }
    return textView;
}

From source file:net.peterkuterna.android.apps.devoxxsched.util.UIUtils.java

/**
 * Sets the color of a session title./*from w w  w.  ja v a 2 s .co  m*/
 * 
 * @param blockStart
 * @param blockEnd
 * @param title
 * @param subtitle
 */
public static void setSessionTitleColor(long blockStart, long blockEnd, TextView title, TextView subtitle) {
    long currentTimeMillis = System.currentTimeMillis();
    int colorId = R.color.body_text_1;
    int subColorId = R.color.body_text_2;

    if (currentTimeMillis > blockEnd && currentTimeMillis < CONFERENCE_END_MILLIS) {
        colorId = subColorId = R.color.body_text_disabled;
    }

    final Resources res = title.getResources();
    title.setTextColor(res.getColor(colorId));
    subtitle.setTextColor(res.getColor(subColorId));
}