Issues 155.2 -- add %f for format
[zxing.git] / android / src / com / google / zxing / client / android / result / ResultHandler.java
index e7fc5a1..db9e235 100644 (file)
 
 package com.google.zxing.client.android.result;
 
+import com.google.zxing.Result;
 import com.google.zxing.client.android.Contents;
 import com.google.zxing.client.android.Intents;
 import com.google.zxing.client.android.LocaleManager;
 import com.google.zxing.client.android.PreferencesActivity;
 import com.google.zxing.client.android.R;
 import com.google.zxing.client.android.book.SearchBookContentsActivity;
+import com.google.zxing.client.android.wifi.WifiActivity;
 import com.google.zxing.client.result.ParsedResult;
 import com.google.zxing.client.result.ParsedResultType;
+import com.google.zxing.client.result.WifiParsedResult;
 
 import android.app.Activity;
 import android.app.AlertDialog;
@@ -69,6 +72,8 @@ public abstract class ResultHandler {
 
   private final ParsedResult result;
   private final Activity activity;
+  private final Result rawResult;
+  private final String customProductSearch;
 
   private final DialogInterface.OnClickListener shopperMarketListener =
       new DialogInterface.OnClickListener() {
@@ -79,14 +84,24 @@ public abstract class ResultHandler {
   };
 
   ResultHandler(Activity activity, ParsedResult result) {
+    this(activity, result, null);
+  }
+
+  ResultHandler(Activity activity, ParsedResult result, Result rawResult) {
     this.result = result;
     this.activity = activity;
+    this.rawResult = rawResult;
+    this.customProductSearch = parseCustomSearchURL();
   }
 
   ParsedResult getResult() {
     return result;
   }
 
+  boolean hasCustomProductSearch() {
+    return customProductSearch != null;
+  }
+
   /**
    * Indicates how many buttons the derived class wants shown.
    *
@@ -143,16 +158,27 @@ public abstract class ResultHandler {
    * @param summary A description of the event
    * @param start   The start time as yyyyMMdd or yyyyMMdd'T'HHmmss or yyyyMMdd'T'HHmmss'Z'
    * @param end     The end time as yyyyMMdd or yyyyMMdd'T'HHmmss or yyyyMMdd'T'HHmmss'Z'
+   * @param location a text description of the event location
+   * @param description a text description of the event itself
    */
-  final void addCalendarEvent(String summary, String start, String end) {
+  final void addCalendarEvent(String summary, 
+                              String start,
+                              String end,
+                              String location,
+                              String description) {
     Intent intent = new Intent(Intent.ACTION_EDIT);
     intent.setType("vnd.android.cursor.item/event");
     intent.putExtra("beginTime", calculateMilliseconds(start));
     if (start.length() == 8) {
       intent.putExtra("allDay", true);
     }
+    if (end == null) {
+      end = start;
+    }
     intent.putExtra("endTime", calculateMilliseconds(end));
     intent.putExtra("title", summary);
+    intent.putExtra("eventLocation", location);
+    intent.putExtra("description", description);
     launchIntent(intent);
   }
 
@@ -310,6 +336,15 @@ public abstract class ResultHandler {
     launchIntent(intent);
   }
 
+  final void wifiConnect(WifiParsedResult wifiResult) {
+    Intent intent = new Intent(Intents.WifiConnect.ACTION);
+    intent.setClassName(activity, WifiActivity.class.getName());
+    putExtra(intent, Intents.WifiConnect.SSID, wifiResult.getSsid());
+    putExtra(intent, Intents.WifiConnect.TYPE, wifiResult.getNetworkEncryption());
+    putExtra(intent, Intents.WifiConnect.PASSWORD, wifiResult.getPassword());
+    launchIntent(intent);
+  }
+
   final void openURL(String url) {
     launchIntent(new Intent(Intent.ACTION_VIEW, Uri.parse(url)));
   }
@@ -376,4 +411,21 @@ public abstract class ResultHandler {
     }
   }
 
-}
+  private String parseCustomSearchURL() {
+    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(activity);
+    String customProductSearch = prefs.getString(PreferencesActivity.KEY_CUSTOM_PRODUCT_SEARCH, null);
+    if (customProductSearch != null && customProductSearch.trim().length() == 0) {
+      return null;
+    }
+    return customProductSearch;
+  }
+
+  String fillInCustomSearchURL(String text) {
+    String url = customProductSearch.replace("%s", text);
+    if (rawResult != null) {
+      url = url.replace("%f", rawResult.getBarcodeFormat().toString());
+    }
+    return url;
+  }
+
+}
\ No newline at end of file