Tuesday, June 18, 2013

Why I stopped using Android Studio - for now

I was pretty happy using Android Studio. Loved the way I could see the preview of a layout while working on the layout. I had written a new app from scratch to match the functionality of our current iPhone app using Android Studio. I also like the dark theme they provide. Easy on the eyes.

Then I ran into a problem that made me stop using it. I wanted the app to run on more devices so I turned towards ActionBarSherlock. I found various posts on Stack Overflow on how to make it work. I tried them all but was ending up with some weird gradle errors that I was unable to solve.

Gradle: A problem occurred configuring root project '{my project}'.
> Failed to notify project evaluation listener.
   > Main Manifest missing from /Users/kpeck/AndroidStudioProjects/{my project}/AndroidManifest.xml

I have a manifest file of course. It is not in the directory given. I even tried to copy my the file to that directory, even though it does not belong there, and attempted the build again but it still did not work.

It is possible that starting a project from scratch with ABS in it and then copying in my files may work. I will have to give that a shot at some point.

Having run ActionbarSherlock under Eclipse in the past I knew pretty much what to do and had it up and running in a matter of minutes. Import the project into the workspace, delete the duplicate android-support-v4.lib, set the dependency between ABS and my project and it was working. I spent the rest of the day converting code to ABS format. That was generally pretty easy with a few minor snags around loaders.

At some point I may go back and attempt to get it working in Android Studio but right now I need to move forward on the project. I have other areas that I want to convert to activities hosting fragments. Currently I only converted the one that needed a loader but I have some ideas on how to layout items on a tablet that would benefit from fragments.

Android Studio keeps changing the way you deal with project settings. It was through a dialog but now they want you to manually edit things in the build files. Somethings happen automatically as you import but it does not seem to finish the job. It is still alpha software and they are pushing out changes quite often. I want to get familiar with gradle but I don't have the time to pause right now and do that.

I also found the preview has some issues especially with Relative Layouts. The above / below / left / right layout parameters seem to be suggestions in the preview. They work fine in the emulator or on a device but that gets frustrating. I may see the screen look just right in the preview then a change to the XML in an area unassociated to the Relative Layout will cause it to paint incorrectly, usually overlapping controls. Really need a preview I can trust so I am not chasing down issues that don't exist.

Probably good to wait another release or two of Android Studio. There will be more tutorials on how to make things like ABS work with it and I can skip the headaches. Back to trusty old Eclipse for now. I found a dark theme that is reasonable for it but it only changes the editor pane. That is the largest part of the screen so it is better than nothing.

Wednesday, June 12, 2013

Cancel SVProgressHUD process by tapping on HUD


I am using NSURLConnection to potentially pull a lot of data from the server based on user search criteria. There are times when the user does a pretty board search and getting the results back can take a couple of minutes. It can be a waste of the user's time and server processing especially when the user realizes how much data they are about to get back. I wanted to add a [Cancel] option. Since I already had this working on the Android version I really needed to make it happen on iOS. I looked on the SVProgressHUD site and there was a rather heated discussion about this and how if I was using the HUD to run super long processes then I was doing it all wrong. 

Obviously I beg to differ on that point. I have a potential long running process based on a user request and I show a progress indicator and allow the user to cancel as needed. The code below shows a simple sample but I actually show "Processing record X of Y" in my code so the user gets a feel for how long the process is going to take. I don't know how many records are coming back in the response until I make the request so I can't give a "Are you sure you want to suck down 10meg of data?" message first.

After reading the SVProgressHUD site I investigated some other HUDs to see if they solved my needs but found them to be harder to use or they had other issues once I hooked them up in code. I sniffed around in the SVProgressHUD source code and discovered a solution - Notification Center messages.

Just before I show the HUD I do the following:

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(hudTapped:) name:SVProgressHUDDidReceiveTouchEventNotification object:nil];

A sample of showing the HUD which lets the user know how to cancel the operation:

[SVProgressHUD showWithStatus:@"Requesting data...\n(tap to cancel)" maskType:SVProgressHUDMaskTypeBlack];

The method that gets called when HUD is tapped:

- (void)hudTapped:(NSNotification *)notification
{
    NSLog(@"They tapped the HUD");
    // Cancel logic goes here
}

and any time I am done with the HUD, either via tap to cancel or run to completion, I call:

[SVProgressHUD dismiss];
[[NSNotificationCenter defaultCenter] removeObserver:self name:SVProgressHUDDidReceiveTouchEventNotification object:nil];

So far it is working like a champ and appears to be a pretty clean solution. I hope you find uses for my discovery as well. Maybe you want to put in an Easter Egg if they tap it 10 times. Have fun.

Thursday, June 6, 2013

Use adb to update APK on device even with emulator running

For my Android development I use the fast HAX based emulator on both my PC and Mac. I do the bulk of my testing on the emulator and push the APK to a real device maybe once a day to to make sure everything still looks good and runs as expected.

If you try adb install {yourapp}.apk it gets mad if it finds multiple devices such as a physical device and the emulator. Plus install gets annoyed if the program is already installed on the device.

You should use the following command

adb -d install -r {yourapp}.apk

The -d option tells it to find a device attached via USB. The -r tells it to upgrade which keeps all the existing app data in place which is handy if you are using SQLite databases or have settings saved such as username and login server. This command can save a lot of time and headaches as you don't have to shut down the emulator to push to a device and you don't have to lose any saved data.

If you have a lock screen enabled you will have to unlock the phone before you can push the update to it.

You can also use adb -devices to make sure it is finding the USB connected device. There are times you have to unplug and replug the USB cable to get things working.

Wednesday, May 29, 2013

Back as solo mobile developer - not easy

Being the solo mobile developer at a job is not easy. I had just gotten used to having a couple of developers around me at my previous contract position. Everyone had bits and pieces of experience in different areas so you would quickly get answers to questions without doing a Google search. They might have some sample code laying about from another project or just know how to do it.

Sure the big boss here wrote the initial iOS code that I have been cleaning up and adding features against but I rarely get to speak with him and he has no Android background. I have been working on the Android port this week getting stuck on silly things that the guy I worked with at the last place would have handled with ease as he had a lot of background in those areas. Now that the core networking is in place I can start moving forward at a pretty good clip.

A real feeling of isolation when you have developers all around you but they either don't know the language (Objective C) or the framework (Android SDK) thus you can't really bounce any ideas off of them. Sure I can hit them up for general business knowledge or Java questions but not for the meat of the development cycle.

For my Android work I have been using Android Studio. I know it is a 0.1 release but that is really just the Android plug-in side of things. The over all IDE is at version 12 and I have enjoyed using IntelliJ in the past. I like the dracula theme as far as colors go.

The ability to edit layout XML and see the results side by side in the preview window is super handy. I have gotten that to generate crash reports from time to time but they did not kill the IDE or lose any of my work.

What I miss from Eclipse is the new class wizard. It asks for the base class and interfaces and lets you quickly build things out. I have asked about this on the IntelliJ forms and they basically stated you can do all of that via a number of steps. I want a Wizard. I also want the auto add of the Activity to the manifest. I should not have to do all that work manually every time I add a new activity to the project. Since this is a new project that has been happening a lot.

The Log Cat filter seems pretty iffy too. I turn it on to filter out things but it forgets about that between program runs so I have to go back to "No Filters" then back to my filter again. It is silly how much junk the emulator kicks out into Log Cat. Since I am using the HAX high speed emulator I get a ton of extra stuff.

I was happy to get the upgrade to 0.11 this morning. Good to know there is active work on Android Studio and I am sure it will continue to improve. I have been using it at home on my Win7 64 bit PC and my Macbook Pro at work. Both seems to run equally well.

Wednesday, May 22, 2013

Core Data stinks for bulk inserts - direct SQLLite is much faster

I was handed an iOS app that was using the basic JSON handlers and keeping everything in memory. This was slow and running out of memory for large requests.

I converted the project to use stream based JSON parsing stored to a Core Data database backed by SQLLite. This solved the memory issues allowing all requests to work. There are 5 tables involved with a total of 239,000 records if you requested all the data from the server.

The problem - that request took 5 minutes and 43 seconds to process on an iPad 2. It took 33 seconds on the simulator. Let's state this again - Always test on a device. That kind of time is totally unacceptable.

After sniffing around the net and attempting to speed up Core Data I determined that Core Data sucks at doing bulk inserts. Core Data is really nice at hiding the gut level fun of SQLLite but for large inserts it is not the way to go.

I converted everything to use SQLLite directly and saw a massive speed increase. I can now process the same record set in 1 minute and 23 seconds. That cuts a whopping 4 minutes and 20 seconds off the time. The simulator went form 33 seconds to 12 seconds.

A typical user would rarely if ever request all the records but testing worst case scenario is really the best way to go. The speed improvement is seen across the board in the app with similar percentages of improvement. I am very happy with the results even though it took a couple of days to get it all sorted out.

As for the code there are areas that are more involved than the Core Data version and there are areas that are actually a lot cleaner. Everything is a trade off and there is no clear winner.

I had never used Core Data before. It was a really good learning experience to set it all up using the GUI editor in Xcode and finding out what it took to add the Core Data library and support code to an iOS project that was created without it originally. I found a lot of Core Data really straight forward and easy to use. I will not shy away from it on other projects unless they involve bulk inserts.

Having used SQLLite in the past I had a basic object set to start with and I knew my way around FMDatabase. My previous experience did bulk insert processing and I wrote both iOS and Android versions so I stuck with SQLLite to make it easier to convert code back and forth. I wanted to learn something new this time around so I went with Core Data. Good thing I could quickly fall back on my direct SQLLite experience to solve the speed issues that arose.

Tuesday, May 21, 2013

Mobile app usage and development - do you just have to magically know what to do?

The more mobile development I do the more I am finding you are just expected to know things magically. There are very few help screens, tips of the day or on screen tutorials. There are so many potential gestures in any app that you need to magically discover. What can we do to make this situation better?

A lot of apps allow swipes to perform an action. Swipe left to call, swipe right to text. Long presses may do something or bring up a menu. Some actions are instant and others prompt you but you are never really sure what will happen. Delete should prompt. Add a new item most likely does not need to unless it will cost money i.e. send a message or use your data plan or will take a long time to perform.

Some will answer the mobile device is so small and we all want to save on code size and people never use help or only use it once so skip it. The original apps were very small and had few features so that worked. News apps have a ton of features. We basically have computers in our pockets and we do a lot of work on them.

Do we need a standard "Cool Features" button showing quick help? Maybe it should show a standardized overlay on the screen to explain the swipes and long presses so people can get more out of our apps.

The other side of this is developer tools. They have a boat load of features too and a lot of their power is there but hidden from the coder. I know Xcode drives me crazy with its lack of right mouse button menus. I expect to be able to perform most actions a context sensitive menu. In general the menus are very terse. Want to add a view controller to a story board? Right click on the story board and you get zooming only options. You have to know to drag a view controller for the Utilities panel. But first the Utilities panel has to be visible. That is the only way to perform this operation. That is not friendly.

Speaking of the Utilities panel it has 6 tabs on it and I seem never to go to the correct one to do what I need. Do do nearly anything you shift between 2 or 3 of the tabs. Somehow I would like the most common settings on a single tab that I could define.

Right click on a segue control and you get zoom options but nothing associated to the segue. Click on the Scene Name in the left hand panel and nothing at all happens. I excepted the editor to scroll to that Scene. You have to click on a view of the scene for that to happen. Oh and it changes your zoom factor when you do that. Just scroll there! If I was zoomed out I want to stay zoomed out!

Is the layout of your windows wrong? Can you right click on something and fix it? No, you have to go to View -> Assistant Editor and pick the layout you want. I did not even know the window I was looking at was called Assistant Editor as nothing on screen indicates that. You can mouse hover over the toolbar button to find that out. Those same buttons are inconsistent. The first three toggle between modes of a view and only one can be pressed at any time. The next three toggle the visibility of views and any or none of them can be pressed but the two sets visually they look identical.

Highlight a word in the editor and hit Cmd+F most editors will automatically put the highlighted word in the search box but not Xcode. I get to copy / paste it up there. Heck I can highlight a word in Eclipse and just hit Ctrl+K to find the next occurrence skipping the Find prompt altogether.

Add files to a project and guess what? They are not flagged as needed to be added to version control. Why? Right click on them to add them and that menu is not there. I have to fire up SourceTree to add them to GIT for this to work. Xcode version control integration is crappy at best.

Tuesday, May 7, 2013

Windows Update error 800B0100 - I finally just gave up

I have been battling Windows Update Error 800B0100 for over a week. I searched the web over and over and tried pretty much every solution presented. I don't know how many times I ran the Windows Readiness Tool, update fixer, fixer fixer, Mr. FixIt, delete this, delete that, uninstall all of these, manually install those, etc.

Nothing made it work. I finally just blew away the VM - this was Windows 7 Professional on my Mac, and did a reinstall from DVD. After many updates it all appears to be working. I have never run into this sort of issue in the past where Windows got so messed up that I had to give up.

Another odd thing, I needed .NET 4.0 so I download that. Right away I have to download 16 patches. This means MS does not keep the installer updated. Must be the original install then you have to download all the patches. Seems a waste of bandwidth to me. I should get a pretty recent version of the .NET 4.0 installer when I download it. I don't expect to download Chrome, 7Zip, Sublime Text or others just to turn around and have its updater run and get more stuff. To me it makes MS appear lazy.

At least it is up and running now. I needed to install IIS but with the update issue that was not possible as the windows features list just came up empty. Now it fills in and I could install IIS. Turns out that was for naught because the final piece of 3rd party software was holding all its errors and only showing me one at a time. It complained about IIS but once that was installed it turned around and told me my OS was not supported. Gee, seems that is a much more important error message. You really should from the worst situation forward or show a list of issues instead of just the first one you find.

Now we have to find and configure a Win Server 2008 to get this all rolling. Guess I will go back to some iOS clean up coding while I wait for that to happen.