【翻译】(51)data元素

本文详细解析了Android应用开发中intent过滤器的数据元素使用方法,包括语法、描述、属性及其在意图过滤器中的作用。文章还强调了在配置数据元素时的注意事项,如URI的匹配规则、MIME类型、路径、主机、端口和模式的使用及大小写敏感性。

【翻译】(51)data元素

 

see

http://developer.android.com/guide/topics/manifest/data-element.html

 

原文见

http://developer.android.com/guide/topics/manifest/data-element.html

 

-------------------------------

 

<data>

 

data元素

 

-------------------------------

 

* syntax:

 

* 语法:

 

-------------------------------

 

<data android:host="string"

      android:mimeType="string"

      android:path="string"

      android:pathPattern="string"

      android:pathPrefix="string"

      android:port="string"

      android:scheme="string" />

 

-------------------------------

 

* contained in:

 

* 被包含在:

 

<intent-filter>

 

* description:

 

* 描述:

 

Adds a data specification to an intent filter. The specification can be just a data type (the mimeType attribute), just a URI, or both a data type and a URI. A URI is specified by separate attributes for each of its parts:

 

添加一个数据规范到一个意图过滤器。规范可以只是一个数据类型(mimeType属性),只是一个URI,或者一个数据类型和一个URI都有。一个URI被不同的属性对它的每个部分作指定。

 

scheme://host:port/path or pathPrefix or pathPattern

 

<模式>://<主机>:<端口>/<路径>或<路径前缀>或<路径模式>

 

These attributes are optional, but also mutually dependent: If a scheme is not specified for the intent filter, all the other URI attributes are ignored. If a host is not specified for the filter, the port attribute and all the path attributes are ignored.

 

这些属性是可选的,但也是相互依赖的:如果没有为意图过滤器指定一个scheme,那么其它所有URI属性被忽略。如果没有为意图过滤器指定一个host,那么port属性和所有path属性被忽略。

 

All the <data> elements contained within the same <intent-filter> element contribute to the same filter. So, for example, the following filter specification,

 

在相同的<intent-filter>元素中包含的所有<data>元素作用于相同的过滤器。因此,例如以下过滤器规范,

 

-------------------------------

 

<intent-filter . . . >

    <data android:scheme="something" android:host="project.example.com" />

    . . .

</intent-filter>

 

-------------------------------

 

is equivalent to this one:

 

等价于这个:

 

-------------------------------

 

<intent-filter . . . >

    <data android:scheme="something" />

    <data android:host="project.example.com" />

    . . .

</intent-filter>

 

-------------------------------

 

You can place any number of <data> elements inside an <intent-filter> to give it multiple data options. None of its attributes have default values.

 

你可以放置任意数量的<data>元素在一个<intent-filter>中以给它多个数据选项。它的没有属性有默认值。

 

Information on how intent filters work, including the rules for how Intent objects are matched against filters, can be found in another document, Intents and Intent Filters. See also the Intent Filters section in the introduction.

 

关于意图过滤器如何工作的信息,包括Intent对象如何匹配过滤器的规则,可以在另一个文档意图与意图过滤器中找到。另见介绍中的意图过滤器章节。

 

* attributes:

 

* 属性:

 

* android:host

 

The host part of a URI authority. This attribute is meaningless unless a scheme attribute is also specified for the filter.

 

URI权力的主机部分。这个属性是没有意义的除非为该过滤器指定一个scheme属性。

 

-------------------------------

 

Note: host name matching in the Android framework is case-sensitive, unlike the formal RFC. As a result, you should always specify host names using lowercase letters.

 

注意:在Android框架中主机名称匹配是大小写敏感的,不像正式的RFC(注:Request For Comments,用于制订基本的互联网通讯协定)那样,你应该总是使用小写字母指定主机名称。

 

-------------------------------

 

* android:mimeType

 

A MIME media type, such as image/jpeg or audio/mpeg4-generic. The subtype can be the asterisk wildcard (*) to indicate that any subtype matches.

 

一个MIME(注:Multipurpose Internet Mail Extensions,多功能互联网邮件扩展)媒体类型,诸如image/jpeg或audio/mpeg4-generic。子类型可以是星号通配符(*)以指示匹配任意子类型。

 

-------------------------------

 

Note: MIME type matching in the Android framework is case-sensitive, unlike formal RFC MIME types. As a result, you should always specify MIME types using lowercase letters.

 

注意:在Android框架中MIME类型匹配是大小写敏感的,不像正式的RFC MIME类型那样。因此,你应该总是用小写字母指定MIME类型。

 

-------------------------------

 

* android:path 

* android:pathPrefix 

* android:pathPattern

 

The path part of a URI. The path attribute specifies a complete path that is matched against the complete path in an Intent object. The pathPrefix attribute specifies a partial path that is matched against only the initial part of the path in the Intent object. The pathPattern attribute specifies a complete path that is matched against the complete path in the Intent object, but it can contain the following wildcards:

 

URI的路径部分。path属性指定一个完整的路径,它被匹配到一个Intent对象中的完整路径。pathPrefix属性指定一个局部路径,它只是被匹配到Intent对象的路径的开始部分。pathPattern属性指定一个完整路径,它被匹配到Intent对象中的完整路径,但它可以包含以下通配符:

 

* An asterisk ('*') matches a sequence of 0 to many occurrences of the immediately preceding character.

 

* 一个星号('*')匹配一个零到多次出现的即时(注:紧接)前驱字符的序列。

 

* A period followed by an asterisk (".*") matches any sequence of 0 to many characters.

 

* 一个点后面跟着一个星号(".*")匹配0到多个字符的任意序列。

 

Because '\' is used as an escape character when the string is read from XML (before it is parsed as a pattern), you will need to double-escape: For example, a literal '*' would be written as "\\*" and a literal '\' would be written as "\\\\". This is basically the same as what you would need to write if constructing the string in Java code.

 

因为'\'被用作一个转义字符当该字符串从XML中被读取(在它被解释为一个模式之前),你将需要双转义:例如,一个字面'*'应该被写成"\\*"而一个字面'\'应该被写成"\\\\"。这基本上和如果在Java代码中构造字符串的话你需要写的东西是相同的。

 

For more information on these three types of patterns, see the descriptions of PATTERN_LITERAL, PATTERN_PREFIX, and PATTERN_SIMPLE_GLOB in the PatternMatcher class.

 

想获得关于这三种类型模式的更多信息,参见PatternMatcher类中PATTERN_LITERAL,PATTERN_PREFIX,和PATTERN_SIMPLE_GLOB的描述。

 

These attributes are meaningful only if the scheme and host attributes are also specified for the filter.

 

这些属性是有意义的仅当还为该过滤器指定scheme和host属性。

 

* android:port

 

The port part of a URI authority. This attribute is meaningful only if the scheme and host attributes are also specified for the filter.

 

URI权力的端口部分。这个属性有意义仅当还为该过滤器指定scheme和host属性。

 

* android:scheme

 

The scheme part of a URI. This is the minimal essential attribute for specifying a URI; at least one scheme attribute must be set for the filter, or none of the other URI attributes are meaningful.

 

一个URI的模式部分。它是指定一个URI的最小基本属性;必须为该过滤器设置至少一个scheme属性,否则其它URI属性中没有一个是有意义的。

 

A scheme is specified without the trailing colon (for example, http, rather than http:).

 

一个模式被指定不带结束的冒号(例如,http,而非http:)

 

If the filter has a data type set (the mimeType attribute) but no scheme, the content: and file: schemes are assumed.

 

如果过滤器拥有一个数据类型集合(mimeType属性)但没有模式,那么假定是content:和file:模式。

 

-------------------------------

 

Note: scheme matching in the Android framework is case-sensitive, unlike the RFC. As a result, you should always specify schemes using lowercase letters.

 

注意:在Android框架中模式匹配是大小写敏感的,不像RFC那样。因此,你应该总是使用小写字母指定模式。

 

-------------------------------

 

* introduced in:

 

* 引入:

 

API Level 1

 

API级别1

 

* see also:

 

* 另见:

 

<action> 

<category>

 

Except as noted, this content is licensed under Apache 2.0. For details and restrictions, see the Content License.

 

除特别说明外,本文在Apache 2.0下许可。细节和限制请参考内容许可证。

 

Android 4.0 r1 - 10 Feb 2012 0:44

 

-------------------------------

 

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

 

(此页部分内容基于Android开源项目,以及使用根据创作公共2.5来源许可证描述的条款进行修改)

 

(本人翻译质量欠佳,请以官方最新内容为准,或者参考其它翻译版本:

* ソフトウェア技術ドキュメントを勝手に翻訳

http://www.techdoctranslator.com/android

* Ley's Blog

http://leybreeze.com/blog/

* 农民伯伯

http://www.cnblogs.com/over140/

* Android中文翻译组

http://androidbox.sinaapp.com/

 

题目三 哈夫曼编/译码器 【问题描述】 利用哈夫曼编码进行通信可以大大提高对信道的利用率,缩短信息传输时 间,降低传输成本。但是,这要求在发送端通过一个编码系统对待传输数据预 先编码,在接收端对接收的数据进行译码(复原),对于双工信道(可以双向 传输信息的信道),每端都需要一个完整的编/译码系统。试为这样的信息收 发站写一个哈夫曼码的编/译码系统。 【基本要求】 一个完整的哈夫曼编/译码系统应具有以下功能: (1)I:初始化(Initialization)。从终端(键盘)读入字符集的大小 n,n个字符及n个权值,建立哈夫曼树并将其存于文件hfmTree中。 (2)E:编码(Encoding)。利用已经建好的哈夫曼树,为每个叶子结点 编码,并对文本文件ToBeTran中的正文进行编码,然后将结果存入文件 CodeFile 中。 (3)D:译码(Decoding)。利用已经建好的哈夫曼树,对文本文件 CodeFile 中的代码进行翻译,结果存入TextFile中。 (4)V:比较文件ToBeTranTextFile的内容是否相同,若不同,则编 译码过程中有错误。 【测试数据】 (1)8个字符及其权值 a b c d e f 0.05 0.29 0.07 0.08 0.14 0.23 0.03 0.11 g (2)空格26个英文字母及其权值 A B C D E F G H 186 4 13 22 32 103 21 15 47 I J K L M N O P Q 57 1 5 32 20 57 63 15 1 R S T U V W X Y Z 48 51 80 23 8 18 1 16 1 【实现提示】 h 实现上述的哈夫曼编/译码系统时,先不考虑文件操作(建立文件、读写文 件等),而是将形成的哈夫曼树存储在用HuffmanTree定义的数组中,将各叶 子结点的编码保存在用HuffmanCode定义的字符数组中,需要编码的信息原文 由终端(键盘)输入后存入一个字符数组A,编码后的01序列存入另一个字符 数组B,最后再翻译B中的01串(译码),结果在终端(显示器屏)显示。 若采用文件保存信息,则以测试数据1为例,需要以下几个文件: (1)文件hfmTree用于保存哈夫曼树,其内容示例如下(其中的数据来自 课堂示例,每行表示树中的一个结点,结点中的权值可以不保存): a 0.05 9 0 0 b 0.29 14 0 0 c 0.07 10 0 0 d 0.08 10 0 0 e 0.14 12 0 0 f 0.23 13 0 0 g 0.03 9 0 0 h 0.11 11 0 0 0.08 11 1 7 0.15 12 3 4 0.19 13 9 8 0.29 14 5 10 0.42 15 11 6 0.58 15 2 12 1.00 0 13 14 (2)文件ToBeTran中存储需要编码的信息原文,其内容示例如下(其中 的数据来自课堂示例): bbfehagd (3)文件CodeFile保存对ToBeTran的编码结果,其内容如下所示: 101001110001000100001111 (4)文件TextFile保存对CodeFile的翻译结果,其内容如下所示: bbfehagd 注意:以上各文件中的内容都可以另行设计,不一定与这里给出的例子相 同。将hfmTree中的内容读取出来后,应依次保存在下标从1开始的数组元素 中。 编写一个c++程序,要求严格符合以上要求
最新发布
10-28
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值