Support SMTP URLs
[zxing.git] / core / src / com / google / zxing / client / result / TelParsedResult.java
index 1545031..a618fe7 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2008 Google Inc.
+ * Copyright 2008 ZXing authors
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
 
 package com.google.zxing.client.result;
 
-import com.google.zxing.Result;
-
 /**
- * Represents a "tel:" URI result, which specifies a phone number.
- *
- * @author srowen@google.com (Sean Owen)
+ * @author Sean Owen
  */
-public final class TelParsedResult extends ParsedReaderResult {
+public final class TelParsedResult extends ParsedResult {
 
   private final String number;
   private final String telURI;
+  private final String title;
 
-  private TelParsedResult(String number, String telURI) {
-    super(ParsedReaderResultType.TEL);
+  public TelParsedResult(String number, String telURI, String title) {
+    super(ParsedResultType.TEL);
     this.number = number;
     this.telURI = telURI;
-  }
-
-  public static TelParsedResult parse(Result result) {
-    String rawText = result.getText();
-    if (rawText == null || !rawText.startsWith("tel:")) {
-      return null;
-    }
-    String telURI = rawText;
-    // Drop tel, query portion
-    int queryStart = rawText.indexOf('?', 4);
-    if (queryStart < 0) {
-      rawText = rawText.substring(4);
-    } else {
-      rawText = rawText.substring(4, queryStart);
-    }
-    return new TelParsedResult(rawText, telURI);
+    this.title = title;
   }
 
   public String getNumber() {
@@ -58,8 +40,15 @@ public final class TelParsedResult extends ParsedReaderResult {
     return telURI;
   }
 
+  public String getTitle() {
+    return title;
+  }
+
   public String getDisplayResult() {
-    return number;
+    StringBuffer result = new StringBuffer(20);
+    maybeAppend(number, result);
+    maybeAppend(title, result);
+    return result.toString();
   }
 
 }
\ No newline at end of file