Thursday, October 06, 2011

Great Role model of Our Generation


No one wants to die. Even people who want to go to heaven don't want to die to get there. And yet death is the destination we all share. No one has ever escaped it. And that is as it should be, because Death is very likely the single best invention of Life. It is Life's change agent. It clears out the old to make way for the new. Right now the new is you, but someday not too long from now, you will gradually become the old and be cleared away. Sorry to be so dramatic, but it is quite true. ~ Steve Jobs

Sunday, October 02, 2011

Greek Holiday

At the end of the "Finnish" summer we had our summer vacation in Greece. The time we arrived to Greece was pretty nice with temperature of around 32C. This summer holiday was my first summer vacation and in previous years we ( me and my wife ) were traveling mostly in winter. It was always good to leave Finland in winter since it is really cold in here, but we realized that the destination will be much nicer if we travel in summer.

We first arrived to Athens air port and then took a bus to Piraeus sea port where we had our first stop. We booked a hotel very close to the port since we had to get into the ship early in the morning. The plan was to take the ferry from main land to island Santorini and then to Milos. Finally to come back to the main land.
On the first day of  the trip we booked a hotel close to Pieraus sea port. Later in the evening we took a metro to Athens to visit Acropolis. The people (Greek people) we met in the metro (not only metro) were really nice and advised us about thieves. They informed us to take care of our belongings especially camera and vollets when traveling  in dense areas. And another girl helped us with direction to the destination. Getting to the top of the Aceopolice was a very nice experience. It was not only because of the great architecture but also the fabulous view of the city. Luckily our timing was really great. We had the opportunity to listen to some greek music (since some music band was practicing for that nights event). Finally we stayed at Acropolis till the sunset and retured back to hotel. The food cost just the same as in many Europian countries. Not that cheap at all. But worth the price.

Day 2: Early next morning we boarded the ferry heading toward Santorini. Small piece of advice, if you are travelling in the day time and in summer you really don't need a cabin. Outside deck of the ship gives you a wonderful view all through out the jouney. The ferry we booked was quite cheaper but it took around 9 hrs to get to Santorini from main land. 
After passing many islands finally the ferry reached Santorini (Thira) port around 4.30 in the evening.  The island was built in such a way that there steep mountains all around it. After getting down at the port we started searching for a bus to go to Fira (main city in Santorini). Unfortunately buses leave only in every 1.5 hours. Then we shared a taxi to Fira with another traveler. It costed around Euro 17. 

By the time we reached our hotel Villa Ilias, we were really tired. The walk from Fira to Firastephani (That's where Villa Ilias) is a  short but we felt it was very long since it was our first time there. There is a little pool in the hotel and the first thing we did was dipping in the water. That soothed the tired bodies. The view from the room was magnificent. It was one of the most beautiful things I've ever seen. That evening after dinner we walked to the Fira town and enjoyed the evening shopping around. Path to Fira is lovely. In the evening it got little mistier and bit chilly. But I enjoyed it.
The hotel staff was good, breakfast was great and view was superb. 

Day 3: We started our third day with a very fresh and filling breakfast. We planned to spend this day travelling around the Island. The first thing we did was renting a motorcycle. Not really a 2 wheel bike we ended up renting a 4 wheel desert rider. The renting places gave the maps and the good thing is there is nothing much know about the roads. There are very few main roads. In many of those junctions you can find sign boards with information. You can also get a clue by observing the paths other travelers taking.   
Map of Santorini

Perissa (Black Sand) Beach
Red Beach
Oia
 Just another tip from our observations; renting places ask you to put fuel for like 10 euros. You really don't need it. 3 euro fuel is more than enough for a day. By the end of day 3 we have been to red sand beach, black sand beach (perissa beach) and Oia. Oia is a very attractive place. The buildings, walking path and everything else is white. Whiter than Fira. It seems very elegant. People say that Oia is the best place to see the sunset. But I prefer Firostefani over Oia.

Day 4: According to the plan we were suppose to board our ferry to Milos at 4 pm. But we went to a ferry agency and asked whether the ship is coming on time. I'm really glad that I asked about it before hand because the ferry has been moved to 19.50. Which is a delay of around 6 hours. When ever you are booking ferries between islands in Greece remember that rescheduling of ferries is very normal. Keep a good time gap when your booking your airlines and other fixed stuff. Finally the ferry delay gave us more time in Santorini. 

In the morning we checked out from the hotel. But left our bags in the luggage room and could still use pool of the hotel, shower rooms and dining room until we leave. That made our day very convenient. The path from hotel ( end of Firostafani) to Fira has a magnificent view of caldera.



Path from Firostefani to Fira
Donkey Taxis







From Fira we took a donkey ride to the old port of Santorini. The path was very steap and there are more than 350 steps to walk down to get there. Donkey ride was very slow but a brand new experience. Then we spent few hours in the port just relaxing and came back to Fira by cable cars (which took 3 min to get back). Then we did some souvenir shopping in Fira and returned to the hotel. Fira is a very busy touristy place. Never select that place as a relaxing destination. And if you are planing to go down by the cable car go early in the morning. Around noon there was a queue of more than 200 people. Fortunately we missed it. But believe me standing there in the queue under the scorching sun  is not a pleasant experience.

Finally in the evening we took the ferry from Thira to Milos. It was only 2.5 hrs. .When we got down from ferry there was a small girl holding our names in the port. Luckily the hotel owner has come to port to pick us (not only to pick us, those hotel owners come to port every time when there is a ship arriving.). 

Day 5: The hotel we booked in Milos was really nice. It doesn't any view, but it was very close to the center (Adamas) of the island. We had a nice breakfast from the hotel and we started walking around the center and had a relaxed time in a beach closer to Adamas.  Nothing much special happened on day 5. We spent the entire day relaxing in the beach and enjoying fabulous sea food. On our way back to the hotel that evening we made an advanced payment to a sailing boat for next day around the island tour. 

Around the island cruise normally leaves around 10am and returns around 6pm. They take you around the western side of the island. The western side of the island is hard to reach through a motorbike or car, because the peaks are very high and the roads are not that good. The best way to go to the west side of the island is by sailing boat. They also fish while travelling and they cook Greek traditional food on the way. If you are not happy with octopus it will be a problem. 

Day 6: We had our breakfast and got prepared to our sailing trip around the island. We were the first to reach the boat. But unfortunately they've cancelled all the trips on that day. The wind on the west course has gotten too strong and the sailors said its not possible to go there swim in that shore. So the tour was cancelled. But we didn't get discouraged instead rented a motorcycle. They just advised us not to swim in any beach facing north and no to take any of the high landed roads. 

First we visited Plaka and Klima. Plaka is the old city center of the island. And Klima is a small finishing village close to Plaka. This finishing village is some what different from many other finishing villages you see in the world. Those finishing men has created closed rooms for their boats to protect them from the harsh winter and pirate attacks. So its like a car parking garage but only thing is it opens to sea.
Hotel in Milos 
(Moschoula Rooms and Apartments)
   

Klima


Paleochori Beach (Volcanic Cooking)

St. Kyriaki Beach

Since the sea in north side was so rough we rode to the south coast of the island. 1st we went to Paleochori beach and next we visited the Ag Kyriaki. Paleochori beach sand is mixture of sulpher. It is bit yellowish in color and when you put you feet under the ground you experience the burning sensation. The ground the sand layer of the beach is really hot due to volcanic activities. There was a one restaurant which sells "Volcanic Food". Which means they make a soup or something using the ground heat. Then we went to Kyriaki beach which has a view very similar to Paleochori.

Day 7 : This was our last day in Milos. The ferry was scheduled at 3.30pm. Again in the morning we checked ferry timetable from a travel agent. No surprise. The ferry been cancelled. Luckily our flight was at the next day evening. We booked the next ferry which was scheduled to leave around midnight. We booked it with a cabin so we can sleep until we get to Athens. Then we canceled the hostel booked in Athens. We thought to kept the bike we rented the other day for the entire day. We started the day with exploring some other places in north.
 Papafragas

Pollonia

Sarakiniko
Achivadolimni Lake

First we went to Papafragas (Filakopi) where we have seen very nice volcano like beach. It was a very windy day and the sea was so rough. No one was there. But it was a very small beach compared to other places. Then we kept riding to the end of the road and we came to Pollonia. It is a big village/city like Adamas. There is a farely large beach and plenty of restaurants. Then we walked to the most top tip of pollonia where we had a very nice view. Then we went to Sarakiniko.

Sarakiniko is totally built from lime stone. Total white lime beaches resembling snow fields and complete absence of flora are unique features of Sarakiniko. When you look at the place from far it looks like nothing but snow. There we spent some time swimming on shallow water bay. If you are going there take food and drinks. There are no shops closer to Sarakiniko beach. But that is something I have seen good in Greece. Almost all the beaches had at most one shop. The travelers have more than enough space to stretch their legs and relax.

Finally we came back to a beach where you can find the one and only lake in Milos. The Lake and sea are separated by a road. I do not really advice anyone to visit to that lake lake though. Its just a dry land (may be it has some water in the rainy season). But there is a very nice view of west side mountains from there. The west side mountain peaks are higher than 700m. It will be a nice place to visit (but car rental people said it will be really windy during this time of the year).

Finally we went back to the hotel and had a swim. Then got prepared to come back. The ferry trip was nothing exciting, because we booked a cabin and slept tightly.

Day 8: We arrived to Pieraus port at around 6 am and we took the metro to the hostel  "Athens Backpackers". As soon as we got to know about the ferry delay (cancellation) we canceled the hostel. But we just went there to see whether the booking was really canceled. Yes, it was cancelled. But they have charged the whole amount. Remember if you are cancelling only a one day, dont do that. Then you will loose your money and the bed. But the person who was there allowed us to have breakfast and to keep our bags. After the breakfast we just had a walk around the city and bought some souverniers. Then after having lunch we took the bus from Athens to Athens air port.

This holiday was the first holiday getaway i had. Previously I have traveled to some other location including driving around Europe. But this felt so good, more relaxing than any other trip.




Thursday, August 04, 2011

How to setup LAMP in AWS (Amazon Web Services - EC2) using Putty

Im going to skip very basic steps. Is you do not have any idea how to get to the screen below this is not for you.
1.) Click "Launch Instance"

2.) Select "SUSE Linux Enterprise Server 11 64-bit (AMI Id: ami-e4a3578d)
SUSE Linux Enterprise Server 11 Service Pack 1 basic install, EBS boot, 64-bit architecture with Amazon EC2 AMI Tools preinstalled; Apache 2.2, MySQL 5.0, PHP 5.3, Ruby 1.8.7, and Rails 2.3.
Root Device Size: 15 GB" from the options. (thats what i did)

PS: If you select SUSE you have to pay. Later I selected "Amazon Linux AMI", which is free for 750hr per month. If you use Amazon Linux later the user name to login is "ec2-user".

3.) For now dont change the following screen. Once you become good at this you can create once with better configurations. And I think you need to pay more when its getting better. Just click "Continue"

4.) Again you will be shown with some details like "Kernal ID" and "Ram disk ID". Dont waste time. Just click "Continue"

5.) Next screen it ask you to enter some keys. They have already given a key as name. For now just type what ever name you like in the value box and click "Continue"

6.) Now you need to create a key pair. Select the 2nd option ("Create a new Key Pair"). Enter a name for your key. When you click create and download your browser will save a file with extension ".PEM". Keep it. We will need it for future. Once you have the file click "Continue" to get to next step.

7.) Next it will ask for security groups. Just add one with full access. I know its bad. But if you need more instructions in setting up better security options read some where else for that.

8.) Finally the "Launch". Now the system starts running your instance.

9.) When you click "Instances" in left menu you will find your server is now running.

10.) One more thing we need to do. Go to "NETWORK &SECURITY -> Elastic IP" option in left menu. Then find the button which says "Allocate New Address". Select "EC2" since we are working on it. And you will start seeing an IP address allocated for you. Its not a public IP for you. So dont be soo happy.

11.) Next right click on the IP address shown. Then you'll get the option to Associate the created server into it. Do it. Now you should get a "Public DNS" name for that given IP. This is the address where you can access your server. But for me when i try this on browser it didnt show up anything. I needed to install Apache, MqSQL and PHP first.


12.) Now the BUGGY part. Accessing server through SSL connection using Putty. 1st download both Putty and PuttyGen.  Open PuttyGen 1st. Then Click "Load" to load an existing private key. And locate the PEM file you saved. And open it. And in the screen for parameters its selected to SSH2 as default. But select SSH1.  Next save the private key. It will save as a PPK file.

13.) Now open putty
Now enter the public DNS given for you from the AWS as the Host name ( Remember ! IT IS NOT the Elastic IP). Goto Connection->SSH->Auth. Give the location of PPK file created using puttygen. It needs to be a SSH1 type file. Now clikc open.

14.) Server will ask you for the username. It is "root" and once you enter that you are logged in. When im reading through some other documents they have mentioned to try "ec-user" as username. If any case root do not work try that.

Upto here i only talks about setting up a SUSE Linux server on AWS EC2. Read here to find about how to install LAMP to SUSE. Whether it says in the selection it has LAMP, it really does not have it in installation. But its very easy to set up.

Monday, July 04, 2011

Simple Rules in Twitter, Google+ and Facebook

Few days back i got an invitation an I created a Goolge+ account. I did it when Facebook came up and when twitter came up too. I was thinking whats so different in Google+ other than in Facebook. I figured three different sharing systems work in all three networks i just mentioned.

Twitter : You can follow any person (Person X). What ever person X share can be seen for all his/her followers. But X do not see any thing that his/her followers do. This is best for people who are like actors, scientists, and so on.

Google+ : If you add some person into your circle, the added person can see your content. So this is the absolute opposite of Twitter. So this is good for normal people to keep informing others. But you cant see what he/she is up to by adding them into a circle. They need to add you into a circle if they want to share things.

Facebook : This is a combination of both Twitter and Google+. When you add a friend and friend accepts his/her friend request you can see their posts and friend can see your posts. Still you can set security levels and sharing levels. But default is sharing happens in both ways.


I have a feeling now its time for me to move from Facebook to Google+. But still "Mark Zuckerberg" will be one of my favorites.

Saturday, June 11, 2011

Bugs and How to Fix them ! for Android Beginners

Unknown Host Exception in Android
When you try to load something from web, and you have done almost everything right still you might get this exception.
06-10 11:08:50.217: WARN/System.err(868): java.net.UnknownHostException: nopsa.hiit.fi
06-10 11:08:50.217: WARN/System.err(868):     at java.net.InetAddress.lookupHostByName(InetAddress.java:497)
06-10 11:08:50.217: WARN/System.err(868):     at java.net.InetAddress.getAllByNameImpl(InetAddress.java:294)
06-10 11:08:50.217: WARN/System.err(868):     at java.net.InetAddress.getAllByName(InetAddress.java:256)
06-10 11:08:50.237: WARN/System.err(868):     at org.apache.harmony.luni.internal.net.www.protocol.http.HttpConnection.(HttpConnection.java:69)
06-10 11:08:50.237: WARN/System.err(868):     at org.apache.harmony.luni.internal.net.www.protocol.http.HttpConnection.(HttpConnection.java:48)
06-10 11:08:50.272: WARN/System.err(868):     at org.apache.harmony.luni.internal.net.www.protocol.http.HttpConnection$Address.connect(HttpConnection.java:322)
06-10 11:08:50.272: WARN/System.err(868):     at org.apache.harmony.luni.internal.net.www.protocol.http.HttpConnectionPool.get(HttpConnectionPool.java:89)
06-10 11:08:50.272: WARN/System.err(868):     at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnectionImpl.getHttpConnection(HttpURLConnectionImpl.java:285)
06-10 11:08:50.277: WARN/System.err(868):     at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnectionImpl.makeConnection(HttpURLConnectionImpl.java:267)
06-10 11:08:50.277: WARN/System.err(868):     at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnectionImpl.retrieveResponse(HttpURLConnectionImpl.java:1018)
06-10 11:08:50.297: WARN/System.err(868):     at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnectionImpl.getInputStream(HttpURLConnectionImpl.java:512)
Solutions:
1.) Change the host name ( here it is nopsa.hiit.fi) to the ip address of the host. It can work.
2.) Restart your emulator ( few times.. may be )
3.) add folowing code to AndroidManifest.xml
<uses-permission android:name="android.permission.INTERNET" />
In some cases when you have'nt done the last change i suggested you might bet the following error as well.
06-10 22:47:29.866: WARN/System.err(380): java.net.SocketException: Permission denied
06-10 22:47:29.896: WARN/System.err(380):     at org.apache.harmony.luni.platform.OSNetworkSystem.socket(Native Method)
06-10 22:47:29.946: WARN/System.err(380):     at dalvik.system.BlockGuard$WrappedNetworkSystem.socket(BlockGuard.java:335)
06-10 22:47:29.946: WARN/System.err(380):     at org.apache.harmony.luni.net.PlainSocketImpl.create(PlainSocketImpl.java:216)
06-10 22:47:29.997: WARN/System.err(380):     at java.net.Socket.checkOpenAndCreate(Socket.java:802)
06-10 22:47:30.026: WARN/System.err(380):     at java.net.Socket.connect(Socket.java:948)
06-10 22:47:30.026: WARN/System.err(380):     at org.apache.harmony.luni.internal.net.www.protocol.http.HttpConnection.(HttpConnection.java:75)
06-10 22:47:30.058: WARN/System.err(380):     at org.apache.harmony.luni.internal.net.www.protocol.http.HttpConnection.(HttpConnection.java:48)
06-10 22:47:30.077: WARN/System.err(380):     at org.apache.harmony.luni.internal.net.www.protocol.http.HttpConnection$Address.connect(HttpConnection.java:322)
06-10 22:47:30.116: WARN/System.err(380):     at org.apache.harmony.luni.internal.net.www.protocol.http.HttpConnectionPool.get(HttpConnectionPool.java:89)
06-10 22:47:30.146: WARN/System.err(380):     at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnectionImpl.getHttpConnection(HttpURLConnectionImpl.java:285)
06-10 22:47:30.146: WARN/System.err(380):     at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnectionImpl.makeConnection(HttpURLConnectionImpl.java:267)
06-10 22:47:30.176: WARN/System.err(380):     at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnectionImpl.retrieveResponse(HttpURLConnectionImpl.java:1018)
06-10 22:47:30.186: WARN/System.err(380):     at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnectionImpl.getInputStream(HttpURLConnectionImpl.java:512)

ActivityNotFoundException
06-10 22:50:18.256: ERROR/AndroidRuntime(572): FATAL EXCEPTION: main
06-10 22:50:18.256: ERROR/AndroidRuntime(572): android.content.ActivityNotFoundException: Unable to find explicit activity class {hiit.nopsa.pirate/hiit.nopsa.pirate.GameHome}; have you declared this activity in your AndroidManifest.xml?
06-10 22:50:18.256: ERROR/AndroidRuntime(572):     at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1405)
06-10 22:50:18.256: ERROR/AndroidRuntime(572):     at android.app.Instrumentation.execStartActivity(Instrumentation.java:1379)
06-10 22:50:18.256: ERROR/AndroidRuntime(572):     at android.app.Activity.startActivityForResult(Activity.java:2827)
06-10 22:50:18.256: ERROR/AndroidRuntime(572):     at android.app.Activity.startActivity(Activity.java:2933)
06-10 22:50:18.256: ERROR/AndroidRuntime(572):     at android.view.View.dispatchTouchEvent(View.java:3885)
06-10 22:50:18.256: ERROR/AndroidRuntime(572):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:942)
06-10 22:50:18.256: ERROR/AndroidRuntime(572):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:942)
06-10 22:50:18.256: ERROR/AndroidRuntime(572):     at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1691)
06-10 22:50:18.256: ERROR/AndroidRuntime(572):     at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1125)
06-10 22:50:18.256: ERROR/AndroidRuntime(572):     at android.app.Activity.dispatchTouchEvent(Activity.java:2096)
06-10 22:50:18.256: ERROR/AndroidRuntime(572):     at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1675)
06-10 22:50:18.256: ERROR/AndroidRuntime(572):     at android.view.ViewRoot.deliverPointerEvent(ViewRoot.java:2194)
06-10 22:50:18.256: ERROR/AndroidRuntime(572):     at android.view.ViewRoot.handleMessage(ViewRoot.java:1878)
06-10 22:50:18.256: ERROR/AndroidRuntime(572):     at android.os.Handler.dispatchMessage(Handler.java:99)
06-10 22:50:18.256: ERROR/AndroidRuntime(572):     at android.os.Looper.loop(Looper.java:123)
06-10 22:50:18.256: ERROR/AndroidRuntime(572):     at android.app.ActivityThread.main(ActivityThread.java:3683)
06-10 22:50:18.256: ERROR/AndroidRuntime(572):     at java.lang.reflect.Method.invokeNative(Native Method)
06-10 22:50:18.256: ERROR/AndroidRuntime(572):     at java.lang.reflect.Method.invoke(Method.java:507)
06-10 22:50:18.256: ERROR/AndroidRuntime(572):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
06-10 22:50:18.256: ERROR/AndroidRuntime(572):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
06-10 22:50:18.256: ERROR/AndroidRuntime(572):     at dalvik.system.NativeStart.main(Native Method)
to fix this bug you should add the following code to the AndroidManifest.xml
<activity  android:name=".ClassName"/>
The ClassName should be replaced by your Class name which is a Activity.

Friday, June 10, 2011

GSoC 2011 - NOPSA Game

I have been accepted to GSoC 2011 and actually im making this post after a cooldiscovery of glowing GSoC sticker :)

My GSoC project is to make an android game which makes use of both haptic feedbacks and nopsa image database. In different situations the user will feel the haptic feedbacks depending on the game state. Haptic feedbacks will be used to enhance the gaming experience while nopsa database will be the source of images to the application

Tuesday, May 31, 2011

Ubi-Challenge & N900

In 2009 me an my wife (Kumaripaba) participated on a competition announced by MediaTeam. The initial task was to propose a novel application to run on Ubi-Hostpots. For the competition we proposed two player Battleship game where players can play standing in two sides of the screen. Next the organizers collected data for reasonable amount of time and selected a winner from deployed applications.

Taken from: UBI challenge workshop 2010: real world urban computing.
It was really happy to be the winners of the 1st Ubi-Challenge organized. And as a award for the winners I received a N900 mobile phone. At first it was not my favorite choice. It was kind of heavy compared to many new mobile phones. But after i realized N900 is not just a mobile phone its something like a small computer i started messing with it.

One of the best things i have done with it is i managed to install Android Gingerbread version in to N900 and currently I'm planing to run Windows 95 pretty soon.

Friday, March 11, 2011

Android : Create a Bouncing Ball on Screen

If you are new to Android try the first article related to Android development first from here. Once you are done with that now you are ready to play with "Canves" where you can draw different kind of items. Following is a screenshot while ball is bouncing. Don't worry it will not stay at same place as in picture. It will bounce around :).
Start with creating an Android project in Eclipse. I used "SimplePuzzle" for project name and application name. Then i put "dinesh.fun" as my package name. Finally i used "LaunchApp" for activity. Then you click "Finish" to create the project.

Then the next step of our project is to edit the "main.xml". You can find this xml file inside the "res/layout" folder. It will contain a "LinearLayout" and a "TextView" element. But now our animation will run in a "View" which will be creating by our selfs. The final code will be look like as follows.  Later we will be creating a "View" named as "PuzzleAnimationView" inside the "dinesh.fun" package. Here in the "main.xml" we are refereeing to it.
<linearlayout 
android:layout_height="fill_parent" 
android:layout_width="fill_parent" 
android:orientation="vertical" 
xmlns:android="http://schemas.android.com/apk/res/android">
<dinesh.fun.puzzleanimationview 
android:id="@+id/anim_view" 
android:layout_height="fill_parent" 
android:layout_width="fill_parent">
</dinesh.fun.puzzleanimationview>
</linearlayout>
Now save the xml and close it. It will create necessary variables inside the "R.java" class. This is a file which is automatically generated and you DONOT need to change it at all. Next its better to add the image you need to use for animation into the folder "res/drawable". In some cases it will have three folders to support on different Android environments. For now you can copy the image into any one of them. In this example i used a "ball.png" as my image (its better to use a very small image for this example).

Now at the moment you can find "LaunchApp.java" is already created inside the package. For now we'll keep it a side and we'll create a new class named "PuzzleAnimationView". This was the defined class previously in "main.xml". This class should be extending "ImageView" class. As the first step you need to create the constructor of the class and see to set the context. The constructor will be appear as following.
public PuzzleAnimationView(Context context, AttributeSet attrs)
    {
     super(context, attrs);
     mContext = context;
    }
Here you will need to create a private variable named as "mContext". Now we are ready to write the actual drawing part. The "ImageView" class has its own method "onDraw" which is created in order to draw what ever things in the screen. hence we will be overriding this method with our animation code. But remember this is not about Android Animation. This is some image moving around. Later I will present you some fun application with Android Animation. First give a look at the code. Then we'll discuss what it is doing.
protected void onDraw(Canvas c) {
     int res_id = mContext.getResources().getIdentifier("ball", "drawable", mContext.getPackageName());
     BitmapDrawable d = (BitmapDrawable) mContext.getResources().getDrawable(res_id);
 
    int draw_x = Math.round(System.currentTimeMillis() % (this.getWidth()*2)) ;
     int draw_y = Math.round(System.currentTimeMillis() % (this.getHeight()*2)) ;
     if (draw_x>this.getWidth())
      draw_x = (this.getWidth()*2)-draw_x;
     if (draw_y>this.getHeight())
      draw_y = (this.getHeight()*2)-draw_y;

        c.drawBitmap(d.getBitmap(), draw_x, draw_y, null);

        float time = System.currentTimeMillis();
        while ((time+5000)>System.currentTimeMillis());

        postInvalidate();     
     }
In "onDraw" method it is called with the parameter "Canvas". The Android phone will call this method with passing this parameter. Our goal is to draw a bitmap in to the given canvas. in line 12 you can see the bitmap drawing takes place. The line 2 and 3 is basically used to load the "ball" image into a bitmap. From 5 to 10 the lines are used here to manipulate the x and y locations that image should be drawn. You can use different kinds of algorithms here. Its just need to stay inside the screen resolution. "this.getWidth()" like emthods will return the screen size. Finally the line 14 and 15 is used as a timer to wait before the next draw. And finally in line 17 we call "postInvalidate()" method to redraw or to call the "onDraw" method through the system. Now we are done with creating the animation.

The next step is really simple. Now you just need to create a "PuzzleAnimationView" object. Then it will start playing automatically. Here is the code for creation.
PuzzleAnimationView anim_view = (PuzzleAnimationView) this.findViewById(R.id.anim_view);
Now its ready to run the application. Enjoy. If you have any concerns leave a comment.

Thursday, March 03, 2011

Android : Hello World Calculator !

Here i'm going to write about how to create a worlds most simplest calculator in a very short period of time to run on Android platform.

First things first:
1. Download the Android SDK (http://developer.android.com/sdk/index.html). I Installed it to windows and i used the exe to install it. It worked pretty well :).
2. Install ADT Plugin for eclipse (http://developer.android.com/sdk/eclipse-adt.html).
3. Now try to follow and create the HelloWorld Application. (http://developer.android.com/guide/tutorials/hello-world.html). If you manage to get the required result you have done all the installation correctly.

Now to the calculator:
Follow this superb tutorial about creating the calculator in Android. http://www.brighthub.com/mobile/google-android/articles/26762.aspx

So Why am i writing another post??. I'll tell you what can go wrong.

Java.lang.NullPointerException 
at com.android.ddmlib.Client.sendAndConsume(Client.java:572)
at com.android.ddmlib.HandleHello.sendHELO(srcfile.java:142)
at com.android.ddmlib.HandleHello.sendHelloCommands(srcfile.java:65)
at com.android.ddmlib.Client.getJdwpPacket(Client.java:671)
......
Either you need to add some value to the AVD SD memory allocation or you have done something wrong in AndroidManifest.xml , It will only happen if you do not follow the tutorial instructions. And again in the emulator the application will not start or it might crash as well.

And the worlds famous question... Is Android Emulator takes agers to load. YES. Don't blame your computer or code. It takes very long time to turn up the emulator. But wait till everything loads up. When everything is done you'll see some nice wallpaper and some icons. WAIT till it appear.

Thats it for now :).