Wednesday, August 28, 2013

UITextField Change made by Apple

The following worked prior to Xcode 5 + iOS 6:


@property (weak, nonatomic) IBOutlet UITextField *source;

if (![self.source.text isEqualToString:@""])

It now needs to be

if (self.source.text != nil && ![self.source.text isEqualToString:@""]) {

Previously if the user never touched the text field you got back an empty string. Now you get back a nil string instead. 

Just found this while testing code I am updating for iOS 7 while running on a device under iOS 6.

Shown for simplicity. In the actual code I am using a utility method to trim the string and check for a length of 0. The stupid trim method for iOS is a super long line and can be found all over the web as everyone must write it over and over as Apple does not include it in the base NSString object.

Tuesday, August 27, 2013

Finally have new ActionBarActivity working with Android Studio

Yes I am a sucker for punishment. The new Android Studio 0.2.6 came out today and I found this out my usual way - saw it on Reddit. Since I just battled this beast yesterday I thought I would give it yet another shot.

Post install it still could not build my project but was mad about even more things. I decided to delete the entire project off disk and start fresh especially since it kept being mad about gradle build settings and make settings that I would change and save and it would forget I had done that.

I deleted the project. Started AS, told it to create a new project with old project name, single activity. While it did this it appeared to download some additional gradle files. Probably updating from 1.6 to 1.7 but I am not sure. It did not do that when opening my old project.

Shut down AS. Copied the java source code, resource files and manifest over from the working Eclipse project. I did not want to risk changes to a working project. Started up AS and it found all the files automatically. I love that about Java, just put the files in the proper directly and have at them.

Copy in the build.gradle from this web site http://www.recursiverobot.com/post/59267986367/setting-up-the-new-actionbarcompat-in-android-studio then add the dependencies to the two bonus libraries I am using - achartengine and GSON. Run the rebuild all and everything worked like a champ. No errors. I was able to deploy it to my Note II and it ran perfectly.

Obviously multiple things happened here. AS was upgraded and it needed to upgrade various support tools which it did not do until I forced it via creation of a new project. That is pretty annoying. Once that was in place it is finally working.

I am glad they fixed the issue dealing with Google support libraries. The actual editing you do to the build.gradle is simpler than the project import work I had to do in Eclipse. You can read those steps here http://developer.android.com/tools/support-library/setup.html

Do I think this project will keep working? Who knows, seems on the AS side of things they make changes that require you to start with a fresh project or you are hosed. Gradle is in flux too. I like the editor and layout preview features of AS so I may use it for the next parts of this project. I really want to come up with functional tablet layouts beyond what you can do on the phone. I have everything split into fragments so this should be possible. I also want to use more than just the pie chart from achartengine and have more than one chart on screen in tablet mode.

This ties back into the JavaScript work I was doing in another area of our product. While that works in the browser on tablets it is slow and cumbersome. I should be able to do something similar in native code with large gains in speed and usability.

Using Genymotion to test against various device sizes. Nice and fast and recommended when you are not testing on an actual device. Very happy they added device rotation support.

Monday, August 26, 2013

Converted from ActionBarSherlock to new Android compatibility library

Since I was never able to get ActionBarSherlock (ABS) to play nice with Android Studio (AS) I thought I would convert to the new blessed by Google Android Compatibility Library and the ActionBarActivity.

Of course that did not work out as planned. I finally gave up on AS and just got it working in Eclipse. I tweaked the code and add an action bar menu item, setup a new base class and did some code clean up. It all works great. I guess I need to try it all in AS again but it gets so frustrating. I really like IntelliJ and there are some cool features I am missing by sticking with Eclipse but AS just is not right in the head when it comes to working with 3rd party libraries you need to import as library projects.

Some are now saying "Yeah, the IDE will show an error but it will run on your device!" Look, I hate warnings in my code and tend to turn as many of them on as possible so the IDE catches as many stupid mistakes as it can. Now to have an outright error everytime I build? No thanks.

I do like the new compatibility library. Got rid of the word Sherlock from various areas in the code so it all looks more native and cleaner. I have missed working in Android land and with a little break in the action I have been able to sneak back in there to do some minor tweaks to our app.

My plan is to get it all working in Android Studio so I can use the best of both IDEs. Prior to ABS and now the compatibility library I was not having any issues doing that.

Friday, August 9, 2013

JavaScript and Highcharts

When you work at a smaller shop you get introduced to a lot of technology and you pretty much have to go with the flow. For the past couple of weeks that flow has been down the white rapids of JavaScript for me.

The goal of the project was conversion from flot to Highcharts. Flot offered some very basic graphing and they wanted more eye candy and functionality so they decided on Highcharts. Will cost the company a licensing fee but it will be a much more professional product in the end.

I have not done much JavaScript in the past. I know it is not Java but the syntax is very close so getting up to speed on that was not an issue. Figuring out all the nuances is another story. I have the project up and running now with some final polish so it works better on iPads and Android tablets.

This would be considered a small project. Single page with two tabs. The page contains a dashboard layout control and you can add widgets. Each widget has associated HTML, shared CSS and a JavaScript to query for the JSON data and convert it into Highchart format. We have all the fun of formatted tooltips and configuration settings such as legend position and visibility of data labels.

So where does the fun begin? The whole code / debug cycle is a bit frustrating. I am using Eclipse and Chrome. If I just change a JS file I can save it in Eclipse, hit refresh in Chrome and see the results. If I am changing CSS or HTML I get to clear the cache in Chrome then refresh to see the changes.

Chrome has a decent debugger but you have to make sure you include the JS in the proper file for Chrome to see it as a source file. I had to remove it from a styles.js and move it into a controlling HTML for this to work. Then the break point may or may not work. You end up doing console.log(object) and then just sniffing around in the output console to see what is happening.

Don't forget console.log('Widget is ' + widget); is totally different than console.log('Widget is'); console.log(widget); The first one converts widget to a string which is generally useless. The second set of lines will show widget as an object you can inspect.

JSON.stringify(object) can come in handy at times. You will get circular references for core objects but for looking at return values from the server and what not it works fine. I usually copy that output into Sublime Text 2 and run the JSON formatter on it to get a good look at the results.

Since JavaScript is not strongly typed Eclipse is not a lot of help when it comes to finding variables and methods. You just have to know what is there by opening code and looking around. Not the best way to be productive. You also are not told your code is crap until you run it. I know dynamic languages have their strong points but I really missed this area of strongly typed languages.

Scoping is another bit of fun. If you want to trigger an event from one place and catch it in another, well it works but figuring out the proper scope can be a bit of a pain. It is all up and running but I ended up getting a lot of help from a developer with a stronger JavaScript background than I. In the end I was still unsure why what he handed me worked but I was just happy it did.

Highcharts is a really solid product. I am very happy with its final look. I was able to pull off a number of cool features. I did a lot of web searching to find out how to format tooltips, grab events, set up gradients, use multiple y axis, do stacked bars, etc. It really helped to be able to run jsFiddle sample projects. Guess that is one of the nice things about JavaScript, you can piddle around with it on a webpage before you toss it into your project.