How to Add Gesture Search to your Android apps

Gesture Search from Google Labs now has an API. You can use the API to easily integrate Gesture Search into your Android apps, so your users can gesture to write text and search for application-specific data. For example, a mobile ordering application for a restaurant might have a long list of menu items; with Gesture Search, users can draw letters to narrow their search.

Another way to use Gesture Search is to enable users to select options using gestures that correspond to specific app functions, like a touch screen version of keyboard shortcuts, rather than forcing hierarchical menu navigation.
 


 
In this post, I’ll demonstrate how we can embed Gesture Search (1.4.0 or later) into an Android app that enables a user to find information about a specific country. To use Gesture Search, we first need to create a content provider named CountryProvider, according to the format required by Android Search framework. This content provider consists of 238 country names.

Then, in GestureSearchAPIDemo, the main activity of the app, we invoke Gesture Search when a user selects a menu item. (Gesture Search can be invoked in other ways depending on specific applications.) To do this, we create an Intent with the action "com.google.android.apps.gesturesearch.SEARCH" and the URI of the content provider. If the data is protected (for example, see AndroidManifest.xml), we also need to grant read permission for the content URI to Gesture Search. We then call startActivityForResult to invoke Gesture Search.

public boolean onCreateOptionsMenu(Menu menu) {
    super.onCreateOptionsMenu(menu);
    menu.add(0, GESTURE_SEARCH_ID, 0, R.string.menu_gesture_search)
        .setShortcut('0', 'g').setIcon(android.R.drawable.ic_menu_search);
    return true;
  }

  @Override
  public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
      case GESTURE_SEARCH_ID:
        try {
          Intent intent = new Intent();
          intent.setAction("com.google.android.apps.gesturesearch.SEARCH");
          intent.setData(SuggestionProvider.CONTENT_URI);
          intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
          intent.putExtra(SHOW_MODE, SHOW_ALL);
          intent.putExtra(THEME, THEME_LIGHT);
          startActivityForResult(intent, GESTURE_SEARCH_ID);
        } catch (ActivityNotFoundException e) {
          Log.e("GestureSearchExample", "Gesture Search is not installed");
        }
        break;
    }
    return super.onOptionsItemSelected(item);
  }

In the code snippet above, we also specify that we want to show all of the country names when Gesture Search is brought up by intent.putExtra(SHOW_MODE, SHOW_ALL). The parameter name and its possible values are defined as follows:

/**
   * Optionally, specify what should be shown when launching Gesture Search.
   * If this is not specified, SHOW_HISTORY will be used as a default value.
   */
  private static String SHOW_MODE = "show";
  /** Possible values for invoking mode */
  // Show the visited items
  private static final int SHOW_HISTORY = 0;
  // Show nothing (a blank screen)
  private static final int SHOW_NONE = 1;
  // Show all of date items
  private static final int SHOW_ALL = 2;

  /**
   * The theme of Gesture Search can be light or dark.
   * By default, Gesture Search will use a dark theme.
   */
  private static final String THEME = "theme";
  private static final int THEME_LIGHT = 0;
  private static final int THEME_DARK = 1;

  /** Keys for results returned by Gesture Search */
  private static final String SELECTED_ITEM_ID = "selected_item_id";
  private static final String SELECTED_ITEM_NAME = "selected_item_name";

As you can see in the code, when Gesture Search appears, we can show a recently selected country name, or nothing. Gesture Search then appears with a list of all the country names. The user can draw gestures directly on top of the list and a target item will pop up at the top. When a user taps a country name, Gesture Search exits and returns the result to the calling app. The following method is invoked for processing the user selection result, reading the Id and the name of the chosen data item.

@Override
  protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (resultCode == Activity.RESULT_OK) {
      switch (requestCode) {
        case GESTURE_SEARCH_ID:
          long selectedItemId = data.getLongExtra(SELECTED_ITEM_ID, -1);
          String selectedItemName = data.getStringExtra(SELECTED_ITEM_NAME);
          // Print out the Id and name of the item that is selected
          // by the user in Gesture Search
          Log.d("GestureSearchExample", selectedItemId + ": " + selectedItemName);
          break;
      }
    }
  }

To use the Gesture Search API, you must be sure Gesture Search is installed. To test this condition, catch ActivityNotFoundException as shown in the above code snippet and display a MessageBox asking the user to install Gesture Search.

You can download the sample code at http://code.google.com/p/gesture-search-api-demo.

Session videos from Google I/O now live

With Google I/O 2011 just two days behind us, we wanted to thank the nearly one million developers who joined us at Moscone Center, attended I/O Extended events, and watched online via I/O Live from 161 countries around the world. In addition to the announcements made at the keynote presentations, we had more than 30 announcements in our 110 sessions. HD recordings of all these sessions are now available online. Here are some of the announcements:

Highlights from this year’s event are posted at www.google.com/io, where we are featuring photos, announcements, and the latest videos. Also, stay tuned for a feature on “Backstage at Google I/O” where we will highlight the developers and artists who helped to make the event possible this year.

Google I/O kicks off the year as our biggest developer event–but we’re only getting started. As of today, we are announcing locations for our eight Google Developer Days (GDDs), which will take place all over the world with more than a few DevFests in between. Stay tuned for more info on the 2011 event details, but we’ll look forward to seeing you in Brazil, Argentina, Prague, Moscow, Tokyo, Sydney, Israel and Germany for our Google Developer Team world tour.

The long way from weekend idea to funded startup

Almost every developer has an idea and might want to start a company. Where do you start? Entrepreneurs Paul Buchheit, Joe Kraus, and Seth Priebatsch explained how to go from hacking on the nights and weekends to building an investor funded startup. We also discussed how to find co-founders, attract investors, and focus on the key decisions. You can watch the complete Google I/O session on YouTube. Here are some highlights.


Should I have a co-founder? Having strong co-founders join you in transforming your idea into a real company is critical to success. There is a positive correlation between the number of co-founders and successful outcomes up to about four co-founders. Beyond four co-founders there isn’t much data. But having more co-founders on your team definitely improves your chances of success.

What are important characteristics of a co-founder? It helps if you have worked together before, know each other well, have complimentary expertise, and can communicate openly and honestly. Joe Kraus said you should be able to settle arguments with great answers, not the compromise middle position. What else should you look for in a co-founder?

  1. Experience starting a company
  2. Domain experience and an understanding of the market
  3. Balance and different experience than your own
  4. Passion about the company vision

How do you get started? Paul Buchheit knew he wanted to start a company but didn’t know how. So, he decided to join a startup to get some experience. That startup was Google. Paul learned how startups grow, and worked with some great people who would later become his co-founders at FriendFeed. Having experience at a startup earns you credibility with potential co-founders, employees, and investors.

What matters most; team, traction, idea, or market segment? They all matter, but the people on the team are the number one consideration. The founding team shapes the product vision and sets the direction for the company. Potential employees and investors are attracted…or not, by the members of the founding team. The idea matters, but will probably change significantly over time, so most investors don’t fixate on the idea. The market segment is important, but only as a gauge of the range of successful outcomes. Traction from early users or customers makes it much easier to raise money.

How do you find investors? People invest in businesses they understand, or people they know. Look for investors that have started companies in your area, or have invested in similar companies in the past. Talk to everyone you know about your idea. Joe Kraus, co-founder of Excite, tells the story of how he read a book about starting companies, called the author, got introduced to other people, who introduced him to other people, and finally ended up with a $3M investment from Kleiner Perkins, one of the top VCs in the world.

Should you raise money from VCs or Angels? The first consideration is who can help you most. You want more than just money from investors. You want help, advice, introductions to other people who can help, and maybe access to press. Aside from help, it depends on how much money you need to raise. Friends and Family is the best place to start to raise small amounts of money. Angel investors can fund anywhere from $100K to $1M or more. Venture Capitalists (VCs) usually invest $1M to $3M in a first round Series A investment.

Incubators, Angels, and VCs – Seth Priebatsch, founder of SCVNGR.com did all three in starting his company. Seth entered a business plan competition at Princeton…and won. He used that to get the initial product built, and then applied to DreamIT, a startup incubator. That experience at the incubator allowed him to build and refine the product. Next he raised a small amount of money from Angels and brought on advisers to help him grow the company. That led to a small round from VCs. Seth believes the more investors you have, the more help, advice, and experience you get.

How do you arrive at a valuation for the company? Joe Kraus says it is an art, not a science. It depends on the stage of the company, the competition, and how fast the market segment is growing. Most early stage startups don’t have revenue and don’t have many users so the valuation is typically between $1M and $3M, and depends on the experience of the founding team, how much progress you have made on the product, and the relative success of competitors. The best way to determine a fair valuation is by having several competing investors give you proposals.

Do I need a business plan? No, but you do need a good slide deck that explains what you want to do, what problem it solves, why it will be successful, and how your team can execute on the vision. Here is a link to a post that explains how to pitch your company to investors. A good pitch deck and a product demo are what most investors are looking for. Business plans might be useful for helping you refine your ideas and vision, but most investors will never read it.

Are patents, IP, and trademarks important? Paul Buchheit says in most cases they don’t matter for early stage startups. Joe Kraus added, patents might be of some value to a potential acquirer, but probably just as a defense against patent infringement cases. Patents are very expensive to obtain (legal bills) and they take two to four years, sometimes longer, to actually get issued. By that time most startups are out of business, acquired, or moving on to something else. Even if you have a patent, most startups can’t afford to defend them in court against potential infringers. The legal expense of defending a patent, and time lost away from your business, make it nearly impossible for a small startup.