Wednesday, September 8, 2010

iPhone SDK: Switching UIViewControllers on orientation change

I recently started to learn iPhone SDK programming. It is amazingly simple to do and fun to learn.

While trying to program an app that switches UIViewControllers when the phone is rotated, I found the best hint on this blog post. The key is really to use a single view in portrait mode and when the phone is rotated to landscape, present a different UIViewController in modal mode. The tricky part is to remove it again when the phone is rotated back to portrait mode.

For this, the portrait mode has to claim to support all orientations:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {

// Return YES for supported orientations

return (interfaceOrientation == UIInterfaceOrientationPortrait ||

interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown ||

interfaceOrientation == UIInterfaceOrientationLandscapeLeft ||

interfaceOrientation == UIInterfaceOrientationLandscapeRight);

}



The mentioned blog post above registers a listener for notifications of the orientation change event emitted by the device. However, I was looking for a different way that uses the methods provided by the UIViewController. Also, I did not want to lose the animation when the phone rotates. It slides in the top bar.

It turns out that the animation that is displayed allows for a callback. This callback is called while the rotation animation is played. In this example the animation callback is used to present the new landscape view.

-(void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {

if (toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft ||

toInterfaceOrientation == UIInterfaceOrientationLandscapeRight) {

self.lView.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;

[self presentModalViewController:self.lView animated:YES];

}

}


This example uses the CrossDissolve transition to phase in the landscape view.

Now, since the landscape view is now on top of the portrait view, it will receive the orientation change notification. Using the same trick as above, use the animation callback to dismiss the modal view again.

-(void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {

if (toInterfaceOrientation == UIInterfaceOrientationPortrait ||

toInterfaceOrientation == UIInterfaceOrientationPortraitUpsideDown) {

// dismiss this view

[self.parentViewController dismissModalViewControllerAnimated:YES];

}

}


To ensure that the landscape view receives the notification it has to indicate that it supports the new orientation.


- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {

return YES;

}


The result is an animation that phases in a different view in landscape mode.



video

Monday, January 26, 2009

OSGi and SCA

I am pretty sure you have heard about SCA (Service Component Architecture) by now. It is hosted by OSOA at http://www.osoa.org.
Since pretty much the same players that are working on SCA are also members of the OSGi Alliance, it seems natural to find common grounds between the two.

At the inception of the Enterprise Expert Group (EEG) in January 2007, we already discussed the possibilities in combining the two technologies somehow. We started RFP 81 to capture the requirements and use cases. For some reason, the RFP was never really paid as much attention to as other EE related RFPs. Given the fact that several companies are bringing out SCA based or supporting products (TIBCO with ActiveMatrix, IBM, Oracle, etc.) the RFP deserves another close look and some tender love and care.

I, myself, am not particularly an expert in SCA, but I begin to grasp the differences in the modular, dynamic, and service oriented architecture of OSGi versus the more deployment oriented, static service composition model of SCA. Candidly, I would summarize this as 'SCA wants to rule the world in large', while OSGi is happy in ruling the services and modularization in context of a single technology and JVM process. SCA is technology independent, OSGi by all means of current practice is JAVA bound.

What do they have in common that is worth specifying?

Well, for one thing, there are more and more customers out there that understand and like the OSGi service programming model. Thanks to component technologies like Spring it becomes very easy to structure a big hairy and complex application as a collection of small beans, which are packaged up as bundles. In the EEG we specified Blueprint Service as part of the EE Edition of OSGi, which will come out some time later this year. For those who don't know or forgot, the RI of Blueprint is the version 2.0 of Spring Dynamic Modules.

Now, if I use SCA to describe my big scary application deployment or domain in SCA terms, can I make my OSGi bundled application part of that SCA domain? I think, it should be as simple as modeling my application as a SCA composite, define the implementation type as implementation.osgi, promote my references as services via the OSGi service registry, and use Configuration Admin to configure the application at runtime. Sounds easy, doesn't it?

Turns out, not so much. I recently discussed this with one of my fellow EEG members during our last face-2-face meeting in Bedford, MA. Apparently, SCA doesn't like the constraint so much that services and references are bound to a particular binding type (OSGi service registry). Their ability to function depends on the fact that those other services are co-deployed with the application in the same OSGi framework.

However, there are a few things that can be done about this.
* the SCA runtime could start a framework dedicated to the OSGi application and wire the external services and references using SCA means. In case the SCA runtime is built itself as an OSGi application, the new RFC 138 Multiple Frameworks specification in OSGi comes in very handy. It allows an OSGi framework to efficiently manage a child framework.
* remove the restriction of having OSGi services only available to the local OSGi framework. This is the power of RFC 119 Distributed OSGi scheduled to be released as part of the EE Edition later this year. When services are now distributable or at least accessible across the JVM process boundaries, then the OSGi binding type becomes interesting for SCA applications again. One of the advantages of RFC 119 is that this scenario has native support for the SCA intent model. So, matching services and references based on intents with the option of additional metadata for policies makes the integration of SCA and OSGi look natural and seamless.

Join our talk about Distributed OSGi at EclipseCon 2009 to hear exactly how this is going to work for you.

As you were...

Thursday, November 13, 2008

Yes, we can!

Thank you, America!

I while ago I asked you to do the right thing by voting for a new president to replace this moron and disgrace of a president. And you listened, you elected Obama, a very good choice :-)

Maybe because of the election and its coverage, I became obsessed with listening to KQED, the only news radio worth listening to in the US. I even became a member during their September pledge drive.

Today, I listened to an interesting show about the election of a black president and how it has affected you personally. You can listen to it here. One of the guests on the show has questioned the claim of many white people under the age of 40 that they are 'color blind'. Well, I would put myself into this category and ever since I came to the US to work in Sillicon Valley claim to be as color blind as possible.

I think it is not so much the race or color that bothers me as it is the intellect and the lack thereof of the person I meet and interact with. I am not very good in expressing this in writing, but I hope you get my point. I can meet a black, Hispanic, Indian, or Asian person and be completely in awe and admiration for the intelligence, knowledge, and confidence that person emits. At the same time, I would tell any dude in a huddy and baggy clothes trying to bully me that he or she will never become president, regardless of what so many minority parents now try to tell their children.

It has to do with education and upbringing and not with the color of the skin or the heritage. There are plenty of white dumb asses out there that will never make it, rightfully so ;-)

For now, let's celebrate Obama's victory as it will be good for all of us.

As you were ....

P.S: Since Obama won, I will not pack my wife and dog and go back to Europe. There is plenty of opportunity here, and maybe I even become an American myself.

Thursday, October 16, 2008

BundleFest in Montpellier

It must have been beginning of 2008 or even earlier that Peter Kriens (Technical Director of the OSGi Alliance) has first pitched the idea of gathering some of the expert groups members together for a week of intensive collaboration. At the time, the idea became more and more appealing as we were fantasising about sitting next to the pool in southern France while drinking wine and philosophizing about OSGi. I kind of signed up immediately, not knowing whether I would actually be able to attend.

Now, in October 2008, we actually did meet in Montpellier, France. The hotel 'La Grande Motte' was chosen by Peter as the hosting location and turns out to be an excellent ambiente for this kind of collaboration. We gathered in a small room near the waterfront for 9 to 10 hours a day, only breaking for coffee and lunch every once in a while. Actually, we took our breaks very seriously :-) The food was delicious French cuisine with appetizers and dessert. I probably gained a few pounds during this week.

Work wise, we focused on the most pressing outstanding action items like the OSGi build, their test cases, and of course, my child, RFC 119 - Distributed OSGi. Having David and his colleagues as well as my former Siemens colleagues together in the same room at the same time was very helpful. Siemens committed their RI for the Discovery part and I completed the TCK within the first 2 days. In the meantime, David assembled all of the CXF based RI into a single bundle to make it usable from the OSGi build. I was not able to complete the full TCK, but pretty much everything is there to finish it alone at home in Palo Alto.

We had some very interesting and controversial discussions:

If the RFC claims that it provides for distribution of OSGi services, does the TCK need to verify this claim by deploying at least 2 separate JVMs?

Peter and I argued that it is sufficient test the contract only in a single JVM, the distributon is part of the implementation, which would need to have its own system tests.

Pretty much the rest of the group was arguing for a more business oriented view, in which a RI should actually provide value. Companies providing the RIs made a sigificant investment into the development and the RI should be more than an academic excercise.

I guess we will have to continue this discussion over time.

Well, I think this meeting was a huge success and should be repeated next year, maybe twice a year as suggested by a few attendees.

As you were...

Tuesday, September 9, 2008

America, please do the right thing

I know this blog was supposed to be technical, but recently I have been too busy in my new position at TIBCO that I didn't really find the time to summarize the technical projects I have worked on and the problems I faced. I really like some other blogs for this, like the one from David Bosschaert. I guess he also has been busy, since his blog hasn't seen a new coder thought since April.

Listening to NPR on the radio every morning and evening during my commute is really informative and entertaining. However, sometimes it really aggravates me when I hear Republicans talk about the upcoming election and how McCain will save America. Unfortunately, I am not eligible to vote in this country, but I would really like to express my concerns when listening to this bull-shit.

Americans, please do the right thing this time and don't fall for the same lies again. If you want to have someone in power you can have a beer with, then you deserve Bush III, but I would appreciate having someone with such executive power to be smarter than me!

You won't believe how much damage this administration has caused to America in the view of the world, until you actually leave the country and look at it from a different angle. I have met Americans in Munich, who won't come back to their home country until the Republicans are out of office. I so understand them.

Why am I here? Well, when I came, Clinton was in office and the economy was doing well. I never understood why Americans could run an impeachment campaign against someone, who has an affair or sexual liason while in office, but they can't do it for a moron like Bush that violates the American constitution, by leading the country into an unjustified war. Sad, sad story.

With Bush, everything went downhill. From the economy to the environment. My job was hanging in there until beginning of the year, when they shut down my site. Fortunately, I was able to find something better quickly. However, if McCain gets elected, I will take my wife and dog with me and live in Europe for a while until America comes to its senses.

Again my appeal, please America, do the right thing, vote for Obama, your only hope!

As you were.

Sunday, April 13, 2008

Mass Production Is Not Mass Design

There is an interesting discussion going on, which was initiated by Eric Newcomer's blog 'Have We Got it all Backwards with Software Assemby?'. He analyzes and compares the production of software with the Ford assembly line. His conclusion is more or less accurately summarized as that software composition and assembly is or should be the harder part once the pieces needed for the product are standardized through interfaces.

From my own experience I would like to add that this is the ideal situation, which everybody thrives to achieve. At Siemens we set out with a completely new SOA based platform to get there as quickly as we can. To a certain extent, it is actually achievable.

However, for the most part I have to agree with Hal Hildebrand's response in his blog 'Mass Production Is Not Mass Design'.

Software Design is the issue, much more than production.

Well, one might come to the conclusion that Eric had something else in mind what he called 'production'. If I understand it correctly, he meant the construction of a product based on existing software pieces - call them components if you want. In Hal's blog, this seems to be reduced to the act of burning a DVD, which is not as skillful as assembling a product for installation.

I remember the lectures of my professor Dieter Rombach of University of Kaiserslautern. He is heading the Computer Science research group for Software Engineering. In the classes he compared the engineering process of writing software products with that of the engineering of a house or a machine. It is more than a decade ago, since I heard him talking about it, and unfortunately, nothing much seems to have changed since then.

Architecting a good software product is a creative process. In a sense, we (software architects) are all artists. The same is true for the architecture of a house. It takes skills, experience, and inspiration to come up with something that works and sells at the same time.
We are relying on standardized building blocks to construct the product, and we may even outsource some of the construction, but the design will always have to be done by a (small) group of highly trained professionals.

"If you earnestly believe you can compensate for the lack of skill by doubling your efforts, there's no end to what you can't do." -- despair.com

Unfortunately, we are no where close to the level of standards as they are in the engineering fields. With our current processes and quality assurance programs in most companies, I can only hope that I will never need a pace maker and no business manager is coming up with the brilliant idea of re-using some software for it to save some bucks.

As you were...

Tuesday, March 25, 2008

Ok, I follow in line

Last week at EclipseCon / OSGi DevCon 2008 all of my colleagues and friends from the OSGi Alliance mentioned their personal blogs. Sometimes they even did not really feel like repeating the information and just referred to it, "oh, I have recently blogged about it, didn't you see that?". No, apparently, I have not. But, I promise, I will follow more closely, now that I have my own ;-)

Right now, I am sitting in the hotel in San Francisco after my first day of Spring Core training class held by Matthew Adams and Daryl Heinz. The first day was not so spectacular as I pretty much know it all already. I finished my labs during the presentation and was rewarded by leaving promptly at the end of the course ;-).

I did learn some interesting things, though. The BeanPostProcessor is a very elegant way of introducing interceptors, but also inject and standard or customized logger to a bean, before it is used. I will try this out in my product code as soon as I get back to work.

Tomorrow, we will go into the details of the DB access layer and the AOP. That should be more interesting.

As the co-chair of the OSGi Enterprise Expert Group I am more interested in the Spring Dynamic Modules project, but that would be another class. Maybe not, since I am working with Adrian Colyer and the other EEG members directly. We (Siemens) have contributed several requirements to Spring DM to make it more useful and a better solution than Declarative Services. DS originally did not cut it for us.

As you were....