Making Android development a little more like Microsoft development

All aboard the Android train!

By day, I mostly use Microsoft development tools, and have used them for YEARS. I’ve been experimenting with some Android development recently, and was annoyed by several missing handy tricks that Microsoft tools have done for years. So, I just coded one replacement.

Commonly, in Microsoft platforms, when you create a user interface element (from VB3 to WPF and Silverlight) and give it an ID/Name, that named element is readily available in code-behind, without any extra effort. Nice.

Android development, apparently, is lacking that feature. So, I created a simple pattern to make it convenient for me. Imagine the following UI element defined in an Android Layout:

<Button android:id="@+id/btnSend" android:layout_width="fill_parent"
     android:layout_alignParentBottom="true" 
    android:layout_height="wrap_content" android:text="@string/send_message" />

As you can see, the id of the Button is btnSend.

Normally, in the backing Java class if you wanted to access that UI element, you’d add code like this:

Button btn = (Button) findViewById(R.id.btnSend);

Simple, but annoying for commonly accessed UI elements (or Views).

I’m not the best Java coder by any means as I’ve not done it full time for more than 10 years and my knowledge of any recent Java innovations is zero. So, take this code with a pinch of skepticism.

private void autoWire() {
    Field[] privateFields = this.getClass().getDeclaredFields();
            
    for(Field f : privateFields){
        f.setAccessible(true);            
        ViewId viewId = f.getAnnotation(ViewId.class);
        if (viewId != null ){
            try {
                f.set(this, (Object)this.findViewById(viewId.Id()));
            } catch (IllegalArgumentException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (IllegalAccessException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
    }
}

Now, in the onCreate method that is typical of an Android Activity, I call the method above, autoWire.

This Java code looks at the current class for declarations like this:

@ViewId(Id=R.id.btnSend)
private Button btnSend;

It’s just an annotation (ViewId), followed by the Id of the control.

The annotation definition is:

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

/**
 * @author WiredPrairie
 *
 */
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.FIELD)
public @interface ViewId {
    int Id();
}

Using autoWire, btnSend is automatically set and ready to rock and roll.

Silverlight to become Microsoft’s next VB6?

There was a huge uproar in the tech blogs this past week regarding some comments made by Bob Muglia (of Microsoft) as reported by Mary Joe Foley in a post entitled, “Microsoft: Our Strategy with Silverlight has shifted.”

The quotes that caused the most ruckus are:

Silverlight is our development platform for Windows Phone,” he said. Silverlight also has some “sweet spots” in media and line-of-business applications, he said.

 

But when it comes to touting Silverlight as Microsoft’s vehicle for delivering a cross-platform runtime, “our strategy has shifted,” Muglia told me.

 

Silverlight will continue to be a cross-platform solution, working on a variety of operating system/browser platforms, going forward, he said. “But HTML is the only true cross platform solution for everything, including (Apple’s) iOS platform,” Muglia said.

OK, so many who read this read a lot between the lines.

Whatever HTML5 means to you (and your definition is likely different than mine unfortunately), it can’t do everything. There’s still a place for Silverlight and Flash in this world. Many consumer facing web sites, simply don’t need Flash or Silverlight. Either of these browser plug-ins can enhance the consumer experience, but rarely are they needed for the average web site. You won’t likely see more Flash or Silverlight on traditional consumer facing web sites.

Thankfully, BobMu responded and tried to calm some fears (which was only somewhat effective).

I’d consider there are a few places where HTML (4+) is not yet rich enough to provide the type of experience demanded by users:

  • Games. JavaScript and HTML just isn’t yet up to the task of creating a good rich game. It’s not really the platform’s fault – it just wasn’t designed with it in mind.
  • Business Applications. It’s great that Twitter can run completely in the web browser or that you’re able to enter a street address to collect a consumer’s home shipping address for a package (with the ability to provide some text hinting as a bonus). But, business applications are far more complex, and require robust data and input handling that are very challenging to handle, especially cross browser. Layout of complex data (tables or not) can be maddening and extremely inefficient in browsers, when data needs to be truncated, formatted, centered, sorted, etc.

    It’s easy to build a ineffective web application in HTML that doesn’t consider the user. Too easy. That’s where the plug-ins can excel when used properly.

Many things can be hacked to work in the web browser without Silverlight. However, this comes at a great cost of development and maintenance and QA. How many times have you written a web application and not needed to fix an issue that happens only in one browser (and worse, only in a particular version)? If you haven’t, it’s likely you haven’t written a complex web application or that your needs are very simple.

This is where Silverlight (and Flash/Flex) both shine. They provide a consistent and robust user experience across supported browsers and platforms. Write it once, and it really should run nearly anywhere the plug-ins are supported without issue. Furthermore, they both provide a better debugging and development experience than JavaScript/HTML.

Even though Silverlight and Flex are best used in Enterprise development, I worry that Microsoft may still abandon the platform sooner rather than later.

Microsoft totally missed the boat on Silverlight for games. If they had gotten a better foothold in that market, I’d be much less worried. I’ve never encountered a game that was written in Silverlight that wasn’t pointed by some Silverlight blog I follow. Flash I encounter all the time. Silverlight should be a decent gaming platform, but the development and design tools for gaming in Silverlight suck in comparison to those provided by Flash. Suck. There’s no real consideration for the type of animation and character creation that the Flash tools provide that game development shops need.

Blend – phhpt. Don’t get me started on how awful that would be to use as an animator. Expression Design? Ha! That thing is a joke compared to Flash CS5. At best, an animator could painfully create illustrations in Photoshop or Illustrator and then import them as layers into Blend, and then try to manage them … yuck. Too many tools and not enough interaction between them.

This is a new game that demonstrated at Adobe Max – beautifully done. It’s using Flash. I can’t imagine it being done in any other platform today.

So, that leaves business applications as the other major distinguishing feature of these plug-ins.

But, will that be enough?

It’s absolutely enough to keep them alive for another 3-5 years without any issues. Even once HTML5 settles into place and the major 3 or 4 browsers implement most of the features, there still will be a lack of good support for typical business applications. Again, it’s just not something HTML 5 was built for. It would require enhancements. HTML 6 maybe?

Eventually, browsers will support the typical enterprise web application needs. It’s at that point that the Flash and Silverlight’s we know of today will be retired. But, neither Microsoft or Adobe is going to sit idly by and watch their platforms die a slow miserable death. Both sell tools. That’s how they make money. The plug-ins generate no real money. It’s the tools. Once the tools stop being profitable, the technologies will be retired or open sourced. For the sake of enterprise development shops, one could hope for the latter (but my guess is that intellectual property issues surrounding much of the plug-in will make this impractical, especially video/audio codecs.).

The best chance for both Adobe and Microsoft seems to be in the application market. Not a pure web application delivered via the browser, but an out-of-the-browser application. Adobe AIR and Silverlight both provide a reasonably robust (and continuously improving) out of the browser experience that in some ways exceeds the native platform capabilities in terms of developer and designer productivity. Both allow developers to be far more productive than the equivalent HTML/JavaScript solution of reasonable complexity.

Furthermore, both are cross platform (Mac OS X and Windows). That’s a huge win for both companies. Although some predict that the rise of “tablets/pads” prove that the end is near for personal computers, Apple’s recent Macbook Air (2010) debut shows the opposite. It’s a slick lightweight laptop. (There are some Win7 notebooks that have similar characteristics). The keyboard is not dead. Giant 8 pound laptops are hopefully dead (except for those who want a “desktop replacement.” The traditional PC tower may be going away for many consumers, but typing and mouse driven interaction isn’t going away any time soon (and laptops aren’t generally very cheap or effective in an enterprise, especially where mobility isn’t important). You may be able to casually browse the web for a couple of hours (?!) on a touch screen tablet (like the iPad), but could you do data entry? Not for very long before you wanted to toss it out the window, or, attach a keyboard.

There’s still a place for many different form factors. As long as there are sufficient business enterprises in need of rich interactive applications, delivered over the web, using web services, there will be a place for Silverlight and Adobe’s Flash. When the time comes and they aren’t necessary anymore, it will be time to port and convert. Microsoft and Adobe won’t want to abandon you in that case either as they’ll want to provide new tools to help you move to the next “web platform.”

Eventually, Microsoft will announce, “Silverlight is being retired. We will support it for the next 3 years.” At that point, you may start the panic. For now though, continue on as usual. Always pick a solution based on the product. Don’t use Silverlight just because you think it’s more fun than HTML. Pick the right tool for the job.

As I said, it will happen. HTML 5 and its friends have accelerated its end, but it’s not happening so soon you should be considering throwing out all of your Silverlight books. Keep them. In fact, this is a good one.

(I would predict today though that Adobe’s products will outlast Microsoft’s)

Zune EULA fail.

OK, I get it. 99.9% of people don’t read the EULA. So, The new Zune software update minimizes the space used by the EULA in the installer/upgrader:

SNAGHTML8b4579e

Notice the scroll bar. It’s really not practical to read at that size. The window isn’t resizable, and it does not provide a quick link to an online version of the document.

Not to be thwarted by this evil EULA dialog, I printed it to PDF first:

SNAGHTML8b5ca2e

The text is gray (grey):

image

Although easier to read because I can read it without scrolling, the light colored text makes it exhausting to do so.

Thinking it was maybe a Print to PDF fluke, I tried the XPS printer:

SNAGHTML8b766fa

No better.

Back to the Zune software installer.

I tried to highlight the text in the text field. No. It’s actually not a text field, so none of the standard keyboard or mouse tricks work (it’s using DirectX). Even SnagIt 10 (which has an autoscroll feature for scrollable regions) couldn’t get the text. (See DirectX problem above).

I’m not going to waste a piece of paper to show how it prints as light colored gray text.

The old license is here:

http://www.zune.net/en-US/products/software/licenseterms.htm

After copying the text from the PDF to the clipboard, pasting into notepad, and manually scanning a few lines, I can say with certainty that the EULA linked above does not match the new EULA. In fact, it’s not even close. The new EULA appears to be more appropriately worded as free downloadable software, whereas the older license read more like a EULA that would be associated with Microsoft Word.

Oh Microsoft, How you Mesh with My Head.

imageMicrosoft, I’m confused. You release Windows Live Essentials and say that the new Live Sync is the Old Live Mesh, and that the Mesh as I know it, is going away. To add to the insult, the storage is dropping from 5GB to 2GB I’m told. It’s annoying, but I switch. I even switched early as a beta tester and had to suffer greatly through “cannot connect” and “please reboot or reinstall” errors.

Now, you’ve sent me a notice that Windows Live Mesh 2011 is available?

I’m confused. I must not be alone in this.

Windows Live Sync which replaced the Beta of Windows Live Mesh apparently has been renamed to a less consumer friendly name, but regained the features of the old Mesh beta product. 

image

XP isn’t supported any more. I wish Windows Home Server was officially supported. It would make for a great place to sync files and a easier way to gain access to the full WHS desktop from anywhere.

By the way, during this confusing period, I switched to DropBox anyway. Sigh.

Seriously Awesome Best Battery Charger (for AA & AA batteries)

I’ve never been excited about a battery charger before. Seriously, what’s to get excited about?

image

I purchased the La Crosse Technology BC-700 battery charger recently – and really love it. I’ve bought a few battery chargers over the years with a few features, but I always have been disappointed when batteries fail to charge fully. In the past, I’ve resorted to recycling them.

No more! This thing has brought back batteries that would only take a partial charge in other chargers! Awesome! I had a few recently purchased Sanyo Eneloop batteries that would not fully charge (80% charge). Worse, and to add to the insult, the new mini Apple battery charger refused to charge them!

After using the charger’s Discharge/Refresh cycle on the batteries, the batteries not only take a full charge now, but they also work in the Apple battery charger as well!Slick! It took a few days for the batteries to complete the cycle, but it was definitely worth the wait. I restored some seriously old rechargeable batteries that wouldn’t take a charge that was more than 20-30% of the full charge anymore. They now too take a full charge (I had to run one battery through two long discharge/refresh cycles).

Also nice about this charger is that each battery can be separately charged / refreshed using different settings. No worries about always finding a second battery to charge.

Apparently, there are some geek settings as part of the device, but I’m not a battery nut. I just want it to work, so I haven’t really paid much attention. You can get a lot more geekery by reading through the comments at Amazon. Based on my initial search, I discovered that there were some issues surrounding overheating of a few different battery charger models from more than one manufacturer. So, I put the battery charger on a cheap IKEA plate I recently purchased to prevent any damage that might occur if the charger exceeded expected operating temperatures. I’ve not noticed that the charger has been any warmer than room temperature, even after one of the long recharge cycles. I’ve only used the lower voltage charging option though, as I wasn’t in a rush.

You have to press a few buttons to get a non-default charge operation going – but it’s really easy to do.

Stupidly highly recommended. It’s around $26 US at Amazon right now. If you use more than a few AA (or AAA) rechargeable batteries, you need this. I don’t know why I didn’t buy it years ago when it first came out.