lunes, 21 de noviembre de 2011

Android little trick: Transparents Backgrounds


Hi Everyone!!!!

When we want to draw the button, text or shape background color, we use the hexadecimal notation. For instance, white color will be #FFFFFF and black color will be #000000.
But if we want a transparent background (or partially transparent) we can use the hexadecimal notation to get it. To do this, we have to add two new numbers in the hexadecimal color number. The value of these two numbers will be between 00 and FF, 00 will be totally opaque and FF will be totally transparent.
For instance, if we want draw a totally opaque white the value will be #00FFFFFF, if we want to draw a totally transparent black the value will be #FF000000.
So, between 00 and FF, we can use any value, but the closer of 00, the more opaque and the closer of FF, the more transparent will be the color.


If you want a web which shows us every color in hexadecimal notation, you can use this http://html-color-codes.info/codigos-de-colores-hexadecimales/

I hope that helps!!!

See you!!!

jueves, 17 de noviembre de 2011

Lanzar la camara del móvil con nuestra aplicación Android

Hola a todos!!!!

Hoy os voy a mostrar un pequeño tutorial de cómo lanzar la cámara de nuestro móvil, a través de nuestra aplicación y recoger la foto que hemos hecho.

Primero tenemos que crear un objeto Intent para que lance la cámara de fotos, esto se hace con la siguiente línea de código: 

Intent camaraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);

Una vez creado este objeto Intent, debemos empezar una nueva actividad. Pero cómo os comentaba al principio no sólo queremos lanzar la cámara de fotos sino que queremos recoger la foto que hemos hecho. Para ello tenemos que lanzar la nueva actividad esperando que nos devuelva un dato, para ello, hacemos lo siguiente:

startActivityForResult(camaraIntent, TOMAR_FOTO);  

La variable TOMAR_FOTO será una constante que identifique la actividad de la camara de fotos.

private static final int TOMAR_FOTO = 1;  

Todo este código (excepto la constante que cómo sabrás debe ir al principio del programa) podemos meterlo, por ejemplo, en el OnClick de un botón. Así cada vez que pinchemos sobre ese botón abrirá la interfaz de la cámara de fotos para hacer la foto.

Cómo última cosa que hacer queda recoger el resultado de la cámara de fotos, que en este caso será una foto. Para ello tenemos que sobrescribir la clase onActivityResult. Se puede hacer de la siguiente manera:

@Override 
protected void onActivityResult(int requestCode, int resultCode, Intent data) {  
                if  (requestCode == TOMAR_FOTO) {
                         Bitmap imagen = (Bitmap) data.getExtras().get("data"); 
               }
 }


Como veis el resultado que devuelve la cámara es un objeto de tipo Bitmap. Bitmap es una clase de Android que sirve para manejar las imágenes. Por ejemplo, si queremos que se muestre en la interfaz de nuestra aplicación la foto que acabamos de hacer, sólo tendremos que hacer esto: 

ImageView iv_foto = (ImageView) findViewById(R.id.fotoView);
iv_foto.setImageBitmap(imagen);  


Y esto es todo, si tenéis alguna duda podéis escribir todos los comentarios que queráis.

Un saludo!!!