mirror of
https://github.com/zxing/zxing.git
synced 2024-11-09 20:44:03 -08:00
Add support for tel: URIs
git-svn-id: https://zxing.googlecode.com/svn/trunk@292 59b500cc-1b3d-0410-9834-0bbf25fbcc57
This commit is contained in:
parent
5248fb1a7e
commit
379c3a8cc0
|
@ -30,4 +30,5 @@
|
|||
<string name="title_add_contact">Add Contact?</string>
|
||||
<string name="title_compose_email">Compose E-mail?</string>
|
||||
<string name="title_lookup_barcode">Look Up Barcode Online?</string>
|
||||
<string name="title_dial">Dial Number?</string>
|
||||
</resources>
|
||||
|
|
|
@ -205,6 +205,8 @@ public final class BarcodeReaderCaptureActivity extends Activity {
|
|||
return R.string.title_compose_email;
|
||||
} else if (type.equals(ParsedReaderResultType.UPC)) {
|
||||
return R.string.title_lookup_barcode;
|
||||
} else if (type.equals(ParsedReaderResultType.TEL)) {
|
||||
return R.string.title_dial;
|
||||
} else {
|
||||
return R.string.title_barcode_detected;
|
||||
}
|
||||
|
|
|
@ -28,6 +28,7 @@ import com.google.zxing.client.result.EmailAddressParsedResult;
|
|||
import com.google.zxing.client.result.EmailDoCoMoParsedResult;
|
||||
import com.google.zxing.client.result.ParsedReaderResult;
|
||||
import com.google.zxing.client.result.ParsedReaderResultType;
|
||||
import com.google.zxing.client.result.TelParsedResult;
|
||||
import com.google.zxing.client.result.UPCParsedResult;
|
||||
import com.google.zxing.client.result.URIParsedResult;
|
||||
import com.google.zxing.client.result.URLTOParsedResult;
|
||||
|
@ -95,6 +96,12 @@ final class ResultHandler extends Handler {
|
|||
intent = new Intent(Intent.SENDTO_ACTION, new ContentURI(emailResult.getEmailAddress()));
|
||||
} catch (URISyntaxException e) {
|
||||
}
|
||||
} else if (type.equals(ParsedReaderResultType.TEL)) {
|
||||
TelParsedResult telResult = (TelParsedResult) result;
|
||||
try {
|
||||
intent = new Intent(Intent.DIAL_ACTION, new ContentURI("tel:" + telResult.getNumber()));
|
||||
} catch (URISyntaxException e) {
|
||||
}
|
||||
//} else if (type.equals(ParsedReaderResultType.GEO)) {
|
||||
// GeoParsedResult geoResult = (GeoParsedResult) result;
|
||||
// try {
|
||||
|
|
|
@ -58,6 +58,8 @@ public abstract class ParsedReaderResult {
|
|||
return result;
|
||||
} else if ((result = AddressBookAUParsedResult.parse(theResult)) != null) {
|
||||
return result;
|
||||
} else if ((result = TelParsedResult.parse(theResult)) != null) {
|
||||
return result;
|
||||
} else if ((result = GeoParsedResult.parse(theResult)) != null) {
|
||||
return result;
|
||||
} else if ((result = URLTOParsedResult.parse(theResult)) != null) {
|
||||
|
|
|
@ -35,6 +35,7 @@ public final class ParsedReaderResultType {
|
|||
public static final ParsedReaderResultType TEXT = new ParsedReaderResultType("TEXT");
|
||||
public static final ParsedReaderResultType ANDROID_INTENT = new ParsedReaderResultType("ANDROID_INTENT");
|
||||
public static final ParsedReaderResultType GEO = new ParsedReaderResultType("GEO");
|
||||
public static final ParsedReaderResultType TEL = new ParsedReaderResultType("TEL");
|
||||
// TODO later, add the NDEF types to those actually processed by the clients
|
||||
public static final ParsedReaderResultType NDEF_TEXT = new ParsedReaderResultType("NDEF_TEXT");
|
||||
public static final ParsedReaderResultType NDEF_URI = new ParsedReaderResultType("NDEF_URI");
|
||||
|
|
58
core/src/com/google/zxing/client/result/TelParsedResult.java
Normal file
58
core/src/com/google/zxing/client/result/TelParsedResult.java
Normal file
|
@ -0,0 +1,58 @@
|
|||
/*
|
||||
* Copyright 2008 Google Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under 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)
|
||||
*/
|
||||
public final class TelParsedResult extends ParsedReaderResult {
|
||||
|
||||
private final String number;
|
||||
|
||||
private TelParsedResult(String number) {
|
||||
super(ParsedReaderResultType.TEL);
|
||||
this.number = number;
|
||||
}
|
||||
|
||||
public static TelParsedResult parse(Result result) {
|
||||
String rawText = result.getText();
|
||||
if (!rawText.startsWith("tel:")) {
|
||||
return null;
|
||||
}
|
||||
// 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);
|
||||
}
|
||||
|
||||
public String getNumber() {
|
||||
return number;
|
||||
}
|
||||
|
||||
public String getDisplayResult() {
|
||||
return number;
|
||||
}
|
||||
|
||||
}
|
|
@ -16,6 +16,7 @@
|
|||
|
||||
package com.google.zxing.client.result;
|
||||
|
||||
import com.google.zxing.BarcodeFormat;
|
||||
import com.google.zxing.Result;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
|
@ -76,8 +77,8 @@ public final class ParsedReaderResultTestCase extends TestCase {
|
|||
}
|
||||
|
||||
public void testUPC() {
|
||||
doTestResult("123456789012", ParsedReaderResultType.UPC);
|
||||
doTestResult("1234567890123", ParsedReaderResultType.UPC);
|
||||
doTestResult("123456789012", ParsedReaderResultType.UPC, BarcodeFormat.UPC_A);
|
||||
doTestResult("1234567890123", ParsedReaderResultType.UPC, BarcodeFormat.UPC_A);
|
||||
doTestResult("12345678901", ParsedReaderResultType.TEXT);
|
||||
}
|
||||
|
||||
|
@ -94,11 +95,23 @@ public final class ParsedReaderResultTestCase extends TestCase {
|
|||
public void testGeo() {
|
||||
doTestResult("geo:1,2", ParsedReaderResultType.GEO);
|
||||
doTestResult("geo:1,2,3", ParsedReaderResultType.GEO);
|
||||
doTestResult("geo:100.33,-32.3344,3.35", ParsedReaderResultType.GEO);
|
||||
doTestResult("geo:100.33,-32.3344,3.35", ParsedReaderResultType.GEO);
|
||||
doTestResult("geography", ParsedReaderResultType.TEXT);
|
||||
}
|
||||
|
||||
public void testTel() {
|
||||
doTestResult("tel:+15551212", ParsedReaderResultType.TEL);
|
||||
doTestResult("tel:212 555 1212", ParsedReaderResultType.TEL);
|
||||
doTestResult("tel:2125551212", ParsedReaderResultType.TEL);
|
||||
doTestResult("telephone", ParsedReaderResultType.TEXT);
|
||||
}
|
||||
|
||||
private static void doTestResult(String text, ParsedReaderResultType type) {
|
||||
Result fakeResult = new Result(text, null, null, null);
|
||||
doTestResult(text, type, null);
|
||||
}
|
||||
|
||||
private static void doTestResult(String text, ParsedReaderResultType type, BarcodeFormat format) {
|
||||
Result fakeResult = new Result(text, null, null, format);
|
||||
ParsedReaderResult result = ParsedReaderResult.parseReaderResult(fakeResult);
|
||||
assertNotNull(result);
|
||||
assertEquals(type, result.getType());
|
||||
|
|
|
@ -22,6 +22,7 @@ import com.google.zxing.client.result.EmailAddressParsedResult;
|
|||
import com.google.zxing.client.result.EmailDoCoMoParsedResult;
|
||||
import com.google.zxing.client.result.ParsedReaderResult;
|
||||
import com.google.zxing.client.result.ParsedReaderResultType;
|
||||
import com.google.zxing.client.result.TelParsedResult;
|
||||
import com.google.zxing.client.result.UPCParsedResult;
|
||||
import com.google.zxing.client.result.URIParsedResult;
|
||||
import com.google.zxing.client.result.URLTOParsedResult;
|
||||
|
@ -214,6 +215,9 @@ public final class ZXingMIDlet extends MIDlet {
|
|||
String upc = ((UPCParsedResult) result).getUPC();
|
||||
String uri = "http://www.upcdatabase.com/item.asp?upc=" + upc;
|
||||
showOpenURL("Look Up Barcode Online?", upc, uri);
|
||||
} else if (type.equals(ParsedReaderResultType.TEL)) {
|
||||
String number = ((TelParsedResult) result).getNumber();
|
||||
showOpenURL("Dial Number?", number, "tel:" + number);
|
||||
} else {
|
||||
showAlert("Barcode Detected", result.getDisplayResult());
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue