2 * Copyright (C) 2008 ZXing authors
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package com.google.zxing.client.android.result;
19 import com.google.zxing.Result;
20 import com.google.zxing.client.result.ParsedResult;
21 import com.google.zxing.client.result.ParsedResultType;
22 import com.google.zxing.client.result.ResultParser;
24 import android.app.Activity;
27 * Manufactures Android-specific handlers based on the barcode content's type.
29 * @author dswitkin@google.com (Daniel Switkin)
31 public final class ResultHandlerFactory {
32 private ResultHandlerFactory() {
35 public static ResultHandler makeResultHandler(Activity activity, Result rawResult) {
36 ParsedResult result = parseResult(rawResult);
37 ParsedResultType type = result.getType();
38 if (type.equals(ParsedResultType.ADDRESSBOOK)) {
39 return new AddressBookResultHandler(activity, result);
40 } else if (type.equals(ParsedResultType.EMAIL_ADDRESS)) {
41 return new EmailAddressResultHandler(activity, result);
42 } else if (type.equals(ParsedResultType.PRODUCT)) {
43 return new ProductResultHandler(activity, result, rawResult);
44 } else if (type.equals(ParsedResultType.URI)) {
45 return new URIResultHandler(activity, result);
46 } else if (type.equals(ParsedResultType.WIFI)) {
47 return new WifiResultHandler(activity, result);
48 } else if (type.equals(ParsedResultType.TEXT)) {
49 return new TextResultHandler(activity, result);
50 } else if (type.equals(ParsedResultType.GEO)) {
51 return new GeoResultHandler(activity, result);
52 } else if (type.equals(ParsedResultType.TEL)) {
53 return new TelResultHandler(activity, result);
54 } else if (type.equals(ParsedResultType.SMS)) {
55 return new SMSResultHandler(activity, result);
56 } else if (type.equals(ParsedResultType.CALENDAR)) {
57 return new CalendarResultHandler(activity, result);
58 } else if (type.equals(ParsedResultType.ISBN)) {
59 return new ISBNResultHandler(activity, result, rawResult);
61 // The TextResultHandler is the fallthrough for unsupported formats.
62 return new TextResultHandler(activity, result);
66 private static ParsedResult parseResult(Result rawResult) {
67 return ResultParser.parseResult(rawResult);