Sunday, January 30, 2011

Difference between Android's and iPhone's Accelerometer

Today I was playing with Android's accelerometer. I am in the process of closing cocos2d-x's issue 242.

Basically I finish coding my first approach but when I run it with the test case the ball went exactly to the opposite side.
I started checking if I was sending the parameters correctly and unfortunately I was doing the right thing :(.

Since the test case was done for an iphone device I checked if the iphone used the same coordinates as Android.

I found two useful links to read about both's accelerometer:
* iphone-tutorial-reading-the-accelerometer
* SensorEvent's doc

If you check the following screens you will notice what I am talking about:





Not completely sure of what was going on I downloaded a demo app to check it gave the same values as my code. We both were sending the same coordinates so there was something different between iphone's and Android's accelerometers.

I ended up download an iphone demo app to check what were the values read. You can see the different outputs with both devices placed in the same position:




Notice the difference in the z axis value.
To fix it, it was just a matter of multiplying by -1 every value from Android's accelerometer.

Sunday, January 16, 2011

Cocos2d's Android flavors

You don't know cocos2d?

Cocos2d started as a python game framework to be used on a competition called PyWeek. The name comes from a city in Córdoba, Argentina called "Los cocos". Cocos2d was born there in a PyCamp by PyAR during 2008.

You will notice that all coocos' tests have a character named Grossini. AFAIK it comes from the PyWeek game: Grossini's Hell.

Afterwards, Ricardo Quesada, one of the creators of cocos2d, ported cocos2d to objective-c and cocos2d-iphone was born. Cocos2d-iphone is far more known that the python version and it's used in a whole bunch of top10 games in the AppStore.

Hey, what does this have to do with Android?
Well, it's just an introduction :).
For android we have two flavors.

* Cocos2d-android (Java version)
* cocos2d-x (c++ version)

I have been testing both trying to decide which one to use to build a game so I will provide some sort of pros/cons of each one.
Both versions are coded by Chinese people so it was difficult to get in touch because of the different timezones.

Android version:

Pros:
* Coded in Java.
* Excellent support. I sent an email to ZhouWeikuan with an issue and he fixed it right away.

Cons:
* Tested on my gf's ldpi device and the scrolling feels slower. I guess there is an issue with density.
* Didn't feel stable.

C++ version:

Pros:
* Multiplatform.
* Organized development with a Roadmap

Cons:
* C++ (Perhaps it's not a cons for you but my C++ skills are a bit rusty)
* Tested on my gf's ldpi device and although it said 50fps it "flickered" a lot. EDIT: This generated an issue in cocos2d-x issue tracker.
* Didn't feel stable.


My conclusions:

Both versions felt unstable. I feel that if I need to do a game I will need to look into the framework src code and fix stuff to make it work correctly but If you are doing a game...

...which does not require a good amount of FPS => java version.
...from the scratch and you will port to different platforms => c++ version.

Also, I would totally recommend to clone both versions repos and play a little with them.
It has been a fun experience for me!

Enjoy!

Monday, January 3, 2011

Review NDrive 10

Para aquellos que todavía no conocen el NDrive (cosa que no creo) es una aplicación que convierte el celular en un sistema de navegación por GPS. Actualmente está portado para Android, iPhone, Symbian y Bada.
Una de las principales ventajas respecto a los demás es que la navegación es offline (no necesita descargar los mapas de internet) y la facilidad a la hora de usarlo.
Esta semana lo estuve probando para poder hacer una buena review al respecto. Quería ver que diferencias encontraba entre los que ya había usado previamente y, de paso, seguir jugueteando con mi Nexus. Así que ahí vamos!

Funcionalidades

Además de que los mapas sean offline, la posibilidad de elegir idioma, importación y exportación de datos, etc. esta nueva versión trae consigo las siguiente funcionales:
  • Navegación Real*1
  • Rutas alternativas
  • TTS (asistencia por voz)
  • POI offline (y la posibilidad de buscarlos online)*2
  • Alertas de velocidad y camaras
  • Modo Aventrua (incluido en la v9)
  • Itinerarios
*Depende de la ubicación geográfica. 1. Actualmente no disponible en Argentina. 2. POIs online tampoco disponibles.

Está muy bien logrado lo que son las rutas alternativas. Durante el viaje se pueden calcular nuevas rutas evitando lugares del trayecto (por ejemplo, sabemos que sobre la 9 de Julio hay un piquete) o marcar directamente que existe un bloqueo a tantos metros. A su vez, si están habilitadas las alertas de velocidad, suena cada vez se pasa de la velocidad máxima de la calle, ruta o autopista (esa me la contaron). Me gustó también la posibilidad de crear itinerarios, por ejemplo, se que tengo que pasar por 3 lugares distintos y lo cargo directamente de una, sin necesidad de que cada vez que llego a un destino tener que cargar el otro destino.

Interfaz

La interfaz es realmente simple e intuitiva. Los botones son grandes, cosa que cuando estés en el auto (o lancha o avión o seas superman) no cueste navegar por la aplicación. No hay muchos botones cosa que te pierdas ni tampoco muchos submenues que haga tedioso el uso. Los colores son simpáticos y amigables. La interfaz del mapa es simple y concreta. Está bueno que los medidores puedan cambiarse y me gustó mucho la fluidez que tiene al momento de uso. Lo que no me gustó, diganme quisquilloso, es la animación de rebote en el menú principal, algunos iconos y la gráfica de los inputs. Todavía se podría mejorar un poquito la pantalla de configuración.


Usabilidad

Cómo dije anteriormente el uso es muy intuitivo. Existe como "ley" para usabilidad (web, aplicaciones, etc) que dice para acceder a un contenido no deben hacerse más 3 clicks, sino se vuelve tedioso. Esta aplicación lo cumple (salvo para el caso que estés buscando algún lugar de interés que tenés que escribir o filtrar, cosa que tiene sentido). Me gustó el hecho de que si estás buscando una calle, a medida que uno va escribiendo, vaya filtrando, y no escribir y que después diga "no existe" o algo similar. Queda muy lindo el mapa apaisado en el Nexus :)

Mapas

Estuve recorriendo la ciudad y, por ahora, no me tiró un nombre inválido. Hubo un solo lugar que no tenía mapa, el centro industrial de garín, pero la verdad que no es un lugar reconocido. Tendría que ir para el lado de Santa Fe y Pueyredón a ver si pasa la prueba del cambio de sentido de las calles. Pero en aspecto general no encontré fallas.

Resumen

Es una aplicación muy práctica y de las mejores que usé en lo que respecta a la navegación por GPS. Es muy util que la navegación sea offline ya que en nuestro querido país todavía no es estable 3g (o edge en mi caso) y aparte los contratos son comunmente por un límite MB. Tiene una importante cantidad de POIs actulizados y esperemos que próximamente cuenten con la posibilidad de buscar mediante internet.

ResizableButton

Some days ago I read Kirill Grouchnikov's blog post about custom components used in the new android market app.

Unfortunately Kirill didn't provide the src code so I did the ResizableButton code myself. Here's the src code.

The important part is the onLayout code:

@Override
protected void onLayout(boolean changed, int left, int top, int right,
int bottom) {
super.onLayout(changed, left, top, right, bottom);
final int oldWidth = getMeasuredWidth();
final int oldHeight = getMeasuredHeight();
int newWidth;
float size = mTextSize;

do {

setTextSize(size--);
measure(MeasureSpec.UNSPECIFIED, MeasureSpec.UNSPECIFIED);
newWidth = getMeasuredWidth();

} while(newWidth > oldWidth);

setMeasuredDimension(oldWidth, oldHeight);
}



Some doubts:
Kirill mentions in his blog post:


As long as the measured width is less than available width – use the left and right parameters passed to onLayout, decrease the text size and repeat.



* It says less than when I am using greater than.
* I am decreasing the font size by 1. I don't know if that is the best way to do this.

What do you guys think?