Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace resources in whole application #14

Closed
ozodrukh opened this issue Apr 12, 2015 · 1 comment
Closed

Replace resources in whole application #14

ozodrukh opened this issue Apr 12, 2015 · 1 comment

Comments

@ozodrukh
Copy link
Owner

Have someone experience in replacing Resources in whole application, i need to intercept getDrawable method everywhere

Testing on Genymotion, Android 4.1.1

i need some ideas how to work around

  1. Approach to wrap context when attachBaseContext method called, failed. When inflating views it doesn't works :(
  2. I found really strange behavior that the original(android) views and custom views are getting different types of Context. Cause i made efforts to set background via XML on ImageButton and get Exception, but when i create custom view extended from ImageButton it worked
    update on approach 2
    hmm, looks like if i define background as an attribute it falls, if do it by code it works

i found what is going on after all, the views calls TypedArray#getDrawable method

    public Drawable getDrawable(int index) {
        if (mRecycled) {
            throw new RuntimeException("Cannot make calls to a recycled instance!");
        }

        final TypedValue value = mValue;
        if (getValueAt(index*AssetManager.STYLE_NUM_ENTRIES, value)) {
            if (value.type == TypedValue.TYPE_ATTRIBUTE) {
                throw new RuntimeException("Failed to resolve attribute at index " + index);
            }
            return mResources.loadDrawable(value, value.resourceId, mTheme);
        }
        return null;
    }

Now i need to think how to replace loadDrawable method 😞

New plan, going to replace LayoutInflater with custom one and create custom attributes like Calligraphy did

@ozodrukh
Copy link
Owner Author

ozodrukh commented May 2, 2015

OK, i think it is unnecessary, because the library like Decor can solve this problem

@ozodrukh ozodrukh closed this as completed May 2, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant