Monday, April 2, 2012

Customizing Google Sites to Individual Users

Ever since Google Groups discontinued support for pages and files I've been running my classes on Google Sites, at least for hosting content.

The sign in link for individual users in Google sites is very carefully hidden at the bottom of the screen making it seem like the emphasis is on content hosting for all rather than on customizing content for individual users, but that is exactly what I'd like to do in order to, for example, show students in my classes which assignments they've completed etc.

It seems like there should be some way to do this, but my searches so far have proved inconclusive, as I keep searching and not quite coming up with anything concrete.  It seems like Google App Scripts should help, but I'll have to look again once the semester has finished:

https://developers.google.com/apps-script/articles

XCode StoryBoarding and SplitViews

So I burnt a lot of time last week trying to get XCode Storyboards working nicely with UISPlitViews on the iPad.  One of the more helpful resources was this one:

http://www.techotopia.com/index.php/Using_Xcode_Storyboarding_(iPhone_iOS_5)

which I found by searching Google for "programmatically trigger segue".  My previous search for "splitviewcontroller segue" was less helpful, turning up short, not really relevant StackOverflow posts.

I also skimmed the following tutorial, but wasn't able to pull the information I wanted fast enough:

http://www.raywenderlich.com/5191/beginning-storyboards-in-ios-5-part-2

Ultimately I got it all working, and I think the biggest roadblock was the idea that the segues still needed to be created in the StoryBoard interface, but that I would trigger them and catch them programmatically.  Given that I wanted different segues to take place depending on whether the user clicked a table cell in the master view, or the associated detail disclosure button.  The trick was to have segues in the Storyboard running from the master view to two other UI views, one for each of the possible segues, but then adjusting the segue type to specify the detail view to ensure that the right part of the splitviewcontroller was updated.

Particularly after some not too disimilar trials and tribulations with Android fragments it makes me wonder if there isn't some way to make mobile development a little less hazardous ...

Of course having got that working there was still the unpleasantly convoluted issue of trying to make the test in a UITableViewCell wordwrap to keep me entertained:

http://stackoverflow.com/questions/2906090/how-to-make-text-in-a-uitableviewcell-wordwrap
http://stackoverflow.com/questions/494562/setting-custom-uitableviewcells-height
http://the-lost-beauty.blogspot.co.uk/2009/11/multi-line-uitableviewcell-using.html

I kind of hacked a solution there.  It seems remarkable that there isn't a dynamic sizing solution that doesn't require hacking at code - maybe I just haven't found it yet.

I think I was also also tripped up by the detailTextLabel not being visible:

http://stackoverflow.com/questions/5190648/why-is-detailtextlabel-not-visible

All my attempts to set a nice background gradient for some elements in the table view failed :-( The top three StackOverflow hits for my google search on "CAGradientLayer UILabel" seemed promising, but I couldn't get it to work.  I did however manage to get something to appear by creating a dummy transparent PNG of the right size and then was able to dynamically create a UILabel with a number on it.


Android ListViews in Tablet Fragments

Putting together a ListView demo for my mobile programming class turned out to be a bit of a pain. I guess I set myself for difficulty by trying to replicate Paul Hegarty's demo of adding a favourites list to a graphing tablet calculator, but I thought I had sufficiently reduced the difficulty level by not trying to replicate the iPad popover, and instead went for a simple ListView embedded in the main Calculator view.

I fell foul of a number of issues, several of which I have encountered before and one might have hoped I wouldn't have been tripped by them again.  They include

1) need for embedded ListViews to have special IDs
2) nature of ArrayAdapters
3) variations arising from fragments

One of the early errors that slowed me down and forced me to create a separate FavesFragment to handle the list in isolation was the "inflating fragment error"  The following StackOverflow posts helped orient me ...

http://stackoverflow.com/questions/7162403/binary-xml-file-line-9-error-inflating-class-fragment
http://stackoverflow.com/questions/6500408/add-static-header-to-listfragment-in-oncreateview

I spent a lot of time thinking that an AsyncTask was going to be necessary in order to enable the listview data to be updated (e.g. add more rows), but that turned out not to be the case.  The key trick there was to do any addition to the data through ArrayAdapter.add, and basically forget about any reference to the initial data passed to ArrayAdapter - ultimately I just initialized with an empty ArrayList.  There were several confusing StackOverflow posts that deflected me from ultimately finding salvation in the android irc channel on freenode.net

http://stackoverflow.com/questions/6799121/listview-freaks-out-when-i-try-to-update-the-arrayadapter-is-the-header
http://stackoverflow.com/questions/3669325/notifydatasetchanged-example
http://stackoverflow.com/questions/9206275/how-to-create-multiple-listviews-with-fragmentsif-possible-with-listfragment

Well this second one should have helped me more, but I was trying to do much at once, as well as programming Pythonically in Java, which often gets me into trouble ...

And I think this android developer blog got me a bit further:

http://android-developers.blogspot.co.uk/2011/02/android-30-fragments-api.html

but annoyingly it was like much of the android docs; code fragments, but not an actual working system.  Ultimately it was IRC that sorted me out, with other developers pointing out that the key issue was updating the data through the ArrayAdapter itself.

I also burnt time seeing if I could get some simple persistence going with Preferences, but it seemed that unlike in iOS, I couldn't store any more than a simple set of Strings in light weight preferences, which wasn't quite sufficient for the stack object I was working with, or maybe it would have been okay?  Hmm ....

Language Models and Python Reflexes

So I burnt slightly more time than necessary on the NLP homework writing my own bigram/unigram calculating code in order to calculate plus one smoothing values on a small corpus.   However it was interesting Python background in terms of the much tripped over integer division issue in Python:

http://stackoverflow.com/questions/1267869/how-can-i-force-division-to-be-floating-point-in-python
http://stackoverflow.com/questions/1282945/python-integer-division-yields-float

As well as an interesting review of the multitude of quick ways to get an item count from a list in Python:

http://stackoverflow.com/questions/2401885/how-to-get-item-count-from-list-in-python
http://stackoverflow.com/questions/3496518/python-using-a-dictionary-to-count-the-items-in-a-list

and my old favorite how to grab a list pairwise in Python:

http://stackoverflow.com/questions/1257413/iterate-over-pairs-in-a-list-circular-fashion-in-python

iPhone/iPad demos for online class

So I was impressed to see Paul Hegarty demo-ing iPad apps in the Stanford iOS class using an iOS dock to hdmi cable adapter, and there seem to be many of these available.  However it doesn't quite meet my needs for an online class.  I'd like to see my iPad or iPhone screen appearing in a window on my desktop computer so that I can run a demo and use Screenflow to record the activity on the phone/pad along with slides, XCode etc.

There seems to be some talk of supporting this via VNC or similar, but a superficial look suggests that all these are for viewing your desktop computer on your iPad etc., and not quite what I am looking for.

http://forums.macrumors.com/showthread.php?t=912536
https://secure.logmein.com/products/ios/

Friday, March 30, 2012

Not so much Ice Cream Sandwich just yet

So I go to my Acer tablet and find it's on Android 3.0 ugh - need to upgrade, need to get it on Wifi, so I need the mac address (googled "acer android mac address"), of course then my BTInternet box wanted my password to adjust the mac filtering, so I had to start up FF cos most of my password are stored back there, but FF bootup takes a while.  In the meantime I get an annoying text from my cell provider "3", which I can't shut off without logging in to their website, for which I don't remember the password and their password reminder requires that I give them the last 6 elements of the SIM, and I don't have a paperclip to push the SIM out of the iPhone since I used my spare paperclip that I usually carry in my wallet to fix my 3 year old's crocs the other day, argh!

Found staple, that failed, must look for paperclip - in the meantime got system update started for Acer.  Got paperclip, got SIM out, got password sent to mobile device, unable to find anything about opting out in 3 website ... hmm, hmm.  Seems like others have had trouble opting out.  I found what seems like the right place to do it for 3:

https://www.three.co.uk/My3Account/Pay_Monthly/Marketing_preferences

and I'd post back to those previous two forums, but both require me to sign in ... ah we need a better overall solutions for passwords/security/spam etc. ...

Got to wait till Acer is on 30% battery before system update, but no USB charging argh!  Ah but charger can be plugging in separately.  And there should be an ice cream sandwich update.  Google searches for acer development settings didn't get me anywhere, but found them under settings -> applications -> development, so now eclipse can see tablet, but can't deploy 4.0 because charge is still only on 17%. 

Okay, got charge.  First update, not 4.0 - starting second update.  Feels like I have to wake the thing up to get the downloading to continue, okay so now I am on 3.1 and downloading another update ... switched to "stay awake" keeping the screen on whilst charging setting.  Now I'm on 3.2 and no more updates, boo!  Looks like it was only the A200 that's got the 4.0 update, not the A500, which is slated for April, so no 4.0 tablet demos for the moment :-(

Thursday, March 29, 2012

BDD/TDD for Mobile (Android/iOS) Part I: Roboelectric Install

So inspired by the Coursera SaaS class, I have been bashing my head against TDD/BDD for mobile again. Let's document some of my findings.

 Robotium and Roboelectric are black box testing options for Android. I got stuck on Robotelectric needing apache ant >= 1.8 and I just re-came across my install attempts in my browser tabs. So I just got that all set up.

 I did notice that I seemed to have all sorts of ant paraphenalia around. I do of course remember ant reasonably fondly from my intense Java programming days. Certainly with more fondness than Maven.

Anyway, so at the risk of exposing my shaky UNIX sys admin knowledge I found that I had ant installed in a couple of places on my OSX machine, specifically:

/Users/samueljoseph/Code/java_libs/apache-ant-1.7.0
 /usr/share/java/ant-1.7.1
 /usr/share/java/ant-1.8.1
 /usr/share/java/ant-1.8.2

so it turned out that I already had the ant I needed on my OSX, and I had not necessarily needed to pull down ant-1.8.3, but I had done that anyway; but having down that I threw that in there as well

 /usr/share/java/ant-1.8.3

hastily adjusting the groups and owners in what looked like me a neat fashion:


 sudo chown -R root /usr/share/java/ant-1.8.3
 sudo chgrp -R wheel /usr/share/java/ant-1.8.3

although to be honest I am not sure if that will have turned out to be necessary, or even done correctly, and in fact it turned out that my ant from the command line was already pointing to 1.8.2


/usr/bin/ant
unknownc8bcc8da38b2:RobolectricSample samueljoseph$ ls -ls /usr/bin/ant
8 lrwxr-xr-x  1 root  wheel  22 Jan 25 11:36 /usr/bin/ant -> /usr/share/ant/bin/ant
unknownc8bcc8da38b2:RobolectricSample samueljoseph$ ls -la /usr/share/ant
lrwxr-xr-x  1 root  wheel  14 Jan 25 11:36 /usr/share/ant -> java/ant-1.8.2

through a series of symbolic links, and it appears that an ANT_HOME variable set in my .profile file was overriding that.

unknownc8bcc8da38b2:RobolectricSample samueljoseph$ more ~/.profile 
export PATH=/opt/local/bin:/opt/local/sbin:$PATH
export DISPLAY=:0.0
export EDITOR=/usr/bin/nano
export ANT_HOME=/Users/samueljoseph/Code/java_libs/apache-ant-1.7.0
export JAXB_HOME=/Users/samueljoseph/Code/java_libs/jaxb-ri-20070122
export JUNIT_HOME=/Users/samueljoseph/Code/java_libs/junit4.4
export AVETANA_HOME=/Users/samueljoseph/Code/java_libs/avetana-jsr-82/
export BLUECOVE_HOME=/Users/samueljoseph/Code/java_libs/bluecove/
export JAVABT_HOME=$AVETANA_HOME
PROMPT_COMMAND='echo -ne "\033]0; ${PWD/$HOME/~}: ${USER}@${HOSTNAME}\007"'

and removing that ANT_HOME variable there and (I think) running source ~/.profile allowed RoboElectric to run :

Buildfile: /Users/samueljoseph/Code/RobolectricSample/build.xml

clean:

-pre-clean:

clean:

-setup:
     [echo] Gathering info for RoblectricSample...
    [setup] Android SDK Tools Revision 16
    [setup] Project Target: Google APIs
    [setup] Vendor: Google Inc.
    [setup] Platform Version: 2.3.3
    [setup] API level: 10


Although to be honest, I now forget what RoboElectric is actually supposed to be doing.  I had started my poking around with finding a deleted blog article about installing ant on OSX


http://webcache.googleusercontent.com/search?q=cache:X40LT6LETnIJ:gauravstomar.blogspot.com/2011/09/installing-or-upgrading-ant-in-mac-osx.html+&cd=6&hl=en&ct=clnk&gl=uk

Perhaps deservedly deleted due to a number of technical errors.  Either way, between that article and the various symbolic links I discovered I was left no clearer on whether there was some systematic method to manage ant on OSX, and I just went with the one that had greater mass, i.e. the two or three versions of ant in it.  At least on Debian I used to be pretty sure that apt-get was the way to grab software and that on windows all bets were off, and I used to be trying to use ports consistently on OSX, but then that failed when I upgraded the OS, and then it started working again, and now I am just not sure what I am supposed to be doing ...

So working through deleting more tabs, I find that I found some slides that covered some of the different testing options:

http://www.slideshare.net/atobulreddy/android-automation-testing-by-atobulreddy

which reminded me about the Android instrumentation framework, which I do have running.  Actually it seemed I could just run vanilla JUnit tests on peripheral android classes (i.e. ones without android specific functionality) in eclipse on individual classes within my android projects, and when I added a few Android Instrumentation ones (in a separate Android Testing Project, as per instructions) that the existing vanilla JUnit tests also got run anyway, but the Android instrumentation framework, which I think had been painfully slow before, seemed not too bad, particularly if I ran the tests on my externally connected Galaxy Nexus.

There was a blog article that I was following (which I just found yay!) from 2009 talking about the pain of android testing, but perhaps with faster and faster android phones, we can cut out the slow emulator and make android testing less arduous; although I get the sense this Android Instrumentation framework may have been released since that article, or at least the article is trying other approaches that don't work so well.

Of course all this reminds me how frustrating it was that my android talk at the testers workshop last summer was at the same time as a real android expert was talking about android testing, and his talk wasn't recorded (whereas mine was), so anyway ... but back to the slides, which mention Monkey, Robotium and Roboelectric.  I've yet to try Monkey, although there's mention of python so that looks interesting.

So anyhow, it would appear that I downloaded the RoboElectric sample.  And it looks like I was following their github sample project instructions when I got distracted by other work. So "ant debug" now generates an app to be debugged, but I can't run adb till I have an emulator running so now I wait while first eclipse and then the emulator startup, and I reflect how it would be great if I properly documented all of my hacking processes like these, particularly because in the two days prior to hacking on Android BDD/TDD frameworks I had done the same for iOS, and got the OCUnit tests working for iPhone up to a similar level of functionality as I subsequently got the vanilla unit tests working for Android, and found that OCUnit and the Android Instrumentation Framework pretty much paralleled each other in allowing one to simulate button presses in code calls to specific Activities (Android) or Controllers (iOS).

And then in the two days following my attempts to look at Robotium and Roboelectric which interestingly parallel at least some of the capabilities of the OSX Instruments "Automation" framework which I had also been looking at, but as I was saying, in the following two days I had been sucked into iPad development and burned many hours solving little iPad issues, particularly relating to SplitViewControllers, thus the generation of countless tabs of links to places like stackoverflow, burying my tabs on RoboElectric and Ant installation procedures.

BTW, the android emulator is still booting as I write this and it occurs to me I could have just plugged in the Galaxy Nexus ... so I do that, and reflect that it would be nice to be writing out my programming/hacking thoughts and including links to all searches and finds relevant and otherwise, and I speculate about some kind of semi-automated process, but conclude that really I should just keep a blog window open at all times for documentation purposes ...

So the adb doesn't seem to detect the connected Galaxy Nexus, and the emulator is STILL booting and I start to try and close more tabs and find a few other interesting notes to record, such as the android equivalent of iOS popover tabs:

http://stackoverflow.com/questions/5663912/android-popover-controller-same-as-ipad

which don't immediately seem to support the full flexibility of iOS popovers.

But now the emulator is running and I get this error:


unknownc8bcc8da38b2:RobolectricSample samueljoseph$ ./../android-sdk-mac_86/platform-tools/adb -e install bin/RoblectricSample-debug.apk
error: device not found

Googling the error message takes me here:

http://stackoverflow.com/questions/5405562/adb-errordevice-not-found

which reminds me of that command to get the list of devices

unknownc8bcc8da38b2:RobolectricSample samueljoseph$ ./../android-sdk-mac_86/platform-tools/adb devices
List of devices attached
01498B1A16010012 device

which reminds me that RoboElectric won't work with real devices, so I unplug the Nexus, and my emulator is still not in the list:


unknownc8bcc8da38b2:RobolectricSample samueljoseph$ ./../android-sdk-mac_86/platform-tools/adb devices
List of devices attached

unknownc8bcc8da38b2:RobolectricSample samueljoseph$



https://www.google.co.uk/search?q=device+not+showing+in+adb+devices
http://stackoverflow.com/questions/7502011/emulator-not-showing-in-adb-devices

makes me try the following:


unknownc8bcc8da38b2:RobolectricSample samueljoseph$ ./../android-sdk-mac_86/platform-tools/adb kill-server
unknownc8bcc8da38b2:RobolectricSample samueljoseph$ ./../android-sdk-mac_86/platform-tools/adb start-server
unknownc8bcc8da38b2:RobolectricSample samueljoseph$ ./../android-sdk-mac_86/platform-tools/adb devices
* daemon not running. starting it now on port 5037 *
* daemon started successfully *
List of devices attached
emulator-5554 device

so we are good there, same issue as we often encounter on eclipse - such a pain - what is up with that Google?

So anyway, so then I get:


unknownc8bcc8da38b2:RobolectricSample samueljoseph$ ./../android-sdk-mac_86/platform-tools/adb -e install bin/RoblectricSample-debug.apk
708 KB/s (278190 bytes in 0.383s)
pkg: /data/local/tmp/RoblectricSample-debug.apk
Success

but no tests run.  I can run the app by selecting it, and get a few screens including a pivotal tracker log in, but am left wondering whether I just ran some tests or whether using ant instead of maven broke all this.  I'll add a screenshot and leave it there for the moment.  Looks like I have missed something, or perhaps I just have to write up some of my own tests ...