From 011c07bd80dea896cf3d692146032a752f13064e Mon Sep 17 00:00:00 2001 From: Mark Lu Date: Thu, 28 Jul 2016 11:15:11 -0700 Subject: [PATCH] docs: fix escaped characters in data binding doc MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This commit fixes the following issues: - replace curved “” ‘’ quotes with straight quotes - replace " and ' with " and ' (no escape required) - fix incorrectly escaped characters like < Bug:30471915 Change-Id: I194d04ef7ac8269db3f99f8526da1283e26ef499 --- .../topic/libraries/data-binding/index.jd | 100 +++++++++--------- 1 file changed, 50 insertions(+), 50 deletions(-) diff --git a/docs/html/topic/libraries/data-binding/index.jd b/docs/html/topic/libraries/data-binding/index.jd index ec6e58c15ca10..454bb59e79833 100644 --- a/docs/html/topic/libraries/data-binding/index.jd +++ b/docs/html/topic/libraries/data-binding/index.jd @@ -246,21 +246,21 @@ android {

Expressions within the layout are written in the attribute properties using - the “@{}” syntax. Here, the TextView’s text is set to + the "@{}" syntax. Here, the TextView's text is set to the firstName property of user:

 <TextView android:layout_width="wrap_content"
           android:layout_height="wrap_content"
-          android:text="&commat;{user.firstName}"/>
+          android:text="@{user.firstName}"/>
 

Data Object

- Let’s assume for now that you have a plain-old Java object (POJO) for User: + Let's assume for now that you have a plain-old Java object (POJO) for User:

@@ -296,8 +296,8 @@ public class User {
 

From the perspective of data binding, these two classes are equivalent. The - expression &commat;{user.firstName} used - for the TextView’s android:text attribute will + expression @{user.firstName} used + for the TextView's android:text attribute will access the firstName field in the former class and the getFirstName() method in the latter class. Alternatively, it will also be resolved to firstName() if that @@ -310,10 +310,10 @@ public class User {

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 + file, converting it to Pascal case and suffixing "Binding" to it. The above layout file was main_activity.xml so the generate class was MainActivityBinding. This class holds all the bindings from the - layout properties (e.g. the user variable) to the layout’s Views + layout properties (e.g. the user 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:

@@ -328,7 +328,7 @@ protected void onCreate(Bundle savedInstanceState) { }

- You’re done! Run the application and you’ll see Test User in the UI. + You're done! Run the application and you'll see Test User in the UI. Alternatively, you can get the view via:

@@ -434,15 +434,15 @@ public class Presenter { Then you can bind the click event to your class as follows:
-  <?xml version="1.0" encoding="utf-8"?>
-  <layout xmlns:android="http://schemas.android.com/apk/res/android">
+  <?xml version="1.0" encoding="utf-8"?>
+  <layout xmlns:android="http://schemas.android.com/apk/res/android">
       <data>
-          <variable name="task" type="com.android.example.Task" />
-          <variable name="presenter" type="com.android.example.Presenter" />
+          <variable name="task" type="com.android.example.Task" />
+          <variable name="presenter" type="com.android.example.Presenter" />
       </data>
-      <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent">
-          <Button android:layout_width="wrap_content" android:layout_height="wrap_content"
-          android:onClick="@{() -> presenter.onSaveClick(task)}" />
+      <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent">
+          <Button android:layout_width="wrap_content" android:layout_height="wrap_content"
+          android:onClick="@{() -> presenter.onSaveClick(task)}" />
       </LinearLayout>
   </layout>
 
@@ -465,7 +465,7 @@ public class Presenter { above could be written as:

-  android:onClick="@{(view) -> presenter.onSaveClick(task)}"
+  android:onClick="@{(view) -> presenter.onSaveClick(task)}"
 
Or if you wanted to use the parameter in the expression, it could work as follows:
@@ -474,7 +474,7 @@ public class Presenter {
 }
 
-  android:onClick="@{(theView) -> presenter.onSaveClick(theView, task)}"
+  android:onClick="@{(theView) -> presenter.onSaveClick(theView, task)}"
 
You can use a lambda expression with more than one parameter:
@@ -483,8 +483,8 @@ public class Presenter {
 }
 
-  <CheckBox android:layout_width="wrap_content" android:layout_height="wrap_content"
-        android:onCheckedChanged="@{(cb, isChecked) -> presenter.completeChanged(task, isChecked)}" />
+  <CheckBox android:layout_width="wrap_content" android:layout_height="wrap_content"
+        android:onCheckedChanged="@{(cb, isChecked) -> presenter.completeChanged(task, isChecked)}" />
 

If the event you are listening to returns a value whose type is not {@code @@ -498,7 +498,7 @@ public class Presenter { }

-  android:onLongClick="@{(theView) -> presenter.onLongClick(theView, task)}"
+  android:onLongClick="@{(theView) -> presenter.onLongClick(theView, task)}"
 

If the expression cannot be evaluated due to {@code null} objects, Data Binding returns @@ -510,7 +510,7 @@ If you need to use an expression with a predicate (e.g. ternary), you can use {@code void} as a symbol.

-  android:onClick="@{(v) -> v.isVisible() ? doSomething() : void}"
+  android:onClick="@{(v) -> v.isVisible() ? doSomething() : void}"
 
Avoid Complex Listeners
@@ -580,7 +580,7 @@ any business logic inside the callback method that you invoked from the listener

When there are class name conflicts, one of the classes may be renamed to an - “alias:” + "alias:"

@@ -601,7 +601,7 @@ any business logic inside the callback method that you invoked from the listener
     <import type="com.example.User"/>
     <import type="java.util.List"/>
     <variable name="user" type="User"/>
-    <variable name="userList" type="List&lt;User>"/>
+    <variable name="userList" type="List<User>"/>
 </data>
 

@@ -695,7 +695,7 @@ any business logic inside the callback method that you invoked from the listener

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 + 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 contact_item.xml will generate ContactItemBinding. If the module package is @@ -718,7 +718,7 @@ any business logic inside the callback method that you invoked from the listener This generates the binding class as ContactItem 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 - “.”: + ".":

@@ -741,7 +741,7 @@ any business logic inside the callback method that you invoked from the listener
 
 
 

- Variables may be passed into an included layout's binding from the + 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:

@@ -855,8 +855,8 @@ any business logic inside the callback method that you invoked from the listener
 android:text="@{String.valueOf(index + 1)}"
-android:visibility="@{age &lt; 13 ? View.GONE : View.VISIBLE}"
-android:transitionName='@{"image_" + id}'
+android:visibility="@{age < 13 ? View.GONE : View.VISIBLE}"
+android:transitionName='@{"image_" + id}'
 

Missing Operations @@ -945,9 +945,9 @@ android:transitionName='@{"image_" + id}' <import type="android.util.SparseArray"/> <import type="java.util.Map"/> <import type="java.util.List"/> - <variable name="list" type="List&lt;String>"/> - <variable name="sparse" type="SparseArray&lt;String>"/> - <variable name="map" type="Map&lt;String, String>"/> + <variable name="list" type="List<String>"/> + <variable name="sparse" type="SparseArray<String>"/> + <variable name="map" type="Map<String, String>"/> <variable name="index" type="int"/> <variable name="key" type="String"/> </data> @@ -969,17 +969,17 @@ android:text="@{map[key]}"

-android:text='@{map["firstName"]}'
+android:text='@{map["firstName"]}'
 

It is also possible to use double quotes to surround the attribute value. - When doing so, String literals should either use the &quot; or back quote + When doing so, String literals should either use the ' or back quote (`).

 android:text="@{map[`firstName`}"
-android:text="@{map[&quot;firstName&quot;]}"
+android:text="@{map['firstName']}"
 

Resources @@ -1216,7 +1216,7 @@ private static class User { }

- That's it! To access the value, use the set and get accessor methods: + That's it! To access the value, use the set and get accessor methods:

@@ -1247,15 +1247,15 @@ user.put("age", 17);
 
 <data>
     <import type="android.databinding.ObservableMap"/>
-    <variable name="user" type="ObservableMap&lt;String, Object>"/>
+    <variable name="user" type="ObservableMap<String, Object>"/>
 </data>
 …
 <TextView
-   android:text='@{user["lastName"]}'
+   android:text='@{user["lastName"]}'
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"/>
 <TextView
-   android:text='@{String.valueOf(1 + (Integer)user["age"])}'
+   android:text='@{String.valueOf(1 + (Integer)user["age"])}'
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"/>
 
@@ -1277,15 +1277,15 @@ user.add(17); <data> <import type="android.databinding.ObservableList"/> <import type="com.example.my.app.Fields"/> - <variable name="user" type="ObservableList&lt;Object>"/> + <variable name="user" type="ObservableList<Object>"/> </data> … <TextView - android:text='@{user[Fields.LAST_NAME]}' + android:text='@{user[Fields.LAST_NAME]}' android:layout_width="wrap_content" android:layout_height="wrap_content"/> <TextView - android:text='@{String.valueOf(1 + (Integer)user[Fields.AGE])}' + android:text='@{String.valueOf(1 + (Integer)user[Fields.AGE])}' android:layout_width="wrap_content" android:layout_height="wrap_content"/>
@@ -1428,7 +1428,7 @@ public abstract void setNote(String note);

When inflating another layout, a binding must be established for the new - layout. Therefore, the ViewStubProxy must listen to the ViewStub's + layout. Therefore, the ViewStubProxy must listen to the ViewStub's {@link android.view.ViewStub.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. @@ -1443,9 +1443,9 @@ public abstract void setNote(String note);

- At times, the specific binding class won't be known. For example, a + At times, the specific binding class won't be known. For example, a {@link android.support.v7.widget.RecyclerView.Adapter} operating against arbitrary layouts - won't know the specific binding class. It still must assign the binding value during the + won't know the specific binding class. It still must assign the binding value during the {@link android.support.v7.widget.RecyclerView.Adapter#onBindViewHolder}.

@@ -1499,13 +1499,13 @@ public void onBindViewHolder(BindingHolder holder, int position) { For an attribute, data binding tries to find the method setAttribute. The namespace for the attribute does not matter, only the attribute name itself.

- For example, an expression associated with TextView's attribute + For example, an expression associated with TextView's attribute android:text 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 + 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.

@@ -1522,7 +1522,7 @@ namespace for the attribute does not matter, only the attribute name itself.

- Some attributes have setters that don't match by name. For these + Some attributes have setters that don't match by name. For these methods, an attribute may be associated with the setter through {@link android.databinding.BindingMethods} annotation. This must be associated with a class and contains {@link android.databinding.BindingMethod} annotations, one for @@ -1591,8 +1591,8 @@ public static void loadImage(ImageView view, String url, Drawable error) { }

-<ImageView app:imageUrl=“@{venue.imageUrl}”
-app:error=“@{@drawable/venueError}”/>
+<ImageView app:imageUrl="@{venue.imageUrl}"
+app:error="@{@drawable/venueError}"/>
 

@@ -1747,7 +1747,7 @@ public static void setListener(View view, final OnViewDetachedFromWindow detach,

 <TextView
-   android:text='@{userMap["lastName"]}'
+   android:text='@{userMap["lastName"]}'
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"/>