Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
This repository was archived by the owner on Feb 26, 2023. It is now read-only.
This repository was archived by the owner on Feb 26, 2023. It is now read-only.

Use ContextCompat to retrieve drawables #1422

Copy link
Copy link
@ened

Description

@ened
Issue body actions

Given I'm injecting a drawable into my fragment like that:

@DrawableRes(R.drawable.bg_button_with_stroke_orange)
protected Drawable backgroundDrawable;

Then Android Annotations generates this code:

private void init_() {
    Resources resources_ = context_.getResources();
    backgroundDrawable = resources_.getDrawable(drawable.bg_button_with_stroke_orange);
}

Which then generates this compiler warning for targetSdk=22 builds:

TheClass_.java:33: warning: [deprecation] getDrawable(int) in Resources has been deprecated
        backgroundDrawable = resources_.getDrawable(drawable.bg_button_with_stroke_orange);

Instead, AndroidAnnoations should, given the class ContextCompat is available, generate this:

private void init_() {
    backgroundDrawable = ContextCompat.getDrawable(context_, drawable.bg_button_with_stroke_orange);
}

Benefits:

  • Obviously, the compiler warning would be gone
  • More importantly, the theme will be applied to the drawable on Lollipop+ devices
Reactions are currently unavailable

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.