Building Android UIs with Custom Views

After few more months working at nights, while commuting and weekends, I managed to write a book specialised on Android Custom Views.
It covers several topics: first it explains the reasons why we need to build custom views and what are the benefits and drawbacks of using them and then, describes how to start drawing our first shapes, add animations and user interactions and do some more complex rendering or create 3D custom Views in OpenGL ES. Finally, it also shows how to share and publish our custom View and how to optimize it for performance.
It’s available as ebook and printed format and, if you’re interested, you can grab a copy in amazon:

or alternatively:
https://www.packtpub.com/application-development/building-android-uis-custom-views

http://shop.oreilly.com/product/9781785882869.do

https://www.kobo.com/us/en/ebook/building-android-uis-with-custom-views

https://www.booktopia.com.au/building-android-uis-with-custom-views-raimon-rafols-montane/prod9781785882869.html

This is a rather advanced book and requires some basic knowledge of how Android works. If you want to learn how to develop applications for Android I recommend to start with my previous book:

Learning Android Application Development

Learning Android Application Development

These last months I’ve been very busy writing a book about Android development. It covers from the very basics to application testing and using third party libraries to make your life as a developer easier.
It’s available both in ebook and printed format, if you’re interested, grab a copy!
IMG6117
PacktPub
https://www.packtpub.com/application-development/learning-android-application-development
Amazon
https://www.amazon.es/Learning-Android-Application-Development-Montane/dp/1785286110/
O’Reilly
http://shop.oreilly.com/product/9781785286117.do
Rakuten
http://books.rakuten.co.jp/rk/a635fb0c500f374a997c977adbe0d71c/
Kobo
https://store.kobobooks.com/en-us/ebook/learning-android-application-development
Booktopia
http://www.booktopia.com.au/ebooks/learning-android-application-development-raimon-rafols-montane/prod9781783553846.html

Speaking at mobile development conferences

These last months I’ve been speaking in some mobile conferences:
Mobiconf (Krakow – Poland)
Droidcon UK (London)
Droidcon NL (Amsterdam)
Here is a video recording of my presentation at Droidcon UK: (you can create a free account with skills matter if you don’t have one)
https://skillsmatter.com/skillscasts/5628-how-to-improve-android-app-performance-with-the-new-art-runtime-and-dalvik-vm-perfmatters
And here is a link to the slides, with a nice summary made by the Droidcon NL organisers:
droidconNL-002
Big thanks to Eric Lafortune for the mention in their blog! https://www.saikoa.com/blog/Mobiconf2014

BcnDevCon Presentation – Improving Java & Dalvik Code Performance

Last week I did a presentation at BcnDevCon about improving Java Code Performance. The focus of the presentation was showing some examples of compiled java sources and evaluate the performance impact of different ways of looping, string concatenation or using Java 1.5 features as autoboxing or foreach loops. According to java the performance optimizations are always left to the JVM, but we will see we can do many things to improve our code performance by knowing how the compiler works.
Some of these examples are also shown on Davlvik bytecode and performance tests are executed on both a computer and an android device. Even if Dalvik is register based and standard java bytecode is stack base in general terms what works for standard java can be also applied for Android apps.
On future posts I will explain in more detail the performance graphs and other topics I didn’t had time to include in the presentation.
Screen Shot 2013-11-15 at 00.51.53
Slides

Outcome BlackBerry 10 presentation

Last thursday I did an introduction to BlackBerry10 for Android developers. I focused most on the current limitations and possibilities of the Android Runtime of BlackBerry10 and I’ve also used some slides explaining how to convert a binary .apk file to a BlackBerry10 .bar file and sign using command line tools. There are, of course, easier tools (eclipse plugin, online repackager) but those don’t really need an explanation. At the end there is also a very quick introduction to QML/Qt and native vs cascades development.
bb_android
Something we learned about the event is people is really tired after 4 days of Mobile World Congress and gets a bit lazy if it’s raining pretty heavily. Luckily the event was live-streamed and there is a recording of the whole presentation.
Find below some links of the event:
Pictures of the event at Google+
Slides (.pdf)
Video capture of the whole presentation
Please stay tuned for the next BlackBerry Group meeting in early April.
http://www.bbdevbcn.org

Few Android applications I've been working on…

I live in a rather small and calm city called Vilanova i la Geltrú, close to Barcelona and to other touristic places like Sitges, most of the time goes completely unnoticed. What applies to tourists also applies to some terms like technology, companies, … As an example, few months ago there wasn’t that much movement about mobile technologies but now seems that, slowly, companies and individuals are talking more and more about mobile apps, mobile web, mobile marketing, … As I already said, some times people doesn’t know what they need until you show them what are the options or opportunities of this “new” technology and then a new need is created for these people.
This is, of course, a very slow process. Last time I checked we weren’t yet at Silicon Valley. In Barcelona there are lot of companies, business, technological groups and, in general, global awareness about mobile technologies. Thanks in part because of the Mobile World Congress and the Mobile Wold Capital. I started noticing graphical designers are getting some small (or not that small) mobile projects, web development companies are starting to think how to provide mobile web solutions, and even some mobile app development companies are sprouting (some of them quite promising and some others not really).
My small contribution to start creating this conscience of mobile apps and mobile technology has been creating, in my free time, some small Android applications for my hometown. Give them a try, they’re a bit different (in UX/UI than most of the standard Android apps). Here is the list:
– RSS Reader of ‘Diari de Vilanova’ (Newspaper)
https://market.android.com/details?id=com.oocit.diaridevilanova



QR Code:
qr_diarivilanova
– Fira Novembre (November Fair of Vilanova i la Geltrú)
https://market.android.com/details?id=com.oocit.firanovembre2011



QR Code:
qr_firanovembre
– Festa Major (Local Festivities of Vilanova i la Geltrú)
https://market.android.com/details?id=com.oocit.festamajor2011



QR Code:
qr_festamajor

Més aparicions a TV!

El passat dia 16 Canal Blau TV va parlar de l’aposta de Vilanova pels smartphones. Dins d’aquesta “petita” notícia va fer una refèrencia a Service2Media i a la petita aplicació que vaig desenvolupar per a llegir les notícies de l’ajuntament de Vilanova publicades al seu RSS Feed.
Aquí teniu el vídeo. Ho podeu veure a partir del minut 12:25
http://blog.rafols.org/player_flv_maxi.swf
Link al video original a TDT Garraf
Per a descarregar l’aplicatiu, només per a Android: https://market.android.com/details?id=com.oocit.ajuntamentvilanova o fent servir el següent codi:

També vaig sortir breument en el capítol 91 de La Malla tendències. Aquí us deixo el tros que parla sobre smartphones:
http://blog.rafols.org/player_flv_maxi.swf
Link al video original a TDT Garraf

Fuga de cervells a la vilanovina..

Des de fa uns dies estic intentant posar Vilanova al mapa… En alguns temes la veritat és que ja hi es i a més hi destaca.. però per exemple, amb el terreny de les aplicacions mòbils hi havia com un buit… Afortunadament no estic sol i ja hi ha gent que ha fet moltíssima feina per a potenciar les noves tecnologies aquí a casa.
Un dels meus motius principals per tornar d’Holanda era de montar una oficina de desenvolupament a Barcelona, ja que per raons d’idioma necessitem gent que sàpiga parlar català i castellà per donar suport als nostres clients espanyols (ves per on en aquest país parlant anglès no vas enlloc…) i tot comentant-ho amb en Conrad Rovira (d’A16 Sistemes informàtics) em va proposar la idea de mirar de situar l’oficina aquí a Vilanova i precisament a Neàpolis. A mi em va semblar una idea força interessant ja que a Vilanova tenim una “fuga de cervells” en petita escala. És el que te viure al costat d’una gran capital com Barcelona.
Després de reunir-me amb la gent de Neàpolis i amb l’Ajuntament de Vilanova, els vaig explicar el nostre projecte i entre tots vam fer una proposta, que vaig defensar amb els meus caps holandesos, per a situar l’oficina a Neàpolis, que començaria amb poca gent i mica en mica aniria creixent. A l’equip de direcció holandès no els va semblar malament la idea i el principal problema era, llavors, trobar o bé gent vilanovina o bé gent que estigués disposada a venir a Vilanova (allò que fem molts vilanovins d’agafar el tren a les 6.49am costa molt que passi al revés).
Ara doncs que aquest detall està arreglat només ens falta l’últim pas per a posar-hi l’oficina. Espero que ho pugui confirmar molt aviat!
Mentrestant, a nivell personal, també he estat ocupat intentant despertar aquesta curiositat per les tecnologies mòbils. Si que tenim tenim tècnics perfectament vàlids, com per exemple l’associació empresarial G15, però ens cal que els altres sectors (els que generen contingut) es donguin compte de quines ventatges i quins beneficis en podrien treure de tenir la seva marca a les butxaques d’un nombre cada cop més gran d’usuaris. Sent aquests usuaris consumidors més agressius que els “simples” usuaris d’internet (I aviat inclús en major nombre).
Com a exemples i basant-me en les idees del opendata vaig fer una aplicació molt senzilla per al Diari de Vilanova sobre terminals Android. Aquí teniu la notícia al mateix Diari:
Diari Vilanova
i el link a l’Android Market: https://market.android.com/details?id=com.oocit.diaridevilanova
Des del mateix mòbil podeu anar a la icona de Market i buscar “Vilanova” per exemple.
També, seguint la mateixa línia, vaig fer un petit lector de les notícies publicades per l’Ajuntament de Vilanova:
Android:
https://market.android.com/details?id=com.oocit.ajuntamentvilanova
Windows Phone 7:
http://redirect.zune.net/External/LaunchZuneProtocol.aspx?pathuri=navigate%3FphoneAppID%3D97cc22d3-6b7b-e011-986b-78e7d1fa76f8
Com que necessita el software Zune de Microsoft, també incloc una captura:
ajvil_wp7
Aviat les dues aplicacions estaran disponibles també per a dispositius BlackBerry i iPhone!
M’agradaria donar un parell de tocs d’atenció des d’aquí.. el primer és per a l’Ajuntament.. estaria bé que obríssiu més dades estil com té la Generalitat, així molta més gent podria fer coses (tant per mòbils com per projectes web, …) i també una mica a les universitats.. Com pot ser, realment, que enginyers a punt de treure’s el títol tinguin un nivell d’anglès pèssim o literalment inexistent? Per què l’anglès no és una prioritat, per exemple, en les carreres tècniques on la major part de documentació, exemples i eines estan en anglès? M’ha costat suor i llàgrimes fer entendre als meus caps holandesos com pot ser que els enginyers de casa, en major part, no parlin anglès. Senzillament no ho entenen… i, la veritat, jo tampoc.

Augmented Reality – II

In my last post I showed how to get position and orientation updates. In this short post (also because it’s quite simple) I’ll show how to integrate it with the camera preview.
To show the camera preview in Android it’s quite easy, just create a class that extends from SurfaceView and implements the SurfaceHolder.Callback methods:
[code lang=”java”]
package com.fuzzion.argine.viewer;
import android.content.Context;
import android.hardware.Camera;
import android.hardware.Camera.PreviewCallback;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
public class CameraView extends SurfaceView implements SurfaceHolder.Callback, PreviewCallback {
private Camera camera;
private boolean running = false;
public CameraView(Context context) {
super(context);
SurfaceHolder holder = getHolder();
holder.addCallback(this);
holder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
setFocusable(true);
requestFocus();
}
@Override
public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
if(running) {
camera.stopPreview();
}
try {
camera.setPreviewDisplay(holder);
} catch(Exception e) {}
camera.startPreview();
running = true;
camera.setPreviewCallback(this);
}
@Override
public void surfaceCreated(SurfaceHolder holder) {
camera = Camera.open();
}
@Override
public void surfaceDestroyed(SurfaceHolder holder) {
try {
if(camera != null) {
camera.stopPreview();
running = false;
camera.release();
camera = null;
}
} catch(Exception e) {}
}
@Override
public void onPreviewFrame(byte[] data, Camera camera) {
}
}
[/code]
It’s really simple, just using the startPreview() / stopPreview methods. To overlay our previous view with the camera preview we have to do that in our Activity main class:
[code lang=”java”]
cv = new CameraView(this);
tv = new TestView(this);
setContentView(cv);
addContentView(tv, new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
[/code]
We’re adding the camera preview and our previous viewer (removing the background, and changing the arrow color to white) so we can see both views at the same time.
I’ve also implemented the PreviewCallback class to receive callbacks with the camera raw data (byte[]). It might be useful some day..