Month: November 2014

I’d really appreciate if you’d head on over and check us out on the Product Hunt Page!!

So much of what I post about Xamarin development comes from my experience doing cross-platform Xamarin dev at Spectafy. There’s lots more Xamarin info to come … in the meantime, we could really use your support!

If you’ve recently updated your Mac to Yosemite, you may be having trouble connecting Visual Studio to the Xamarin Build server.

You know you’re entering the connection pin correctly but you keep seeing the error message…

“The Pin You Entered is Invalid”

Don’t worry, you’re not crazy … It turns out that changes to the network stack in the Yosemite edition of OSX are causing problems in the communication between Xamarin within Visual Studio (running on Windows) and the Xamarin build server (running on OSX).

The Good News: The solution is simple…
Update Yosemite to the latest version, restart Visual Studio and the Xamarin build server and then all should be well.

We’ve been talking about Instruction Overlays (or what we at Spectafy call instructables) over several posts (adding instructables and instructable exit animation) this week. Let’s wrap up the week with one more point about showing instructables on Xamarin Android (next week we’ll look at Xamarin iOS).

So far, for simplicity, we’ve be showing our instructable as a single image file. Although simple, this approach runs into issues due to screen sizes differences with Android devices.

Here’s our instructable on a screen of the desired size (looks good)…

And here it is on a device with a wider screen (not so good — doesn’t cover the right edge)…

One thought is that we might scale or stretch the image but doing so would distort the instructable which we don’t want. It’s important for instructables to be clear and engaging so that our users will want to read them.

Given the wide variety of screen sizes across Android devices, creating a separate image for each screen size would be virtually impossible .. so what do we do?

What we need to do is separate the content of the instructable (the images, words, etc.) from the background. With that, we can keep the content a fixed size, adjust the content positioning, and adjust the background to cover the whole screen.

In the case of the instructable we’ve been looking at this week, we’re now going to need 3 parts.

A graphic for the main content of the instructable

A graphic for the “tap to dismiss” message

A background that will adjust its size without distorting.

For #1 & #2, you’ll need to head back to your graphics person and have them create those images with fully transparent backgrounds. This is also a good time to take a close look at the instructable and see if you might want to make any improvements [ you’re re-doing the graphics anyway 🙂 ].

Here’s our new graphics files … they won’t show well here but if you download them and take a look against a dark background, you’ll be able to see them better.

Graphic #1

Graphic #2

For #3, we can take advantage of Android’s drawable resources. In the drawable folder under the Resources folder, create a file called instructional_background.xml that contains the following…

This file describes a rectangle with a solid fill color of black (000000) that is 80% opaque (CC). The rectangle will draw at whatever size it needs to be.

To create our new screen-size-variation-friendly instructable, we replace the ImageView we created earlier with the following layout description. (In other words, this layout now becomes the last element under the FrameView and you delete the ImageView that was there previously.)

The RelativeLayout element is set to fill the entire screen and has specified our instructional_background drawable as its background. This will give us an 80% opaque black background that fills the screen across all screen sizes and won’t distort.

We’ve then set the main graphic (map_coaching_main) to be centered on the screen.

And finally, our “tap to dismiss” graphic is placed just above the bottom edge of the screen, centered horizontally.

And voila .. we have an instructable that looks good across all screen sizes.

Here’s the narrow-screen device (looking good)…

And the wider-screen device (still looking good)…

We have one other small change to make … We need to be sure that the exit animation we added is applied to the RelativeLayout containing the instructable instead of that single image file we we’re using before.

All we need to do is change the line that did the FindViewById on the ImageView to find the RelativeLayout.

Basically we just set the instructable’s visibility to gonewhich causes it to disappear instantly. We can give the instructable a much more professional look by adding a simple animation that causes the instructable to slide off of the screen.

Adding that effect is as easy as adding 2 lines of code and an animation resource file. Let’s start with the resource file.

Before we can create the animation resource file we need to create an anim folder under our Resources folder (right-click on Resources in the Solution Explorer and choose Add/New Folder).

In this animation we’re telling Android that we want to translate the X position of the View from it’s current position (0%) to a negative 100% (slide it all of the way left); the animation will take 500 milliseconds to execute.

That XML file takes care of all of the hard work.

To perform the animation, all we have to do is load the animation resource and start it.

For an app to be successful you have to be sure your users know what they’re supposed to do in the app. This is where instruction overlays come in (or Instructables as we call them at Spectafy). With an instructable you can overlay specific instructions right on top of the screen just as the user is about to use it. You tell your users exactly what they need to know when they need to know it.

Including instructables in your app is much easier than you might think. Over the next few posts I’ll go over a number of techniques for showing instructables using Xamarin on both Android and iOS.

Let’s start with a basic screen overlay on Android.

The first step is for you or your graphics person [ in my case it definitely needs to be the graphics person 🙂 ] to create the overlay. Be sure that the graphic is semi transparent so that the user can see that the instructable is overlaying the app’s regular screen. Something like this…

Although you can dynamically add the overlay to your screen, the easiest thing to do is simply include the overlay in the screen’s layout resource. Let’s assume that we have an existing layout resource similar to the following…

The ImageView needs to be the last element under the FrameLayout so that its at the top of the z-order and therefore appears in front of the other content

The ImageView visibility is set to “gone” so that it doesn’t normally appear in the screen layout

With the instructable in the layout resource we just need to show it and give the user a way to dismiss it.

In most cases you’ll want the instructable to appear the first time the user visits the screen. You can track a user’s first visit to a screen in a number of ways. The technique I generally use is to store a value in shared preferences (Context.GetSharedPreferences).

When the screen launches I check that value and make the instructable visible if this is the user’s first visit.