Example usage for android.content.res Resources getColor

List of usage examples for android.content.res Resources getColor

Introduction

In this page you can find the example usage for android.content.res Resources getColor.

Prototype

@ColorInt
@Deprecated
public int getColor(@ColorRes int id) throws NotFoundException 

Source Link

Document

Returns a color integer associated with a particular resource ID.

Usage

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

public static void populateAutoTextViews(TextView autoTextView, String autoText, int drawableId,
        Resources res) {
    autoTextView.setText(autoText);//from  w  w  w .ja v  a 2s  .  c o  m
    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.google.android.apps.iosched.util.UIUtils.java

public static void updateTimeAndLivestreamBlockUI(final Context context, long blockStart, long blockEnd,
        boolean hasLivestream, View backgroundView, TextView titleView, TextView subtitleView,
        CharSequence subtitle) {/*  w w w  .  ja  va  2s  .  co  m*/
    long currentTimeMillis = getCurrentTime(context);

    boolean past = (currentTimeMillis > blockEnd && currentTimeMillis < CONFERENCE_END_MILLIS);
    boolean present = (blockStart <= currentTimeMillis && currentTimeMillis <= blockEnd);

    final Resources res = context.getResources();
    if (backgroundView != null) {
        backgroundView.setBackgroundColor(past ? res.getColor(R.color.past_background_color) : 0);
    }

    if (titleView != null) {
        titleView.setTypeface(Typeface.SANS_SERIF, past ? Typeface.NORMAL : Typeface.BOLD);
    }

    if (subtitleView != null) {
        boolean empty = true;
        SpannableStringBuilder sb = new SpannableStringBuilder(); // TODO: recycle
        if (subtitle != null) {
            sb.append(subtitle);
            empty = false;
        }

        if (present) {
            if (sNowPlayingText == null) {
                sNowPlayingText = Html.fromHtml(context.getString(R.string.now_playing_badge));
            }
            if (!empty) {
                sb.append("  ");
            }
            sb.append(sNowPlayingText);

            if (hasLivestream) {
                if (sLivestreamNowText == null) {
                    sLivestreamNowText = Html
                            .fromHtml("&nbsp;&nbsp;" + context.getString(R.string.live_now_badge));
                }
                sb.append(sLivestreamNowText);
            }
        } else if (hasLivestream) {
            if (sLivestreamAvailableText == null) {
                sLivestreamAvailableText = Html.fromHtml(context.getString(R.string.live_available_badge));
            }
            if (!empty) {
                sb.append("  ");
            }
            sb.append(sLivestreamAvailableText);
        }

        subtitleView.setText(sb);
    }
}

From source file:com.github.michalbednarski.intentslab.browser.ComponentInfoFragment.java

static CharSequence dumpIntentFilter(IntentFilter filter, Resources res, boolean isBroadcast) {
    FormattedTextBuilder ftb = new FormattedTextBuilder();
    int tagColor = res.getColor(R.color.xml_tag);
    int attributeNameColor = res.getColor(R.color.xml_attr_name);
    int attributeValueColor = res.getColor(R.color.xml_attr_value);
    int commentColor = res.getColor(R.color.xml_comment);
    final String protectedComment = " <!-- " + res.getString(R.string.broadcast_action_protected_comment)
            + " -->";

    ftb.appendColoured("\n<intent-filter>", tagColor);

    for (int i = 0, j = filter.countActions(); i < j; i++) {
        final String action = filter.getAction(i);
        ftb.appendColoured("\n  <action", tagColor);
        ftb.appendColoured(" a:name=", attributeNameColor);
        ftb.appendColoured("\"" + action + "\"", attributeValueColor);
        ftb.appendColoured(">", tagColor);

        if (isBroadcast && Utils.isProtectedBroadcast(action)) {
            ftb.appendColoured(protectedComment, commentColor);
        }//from   w  w  w  . ja  v a  2s .  c  o  m
    }

    for (int i = 0, j = filter.countCategories(); i < j; i++) {
        ftb.appendColoured("\n  <category", tagColor);
        ftb.appendColoured(" a:name=", attributeNameColor);
        ftb.appendColoured("\"" + filter.getCategory(i) + "\"", attributeValueColor);
        ftb.appendColoured(">", tagColor);
    }

    for (int i = 0, j = filter.countDataSchemes(); i < j; i++) {
        ftb.appendColoured("\n  <data", tagColor);
        ftb.appendColoured(" a:scheme=", attributeNameColor);
        ftb.appendColoured("\"" + filter.getDataScheme(i) + "\"", attributeValueColor);
        ftb.appendColoured(">", tagColor);
    }

    for (int i = 0, j = filter.countDataAuthorities(); i < j; i++) {
        IntentFilter.AuthorityEntry authority = filter.getDataAuthority(i);
        ftb.appendColoured("\n  <data", tagColor);
        ftb.appendColoured(" a:host=", attributeNameColor);
        ftb.appendColoured("\"" + authority.getHost() + "\"", attributeValueColor);
        if (authority.getPort() != -1) {
            ftb.appendColoured(" a:port=", attributeNameColor);
            ftb.appendColoured("\"" + authority.getPort() + "\"", attributeValueColor);
        }
        ftb.appendColoured(">", tagColor);
    }

    for (int i = 0, j = filter.countDataPaths(); i < j; i++) {
        PatternMatcher pathMatcher = filter.getDataPath(i);
        int type = pathMatcher.getType();
        ftb.appendColoured("\n  <data", tagColor);
        ftb.appendColoured(
                " a:path"
                        + (type == PatternMatcher.PATTERN_LITERAL ? ""
                                : type == PatternMatcher.PATTERN_PREFIX ? "Prefix"
                                        : type == PatternMatcher.PATTERN_SIMPLE_GLOB ? "Pattern" : "[unknown]")
                        + "=",
                attributeNameColor);
        ftb.appendColoured("\"" + pathMatcher.getPath() + "\"", attributeValueColor);
        ftb.appendColoured(">", tagColor);
    }

    for (int i = 0, j = filter.countDataTypes(); i < j; i++) {
        String dataType = filter.getDataType(i);
        if (!dataType.contains("/")) {
            // IntentFilter for partial types don't store "/*" at end
            // e.g. "image" instead of "image/*".
            // We display it in full form here
            dataType += "/*";
        }
        ftb.appendColoured("\n  <data", tagColor);
        ftb.appendColoured(" a:mimeType=", attributeNameColor);
        ftb.appendColoured("\"" + dataType + "\"", attributeValueColor);
        ftb.appendColoured(">", tagColor);
    }

    ftb.appendColoured("\n</intent-filter>", tagColor);
    return ftb.getText();
}

From source file:com.andrewshu.android.reddit.common.Common.java

public static void setTextColorFromTheme(int theme, Resources resources, TextView... textViews) {
    int color;/*from  w w w  .j a  v a  2  s. co m*/
    if (Util.isLightTheme(theme))
        color = resources.getColor(R.color.reddit_light_dialog_text_color);
    else
        color = resources.getColor(R.color.reddit_dark_dialog_text_color);
    for (TextView textView : textViews)
        textView.setTextColor(color);
}

From source file:com.android.calendar.Event.java

/**
 * Adds all the events from the cursors to the events list.
 *
 * @param events The list of events//  w  w w. j a va 2  s. c om
 * @param cEvents Events to add to the list
 * @param context
 * @param startDay
 * @param endDay
 */
public static void buildEventsFromCursor(ArrayList<Event> events, Cursor cEvents, Context context, int startDay,
        int endDay) {
    if (cEvents == null || events == null) {
        Log.e(TAG, "buildEventsFromCursor: null cursor or null events list!");
        return;
    }

    int count = cEvents.getCount();

    if (count == 0) {
        return;
    }

    Resources res = context.getResources();
    mNoTitleString = res.getString(R.string.no_title_label);
    mNoColorColor = res.getColor(R.color.event_center);
    // Sort events in two passes so we ensure the allday and standard events
    // get sorted in the correct order
    cEvents.moveToPosition(-1);
    while (cEvents.moveToNext()) {
        Event e = generateEventFromCursor(cEvents);
        if (e.startDay > endDay || e.endDay < startDay) {
            continue;
        }
        events.add(e);
    }
}

From source file:com.linkbubble.util.Util.java

static public void showThemedDialog(Dialog dialog) {
    dialog.show();/*from  w w  w  . j  a  v  a2  s  .  co m*/

    Resources resources = dialog.getContext().getResources();
    int color = resources.getColor(
            Settings.get().getDarkThemeEnabled() ? R.color.color_primary_bright : R.color.color_primary);

    int dividerId = resources.getIdentifier("android:id/titleDivider", null, null);
    if (dividerId > 0) {
        View divider = dialog.findViewById(dividerId);
        if (divider != null) {
            divider.setBackgroundColor(color);
        }
    }

    int titleTextViewId = resources.getIdentifier("android:id/alertTitle", null, null);
    if (titleTextViewId > 0) {
        TextView textView = (TextView) dialog.findViewById(titleTextViewId);
        if (textView != null) {
            textView.setTextColor(color);
        }
    }
}

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

public static Bitmap getLargeIcon(int iconResourceId, Resources resources) {
    Bitmap icon = BitmapFactory.decodeResource(resources, iconResourceId);

    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP)
        return icon;

    int iconSize = ControlHelper.dpToPx(40, resources);
    int innerIconSize = ControlHelper.dpToPx(24, resources);
    icon = Bitmap.createScaledBitmap(icon, iconSize, iconSize, false);
    Bitmap largeIcon = icon.copy(Bitmap.Config.ARGB_8888, true);
    icon = Bitmap.createScaledBitmap(icon, innerIconSize, innerIconSize, false);

    Canvas canvas = new Canvas(largeIcon);
    int center = canvas.getHeight() / 2;
    Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
    paint.setColor(resources.getColor(R.color.accent));
    canvas.drawCircle(center, center, center, paint);
    paint.setColor(Color.WHITE);/*  w  ww. j  av a  2s. c  o  m*/
    canvas.drawBitmap(icon, center - icon.getWidth() / 2, center - icon.getWidth() / 2, paint);

    return largeIcon;
}

From source file:com.gdgdevfest.android.apps.devfestbcn.ui.PlusStreamRowViewBinder.java

public static ImageLoader getPlusStreamImageLoader(FragmentActivity activity, Resources resources) {
    DisplayMetrics metrics = resources.getDisplayMetrics();
    int largestWidth = metrics.widthPixels > metrics.heightPixels ? metrics.widthPixels : metrics.heightPixels;

    // Create list of placeholder drawables (this ImageLoader requires two different
    // placeholder images).
    ArrayList<Drawable> placeHolderDrawables = new ArrayList<Drawable>(2);
    placeHolderDrawables.add(PLACEHOLDER_USER_IMAGE, resources.getDrawable(drawable.person_image_empty));
    placeHolderDrawables.add(PLACEHOLDER_MEDIA_IMAGE,
            new ColorDrawable(resources.getColor(R.color.plus_empty_image_background_color)));

    // Create ImageLoader instance
    return new ImageLoader(activity, placeHolderDrawables).setMaxImageSize(largestWidth);
}

From source file:com.nickandjerry.dynamiclayoutinflator.DynamicLayoutInflator.java

public static int parseColor(View view, String text) {
    if (text.startsWith("@color/")) {
        Resources resources = view.getResources();
        return resources.getColor(resources.getIdentifier(text.substring("@color/".length()), "color",
                view.getContext().getPackageName()));
    }/*www  .  ja  v a  2 s  .c o m*/
    if (text.length() == 4 && text.startsWith("#")) {
        text = "#" + text.charAt(1) + text.charAt(1) + text.charAt(2) + text.charAt(2) + text.charAt(3)
                + text.charAt(3);
    }
    return Color.parseColor(text);
}

From source file:com.fastbootmobile.encore.utils.Utils.java

public static void showCurrentSongOverflow(final Context context, final View parent, final Song song,
        final boolean showArtist) {
    PopupMenu popupMenu = new PopupMenu(context, parent);
    popupMenu.inflate(R.menu.queue_overflow);
    if (song.getAlbum() == null) {
        Log.d(TAG, "No album information, removing album options");

        // This song has no album information, hide the entries
        Menu menu = popupMenu.getMenu();
        menu.removeItem(R.id.menu_add_album_to_queue);
        menu.removeItem(R.id.menu_open_album);
    }//from  ww w .  ja  v  a2  s. c o  m

    if (!showArtist) {
        Menu menu = popupMenu.getMenu();
        menu.removeItem(R.id.menu_open_artist);
    }

    popupMenu.show();

    popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(MenuItem menuItem) {
            final ProviderAggregator aggregator = ProviderAggregator.getDefault();

            switch (menuItem.getItemId()) {
            case R.id.menu_open_album:
                final Resources res = context.getResources();
                Intent intent = AlbumActivity.craftIntent(context,
                        ((BitmapDrawable) res.getDrawable(R.drawable.album_placeholder)).getBitmap(),
                        song.getAlbum(), song.getProvider(),
                        res.getColor(R.color.default_album_art_background));
                context.startActivity(intent);
                break;

            case R.id.menu_open_artist:
                intent = ArtistActivity.craftIntent(context, null, song.getArtist(), song.getProvider(),
                        context.getResources().getColor(R.color.default_album_art_background));
                context.startActivity(intent);
                break;

            case R.id.menu_add_album_to_queue:
                PlaybackProxy.queueAlbum(aggregator.retrieveAlbum(song.getAlbum(), song.getProvider()), false);
                Toast.makeText(context, R.string.toast_album_added_to_queue, Toast.LENGTH_SHORT).show();
                break;

            case R.id.menu_add_to_playlist:
                PlaylistChooserFragment fragment = PlaylistChooserFragment.newInstance(song);
                if (context instanceof FragmentActivity) {
                    FragmentActivity act = (FragmentActivity) context;
                    fragment.show(act.getSupportFragmentManager(), song.getRef());
                } else {
                    throw new IllegalArgumentException("Context must be an instance of FragmentActivity");
                }
                break;

            default:
                return false;
            }
            return true;
        }
    });
}