Welcome iPhone OS 3.0

•June 21, 2009 • Leave a Comment

Lately, upgrading unlocked iPhones firmware is not such a big deal as it used to be (thanks to iPhoneDevTeam)… I have upgraded my unlocked 2G iPhone (Yes I know how all you 3G/3GS owners feel… don’t get me started on that)… I just followed this iClarified link and all it took me was 20 minutes of time… (that too because of all the backups that I need to take)

To take backup of your iPhone…

Contacts : Use iTunes
SMS
: Copy the sms.db in /private/var/mobile/Library/SMS to local and restore it back after upgrade*
Notes
: Copy the notes.db in /private/var/mobile/Library/Notes to local and restore it back after upgrade*

* You should have installed OpenSSH in your iPhone through Cydia to remote login from a PC and copy these files

Struts & Springs in iPhone

•February 15, 2009 • 2 Comments

I found the following image in one of the Apple’s Interface Builder tutorials for iPhone programming. I have this habit of skimming through the whole page before giving it a concentrated read and after seeing this image, thought “Wow… Something explained here in relation to two poular web frameworks “Struts” and “Springs”… But but, i am in Interface builder tutorial… What is happening here???… “

After reading what they are trying to say in that section, I realized they mean what plain english word means when you say “spring” and “strut”…

But, I felt this as a rare coincidence to see these words together in the least expected spot :)

Struts & Springs

Struts & Springs

Is it a rectangle?

•November 2, 2008 • Leave a Comment

Couple of days back when I was travelling back to home from office, I overheard two fellow employees discussing over a programming problem… “If four points in a 2D plane (x,y) is given, how to find whether it forms a rectangle or not?”. Question sounds simple right? Well, how would you program this solution? what will be the algorithm? Just give it a shot.

Check out my implementation below… It did not look this small and simple when I started solving it. Tried calculating angles between edges, tried equating edge lengths, tried rotating the skewed rectangles (special case), tried getting B.Sc. Maths degree first… But, all of these are not really needed for the solution…  It is enough if you calculate the centroid and make sure all the 4 points are equi-distant from the centroid. Well, square also satisfies this logic and square is also a rectangle :)

I guess it is always hard to come up with a simple solution… You have to put lot of effort to think simple!

 1 public class RectangleValidator {
 2
 3 	public static boolean validate(Point p1, Point p2, Point p3, Point p4) {
 4 		// Find the centroid using Euclid's geometric principle
 5 		Point centroid = new Point();
 6 		centroid.x = (p1.x + p2.x + p3.x + p4.x) / 4;
 7 		centroid.y = (p1.y + p2.y + p3.y + p4.y) / 4;
 8
 9 		// Now check if the centroid is equi-distant from all the corners
10 		double dist1 = getLength(p1, centroid);
11 		double dist2 = getLength(p2, centroid);
12 		double dist3 = getLength(p3, centroid);
13 		double dist4 = getLength(p4, centroid);
14 		return (dist1 == dist2 && dist2 == dist3 && dist3 == dist4 && dist4 == dist1);
15 	}
16
17 	private static double getLength(Point p1, Point p2) {
18 		// Using pythogoras theorem
19 		double xDiff = Math.abs(p1.x - p2.x);
20 		double yDiff = Math.abs(p1.y - p2.y);
21 		return Math.sqrt((xDiff * xDiff) + (yDiff * yDiff));
22 	}
23
24 	public static class Point {
25 		Point() {
26 		}
27
28 		Point(double x, double y) {
29 			this.x = x;
30 			this.y = y;
31 		}
32
33 		double x;
34 		double y;
35 	}
36
37 }

Thanks to Code2HTML

My first iPhone app

•September 2, 2008 • Leave a Comment

Well well…. It is really a great experience to soak my feet in iPhone programming… But, after 3 hours of playing with Objective-C and Cocoa, I was able to get some very simple and completely useless app to work… It does nothing other than displaying a text on button click… Sounds silly right? Yes i know… But, for a java programmer who had never touched Objective-C and Cocoa, I think this as an achievement! :)

Apple’s architecture of keeping UIComponents (xib files) and the operations (on it) separate is good… I can design application screens (in Interface Builder) and write functions in Objective-C independently and then associate them later. This way, there is a lot of scope for reuse… However, this mapping part is bit tricky… It took me some time to understand Outlets and Actions…

There is a loooooooooooooong way from here to my first useful application “Time Tracker” and I hope I will be able to do it in a month’s time given my busy schedule ;)

Following sites were very helpful for me in understanding the basics of Objective-C and Cocoa…

Progress bar in HTML

•March 30, 2008 • 7 Comments

When I was creating a simple google widget for our office coffee club, I thought of showing current inventory status with a progress bar. To my surprise, I was not able to google any simple html/javascript code for it. All I found was hefty javascripts which does a zillion things to display just a progress bar. Creating a progress bar should not be that hard… So, I googled harder, but no use.

After a while I decided to create my own and my requirement was not to write too much code (more code means more maintenance work) and should work in any web browser (ofcourse, it should be javascript enabled)

After an hour of work, I had it ready and hooked it in my widget.
Feel free to use it for your ‘Progress bar’ needs :)


<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<style>
.bar {
	border-style: solid;
	border-color: gray;
	border-width: 1px;
}
</style>
<script>
function setPercent(id, percent)
{
var div = document.getElementById(id);
var barImg = div.getElementsByTagName("img");
barImg[0].width = (div.offsetWidth * percent) / 100;
}
</script>
</head>
<body onload="setPercent('fir',75);setPercent('sec',11)">
Progress bar with 75% complete
<div class="bar" id="fir" class="progressbar"><img src="bar.jpg"
	width="20px" height="20px" /></div>
<br>
Progress bar of size 300 px with 11% complete
<div class="bar" id="sec" class="progressbar" style="width: 300px"><img
	src="bar.jpg" width="20px" height="20px" /></div>
</body>
</html>


Logic: Whenever the setPercent() method is called, the javascript will get the right div tag, calculates and sets the width of image inside it based on the current div tags width and percent complete. Simple right?

My 1.1.4 iPhone

•March 13, 2008 • 2 Comments

Ok, you got an iPhone when it was in version 1.1.1 and, when there was a possibility of unlocking it, you did it… But, Apple did not stop there… they kept adding more features to it and dammit, you cannot run automatic updates for it and keep it unlocked… like me, if you were also praying for some great soul to come and rescue your iPhone, good news… our prayers are answered… and that great soul is zibri :) Ok… enough of my *#@$% let me scrap how I did it so it might help others…

This whole unlocked iPhone upgrading process is so easy even a caveman can do it. Don’t believe me? Check it out…

  1. ziphone software: Downloaded it here and zibri’s blog is here
  2. 1.1.4 firmware file: This link is present in ziphone software. After extracting the executable zip file downloaded from above step, I opened ZiphoneGUI.exe and clicked on “Help & Info” button in the right side. This help window has “Web links” section containing links for all the firmware versions. Downloaded 1.1.4 from it.

I was aware that I will lose all the data in my phone. As expected, All the contacts, apps, calendar, notes, music, and every other things I dumped in were lost after the update. iTunes ’sync to computer’ saved my day.

Firmware update steps (For out of the box 1.1.4 iPhones brought recently, I would have started from step 7):

  1. Switched off my iPhone (hold the sleep/wake button)
  2. Started in restore mode (kept holding the home button and connected it to the computer)
  3. iTunes opened and displayed my phone with restore option… Clicked on the restore button by holding down the shift key to open the file browser… Selected the downloaded 1.1.4 firmware file
  4. iTunes did its ‘thing’ to restore the phone to 1.1.4 firmware
  5. After successful completion of the above step, My iPhone restarted automatically to show iTunes with welcome screen to activate it through AT&T (ya right… I was going to do it ;) )
  6. Disconnected the phone and closed iTunes. Also killed the background process iTunesHelper.exe
  7. For the second time, I connected my iPhone to the computer in restore mode
  8. Opened ZiPhoneGUI.exe and clicked on “Do it all!” button
  9. Was relaxing for around 4 mins by looking at the wonders zibri software did to my phone. (you can see it on the phone screen… ya… iPhone-only-understood-rolling-text)
  10. Zibri software window displayed success message
  11. Phone restarted and iTunes listed it with setup screen to set the name and configuration type. I selected option saying something like “Set up as a new phone”. – There seems to be some weird problems with the other option.

At last, I was able to try out some of the new iPhone features and looks pretty cool than the you tube video demos. Also, donated some money to zibri (through his blog site) supporting his work….

Assassins Creed???

•January 1, 2008 • 3 Comments

If you are as game crazy as me, the Title of this post explains the wallpaper’s theme. If not, google is your friend here. The question marks in the title is for a reason. Just look at the wallpaper below and try finding it. :)

Rayassassin

So…did you find it? If not, let me help you… It is not ‘Altaïr’ (hero of the game who is an Assassin) in the above image but it is me :) Yes… Photoshopped it and created ‘RAYssassin’. Ya ya… I know none will be interested in Rayssassin (instead of Altair) for the iPhone wallpaper but, wanted to post it just for the records ;)

Vinayaka

•December 13, 2007 • Leave a Comment

This time it is Vinayaka… Saw this picture in the web and looked like a right candidate for my iPhone. Can also be used with iPod Touch.

Vinayaka

Hare Krishna

•November 15, 2007 • 3 Comments

A week after getting an iPhone, pre loaded goodies looks boring… So, I started to customize it with the most easiest part… wallpaper… I got this picture from my friend Venky. Color balanced the original image and resized it… tada…. a new wallpaper for my iPhone :) This can also be used for iPod touch as both have the same screen resolution (240 X 320 pixels)

Hare Krishna

Enable Java Apps browser

•October 31, 2007 • Leave a Comment

If you are having a T-Mobile SDA (in USA) / HTC Tornado (outside world) and installed a java application say a game, you cannot browse to it because the java apps browser is not shown in the start menu by default (what the…..). Ya, i donno why it is not enabled by default, but, there is a way to enable it. I did the following and made it work. By the way, i did not discover this method… it is already available in the internet but not so easy (For me) to find… I am just increasing the chances (May be not!!!) of someone finding it easily :)

NOTE: To do the following, u should have a windows PC with Microsoft Activesync installed.

  1. Connect your windows mobile smartphone to the PC (which has the Activesync installed)
  2. After the computer detecting the phone, you should see ‘Mobile Device’ icon in ‘My Computer’
  3. Open it and find ‘My Windows Mobile-Based Device’ icon in it.
  4. After opening it, Browse to \windows folder and locate jmm.exe
  5. Right click on it and select “Create shortcut”
  6. Now, move this created shortcut into the \windows\Start menu folder
  7. Rename the shortcut to “Java Apps” (You can give any name you want… But, this is the name in which the java apps browser will be shown in the mobile start menu)
  8. Now disconnect your phone from computer and look in start menu. You should be able to see a new shortcut (usually at the last page) for browsing through all the installed java apps in your phone.

Have fun!