Sunday, 12 December 2010

Apache quits JCP, begun the clone wars has...

This was something expected but still shaking. Apache who had great contributions to Java and JCP and had been choosen JCP member of the year several times left JCP. Since from Sun era, Apache had a clash on TCK license for Apache Harmony project. Actually about a month ago at devoxx keynote panel things became more clear when Joshua Bloch talked about Oracle's reaction behind close doors.
After the JSRs for Java7 voted, Apache finally made the expected move and quit the JCP and the executive commitee.
JCP might not have been a responsive and effective organization but still it was something important for the community. I extremely agree this post on how JCP was ineffective. However this separation would change things on Java world forever. This seperatists movement will make forking of Java official which had been in progress for long. The community will probably follow apache, android and other Java likes where the business will follow Oracle and EE standarts.
Oracle is planning good stuff for Java but definitely they have no idea on community relations. This is the only response on Oracle side while Apache clearly showed their reasons. Please Oracle hire someone to keep up the community relations and please tell your lawyers to let him free.  Or is this just like Palpatine's plan to push a seperatist movement to make legal excuse for the war? Whatever it is, this is not a victory and begun the clone wars has...

Thursday, 2 December 2010

org.eclipse.swt.SWTException: Invalid thread access


Eclipse plugin development may introduce new set of exceptions to your life but actually this one is familiar. Just like most other UI architectures SWT, thus eclipse offers a single threaded UI model. Nature of working with in plugins may confuse in which thread you are but eclipse will definitely and politely remind you by raising an "org.eclipse.swt.SWTException: Invalid thread access" exception.

Although most the exceptions you may face during plugin development can be quite tricky, this is one is quite well documented and well known, even in SWT faq.
Briefly the code block needs to deal with the UI thread should be running within the following block:
Display.getDefault().syncExec( new Runnable() {
   public void run() {
      //access UI stuff
   }
});
Simple? Just keep in mind, SWT is a single threaded UI model just like awt, swing or most of the others.

Monday, 27 September 2010

JavaFX dead, Long live JavaFX…

For the last 3 javaones javafx managed to keep as the most popular topic. This year again there were promising javafx demos but also bundled with some shocking news.
Oracle has taken a bold step and decided to kill javafx, well at least the javafx script part. The tecnology still keeps the javafx name, however, without the declerative scripting counterpart nobody really knows how will it differ than swing and applets. Javafx script made nice start and offered promising future. Unlike its xml based rivals flex and silverlight, javafx adopted a css like declerative scripting. JavaFX also managed to have a public display of rich website of the last winter olympics.
Meanwhile, JavaFX failed to offer progress and tool support, thus failed to gain developer and community support. Although it was all java, different sytax and usage was not well atopted and made flex an easier learning path.
This year javaone keynote also introduced hard to believe javafx demos, but also brought the news that the scripting engine is not supported anymore and there wil not be any porting for javafx 2.0 . This led questions from java developers who felt left in dark. If anyone invest in learning javafx now, or even use their already gained experience, they are going to produce code which will not be supported in the new sdk. However nobody exactly know when the new sdk will be ready for production and how complete will it be? Also leaving declerative syntax behind and adopting a swing/gwt like style may also not be the best choise in the era of declerative uis. When compared to xml in flex, silverlight and even android, building your ui by code is not really attractive.

Oracle really took a bold move by making catastrophic changes which may bring life to javafx. They are completely rewriting and reengineering javafx but they lost very talented people from java, swing, javafx etc.. Who both knew java and the previous implementatins well (just to name few, Chet Haase, Romain Guy, Josh Marinacci). Honestly ireally think Oracle needs a UI product like javafx in their techonology stack and they are aware of this. However this move also left all current javafx development and developers in dark with some promises on future. Well we will see how much the "Future" will work javafx in java community.

Tuesday, 14 September 2010

Hungry to Flex? Welcome Burrito...

Those who have migrated to Flash Builder 4, has already should notice developer friendly enhancements in the IDE. However Flash Builder is still far from being perfect when ActionScript editor capabilities are compared to Java editor but the progress goes on... Adobe has just published a video of showing nice editor enhancements of Flash Builder.


Flash Builder Burrito - Generate from Usage from Andrew Shorten on Vimeo.

Adobe might have released Flex 4 and Flash Builder (spark mobile issues, missing spark components... etc) before they are complete but seems they are catching up.

Tuesday, 20 July 2010

Nexus One, Gone?

Nexus one was the first device introduced with such a massive hardware such as 1ghz cpu, 512 ram..etc.. but still lack getting consumer attention via Web as stated by Google. Google has announced that their web store is behind the expectations and they are shutting it down, leaving Nexus One available as a developer device.
Earlier this year, we announced that we will be closing the Nexus One web store. This week we received our last shipment of Nexus One phones. Once we sell these devices, the Nexus One will no longer be available online from Google. Customer support will still be available for current Nexus One customers. And Nexus One will continue to be sold by partners including Vodafone in Europe, KT in Korea, and possibly others based on local market conditions.
To ensure our developers have access to a phone with the latest Android OS, Google will be offering the Nexus One through a partner for sale to registered developers. Visit the Android Market Publisher site and log into your developer account to purchase a Nexus One.
Whatever you call it, Nexus One was a great success and a real milestone. I had been watching Android devices since the beginning while i was using an iPhone. Last year Google I/O I was given a developer device (HTC Ion) which was showing android made great progress but still far behind of iPhone. Until the release of Nexus One, all of the Android devices released had small screens, poor designs and lack of attraction.

I don't really believe Google wanted to produce, sell and make profit from hardware since from beginning of the 'Google Phone' rumours I denied to believe. But they did, they released the Nexus One, the first android labeled as Super Phone. Google needed to step in and take responsibility and they did. Until Nexus one no one including HTC, Motorola, Samsung dare to build phones with larger screens than iPhone. Google introduced the first real attractive android design and also used the new version of the OS (Eclair) first available for their new device.
I remember watching the ads and checking the web site of Nexus One about 6 months ago. Since then every single thing on the Android world has changed. Other super phones Droid, Evo 4G, Eris, DroidX, GalaxyS had been released. Most of those devices even have larger screens than the Nexus One. HTC polish Sense UI even more and Motorola followed by MotoBlur. All devices now have multitouch support, great navigation (thanks to larger screens), better and more customized UI. Also there had been an explosion of applications on Android Market.

Android is still way behind of iPhone in terms of design and ease of use. However Nexus One had opened the pandoras box and the change had been started. Today the avarage of android device development cycle is 3 to 6 months. Although iPhone offers better user experience in general the new wave of Android devices offered an unexpected user experience in maps, multimedia, surfing etc thanks to larger screens, wifi tethering, customizable UIs, live desktops and many many more.

Whoever thinks Google had failed with Nexus one, should just sit back and imagine would Android be at this point if nexus one had never been existed. Nexus One had changed the expectations, the view of both the manufacturers and consumers, and accelerated the move to android, changing the fate of mobile world.
So long Nexus One, the first real super smart phone. Thanks Google, thaks for giving the inspiration the consumers and mufacturers needed and thaks to let us now that you would not hesitate to step in to shape up when the platform needs your support..

Tuesday, 29 June 2010

Froyo update goes official!!

The long waited android 2.2 update, codenamed froyo is now official and expected arrive via over the air within this week. I had been using FRF82 build on my nexus one for a week and it's simply great. Here are some key points you are going to receive with the froyo update:

  • Everything running faster! really faster. You can  really spot the difference in native apps, 3rd party apps or even in web pages. Froyo is much much faster and seems more stable than 2.1
  • Battery life is great! before froyo i needed to charge my phone about twice a day (under moderate to heavy usage). Now it can easily survive more than a day, no matter how much I use the device.
  • Flash provides full web experience. Despite it is still beta and not really designed for touch screens and multi touch still without flash the web is not full. Flash on Froyo seems quite stable and most of the flash content runs smoothly. Even complicated Flex applications run quite stable on provided Flash Runtime.
  • Better Accounts syncronization. Before froyo update although i had 4 google accounts registered on the device, i was able to use only the main accounts calendar. Now all calendars under all accounts can be used.
  • Internet tethering. This one is even enough to have a reason to upgrade. You can tether your mobile data either via usb or converting the phone to a wifi hotspot. 
  • Many tiny UI and functionality enhanchements such as the cam and the phone icon on the home screen.
This are the main key upgrades for end users, however, froyo offers much more for developers. Android SDK 2.2 brings great new and upgraded features.
    Well done Google, it was worth to wait. Let's see when will the "Gingerbread" be available to download.

    Monday, 28 June 2010

    What's up with Java Store??

    Java Store was one of the key points of last years JavaOne. James Gosling who is known as the father of the store, personally demonstrated the JavaStore.

    It has been a year, there should have been a JavaOne by today if Oracle did not have bought Sun and the new Oraclised JavaOne is ahead but still there is not much news from JavaStore. Sun could not make it available worldwide (anywhere outside US), hopefully Oracle will but still JavaStore is only available in US. After Gosling's departure it seems like Java Store lost its voice. Honestly, JavaStore would be a good centralized market for JavaFX apps and would drive JavaFX to a better place.

    By that time Apple doubled the size of app store, formed a new bransh for the new comer iPad, Google had good job with Android Market and although JavaStore is taking it slowly still there is not much similar market for desktop apps.

    So why not Oracle? Open it to whole globe by JavaOne 2010 and do what apple does to mobile... Still not that late..

    Wednesday, 2 June 2010

    After Google I/O 2010

    I/O 2010 is over and we ions already started waiting for may 2011. This years I/O was tremendous. The two day even was full of sessions worth to cover a week. Since the sessions run in parallel, I had missed most of the ones I wanted to attend. This year there was also a 1 day bootcamp event (of 101 sessions) prior to Google I/O. That was really well taught (good job Steph), however, I strongly believe this bootcamp should be available for all I/O attendees and should be a part of conference. May be even users (such as from user groups) can present 101 sessions.

    When I was on my flight to San Francisco, honestly I was more interested in GWT and App Engine than Android, but during the conference android sessions occupied majority of my time. There is a move to Android and I was so surprised since few months ago I didn't observe such an Android passion while I was there.  The city is full of android/droid ads, 80% percent of the phones which carriers offer are powered by Android. I really wonder if this Android wave would hit europe.

    Google is great, they are so inspiring in innovation. Apple has always been good on building the devices which no body ever think of (imagine ipad, or the iphone which came out to market without a gps and multitasking) but google is great on building what you ever really need. All the product, software and API announcements really hit our hearts.

    Lets start with Android, Android is backed up with an unbelievable momentum from vendors, carriers and consumers. Currently there is an Android army of over 80 devices from several vendors and 80% percent of the phones offered by the carriers are powered by Android. Honestly I always find versioning would be a great problem for Android due to different hardware specs from different vendors. However It seems like both vendors and developers are handling the situation well and most probably the market would not be divided between more than two major versions. Android 2.2 is bringing great stuff to the platform, server push notifications, including installing software which has been triggered from your desktop computer and using intentions with push messages are really rocking inspiring stuffs for a developer. One of the top feature on the waiting list, internet tethering is already announced to be released on 2.2. By the way I managed to use Android tethering on my HTC Sprint Evo 4G which was a wonderful experience (imagine me, abroad with one free data line and 3 other wifi hungry devices). I/O offered nice sessions giving tips one handling different versions, using best practices  and introducing the new features. Don't need to mention that google emailed each attendee for sending them and android device (nexus one or droid depending on location) which was smart since people could start playing with apis and the device much before they come to the conference. But Google also gave a brand new HTC Sprint Evo 4G device which has a incredible 4.7" screen size with 8mp camera (720p video shooting), dual led flash and an incredible HDMI output. Its so sad that the deice is CDMA only and locked up to Sprint, since I'm already on my flight back to europe. Well still I have nice digital photo frame with an embedded cam :)

    App Engine is getting quite mature and either you prefer to use python or java it has a lot to offer. One of the most interesting sessions I attended was Next Gen Queries, which would loosen the strings on usage of BigTable. App engine is a great backend alternative for any web or mobile app. This time last year I was struggling to make jersey work on app engine, which I failed. However today most of the frameworks including jersey are available to run on app engine, but the wreak great news was using Spring's Roo on App Engine which is fast, easy and elegant to implement. I am planning to post more on this stuff and encourage everyone to watch the related sessions as soon as they become available online (also in HD).

    Another big news is the GoogleTV. It is an android powered device with chrome on top and supporting flash. GoogleTV is just a proof that Android is very capable and flexible. CEOs of Sony, Logitech, BestBuy, Adobe and more were on stage to show the support and integration. Honestly I am very excited and surprised with the smooth experience which GoogleTV offers. The SDK is told to be released soon and the hardware would be available by fall 2010. Just after mobile phone market, Google shows how they are willing to enter any field where there is place for ads.

    GWT had a huge leap with version 2 which was pre announced last year. GWT 2.1 with HTML5 is a great alternative to any plugin based rich client platform (such as flash, silverlight...). Everybody expected a stable release of ChromeOS. Although I didn't have time to attend any chromeOS session, I don't think there is any shocking news on chrome side (at least not on keynotes). I really wonder if Google would drop ChromeOS and will go on with Android for netbooks and other light devices. Actually GoogleTV also proves Android powered Chrome browser will be strong, capable and flexible platform.

    The keynote sessions are available (also aired live) and sessions to be told online very soon (even could have been online by the time you are reading this post).

     It is free, it is hd, well they will not give you freebies but still these sessions are one of best available online!!

    Tuesday, 4 May 2010

    Java Developer Diaries; A month of Mobile Development



    Minute 1, Unpacking...
    iPhone: Wow nice packaging and an impressive device!! So excited let's turn it on!!
    Android: Hmm ok doesn't look as trendy as iPhone but definitly thats something close.
    Windows Mobile: Dad can we switch our phones! Ok, ok I'll give a try.
    Blackberry: Oh this one seems even worse than win mobile, well at least I should be a manager at some corporation since I get this.

    Minute 3, Start using the phone
    iPhone: Hey why do I need to connect to iTunes to start using this?!? Ok seems like Apple is locking me up... Let me boot up my laptop
    Android: Wow that was easy, hey mum its me calling this is my new phone, yeah you are right it has another mic for noise canceling thats why it is so quite..
    Windows Mobile: Hmm its says it has a HD display, nice.. well how bad can this be.
    Blackberry: Ohh no!! I am not a manager I got this device for development, hey anybody I want to have a big screen and less buttons please!!

    Minute 5, checking the features
    iPhone: Ok seems like its worth to wait, iTunes already transfered my music, pics, contacts and also backed up my phone!! Lets find some apps to install!!!
    Android: Hmm the app market doesn't look bad, at least most of them are free but wait seems like I will miss my favourite iPhone apps. The live wallpaper feature is great!!
    Windows Mobile: Seems like I will have the best full GPS apps!! Hey wait how come the memory is full, it has been just five minutes!!!
    Blackberry: Well at least this thing supports Java. Wait need the call the BES admin to activate my data line.

    Minute 10, apps, apps, apps...
    iPhone: Ok,ok I'll quit playing and start working on the phone. It was easy to set up my email accounts. The GPS and the cam is not great but its is ok since I won"t be carrying a dedicated cam and gps. This thing looks great! Lets start reading some on development.
    Android: Hmm interesting there are less apps and not all are as fun as iPhone apps but suprisingly these apps can perform much more than iPhone counterparts. This device is multitasking and apps can register themselves as services, hmm should be exciting to develop on.
    Windows Mobile: Hmm nice set of apps. Well not trendy but lots of apps from different vendors, wish I there was a central store or something which I can browse them all.
    Blackberry: Ok i got my BES activation, wow I got my emails even before my laptop. But the gps is a huge disappointment just as the app store. Well this thing is Java I"m going to write whatever i want!!

    Hour 1, ok time to work...
    iPhone: Wait no Java, no Flash, God nooooooo!!
    Android: Wow, thats fun its all Java... and much much capable than JavaME. Everything is already eclipse integrated. All I have to do is to start downloading!!!
    Windows Mobile: Oh its just JavaME or .net compact framework. Hey wait a service is down, what it is the phone service, what the hell is the phone is for if the phone service is down!! This feels like the same windows I have on my desktop!!
    Blackberry: Hmm, thats interesting its all JavaME based, however, it is a superset with RIM specific APIs. I need to find more docs and samples, well nice the development platform is on eclipse but wait its for windows only!!

    Hour 6, starting development
    iPhone: What the hell is this Objective-C thing and why do I have to use a Mac!! Hey boss, I need a mac if you want this app complete hehe... and can we also order some books on Objective-C
    Android: Hey I got my first application running on emulator. Ok doesn't seem as shinny as an iPhone app but I made it work!!
    Windows Mobile: Hmm this C# thing is not very different than Java, well at least except for the substring method. But I need to setup Visual Studio or go back to JavaME.
    Blackberry: The SDK and tools are suprisingly great but I still feel a little limited with this JavaME superset.

    Hour 12, language and the tools
    iPhone: I still dont get a single word from this Objective-C thing. What is synthesize, why do I need to create so many files, how can a syntax can be so complicated and different. I need more time read!!! Oh nooo pointers are back and there is no garbage collection!!!
    Android: Ok this syntax seems so but this is not just Java! I need to learn about APIs, capabilities and the SDK.
    Windows Mobile: Ok don't need this phone for a while I'll just stick with JavaME and emulators. I will get you back when I'm done.
    Blackberry: This thing is definitly not an iPhone or an Android but at least a bit more than JavaME and has a proper development platform.

    Day 2, SDK and APIs
    iPhone: The battery was already flat. I am still reading, I must admit Objective-C seems very organized but I still not sure if I can call a method (or should i say send a message).
    Android: I am confused most of the books are for old sdks. The project examples are nice but I need more documentation!
    Windows Mobile: Ok I got my first JavaME app running on the emulator. Hmm so limited limited for so much ram and cpu...
    Blackberry: My first app is running on the emulator!! It is much easier to use networking, GPS, cam etc... but this is definitly not much than JavaME. When compared to Android and iPhone there are no build in patterns and the programming model is not very organized unless you develop your own framework in the first place.

    Day 4, Deep in development
    iPhone: Hmm seems like I am getting used to Objective-C. I'm still trying to use eclipse shortcuts on Xcode but  I'll be ok. I must admit the language seems nice and organized but its really different than Java. Well at least there are lots of books with different fruits on the cover.
    Android: When compared to iPhone, there are so little choice of books but I still can survive thanks to community and the low learning curve. I feel the sdk permits you to perform whatever you can dream of. This device is definitly the dream development platform.
    Windows Mobile: Ups that not good, JavaME doesn't really fit this device and it doesn't seem native either. I need to switch back to .net. Oh god memory is full again!! Why applications does not have a close button. I wish this device did not support multitasking like iPhone!
    Blackberry: Gosh, the device is locked up, time to remove the battery. I just learn "removing battery" is a well known term for blackberry development. Now that I see how superior is iPhoneOS, can you imagine a blackberry without a removable battery like iPhone!!

    Day 7, Deeper in development
    iPhone: Here is my first app running in the simulator. Wow the simulator is great! and I'm much used to Objective-C. Using Interface Builder for UI is great and the built in components look fantastic!! Everything is just so native and binding UI with your code is so elegant!! I really start appreciating the development model.
    Android: Wait building UI was easy at the beginning but I'm bored binding this R class to references via code. Why don't they come up something like Apple's Interface Builder which is much more cleaner. I managed the deploy my first app on my phone. Seems just like the emulator!!
    Windows Mobile: Although Visual Studio is much different, C# seems friendly for a Java developer and it seems much capable than JavaME.
    Blackberry: I wish I had more resources and examples on Blackberry specific APIs. Managed to deploy my first app on my phone, oh wait it doesn't work. How could I know the simulator and the real device needed different parameters for network connection. Seems like I need to add an "if" for the simulator...

    Day 10, Development Model
    iPhone: Still need to check the books while typing but I am really impressed with the programming model. MVC, Delegates, Flyweight, Observers are all integrated and are in use even you do not realize.
    Android: I can do anything on this phone, remote debugging works great and emulators can reflect the real device. Apps can trigger other apps or share data with each other. But I must confess I envy iPhone's UI programming model, sms application and its ipod feature with the cover flow.
    Windows Mobile: I hate stylus, I hate windows 3.1 looking UI components, I have building UIs thinking how people use it with nails. I am ok not to have multi touch but why the stylus!!!
    Blackberry: This screen is small, there is no sleeky UI components, even the default apps have just white background with some black text. I need more space more build in stuff!!! Oh by the way I managed to create an uninstallable app on my phone, wonder how will I get rid of it.

    Day 13, OS Update
    iPhone: New OS no problem, just install the new SDK bundled with Xcode. iTunes should already handle d the update of my phone even before I download the sdk.
    Android: Great eclipse downloads the new sdk, just change the projects sdk and voila... but wait my phone is stuck on this firmware!!! Oh god now that I learn older devices are even stuck at 1.5 and 1.6. Google says I need to contact my device provider but wait isn't all those open source stuff, how can I not build it myself... or is it not???
    Windows Mobile: New OS?? Need to wait and pay for the one specific to my device. Is this a Windows tradition? I should have waited the first service pack version. Now my memory exhaust faster and even my battery dies faster.
    Blackberry: Very smooth to update the sdk. Also not very hard to update the phone's OS. But really not sure what the new version brings everything seems same.

    Day 18. Running on device
    iPhone: Wait, do I really need to pay Apple to test my app on my own phone?!? Is this a joke. Gosh I need to wait until they issue a developer certificate.
    Android: I still wonder which SDK I should be targeting. Why can't they keep all devices uptodate just like apple? Seems like 1.5 and 1.6 is majority for now, but should I target 2.0 and hope them to get an update soon??
    Windows Mobile: For whom it may concern, By today I am willing to resign from my job on my own request. I wish you all good luck!
    Blackberry: Seems like I should be building different CODs for different SDK versions. Hopefully BES will handle them.

    Day 24, Deployment
    iPhone: Ok I got my cert, now need to download something to my keychain them upload something to generate something else then to download that to sign my app and deploy it to the phone.Wow thats confusing, why so much security?? Better not to miss any steps, Apple's online documentation works well if you are careful enough.
    Android: Build my app, done my test and sending to market.. Hey boss can I keep the phone for another week to pla.. ehmm incase something goes wrong with the app?
    Blackberry: BES admin just informed me that my app must be signed in order to be able to deployed for older versions. By the way the BES admin told me that he remotely distributed my app but my phone still doesn't have it. He says i need to wait from 2 hours to 48 hours?!?

    Day 30, The end
    iPhone: I managed to sign my app to send for Apple's approval which is more complicated than building for my own device. Be careful at following the documentation. Oh wait, Apple already refused my app!!! They say I need to go and read the HIG?!? Oh seems like it is the Human Interface Guide telling how apps should be to be used on Applish devices.. Well should be ok after I reflect the changes (as long my app is written originally with Objective-C without any compability layer and does not try to replace any existing functionality of the platform). Honestly there are so many rules but developing for iPhone (aka iPad) with Objective-C is fun!!! I would definitely continue developing!!
    Android: Well this device does not have the looks and feel of the iPhone but seems it is much more fun for a developer to use and feels more comfortable to work on. But I still wonder about version changes and although this one seems fun iPhone seems more promising to build and sell an application if you have a nice idea.
    Blackberry: Blackberry support couldn't manage to help, BES admins did not find any clue and at the end we found that something about the certificate was failed because the BES is behind a proxy but how on earth I could understand that without any error log and waiting for 48 hour periods between each deployment!!


    *No offence, this post is just fiction with some humor and some real experience. I had used windows mobile more than 1.5 years, developed commercial software on compact framework using C#. Never had my own Blackberry but used most of the models and developed commercial software on the platform with my own custom MVC framework. I had been a iPhone user more than 1.5 years and has developer certificate about a year. Tried every possible way before learning Objective-C and at the end bought several books and developer some not commercial apps and also posted tutorials on iphone development. I have been an HTC Ion (android) user for a year and since then observing the sdk and tools. Very soon getting my Nexus One at Google I/O.

    **For a year although I own both an iPhone and an Android Ion, I preferred to use iPhone as my primary phone. Very soon I am switching to Nexus One and leaving my old iPhone as a developer device. So you as you might see I had to decide to use one platform to other at a point of my life..

    Saturday, 17 April 2010

    Apple, iPhone OS4 and the others (or should I say "vs others")

    Last week Steve Jobs announced iPhoneOS4 personally. Besides the new APIs, multitasking and all the other nice features, I'm sure no one was expecting to see flash support but even more Jobs closed the gates of App Store to all binaries which are built using a compability layer including Flash CS5, which has an export tool, just few days before Adobe's CS5 release.
    “3.3.1 … Applications must be originally written in Objective-C, C, C++, or JavaScript as executed by the iPhone OS WebKit engine, and only code written in C, C++, and Objective-C may compile and directly link against the Documented APIs (e.g., Applications that link to Documented APIs through an intermediary translation or compatibility layer or tool are prohibited).”
    Jobs responded comments as such compability layers produce substandard apps which might be true in terms of performance and memory but the way and timing of the announcement, seems like Jobs really wants to hurt Adobe.  Although OS4 is going to bring great features, this version change became more popular with discussions over the latest prohibition. Jobs did this version change trick to change the rules when he returned to Apple. In 1997 Mac OS 7.7 was renamed to 8 to change the licencing and stop production of mac clones which Apple licenced to third party manufacturers.

    There is also one more item in the agreement trying to stop comments about the statement.
    “10.4 Press Releases and Other Publicity. You may not issue any press releases or make any other public statements regarding this Agreement, its terms and conditions, or the relationship of the parties without Apple’s express prior written approval, which may be withheld at Apple’s discretion.”
    Oh by the way iTunes on windows does not even use native OS's apis, it even uses custom scroll bars on Windows OS which might be calles illegal if Microsoft had such a term in Windows's agreement.

    No matter what Nokia and RIM says Apple is the main player smart phone market. RIM sells blackberries to corporations, and they like to buy it since its labeled as an office device. Also they have the advantage of secure data connection to Blackberry Enterprise Server but if they can not keep up their device hardware and software up to date those issues can change really fast. Look at Windows Mobile, they used to have a such advantages too (and see where they are now). Does anybody still really use them? If RIM is still under the illusion of best selling smart phone producer (as they mention in every presentation or announcement) it has already been to late for them. Nokia already left the higher end device market. They produce cheap and basic phones and sell in high quantities. Nobody really targets RIM and Nokia when building web sites but iPhone. This issue is hurting Adobe and pushing designers away from Flash.

    Release of flash free iPad and the announcement of the SDK agreement change may seem as a bold move but if we go back to first announcement of iPhone when there were no applications in app store and the all other mobile world was full of JavaME apps, that time Jobs left Java out of iPhone calling Java as a ball and chain.

    I understand Jobs that he wants to control the apps distribution on mobile market and find it reasonable (although personally i would prefer a not closed device). Mobile devices are not computers, they are limited and mostly target communication and connectibility. Most of the time you wont have time to reboot or reinstall things. So Jobs vision of controlling software on those devices work as a safe guard preserving the stability. However, iPad is a bit more than a mobile device so limiting it to app store is just making it not attractive for geeks. Jobs does not want Java and Flash not only they form another layer o top of OS to run the application, he does not want them because they can execute arbitary code which might be downloaded from web or somewhere else out of app store. I also understand Jobs's concern about the problems of the compability and transformation layers. Lets say what if Flash becomes the main development platform for iPhone and Apple introduces a new API which Adobe does not integrate into Flash's iPhone App support.  Such an issue would definitly collapse the innovation. But what about projects like Unreal Engine on iPhone. I think with the current SDK it would not be legal for such an engine to run UnrealScript although Unreal Engine seems like a great match for iPad!

    Also it seems like Jobs did not forget Adobe to declare Windows as their primary development platform in 1996 while Apple was struggling about financial issues.

    So what will happen now? Well Adobe is quite angry, internet is full of sites showing their anger. Some employees even telling they stop using macbooks and buying music on iTunes. Apple is taking another bet. When they introduced iPhone to mobile world, they did not have lots of apps and developers community who knows objective-c where there were many JavaME developers. They refused Java and continue their way, dominating the mobile world and building a huge app store. With OS4 finally they are introducing multitasking, folders and other achievements. Also I am expecting to see a major hardware and design upgrade on the device.  Defintely they will continue pushing developers to build native  objective-c apps. Meanwhile Google's Android army is finally ready. The long development process finally built a nice, open and extensible OS, which is rumored to be use on tablets and even on ebook readers! Google's effort to make manufacturers to build sleeky devices finally made new sexy devices to be available such as Nexus One, Desire, Legend, Droid. Android's SDK is built on Java and is very extensible, which qualifies Android as a dream platform for a developer. However time will show how other consumers will react to the device. For sure Android has a great advantage. They have full support for Java and Flash which are the platforms of the modern web.  Also unlike Apple announcing an upgrade yearly, a new Android device is announced every day. Besides they have huge problem of versioning and device support. I still use Android 1.6 on my Ion developer device (come on its a developer device, I expect to see new platform upgrades available instantly!).

    So for now Apple seems alone vs everyone. Although they also get hurt by not supporting flash (no flash support means no real web experience) they definitely hurt Adobe more. The new OS4 looks promising but without a major hardware and design upgrade, android may take up the lead. I'm sure Jobs is preparing a great suprise for June.

    Well so for now if you want to develop on iPhone grab a Objective-C book...

    Friday, 16 April 2010

    My Story on Google

    If you had watched Google's Parisian Love ad and like it, now its time for you to create your own. Just visit the Search Stories page, which is a smart and very easy to use flash application. Addd some key words, choose a music and your story is ready. I created a couple and here is one of them...

    Tuesday, 16 March 2010

    Android as SOA player


    There is no argue with the fact that one of the most important parts of SOA is to provide business processes combined with human interaction, meaning that an interruption occurs until a person interacts with the system by performing an action on a waiting task to make the process flow. Therefore, it is crucial to provide a medium for human interaction to accelerate the work behind the business process. No doubt that the mobile world is growning very fast providing connection options to Internet supported by GSM operators. The pattern of combining these two trends into IT structure has been used in most SOA implementations.


    Whatever the target businesses of an application, it gets more attention by the users once it is supported by the mobile platform. This is why I tried to develop an Android application as a client of composite application developed in Oracle SOA Suite environment. The composite application is TranslationService mentioned in my last blog post. Briefly, it implements client of Google's RESTful service that translates any statement from a source language to a target language. Mediator component in SOA composite application's and its implementation detail is given in my last post, but Java code of Mediator's callout class is given in lowermost part. The Android application's screen design is given in Figure 1, including all of the necessary fields required by the translator client. Source text, language and target language values are prompted first, and then the Translate button is used to perform translation service call at Oracle SOA Suite side. The result is displayed at a particular field and the Reset button rearranges the screen to make it ready for further translations.



    Figure 1
    Figure 1



    Available mobile platforms have several disadvantages that should be taken into account carefully. Extra server or product installation requirement or application signing procedure complexity are examples of these obstacles. I think Android, as a Java developer friendly environment, is pretty enjoyable and a simple mobile application development platform. First of all, it is based on Java and XML technologies similar to trendy and effective platforms. It supports resource bundle usage by also supporting internationalization. Screen development consists of just designning an XML resource with binding a Java bean. Such resources created during demo application are given below.


    XML SOURCE CODE ::
    <code lang="xml">
    <?xml version="1.0" encoding="utf-8"?>
    <AbsoluteLayout
    android:id="@+id/varTitle1"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    xmlns:android="http://schemas.android.com/apk/res/android"
    >
    <TextView
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="@string/welcomeToSample1"
    />


    <TextView
    android:id="@+id/varInputText_1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/inputText"
    android:layout_x="40px"
    android:layout_y="32px"
    >
    </TextView>
    <EditText
    android:id="@+id/varInputText"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text=""
    android:layout_x="200px"
    android:layout_y="32px"
    >
    </EditText>


    <TextView
    android:id="@+id/varSLang_1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/sourceLang"
    android:layout_x="40px"
    android:layout_y="82px"
    >
    </TextView>
    <EditText
    android:id="@+id/varSLang"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text=""
    android:layout_x="200px"
    android:layout_y="82px"
    >
    </EditText>


    <TextView
    android:id="@+id/varTLang_1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/targetLang"
    android:layout_x="40px"
    android:layout_y="132px"
    >
    </TextView>
    <EditText
    android:id="@+id/varTLang"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text=""
    android:layout_x="200px"
    android:layout_y="132px"
    >
    </EditText>


    <Button
    android:id="@+id/btnTranslate"
    android:layout_width="87px"
    android:layout_height="wrap_content"
    android:text="@string/button1"
    android:layout_x="40px"
    android:layout_y="282px"
    >
    </Button>

    <TextView
    android:id="@+id/varResult_1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/resultTrans"
    android:layout_x="40px"
    android:layout_y="332px"
    >
    </TextView>
    <TextView
    android:id="@+id/varResult"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text=""
    android:layout_x="200px"
    android:layout_y="332px"
    >
    </TextView>
    <Button
    android:id="@+id/btnReset"
    android:layout_width="87px"
    android:layout_height="wrap_content"
    android:text="@string/button2"
    android:layout_x="40px"
    android:layout_y="382px"
    >
    </Button>
    </AbsoluteLayout>



    JAVA BEAN SOURCE CODE ::

    package com.example.android.helloactivity;

    import org.ksoap2.SoapEnvelope;
    import org.ksoap2.serialization.PropertyInfo;
    import org.ksoap2.serialization.SoapObject;
    import org.ksoap2.serialization.SoapSerializationEnvelope;
    import org.ksoap2.transport.AndroidHttpTransport;

    import android.app.Activity;
    import android.os.Bundle;
    import android.view.View;
    import android.widget.Button;
    import android.widget.EditText;
    import android.widget.TextView;

    public class HelloActivity extends Activity {
    private EditText inputText;
    private EditText sourceLang;
    private EditText targetLang;
    private TextView resultText;
    private Button translateButton;
    private Button resetButton;

    private static final String SOAP_ACTION = "execute";
    private static final String METHOD_NAME = "translationSource";
    private static final String NAMESPACE = "http://xmlns.oracle.com/singleString";
    private static final String WSURL = "http://192.168.2.4:8001/soa-infra/services/default/TranslationServiceProject/TranslatorMediator_ep?WSDL";

    @Override
    public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.hello_activity);
    initControls();
    }

    private void initControls() {
    inputText = (EditText) findViewById(R.id.varInputText);
    sourceLang = (EditText) findViewById(R.id.varSLang);
    targetLang = (EditText) findViewById(R.id.varTLang);
    resultText = (TextView) findViewById(R.id.varResult);
    translateButton = (Button) findViewById(R.id.btnTranslate);
    translateButton.setOnClickListener(new Button.OnClickListener() {
    public void onClick(View v) {
    translate();
    }
    });
    resetButton = (Button) findViewById(R.id.btnReset);
    resetButton.setOnClickListener(new Button.OnClickListener() {
    public void onClick(View v) {
    reset();
    }
    });
    }

    private void translate() {
    resultText.setText("error occured");

    SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);

    PropertyInfo pi1 = new PropertyInfo();
    pi1.setNamespace(NAMESPACE);
    pi1.setName("input");
    pi1.setType(String.class);
    pi1.setValue(inputText.getText().toString());
    request.addProperty(pi1);

    PropertyInfo pi2 = new PropertyInfo();
    pi2.setNamespace(NAMESPACE);
    pi2.setName("sourceLanguage");
    pi2.setType(String.class);
    pi2.setValue(sourceLang.getText().toString());
    request.addProperty(pi2);

    PropertyInfo pi3 = new PropertyInfo();
    pi3.setNamespace(NAMESPACE);
    pi3.setName("targetLanguage");
    pi3.setType(String.class);
    pi3.setValue(targetLang.getText().toString());
    request.addProperty(pi3);

    SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
    SoapEnvelope.VER11);
    envelope.setOutputSoapObject(request);
    AndroidHttpTransport androidHttpTransport = new AndroidHttpTransport(
    WSURL);
    try {
    androidHttpTransport.call(SOAP_ACTION, envelope);

    // Get the SAOP Envelope back and the extract the body
    SoapObject resultsRequestSOAP = (SoapObject) envelope.bodyIn;
    if(resultsRequestSOAP != null && resultsRequestSOAP.getProperty("output") != null)
    resultText.setText(resultsRequestSOAP.getProperty("output").toString());


    } catch (Exception E) {
    System.out.print("ERROR:" + E.getClass().getName() + ": "
    + E.getMessage());
    }
    }

    private void reset() {
    initControls();
    }
    }



    When analyzing the source code, you will see usage of kSOAP framework that helps on calling a web service via Java mobile platform. At that point, usage of such a memory consuming framework in mobile appliation can be discussed. But, I only aimed to create a client of a SOA composite application, thats scenario and details are mentioned before. While researching the topic, I came across with kSOAP and it seemed worth to try. The main problem with the framework was namespace conflict, although the target namespace value was given to the root node, it was not assigned to the given parameters. This caused namespace conflict at the service side. As given at the source code, I needed to assign the same namespace value to each parameter manually. Finally, I am able to say that the combination of these technologies worked well. Figure 2 shows the result of Android application that with respect of given input values, the translation result was displayed at Result field. As analyzing effects at Oracle SOA Suite 11gR1 product side, Figure 3 shows the log output of composite application provided by the callout class.


    Figure 2
    Figure 2


    Figure 3
    Figure 3




    MEDIATOR'S JAVA CALLOUT SOURCE CODE ::

    package com.eteration.sample;

    import java.io.BufferedReader;
    import java.io.IOException;
    import java.io.InputStreamReader;
    import java.io.OutputStreamWriter;

    import java.net.HttpURLConnection;
    import java.net.MalformedURLException;
    import java.net.ProtocolException;
    import java.net.URL;

    import java.util.Iterator;

    import java.util.Map;

    import javax.xml.parsers.ParserConfigurationException;

    import oracle.tip.mediator.common.api.AbstractJavaCalloutImpl;
    import oracle.tip.mediator.common.api.CalloutMediatorMessage;
    import oracle.tip.mediator.common.api.MediatorCalloutException;
    import oracle.tip.mediator.utils.XmlUtils;

    import org.w3c.dom.Node;

    import oracle.xml.jaxp.JXDocumentBuilder;
    import oracle.xml.jaxp.JXDocumentBuilderFactory;
    import oracle.xml.parser.v2.NSResolver;
    import oracle.xml.parser.v2.XMLDocument;
    import oracle.xml.parser.v2.XMLElement;
    import oracle.xml.parser.v2.XMLNode;

    import oracle.xml.parser.v2.XMLText;

    import org.json.simple.JSONObject;
    import org.json.simple.JSONValue;

    public class TranslatorMediatorCalloutClass extends AbstractJavaCalloutImpl {
    private static String googleTranslationService =
    "http://ajax.googleapis.com/ajax/services/language/translate";

    @Override
    public boolean postRouting(CalloutMediatorMessage calloutMediatorMessage,
    CalloutMediatorMessage calloutMediatorMessage2,
    Throwable throwable) throws MediatorCalloutException {
    boolean returnValue =
    super.postRouting(calloutMediatorMessage, calloutMediatorMessage2,
    throwable);
    String sPayload = "null";
    for (Iterator msgIt1 =
    calloutMediatorMessage.getPayload().entrySet().iterator();
    msgIt1.hasNext(); ) {
    System.out.println("Google Translator postRouting4");
    Map.Entry msgEntry = (Map.Entry)msgIt1.next();
    Object msgKey = msgEntry.getKey();
    Object msgValue = msgEntry.getValue();
    sPayload = XmlUtils.convertDomNodeToString((Node)msgValue);
    try {
    XMLDocument changedoc = XmlUtils.getXmlDocument(sPayload);
    XMLNode inputS1 =
    (XMLNode)changedoc.selectSingleNode("//inp1:input",
    new LocalNamespaceResolver());
    System.out.println("the value of the source text = " +
    inputS1.getTextContent());
    XMLNode inputS2 =
    (XMLNode)changedoc.selectSingleNode("//inp1:sourceLanguage",
    new LocalNamespaceResolver());
    System.out.println("the value of the sourceLanguage = " +
    inputS2.getTextContent());
    XMLNode inputS3 =
    (XMLNode)changedoc.selectSingleNode("//inp1:targetLanguage",
    new LocalNamespaceResolver());
    System.out.println("the value of the targetLanguage = " +
    inputS3.getTextContent());

    XMLDocument doc =
    prepareReturnMessage(inputS1.getTextContent(),
    inputS2.getTextContent(),
    inputS3.getTextContent());
    if (doc != null) {
    String mykey = "reply";
    calloutMediatorMessage2.addPayload(mykey,
    doc.getDocumentElement());
    }

    } catch (Exception e) {
    System.out.println(e);
    }
    } //for
    return returnValue;
    }

    private XMLDocument prepareReturnMessage(String input,
    String sourceLanguage,
    String targetLanguage) throws ParserConfigurationException {
    JXDocumentBuilderFactory factory =
    (JXDocumentBuilderFactory)JXDocumentBuilderFactory.newInstance();
    JXDocumentBuilder documentBuilder =
    (JXDocumentBuilder)factory.newDocumentBuilder();
    XMLDocument doc = (XMLDocument)documentBuilder.newDocument();
    doc.setVersion("1.0");
    doc.setEncoding("UTF-8");
    XMLElement rootElement =
    (XMLElement)(doc.createElementNS("http://xmlns.oracle.com/singleString",
    "translationResult"));
    doc.appendChild(rootElement);
    XMLElement inputElement = (XMLElement)(doc.createElement("output"));
    rootElement.appendChild(inputElement);
    String translation = this.translate(input, sourceLanguage, targetLanguage);
    System.out.println("translation result = " + translation);

    if (translation != null && translation.equalsIgnoreCase(input))
    return null;

    XMLText translationElement = (XMLText)doc.createTextNode(translation);
    inputElement.appendChild(translationElement);
    return doc;
    }

    class LocalNamespaceResolver implements NSResolver {
    public String resolveNamespacePrefix(String prefix) {
    return "http://xmlns.oracle.com/singleString";
    }
    }

    private static String extractTranslationFromJSON(String response) {
    final JSONObject jsonObj = (JSONObject)JSONValue.parse(response);
    String translation = null;
    if (jsonObj != null && jsonObj.containsKey("responseData")) {
    final JSONObject responseData =
    (JSONObject)jsonObj.get("responseData");
    translation = responseData.get("translatedText").toString();
    }
    return translation;
    }

    public static String translate(String sourceString, String sourceLanguage,
    String targetLanguage) {
    return extractTranslationFromJSON(translateString(sourceString,
    sourceLanguage,
    targetLanguage));
    }

    private static String translateString(String sourceString,
    String sourceLanguage,
    String targetLanguage) {
    HttpURLConnection connection = null;
    OutputStreamWriter wr = null;
    BufferedReader rd = null;
    StringBuilder sb = null;
    String line = null;

    URL serverAddress = null;

    try {
    serverAddress =
    new URL(googleTranslationService + "?v=1.0&&q=" + sourceString.replace(' ','+') + "&&langpair=" + sourceLanguage + "%7C" + targetLanguage);
    connection = null;
    connection = (HttpURLConnection)serverAddress.openConnection();
    connection.setRequestMethod("GET");
    connection.setDoOutput(true);
    connection.setReadTimeout(10000);
    connection.connect();
    rd = new BufferedReader(new InputStreamReader(connection.getInputStream()));
    sb = new StringBuilder();

    while ((line = rd.readLine()) != null) {
    sb.append(line + '\n');
    }

    return (sb.toString());

    } catch (MalformedURLException e) {
    e.printStackTrace();
    } catch (ProtocolException e) {
    e.printStackTrace();
    } catch (IOException e) {
    e.printStackTrace();
    } finally {
    connection.disconnect();
    rd = null;
    sb = null;
    wr = null;
    connection = null;
    }
    return null;
    }
    }

    Monday, 8 March 2010

    Custom ToolTip on NavBar and TabBar components

    In Flex, when you want to give a tool tip text for visual component that extends UIComponent class, set the value of toolTip property with the desired text.
    However, it is possible to create custom ToolTips for your visual components by implementing mx.core.IToolTip interface in your custom component. After creating a custom component, you should add a handler to override the basic toolTip mechanism of the target component by intercepting toolTipCreate event.

    You can find lots of samples about customization of toolTips in the blogs and adobe's website http://livedocs.adobe.com/flex/3/html/help.html?content=tooltips_4.html .

    Here, I wanted to show how to customize toolTips on NavBar and TabBar subclasses (such as ButtonBar, LinkBar, and ToggleButtonBar) support ToolTips in their data providers.

    Firstly, I showed how to assign toolTips for the children in BasicToolTipButtonBar.mxml component. Here, toolTipField property of ButtonBar is used to specify which field of dataProvider array will be displayed as tooltip.

    <?xml version="1.0" encoding="utf-8"?>
    <mx:ToggleButtonBar xmlns:mx="http://www.adobe.com/2006/mxml"
    labelField="name"
    toolTipField="code" dataProvider="{courseList}">

    <mx:Script>
    <![CDATA[
    [Bindable]
    private var courseList:Array = [{name:'C Programming', code:'C140'},
    {name:'PL Concepts', code:'C242'}, {name:'Software Engineering', code:'C350'}];
    ]]>
    </mx:Script>
    </mx:ToggleButtonBar>

    After this basic sample, I took a step forward to customize the displayed toolTip in CustomToolTipButtonBar.mxml component. I used a Panel container as custom component to display course info on it. To achive this, you should implement a tricky solution by intercepting the children components' creations in the navigation bar and adding ToolTipEvent.TOOL_TIP_CREATE event listener for all of them. The rest is the same when you customize a toolTip.

    <?xml version="1.0" encoding="utf-8"?>
    <mx:ToggleButtonBar xmlns:mx="http://www.adobe.com/2006/mxml"
    labelField="name"
    toolTipField="code" dataProvider="{courseList}"
    updateComplete="updateCompleteListener(event)">

    <mx:Script>
    <![CDATA[
    import mx.controls.Button;
    import mx.events.FlexEvent;
    import mx.events.ToolTipEvent;
    [Bindable]
    private var courseList:Array = [{name:'C Programming', code:'C140'},
    {name:'PL Concepts', code:'C242'}, {name:'Software Engineering', code:'C350'}];

    private function updateCompleteListener(event:FlexEvent):void {
    if (this.getChildren() == null) {
    return;
    }
    for each (var btn:Button in this.getChildren()) {
    btn.addEventListener(ToolTipEvent.TOOL_TIP_CREATE, onCreateToolTip);
    }
    }

    private function onCreateToolTip(e:ToolTipEvent):void {
    var btnLbl:String = Button(e.target).label;
    var toolTipLbl:String = Button(e.target).toolTip;

    var customToolTip:ToolTipComponent = new ToolTipComponent();
    customToolTip.title = "Course Code: " + toolTipLbl;
    customToolTip.courseName = btnLbl;
    e.toolTip = customToolTip;
    }
    ]]>
    </mx:Script>
    </mx:ToggleButtonBar>


    Java Developer Diaries; Developing Android Applications

    On September 6th, 2007 i received a message from Chloe Arrowsmith of Google over Linkedin, asking if I am interested in a position Mobile Applications software engineering team they are building in London. As you may guess this team was setup for building Android and they didn't hire me in the end :).

    Since then I am trying watch android closer. Frankly there things I like in android and there are things i don't.

    Android is a mature platform thanks to google's strategy to release the sdk to public much before than any device available. When I start to deal with android i realized I am comparing every structure with iPhone and objective-c which is actually weird because I am a Java guy more than Objective-C. Like it or not iPhone and Objective-C is a well organized and elegant platform to work on and the deeper I dive into android sdk, the more I find things sometimes not so easy and well organized.

    Honestly I am not really interested in JavaME since beginning since I find it a bit limited but new coming devices and SDK (such as Android and IPhone) are much more sophisticated and capable. Android offers much more than IPhone SDK can even imagine. You can code Activities which are the building blocks of user interfaces. You can use content providers to access and share data between applications. Besides you can use Intents to get noticed about various events, from hardware state changes to incoming data, to application events and also not only can you respond to intents, but you can create your own, to launch other activities, or to let you know when specific situations arise which you can't on an IPhone. There is one other key stuff which IPhone lacks, the services which can keep running even not related to an activity, like keep listening messages even if you close the control unit of your instant messaging client.

    These were the best and most promising part since most of them are only available on Android devices. However I find the UI and controller integration a bit troublesome. Also even if the UI controller structures seems like taken from Objective-C, they don't seem as neat.

    Enough talking lets see things in action;

    If you had read my previous post on developing IPhone application, why don't we just build the same on Android, which will use GPS, accelerometer and UI actions (if not you can go back to check the iphone post since it may lead you a better comparison, which is, however, not necessary). First of all I assume you downloaded and setup the Android SDK and ADT Eclipse Plugin. The installation is pretty straight forward and ran smoothly on mac and ubuntu (should be ok on windows too). I also assume you have basic knowledge of eclipse and java development on eclipse.

    Fire up your eclipse and create a new android project, as if you are creating a java project.



    Next type a project, application and package name. We also need to specify a target runtime which I choose 2.1. Since we are not using any new apis it should be ok to select as low as 1.5. Click finish to create your project.



    You may have noticed some errors in your project which is actually not a real problem.



    If you clean and rebuild you project the errors will be gone. This seems like a small issue in ADT plugin which should be either because of not running the incremental builders in project creation time or not cleaning the error markers after the first build, whichever it is, just nevermind.



    The MainActivity class is created with an overridden onCreate method which is fired when the activity is first created. Android has a different way of UI declaration. Here the main.xml file under layout folder is used for creating the UI layout which also provides a visual designer. strings.xml under values folder is used to hold static values. We would be able to change those within out code. To be honest I really like this approach, it is quite easy, well organized and the visual designer is a great plus. Also if you are coming from a xml declarative platform such as Flex(MXML) or Silverlight(XAML) you won't find it much different (which actually is).



    Even at this stage you might realized Android application has much less files than an iPhone application (can check previous post). Although these makes it appear simpler and easier to start with, the deeper you go you realized Objective-C is a bit more organized. Open MainActivity class which acts as the view controller. The basic usage of the APIs would not be very different than iPhone, we are going to implement a listener interface, register or class as the listener and code the implementation method.

    Lets start with building our interface, the default view already has a TextView printing hello. We can modify this one and add another to display our latitude and longitude.


    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
    <TextView
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:id="@+id/latitude"
    />
    <TextView
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:id="@+id/longitude"
    />
    </LinearLayout>


    You may also noticed ‘id’ attributes are added in order to access this components within the code. As I mentioned before this approach is much like other XML declerative platforms. By the way if you feel comfortable (or brave enough) you may also try tweak the UI using the layout view.



    Since this should be enough for the view lets go back to our activity class. The MainActivity class is created with an overridden onCreate method which is fired when the activity is first created.

    First lets create two TextViews to control our UI code and get the LocationManager to access the GPS.


    public class MainActivity extends Activity {

    private LocationManager locationManager;
    private TextView latitude;
    private TextView longitude;

    @Override
    public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    //bind the ui components to code referances
    latitude = (TextView) findViewById(R.id.latitude);
    longitude = (TextView) findViewById(R.id.longitude);
    //get the locationManager
    locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
    }
    //...


    So far the most suprising thing for me was the need to bind the UI components to code references manually via findViewById method. Honestly this seems a bit unnecessary and weird. I was expecting the compiler to access UI components dynamically (as in other xml declarative languages) or use visual tools to do the job (as in interface builder on mac). This seems fine for now but more complicated views might become troublesome.
    Since we are mostly done with the UI code we can start utilizing the GPS. We already added and initiated the location manager.

    This would be enough get the location manager but to get the location updates we need to register a listener. To keep things simple and more like what I did in the iPhone tutorial, I am going to implement the needed listener interfaces to our activity class. You may prefer to create anonymous listener classes.


    public class MainActivity extends Activity implements LocationListener {


    Next we create two methods to register our class as the listener of the location updates via using locationManager.requestLocationUpdates method. This method provider constant, minimum time interval, minimum distance interval and finally the listener class.


    private void startListening() {
    //registers our class as the listener
    locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0,
    0, this);
    }

    private void stopListening() {
    locationManager.removeUpdates(this);
    }


    Since the methods are ready we can call startListening in onCreate method to register our class as the listener of location updates.


    ...
    locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
    startListening();
    ...


    Implementing the LocationListener interface brings four new methods to be implemented. To avoid errors lets create those and also implement the onLocationChanged method.


    public void onLocationChanged(Location location) {
    latitude.setText(location.getLatitude()+"");
    longitude.setText(location.getLongitude()+"");
    stopListening();
    }

    public void onProviderDisabled(String provider) {
    // TODO Auto-generated method stub

    }

    public void onProviderEnabled(String provider) {
    // TODO Auto-generated method stub

    }

    public void onStatusChanged(String provider, int status, Bundle extras) {
    // TODO Auto-generated method stub

    }


    Any new location update will trigger onLocationChanged method. However we don’t need any update after we get the locations so as we get location update we assign those to UI text fields and call stopListening to unregister our listener class.

    As you may remember from the iPhone post we want our application to update the location info when we shake the handheld. To achieve this we need to ask the sensor service to inform us on accelerometer events. This approach is a bit primitive when compared to shake API introduced in iPhone OS 3. However it is much or same with the older iPhone OS. First lets get the sensor manager.


    private SensorManager sensorManager;


    And in onCreate method initialize the sensorManager and add a listener.


    ...
    sensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
    sensorManager.registerListener(this, sensorManager.getSensorList(
    Sensor.TYPE_ACCELEROMETER).get(0), 100);
    ...


    We also need to implement a new interface to let our class to become a listener for SensorEvents.


    public class MainActivity extends Activity implements LocationListener, SensorEventListener {


    Adding the interface will cause errors because of unimplemented methods. Add the needed methods and implement the onSensorChanged method to detect shake and reregister for GPS updates.


    // The threshold value to detect shake
    private float kThreshold = 1.2f;
    public void onAccuracyChanged(Sensor sensor, int accuracy) {
    // TODO Auto-generated method stub
    }
    public void onSensorChanged(SensorEvent event) {
    if (event.sensor.getType() == Sensor.TYPE_ACCELEROMETER) {
    float[] values = event.values;
    if (values[SensorManager.DATA_X] > kThreshold
    || values[SensorManager.DATA_Y] > kThreshold
    || values[SensorManager.DATA_Z] > kThreshold) {
    startListening();
    }
    }
    }


    Finally we want our UI to respond and rotate according to orientation changes. Unlike the iPhone counterpart, android does not need any code change for this purpose, just tweak the AndroidManifest.xml and it is done!





    Although ADT offers visual editors for this xml file, it is not possible to change the screenOrientation parameter visually.



    Now we are ready to run our application. Android SDK comes with an emulator. To set up new virtual devices, use awd manager.



    You can add virtual devices varying from version 1.1 to 2.1. The SDK comes with 2.1 version but other packages can also be downloaded from available packages section.



    Be careful about not choosing an older AVD version than the project build target you choose, shown in figure 2. As our AVD is ready now we can run the application. Right click on the project and select run as android application.



    This should fire the emulator and deploy your project which should get an error as shown below.



    Unlike iPhone, Android offers much more services and integration to developers which brings up another problem, the security. Android programming model expects you to declare the resources you want to use at the time of installation, so instead of asking permission each time the application started, Android lets the user know what the application doing during installation. While this approach is much simpler and less pain for the user, it will also provide eternal access to resources once user confirms.

    To add those permissions open the AndroidManifest.xml and go to permissions tab.



    Click add.



    And add ACCESS_COARSE_LOCATION, ACCESS_FINE_LOCATION permissions from the dropdown.



    Finally our application is really ready to run. I had some difficulties getting location data on the emulator. Also shaking the emulator window didn’t cause the accelerometer to detect any shake. However when I deployed the application on a real device everything ran smoothly. Later i realized I need to install SensorSimulatorSettings.apk to get mock location and trigger shake. To install use the following command;

    %ANDROID_SDK_HOME%/tools/adb install SensorSimulatorSettings.apk

    You can also refer this post for more info about SensorSimulatorSettings.

    The running application should be similar to the screenshot below, responding to shake and orientation changes. (BTW thanks to Google giving the developer phone last year at I/O).



    Android is a very promising platform and although its quite young its already quite mature. I will later write another post comparing iPhone and Android development but to tell the truth staying in Java and having a more open and flexible platform feels more comfortable. However when compared to iPhone documentation, samples and even books are still might not be as good.

    Sunday, 21 February 2010

    The war in your pocket, the Mobile World

    Shortly after the announcement of Apple’s long waited iPad, GSMA 2010 heated the mobile arena much more. It is quite clear that the kingdom of iPhone is in great danger unless they have new suprises.


    Here are some key points;


    Android, should be the most promising system on the market. There are over 100 android devices announced either available or hit the shelf soon. HTC announced new models based on Nexus One and Hero. One of the greatest advantage of Android is the full flash support. So far it seems like its the most compatible and mature system for the flash player. Also android offers a quite open platform and easy development for Java/JavaME developers. Google has handled the most important problem, the hardware variety quite well. Android seems to be performing quite compatible and customised on different handhelds which was a key point against iPhone since Apple does not need to face such an issue as the only hardware provider. Also Google’s attempt to attract developers to build apps even much before the devices exist, is really paying back now.


    Windows Phone 7 series, looks nice and modern. Integration with current Microsoft tools is a plus but i still wonder if it can wipe the bad memories of the previous Windows Mobile systems. Microsoft should also be worried about that since the name WM totaly changed to Windows Phone. XBox Live could be a nice catch but not sure if it will be enough to attract any gamers. The user interface look very modern and sleeky. Microsoft has done quite a lot in terms of user experience but I’m not sure if the animations and transitions are really well designed. To be honest they look nice at first look but for daily use I feel they would be a bit slow and exaggereted. Also they need hardware support which seems like it would not be problem but in terms of nice stunning designs that could become a problem against iPhone and Android. One more questions is even though Windows has been around much longer than Android, iPhone it lacks the application variety and a centralised app store which their rivals have.


    IPhone, is the quite leader of the modern smart phone market. Besides the handhelds and OSs they also rule and make good money on the applications. IPhone had a minor update with 3Gs but I really feel they are getting a little outdated with the upcoming devices against Android. But still Apple is always full of suprises so there might be a very unexpected upgrade which would change the current situation. Well even for the current models, iPhone offers easy of use, sleeky and a trendy device against its rivals. Also Apple now has a huge mobile device which is called iPad whose destiny would be interesting to watch.


    Samsung have their own OS, with Java support and trendy models. I am not sure if they can offer the same rich use experience but it is sure that they are quite fast to implement new stuff.


    Palm has been left out of my scope for a long time, however, now I have an eye on them after the move of Sun’s Josh Marinacci. It would be nice to use his experience on JavaFX to bring better user experience to Palm.


    Seems like 2010 will be a very big challenge for mobile world. Flash will be out soon with Flex and ability to export IPhone apps even though Iphone does not have a flash player, JavaFX offers easy mobile development, Android is has a solid OS now and they are taking nice steps for user experince, animations, transtions and they have a nice app store. Microsoft finally have a modern OS (although they are about 2 years late, actually I find it hard to understand they should know the advantage of being early on the market from their XBox experience), Apple (probably) making secret plans to keep the advantage of being unique.


    Let’s wait and see..