微波EDA网,见证研发工程师的成长!
首页 > 研发问答 > 手机设计讨论 > MTK手机平台交流 > calendar日程事件的地址和电话号码 匹配的问题

calendar日程事件的地址和电话号码 匹配的问题

时间:10-02 整理:3721RD 点击:
[DESCRIPTION]

Calender中新建活动日程,其地点栏位的text的链接形式默认为map。
但是输入如号码时有2种情况:
1 输入“10086”,这时点击匹配的是map。
2 输入“15050885432”,这时点击匹配的是号码。
请帮忙确认,点击如“10086”或者“525252”时匹配map是否正常行为,比如逻辑为将其识别为坐标值链接map并且优
先级比号码高?
如果不是正常行为,请帮忙fix。

[SOLUTION]

描述的问题是android default 设计,该设计的详细信息可以参考utils.java的extendedLinkify方法。
该方法对US地区的匹配做了特殊处理,而10086是不符合US下的phone number规则,所以没有被匹配成电话号码, 如下:
public static Spannable extendedLinkify(String text, boolean lastDitchGeo) {
// We use a copy of the string argument so it's available for later if necessary.
Spannable spantext = SpannableString.valueOf(text);
/*
* If the text includes a street address like "1600 Amphitheater Parkway, 94043",
* the current Linkify code will identify "94043" as a phone number and invite
* you to dial it (and not provide a map link for the address). For outside US,
* use Linkify result iff it spans the entire text. Otherwise send the user to maps.
*/
String defaultPhoneRegion = System.getProperty("user.region", "US");
if (!defaultPhoneRegion.equals("US")) {
...///M:<--- 非US下,走这个code 分支,如中国区域;此时是可以将10086匹配为电话号码的。
///另外注意一点,android default有个问题,仅在开机时会写入user.region属性,开机后再切换语系该属性不会变

}
/*
* For within US, we want to have better recognition of phone numbers without losing
* any of the existing annotations. Ideally this would be addressed by improving Linkify.
* For now we manage it as a second pass over the text.
*
* URIs and e-mail addresses are pretty easy to pick out of text. Phone numbers
* are a bit tricky because they have radically different formats in different
* countries, in terms of both the digits and the way in which they are commonly
* written or presented (e.g. the punctuation and spaces in "(650) 555-1212").
* The expected format of a street address is defined in WebView.findAddress(). It's
* pretty narrowly defined, so it won't often match.
*
* The RFC 3966 specification defines the format of a "tel:" URI.
*
* Start by letting Linkify find anything that isn't a phone number. We have to let it
* run first because every invocation removes all previous URLSpan annotations.
///M: <--- US下,先匹配phone number外的部分,最后匹配phone number;从代码逻辑可以看到,当完全没有匹配成
功时,会讲其整体匹配为MAP。
*
* Ideally we'd use the external/libphonenumber routines, but those aren't available
* to unbundled applications.
*/
android 注解中给出的US phone number示例如下,供您参考:
* A few interesting cases:
* 94043 # too short, ignore
* 123456789012 # too long, ignore
* +1 (650) 555-1212 # 11 digits, spaces
* (650) 555 5555 # Second space, only when first is present.
* (650) 555-1212, (650) 555-1213 # two numbers, return first
* 1-650-555-1212 # 11 digits with leading '1'
* *#650.555.1212#*! # 10 digits, include #*, ignore trailing '!'
* 555.1212 # 7 digits

Copyright © 2017-2020 微波EDA网 版权所有

网站地图

Top