Chinaunix首页 | 论坛 | 博客
  • 博客访问: 91627
  • 博文数量: 40
  • 博客积分: 651
  • 博客等级: 上士
  • 技术积分: 356
  • 用 户 组: 普通用户
  • 注册时间: 2011-08-08 22:31
文章分类

全部博文(40)

文章存档

2013年(6)

2012年(3)

2011年(31)

我的朋友

分类: 系统运维

2011-08-09 13:36:22

Android SDK3.0下载地址:


ADT 10.0.0的离线地址:


Android SDK 3.0的更新内容:

API Overview

The sections below provide a technical overview of what's new for developers in Android 3.0, including new features and changes in the framework API since the previous version.

Fragments

A fragment is a new framework component that allows you to separate distinct elements of an activity into self-contained modules that define their own UI and lifecycle. To create a fragment, you must extend the Fragment class and implement several lifecycle callback methods, similar to an Activity. You can then combine multiple fragments in a single activity to build a multi-pane UI in which each pane manages its own lifecycle and user inputs.

You can also use a fragment without providing a UI and instead use the fragment as a worker for the activity, such as to manage the progress of a download that occurs only while the activity is running.

Additionally:

Fragments are self-contained and you can reuse them in multiple activitiesYou can add, remove, replace and animate fragments inside the activityYou can add fragments to a back stack managed by the activity, preserving the state of fragments as they are changed and allowing the user to navigate backward through the different statesBy providing alternative layouts, you can mix and match fragments, based on the screen size and orientationFragments have direct access to their container activity and can contribute items to the activity's Action Bar (discussed next)

To manage the fragments in your activity, you must use the FragmentManager, which provides several APIs for interacting with fragments, such as finding fragments in the activity and popping fragments off the back stack to restore their previous state.

To perform a transaction, such as add or remove a fragment, you must create a FragmentTransaction. You can then call methods such as add()remove(), or replace(). Once you've applied all the changes you want to perform for the transaction, you must call commit() and the system applies the fragment transaction to the activity.

For more information about using fragments, read the Fragments documentation. Several samples are also available in the API Demos application.

Action Bar

The Action Bar is a replacement for the traditional title bar at the top of the activity window. It includes the application logo in the left corner and provides a new interface for items in the Options Menu. Additionally, the Action Bar allows you to:

Add menu items directly in the Action Bar—as "action items."

In your XML declaration for the menu item, include the android:showAsAction attribute with a value of "ifRoom". When there's enough room, the menu item appears directly in the Action Bar. Otherwise, the item is placed in the overflow menu, revealed by the menu icon on the right side of the Action Bar.

Replace an action item with a widget (such as a search box)—creating an "action view."

In the XML declaration for the menu item, add the android:actionViewLayout attribute with a layout resource or the android:actionViewClass attribute with the class name of a widget. (You must also declare the android:showAsAction attribute so that the item appears in the Action Bar.) If there's not enough room in the Action Bar and the item appears in the overflow menu, it behaves like a regular menu item and does not show the widget.

Add an action to the application logo and replace it with a custom logo

The application logo is automatically assigned the android.R.id.home ID, which the system delivers to your activity's onOptionsItemSelected() callback when touched. Simply respond to this ID in your callback method to perform an action such as go to your application's "home" activity.

To replace the icon with a logo, specify your application logo in the manifest file with the android:logo attribute, then call setDisplayUseLogoEnabled(true) in your activity.

Add breadcrumbs to navigate backward through the back stack of fragmentsAdd tabs or a drop-down list to navigate through fragmentsCustomize the Action Bar with themes and backgrounds

The Action Bar is standard for all applications that use the new holographic theme, which is also standard when you set either the android:minSdkVersion or android:targetSdkVersion to "11".

For more information about the Action Bar, read the Action Bar documentation. Several samples are also available in the API Demos application.

System clipboard

Applications can now copy and paste data (beyond mere text) to and from the system-wide clipboard. Clipped data can be plain text, a URI, or an intent.

By providing the system access to the data you want the user to copy, through a content provider, the user can copy complex content (such as an image or data structure) from your application and paste it into another application that supports that type of content.

To start using the clipboard, get the global ClipboardManager object by calling getSystemService(CLIPBOARD_SERVICE).

To copy an item to the clipboard, you need to create a new ClipData object, which holds one or more ClipData.Item objects, each describing a single entity. To create a ClipData object containing just one ClipData.Item, you can use one of the helper methods, such as newPlainText(), newUri(), and newIntent(), which each return a ClipData object pre-loaded with the ClipData.Item you provide.

To add the ClipData to the clipboard, pass it to setPrimaryClip() for your instance of ClipboardManager.

You can then read a file from the clipboard (in order to paste it) by calling getPrimaryClip() on the ClipboardManager. Handling the ClipData you receive can be complicated and you need to be sure you can actually handle the data type in the clipboard before attempting to paste it.

The clipboard holds only one piece of clipped data (a ClipData object) at a time, but one ClipData can contain multiple ClipData.Items.

For more information, read the Copy and Paste documentation. You can also see a simple implementation of copy and paste in the API Demos and a more complete implementation in the Note Pad application.

Drag and drop

New APIs simplify drag and drop operations in your application's user interface. A drag operation is the transfer of some kind of data—carried in a ClipData object—from one place to another. The start and end point for the drag operation is a View, so the APIs that directly handle the drag and drop operations are in the View class.

A drag and drop operation has a lifecycle that's defined by several drag actions—each defined by a DragEvent object—such as ACTION_DRAG_STARTED, ACTION_DRAG_ENTERED, and ACTION_DROP. Each view that wants to participate in a drag operation can listen for these actions.

To begin dragging content in your activity, call startDrag() on a View, providing a ClipData object that represents the data to drag, a View.DragShadowBuilder to facilitate the "shadow" that users see under their fingers while dragging, and an Object that can share information about the drag object with views that may receive the object.

To accept a drag object in a View (receive the "drop"), register the view with an OnDragListener by calling setOnDragListener(). When a drag event occurs on the view, the system calls onDrag() for the OnDragListener, which receives a DragEvent describing the type of drag action has occurred (such as ACTION_DRAG_STARTED, ACTION_DRAG_ENTERED, and ACTION_DROP). During a drag, the system repeatedly calls onDrag() for the view underneath the drag, to deliver a stream of drag events. The receiving view can inquire the event type delivered to onDragEvent() by calling getAction() on the DragEvent.

Note: Although a drag event may carry a ClipData object, this is not related to the system clipboard. A drag and drop operation should never put the dragged data in the system clipboard.

For more information, read the Dragging and Dropping documentation. You can also see an implementation of drag and drop in the API Demos application and the Honeycomb Gallery application.

App widgets

Android 3.0 supports several new widget classes for more interactive app widgets on the users Home screen, including: GridView, ListView, StackView, ViewFlipper, and AdapterViewFlipper.

More importantly, you can use the new RemoteViewsService to create app widgets with collections, using widgets such as GridView, ListView, and StackView that are backed by remote data, such as from a content provider.

The AppWidgetProviderInfo class (defined in XML with an element) also supports two new fields: autoAdvanceViewId and previewImage. The autoAdvanceViewId field lets you specify the view ID of the app widget subview that should be auto-advanced by the app widget’s host. The previewImage field specifies a preview of what the app widget looks like and is shown to the user from the widget picker. If this field is not supplied, the app widget's icon is used for the preview.

To help create a preview image for your app widget (to specify in the autoAdvanceViewId field), the Android emulator includes an application called "Widget Preview." To create a preview image, launch this application, select the app widget for your application and set it up how you'd like your preview image to appear, then save it and place it in your application's drawable resources.

You can see an implementation of the new app widget features in the StackView App Widget and Weather List Widget applications.

Status bar notifications

The Notification APIs have been extended to support more content-rich status bar notifications, plus a new Notification.Builder class allows you to easily create Notification objects.

New features include:

Support for a large icon in the notification, using setLargeIcon(). This is usually for social applications to show the contact photo of the person who is the source of the notification or for media apps to show an album thumbnail.Support for custom layouts in the status bar ticker, using setTicker().Support for custom notification layouts to include buttons with PendingIntents, for more interactive notification widgets. For example, a notification can control music playback without starting an activity.Content loaders

New framework APIs facilitate asynchronous loading of data using the Loader class. You can use it in combination with UI components such as views and fragments to dynamically load data from worker threads. The CursorLoader subclass is specially designed to help you do so for data backed by a ContentProvider.

All you need to do is implement the LoaderCallbacks interface to receive callbacks when a new loader is requested or the data has changed, then call initLoader() to initialize the loader for your activity or fragment.

For more information, read the Loaders documentation. You can also see example code using loaders in the FragmentListCursorLoader and LoaderThrottle samples.

Bluetooth A2DP and headset APIs

Android now includes APIs for applications to verify the state of connected Bluetooth A2DP and headset profile devices. For example, applications can identify when a Bluetooth headset is connected for listening to music and notify the user as appropriate. Applications can also receive broadcasts for vendor specific AT commands and notify the user about the state of the connected device, such as when the connected device's battery is low.

You can initialize the respective BluetoothProfile by calling getProfileProxy() with either the A2DP or HEADSET profile constant and a BluetoothProfile.ServiceListener to receive callbacks when the Bluetooth client is connected or disconnected.

Animation framework

An all new flexible animation framework allows you to animate arbitrary properties of any object (View, Drawable, Fragment, Object, or anything else). It allows you to define several aspects of an animation, such as:

DurationRepeat amount and behaviorType of time interpolationAnimator sets to play animations together, sequentially, or after specified delaysFrame refresh delay

You can define these animation aspects, and others, for an object's int, float, and hexadecimal color values, by default. That is, when an object has a property field for one of these types, you can change its value over time to affect an animation. To animate any other type of value, you tell the system how to calculate the values for that given type, by implementing the TypeEvaluator interface.

There are two animators you can use to animate the values of a property: ValueAnimator and ObjectAnimator. The ValueAnimator computes the animation values, but is not aware of the specific object or property that is animated as a result. It simply performs the calculations, and you must listen for the updates and process the data with your own logic. The ObjectAnimator is a subclass of ValueAnimator and allows you to set the object and property to animate, and it handles all animation work. That is, you give the ObjectAnimator the object to animate, the property of the object to change over time, and a set of values to apply to the property over time, then start the animation.

Additionally, the LayoutTransition class enables automatic transition animations for changes you make to your activity layout. To enable transitions for part of the layout, create a LayoutTransition object and set it on any ViewGroup by calling setLayoutTransition(). This causes default animations to run whenever items are added to or removed from the group. To specify custom animations, call setAnimator() on the LayoutTransition and provide a custom Animator, such as a ValueAnimator or ObjectAnimator discussed above.

For more information, see the Property Animation documentation. You can also see several samples using the animation APIs in the API Demos application.

Extended UI frameworkMultiple-choice selection for ListView and GridView

New CHOICE_MODE_MULTIPLE_MODAL mode for setChoiceMode() allows users to select multiple items from a ListView or GridView. When used in conjunction with the Action Bar, users can select multiple items and then select the action to perform from a list of options in the Action Bar (which has transformed into a Multi-choice Action Mode).

To enable multiple-choice selection, call setChoiceMode(CHOICE_MODE_MULTIPLE_MODAL) and register a MultiChoiceModeListener with setMultiChoiceModeListener().

When the user performs a long-press on an item, the Action Bar switches to the Multi-choice Action Mode. The system notifies the MultiChoiceModeListener when items are selected by calling onItemCheckedStateChanged().

For an example of multiple-choice selection, see the List15. java class in the API Demos sample application.

New APIs to transform views

New APIs allow you to easily apply 2D and 3D transformations to views in your activity layout. New transformations are made possible with a set of object properties that define the view's layout position, orientation, transparency and more.

New methods to set the view properties include: setAlpha(), setBottom(), setLeft(), setRight(), setBottom(), setPivotX(), setPivotY(), setRotationX(), setRotationY(), setScaleX(), setScaleY(), setAlpha(), and others.

Some methods also have a corresponding XML attribute that you can specify in your layout file, to apply a default transformation. Available attributes include: translationX, translationY, rotation, rotationX, rotationY, scaleX, scaleY, transformPivotX, transformPivotY, and alpha.

Using some of these new view properties in combination with the new animation framework (discussed above), you can easily apply some fancy animations to your views. For example, to rotate a view on its y-axis, supply ObjectAnimator with the View, the "rotationY" property, and the start and end values:

ObjectAnimatoranimator=ObjectAnimator.ofFloat(myView,"rotationY",0,360);
animator
.setDuration(2000);
animator
.start();New holographic themes

The standard system widgets and overall look have been redesigned and incorporate a new "holographic" user interface theme. The system applies the new theme using the standard style and theme system.

Any application that targets the Android 3.0 platform—by setting either the android:minSdkVersion or android:targetSdkVersion value to "11"—inherits the holographic theme by default. However, if your application also applies its own theme, then your theme will override the holographic theme, unless you update your styles to inherit the holographic theme.

To apply the holographic theme to individual activities or to inherit them in your own theme definitions, use one of several new Theme.Holo themes. If your application is compatible with version of Android lower than 3.0 and applies custom themes, then you should select a theme based on platform version.

New widgetsAdapterViewAnimator

Base class for an AdapterView that performs animations when switching between its views.

AdapterViewFlipper

Simple ViewAnimator that animates between two or more views that have been added to it. Only one child is shown at a time. If requested, it can automatically flip between each child at a regular interval.

CalendarView

Allows users to select dates from a calendar by touching the date and can scroll or fling the calendar to a desired date. You can configure the range of dates available in the widget.

ListPopupWindow

Anchors itself to a host view and displays a list of choices, such as for a list of suggestions when typing into an EditText view.

NumberPicker

Enables the user to select a number from a predefined range. The widget presents an input field and up and down buttons for selecting a number. Touching the input field allows the user to scroll through values or touch again to directly edit the current value. It also allows you to map positions to strings, so that the corresponding string is displayed instead of the index position.

PopupMenu

Displays a Menu in a modal popup window that's anchored to a view. The popup appears below the anchor view if there is room, or above it if there is not. If the IME (soft keyboard) is visible, the popup does not overlap the IME it until the user touches the menu.

SearchView

Provides a search box that works in conjunction with the Search Manager (in the same manner as the traditional search dialog). It can also display recent query suggestions or custom suggestions as configured by the search provider. This widget is particularly useful for offering search in the Action Bar.

StackView

A view that displays its children in a 3D stack and allows users to swipe through views like a rolodex.

GraphicsHardware accelerated 2D graphics

You can now enable the OpenGL renderer for your application by setting android:hardwareAccelerated="true" in your manifest element's element or for individual elements.

This flag helps applications by making them draw faster. This results in smoother animations, smoother scrolling, and overall better performance and response to user interaction.

View support for hardware and software layers

By default, a View has no layer specified. You can specify that the view be backed by either a hardware or software layer, specified by values LAYER_TYPE_HARDWARE and LAYER_TYPE_SOFTWARE, using setLayerType() or the layerType attribute.

A hardware layer is backed by a hardware specific texture (generally Frame Buffer Objects or FBO on OpenGL hardware) and causes the view to be rendered using Android's hardware rendering pipeline, but only if hardware acceleration is turned on for the view hierarchy. When hardware acceleration is turned off, hardware layers behave exactly as software layers.

A software layer is backed by a bitmap and causes the view to be rendered using Android's software rendering pipeline, even if hardware acceleration is enabled. Software layers should be avoided when the affected view tree updates often. Every update will require to re-render the software layer, which can potentially be slow.

For more information, see the LAYER_TYPE_HARDWARE and LAYER_TYPE_SOFTWARE documentation.

.................


阅读(2297) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~