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 android.app.Activity;
20 import com.google.zxing.Result;
21 import com.google.zxing.client.result.ParsedResult;
22 import com.google.zxing.client.result.ParsedResultType;
23 import com.google.zxing.client.result.ResultParser;
25 public final class ResultHandlerFactory {
27 public static ResultHandler makeResultHandler(Activity activity, Result rawResult) {
28 ParsedResult result = parseResult(rawResult);
29 ParsedResultType type = result.getType();
30 if (type.equals(ParsedResultType.ADDRESSBOOK)) {
31 return new AddressBookResultHandler(activity, result);
32 } else if (type.equals(ParsedResultType.EMAIL_ADDRESS)) {
33 return new EmailAddressResultHandler(activity, result);
34 } else if (type.equals(ParsedResultType.PRODUCT)) {
35 return new ProductResultHandler(activity, result);
36 } else if (type.equals(ParsedResultType.URI)) {
37 return new URIResultHandler(activity, result);
38 } else if (type.equals(ParsedResultType.TEXT)) {
39 return new TextResultHandler(activity, result);
40 } else if (type.equals(ParsedResultType.GEO)) {
41 return new GeoResultHandler(activity, result);
42 } else if (type.equals(ParsedResultType.TEL)) {
43 return new TelResultHandler(activity, result);
44 } else if (type.equals(ParsedResultType.SMS)) {
45 return new SMSResultHandler(activity, result);
46 } else if (type.equals(ParsedResultType.CALENDAR)) {
47 return new CalendarResultHandler(activity, result);
48 } else if (type.equals(ParsedResultType.ISBN)) {
49 return new ISBNResultHandler(activity, result);
51 // The TextResultHandler is the fallthrough for unsupported formats.
52 return new TextResultHandler(activity, result);
56 private static ParsedResult parseResult(Result rawResult) {
57 ParsedResult result = ResultParser.parseResult(rawResult);
59 // Disabled for now. To reactivate, create an AndroidIntentResultHandler.
60 // if (result.getType().equals(ParsedResultType.TEXT)) {
61 // String rawText = rawResult.getText();
62 // AndroidIntentParsedResult androidResult = AndroidIntentParsedResult.parse(rawText);
63 // if (androidResult != null) {
64 // Intent intent = androidResult.getIntent();
65 // if (!Intent.ACTION_VIEW.equals(intent.getAction())) {
66 // // For now, don't take anything that just parses as a View action. A lot
67 // // of things are accepted as a View action by default.
68 // result = androidResult;