I'm trying to export the Facebook Android SDK as a JAR for use in my project.
This requires loading all the resources dynamically.
For example, I have to make changes similar to this:
//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 commented line shows the original, and the 2 lines below show the change I made to load the same resource dynamically.
The Facebook SDK declares a R.styleable resource, and I can't figure out how to load it dynamically. Here's the original 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 in attrs.xml, the following is declared:
<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, (e.g. replace the R.styleable reference) ?
I'm answering the question here incase anyone is specifically trying to also export the Facebook SDK as a jar.
I used the function described in the answer to this question: Accessing <declare-styleable> resources programatically
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();
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With