Sunday, August 29, 2010

Android MVC - Forward and Backward Navigation

This weekend's changes to the Android MVC project include the following:
  • Reorganization of the Command classes. AbstractBaseCommand has been created for simple get/set. All methods except "execute" have been implemented. This class now forms the base for IdentityCommand as well as AbstractCommand.
  • Controller now has full support for forward as well as backward navigation.
  • Controller can now record the activity navigation. Uses ActivityStackInfo.
  • Controller now support forward navigation with few more options:
    1. Can optionally mark the command to not be recorded
    2. Can optionally reset the activity stack
  • Controller now has back method for backward navigation.
  • Controller, during forward navigation, manipulates the activity stack appropriately.
    • Missing part is handling failure scenario when receiving a response. When processing the response, if it is in "error" state, IMHO, the response must be handled by the same activity rather than launching a new one.
    • More so, the command must be removed from the top of the stack if there was an error.
  • The support for IMemento, IInitializable has been removed. Not required.
  • The initialize method, henceforth, has been removed from BaseActivity.
  • BaseActivity now has two methods preProcessData and processData called before onBeforeCreate and before onCreateContent respectively.
  • BaseActivity now handles the back button (using the v2.0 function onBackPressed) by calling the back method for navigation.
    • Developers using v1.6 can override the method onKeyPressed and look for the KeyEvent.KEYCODE_BACK and call the method back.
Sample case study (showcase) now comprises of the following:
  • SplashActivity that happens to be the main launcher activity.
  • Erstwhile MainActivity has been renamed to LoginActivity to reflect its purpose.
  • HomeActivitiy continues to be the same.
  • SplashActivity launches LoginActivity using IdentityCommand and sharing some data (using Tag)
  • LoginActivity launches HomeActivity upon successful login (sharing some data using Tag and passing some piece of data to LoginCommand using Data).
The code is, as usual, available on Sourceforge at http://android-mvc.git.sourceforge.net/git/gitweb.cgi?p=android-mvc/android-mvc;a=tree. Additionally, I've also pushed the codebase on Github at http://github.com/gvaish/Android-MVC.

Monday, August 23, 2010

Android MVC - Stable Release and Case Study

Yes! The code has moving quite fast... now from Beta-- to Beta- as I see it ;).

And soon, the Android MVC project should move up to real Beta.

The Http-Commands have been made more robust with better error handling. Controller has been enhanced to provide support for registering activities dynamically.

What still remains pending is activity-stack management by the Controller - which otherwise is done by the Android OS. The stack management is not a trivial task, however for an application it will provide some interesting bits. Firstly, it'd be great for a single-Activity-at-a-time application without too many overheads. Secondly, the Controller will some enhancements to ensure that forward-and-back work without too many duplicates in the UI as what happens in several applications as of now.

As earlier... the code can be browsed at: http://bit.ly/cLHzbW.

And Oh Yes... to login, use these credentials - username: "gvaish", password: "password" (without quotes).

Sunday, August 22, 2010

Android MVC Project Updates

The latest code can be browsed at http://bit.ly/cLHzbW. A couple of critical changes have gone into the structure:
  • Removed the logic for progress or error activity from the Controller. The effect is - the fields progressActivity, errorActivity have been removed and also the code pieces that referenced them have been deleted.
  • Progress activity has been replaced by a simple, easy to use, ProgressDialog. This dialog is initialized in and launched from BaseActivity, as opposed to earlier structure where the progress activity was launched from Controller
  • Overloaded "go" methods have been added in BaseActivity. This gives ease and peace of mind to the BaseActivity-inherited classes to never be bothered about the Controller.
Pending items include:
  • Appropriate response handling in case of error from the incoming response in Controller.
  • Ensuring that if an error occurs and the same activity is shown, pressing the "back" button should not execute the "errorsome" command again (deviation from normal browsing a MVC-designed website).
  • Creating a robust case study to test out a few scenarios:
    Main (Splash) => Login => Successful => Home => Back (should exit);
    Splash => Login => Failed => Relogin (may be same activity or different) => Back (should exit);
    Splash => Login => Cancel (back button) => Should just cancel the login request.
Keep watching for more updates!

Saturday, August 14, 2010

Model View Controller (MVC) for Android

Finally, I have been able to find time to push the initial code for "Model View Controller" implementation on Android.

Quite a few people told me that MVC is inbuilt in Android, with the View being represented by the Activity but I failed to visualize or tangelize the Controller. Well, the Model can always be the backend data - the business entities.

The code is hosted on Sourceforge - https://sourceforge.net/projects/android-mvc/

If are you interested in the code, you can get it using Git at git://android-mvc.git.sourceforge.net/gitroot/android-mvc/android-mvc.

Or if you just want to browse the code before downloading it on your machine, you can visit http://android-mvc.git.sourceforge.net/.

The code, by any means, is not yet ready for production use since I know various pitfalls, specially for the scenarios when the "Command" fetches the data from the network or database or from anywhere that takes long time.

In these cases, the best practice would be to hive-off the execution in a separate thread (read: Non-UI Thread). When the response is ready, you would pass it to the main thread (read: UI Thread) using a Handler. This part is implemented in the Controller, however, there can be race conditions in the scenarios where in multiple commands get issued - specially in very interactive application.

Additionally, since, currently, the progress is presented using another Activity, there is an extra house keeping that is being done and I know (by use of this approach in my application), it is bound to fail in near-extreme scenarios.

The fixes are available with me... and I should soon find time to push them. Besides, I also need to a create more powerful case-study! :D

So... keep watching!

And yes... if you feel that the code has done any good to you, please do spread the word and "Share the Love" :)

Here are initial screenshots of a trivial case-study (scenario) of initial implementation...




Friday, August 6, 2010

On becoming "Double Chachu"

And finally, the d-day has come. My friend and business colleague, Umakant, has been blessed with a daughter - Goddess Laksmi for the second time in his family! Sooo lucky :)

The name is Yana, meaning "Precious to God". See Yana and Ioannes.

Here are some photos...






Thursday, August 5, 2010

Home, Sweet Home

A few weeks ago, I got time to take a video of my flat (condominium or condo, if you like it that way).

And then, I got time to put it up. Here's the video...