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;
import android.net.Uri;
import android.preference.PreferenceManager;
import android.provider.Contacts;
+import android.view.View;
+import android.widget.Button;
import java.text.DateFormat;
import java.text.ParsePosition;
private final ParsedResult result;
private final Activity activity;
+ private final Result rawResult;
+ private final String customProductSearch;
private final DialogInterface.OnClickListener shopperMarketListener =
new DialogInterface.OnClickListener() {
};
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();
+
+ // Make sure the Shopper button is hidden by default. Without this, scanning a product followed
+ // by a QR Code would leave the button on screen among the QR Code actions.
+ Button shopperButton = (Button) activity.findViewById(R.id.shopper_button);
+ shopperButton.setVisibility(View.GONE);
}
ParsedResult getResult() {
return result;
}
+ boolean hasCustomProductSearch() {
+ return customProductSearch != null;
+ }
+
/**
* Indicates how many buttons the derived class wants shown.
*
*/
public abstract void handleButtonPress(int index);
+ /**
+ * The Google Shopper button is special and is not handled by the abstract button methods above.
+ *
+ * @param listener The on click listener to install for this button.
+ */
+ protected void showGoogleShopperButton(View.OnClickListener listener) {
+ Button shopperButton = (Button) activity.findViewById(R.id.shopper_button);
+ shopperButton.setVisibility(View.VISIBLE);
+ shopperButton.setOnClickListener(listener);
+ }
+
/**
* Create a possibly styled string for the contents of the current barcode.
*
* @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, String location) {
+ 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));
intent.putExtra("endTime", calculateMilliseconds(end));
intent.putExtra("title", summary);
intent.putExtra("eventLocation", location);
+ intent.putExtra("description", description);
launchIntent(intent);
}
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)));
}
}
}
- protected String parseCustomSearchURL() {
+ 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 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