Pages Menu
Categories Menu

Posted by on Apr 30, 2012 in Mobile |

What is Windows 8 Metro, anyway, and why should I care?

Metro is the UI (“design language”) that originated with Windows Phone 7, and is a big part of Windows 8 as Microsoft prepares to challenge Apple and Google in the tablet market. In the consumer market, the Kindle Fire has gobbled up over 50% of the Android tablet market share, which is hovering around 50% of the overall tablet market, but if you’re interested in the enterprise space at all, second place in that market behind the iPad is wide open territory:


Android has been plagued in the enterprise space by the security concerns of Gingerbread (Encryption? What’s that?), lackluster adoption of the more secure Ice Cream Sandwich (ICS) by device manufacturers, and nervousness over fragmentation. iPad has done exceptionally well, with built-in security features that rival the most hardened laptop, but knowing corporate IT’s preferences for Microsoft products, Windows 8 tablets could easily be poised to trounce Android and even challenge Apple in the years ahead.

At the same time, users want apps, and developers want users. Microsoft seems to have recognized that in order to grow the user base, they need more apps being developed, and there aren’t enough users around yet to entice the development community, so Microsoft is paying developers between $60k and $600k to develop for the Microsoft Store that, at 70k apps is lagging behind Android’s roughly 400k apps and Apple’s 600k apps. So, now’s a good time to work on a Windows Metro app.

Metro Design Principles

One of the nicest things about Metro is that Microsoft seems to have taken a cue from Apple’s book (the venerable iOS HIG), and have put some real thought into the UI and these design principles:

Content Before Chrome

Chrome is basically all of the stuff in your app that isn’t content. The toolbars, the tabs, button gradients, scrollbars, etc. One of the core concepts in Metro is to de-emphasize the app chrome and to use the size, weight, and color of typography to convey hierarchical information on the page. Looking at some popular apps, the difference is pretty easy to see in the lack of tab-bars, toolbars, and other application chrome elements. This is Spotify:

Apps are designed to flow from one screen to another instead of having tabs, as is you can see in these Spotify screenshots:


Be Fast and Fluid — Touch First

As with most tablet interfaces, touch gestures are important. Most of these are similar to iOS and Android, but Windows 8 has defined a few new ones, with app commands and system commands being shown in hidden toolbars on the bottom and right edge of the screen.


Be Fast and Fluid — Use Animation Library to Illustrate Common Scenarios

Again, nothing too groundbreaking here, except there are a number of nice animations built into the stock components. Some of them are demonstrated in these demo projects that are worth a look:

Snap and Scale Beautifully

Since Windows 8 apps will run on phones, tablets, netbooks, notebooks, and 30” displays, it makes sense to display more information on larger screen sizes rather than just making things bigger. Just like with the Mobile Web, native apps should handle different screen sizes elegantly, and adapt accordingly.

Snapping is an interesting feature that allows multiple apps to be shown on the screen at the same time. Since Metro isn’t really windowed, this is a way to keep your app on-screen in a sidebar while someone is off doing something else. For instance, if you wanted to monitor Twitter while browsing the maps application:


Use the Right Contracts

Contracts control how Metro apps interact with each other and with the OS.

  • Share Sources and Targets allow for sharing between apps.
  • Search allows users to search within an app from anywhere in Windows.
  • And the File Picker allows users to open or save content between apps in a controlled manner.

Invest in a Great Tile

Tiles are the icons of Windows Metro. Their real power lies in the ability to use the Microsoft Push Notification Server to push out content updates to Live Tiles. Personalized, regionalized, and/or customized content helps keep users coming back to your app.


Roam to the Cloud

Similar to Apple iCloud and Google Drive, Metro apps get per-user cloud storage for saving state to allow users to continue tasks across devices.

Developing Windows 8

Getting started is easy and free. Just download the Windows 8 Consumer Preview and Visual Studio 11 Express Beta. Both can be installed in a VM, on a desktop/laptop, or on an actual tablet. From there, you basically just choose a template to start with. Your choices are Javascript, VB or C# .net, and C++ (mostly useful for DirectX games).


The Native options give you a handy XAML (eXtensible Application Markup Language) visual designer:


The Javascript templates, though, are really interesting because they give you the ability to create an app entirely in HTML5/Javascript, similar to what you would do on other platforms with PhoneGap/Cordova, but without the need for any external libraries.

So, that’s Metro. What are you doing with it?

facebooktwittergoogle_plusredditpinterestlinkedinmail Read More

Posted by on Apr 19, 2012 in Code, Mobile, The Cloud |

Storing Data Offline with Salesforce Mobile SDK SmartStore

Storing Data Offline with Salesforce Mobile SDK SmartStore

Say you’re writing a “hybrid” mobile app for iOS and Android using PhoneGap (“Callback” or “Cordova”) and you want to store data locally. Your choices are kind of limited. You could, for instance, use WebSQL, which has been implemented in WebKit for a while now and is available on both iOS and Android devices. If you clicked that link, though, you’ll probably notice the big scary warning that WebSQL has been deprecated…


 

It works right now, but maybe it’s not the best idea to use it if you don’t want to have to strip it out someday down the road. You also have to deal with all the data size limitations and requests to the user to allow the app to increase the database size.

So, what’s up next from the W3C if the WebSQL spec isn’t being maintained? The new spec is IndexedDB, which is a “database of records holding simple values and hierarchical objects”. Perfect! We’ll just check caniuse.com to make sure it’s supported on iOS and Android:


 

So… okay. It looks like it’s not supported yet on either. Does PhoneGap provide anything? In fact, it does, the Storage class. Which is based on WebSQL… I think you can see where I’m going here.

What do you do? Well, the Salesforce Mobile SDK for iOS and Android has implemented an ORM layer called SmartStore abstraction to SQLite, which uses FMDB on iOS and SQLCipher on Android. It’s easy to use and allows you to store data in JSON format locally and specify indexes for searching and sorting. Also, it uses native implementations of SQLite which are accessed via PhoneGap plugins so you don’t have any issues with HTML5 storage limitations or the W3C changing their mind about what web database technology everyone should standardize on.

To demonstrate SmartStore, I’ve put together a simple demo app, and posted it to Github:

https://github.com/tomgersic/SmartStoreDemo

The Sample App

Here it is running on the iPad simulator. One thing to know about SmartStore is that each database Table is called a Soup. It’s an Apple Newton thing. The Newton’s file system was based on a “Soup” store model. So here, I’ve asked the app to create a new Soup named “EggDrop” specified that I want to use just the “id” field as an index, and entered a Salesforce REST API query to be executed using the handy ForceTK library.


To start off, download the code from GitHub and open up the XCode project. If you want to start from scratch, you’ll want to install the Salesforce Mobile SDK for iOS and selected “Hybrid Force.com App” from X-Code’s New Project wizard.


Going from top to bottom:

  • Input Boxes
  • Soup Name: A “Soup” named this will be created.
  • Indexes: I’ll show how this gets represented in the data model in a bit, but you can specify JSON fields for indexing and specify a type of either “string” or “integer”.
  • REST Query: Basically any query to the Salesforce REST API. Here we’re just defaulting to pulling down my Chatter feed items. I have 3 in my feed in a dev org that we’ll pull down.
  • Buttons
  • Query SFDC: Run the REST Query, save the results to the specified Soup, and log the results to the console (on the page).
  • Query SmartStore: Query the specified Soup and log the results to the console. They should be the same results as the remote Salesforce Query.
  • Reset: Delete all the Soups that we’ve created during this session.
  • Logout: Log out of your Salesforce org.


SmartStore Soup Functions

To see how all this works, the interesting bits are in the inline.js file.

  • To register a Soup, we call registerSoup:


navigator.smartstore.registerSoup(soupName,indexes,success,error);

  • To add some records to that Soup, we call upsertSoupEntries:


navigator.smartstore.upsertSoupEntries(soupName,records, success, error);

  • To query the Soup, first we have to define a querySpec (buildAllQuerySpec just pulls all records rather than searching for specific records):


var querySpec = navigator.smartstore.buildAllQuerySpec(“id”, null, 20);


This querySpec specifies “id’ as an index, null (allow default) for the sort order, and 20 for the page size.

  • We then use that querySpec to get records back from the Soup:

       

navigator.smartstore.querySoup(soupName,querySpec, success(cursor),logError);

  • Additionally, if we want, we can delete Soups with removeSoup:


navigator.smartstore.removeSoup(record,success,error);

Running the App

When you run the app for the first time, you’ll be presented with an oAuth 2.0 User-Agent login screen for Salesforce. If you don’t already have a Developer Org, get one at http://developer.force.com/. It’s free.

Once you log in, hit Query SFDC, and you see the Soup get registered, JSON data gets downloaded from the REST API and added to the SOUP. Take a look at the JSON data, and then hit the “Query SmartStore” button. You’ll see it load that same data from the SmartStore Soup and display it in the console log.

The Database

Let’s take a look at the actual SQLite database file and see how things are stored behind the scenes. You’ll see we have 3 tables in the database: soup_names, soup_index_map, and TABLE_1 (sqlite_master and sqlite_sequence are used internally by SQLite):

 

  • soup_names keeps a list of the Soups I’ve created

 

 

  • soup_index_map keeps track of the indexes for each Soup.

 


 

  • TABLE_1 is a generically named table that contains my JSON data and Index values. The TABLE_1_0 field here is the “id” index we specified when we created the Soup. If I had created more indexes, like a “name” index, another column would be shown here.

 

 

The Soup field contains the full JSON response for that record so you can reuse whatever code you wrote to deal with the JSON record from the REST API once you’ve pulled it from the Soup.

 



So that’s SmartStore. It’s a great way to put together an app for Salesforce, Database.com, or Chatter that stores JSON data on the device for offline access.

facebooktwittergoogle_plusredditpinterestlinkedinmail Read More