diff options
Diffstat (limited to 'docs/html/preview')
-rw-r--r-- | docs/html/preview/data-binding/guide.jd | 908 | ||||
-rw-r--r-- | docs/html/preview/index.html | 372 | ||||
-rw-r--r-- | docs/html/preview/index.jd | 44 | ||||
-rw-r--r-- | docs/html/preview/license.html | 274 |
4 files changed, 926 insertions, 672 deletions
diff --git a/docs/html/preview/data-binding/guide.jd b/docs/html/preview/data-binding/guide.jd new file mode 100644 index 0000000..49b690f --- /dev/null +++ b/docs/html/preview/data-binding/guide.jd @@ -0,0 +1,908 @@ +page.title=Data Binding Guide + +@jd:body +<p>Data Binding allows you write declarative layouts and minimize the glue code +that is necessary to bind your application logic and layouts.</p> + + +<h2 id=build_environment>Build Environment</h2> + + +<p><strong>Setting Up Work Environment:</strong></p> + +<p>Data Binding EAP only supports gradle.</p> + +<p>To set up your application, unzip the provided bundle to a location. It has 3 +sections</p> + +<ul> + <li> <em>maven-repo:</em> which keeps the data-binding libraries + <li> <em>samples:</em> Sample applications + <li> <em>databinding.properties:</em> Properties file that can be used to integrate with your app +</ul> + +<p>Add the following section to the project’s build.gradle file (not the module's +build.gradle) and replace <code><BUNDLE_FOLDER> </code>with the absolute path of the bundle that you’ve unzipped in the previous step.</p> + +<pre class=prettyprint> +buildscript { + <strong>def </strong>eapFolder = '<BUNDLE_FOLDER>' +<strong> def </strong>Properties props = <strong>new </strong>Properties() + props.load(<strong>new </strong>FileInputStream(<strong>"</strong>${eapFolder}<strong>/databinding.properties"</strong>)) + props.mavenRepoDir = <strong>"</strong>${eapFolder}<strong>/</strong>${props.mavenRepoName}<strong>" + </strong>ext.config = props + repositories { + jcenter() + maven { + url config.mavenRepoDir + } + } + dependencies { + classpath <strong>"com.android.tools.build:gradle:1.1.3" + </strong>classpath <strong>"com.android.databinding:dataBinder:</strong>${config.snapshotVersion}<strong>" +<em></strong> </em>} +} +allprojects { + repositories { + jcenter() + maven { + url config.mavenRepoDir + } + } +} +</pre> + +<p>Next, add the following lines to the <em>build.gradle</em> +file of each module that will use data-binding. The application module must +have this, even if only its libraries use data binding.</p> + +<pre class=prettyprint> +apply plugin: <strong>'com.android.databinding' +</strong>dependencies { + compile <strong>"com.android.databinding:library:</strong>${config.snapshotVersion}<strong>" +</strong> compile <strong>"com.android.databinding:baseLibrary:</strong>${config.snapshotVersion}<strong>" +</strong> compile <strong>"com.android.databinding:adapters:</strong>${config.snapshotVersion}<strong>" +</strong> provided <strong>"com.android.databinding:annotationprocessor:</strong>${config.snapshotVersion}<strong>" +</strong>} +</pre> + + +<h2 id="data_binding_layout_files">Data Binding Layout Files</h2> + + +<h3 id="writing_expressions">Writing your first data binding expressions:</h3> + +<p>Data-binding layout files are slightly different and start with a root tag of +<strong>layout</strong> followed by a <strong>data</strong> element and a +<strong>view</strong> root element. This view element is what your root would +be in a non-binding layout file.A sample file looks like this:</p> + +<pre class=prettyprint> +<em><?<strong></em>xml version="1.0" encoding="utf-8"<em></strong>?> +</em><<strong>layout xmlns:android="http://schemas.android.com/apk/res/android"</strong>> + <<strong>data</strong>> + <<strong>variable name="user" type="com.example.User"</strong>/> + </<strong>data</strong>> + <<strong>LinearLayout + android:orientation="vertical" + android:layout_width="match_parent" + android:layout_height="match_parent"</strong>> + <<strong>TextView android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:text="@{user.firstName}"</strong>/> + <<strong>TextView android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:text="@{user.lastName}"</strong>/> + </<strong>LinearLayout</strong>> +</<strong>layout</strong>> +</pre> + +<p>The user <strong>variable</strong> within <strong>data</strong> describes a property that may be used within this layout.</p> + +<pre class=prettyprint> +<<strong>variable name="user" type="com.example.User"</strong>/> +</pre> + +<p>Expressions within the layout are written in the attribute properties using the +“<code>@{}</code>” syntax. Here, the TextView’s text is set to the firstName property of user:</p> +<pre class=prettyprint> +<<strong>TextView android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:text="@{user.firstName}"</strong>/> +</pre> + + +<h3 id="data_object">Data Object</h3> + +<p>Let’s assume for now that you have a plain-old Java object (POJO) for User:</p> +<pre class=prettyprint> +<strong>public class </strong>User { + <strong>public final </strong>String <strong>firstName</strong>; + <strong>public final </strong>String <strong>lastName</strong>; + <strong>public </strong>User(String firstName, String lastName) { + <strong>this</strong>.<strong>firstName </strong>= firstName; + <strong>this</strong>.<strong>lastName </strong>= lastName; + } +} +</pre> + +<p>This type of object has data that never changes. It is common in applications +to have data that is read once and never changes thereafter. It is also +possible to use a JavaBeans objects:</p> +<pre class=prettyprint> +<strong>public class </strong>User { + <strong>private final </strong>String <strong>firstName</strong>; + <strong>private final </strong>String <strong>lastName</strong>; + <strong>public </strong>User(String firstName, String lastName) { + <strong>this</strong>.<strong>firstName </strong>= firstName; + <strong>this</strong>.<strong>lastName </strong>= lastName; + } + <strong>public </strong>String getFirstName() { + <strong>return this</strong>.<strong>firstName</strong>; + } + <strong>public </strong>String getLastName() { + <strong>return this</strong>.<strong>lastName</strong>; + } +} +</pre> + +<p>From the perspective of data binding, these two classes are equivalent. The +expression <strong><code>@{user.lastName}</code></strong> used for the TextView’s <strong><code>android:text</code></strong> attribute will access the <strong><code>firstName</code></strong> field in the former class and the <code>getFirstName()</code> method in the latter class. +</p><h3 id=binding_data>Binding Data</h3> + +<p>By default, a Binding class will be generated based on the name of the layout +file, converting it to Pascal case and suffixing “Binding” to it. The above +layout file was <code>activity_main.xml</code> so the generate class was <code>ActivityMainBinding</code>. This class holds all the bindings from the layout properties (e.g. the <code>user</code> variable) to the layout’s Views and knows how to assign values for the binding +expressions.The easiest means for creating the bindings is to do it while inflating: +</p> + +<pre class=prettyprint> +@Override +<strong>protected void </strong>onCreate(Bundle savedInstanceState) { + <strong>super</strong>.onCreate(savedInstanceState); + ActivityMainBinding binding = DataBindingUtil.<em>setContentView</em>(<strong>this</strong>, R.layout.<em><strong>main_activity</strong></em>); + User user = <strong>new </strong>User(<strong>"Test"</strong>, <strong>"User"</strong>); + binding.setUser(user); +} +</pre> + +<p>You’re done! Run the application and you’ll see Test User in the UI.Alternatively, you can get the view via: +</p><pre class=prettyprint> +MainActivityBinding binding = MainActivityBinding.<em>inflate</em>(getLayoutInflater()); +</pre> + +<p>If you are using data binding items inside a ListView or RecyclerView adapter, +you may prefer to use: +</p><pre class=prettyprint> +ListItemBinding binding = ListItemBinding.inflate(layoutInflater, viewGroup, +false); +//or +ListItemBinding binding = DataBindingUtil.<em>inflate</em>(layoutInflater, R.layout.<em><strong>list_item</strong></em>, viewGroup, <strong>false</strong>); +</pre> + + +<h2 id=layout_details>Layout Details</h2> + + +<h3 id=imports>Imports</h3> + +<p>Zero or more <strong><code>import</code></strong> elements may be used inside the <strong><code>data</code></strong> element. These allow easy reference to classes inside your layout file, just +like in Java. +</p><pre class=prettyprint> +<<strong>data</strong>> + <<strong>import type="android.view.View"</strong>/> +</<strong>data</strong>> +</pre> + +<p>Now, View may be used within your binding expression: +</p><pre class=prettyprint> +<<strong>TextView + android:text="@{user.lastName}" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:visibility="@{user.isAdult ? View.VISIBLE : View.GONE}"</strong>/> +</pre> + +<p>When there are class name conflicts, one of the classes may be renamed to an +“alias:”</p> +<pre class=prettyprint> +<<strong>import type="android.view.View"</strong>/> +<<strong>import type="com.example.real.estate.View" + alias="Vista"</strong>/> +</pre> + +<p>Now, <strong><code>Vista</code></strong> may be used to reference the <code>com.example.real.estate.View</code> and <strong><code>View</code></strong> may be used to reference <code>android.view.View </code>within the layout file.Imported types may be used as type references in variables and expressions:</p> +<pre class=prettyprint> +<<strong>data</strong>> + <<strong>import type="com.example.User"</strong>/> + <<strong>import type="java.util.List"</strong>/> + <<strong>variable name="user" type="User"</strong>/> + <<strong>variable name="userList" type="List<User>"</strong>/> +</<strong>data</strong>> +… +<<strong>TextView + android:text="@{((User)(user.connection)).lastName}" + android:layout_width="wrap_content" + android:layout_height="wrap_content"</strong>/> +</pre> + +<p>Imported types may also be used when referencing static fields and methods in +expressions:</p> +<pre class=prettyprint> +<<strong>data</strong>> + <<strong>import type="com.example.MyStringUtils"</strong>/> + <<strong>variable name="user" type="com.example.User"</strong>/> +</<strong>data</strong>> +… +<<strong>TextView + android:text="@{MyStringUtils.capitalize(user.lastName)}" + android:layout_width="wrap_content" + android:layout_height="wrap_content"</strong>/> +</pre> + +<p>Just as in Java, <code>java.lang.*</code> is imported automatically.</p> +<h3 id=variables>Variables</h3> + +<p>Any number of <strong><code>variable</code></strong> elements may be used inside the <strong><code>data</code></strong> element. Each <strong><code>variable</code></strong> element describes a property that may be set on the layout to be used in +binding expressions within the layout file.</p> +<pre class=prettyprint> +<<strong>data</strong>> + <<strong>import type="android.graphics.drawable.Drawable"</strong>/> + <<strong>variable name="user" type="com.example.User"</strong>/> + <<strong>variable name="image" type="Drawable"</strong>/> + <<strong>variable name="note" type="String"</strong>/> +</<strong>data</strong>> +</pre> + +<p>The variable types are inspected at compile time, so if a variable implements <a href="#observable_objects">Observable</a>, <a href="#observable_collections">observable collection</a>, that should be reflected in the type. If the variable is a base class or + interface that does not implement the Observable* interface, the variables will <strong>not be</strong> observed!</p> + +<p>When there are different layout files for various configurations (e.g. +landscape or portrait), the variables will be combined. There must not be +conflicting variable definitions between these layout files.</p> + +<p>The generated binding class will have a setter and getter for each of the +described variables. The variables will take the default Java values until the +setter is called — <code>null</code> for reference types, <code>0</code> for <code>int</code>, <code>false</code> for <code>boolean</code>, etc.</p> + +<h3 id=custom_binding_class_names>Custom Binding Class Names</h3> + +<p>By default, a Binding class is generated based on the name of the layout file, +starting it with upper-case, removing underscores ( _ ) and capitalizing the +following letter and then suffixing “Binding”. This class will be placed in a +databinding package under the module package. For example, the layout file <code>contact_item.xml</code> will generate <code>ContactItemBinding</code>. If the module package is <code>com.example.my.app</code>, then it will be placed in <code>com.example.my.app.databinding</code>.</p> + +<p>Binding classes may be renamed or placed in different packages by adjusting the <strong><code>class</code></strong> attribute of the <strong><code>data</code></strong> element. For example:</p> +<pre class=prettyprint> +<<strong>data class="ContactItem"</strong>> + ... +</<strong>data</strong>> +</pre> + +<p>This generates the binding class as <code>ContactItem</code> in the databinding package in the module package. If the class should be +generated in a different package within the module package, it may be prefixed +with “.”:</p> +<pre class=prettyprint> +<<strong>data class=".ContactItem"</strong>> + ... +</<strong>data</strong>> +</pre> + +In this case, <code>ContactItem</code> is generated in the module package directly.Any package may be used if the full package is provided: +<pre class=prettyprint> +<<strong>data class="com.example.ContactItem"</strong>> + ... +</<strong>data</strong>> +</pre> + + +<h3 id=includes>Includes</h3> + +<p>Variables may be passed into an included layout's binding from the containing +layout by using the application namespace and the variable name in an +attribute:</p> +<pre class=prettyprint> +<em><?<strong></em>xml version="1.0" encoding="utf-8"<em></strong>?> +</em><<strong>layout xmlns:android="http://schemas.android.com/apk/res/android" +</strong> <strong> xmlns:bind="http://schemas.android.com/apk/res-auto"</strong>> + <<strong>data</strong>> + <<strong>variable name="user" type="com.example.User"</strong>/> + </<strong>data</strong>> + <<strong>LinearLayout + android:orientation="vertical" + android:layout_width="match_parent" + android:layout_height="match_parent"</strong>> + <<strong>include layout="@layout/name" + bind:user="@{user}"</strong>/> + <<strong>include layout="@layout/contact" + bind:user="@{user}"</strong>/> + </<strong>LinearLayout</strong>> +</<strong>layout</strong>> +</pre> + +<p>Here, there must be a <code>user</code> variable in both the <code>name.xml </code>and <code>contact.xml </code>layout files.</p> +<h3 id=expression_language>Expression Language</h3> + + +<h4 id=common_features>Common Features</h4> + +<p>The expression language looks a lot like a Java expression. These are the same:</p> +<ul> + <li> Mathematical <strong><code>+ - / * %</code></strong> + <li> String concatenation <strong><code>+</code></strong> + <li> <code>L</code>ogical <strong><code>&& ||</code></strong> + <li> Binary <strong><code>&</code> <code>|</code> <code>^</code></strong> + <li> Unary <strong><code>+ - ! ~</code></strong> + <li> Shift <strong><code>>> >>> <<</code></strong> + <li> Comparison <strong><code>== > < >= <=</code></strong> + <li> <strong><code>instanceof</code></strong> + <li> Grouping <strong><code>()</code></strong> + <li> Literals - character, String, numeric, <strong><code>null</code></strong> + <li> Cast + <li> Method calls + <li> Field access + <li> Array access <strong><code>[]</code></strong> + <li> Ternary operator <strong><code>?:</code></strong> +</ul> +<p>Examples:</p> +<pre class=prettyprint> +<strong>android:text="@{String.valueOf(index + 1)}" +android:visibility="@{age < 13 ? View.GONE : View.VISIBLE}" +android:transitionName='@{"image_" + id}'</strong> +</pre> + + +<h4 id=missing_operations>Missing Operations</h4> + +<p>A few operations are missing from the expression syntax that you can use in +Java.</p> +<ul> + <li> <strong><code>this</code></strong> + <li> <strong><code>super</code></strong> + <li> <strong><code>new</code></strong> + <li> Explicit generic invocation +</ul> + +<h4 id=null_coalescing_operator>Null Coalescing Operator</h4> + +<p>The null coalescing operator (<strong><code>??</code></strong>) chooses the left operand if it is not null or the right if it is null.</p> +<pre class=prettyprint> +<strong>android:text="@{user.displayName ?? user.lastName}"</strong> +</pre> + +<p>This is functionally equivalent to:</p> +<pre class=prettyprint> +<strong>android:text="@{user.displayName != null ? user.displayName : user.lastName}"</strong> +</pre> + + +<h4 id=property_reference>Property Reference</h4> + +<p>The first was already discussed in the <a href="#writing_your_first_data_binding_expressions">Writing your first data binding expressions</a> above: short form JavaBean references. When an expression references a +property on a class, it uses the same format for fields, getters, and +ObservableFields.</p> +<pre class=prettyprint> +<strong>android:text="@{user.lastName}"</strong> +</pre> + + +<h4 id=collections>Collections</h4> + +<p>Common collections: arrays, lists, sparse lists, and maps, may be accessed +using the <code>[]</code> operator for convenience.</p> +<pre class=prettyprint> +<<strong>data</strong>> + <<strong>import type="android.util.SparseArray"</strong>/> + <<strong>import type="java.util.Map"</strong>/> + <<strong>import type="java.util.List"</strong>/> + <<strong>variable name="list" type="List<String>"</strong>/> + <<strong>variable name="sparse" type="SparseArray<String>"</strong>/> + <<strong>variable name="map" type="Map<String, String>"</strong>/> + <<strong>variable name="index" type="int"</strong>/> + <<strong>variable name="key" type="String"</strong>/> +</<strong>data</strong>> +… +<strong>android:text="@{list[index]}" +</strong>… +<strong>android:text="@{sparse[index]}" +</strong>… +<strong>android:text="@{map[key]}" +</strong> +</pre> + + +<h4 id=string_literals>String Literals</h4> + +<p>When using single quotes around the attribute value, it is easy to use double +quotes in the expression:</p> +<pre class=prettyprint> +<strong>android:text='@{map["firstName"]}'</strong> +</pre> + +<p>It is also possible to use double quotes to surround the attribute value. When +doing so, String literals should either use the " or back quote (`).</p> +<pre class=prettyprint> +<strong>android:text="@{map[`firstName`}" +android:text="@{map["firstName"]}"</strong> +</pre> + + +<h4 id=resources>Resources</h4> + +<p>It is possible to access resources as part of expressions using the normal +syntax:</p> +<pre class=prettyprint> +<strong>android:padding="@{large? @dimen/largePadding : @dimen/smallPadding}"</strong> +</pre> + +<p>Format strings and plurals may be evaluated by providing parameters:</p> +<pre class=prettyprint> +<strong>android:text="@{@string/nameFormat(firstName, lastName)}" +android:text="@{@plurals/banana(bananaCount)}"</strong> +</pre> + +<p>Some resources require explicit type evaluation.</p> + +<table> + <tr> + <th>Type</th> + <th>Normal Reference</th> + <th>Expression Reference</th> + </tr> + <tr> + <td> +<pre class=prettyprint> +String[]</td> + <td> +@array</td> + <td> +@stringArray</td> + </tr> + <tr> + <td> +int[]</td> + <td> +@array</td> + <td> +@intArray</td> + </tr> + <tr> + <td> +TypedArray</td> + <td> +@array</td> + <td> +@typedArray</td> + </tr> + <tr> + <td> +Animator</td> + <td> +@animator</td> + <td> +@animator</td> + </tr> + <tr> + <td> +StateListAnimator</td> + <td> +@animator</td> + <td> +@stateListAnimator</td> + </tr> + <tr> + <td> +</pre> + +color <code>int</code></td> + <td> +<pre class=prettyprint> +@color</td> + <td> +@color</td> + </tr> + <tr> + <td> +ColorStateList</td> + <td> +@color</td> + <td> +@colorStateList</td> + </tr> +</table> + +</pre> + + +<h2 id="data_objects">Data Objects</h2> + + +<p>Any plain old Java object (POJO) may be used for data binding, but modifying a +POJO will not cause the UI to update. The real power of data binding can be +used by giving your data objects the ability to notify when data changes. There +are three different data change notification mechanisms, <code>Observable </code>objects, <code>ObservableField</code>s, and <code>observable collections</code>.</p> + +<p>When one of these observable data object is bound to the UI and a property of +the data object changes, the UI will be updated automatically.</p> + +<h3 id=observable_objects>Observable Objects</h3> + + +<p>A class implementing <code>android.databinding.Observable</code> interface will allow the binding to attach a single listener to a bound object +to listen for changes of all properties on that object.</p> + +<p>The <code>Observable</code> interface has a mechanism to add and remove listeners, but notifying is up to +the developer. To make development easier, a base class, <code>BaseObservable,</code> was created to implement the listener registration mechanism. The data class +implementer is still responsible for notifying when the properties change. This +is done by assigning an <code>Bindable </code>annotation to the getter and notifying in the setter.</p> + +<pre class=prettyprint> +<strong>private static class </strong>User <strong>extends </strong>BaseObservable { + <strong>private </strong>String <strong>firstName</strong>; + <strong>private </strong>String <strong>lastName</strong>; + @Bindable + <strong>public </strong>String getFirstName() { + <strong>return this</strong>.<strong>firstName</strong>; + } + @Bindable + <strong>public </strong>String getFirstName() { + <strong>return this</strong>.<strong>lastName</strong>; + } + <strong>public void </strong>setFirstName(String firstName) { + <strong>this</strong>.<strong>firstName </strong>= firstName; + notifyPropertyChanged(BR.firstName); + } + <strong>public void </strong>setLastName(String lastName) { + <strong>this</strong>.<strong>lastName </strong>= lastName; + notifyPropertyChanged(BR.lastName); + } +} +</pre> + +<p>The <code>Bindable </code>annotation generates an entry in the BR class file during compilation. The BR +class file will be generated in the module package.If the base class for data classes cannot be changed, the <code>Observable</code> interface may be implemented using the convenient <code>PropertyChangeRegistry</code> to store and notify listeners efficiently.</p> + +<h3 id=observablefields>ObservableFields</h3> + +<p>A little work is involved in creating Observable classes, so developers who +want to save time or have few properties may use ObservableFields. +ObservableFields are self-contained observable objects that have a single +field. There are versions for all primitive types and one for reference types. +To use, create a public final field in the data class:</p> +<pre class=prettyprint> +<strong>private static class </strong>User <strong>extends </strong>BaseObservable { + <strong>public final </strong>ObservableField<String> <strong>firstName </strong>= + <strong>new </strong>ObservableField<>(); + <strong>public final </strong>ObservableField<String> <strong>lastName </strong>= + <strong>new </strong>ObservableField<>(); + <strong>public final </strong>ObservableInt <strong>age </strong>= <strong>new </strong>ObservableInt(); +} +</pre> + +<p>That's it! To access the value, use the set and get accessor methods:</p> +<pre class=prettyprint> +user.<strong>firstName</strong>.set(<strong>"Google"</strong>); +<strong>int </strong>age = user.<strong>age</strong>.get(); +</pre> + + +<h3 id=observable_collections>Observable Collections</h3> + +<p>Some applications use more dynamic structures to hold data. Observable + collections allow keyed access to these data objects.ObservableArrayMap is useful when the key is a reference type, such as String.</p> + +<pre class=prettyprint> +ObservableArrayMap<String, Object> user = <strong>new </strong>ObservableArrayMap<>(); +user.put(<strong>"firstName"</strong>, <strong>"Google"</strong>); +user.put(<strong>"lastName"</strong>, <strong>"Inc."</strong>); +user.put(<strong>"age"</strong>, 17); +</pre> + +In the layout, the map may be accessed through the String keys: +<pre class=prettyprint> +<<strong>data</strong>> + <<strong>import type="android.databinding.ObservableMap"</strong>/> + <<strong>variable name="user" type="ObservableMap<String, Object>"</strong>/> +</<strong>data</strong>> +… +<<strong>TextView + android:text='@{user["lastName"]}' + android:layout_width="wrap_content" + android:layout_height="wrap_content"</strong>/> +<<strong>TextView + android:text='@{String.valueOf(1 + (Integer)user["age"])}' + android:layout_width="wrap_content" + android:layout_height="wrap_content"</strong>/> +</pre> + +<p>ObservableArrayList is useful when the key is an integer:</p> +<pre class=prettyprint> +ObservableArrayList<Object> user = <strong>new </strong>ObservableArrayList<>(); +user.add(<strong>"Google"</strong>); +user.add(<strong>"Inc."</strong>); +user.add(17); +</pre> + +<p>In the layout, the list may be accessed through the indices:</p> +<pre class=prettyprint> +<<strong>data</strong>> + <<strong>import type="android.databinding.ObservableList"</strong>/> + <<strong>import type="com.example.my.app.Fields"</strong>/> + <<strong>variable name="user" type="ObservableList<Object>"</strong>/> +</<strong>data</strong>> +… +<<strong>TextView + android:text='@{user[Fields.LAST_NAME]}' + android:layout_width="wrap_content" + android:layout_height="wrap_content"</strong>/> +<<strong>TextView + android:text='@{String.valueOf(1 + (Integer)user[Fields.AGE])}' + android:layout_width="wrap_content" + android:layout_height="wrap_content"</strong>/> +</pre> + + +<h2 id=generated_binding>Generated Binding</h2> + +<p>The generated binding class links the layout variables with the Views within +the layout. As discussed earlier, the name and package of the Binding may be <a href="#custom_binding_class_names">customized</a>. The Generated binding classes all extend <code>android.databinding.ViewDataBinding</code>.</p> +<h3 id=creating>Creating</h3> + +<p>The binding should be created soon after inflation to ensure that the View +hierarchy is not disturbed prior to binding to the Views with expressions +within the layout. There are a few ways to bind to a layout. The most common is +to use the static methods on the Binding class.The inflate method inflates the View hierarchy and binds to it all it one step. +There are versions that attach the View to its parent and that inflate without +attaching.</p> +<pre class=prettyprint> +MyLayoutBinding binding = MyLayoutBinding.<em>inflate</em>(<strong>this</strong>); +MyLayoutBinding binding = MyLayoutBinding.<em>inflate</em>(viewGroup); +</pre> + +<p>If the layout was inflated using a different mechanism, it may be bound +separately:</p> +<pre class=prettyprint> +MyLayoutBinding binding = MyLayoutBinding.<em>bind</em>(viewRoot); +</pre> + +<p>Sometimes the binding cannot be known in advance. In such cases, the binding +can be created using the DataBindingUtil class:</p> +<pre class=prettyprint> +ViewDataBinding binding = DataBindingUtil.<em>inflate</em>(context, layoutId, + parent, attachToParent); +ViewDataBinding binding = DataBindingUtil.<em>bindTo</em>(viewRoot, layoutId); +</pre> + + +<h3 id=views_with_ids>Views With IDs</h3> + +<p>A public final field will be generated for each View with an ID in the layout. +The binding does a single pass on the View hierarchy, extracting the Views with +IDs. This mechanism can be faster than calling findViewById for several Views. For example:</p> +<pre class=prettyprint> +<<strong>layout xmlns:android="http://schemas.android.com/apk/res/android"</strong>> + <<strong>data</strong>> + <<strong>variable name="user" type="com.example.User"</strong>/> + </<strong>data</strong>> + <<strong>LinearLayout + android:orientation="vertical" + android:layout_width="match_parent" + android:layout_height="match_parent"</strong>> + <<strong>TextView android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:text="@{user.firstName}" +</strong> <strong>android:id="@+id/firstName"</strong>/> + <<strong>TextView android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:text="@{user.lastName}"</strong> <strong>android:id="@+id/lastName"</strong>/> + </<strong>LinearLayout</strong>> +</<strong>layout</strong>> +</pre> + +Will generate a binding class with: +<pre class=prettyprint> +<strong>public final </strong>TextView <strong>firstName</strong>; +<strong>public final </strong>TextView <strong>lastName</strong>; +</pre> + +<p>IDs are not nearly as necessary as without data binding, but there are still +some instances where access to Views are still necessary from code.</p> +<h3 id=variables>Variables</h3> + +<p>Each variable will be given a accessor methods.</p> +<pre class=prettyprint> +<<strong>data</strong>> + <<strong>import type="android.graphics.drawable.Drawable"</strong>/> + <<strong>variable name="user" type="com.example.User"</strong>/> + <<strong>variable name="image" type="Drawable"</strong>/> + <<strong>variable name="note" type="String"</strong>/> +</<strong>data</strong>> +</pre> + +<p>will generate setters and getters in the binding:</p> +<pre class=prettyprint> +<strong>public abstract </strong>com.example.User getUser(); +<strong>public abstract void </strong>setUser(com.example.User user); +<strong>public abstract </strong>Drawable getImage(); +<strong>public abstract void </strong>setImage(Drawable image); +<strong>public abstract </strong>String getNote(); +<strong>public abstract void </strong>setNote(String note); +</pre> + + +<h3 id=viewstubs>ViewStubs</h3> + +<p>ViewStubs are a little different from normal Views. They start off invisible +and when they either are made visible or are explicitly told to inflate, they +replace themselves in the layout by inflating another layout.</p> + +<p>Because the ViewStub essentially disappears from the View hierarchy, the View +in the binding object must also disappear to allow collection. Because the +Views are final, a ViewStubProxy object takes the place of the ViewStub, giving +the developer access to the ViewStub when it exists and also access to the +inflated View hierarchy when the ViewStub has been inflated.</p> + +<p>When inflating another layout, a binding must be established for the new +layout. Therefore, the ViewStubProxy must listen to the ViewStub's +OnInflateListener and establish the binding at that time. Since only one can +exist, the ViewStubProxy allows the developer to set an OnInflateListener on it +that it will call after establishing the binding.</p> + +<h3 id=advanced_binding>Advanced Binding</h3> + + +<h4 id=dynamic_variables>Dynamic Variables</h4> + +<p>At times, the specific binding class won't be known. For example, a +RecyclerView Adapter operating against arbitrary layouts won't know the +specific binding class. It still must assign the binding value during the +onBindViewHolder.</p> + +<p>In this example, all layouts that the RecyclerView binds to have an "item" +variable. The BindingHolder has a getBinding method returning the <code>ViewDataBinding</code> base.</p> +<pre class=prettyprint> +<strong>public void </strong>onBindViewHolder(BindingHolder holder, <strong>int </strong>position) { + <strong>final </strong>T item = <strong>mItems</strong>.get(position); + holder.getBinding().setVariable(BR.item, item); + holder.getBinding().executePendingBindings(); +} +</pre> + + +<h4 id=immediate_binding>Immediate Binding</h4> + +<p>When a variable or observable changes, the binding will be scheduled to change +before the next frame. There are times, however, when binding must be executed +immediately. To force execution, use the executePendingBindings() method.</p> +<h2 id=attribute_setters>Attribute Setters</h2> + +<p>Whenever a bound value changes, the generated binding class must call a setter +method on the View with the binding expression. The data binding framework has +ways to customize which method to call to set the value.</p> +<h3 id=automatic_setters>Automatic Setters</h3> + +For an attribute, data binding tries to find the method setAttribute. The +namespace for the attribute does not matter, only the attribute name itself. + +<p>For example, an expression associated with TextView's attribute <strong><code>android:text</code></strong> will look for a setText(String). If the expression returns an int, data +binding will search for a setText(int) method. Be careful to have the +expression return the correct type, casting if necessary.Note that data binding will work even if no attribute exists with the given +name. You can then easily "create" attributes for any setter by using data +binding. For example, support DrawerLayout doesn't have any attributes, but +plenty of setters. You can use the automatic setters to use one of these.</p> +<pre class=prettyprint> +<android.support.v4.widget.<strong>DrawerLayout + android:layout_width="wrap_content" + android:layout_height="wrap_content" + app:scrimColor="@{@color/scrim}" + app:drawerListener="@{fragment.drawerListener}"/></strong> +</pre> + + +<h3 id=renamed_setters>Renamed Setters</h3> + +<p>Some attributes have setters that don't match by name. For these methods, an +attribute may be associated with the setter through BindingMethods annotation. +This must be associated with a class and contains BindingMethod annotations, +one for each renamed method. For example, the <strong><code>android:tint</code></strong> attribute is really associated with setImageTintList, not setTint.</p> +<pre class=prettyprint> +@BindingMethods({ + @BindingMethod(type = <strong>"android.widget.ImageView"</strong>, + attribute = <strong>"android:tint"</strong>, + method = <strong>"setImageTintList"</strong>), +}) +</pre> + +<p>It is unlikely that developers will need to rename setters; the android +framework attributes have already been implemented.</p> +<h3 id=custom_setters>Custom Setters</h3> + +<p>Some attributes need custom binding logic. For example, there is no associated +setter for the <strong><code>android:paddingLeft</code></strong> attribute. Instead, setPadding(left, top, right, bottom) exists. A static +binding adapter method with the BindingAdapter annotation allows the developer +to customize how a setter for an attribute is called.</p> + +<p>The android attributes have already had BindingAdapters created. For example, +here is the one for paddingLeft:</p> +<pre class=prettyprint></p> +@BindingAdapter(<strong>"android:paddingLeft"</strong>) +<strong>public static void </strong>setPaddingLeft(View view, <strong>int </strong>padding) { + view.setPadding(padding, + view.getPaddingTop(), + view.getPaddingRight(), + view.getPaddingBottom()); +} +</pre> + +<p>Binding adapters are useful for other types of customization. For example, a + custom loader can be called off-thread to load an image.</p> + +<p>Developer-created binding adapters will override the data binding default +adapters when there is a conflict.</p> + +<p>You can also have adapters that receive multiple parameters. </p> +<pre class=prettyprint> +@BindingAdapter(attributes = {<strong>"bind:imageUrl"</strong>, <strong>"bind:error"</strong>}) +<strong>public static void </strong>loadImage(ImageView view, String url, Drawable error) { + Picasso.<em>with</em>(view.getContext()).load(url).error(error).into(view); +} +</pre> + +<p>This adapter will be called if both <strong>imageUrl </strong>and <strong>error </strong>are used for an ImageView and <em>imageUrl </em>is a string and <em>error</em> is a drawable.</p> +<ul> + <li> Custom namespaces are ignore during matching. + <li> You can also write adapters for android namespace. +</ul> + +<pre class=prettyprint> +<ImageView app:imageUrl=“@{venue.imageUrl}” +app:error=“@{@drawable/venueError}”/> +</pre> + + +<h2 id=converters>Converters</h2> + + +<h3 id=object_conversions>Object Conversions</h3> + +<p>When an Object is returned from a binding expression, a setter will be chosen +from the automatic, renamed, and custom setters. The Object will be cast to a +parameter type of the chosen setter.</p><p>This is a convenience for those using ObservableMaps to hold data. for example:</p> +<pre class=prettyprint> +<<strong>TextView + android:text='@{userMap["lastName"]}' + android:layout_width="wrap_content" + android:layout_height="wrap_content"</strong>/> +</pre> + +<p>The userMap returns an Object and that Object will be automatically cast to +parameter type found in the setter <code>setText(CharSequence)</code>. When there may be confusion about the parameter type, the developer will need +to cast in the expression.</p> +<h3 id=custom_conversions>Custom Conversions</h3> + +<p>Sometimes conversions should be automatic between specific types. For example, +when setting the background:</p> +<pre class=prettyprint> +<<strong>View + android:background="@{isError ? @color/red : @color/white}" + android:layout_width="wrap_content" + android:layout_height="wrap_content"</strong>/> +</pre> + +<p>Here, the background takes a <code>Drawable</code>, but the color is an integer. Whenever a <code>Drawable</code> is expected and an integer is returned, the <code>int</code> should be converted to a <code>ColorDrawable</code>. This conversion is done using a static method with a BindingConversion +annotation:</p> +<pre class=prettyprint> +@BindingConversion +<strong>public static </strong>ColorDrawable convertColorToDrawable(<strong>int </strong>color) { + <strong>return new </strong>ColorDrawable(color); +} +</pre> + +<p>Note that conversions only happen at the setter level, so it is <strong>not allowed </strong>to mix types like this:</p> +<pre class=prettyprint> +<<strong>View + android:background="@{isError ? @drawable/error : @color/white}" + android:layout_width="wrap_content" + android:layout_height="wrap_content"</strong>/> +</pre> + diff --git a/docs/html/preview/index.html b/docs/html/preview/index.html deleted file mode 100644 index af99e2d..0000000 --- a/docs/html/preview/index.html +++ /dev/null @@ -1,372 +0,0 @@ -<!DOCTYPE html> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -<html> -<head> - - -<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> -<meta name="viewport" content="width=970" /> - -<meta name="Description" content="Test and build your apps against the next version of Android to ensure they're ready when the platform officially launches."> -<link rel="shortcut icon" type="image/x-icon" href="/favicon.ico" /> -<title>Android M Developer Preview | Android Developers</title> - -<!-- STYLESHEETS --> -<link rel="stylesheet" -href="//fonts.googleapis.com/css?family=Roboto+Condensed"> -<link rel="stylesheet" href="//fonts.googleapis.com/css?family=Roboto:light,regular,medium,thin,italic,mediumitalic,bold" - title="roboto"> -<link href="/assets/css/default.css" rel="stylesheet" type="text/css"> - - - -<!-- JAVASCRIPT --> -<script src="//www.google.com/jsapi" type="text/javascript"></script> -<script src="/assets/js/android_3p-bundle.js" type="text/javascript"></script> -<script type="text/javascript"> - var toRoot = "/"; - var metaTags = []; - var devsite = false; -</script> -<script src="/assets/js/docs.js" type="text/javascript"></script> - -<script> - (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){ - (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o), - m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m) - })(window,document,'script','//www.google-analytics.com/analytics.js','ga'); - - ga('create', 'UA-5831155-1', 'android.com'); - ga('create', 'UA-49880327-2', 'android.com', {'name': 'universal'}); // New tracker); - ga('send', 'pageview'); - ga('universal.send', 'pageview'); // Send page view for new tracker. -</script> - -</head> - -<body class="gc-documentation - -" itemscope itemtype="http://schema.org/Article"> - - -<a name="top"></a> -<div id="body-content"> -<div class="fullpage" > -<div id="jd-content"> - <div class="jd-descr" itemprop="articleBody"> - <style> -.fullpage>#footer, -#jd-content>.content-footer.wrap { - display:none; -} -</style> - -<style> -#footer { - display: none; -} -.content-footer { - display: none; -} -</style> - -<!-- -<div style="height:20px"></div> -<div id="butterbar-wrapper"> - <div id="butterbar"> - <a href="#" id="butterbar-message"> - butterbar message - </a> - </div> -</div> ---> - - <div class="landing-rest-of-page"> - <div class="landing-section" style="padding-top:60px"> - <div class="wrap"> - <div class="landing-section-header"> - <div class="landing-h1">Android M Developer Preview</div> - <div class="landing-subhead"> - Get an early look at the next release and prepare your apps for the - official platform launch. - </div> - - <img src="/preview/images/dev-prev.png" style=" margin:0px 0 0 40px" width="860px"/> - <div class="col-6" style="margin-left:660px; margin-top:-105px"> - <a href="/preview/setup-sdk.html" class="landing-button landing-primary" - style="position:absolute;z-index:100;float:right;margin-top: 0px;"> - Get Started</a> - </div> - </div> - </div> <!-- end .wrap --> - </div> <!-- end .landing-section --> - - - - <div class="landing-section landing-gray-background" - style="margin-top:-105px; padding-bottom:20px"> - <div class="wrap"> - <div class="cols"> - <div class="landing-body" style="margin-top:-80px" > - - <div class="landing-breakout cols"> - <div class="col-4"> - <p>This Feature</p> - <p class="landing-small"> - Kevin ham hock pig cupim brisket picanha, doner pork tri-tip frankfurter - leberkas turkey. - </p> - <p class="landing-small"> - <a href="/preview/api-overview.html">Learn about this feature</a> - </p> - </div> - <div class="col-4"> - <p>That Feature</p> - <p class="landing-small"> - Bacon ipsum dolor amet meatball tongue pork loin fatback, andouille shoulder - chicken picanha pig landjaeger kielbasa shankle pastrami flank meatloaf. - </p> - <p class="landing-small"> - <a href="/preview/api-overview.html">Learn about that feature</a> - </p> - </div> - <div class="col-4"> - <p style="width:230px">Another Feature</p> - <p class="landing-small"> - Landjaeger tri-tip tenderloin pork loin jowl, meatloaf t-bone kielbasa sausage - swine spare ribs drumstick corned beef ham. - </p> - <p class="landing-small"> - <a href="/preview/api-overview.html">Learn about notifications</a> - </p> - </div> - <div class="col-4"> - <p>Moar Features</p> - <p class="landing-small"> - <b>Feature Name</b> is our effort to meatloaf boudin meatball sausage strip - steak hamburger, chuck ham pork chop. - </p> - <p class="landing-small"> - <a href="/preview/api-overview.html">Learn about moar feature</a> - </p> - </div> - </div> - <p style="margin-left:20px">See the <a href="/preview/api-overview.html">API - overview</a> for more information on the rest of the new and updated features.</p> - </div> - </div></div></div> - <div class="landing-section"> - <div class="wrap"> - <div class="cols"> - <div class="landing-body"> - <div class="col-3-wide"> - <a target="_blank" href="https://code.google.com/p/android-developer-preview/"> - <img class="landing-social-image" src="/preview/images/bugs.png" alt=""> - </a> - <div class="landing-social-copy"> - <p>Issue Tracker</p> - <p class="landing-small"> - Let us know when you encounter problems, so we can fix them and make - the platform better for you and your users. - </p><p class="landing-small"> - <a href="https://code.google.com/p/android-developer-preview/"> - Report Issues</a> - </p> - <p></p> - </div> - </div> - <div class="col-3-wide"> - <a target="_blank" href="http://g.co/androidldevpreview"> - <img class="landing-social-image" src="//www.google.com/images/icons/product/gplus-128.png" alt=""> - </a> - <div class="landing-social-copy"> - <p>Google+ </p> - <p class="landing-small"> - Join the community of Android developers testing out the M Developer Preview and - share your thoughts and experiences. - </p><p class="landing-small"> - <a href="http://g.co/androidldevpreview"> - Discuss on Google+</a> - </p> - </div> - </div> - <div class="col-3-wide"> - <a target="_blank" href="/preview/support.html"> - <img class="landing-social-image" src="/preview/images/updates.png" alt=""> - </a> - <div class="landing-social-copy"> - <p>Support and Updates</p> - <p class="landing-small"> - Updates to the preview are delivered - in the Android SDK Manager. Check back periodically - for news about the changes. - </p> - <p class="landing-small"> - <a href="/preview/support.html">Get Support</a> - </p> - </div> - </div> - </div> - </div> - </div> - </div> - - <div class="content-footer wrap" itemscope="" itemtype="http://schema.org/SiteNavigationElement"> - <div class="layout-content-col col-16" style="padding-top:4px"> - <style>#___plusone_0 {float:right !important;}</style> - <div class="g-plusone" data-size="medium"></div> - </div> - </div> - <div id="footer" class="wrap" style="width:940px;position:relative;top:-35px;z-index:-1"> - <div id="copyright"> - Except as noted, this content is - licensed under <a href="http://creativecommons.org/licenses/by/2.5/"> - Creative Commons Attribution 2.5</a>. For details and - restrictions, see the <a href="/license.html">Content - License</a>. - </div> - </div> - </div> <!-- end landing-body-content --> - - <script> - $("a.landing-down-arrow").on("click", function(e) { - $("body").animate({ - scrollTop: $(".preview-hero").height() + 76 - }, 1000, "easeOutQuint"); - e.preventDefault(); - }); - </script> - </div> - - <div class="content-footer wrap" - itemscope itemtype="http://schema.org/SiteNavigationElement"> - - <div class="paging-links layout-content-col col-10"> - - </div> - <div class="layout-content-col plus-container col-2" > - <style>#___plusone_0 {float:right !important;}</style> - <div class="g-plusone" data-size="medium"></div> - - </div> - - </div> - - - - - </div> <!-- end jd-content --> - -<div id="footer" class="wrap" style="width:940px"> - - - <div id="copyright"> - - Except as noted, this content is - licensed under <a href="http://creativecommons.org/licenses/by/2.5/"> - Creative Commons Attribution 2.5</a>. For details and - restrictions, see the <a href="/license.html">Content - License</a>. - </div> - - -</div> <!-- end footer --> -</div><!-- end doc-content --> - -</div> <!-- end body-content --> - - - - - - <script src="https://developer.android.com/ytblogger_lists_unified.js" type="text/javascript"></script> - <script src="/jd_lists_unified.js" type="text/javascript"></script> - <script src="/jd_extras.js" type="text/javascript"></script> - <script src="/jd_collections.js" type="text/javascript"></script> - <script src="/jd_tag_helpers.js" type="text/javascript"></script> - -</body> -</html> diff --git a/docs/html/preview/index.jd b/docs/html/preview/index.jd index a2d0b18..c6c2068 100644 --- a/docs/html/preview/index.jd +++ b/docs/html/preview/index.jd @@ -17,44 +17,36 @@ footer.hide=1 <div class="col-1of2 col-pull-1of2"> <h1 class="dac-hero-title">M Developer Preview</h1> <p class="dac-hero-description"> - Get ready for the next official release of the platform. Test your apps - and give us feedback! + Get ready for the next official release of the platform. The preview program gives + you an advance look at new APIs, features, and behaviors coming to Android. + Test your apps and give us feedback! </p> - <a class="dac-hero-cta" href="{@docRoot}preview/setup-sdk.html"> + + <a class="dac-hero-cta" href="{@docRoot}preview/overview.html"> <span class="dac-sprite dac-auto-chevron"></span> - Set up the Preview SDK + Preview Program Overview </a><br> <a class="dac-hero-cta" href="{@docRoot}preview/api-overview.html"> <span class="dac-sprite dac-auto-chevron"></span> Review the API changes </a><br> + <a class="dac-hero-cta" href="{@docRoot}preview/setup-sdk.html"> + <span class="dac-sprite dac-auto-chevron"></span> + Set up the Preview SDK + </a><br> <a class="dac-hero-cta" href="https://code.google.com/p/android-developer-preview/"> <span class="dac-sprite dac-auto-chevron"></span> Report issues </a><br> + </div> </div> - </div> -</section> - -<section class="dac-section dac-gray dac-small dac-invert"><div class="wrap"> - <h2 class="norule">Latest</h2> - <div class="resource-widget resource-flow-layout col-16" - data-query="collection:develop/landing/latest" - data-cardSizes="6x6" - data-maxResults="3"></div> -</div></section> - -<section class="dac-section"><div class="wrap"> - <h1 class="dac-section-title">Resources</h1> - <div class="dac-section-subtitle"> - Check out these resources to help you get started with the M Developer Preview. + <div class="dac-section dac-small"> + <div class="resource-widget resource-flow-layout col-16" + data-query="collection:preview/landing/resources" + data-cardSizes="6x2" + data-maxResults="6"></div> + </div> </div> - <div class="resource-widget resource-flow-layout col-16" - data-query="collection:preview/landing/resources" - data-cardSizes="6x6" - data-maxResults="6"></div> -</div></section> - - +</section>
\ No newline at end of file diff --git a/docs/html/preview/license.html b/docs/html/preview/license.html deleted file mode 100644 index deb16aa..0000000 --- a/docs/html/preview/license.html +++ /dev/null @@ -1,274 +0,0 @@ -<!DOCTYPE html> - -<html> -<head> - - -<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> -<meta name="viewport" content="width=970" /> - -<meta name="Description" content="To get started with the Android SDK Preview, you must agree to the following terms and conditions. As described below, please note that this is a preview version of the Android SDK, subject to change, that you use at your own risk."> -<link rel="shortcut icon" type="image/x-icon" href="/favicon.ico" /> -<title>License Agreement | Android Developers</title> - -<!-- STYLESHEETS --> -<link rel="stylesheet" -href="//fonts.googleapis.com/css?family=Roboto+Condensed"> -<link rel="stylesheet" href="//fonts.googleapis.com/css?family=Roboto:light,regular,medium,thin,italic,mediumitalic,bold" - title="roboto"> -<link href="/assets/css/default.css" rel="stylesheet" type="text/css"> - - - -<!-- JAVASCRIPT --> -<script src="//www.google.com/jsapi" type="text/javascript"></script> -<script src="/assets/js/android_3p-bundle.js" type="text/javascript"></script> -<script type="text/javascript"> - var toRoot = "/"; - var metaTags = []; - var devsite = false; -</script> -<script src="/assets/js/docs.js" type="text/javascript"></script> - -<script> - (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){ - (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o), - m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m) - })(window,document,'script','//www.google-analytics.com/analytics.js','ga'); - - ga('create', 'UA-5831155-1', 'android.com'); - ga('create', 'UA-49880327-2', 'android.com', {'name': 'universal'}); // New tracker); - ga('send', 'pageview'); - ga('universal.send', 'pageview'); // Send page view for new tracker. -</script> - -</head> - - -<body class="gc-documentation" itemscope="" itemtype="http://schema.org/Article"> - - -<a name="top"></a> -<div id="body-content"> -<div class="fullpage"> -<div id="jd-content"> - <div class="jd-descr" itemprop="articleBody"> -<style> -body,html, #qv {background-color:#e9e9e9} - -#qv * { font-weight:bold;} - -.fullpage>#footer, -#jd-content>.content-footer.wrap { - display:none; -} - -.content-footer { - display: none; -} -</style> - - <div style="border-bottom: 1px solid #a5c43a; position: absolute; left: 0; right: 0; top: 0;"> - <div class="wrap" style="position: relative; height: 45px; padding: 0 20px;"> - <a href="/index.html" style="position:absolute;top:8px"> - <img src="/assets/images/dac_logo.png" srcset="/assets/images/dac_logo@2x.png 2x" width="123" height="25" alt="Android Developers home page"> - </a> - </div> - </div> - - <div class="landing-rest-of-page"> - <div class="landing-section" style="padding:55px 10px 0"> - -<div class="wrap"> - -<div class="col-16" id="doc-col" > - - <h1 itemprop="name" >L Developer Preview License Agreement</h1> - -<div class="jd-descr" itemprop="articleBody"> - <p> -If you are using the Android SDK -Preview, you must agree to the following terms -and conditions. As described below, please note that the preview version of the -Android SDK is subject to change, and that you use it at your own risk. The -Android SDK Preview is not a stable release, and may contain errors and defects -that can result in serious damage to your computer systems, devices and data. -</p> - -<p> -This is the Android SDK Preview License Agreement (the “License Agreement”). -</p> - -<div class="sdk-terms" style="height:auto;border:0;padding:0;width:940px"> -1. Introduction - -1.1 The Android SDK Preview (referred to in the License Agreement as the “Preview” and specifically including the Android system files, packaged APIs, and Preview library files, if and when they are made available) is licensed to you subject to the terms of the License Agreement. The License Agreement forms a legally binding contract between you and Google in relation to your use of the Preview. - -1.2 "Android" means the Android software stack for devices, as made available under the Android Open Source Project, which is located at the following URL: http://source.android.com/, as updated from time to time. - -1.3 "Google" means Google Inc., a Delaware corporation with principal place of business at 1600 Amphitheatre Parkway, Mountain View, CA 94043, United States. - -2. Accepting the License Agreement - -2.1 In order to use the Preview, you must first agree to the License Agreement. You may not use the Preview if you do not accept the License Agreement. - -2.2 By clicking to accept and/or using the Preview, you hereby agree to the terms of the License Agreement. - -2.3 You may not use the Preview and may not accept the License Agreement if you are a person barred from receiving the Preview under the laws of the United States or other countries including the country in which you are resident or from which you use the Preview. - -2.4 If you will use the Preview internally within your company or organization you agree to be bound by the License Agreement on behalf of your employer or other entity, and you represent and warrant that you have full legal authority to bind your employer or such entity to the License Agreement. If you do not have the requisite authority, you may not accept the License Agreement or use the Preview on behalf of your employer or other entity. - -3. Preview License from Google - -3.1 Subject to the terms of the License Agreement, Google grants you a royalty-free, non-assignable, non-exclusive, non-sublicensable, limited, revocable license to use the Preview, personally or internally within your company or organization, solely to develop applications to run on the Android platform. - -3.2 You agree that Google or third parties owns all legal right, title and interest in and to the Preview, including any Intellectual Property Rights that subsist in the Preview. "Intellectual Property Rights" means any and all rights under patent law, copyright law, trade secret law, trademark law, and any and all other proprietary rights. Google reserves all rights not expressly granted to you. - -3.3 You may not use the Preview for any purpose not expressly permitted by the License Agreement. Except to the extent required by applicable third party licenses, you may not: (a) copy (except for backup purposes), modify, adapt, redistribute, decompile, reverse engineer, disassemble, or create derivative works of the Preview or any part of the Preview; or (b) load any part of the Preview onto a mobile handset or any other hardware device except a personal computer, combine any part of the Preview with other software, or distribute any software or device incorporating a part of the Preview. - -3.4 You agree that you will not take any actions that may cause or result in the fragmentation of Android, including but not limited to distributing, participating in the creation of, or promoting in any way a software development kit derived from the Preview. - -3.5 Use, reproduction and distribution of components of the Preview licensed under an open source software license are governed solely by the terms of that open source software license and not the License Agreement. You agree to remain a licensee in good standing in regard to such open source software licenses under all the rights granted and to refrain from any actions that may terminate, suspend, or breach such rights. - -3.6 You agree that the form and nature of the Preview that Google provides may change without prior notice to you and that future versions of the Preview may be incompatible with applications developed on previous versions of the Preview. You agree that Google may stop (permanently or temporarily) providing the Preview (or any features within the Preview) to you or to users generally at Google's sole discretion, without prior notice to you. - -3.7 Nothing in the License Agreement gives you a right to use any of Google's trade names, trademarks, service marks, logos, domain names, or other distinctive brand features. - -3.8 You agree that you will not remove, obscure, or alter any proprietary rights notices (including copyright and trademark notices) that may be affixed to or contained within the Preview. - -4. Use of the Preview by You - -4.1 Google agrees that nothing in the License Agreement gives Google any right, title or interest from you (or your licensors) under the License Agreement in or to any software applications that you develop using the Preview, including any intellectual property rights that subsist in those applications. - -4.2 You agree to use the Preview and write applications only for purposes that are permitted by (a) the License Agreement, and (b) any applicable law, regulation or generally accepted practices or guidelines in the relevant jurisdictions (including any laws regarding the export of data or software to and from the United States or other relevant countries). - -4.3 You agree that if you use the Preview to develop applications, you will protect the privacy and legal rights of users. If users provide you with user names, passwords, or other login information or personal information, you must make the users aware that the information will be available to your application, and you must provide legally adequate privacy notice and protection for those users. If your application stores personal or sensitive information provided by users, it must do so securely. If users provide you with Google Account information, your application may only use that information to access the user's Google Account when, and for the limited purposes for which, each user has given you permission to do so. - -4.4 You agree that you will not engage in any activity with the Preview, including the development or distribution of an application, that interferes with, disrupts, damages, or accesses in an unauthorized manner the servers, networks, or other properties or services of Google or any third party. - -4.5 You agree that you are solely responsible for (and that Google has no responsibility to you or to any third party for) any data, content, or resources that you create, transmit or display through Android and/or applications for Android, and for the consequences of your actions (including any loss or damage which Google may suffer) by doing so. - -4.6 You agree that you are solely responsible for (and that Google has no responsibility to you or to any third party for) any breach of your obligations under the License Agreement, any applicable third party contract or Terms of Service, or any applicable law or regulation, and for the consequences (including any loss or damage which Google or any third party may suffer) of any such breach. - -4.7 The Preview is in development, and your testing and feedback are an important part of the development process. By using the Preview, you acknowledge that implementation of some features are still under development and that you should not rely on the Preview having the full functionality of a stable release. You agree not to publicly distribute or ship any application using this Preview as this Preview will no longer be supported after the official Android SDK is released. - -5. Your Developer Credentials - -5.1 You agree that you are responsible for maintaining the confidentiality of any developer credentials that may be issued to you by Google or which you may choose yourself and that you will be solely responsible for all applications that are developed under your developer credentials. - -6. Privacy and Information - -6.1 In order to continually innovate and improve the Preview, Google may collect certain usage statistics from the software including but not limited to a unique identifier, associated IP address, version number of the software, and information on which tools and/or services in the Preview are being used and how they are being used. Before any of this information is collected, the Preview will notify you and seek your consent. If you withhold consent, the information will not be collected. - -6.2 The data collected is examined in the aggregate to improve the Preview and is maintained in accordance with Google's Privacy Policy located at http://www.google.com/policies/privacy/. - -7. Third Party Applications - -7.1 If you use the Preview to run applications developed by a third party or that access data, content or resources provided by a third party, you agree that Google is not responsible for those applications, data, content, or resources. You understand that all data, content or resources which you may access through such third party applications are the sole responsibility of the person from which they originated and that Google is not liable for any loss or damage that you may experience as a result of the use or access of any of those third party applications, data, content, or resources. - -7.2 You should be aware the data, content, and resources presented to you through such a third party application may be protected by intellectual property rights which are owned by the providers (or by other persons or companies on their behalf). You may not modify, rent, lease, loan, sell, distribute or create derivative works based on these data, content, or resources (either in whole or in part) unless you have been specifically given permission to do so by the relevant owners. - -7.3 You acknowledge that your use of such third party applications, data, content, or resources may be subject to separate terms between you and the relevant third party. - -8. Using Google APIs - -8.1 Google APIs - -8.1.1 If you use any API to retrieve data from Google, you acknowledge that the data may be protected by intellectual property rights which are owned by Google or those parties that provide the data (or by other persons or companies on their behalf). Your use of any such API may be subject to additional Terms of Service. You may not modify, rent, lease, loan, sell, distribute or create derivative works based on this data (either in whole or in part) unless allowed by the relevant Terms of Service. - -8.1.2 If you use any API to retrieve a user's data from Google, you acknowledge and agree that you shall retrieve data only with the user's explicit consent and only when, and for the limited purposes for which, the user has given you permission to do so. - -9. Terminating the License Agreement - -9.1 the License Agreement will continue to apply until terminated by either you or Google as set out below. - -9.2 If you want to terminate the License Agreement, you may do so by ceasing your use of the Preview and any relevant developer credentials. - -9.3 Google may at any time, terminate the License Agreement, with or without cause, upon notice to you. - -9.4 The License Agreement will automatically terminate without notice or other action upon the earlier of: -(A) when Google ceases to provide the Preview or certain parts of the Preview to users in the country in which you are resident or from which you use the service; and -(B) Google issues a final release version of the Android SDK. - -9.5 When the License Agreement is terminated, the license granted to you in the License Agreement will terminate, you will immediately cease all use of the Preview, and the provisions of paragraphs 10, 11, 12 and 14 shall survive indefinitely. - -10. DISCLAIMERS - -10.1 YOU EXPRESSLY UNDERSTAND AND AGREE THAT YOUR USE OF THE PREVIEW IS AT YOUR SOLE RISK AND THAT THE PREVIEW IS PROVIDED "AS IS" AND "AS AVAILABLE" WITHOUT WARRANTY OF ANY KIND FROM GOOGLE. - -10.2 YOUR USE OF THE PREVIEW AND ANY MATERIAL DOWNLOADED OR OTHERWISE OBTAINED THROUGH THE USE OF THE PREVIEW IS AT YOUR OWN DISCRETION AND RISK AND YOU ARE SOLELY RESPONSIBLE FOR ANY DAMAGE TO YOUR COMPUTER SYSTEM OR OTHER DEVICE OR LOSS OF DATA THAT RESULTS FROM SUCH USE. WITHOUT LIMITING THE FOREGOING, YOU UNDERSTAND THAT THE PREVIEW IS NOT A STABLE RELEASE AND MAY CONTAIN ERRORS, DEFECTS AND SECURITY VULNERABILITIES THAT CAN RESULT IN SIGNIFICANT DAMAGE, INCLUDING THE COMPLETE, IRRECOVERABLE LOSS OF USE OF YOUR COMPUTER SYSTEM OR OTHER DEVICE. - -10.3 GOOGLE FURTHER EXPRESSLY DISCLAIMS ALL WARRANTIES AND CONDITIONS OF ANY KIND, WHETHER EXPRESS OR IMPLIED, INCLUDING, BUT NOT LIMITED TO THE IMPLIED WARRANTIES AND CONDITIONS OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. - -11. LIMITATION OF LIABILITY - -11.1 YOU EXPRESSLY UNDERSTAND AND AGREE THAT GOOGLE, ITS SUBSIDIARIES AND AFFILIATES, AND ITS LICENSORS SHALL NOT BE LIABLE TO YOU UNDER ANY THEORY OF LIABILITY FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, CONSEQUENTIAL OR EXEMPLARY DAMAGES THAT MAY BE INCURRED BY YOU, INCLUDING ANY LOSS OF DATA, WHETHER OR NOT GOOGLE OR ITS REPRESENTATIVES HAVE BEEN ADVISED OF OR SHOULD HAVE BEEN AWARE OF THE POSSIBILITY OF ANY SUCH LOSSES ARISING. - -12. Indemnification - -12.1 To the maximum extent permitted by law, you agree to defend, indemnify and hold harmless Google, its affiliates and their respective directors, officers, employees and agents from and against any and all claims, actions, suits or proceedings, as well as any and all losses, liabilities, damages, costs and expenses (including reasonable attorneys’ fees) arising out of or accruing from (a) your use of the Preview, (b) any application you develop on the Preview that infringes any Intellectual Property Rights of any person or defames any person or violates their rights of publicity or privacy, and (c) any non-compliance by you of the License Agreement. - -13. Changes to the License Agreement - -13.1 Google may make changes to the License Agreement as it distributes new versions of the Preview. When these changes are made, Google will make a new version of the License Agreement available on the website where the Preview is made available. - -14. General Legal Terms - -14.1 the License Agreement constitutes the whole legal agreement between you and Google and governs your use of the Preview (excluding any services which Google may provide to you under a separate written agreement), and completely replaces any prior agreements between you and Google in relation to the Preview. - -14.2 You agree that if Google does not exercise or enforce any legal right or remedy which is contained in the License Agreement (or which Google has the benefit of under any applicable law), this will not be taken to be a formal waiver of Google's rights and that those rights or remedies will still be available to Google. - -14.3 If any court of law, having the jurisdiction to decide on this matter, rules that any provision of the License Agreement is invalid, then that provision will be removed from the License Agreement without affecting the rest of the License Agreement. The remaining provisions of the License Agreement will continue to be valid and enforceable. - -14.4 You acknowledge and agree that each member of the group of companies of which Google is the parent shall be third party beneficiaries to the License Agreement and that such other companies shall be entitled to directly enforce, and rely upon, any provision of the License Agreement that confers a benefit on (or rights in favor of) them. Other than this, no other person or company shall be third party beneficiaries to the License Agreement. - -14.5 EXPORT RESTRICTIONS. THE PREVIEW IS SUBJECT TO UNITED STATES EXPORT LAWS AND REGULATIONS. YOU MUST COMPLY WITH ALL DOMESTIC AND INTERNATIONAL EXPORT LAWS AND REGULATIONS THAT APPLY TO THE PREVIEW. THESE LAWS INCLUDE RESTRICTIONS ON DESTINATIONS, END USERS AND END USE. - -14.6 The License Agreement may not be assigned or transferred by you without the prior written approval of Google, and any attempted assignment without such approval will be void. You shall not delegate your responsibilities or obligations under the License Agreement without the prior written approval of Google. - -14.7 The License Agreement, and your relationship with Google under the License Agreement, shall be governed by the laws of the State of California without regard to its conflict of laws provisions. You and Google agree to submit to the exclusive jurisdiction of the courts located within the county of Santa Clara, California to resolve any legal matter arising from the License Agreement. Notwithstanding this, you agree that Google shall still be allowed to apply for injunctive remedies (or an equivalent type of urgent legal relief) in any jurisdiction. - - -</div> - </div> - </div> - -</div> - </div> <!-- end landing-body-content --> - - </div> - - <div class="content-footer wrap" itemscope="" - itemtype="http://schema.org/SiteNavigationElement"> - - <div class="paging-links layout-content-col col-10"> - - </div> - - </div> - - - - - </div> <!-- end jd-content --> - -<div id="footer" class="wrap" style="width:940px"> - - - <div id="copyright"> - - Except as noted, this content is - licensed under <a href="http://creativecommons.org/licenses/by/2.5/"> - Creative Commons Attribution 2.5</a>. For details and - restrictions, see the <a href="https://developer.android.com/license.html">Content - License</a>. - </div> - - -</div> <!-- end footer --> -</div><!-- end doc-content --> - -</div> <!-- end body-content --> - -</body> -</html> |