toggle Cinema 23 Aug 2010

Display Notifications on Android SDK Posted by Insane in Java, android | No responses

android

During my journey of discover in this amazing platform I had the need of display several types of messages in the device in order to let know the user that something was actually happening in background and that black window was all on purpose. So I decide to gather all this types of notifications in this post and show their implementations, let´s get started.

Android SDK offers 3 main types of notifications that could perfectly cover all your needs.

  • Alert Dialogs.
  • Notifications
  • Toats

Alert Dialogs.

This is the classic way and you´ve seen it before. It´s about to show a small prompt with a message on it, for this type of notification you can construct an AlertDialog by using Builder whose methods all return the instance of itself, so you can chain a serie of calls togheter in line (This pattern is also kwnow as Prototype),  take a look to the next line:

new AlertDialog.Builder(this).setTitle("You").setMessage("Suck at photoshop").setPositiveButton("OK", null).show();

So,what we have here:

There´s a call to the method Builder of AlertDialog whose return an instance of the builder AlertDialog.Builder(context), context is the contexts on wich your alert will show. in this case the current scope this.

  • setTitle(String title) allows us to, well you know.
  • setMessage(String message) method allows us to specify the content of the alert.
  • setNeutralButton(String title, OnClickListener) creates a button with the specified title and optionally you can specify a second argument, that would be the handler for all those events that happend when the button is clicked ( for instance you could try to perform some check before close the window ya know? )

Last thing, you can call any of the three methods availables setPositiveButton,setNeutralButton and setNegativeButton before call show method,these methods specify the type of button(s) that will be displayed.

  • setPositiveButton – Describes an intended action or a confirmation, e.g. “Save” or “Yes”.
  • setNeutralButton  – Describes a “neutral” action such as “Close”.
  • setNegativeButton – Describes a cancellation or simply a “No”.

android alert

Now, we can make our alert baby a little more cute wih an icon.

The method is setIcon(int resourceId) wich can be called in any order of your chain call, resourceId referes to a drawable reference of your proyect, take the following line as an example:

new AlertDialog.Builder(this).setTitle("You").setMessage("Suck at photoshop").setIcon(R.drawable.icon).setPositiveButton("OK", null).show();

notification_android_icon

For a full list of builder methods, click here (API Docs)

Notifications

Notifications may look a litle bit complex but they´re not, so why don´t I give you first the code and the explain what does it means?

static final int NOTIFICATION_ID = 1593;

NotificationManager notifManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
Notification note = new Notification(R.drawable.icon, "New E-mail", System.currentTimeMillis());

PendingIntent intent = PendingIntent.getActivity(this, 0, new Intent(this, Main.class), 0);
note.setLatestEventInfo(this, "New E-mail", "You have one unread message.", intent);
notifManager.notify(NOTIF_ID, note);

Let me explain the flow of this by showing you this image:

notification

  • NotificationManager can send out – of course – Notifications objects,  so with the first of all what we do it´s create an instance of the device server and cast it as NotificationManager.
  • Next line, we create the notification Notification(int icon, CharSequence tickerText, long when) — constructs a Notification object with the
  • information needed to have a status bar icon without the standard expanded view. There´s also 2 different constructors so you can just call it
  • without arguments Notification() ( setted all to 0) and Notification(Parcel parcel) wich unflatten the notifdication from a parcel object.

Next line, creates an PendingIntent that will be the “callback” when the user hits the notification (in this case we’re having it start the MainActivity of the app)

PendingIntent : “By giving a PendingIntent to another application, you are granting it the right to perform the operation you have specified as if the other application was yourself (with the same permissions and identity)”

Now, Using setLatestEventInfo(Context context, CharSequence contentTitle, CharSequence contentText, PendingIntent contentIntent) we can specify a title, a message, and the Intent previously created that will be invoked when users click on the notification in the expanded

And then our notifManager will notify – :P the notification – the first argument is the constant to store and ID and can keep track of the notification, the value could be any int number that you wish.

Things you need to know when working with Notifications.

  • The notification is not cleared after the user clicks on it, you need to call notifManager.cancel(NOTIF_ID);

Toats

These are my favorites ones, because their simplicity and non obstrusive way of showing. In order to create a Toast, you need to create an object with one of the makeText() methods. This method takes three parameters: the application Context, the text message, and the duration for the toast. It returns a properly initialized Toast object.

Context context = getApplicationContext();//or this
CharSequence text = "Hello toast!";
int duration = Toast.LENGTH_SHORT;
Toast.makeText(context, text, duration).show();

toats android

  • Share/Bookmark
toggle Cinema 28 Jul 2010

andshort – acortador de direcciones y bookmarks [opensource,acortadores] Posted by Insane in Projects | No responses

Andshort es un acortador de direcciones URL opensource que nace después del estallido de acortadores gracias en gran medida a twitter.
He venido retrasando la liberación de este proyecto personal ya casi un año por bastante falta de tiempo y creo que podría faltar aún más antes de que viera la luz , si no lo hago ahora sera eternamente beta. La idea desde el principio fue muy clara, crear el acortador de direcciones Opensource definitivo \\O_O//.
Características técnicas.
PHP (OOP) , Smarty.
MYSQL 5.x
Optimizado para Apache 2.x
El front tiene su propio core en JS, Jquery tambien es usado.
Minifier de CSS & JS con YUI / ShrinkSafe / CLOSURE
Importador de marcadores Delicious , Google bookmarks y RSS incluido.
REST API , aun falta la documentación pero de momento la API permite acortar direcciones y proporciona datos sobre urls y usuarios.
Google gadget.
Widget para WordPress ( en progreso )
Addon para firefox ( en progreso )
Características principales
Opensource baby!! (MIT License)
Facil de usar.
Fácil de instalar.
Estadísticas detalladas de acceso.
Permite generar ingresos mediante Adsense.
Compartir enlaces por usando OAUTH en fb y tw.
Organización y administración de enlaces
Así que aquí esta la invitación a colaborar en este proyecto. Si tienes dudas,comentarios y/o criticas constructivas tweet me up > @insane
Demo > zik.bz , diseñado y maquetado por el gran @infectedfx
API > Si quieres probar la API y cuentas con Tweetdeck puedes sustituir tu acortador default por otro, entra a Settings > Services > y en endpoint pega http://zik.bz/quick/?resultFormat=simple&url=%@


Andshort es un acortador de direcciones URL opensource que nace después del estallido de acortadores gracias en gran medida a twitter.

He venido retrasando la liberación de este proyecto personal ya casi un año por bastante falta de tiempo y creo que podría faltar aún más antes de que viera la luz , si no lo hago ahora sera eternamente beta. La idea desde el principio fue muy clara, crear el acortador de direcciones Opensource definitivo \\O_O//.

Características principales

  • Opensource baby!! (MIT License)
  • Facil de usar.
  • Fácil de instalar.
  • Estadísticas detalladas de acceso.
  • Permite generar ingresos mediante Adsense.
  • Compartir enlaces por usando OAUTH en fb y tw.
  • Organización y administración de enlaces

Características técnicas

  • PHP (OOP) , Smarty.
  • MYSQL 5.x
  • Optimizado para Apache 2.x
  • El front tiene su propio core en JS, Jquery tambien es usado.
  • Minifier de CSS & JS con YUI / ShrinkSafe / CLOSURE
  • Importador de marcadores Delicious , Google bookmarks y RSS incluido.
  • REST API , aun falta la documentación pero de momento la API permite acortar direcciones y proporciona datos sobre urls y usuarios.
  • Google gadget.
  • Widget para WordPress ( en progreso )
  • Addon para firefox ( en progreso )
  • Características principales

Demo > he montado un demo bajo el dominio zik.bz , diseñado y maquetado por @infectedfx

API > Si deseas probar la API y cuentas con Tweetdeck puedes sustituir tu acortador default por otro, entra a Settings > Services > Selecciona Otro > en endpoint pega http://zik.bz/quick/?resultFormat=simple&url=%@

  • Share/Bookmark
toggle Cinema 22 Jul 2010

3D with OpenGL [Android] Posted by Insane in Uncategorized | No responses

Looking for some OpenGL snippets I just came up to this project wich is a port of NeHe’s tutorials for the Android platform.
It bundles several examples and is also available to download from the market place.

Looking for some OpenGL snippets I just came up to this project wich is a port of NeHe’s tutorials for the Android platform. The project comes with several examples and is also available to download from the market place.

QR code for Android Market:

OpenGL demos

OpenGL demos




Since I already own an android , I realized that all those proofs of concept that I´ve being doing and testing with the emulator, they actually works on mobile!! :P , so I will start publishing more content (and code) related to the platform , so you better stay tunned.

Last,  i think  you may find usefull this links:

  • Share/Bookmark