基于Android的二手图书交易系统的设计与实现外文翻译资料

 2022-10-30 11:10

Android :A Programmerrsquo;s Guide

1.What is Android?

It can be said that, for a while, traditional desktop application developers have been spoiled. This is not to say that traditional desktop application development is easier than other forms of development. However, as traditional desktop application developers, we have had the ability to create almost any kind of application we can imagine. I am including myself in this grouping because I got my start in desktop programming.

One aspect that has made desktop programming more accessible is that we have had the ability to interact with the desktop operating system, and thus interact with any underlying hardware, pretty freely (or at least with minimal exceptions). This kind of freedom to program independently, however, has never really been available to the small group of programmers who dared to venture into the murky waters of cell phone development.

Brief History of Embedded Device Programming

For a long time, cell phone developers comprised a small sect of a slightly larger group of developers known as embedded device developers. Seen as a less “glamorous” sibling to desktop—and later web—development, embedded device development typically got the proverbial short end of the stick as far as hardware and operating system features, because embedded device manufacturers were notoriously stingy on feature support. Embedded device manufacturers typically needed to guard their hardware secrets closely, so they gave embedded device developers few libraries to call when trying to interact with a specific device.

Embedded devices differ from desktops in that an embedded device is typically a “computer on a chip.” For example, consider your standard television remote control; it is not really seen as an overwhelming achievement of technological complexity. When any button is pressed, a chip interprets the signal in a way that has been programmed into the device. This allows the device to know what to expect from the input device (key pad), and how to respond to those commands (for example, turn on the television). This is a simple form of embedded device programming. However, believe it or not, simple devices such as these are definitely related to the roots of early cell phone devices and

development.

Most embedded devices ran (and in some cases still run) proprietary operating systems. The reason for choosing to create a proprietary operating system rather than use any consumer system was really a product of necessity. Simple devices did not need very robust and optimized operating systems.

As a product of device evolution, many of the more complex embedded devices, such as early PDAs, household security systems, and GPSs, moved to somewhat standardized operating system platforms about five years ago. Small-footprint operating systems such as Linux, or even an embedded version of Microsoft Windows, have become more prevalent on many embedded devices. Around this time in device evolution, cell phones branched from other embedded devices onto their own path. This branching is evident when you examine their architecture.

Nearly since their inception, cell phones have been fringe devices insofar as they run

on proprietary software—software that is owned and controlled by the manufacturer, and

is almost always considered to be a “closed” system. The practice of manufacturers using proprietary operating systems began more out of necessity than any other reason. That is, cell phone manufacturers typically used hardware that was completely developed in-house, or at least hardware that was specifically developed for the purposes of running cell phone equipment. As a result, there were no openly available, off-the-shelf software packages or solutions that would reliably interact with their hardware. Since the manufacturers also wanted to guard very closely their hardware trade secrets, some of which could be revealed by allowing access to the software level of the device, the common practice was, and in most cases still is, to use completely proprietary and closed software to run their devices. The downside to this is that anyone who wanted to develop applications for cell phones needed to have intimate knowledge of the proprietary environment within which it was to run. The solution was to purchase expensive development tools directly from the manufacturer. This isolated many of the “homebrew” developers.

Another, more compelling “necessity” that kept cell phone development out of the hands of the everyday developer was the hardware manufacturersrsquo; solution to the “memory versus need” dilemma. Until recently, cell phones did little more than execute and receive phone calls, track your contacts, and possibly send and receive short text messages; not really the “Swiss army knives” of technology they are today. Even as late as 2002, cell phones with cameras were not commonly found in the hands of consumers.

By 1997, small applications such as calculators and games (Tetris, for example) crept their way onto cell phones, but the overwhelming function was still that of a phone dialer itself. Cell phones had not yet become the multiuse, multifunction personal tools they are today. No one yet saw the need for Internet browsing, MP3 playing, or any of the multitudes of functions we are accustomed to using today. It is possible that the cell phone manufacturers of 1997 did not fully perceive the need consumers would have for an all-in-one device. However, even if the need was present, a lack of device memory and storage capacity was an even bigger obstacle to overcome. More people may have wanted their devices to be all-in-one tools, but manufacturers still had to climb the memory hurdle.

To put the problem simply, it takes memory to store and run applications on any device, cell phones included. Cell phones, as a device,

剩余内容已隐藏,支付完成后下载完整资料


Android:程序员指南

1.什么是Android?

可以说,一段时间以来,传统的桌面应用开发者已经被宠坏了。这并不是说传统的桌面应用开发比其他形式的开发更容易。然而,作为传统的桌面应用程序开发人员,我们已经有能力创建几乎任何我们可以想象的应用程序。我把自己包括在这个分组中,因为我在桌面编程方面小有经验。

使桌面编程更易于访问的一个方面是,我们已经能够与桌面操作系统进行交互,因此可以非常自由地(或至少在极少的例外情况下)与任何底层硬件进行交互。然而,这种独立程序的自由从来没有真正适用于敢于冒险进入手机开发的阴暗水域的程序员。

嵌入式设备编程历史

很长一段时间以来,手机开发商组成了一小部分开发商,被称为嵌入式设备开发人员的小部分。 由于嵌入式设备制造商在功能支持方面臭名昭著,因此看起来像台式机和随后的网络开发相比,嵌入式设备开发通常在硬件和操作系统功能方面具有绰绰的短杆。嵌入式设备制造商通常需要密切监视其硬件秘密,因此他们为嵌入式设备开发人员提供了在尝试与特定设备进行交互时调用的库。

嵌入式设备与台式机的不同之处在于,嵌入式设备通常是“芯片上的计算机”。例如,考虑您的标准电视遥控器;它并不是真正被视为技术复杂性的压倒性成就。当按下任何按钮时,芯片将对已编程到设备中的方式对信号进行解释。这允许设备知道从输入设备(键盘)预期的内容,以及如何响应这些命令(例如打开电视机)。这是嵌入式设备编程的一种简单形式。然而,不管相信还是不相信,这些简单的设备肯定与早期手机设备的根源有关发展。

大多数嵌入式设备运行(在某些情况下仍然运行)专有操作系统。选择创建专有操作系统而不是使用任何消费者系统的原因真的是必要的产物。简单的设备不需要非常强大和优化的操作系统。

作为设备演进的产物,许多更为复杂的嵌入式设备(如早期PDA,家庭安全系统和GPS)在五年前就转移到了一些标准化的操作系统平台上。诸如Linux等小尺寸操作系统,甚至是Microsoft Windows的嵌入式版本,在许多嵌入式设备中已经变得越来越普遍。在这个时候在设备演进中,手机从其他嵌入式设备分支到自己的路径上。当您检查其架构时,这种分支是显而易见的。

手机几乎自成立以来一直是边缘装置在由制造商拥有和控制的专有软件 - 软件上几乎总是被认为是一个“封闭”的系统。使用专有操作系统的制造商的做法比任何其他原因更加不必要。也就是说,手机制造商通常使用内部完全开发的硬件,或者至少是专门用于运行手机设备的硬件。因此,没有可靠的现成的软件包或解决方案可靠地与其硬件交互。由于制造商还希望非常密切地保护其硬件商业秘密,其中一些可以通过访问设备的软件级别来揭示,通常的做法是,在大多数情况下仍然是使用完全专有和封闭的软件运行他们的设备。缺点是任何想要开发手机应用程序的人都需要对其运行的专有环境有深入的了解。该解决方案是直接从制造商处购买昂贵的开发工具。这个孤立的许多“自制”开发者。

将手机开发放在日常开发者手中的另一个更引人注目的“必要性”就是硬件制造商对“记忆与需求”两难的解决方案。直到最近,手机只是执行和接收电话,跟踪你的联系人,并且可能发送和接收短信息;不是真正的“瑞士军刀”的技术,他们今天。即使在2002年以前,手机与相机并不常见于消费者手中。

到1997年,诸如计算器和游戏(例如俄罗斯方块)等小型应用开始进入手机,但是压倒性的功能仍然是手机拨号器的功能。手机尚未成为今天使用的多功能多功能个人工具。没有人看到需要互联网浏览,MP3播放,或者我们今天习惯使用的任何许多功能。1997年的手机制造商有可能没有完全察觉消费者对于一体机的需求。然而,即使存在需求,缺乏设备内存和存储容量也是一个更大的障碍。更多的人可能希望他们的设备是一体式工具,但制造商仍然不得不爬上记忆障碍。

要简单地解决问题,需要内存来存储和运行应用程序,包括任何设备,手机。手机作为一种装置,直到最近才没有可用的内存量,这将有助于包含“额外的”程序。在过去两年中,存储芯片的价格已经达到非常低的水平。设备制造商现在有能力以更低的价格包含更多的内存。目前,许多手机的标准内存比一般电脑在20世纪90年代中期要高。所以,现在我们有需要和记忆,我们可以全力以赴,开发出世界各地手机的酷应用,对吧?不完全是。设备制造商仍然严密保护在其设备上运行的操作系统。虽然有几个已经开放,他们将允许一些基于Java的应用程序在手机的小环境中运行,但许多人不允许这样做。即使允许一些Java应用程序运行的系统也不允许访问标准桌面开发人员习惯的“核心”系统。

开放手机联盟和Android

2007年11月,Google在开放手机联盟下,发布了Android应用程序开发的障碍。 开放手机联盟是一组硬件和软件开发商,包括谷歌,NTT DoCoMo,Sprint Nextel和HTC,其目标是创造一个更开放的手机环境。在联盟下发布的第一个产品是移动设备操作系统Android。

随着Android的发布,Google提供了大量开发工具和教程,以帮助未来的开发人员进入新的系统。帮助文件,平台软件开发工具包(SDK),甚至开发者社区都可以找到Google的Android网站http://code.google.com/android。这个网站应该是你的出发点,我强烈建议您访问该网站。

虽然运行Linux,Windows,甚至PalmOS的手机很容易找到,在撰写本文时,没有任何硬件平台已经宣布为Android运行。HTC,LG电子,摩托罗拉和三星是Android手机发布的开放手机联盟的成员,所以我们只能希望他们在不久的将来有几个基于Android的设备。自2007年11月发布以来,该系统本身仍处于软件测试阶段。 这对开发人员来说是一个好消息,因为它给了我们一个罕见的进一步的前景,看看未来的系统,并有机会开始开发应用程序,一旦硬件发布就会运行。

Android简介

作为一个系统,Android是一种基于Java的操作系统,可在Linux 2.6内核上运行。该系统非常轻巧,功能齐全。图1-1显示了未修改的Android主屏幕。

Android应用程序是使用Java开发的,可以很容易地移植到新平台。 如果您尚未下载Java或不确定您需要哪个版本,我将在第2章中详细介绍开发环境的安装。Android的其他功能包括加速的3-D图形引擎(基于硬件支持),数据库支持 由SQLite和一个集成的Web浏览器。

如果您熟悉Java编程或任何类型的OOP开发人员,那么您可能习惯于编程用户界面(UI)开发,即直接在程序代码中处理的UI布局。Android在识别和允许编程UI开发的同时,也支持更新的基于XML的UI布局。XML UI布局是平均桌面开发人员的一个相当新的概念。我将在本书的支持章节中介绍XML UI布局和编程UI开发。

Android的更令人激动和引人注目的功能之一是,由于其架构,第三方应用程序(包括“本土增长”)的应用程序的执行与与核心系统捆绑的系统优先级相同。这是大多数系统的主要偏离,这给嵌入式系统应用程序提供了比由第三方开发人员创建的应用程序可用的线程优先级更高的执行优先级。此外,每个应用程序都使用非常轻量级的虚拟机在其自己的线程内执行。

除了非常慷慨的SDK和我们开发出来的格式良好的库之外,Android开发人员最令人激动的功能是,我们现在可以访问操作系统可以访问的任何内容。换句话说,如果要创建拨打电话的应用程序,您可以访问手机的拨号器;如果您想创建一个利用手机内部GPS(如果配备)的应用程序,则可以访问该应用程序。开发人员创造动态和有趣的应用程序的潜力现在已经开放。

除了Android方面提供的所有功能之外,Google已经引入了一些非常诱人的功能。Android应用程序的开发人员将能够将其应用程序与现有的Google产品(如Google地图和无处不在的Google搜索)相结合。假设您想编写一个应用程序,该应用程序可以拉出来自哪个来电的Google地图,或者希望能够与您的联系人一起存储常见的搜索结果; Android的可能性已经大开眼界。

2.使用意图和电话拨号器

到目前为止,这些章节已经介绍了Android编程的基础知识。您已经检查了Android应用程序的大纲,并将您的第一个应用程序安装到Android服务器。您已经学习了如何使用Views和setContentView(),以及如何在XML中创建UI。这些技能帮助您创建一个静态应用程序。您还没有做的是使用应用程序界面与手机创建的硬件进行交互。

您不应该忽视Android创建的平台本质上仍然是手机。Android将运行的设备的底层硬件设计用于个人到个人通信的目的。如果您剥离Android SDK能够添加到手机中的所有铃声和口哨声,仍然必须能够发送和接收电话。因此,本章重点介绍使您能够与手机硬件进行交互的代码。

在本章结尾,您应该具备与手机的一些基本功能进行交互所需的技能。您可以使用拨号器发送和接收电话。这些工具和技能将成为您在此灵活平台上创建有用应用程序的关键。

您正在阅读本书,因为您打算设计在手机上运行的应用程序,因此,您应该了解Android应该如何了解Android如何与手机硬件进行交互,特别是使手机能够发送和接收的过程调用。

当我们想到手机时,会考虑几个基本功能。第一个也是最明显的,它是发送和接收电话的能力。这无疑是手机的典型功能。有一些外围功能使手机更易于使用,例如保持和管理联系人的能力,以及存储和查看未接来电的能力。正如本章所述,您可以访问和操作所有这些功能的代码。

本章您将看到的第一个电话功能是发送呼叫。您将使用Intent创建一个控制电话拨号器的应用程序,并使其对号码进行呼叫。随着本章的进展,您将会扩展此应用程序,并添加一些铃声和口哨。

什么是意图?

在您可以开始与电话拨号器进行交互之前,您需要了解您将用于执行此工作的代码类型。Android使用Intents在应用程序中执行特定的作业。一旦掌握了Intents的使用,一个全新的应用程序开发世界将向您敞开。本节定义了Intent是什么以及如何使用它。

意图是Android将某些信息从一个Activity传递到另一个Activity的方法。一个意图,简单来说,表达给你的意图做某事。您可以将意图视为活动之间传递的消息。例如,假设您有一个需要打开Web浏览器并在Android设备上显示页面的活动。您的活动将向Android Intent Resolver发送“将Web浏览器中的x页面打开,称为WEB_SEARCH_ACTION意图”。意向解析器通过活动列表进行解析,并选择最符合您的意图的;在这种情况下,Web浏览器活动。然后,Intent Resolver将您的页面传递到Web浏览器并启动Web浏览器活动。

意图分为两大类:

●活动动作意向用于在应用程序之外调用活动的意图。 只有一个活动可以处理意图。例如,对于Web浏览器,您需要打开Web浏览器活动来显示页面。

●广播意向发送到多个活动处理的意图。 广播意图的一个例子是Android发送的关于当前电池电量的消息。任何活动可以处理此意图并相应地作出反应,例如,如果电池电量低于某一点,则取消活动。

意图只是图片的三分之一。意图真的只是这样,意图做某事; 一个意图本身不能做任何事情。您需要意向过滤器和意向接收器来监听和解释意向。

意图接收器就像活动的邮箱。意图接收器用于允许活动接收指定的意图。 使用以前的Web浏览器示例,Web浏览器活动设置为接收Web浏览器Intents。像这样的系统允许不相关的活动忽略他们无法处理的意图。它还允许需要另一个活动的帮助的活动来利用该活动,而不需要知道如何调用它。

使用Intent和Intent接收器,一个Activity可以发送一个Intent,另一个Activity可以接收它。然而,需要有一些管理可以在两个活动之间发送的信息的类型。这是Intent Filters进来的地方。

活动使用意图过滤器来描述他们想要接收的意向类型。更重要的是,它们概述了Intent中应该传递的数据类型。因此,在我们的示例场景中,我们希望Web浏览器打开一个网页。意图过滤器将声明使用WEB_SEARCH_ACTION意图传递的数据应以URL的形式。

在下一部分中,您将开始使用Intents打开和使用手机的拨号器。

使用拨号器

现在你知道一个意图是什么,现在是时候看一个具体的例子了。本节介绍如何使用DIAL_ACTION意图打开电话拨号器。你会通过一个电话号码与你的意图。如果您的应用程序正常工作,您应该看到在拨号器中显示与您的意图通过的号码。

第一步是为此活动创建一个新项目(有关说明,请参阅第5章)。 将项目命名为AndroidPhoneDialer。下图显示了该项目的新建Android项目向导。

在Eclipse中打开新应用程序后,第一个业务是从包含该Hello World语句的main.xml中删除TextView。 删除TextView后,main.xml文件应该是这样的:

lt;?xml version='1.0' encoding='utf-8'?gt;

lt;LinearLayout xmlns:android=http://schemas.android.com/apk/res/android

android:orientation='vertical'

android:layout_width='fill_parent'

android:layout_height='fill_parent'

gt;

lt;/LinearLayoutgt;

您需要在项目中添加两个新的包来使用DIAL_ACTION

剩余内容已隐藏,支付完成后下载完整资料


资料编号:[138209],资料为PDF文档或Word文档,PDF文档可免费转换为Word

您需要先支付 30元 才能查看全部内容!立即支付

课题毕业论文、开题报告、任务书、外文翻译、程序设计、图纸设计等资料可联系客服协助查找。