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