Category: Mobile

Conferences

Stir Trek 2014 Talk Recap

Stir Trek LogoI did it! Mission Accomplished (and I don’t mean in that ironic “banner on an aircraft carrier” way).

A few months ago, I submitted a talk to Stir Trek and it got accepted. I had wanted to speak at a conference again, but I was super stumped as to what to talk about that would be interesting enough to stand out. There were only 40 speaking slots and hundreds of applicants, so it had to be good. Part of the selection this year was done blind (based on nameless abstracts), so content really needed to be key.

Thankfully, my co-worker Jey came up with a great idea. He suggested talking about how to do push notifications in iOS. I wanted to really think big, so I expanded it to include Android. Another co-worker, Jeff, thought that if I included Win Phone 8 I would really increase my appeal. So, I submitted this:

Don’t Call Us, We’ll Call You: Push Notifications in iOS, Android, and Win Phone 8

Mobile is the future and one-way-only conversations are boring. Find out how to keep your app’s users in the know with push notifications. In this session, we will evaluate the push notification landscape, see why push notifications are useful, and how you would send and receive them to iOS, Android, and Windows Phone 8 devices. Then, we’ll take a look at writing a push server, and evaluate the pros and cons of rolling our own versus leveraging a Notification as a Service platform such as Urban Airship or Parse.

As I mentioned in my talk, my original idea was that writing the native push servers would be a really bad experience and then the cloud providers would wipe all of my tears away. Nothing could have been further from the truth. I mean, the native push servers (especially iOS) definitely had their challenges, but once you write them, they are done. The cloud providers don’t protect you from the worst parts of setting up the push servers, anyway. Their benefits aren’t ease of development, but rather their reliability and extra features that they offer that don’t show up in a simple push demonstration.

Preparing for the talk was a lot more difficult that I originally thought and took at least twice as long. I wrote an iOS application, an Android application, a Windows Phone 8 application, and a .Net REST service to push to them. I deployed the .Net service to an EC2 instance so that it would be available everywhere.

The code to make the application do what it needed to do at its core wasn’t difficult (on purpose). However, the amount of yak shaving that I had to do to get things rolling in iOS, configure the EC2 instance, and get the Windows Phone 8 environment running inside VMWare were really painful.

I did learn a lot, though. Thankfully, all of my demos went off without a hitch. That was my biggest fear, but I was very fortunate to have had no problems at all. My next biggest fear was that I’d get questions that I had no idea about. Fortunately, I got great questions from the audience and I was able to speak to them with some degree of intelligence.

I had a lot of friends turn out to see me talk, which helped a lot. It was also an amazing experience to present on such a huge screen and in such a large room. Add to that the way that the speakers were treated by the amazing organizers (see our speaker room spread here), and it served to make the entire day very special for me.

As promised, all of my code and slides are up on the Stir Trek Github Repo under the Mobile track, so check them out.

If you were at my talk and would be so kind as to rate the talk (and give any optional feedback), I’d really appreciate it. You can do that here.

Android

Dynamically Preventing Rotation on an Android Fragment

Recently at work, I’ve been working on making an Android version of the company’s iOS application. The application itself runs entirely in portrait mode, except for the image of the benefits card that is included in the application. In iOS, that was easy enough to accomplish. In Android, the most common way to limit orientation changes is on a per-activity basis in the manifest, like this:

<activity
   android:screenOrientation="portrait"
   android:configChanges="orientation|keyboardHidden">
</activity>

Unfortunately, we can’t do that. Our application makes use of the “slide out” menu that was made popular in the Facebook application, but that you can now find as a very common pattern in many applications. The way that you accomplish this pattern in Android is by using the DrawerLayout and by using Fragments. Fragments are much like User Controls in Asp.Net WebForms or Partial Views in Asp.Net MVC or Rails. You have a container and you can load different layouts into that container, while maintaining the rest of the page’s layout as-is. The code that drives the fragment layouts has its own lifecycle (making it much more like WebForms User Controls than a Partial View).

The problem that this causes us is that we have one activity that sometimes we want to be able to rotate and other times, we want to keep it locked into place depending on which fragment is loaded at any given time. I searched and searched and could not find a solution that worked for us 100% of the time and was simple enough to implement. Eventually, I came up with my own solution to this problem.

The code for this entire project can be found on GitHub. For demonstration purposes, the project is based on a Sliding Menu project created by Ravi Tamada. Most of the code is his, with just the modifications I’m going to discuss here.

The menu looks like this:
The Slide Out Menu

When you click an item, it loads a fragment into the main window section. Here are the landscape modes of the Home Screen, followed by the Communities Screen:
The Home Screen in Landscape

The Communities Screen in Landscape

What we want, however, is for the Communities screen to remain in portrait mode no matter how we turn the phone, but the other pages can rotate. To accomplish this, I modified the method that is called whenever someone selects one of the menu items out of the menu.

/**
	 * Diplaying fragment view for selected nav drawer list item
	 * */
	private void displayView(int position) {
		// update the main content by replacing fragments
		Fragment fragment = null;
		
		// We allow the Sensor to be used in all instances by default
		setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR);
		switch (position) {
		case 0:
			fragment = new HomeFragment();
			break;
		case 1:
			fragment = new FindPeopleFragment();
			break;
		case 2:
			fragment = new PhotosFragment();
			break;
		case 3:
			// In just this one instance, we turn the sensor off
			// Until a different menu item is selected, which re-enables it
			setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_NOSENSOR);
			fragment = new CommunityFragment();
			break;
		case 4:
			fragment = new PagesFragment();
			break;
		case 5:
			fragment = new WhatsHotFragment();
			break;

		default:
			break;
		}

		if (fragment != null) {
			FragmentManager fragmentManager = getFragmentManager();
			fragmentManager.beginTransaction()
					.replace(R.id.frame_container, fragment).commit();

			// update selected item and title, then close the drawer
			mDrawerList.setItemChecked(position, true);
			mDrawerList.setSelection(position);
			setTitle(navMenuTitles[position]);
			mDrawerLayout.closeDrawer(mDrawerList);
		} else {
			// error in creating fragment
			Log.e("MainActivity", "Error in creating fragment");
		}
	}

Notice that the first thing we do is allow the orientation sensor to work.

setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR);

However, as we are setting to load the fragment for communities (if that is selected), we turn the orientation sensor off.

setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_NOSENSOR);

That causes the device to not rotate and to return to the original orientation, no matter how you are holding the phone when it loads.

After this change, we see the following. The home screen looks right in portrait mode:
After - The Home Screen in Portrait

Rotating it, does make it move to landscape:
After - The Home Screen in Landscape

But, when I choose Communities and we are in landscape, the app will only display portrait mode:
After - The Communities Screen in Landscape

That’s all there is to it. If you have a better solution, please feel free to leave it in the comments. If you want to check out the code and play around with it, here is the link to the repo again.

iPhone

Best Nine Dollars a Month You’ll Ever Spend

I’ve been getting more and more into iOS programming recently. It is something that I’ve been doing more and more as a hobby, as well as landing a few paying consulting roles creating native iOS applications. I’ve kind of been “marinating” in iOS for some time, but about a year ago I started really getting serious and attempting to have an actual goal with regards to Objective-C and iOS.

One good FREE resource is the Introduction to iPhone series on TekPub with Ben Schierman. It was done a few years ago, and Rob Conery has now given it to the community. It is a little out of date, but you can’t beat the price and it will help you learn a few things.

I have a TekPub subscription, so from there I moved on to Show Me Objective-C, another Ben Schierman TekPub series. I really liked the way that Ben explained things, so I started doing a little cyber-stalking digging about him and I discovered his site over at NSScreencast.

Ben has some free videos there, as well. I downloaded and watched them all and learned a TON. His video about AFNetworking alone was worth the time. I noticed that he had a subscription package initially, but didn’t check back into it until I had watched all of the free videos. I’m glad I did. He offers full access to his videos (new ones weekly) for only $9.00 a month.

This is a BARGAIN!

I feel like – thanks to Ben – that I am an honest-to-goodness-real-life iPhone Developer now. I’m not scared of Xcode, I’m not mystified by Objective-C, nothing. With the videos he has to date, you can spend a weekend and gain an insane amount of confidence on the platform. I highly recommend it.

Business of Software

A Mobile Strategy?

Harvard Business Review published an article at the end of last month titled Building a Mobile App Is Not a Mobile Strategy. The TL;DR; version is that mobile is not an item to be marked off of a checklist. It is bad if your company just created a mobile app so that you can answer “yes” when the CEO asks, “Do we do mobile?”.

I heard someone speak at a conference here in Ohio who was making this same point. Some time ago, the best visual medium for advertising was the print ad. Since that was the end of the standard understanding, when the web came about, people set out to put up what we now call “brochureware”. Basically taking their magazine ad or brochure and putting it up on the web. No real interaction and no reason to ever have a repeat visitor. Hey, but at least they had an “Internet Strategy”, right?

The same thing is happening now. Mobile is hot, so people are trying to create mobile apps that are nothing more than advertisements or brochureware for their product or business. Not a lot of people “get” mobile yet, so the good ideas are coming slowly. However, just as companies began to create interactive websites that provided a service or amusement while educating or advertising their service, that time will arrive for mobile, too.

Sit or SquatEven now, forward thinking companies are getting it. The article mentions Proctor and Gamble’s sponsorship of a 3rd party application called “Sit or Squat” that helps locate public restrooms wherever you are, while at the same time keeping Charmin at the forefront of your mind and associating it with the best possible restroom experiences.

Having an idea or a strategy for what you will do to “accomplish” mobile is great, but the Harvard Business Review article pretty much stops there. In my opinion, the key to having a dynamic and impactful mobile strategy isn’t just how you will market to consumers. It encompasses how your employees will be productive. What sorts of applications could your employees use “on the go” (in meetings, during travel, etc) on a smartphone or tablet device? How will you deliver those applications to them?

The other big key to a successful mobile strategy is integration with your existing business platform. What sorts of services or APIs does your organization have exposed to allow mobile applications to integrate with your systems? If you have none, what would it take to create them? This to me is the heart of a Great Mobile Strategy in the Enterprise. It is mobile as an integrated natural evolution of your systems in a way that encourages productivity and growth. And that is the hard part.

If you aren’t in a place where new applications can integrate with you, then you are in a place that is stagnant. If every new application has to tear down and throw away what came before it, you are asking to fall behind. A Great Mobile Strategy starts with a Great Overall IT Strategy that allows mobile to become not just something “checked off” or “bolted on” but a full-fledged member of your company’s application stack.