Obtain styleable fields at runtime

Ususally, when we want to get some “R” attributes at runtime, we use the Resources getIdentifier method, which is useful for getting strings, drawables and ids at runtime. Unfortunately this method cannot be used to get the styleable fields. However, using java reflections, there’s another way to solve the problem. With this snippet you can get styleable fields at runtime in your code:

[cce]public static final <T> T getFieldFromStyleable( Context context, String name ) {
try {
// use reflection to access the resource class
Field field = Class.forName( context.getPackageName() + “.R$styleable” ).getField( name );
if ( null != field ) {
return (T) field.get( null );
}
} catch ( Throwable t ) {
t.printStackTrace();
}
return null;
}[/cce]

Which can be used in this way:
[cce]int[] array = getFieldFromStyleable( context, “MyListView” );
array = context.obtainStyledAttributes( attrs, styleableArray, defStyle, 0 );[/cce]

Compile skia for android on Mac Lion

Some time ago I started to look at skia as possible solution for graphics 2D editing for a native android project I was developing.
Well, even if skia is part of the android system and it’s used everywhere by android itself, trying to include skia in my project was quite an hell..
Looking for resources I just found old examples and tips, and every try was just a failure.. but since android uses skia internally to do graphics operations I decided to look into the android project.

After downloading the skia module from the android git repository I just realized it couldn’t be compiled by itself because it has external dependencies. So next step was to download and compile the whole android source code. Easy task? not at all, at least if you’re on a mac running Lion!

At the end I managed to compile everything and build the skia module as static module, in this way now my project can link the skia library and include correctly the skia headers.

Ok, I don’t have the whole procedure step by step here, first of all because it depends on the android version you’re going to compiled, second and most important because I didn’t write down all the steps 🙂 So this is more a sort of list of notes about compiling android on Lion and a reminder for myself too. ( I was trying to compile android 2.2 using “generic-user” as lunch configuration )

Build Android: http://source.android.com/source/initializing.html

To get rid of clearsilver errors: http://code.google.com/p/android/issues/detail?id=993#c27

Java 1.5 version complaining: http://wiki.oneswarm.org/index.php/OS_X_10.6_Snow_Leopard

Well, the first time you’ll try to “make” everything probably you’ll get this error:

[cc]
./external/elfutils/config-compat-darwin.h:42: error: static declaration of ‘strnlen’ follows non-static declaration
[/cc]

modify ./external/elfutils/config-compat-darwin.h.
replace:
[cc lang=”c”]
static inline size_t strnlen (const char *__string, size_t __maxlen)
{
int len = 0;
while (__maxlen– && *__string++)
len++;
return len;
}
[/cc]

with:
[cc lang=”c”]
#if 0
static inline size_t strnlen (const char *__string, size_t __maxlen)
{
int len = 0;
while (__maxlen– && *__string++)
len++;
return len;
}
#endif
[/cc]

Well, at the end of the process I just edited the Android.mk makefile into external/skia adding a new entry for BUILD_STATIC_LIBRARY and the next command was simply:

[cc]mmm external/skia[/cc]

which produced the required libskia.a file to be linked in my project.

Java 6 Update 10 breaks Flex compiler!

I just want to share this problem I found so maybe someone can save some time..

Today while surfing the net I received a notification of an update of my Java installation to the Update 10 in order to see correctly the contents of that site.. bla bla bla..

Sometime later I switched to Flex and at the first execution of my ant script for compiling a flex project I suddenly received this beautiful error:
[exec] Error: java/security/MessageDigest
[exec] java.lang.NoClassDefFoundError: java/security/MessageDigest
[exec] at java.io.ObjectStreamClass.computeDefaultSUID(Unknown Source)
[exec] at java.io.ObjectStreamClass.access$100(Unknown Source)
[exec] at java.io.ObjectStreamClass$1.run(Unknown Source)
[exec] at java.security.AccessController.doPrivileged(Native Method)
[exec] at java.io.ObjectStreamClass.getSerialVersionUID(Unknown Source)
[exec] at java.io.ObjectStreamClass.initNonProxy(Unknown Source)
[exec] at java.io.ObjectInputStream.readNonProxyDesc(Unknown Source)
[exec] at java.io.ObjectInputStream.readClassDesc(Unknown Source)
[exec] at java.io.ObjectInputStream.readNonProxyDesc(Unknown Source)
[exec] at java.io.ObjectInputStream.readClassDesc(Unknown Source)
[exec] at java.io.ObjectInputStream.readOrdinaryObject(Unknown Source)
[exec] at java.io.ObjectInputStream.readObject0(Unknown Source)
[exec] at java.io.ObjectInputStream.readObject(Unknown Source)
[exec] at flex.util.SerializedTemplateFactory.load(SerializedTemplateFactory.java:30)
[exec] at flex2.compiler.util.VelocityManager.getTemplate(VelocityManager.java:162)
[exec] at flex2.compiler.util.VelocityManager.getTemplate(VelocityManager.java:151)
[exec] at flex2.compiler.util.VelocityManager.getTemplate(VelocityManager.java:137)
[exec] at flex2.compiler.as3.genext.GenerativeSecondPassEvaluator.generateSupportCode(GenerativeSecondPassEvaluator.java:256)
[exec] at flex2.compiler.as3.genext.GenerativeSecondPassEvaluator.modifySyntaxTree(GenerativeSecondPassEvaluator.java:355)
[exec] at flex2.compiler.as3.binding.BindableSecondPassEvaluator.evaluate(BindableSecondPassEvaluator.java:102)
[exec] at macromedia.asc.parser.ClassDefinitionNode.evaluate(ClassDefinitionNode.java:106)
[exec] at flash.swf.tools.as3.EvaluatorAdapter.evaluate(EvaluatorAdapter.java:338)
[exec] at macromedia.asc.parser.StatementListNode.evaluate(StatementListNode.java:60)
[exec] at flash.swf.tools.as3.EvaluatorAdapter.evaluate(EvaluatorAdapter.java:923)
[exec] at macromedia.asc.parser.ProgramNode.evaluate(ProgramNode.java:80)
[exec] at flex2.compiler.as3.genext.GenerativeExtension.parse2(GenerativeExtension.java:114)
[exec] at flex2.compiler.as3.Compiler.parse2(Compiler.java:386)
[exec] at flex2.compiler.API.parse2(API.java:2390)
[exec] at flex2.compiler.API.parse2(API.java:2348)
[exec] at flex2.compiler.API.batch2(API.java:375)
[exec] at flex2.compiler.API.batch(API.java:1117)
[exec] at flex2.compiler.API.compile(API.java:1290)
[exec] at flex2.compiler.API.compile(API.java:1210)
[exec] at flex2.tools.Compc.compc(Compc.java:158)
[exec] at flex2.tools.Compc.main(Compc.java:41)

so I tried also to compile another project before go crazy, but I got this another java funny error, which was more or less unreadable as the previous one!

Fortunately I remembered the update I did of Java! And in fact after remove that update everything worked again!

Red5, first thoughts

As I promised myself, I started to spend some of the time in testing red5 since I’ve read the about the 0.6RC1 release.
Unfortunately I wasn’t able to run it on my Windows Vista so I try it on an older Windows XP. Once unpacked the installer I first tested some of the example applications boundled, everything worked fine.. cool, nice, great project indeed!

But then I wanted to migrate one of my FCS2 projects to Red5 in order to test “the real world”.
Ok, I need to write in Java? (there’s Python support, but it’s Jython) Cool.. I never seen Java, I thought it was a monster with eight heads 🙂
Got the first Java editor I found on the net, IntelliJIdea (what a wonderful editor indeed! much expensive, but really cool), and started with headache..
But at least, for a newbie like me, it seems to me like editing ActionScript3 files, so it wasn’t so difficult to make things running.
I’m still “trying” to re-write the application (with minor changes also in the flash files) but I managed to make remote sharedobjects, streams and remote calls running like in the FCS2 original application and I’m so happy 🙂

I just encounter a couple of time a Windows blue screen error while getting webcam streams (I need to make a snapshot next time) and some human unreadable java exceptions (It’s indeed a my fault) but I think it was a positive beginning after all.
Great great compliments to red5 developers!

Which documentator for AS2?

I was searching for a valid AS documentation tool…
I have tested the AS2Doc trial but it doesn’t parse correctly my classes.
Also ZenDoc seems to be a valid alternative, also because it’s written in PHP, but it skip all the uncommented methods 🙁
NaturalDocs probably is the best choice, for me, but it doesn’t support standard javadoc comments
Acid gives me python errors while parsing the packages and the python code is quite unreadable.
BLDoc is really promising, but it’s still in beta
Probably the best program I found is as2api, which creates a standard javadoc html output. The only thing is that it doesn’t seem to have an option to allow documentation for private methods
Did you have experience with some of these tools, or someone else I didn’t tested?
Which one do you currently use?