Saturday, February 5, 2011

Android Intents

    We are back, This time with more on android. In this article i will share my experience of using intents and try to simplify things.

    Whenever one calls a function, he/she can pass arguments to the function. Similarly when one calls another activity from an activity, how are the arguments passed to the called application ? Or even if two activities want to talk ( exchange messages ), how do they achieve it ?. How does an activity start another activity ? The answer to these questions is intents !

    Intent is basically a carrier for your message. You can send messages to the other activity via intents. The way i most prefer is to put it into extras and then get the bundle
eg.


Intent intent = new Intent() ;
intent.putExtra("Name", "Saket" ) ; //These are key-value pairs with string key.
intent.putExtra("Age", 20 ) ; //Value can of any type


To get the sent information on other side, one can follow the following way.

Bundle bundle = getIntent().getExtras();
String name = bundle.getString("Name");
int age = bundle.getInt("Age");

and so on....

So, We now know how to pass messages. One thing here, to ponder over, is that an activity can call an activity/service as a sequel or may be it is expecting a reply from the called activity. A rough example of a sequel calling can be an ImageDisplayActivity or a SlideShowActivity. Example of calling an activity, when expecting a reply, is calling SelectImageActivity which displays images of a given folder and then replies the imageFile which was selected by the user. Another can be of calling MakeTransactionActivity which tells if the transaction was successfully completed or not, etc. The above two methods of initiating another activity can be done by

  • startActivity()
  • startActivityForResult().

Also one can broadcast some info or object using intents, to other Broadcast Receivers, by the means of sendBroadcast() and other similar methods. The broadcast listeners have to override their onReceive() method.
For more information on broadcasting intents refer here

For initiating other standard activites, just call startActivity with the activity Action. eg the most common is to initiate a phone call. This is a way how it can be done.


Intent intent = new Intent ( Intent.ACTION_CALL ) ;
intent.setData( Uri.parse("tel:999666333") ) ;
startActivity( intent ) ;

Hope this helps :)

Friday, January 7, 2011

Rendering Made Easy

This one concerns friends who have to do away with Graphics. We had our Graphics, some of us liked it while the others "Really" liked it ! :p . The main reason for such "real" liking were the painstaking assignments. Yes!, The assignments, which can be great fun for some, are tremendously boring for others.
    Writing long C++ codes to get triangles form rectangle and circles, is like calculating the sum of first n Fibonacci numbers with pen and paper!. Many a times people are not comfortable with stack manipulation of Instruction Pointer, and they are asked to manipulate stack of matrices.
    The main problem arises when triangles have to aligned to look like robots and dogs. Also the texture of the triangles have to be so adjusted that the triangle skeleton indeed looks like a Dog!. Write a file, compile it, run it, change values, compile it, run it, change values, compile it, run it,...and so on.
   But all this can be avoided :D. To your rescue is Python, a language which requires minimum amount of code. I would like to draw your attention to PyFLTK ( Python Fast Light Tool Kit ). It will certainly make your life easy.
   No need to write codes !. Just design your window on an interactive shell :). Type a statement and see the results. No need to compile, no need to re-execute the previous steps, no need to bang your head against the wall. Here's an example.
        > python
        >>> from fltk import *
        >>> window = Fl_Window(300,300)
        >>> window.end()
        >>> window.show()
        # Window pops up here
        >>> window.label("My new title")
        # Window label changes immediately
        >>> window.color(FL_RED)
        >>> window.redraw()
        # Window color changes to red immediately. TADA !

Short, rather much shorter codes.
from fltk import * ;
window = Fl_Window(300,300) ;
window.end();
Fl.run();
Thats it, just 4 lines to create a window. Probably you will still be including libraries and header files in your C++ code.

Show/Hide Functions


Still bothered about your submission in C++ ?
You can put your OpenGl code inside the python file by wrapping it with gl_start() and gl_finish()
     gl_start()
     ... put your OpenGL code here ...
     gl_finish()
Voila ! Party TIme :P

To install PyFLTK, and enjoy Graphics ;) go here.
You can find more about PyFLTK here


Tuesday, January 4, 2011

Android: No Proxy

         When it comes down to Google, It has to be 'the' Best. Android, a mind blowing Mobile OS with staggering features. Building Applications on this platform is always fun. Most of the time, you need to work with the net. Everything goes fine, until, you get into the not-so-sophisticated problem of proxy servers for accessing internet.
          It came as a surprise for me, when i was unable to find proxy settings for the Android Emulator. After asking a few friends, I came to know, that I was searching for the non-existent! Android Emulator does not have a proxy settings option. How could a phone of such a caliber miss out on proxy settings.
          This, certainly, does not mean that the world has come to an end. The Android Emulator will set its proxy as well as "No-Proxy" fields from the environment variables. So just setting the environment variables does the trick.
          In Linux, open the ~/.bashrc, and set the http_proxy and no_proxy variables. Then run .bashrc. Voila !
          The following commands help

  • cd
  • sudo vim .bashrc
  • Add export http_proxy='proxy.server.example.com'
  • Add export no_proxy='127.0.0.1' #And other sites for which to bypass proxy-server.
  • . .bashrc
  • emulator -avd <name>
Now, Your Emulator runs under proxy as well. Enjoy and Happy Coding :)

Sunday, January 2, 2011

Firefox Beta 4


For All Firefox lovers,
Firefox 4 is on the wire. Currently the Beta Version. Here are some of the features.

1. The Interface


With everything having a new interface, how can Firefox fall behind!. The Firefox window has the firefox button, like every other application. To get back the menu's, press ALT. You can revert back to the old look by going to View ( ALT + 'V' ) and then Toolbars, Then checking the menu bar. 
The Tab bar now has a special place, ie on the Top of the window. Looks Cool! Again for the traditionals, it can be brought down ( the earlier place ), View ( ALT + 'V' ), Then Toolbars, Then un-check 'Tabs on Top'. Voila!




What I like about this is that it has a compact look and gives more space for the website.

2. The Tab Group

Opening new windows, to keep similar tabs in the same window ?. Well, Not any more. The new firefox has the Tab Group feature. You can form Tab groups to keep same subject tabs in the same group. To form Tab groups click on the panaroma icon just below 'X', close button. To go back, press Esc. Now, you can see all your tabs open. Just click and drag them to form groups. You can create an empty group by just selecting some blank space in the window. Click on a group, to see tabs of that group only
Certainly, A golden feature added. I was so looking for such a feature in browsers where one can group tabs rather than opening new window or another browser for a different set of tabs. Bravo!

3. The Firefox Sync

Everyone stores passwords, bookmarks, favorites, history. But what does one do when on some other OS, other PC or even other device ( eg mobile ) ? Firefox has a solution! with its firefox sync. You can sync all your saved stuff in firefox by just making an account and saving a key, rest firefox handles. For more on sync, watch this video.
Yup, Another golden egg in the basket. Mobilizing your eye to the web.

For more details check The Mozilla Site here
Enjoy Surfing :)

Saturday, January 1, 2011

Hello, World !

Welcome to blackBird's Blog.
Enjoy Reading and Post Comment.

~~ Blog, Learn and Teach ! ~~