How to dynamically load R.styleable resource?

I am trying to export the Android Android SDK as a JAR for use in my project.

This requires loading all resources dynamically.

For example, I need to make the following changes:

//findViewById(R.id.com_facebook_login_activity_progress_bar).setVisibility(View.VISIBLE);
int viewID = getResources().getIdentifier("com_facebook_login_activity_progress_bar", "id", getPackageName());
findViewById(viewID).setVisibility(View.VISIBLE);

The marked line shows the original, and the two lines below show the change I made to dynamically load the same resource.

The Facebook SDK announces the R.styleable resource, and I cannot figure out how to load it dynamically. Here is the source code:

private void parseAttributes(AttributeSet attrs) {
    TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.com_facebook_profile_picture_view);
    setPresetSize(a.getInt(R.styleable.com_facebook_profile_picture_view_preset_size, CUSTOM));
    isCropped = a.getBoolean(R.styleable.com_facebook_profile_picture_view_is_cropped, IS_CROPPED_DEFAULT_VALUE);
    a.recycle();
}

Then the following is declared in attrs.xml:

    <declare-styleable name="com_facebook_profile_picture_view">
        <attr name="preset_size">
            <!-- Keep in sync with constants in ProfilePictureView -->
            <enum name="small" value="-2" />
            <enum name="normal" value="-3" />
            <enum name="large" value="-4" />
        </attr>
        <attr name="is_cropped" format="boolean" />
    </declare-styleable>

How can I load this resource dynamically (for example, replace the R.styleable link)?

+5
source share
1 answer

, - SDK Facebook .

, : < declare-styleable >

private void parseAttributes(AttributeSet attrs) {
    int attrArray[] = StyleableHelper.getResourceDeclareStyleableIntArray(getContext(), "com_facebook_profile_picture_view");
    //TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.com_facebook_profile_picture_view);
    TypedArray a = getContext().obtainStyledAttributes(attrs, attrArray);

    setPresetSize(a.getInt(0, CUSTOM));
    isCropped = a.getBoolean(1, IS_CROPPED_DEFAULT_VALUE);
    //setPresetSize(a.getInt(R.styleable.com_facebook_profile_picture_view_preset_size, CUSTOM));
    //isCropped = a.getBoolean(R.styleable.com_facebook_profile_picture_view_is_cropped, IS_CROPPED_DEFAULT_VALUE);
    a.recycle();
}
+3

All Articles