ResultHandlerFactory.java 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. /*
  2. * Copyright (C) 2008 ZXing authors
  3. *
  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
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  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.
  15. */
  16. package com.google.zxing.client.android.result;
  17. import com.google.zxing.Result;
  18. import com.google.zxing.client.result.ParsedResult;
  19. import com.google.zxing.client.result.ResultParser;
  20. import me.yoqi.qrcode.CaptureActivity;
  21. /**
  22. * Manufactures Android-specific handlers based on the barcode content's type.
  23. *
  24. * @author dswitkin@google.com (Daniel Switkin)
  25. */
  26. public final class ResultHandlerFactory {
  27. private ResultHandlerFactory() {
  28. }
  29. public static ResultHandler makeResultHandler(CaptureActivity activity, Result rawResult) {
  30. ParsedResult result = parseResult(rawResult);
  31. switch (result.getType()) {
  32. case URI:
  33. return new URIResultHandler(activity, result);
  34. case ADDRESSBOOK:
  35. case EMAIL_ADDRESS:
  36. case PRODUCT:
  37. case WIFI:
  38. case GEO:
  39. case TEL:
  40. case SMS:
  41. case CALENDAR:
  42. case ISBN:
  43. default:
  44. return new DefaultResultHandler(activity, result, rawResult);
  45. }
  46. }
  47. private static ParsedResult parseResult(Result rawResult) {
  48. return ResultParser.parseResult(rawResult);
  49. }
  50. }