Damon Oehlman

author
+ Follow
since Jan 26, 2011
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
In last 30 days
0
Forums and Threads

Recent posts by Damon Oehlman

Hey Monu,

You could possibly do this using the web apps approach if you wanted to give it a try. The Sencha Touch framework does come with a carousel UI element that works really well for both android and iPhone.

You can check it out in the Sencha Touch Kitchen Sink Demo (under User Interface > Carousel).

Cheers,
Damon.
14 years ago
Congratulations to the guys who won the book. I'll try and keep an eye on the ranch for questions around mobile web app development on Android.

Thanks again for the great questions and awesome interaction through the site

Cheers,
Damon.
14 years ago

Daniel Trebbien wrote:Hi Damon,

I'll be following XPMobi.org with great interest. I'm glad that you made the site open source on GitHub, as I might be able to contribute someday by forking and issuing a pull request.

These past few discussions with you, Sébastien, and others have really got me thinking about some things. I look forward to exploring these ideas and sharing the results.



Cool - great. Yep - that's the idea - writing articles coder style

It's been great actually, really impressed with JavaRanch actually and the discussions that we've had. I'll be interested to see what you get up to.

Cheers,
Damon.
14 years ago
Hey Daniel,

Having a look at the DroidGap source I can't see any handling as per what you describe in your question. Orientation changes in the a WebView in more recent versions of the Android fire an onorientationchange change event at the window level. Some of the older browser implementations don't support this event though so you are left to handle things by capturing the onresize event. You are best detecting what you have available through feature level detection.

In the source code (which you can download from the Apress site) I wrote some code which shows an example on how to deal with this. Content is covered in chapter 2.

If you don't want to download the full zip, then you can also have a look at the code on github:

https://github.com/sidelab/prowebapps-code/blob/1.0/snippets/02/orientation-monitor.js

So essentially you capture the orientation changes at the web level with no need for any notifications to be passed through from PhoneGap. This is good as it means your code will work in both a hosted and "native wrapped" app situation.

With regards to the second part of the question (saving instance state) my approach is generally to "serialize as I go". Basically, if I expect that something should be available and remain in the same state if the application was loaded from scratch then I will write a value using HTML5 localStorage (actually, I tend to serialize all my settings together as JSON first and write and read the whole lot together). I then look for these settings (or other state variables) on application load and then restore application state appropriately.

This approach tends to save me from the "I never received my app is closing" message and thus having some state lost. The one thing you can always rely on is getting some information that your application is loading, so restoring the state is nice and reliable. In terms of handling performance overheads of serializing the data, I will usually use Javascript timers (setTimeout, setInterval) to delay the save operation for a second or so after the save which ensures that if multiple settings are written the save operation only happens the once. You just do a clearTimeout followed by a setTimeout to clear an reset the timer delay on each setting write.

As far as content on this topic in the book goes, Chapter 3 and 4 cover using localStorage and the Web SQL database to save data, but not primarily around the topic of managing application state (although the JSON serialization technique I spoke about is covered). As per previous threads, I might see if I can put some content on the topic of "Managing application state through local storage" online somewhere. The books focus is primarily on managing application data.

Hope that makes sense, and answers both your questions Daniel.

Cheers,
Damon.
14 years ago
A big +1 on all Seb's responses here, and I'd also just point you towards the thread below that talks about PhoneGap plugins:

https://coderanch.com/t/525012/Android/Mobile/Does-Pro-Android-Web-Apps

As soon as you said "scan the barcodes" I remembered that I saw a PhoneGap plugin that has already been built for that:

https://github.com/phonegap/phonegap-plugins/tree/master/Android/BarcodeScanner

While I haven't tried it myself, I expect it should be pretty simple to implement. We have a little coverage on using PhoneGap plugins in chapter 12 in the book if you are after some guidance on the topic.

The plugin would probably give you a bit of a leg up in terms of getting your application started, although it does seem to rely on another app.

Cheers,
Damon.
14 years ago
Hey Guys,

This isn't something that we cover specifically in the book, but I would be more than happy to blog (or write an article, see below) about it. In fact a good friend of mine will be joining me in my business pretty soon and he has extensive experience in the security space, so I would probably pick his brains or potentially even collaborate on writing that post.

In addition to the book, I plan on building up some online resources at a site I've created @ http://www.xpmobi.org/. All the content there will be creative commons licensed and I'm building the site using Jekyll with the intention that people can fork a github repository (https://github.com/sidelab/xpmobi) and contribute articles, all while getting to write their content using markdown

With some of the stuff your getting up to Daniel, I'd certainly welcome any contributions from yourself regarding the things you are doing in the "hybrid" web app / native app space.

The site is still a work in progress, and I have to get a couple of those pages finished before the book hits the shelves...

Kind of got off topic there... sorry... I'm just really keen to see more, useful information around how people can go about building cross-platform mobile apps. The book definitely captures some of that information, but there is just so much more that we can cover, as this particular thread points out.

Cheers,
Damon.
14 years ago

Jason Koonce wrote:Will the book go into detail for HTML5, CSS, etc? I have even less experience in web development than I do Java. If it goes into detail, enough that my lack of experience isn't a problem, great. But if it doesn't I will need to study additional stuff, which isn't a problem, just good to know ahead of time.



Hey Jason,

It would be certainly worth investing a little time getting to know HTML, CSS + JS. While the book has complete sample code which you could definitely follow, it is targeted primarily at people with some prior experience with coding web apps.

I'll try to put together a list of recommended reading for those coming from a native Android development background interested in investigating the web apps approach.

Cheers,
Damon.
14 years ago

Daniel Trebbien wrote:Interesting! I checked with Android 2.3 and the HTML img tag is able to pull an image from my custom content provider.



Awesome Daniel, I think is a good example of how you can really use web and native together for writing apps for Android. Did the same situation work for the HTML just running through the browser?
14 years ago
Hey Guys,

I will try and add some clarification to for this thread. As Ulf (and Burk) point out the book is focused primarily on creating applications using HTML, CSS and Javascript. This is somewhat of a different approach to what most people in this forum may be used to but it certainly has some merits (which are being nicely discussed in other threads on the forum).

As for whether we cover consuming a SOAP webservice, no we don't and the resources Monu points to would be a good starting place if you are looking to do this from a native Android application.

The book certainly has more than one example of consuming RESTful (and RESTlike) webservices which is probably more common from Javascript code, but as this thread on stack overflow points out it is possible to consume SOAP webservices from Javascript also.

Cheers,
Damon.

14 years ago
Hey Jecki,

We've touched on question 1 in a previous thread, and I expect there will continue to be some good discussion there, so I'd recommend checking that out:

https://coderanch.com/t/524844/Android/Mobile/Android-web-app-other-devices

Question 2 is a good one, and one that I would likely rant at length about if given the chance. I will admit though I am biased given it is the business I am in, so you should definitely take what I say with a grain of salt.

My opinion is that if you are developing applications for mobile that could be developed as a mobile web app, then you should definitely consider that approach over native app development. Why? Well consider the fact that we have a variety of different handsets out there, and according to the various stats around their web access, no platform has more than about %30 market share at most. My background before coding for the web was as a windows developer, and at that time I felt a little uncomfortable with the fact that software I was writing would only cater for 90+% of users. Move forward to today, when I am coding for mobile, I really just cannot bring myself to build applications that target only 30%.

Admittedly, using the techniques that we outline in the book won't get you to 100% mobile device coverage, or even close to the 90% that I used to feel bad about when coding windows. Mobile devices with a webkit browser are on the increase though, and using that as your "lowest common denominator" should in time bring you close to 70% (a rough estimate) device coverage. As per the thread I liked to regarding question 1 though, there is always small tweaks to do to get things working well on each of the devices, but build your application right and you will have a much more maintainable solution than attempting to manage separate native apps for a variety of platforms. The bigger companies and startups with VC funding can probably take that approach, but it's not going to be suitable or sustainable for the "rest of us" (or the businesses that are our clients).

I'll probably stop there, before I hit full rant mode, but I think I've communicated why I think coding mobile web apps in most cases is a better approach than going native. There are of course things that are more challenging to using web technologies than native (games are a good example) but I think that will probably change over the next few years as well as HTML5 canvas support grows.

With regards to question 3, if you can manage to do both, then you are very well positioned for getting the absolute "best bang for your buck" right now. A knowledge of how Android apps work under the hood can assist you with writing PhoneGap (a mobile web application native wrapper) plugins and also allow you to mix and match technologies. My guess is that in 3 years time, we will all be writing mobile web apps (games being a likely exception), and in the meantime we are going to see quite a few Hybrid applications that mix and match native and web technologies.

Hope that answers your questions, and I didn't get too off topic. Re-reading over my response here, I would expect people to wonder exactly what constitutes an application that could be written as a web app, and I will definitely attempt to answer that as a follow-up if people are wondering.

Cheers,
Damon.
14 years ago
Hey Burk,

Going with a web UI framework is generally a good start, and even though in the book we start with the "roll your own" approach to teach the fundamentals we also cover quite a few frameworks in Chapter 12 (see https://coderanch.com/t/524920/Android/Mobile/Javascript-frameworks-have-good-performance).

In terms of screen sizes and aspect ratios you can handle these things with CSS3 media queries and/or a good fluid HTML design.

Cheers,
Damon.
14 years ago

Lemig Gimeno wrote:Hi, What are the prerequisites for your book? I have no web apps experience but I know how to code in java. I'm also currently learning android application development. thanks.



Ideally you would have some experience with HTML, CSS and Javascript before jumping into Pro Android Web Apps. If you haven't you can still work through the samples, but I will be honest and say it will get pretty heavy going quite quickly. If you were interested in investigating the mobile web apps approach, then the book would definitely help you do that. I would just make sure you have a Javascript and possibly jQuery book close at hand before diving in though. The HTML is nothing complicated, and you could get by without understanding how the CSS works (until a later time at least).

Hopefully that answers your question.

Cheers,
Damon.
14 years ago
You've had these questions brewing for sometime haven't you Daniel. I have to admit I don't know the answer to this one, but I'll definitely investigate. My gut feel is that in a PhoneGap wrapped application might be able to, but in a web app presented through the browser might not.

Is the application you have built available in the Marketplace? If not, I'll put together a test app at some stage and test for both situations.

Cheers,
Damon.
14 years ago
Thanks Guys

Hopefully both Seb and I can provide some useful pointers around building Android (and mobile in general) web apps.

Good luck with winning the book.

Cheers,
Damon.
14 years ago

Tiffany Coleman wrote:

The good news is that the majority of the books content is applicable to programming for other mobile device platforms that ship with WebKit browsers (iOS, WebOS, Blackberry Torch, some Nokia), but this still leaves a lot of devices that code samples in the book just won't work on.



Does that mean that this book will help me be able to write an app that I can use on my droid, as well as, then be able to turn around and use it on my iPad? Most of my app ideas are for things like -- accessing online games or reviewing specific database information for online games. I'd like to be able to do it whether I was using my phone or my tablet.

And -- will the book give me enough of the 80% that I could learn the 80% and then grab the 20% to make my app work cross platform? Does it define the 80/20 items -- for instance, does it say, this portion will work multi-platform and also say, this is Android specific and doesn't function somewhere else? If not, would it then be "trial and error" to find out which parts work and don't work if you want to have it be cross OS?

Thanks.

--tiffany



Hey Tiffany,

Another good question. The short answer is yes. Because both your Droid and an iPad (I have a HTC Desire and iPad) both have a Webkit browser just about everything you will code will "just work". I'd recommend starting by targeting the Android first as it's probably the "fussier" of the two platforms.

The one thing you should consider when writing for these two platforms is the different screen sizes that you are coding for. So when thinking about your layout think about using percentages rather than absolute pixel dimensions to ease the transition, but you can also use CSS3 media queries to supply different styles for the different screen sizes also.

In terms of what to watch out for, main things are slight variations in Touch handling and some frustrating things around Android 2.1's handling of "device-dpi" when working with the HTML canvas (problem goes away in 2.2 thankfully). On the touch handling front, I have written a Javascript library to try and help out with that, but it isn't covered in the book as I only created it very recently.

Hope that helps answer your question.

Cheers,
Damon.
14 years ago