Groovy Gradle’s build scripts are written in Groovy, not XML. But unlike other approaches this is not for simply exposing the raw scripting power of a dynamic language. That would just lead to a very difficult to maintain build. The whole design of Gradle is oriented towards being used as a language, not as a rigid framework. And Groovy is our glue that allows you to tell your individual story with the abstractions Gradle (or you) provide. Gradle provides some standard stories but they are not privileged in any form. This is for us a major distinguishing feature compared to other declarative build systems. Our Groovy support is not just sugar coating. The whole Gradle API is fully Groovy-ized. Adding Groovy results in an enjoyable and productive experience.
This class represents a popup window that can be used to display an arbitrary view. The popup window is a floating container that appears on top of the current activity.
Base class for a remotable object, the core part of a lightweight remote procedure call mechanism defined by IBinder. This class is an implementation of IBinder that provides standard local implementation of such an object.
Most developers will not implement this class directly, instead using the aidl tool to describe the desired interface, having it generate the appropriate Binder subclass. You can, however, derive directly from Binder to implement your own custom RPC protocol or simply instantiate a raw Binder object directly to use as a token that can be shared across processes.
This class is just a basic IPC primitive; it has no impact on an application’s lifecycle, and is valid only as long as the process that created it continues to run. To use this correctly, you must be doing so within the context of a top-level application component (a Service, Activity, or ContentProvider) that lets the system know your process should remain running.
You must keep in mind the situations in which your process could go away, and thus require that you later re-create a new Binder and re-attach it when the process starts again. For example, if you are using this within an Activity, your activity’s process may be killed any time the activity is not started; if the activity is later re-created you will need to create a new Binder and hand it back to the correct place again; you need to be aware that your process may be started for another reason (for example to receive a broadcast) that will not involve re-creating the activity and thus run its code to create a new Binder.
Base interface for a remotable object, the core part of a lightweight remote procedure call mechanism designed for high performance when performing in-process and cross-process calls. This interface describes the abstract protocol for interacting with a remotable object. Do not implement this interface directly, instead extend from Binder.
The key IBinder API is transact() matched by Binder.onTransact(). These methods allow you to send a call to an IBinder object and receive a call coming in to a Binder object, respectively. This transaction API is synchronous, such that a call to transact() does not return until the target has returned from Binder.onTransact(); this is the expected behavior when calling an object that exists in the local process, and the underlying inter-process communication (IPC) mechanism ensures that these same semantics apply when going across processes.
The data sent through transact() is a Parcel, a generic buffer of data that also maintains some meta-data about its contents. The meta data is used to manage IBinder object references in the buffer, so that those references can be maintained as the buffer moves across processes. This mechanism ensures that when an IBinder is written into a Parcel and sent to another process, if that other process sends a reference to that same IBinder back to the original process, then the original process will receive the same IBinder object back. These semantics allow IBinder/Binder objects to be used as a unique identity (to serve as a token or for other purposes) that can be managed across processes.
The system maintains a pool of transaction threads in each process that it runs in. These threads are used to dispatch all IPCs coming in from other processes. For example, when an IPC is made from process A to process B, the calling thread in A blocks in transact() as it sends the transaction to process B. The next available pool thread in B receives the incoming transaction, calls Binder.onTransact() on the target object, and replies with the result Parcel. Upon receiving its result, the thread in process A returns to allow its execution to continue. In effect, other processes appear to use as additional threads that you did not create executing in your own process.
The Binder system also supports recursion across processes. For example if process A performs a transaction to process B, and process B while handling that transaction calls transact() on an IBinder that is implemented in A, then the thread in A that is currently waiting for the original transaction to finish will take care of calling Binder.onTransact() on the object being called by B. This ensures that the recursion semantics when calling remote binder object are the same as when calling local objects.
When working with remote objects, you often want to find out when they are no longer valid. There are three ways this can be determined:
The transact() method will throw a RemoteException exception if you try to call it on an IBinder whose process no longer exists.
The pingBinder() method can be called, and will return false if the remote process no longer exists.
The linkToDeath() method can be used to register a IBinder.DeathRecipient with the IBinder, which will be called when its containing process goes away.
/** * Use with {@link #getSystemService} to retrieve a * {@link android.os.PowerManager} for controlling power management, * including "wake locks," which let you keep the device on while * you're running long tasks. */ public static final String POWER_SERVICE = "power";
/** * Use with {@link #getSystemService} to retrieve a * {@link android.os.RecoverySystem} for accessing the recovery system * service. * *@see #getSystemService *@hide */ public static final String RECOVERY_SERVICE = "recovery";
/** * Use with {@link #getSystemService} to retrieve a * {@link android.view.WindowManager} for accessing the system's window * manager. * *@see #getSystemService *@see android.view.WindowManager */ public static final String WINDOW_SERVICE = "window";
/** * Use with {@link #getSystemService} to retrieve a * {@link android.view.LayoutInflater} for inflating layout resources in this * context. * *@see #getSystemService *@see android.view.LayoutInflater */ public static final String LAYOUT_INFLATER_SERVICE = "layout_inflater";
/** * Use with {@link #getSystemService} to retrieve a * {@link android.accounts.AccountManager} for receiving intents at a * time of your choosing. * *@see #getSystemService *@see android.accounts.AccountManager */ public static final String ACCOUNT_SERVICE = "account";
/** * Use with {@link #getSystemService} to retrieve a * {@link android.app.ActivityManager} for interacting with the global * system state. * *@see #getSystemService *@see android.app.ActivityManager */ public static final String ACTIVITY_SERVICE = "activity";
/** * Use with {@link #getSystemService} to retrieve a * {@link android.app.AlarmManager} for receiving intents at a * time of your choosing. * *@see #getSystemService *@see android.app.AlarmManager */ public static final String ALARM_SERVICE = "alarm";
/** * Use with {@link #getSystemService} to retrieve a * {@link android.app.NotificationManager} for informing the user of * background events. * *@see #getSystemService *@see android.app.NotificationManager */ public static final String NOTIFICATION_SERVICE = "notification";
/** * Use with {@link #getSystemService} to retrieve a * {@link android.view.accessibility.AccessibilityManager} for giving the user * feedback for UI events through the registered event listeners. * *@see #getSystemService *@see android.view.accessibility.AccessibilityManager */ public static final String ACCESSIBILITY_SERVICE = "accessibility";
/** * Use with {@link #getSystemService} to retrieve a * {@link android.view.accessibility.CaptioningManager} for obtaining * captioning properties and listening for changes in captioning * preferences. * *@see #getSystemService *@see android.view.accessibility.CaptioningManager */ public static final String CAPTIONING_SERVICE = "captioning";
/** * Use with {@link #getSystemService} to retrieve a * {@link android.app.NotificationManager} for controlling keyguard. * *@see #getSystemService *@see android.app.KeyguardManager */ public static final String KEYGUARD_SERVICE = "keyguard";
/** * Use with {@link #getSystemService} to retrieve a {@link * android.location.LocationManager} for controlling location * updates. * *@see #getSystemService *@see android.location.LocationManager */ public static final String LOCATION_SERVICE = "location";
/** * Use with {@link #getSystemService} to retrieve a * {@link android.location.CountryDetector} for detecting the country that * the user is in. * *@hide */ public static final String COUNTRY_DETECTOR = "country_detector";
/** * Use with {@link #getSystemService} to retrieve a {@link * android.app.SearchManager} for handling searches. * *@see #getSystemService *@see android.app.SearchManager */ public static final String SEARCH_SERVICE = "search";
/** * Use with {@link #getSystemService} to retrieve a {@link * android.hardware.SensorManager} for accessing sensors. * *@see #getSystemService *@see android.hardware.SensorManager */ public static final String SENSOR_SERVICE = "sensor";
/** * Use with {@link #getSystemService} to retrieve a {@link * android.os.storage.StorageManager} for accessing system storage * functions. * *@see #getSystemService *@see android.os.storage.StorageManager */ public static final String STORAGE_SERVICE = "storage";
/** * Use with {@link #getSystemService} to retrieve a * com.android.server.WallpaperService for accessing wallpapers. * *@see #getSystemService */ public static final String WALLPAPER_SERVICE = "wallpaper";
/** * Use with {@link #getSystemService} to retrieve a {@link * android.os.Vibrator} for interacting with the vibration hardware. * *@see #getSystemService *@see android.os.Vibrator */ public static final String VIBRATOR_SERVICE = "vibrator";
/** * Use with {@link #getSystemService} to retrieve a {@link * android.app.StatusBarManager} for interacting with the status bar. * *@see #getSystemService *@see android.app.StatusBarManager *@hide */ public static final String STATUS_BAR_SERVICE = "statusbar";
/** * Use with {@link #getSystemService} to retrieve a {@link * android.net.ConnectivityManager} for handling management of * network connections. * *@see #getSystemService *@see android.net.ConnectivityManager */ public static final String CONNECTIVITY_SERVICE = "connectivity";
/** * Use with {@link #getSystemService} to retrieve a {@link * android.os.IUpdateLock} for managing runtime sequences that * must not be interrupted by headless OTA application or similar. * *@hide *@see #getSystemService *@see android.os.UpdateLock */ public static final String UPDATE_LOCK_SERVICE = "updatelock";
/** * Constant for the internal network management service, not really a Context service. *@hide */ public static final String NETWORKMANAGEMENT_SERVICE = "network_management";
/** * Use with {@link #getSystemService} to retrieve a {@link * android.app.usage.NetworkStatsManager} for querying network usage stats. * *@see #getSystemService *@see android.app.usage.NetworkStatsManager */ public static final String NETWORK_STATS_SERVICE = "netstats"; /** {@hide} */ public static final String NETWORK_POLICY_SERVICE = "netpolicy";
/** * Use with {@link #getSystemService} to retrieve a {@link * android.net.wifi.WifiManager} for handling management of * Wi-Fi access. * *@see #getSystemService *@see android.net.wifi.WifiManager */ public static final String WIFI_SERVICE = "wifi";
/** * Use with {@link #getSystemService} to retrieve a {@link * android.net.wifi.p2p.WifiP2pManager} for handling management of * Wi-Fi peer-to-peer connections. * *@see #getSystemService *@see android.net.wifi.p2p.WifiP2pManager */ public static final String WIFI_P2P_SERVICE = "wifip2p";
/** * Use with {@link #getSystemService} to retrieve a * {@link android.net.wifi.nan.WifiNanManager} for handling management of * Wi-Fi NAN discovery and connections. * *@see #getSystemService *@see android.net.wifi.nan.WifiNanManager *@hide PROPOSED_NAN_API */ public static final String WIFI_NAN_SERVICE = "wifinan";
/** * Use with {@link #getSystemService} to retrieve a {@link * android.net.wifi.WifiScanner} for scanning the wifi universe * *@see #getSystemService *@see android.net.wifi.WifiScanner *@hide */ @SystemApi public static final String WIFI_SCANNING_SERVICE = "wifiscanner";
/** * Use with {@link #getSystemService} to retrieve a {@link * android.net.wifi.RttManager} for ranging devices with wifi * *@see #getSystemService *@see android.net.wifi.RttManager *@hide */ @SystemApi public static final String WIFI_RTT_SERVICE = "rttmanager";
/** * Use with {@link #getSystemService} to retrieve a {@link * android.net.EthernetManager} for handling management of * Ethernet access. * *@see #getSystemService *@see android.net.EthernetManager * *@hide */ public static final String ETHERNET_SERVICE = "ethernet";
/** * Use with {@link #getSystemService} to retrieve a {@link * android.net.nsd.NsdManager} for handling management of network service * discovery * *@see #getSystemService *@see android.net.nsd.NsdManager */ public static final String NSD_SERVICE = "servicediscovery";
/** * Use with {@link #getSystemService} to retrieve a * {@link android.media.AudioManager} for handling management of volume, * ringer modes and audio routing. * *@see #getSystemService *@see android.media.AudioManager */ public static final String AUDIO_SERVICE = "audio";
/** * Use with {@link #getSystemService} to retrieve a * {@link android.hardware.fingerprint.FingerprintManager} for handling management * of fingerprints. * *@see #getSystemService *@see android.hardware.fingerprint.FingerprintManager */ public static final String FINGERPRINT_SERVICE = "fingerprint";
/** * Use with {@link #getSystemService} to retrieve a * {@link android.media.MediaRouter} for controlling and managing * routing of media. * *@see #getSystemService *@see android.media.MediaRouter */ public static final String MEDIA_ROUTER_SERVICE = "media_router";
/** * Use with {@link #getSystemService} to retrieve a * {@link android.media.session.MediaSessionManager} for managing media Sessions. * *@see #getSystemService *@see android.media.session.MediaSessionManager */ public static final String MEDIA_SESSION_SERVICE = "media_session";
/** * Use with {@link #getSystemService} to retrieve a * {@link android.telephony.TelephonyManager} for handling management the * telephony features of the device. * *@see #getSystemService *@see android.telephony.TelephonyManager */ public static final String TELEPHONY_SERVICE = "phone";
/** * Use with {@link #getSystemService} to retrieve a * {@link android.telephony.SubscriptionManager} for handling management the * telephony subscriptions of the device. * *@see #getSystemService *@see android.telephony.SubscriptionManager */ public static final String TELEPHONY_SUBSCRIPTION_SERVICE = "telephony_subscription_service";
/** * Use with {@link #getSystemService} to retrieve a * {@link android.telecom.TelecomManager} to manage telecom-related features * of the device. * *@see #getSystemService *@see android.telecom.TelecomManager */ public static final String TELECOM_SERVICE = "telecom";
/** * Use with {@link #getSystemService} to retrieve a * {@link android.telephony.CarrierConfigManager} for reading carrier configuration values. * *@see #getSystemService *@see android.telephony.CarrierConfigManager */ public static final String CARRIER_CONFIG_SERVICE = "carrier_config";
/** * Use with {@link #getSystemService} to retrieve a * {@link android.text.ClipboardManager} for accessing and modifying * {@link android.content.ClipboardManager} for accessing and modifying * the contents of the global clipboard. * *@see #getSystemService *@see android.content.ClipboardManager */ public static final String CLIPBOARD_SERVICE = "clipboard";
/** * Use with {@link #getSystemService} to retrieve a * {@link android.view.inputmethod.InputMethodManager} for accessing input * methods. * *@see #getSystemService */ public static final String INPUT_METHOD_SERVICE = "input_method";
/** * Use with {@link #getSystemService} to retrieve a * {@link android.view.textservice.TextServicesManager} for accessing * text services. * *@see #getSystemService */ public static final String TEXT_SERVICES_MANAGER_SERVICE = "textservices";
/** * Use with {@link #getSystemService} to retrieve a * {@link android.appwidget.AppWidgetManager} for accessing AppWidgets. * *@see #getSystemService */ public static final String APPWIDGET_SERVICE = "appwidget";
/** * Official published name of the (internal) voice interaction manager service. * *@hide *@see #getSystemService */ public static final String VOICE_INTERACTION_MANAGER_SERVICE = "voiceinteraction";
/** * Use with {@link #getSystemService} to access the * {@link com.android.server.voiceinteraction.SoundTriggerService}. * *@hide *@see #getSystemService */ public static final String SOUND_TRIGGER_SERVICE = "soundtrigger";
/** * Use with {@link #getSystemService} to retrieve an * {@link android.app.backup.IBackupManager IBackupManager} for communicating * with the backup mechanism. *@hide * *@see #getSystemService */ @SystemApi public static final String BACKUP_SERVICE = "backup";
/** * Use with {@link #getSystemService} to retrieve a * {@link android.os.DropBoxManager} instance for recording * diagnostic logs. *@see #getSystemService */ public static final String DROPBOX_SERVICE = "dropbox";
/** * System service name for the DeviceIdleController. There is no Java API for this. *@see #getSystemService *@hide */ public static final String DEVICE_IDLE_CONTROLLER = "deviceidle";
/** * Use with {@link #getSystemService} to retrieve a * {@link android.app.admin.DevicePolicyManager} for working with global * device policy management. * *@see #getSystemService */ public static final String DEVICE_POLICY_SERVICE = "device_policy";
/** * Use with {@link #getSystemService} to retrieve a * {@link android.app.UiModeManager} for controlling UI modes. * *@see #getSystemService */ public static final String UI_MODE_SERVICE = "uimode";
/** * Use with {@link #getSystemService} to retrieve a * {@link android.app.DownloadManager} for requesting HTTP downloads. * *@see #getSystemService */ public static final String DOWNLOAD_SERVICE = "download";
/** * Use with {@link #getSystemService} to retrieve a * {@link android.os.BatteryManager} for managing battery state. * *@see #getSystemService */ public static final String BATTERY_SERVICE = "batterymanager";
/** * Use with {@link #getSystemService} to retrieve a * {@link android.nfc.NfcManager} for using NFC. * *@see #getSystemService */ public static final String NFC_SERVICE = "nfc";
/** * Use with {@link #getSystemService} to retrieve a * {@link android.bluetooth.BluetoothManager} for using Bluetooth. * *@see #getSystemService */ public static final String BLUETOOTH_SERVICE = "bluetooth";
/** * Use with {@link #getSystemService} to retrieve a * {@link android.net.sip.SipManager} for accessing the SIP related service. * *@see #getSystemService */ /**@hide */ public static final String SIP_SERVICE = "sip";
/** * Use with {@link #getSystemService} to retrieve a {@link * android.hardware.usb.UsbManager} for access to USB devices (as a USB host) * and for controlling this device's behavior as a USB device. * *@see #getSystemService *@see android.hardware.usb.UsbManager */ public static final String USB_SERVICE = "usb";
/** * Use with {@link #getSystemService} to retrieve a {@link * android.hardware.SerialManager} for access to serial ports. * *@see #getSystemService *@see android.hardware.SerialManager * *@hide */ public static final String SERIAL_SERVICE = "serial";
/** * Use with {@link #getSystemService} to retrieve a * {@link android.hardware.hdmi.HdmiControlManager} for controlling and managing * HDMI-CEC protocol. * *@see #getSystemService *@see android.hardware.hdmi.HdmiControlManager *@hide */ @SystemApi public static final String HDMI_CONTROL_SERVICE = "hdmi_control";
/** * Use with {@link #getSystemService} to retrieve a * {@link android.hardware.input.InputManager} for interacting with input devices. * *@see #getSystemService *@see android.hardware.input.InputManager */ public static final String INPUT_SERVICE = "input";
/** * Use with {@link #getSystemService} to retrieve a * {@link android.hardware.display.DisplayManager} for interacting with display devices. * *@see #getSystemService *@see android.hardware.display.DisplayManager */ public static final String DISPLAY_SERVICE = "display";
/** * Use with {@link #getSystemService} to retrieve a * {@link android.os.UserManager} for managing users on devices that support multiple users. * *@see #getSystemService *@see android.os.UserManager */ public static final String USER_SERVICE = "user";
/** * Use with {@link #getSystemService} to retrieve a * {@link android.content.pm.LauncherApps} for querying and monitoring launchable apps across * profiles of a user. * *@see #getSystemService *@see android.content.pm.LauncherApps */ public static final String LAUNCHER_APPS_SERVICE = "launcherapps";
/** * Use with {@link #getSystemService} to retrieve a * {@link android.content.RestrictionsManager} for retrieving application restrictions * and requesting permissions for restricted operations. *@see #getSystemService *@see android.content.RestrictionsManager */ public static final String RESTRICTIONS_SERVICE = "restrictions";
/** * Use with {@link #getSystemService} to retrieve a * {@link android.app.AppOpsManager} for tracking application operations * on the device. * *@see #getSystemService *@see android.app.AppOpsManager */ public static final String APP_OPS_SERVICE = "appops";
/** * Use with {@link #getSystemService} to retrieve a * {@link android.hardware.camera2.CameraManager} for interacting with * camera devices. * *@see #getSystemService *@see android.hardware.camera2.CameraManager */ public static final String CAMERA_SERVICE = "camera";
/** * {@link android.print.PrintManager} for printing and managing * printers and print tasks. * *@see #getSystemService *@see android.print.PrintManager */ public static final String PRINT_SERVICE = "print";
/** * Use with {@link #getSystemService} to retrieve a * {@link android.hardware.ConsumerIrManager} for transmitting infrared * signals from the device. * *@see #getSystemService *@see android.hardware.ConsumerIrManager */ public static final String CONSUMER_IR_SERVICE = "consumer_ir";
/** * {@link android.app.trust.TrustManager} for managing trust agents. *@see #getSystemService *@see android.app.trust.TrustManager *@hide */ public static final String TRUST_SERVICE = "trust";
/** * Use with {@link #getSystemService} to retrieve a * {@link android.media.tv.TvInputManager} for interacting with TV inputs * on the device. * *@see #getSystemService *@see android.media.tv.TvInputManager */ public static final String TV_INPUT_SERVICE = "tv_input";
/** * {@link android.net.NetworkScoreManager} for managing network scoring. *@see #getSystemService *@see android.net.NetworkScoreManager *@hide */ @SystemApi public static final String NETWORK_SCORE_SERVICE = "network_score";
/** * Use with {@link #getSystemService} to retrieve a {@link * android.app.usage.UsageStatsManager} for querying device usage stats. * *@see #getSystemService *@see android.app.usage.UsageStatsManager */ public static final String USAGE_STATS_SERVICE = "usagestats";
/** * Use with {@link #getSystemService} to retrieve a {@link * android.app.job.JobScheduler} instance for managing occasional * background tasks. *@see #getSystemService *@see android.app.job.JobScheduler */ public static final String JOB_SCHEDULER_SERVICE = "jobscheduler";
/** * Use with {@link #getSystemService} to retrieve a {@link * android.service.persistentdata.PersistentDataBlockManager} instance * for interacting with a storage device that lives across factory resets. * *@see #getSystemService *@see android.service.persistentdata.PersistentDataBlockManager *@hide */ @SystemApi public static final String PERSISTENT_DATA_BLOCK_SERVICE = "persistent_data_block";
/** * Use with {@link #getSystemService} to retrieve a {@link * android.media.projection.MediaProjectionManager} instance for managing * media projection sessions. *@see #getSystemService *@see android.media.projection.MediaProjectionManager */ public static final String MEDIA_PROJECTION_SERVICE = "media_projection";
/** * Use with {@link #getSystemService} to retrieve a * {@link android.media.midi.MidiManager} for accessing the MIDI service. * *@see #getSystemService */ public static final String MIDI_SERVICE = "midi";
/** * Use with {@link #getSystemService} to retrieve a * {@link android.hardware.radio.RadioManager} for accessing the broadcast radio service. * *@see #getSystemService *@hide */ public static final String RADIO_SERVICE = "radio";
/** * Use with {@link #getSystemService} to retrieve a * {@link android.os.HardwarePropertiesManager} for accessing the hardware properties service. * *@see #getSystemService */ public static final String HARDWARE_PROPERTIES_SERVICE = "hardware_properties";
/** * TODO Javadoc * *@see #getSystemService *@see android.content.pm.ShortcutManager * *@hide */ public static final String SHORTCUT_SERVICE = "shortcut";
/** * Use with {@link #getSystemService} to retrieve a {@link * android.hardware.location.ContextHubManager} for accessing context hubs. * *@see #getSystemService *@see android.hardware.location.ContextHubManager * *@hide */ @SystemApi public static final String CONTEXTHUB_SERVICE = "contexthub";
/** * Use with {@link #getSystemService} to retrieve a * {@link android.os.health.SystemHealthManager} for accessing system health (battery, power, * memory, etc) metrics. * *@see #getSystemService */ public static final String SYSTEM_HEALTH_SERVICE = "systemhealth";
/** * Gatekeeper Service. *@hide */ public static final String GATEKEEPER_SERVICE = "android.service.gatekeeper.IGateKeeperService";
The property animation system is a robust framework that allows you to animate almost anything. You can define an animation to change any object property over time, regardless of whether it draws to the screen or not. A property animation changes a property’s (a field in an object) value over a specified length of time. To animate something, you specify the object property that you want to animate, such as an object’s position on the screen, how long you want to animate it for, and what values you want to animate between.
The property animation system lets you define the following characteristics of an animation:
Duration: You can specify the duration of an animation. The default length is 300 ms.
Time interpolation: You can specify how the values for the property are calculated as a function of the animation’s current elapsed time.
Repeat count and behavior: You can specify whether or not to have an animation repeat when it reaches the end of a duration and how many times to repeat the animation. You can also specify whether you want the animation to play back in reverse. Setting it to reverse plays the animation forwards then backwards repeatedly, until the number of repeats is reached.
Animator sets: You can group animations into logical sets that play together or sequentially or after specified delays.
Frame refresh delay: You can specify how often to refresh frames of your animation. The default is set to refresh every 10 ms, but the speed in which your application can refresh frames is ultimately dependent on how busy the system is overall and how fast the system can service the underlying timer.
属性动画系统允许你定义一下几种动画的特性。
Duration:你可以指定动画的具体间隔,默认情况下是300ms。
Time interpolation:你可以指定如何根据属性值的来计算当前动画的运行时间。
Repeat count and behavior:你可以指定当动画按照duration结束后是否让动画重复。你可以指定是否让动画从后向前播放。设置它来反向播放动画,先正常播放然后从后向前播放,重复这样的操作直到运行到指定次数。
First, let’s go over how an animation works with a simple example. Figure 1 depicts a hypothetical object that is animated with its x property, which represents its horizontal location on a screen. The duration of the animation is set to 40 ms and the distance to travel is 40 pixels. Every 10 ms, which is the default frame refresh rate, the object moves horizontally by 10 pixels. At the end of 40ms, the animation stops, and the object ends at horizontal position 40. This is an example of an animation with linear interpolation, meaning the object moves at a constant speed.
You can also specify animations to have a non-linear interpolation. Figure 2 illustrates a hypothetical object that accelerates at the beginning of the animation, and decelerates at the end of the animation. The object still moves 40 pixels in 40 ms, but non-linearly. In the beginning, this animation accelerates up to the halfway point then decelerates from the halfway point until the end of the animation. As Figure 2 shows, the distance traveled at the beginning and end of the animation is less than in the middle.
Let’s take a detailed look at how the important components of the property animation system would calculate animations like the ones illustrated above. Figure 3 depicts how the main classes work with one another.
Figure 3. How animations are calculated
现在来仔细看一看属性动画系统里的重要组件是怎样计算动画的,图片描述了它的主要的类相互工作的方式。
The ValueAnimator object keeps track of your animation’s timing, such as how long the animation has been running, and the current value of the property that it is animating.
The ValueAnimator encapsulates a TimeInterpolator, which defines animation interpolation, and a TypeEvaluator, which defines how to calculate values for the property being animated. For example, in Figure 2, the TimeInterpolator used would be AccelerateDecelerateInterpolator and the TypeEvaluator would be IntEvaluator.
To start an animation, create a ValueAnimator and give it the starting and ending values for the property that you want to animate, along with the duration of the animation. When you call start() the animation begins. During the whole animation, the ValueAnimator calculates an elapsed fraction between 0 and 1, based on the duration of the animation and how much time has elapsed. The elapsed fraction represents the percentage of time that the animation has completed, 0 meaning 0% and 1 meaning 100%. For example, in Figure 1, the elapsed fraction at t = 10 ms would be .25 because the total duration is t = 40 ms.
When the ValueAnimator is done calculating an elapsed fraction, it calls the TimeInterpolator that is currently set, to calculate an interpolated fraction. An interpolated fraction maps the elapsed fraction to a new fraction that takes into account the time interpolation that is set. For example, in Figure 2, because the animation slowly accelerates, the interpolated fraction, about .15, is less than the elapsed fraction, .25, at t = 10 ms. In Figure 1, the interpolated fraction is always the same as the elapsed fraction.
When the interpolated fraction is calculated, ValueAnimator calls the appropriate TypeEvaluator, to calculate the value of the property that you are animating, based on the interpolated fraction, the starting value, and the ending value of the animation. For example, in Figure 2, the interpolated fraction was .15 at t = 10 ms, so the value for the property at that time would be .15 X (40 - 0), or 6.
The com.example.android.apis.animation package in the API Demos sample project provides many examples on how to use the property animation system.