LightBlog

mardi 16 août 2016

BLU’s upcoming Pure XR flagship teased with 4GB of RAM and giveaway

pure-xr-gleam-give-away

The Miami-based unlocked smartphone maker, BLU, is showing no signs of stopping its barrage of affordable and compelling Android offerings. The company's latest move is to try to surround hype around an upcoming top-end phone, dubbed the Pure XR. Mind you, for a phone manufacturer that targets value, this "flagship" will land at an MSRP of only $299.

The tease came by as a post on the company's Facebook page, and naturally, we aren't given much info about the device (but just enough to intrigue us). It is said to be a 'premium smartphone', which in this day and age implies a metal build. The teaser image shows a front view that looks a lot like the OnePlus 3, particularly by the shape of the fingerprint scanner and LED dots for capacity buttons. BLU better watch it; it's not like the Pure XR's price undercuts the $399 base price of the stellar OnePlus 3 by that much.

OnePlus-3-3See also: OnePlus 3 review155

Regarding specs, the only tidbit we're given is that the Pure XR will pack 4GB of RAM, which hints that the internal components may back the phone's premium facade. Although, it's best to remain suspicious for now. We're also told a launch date of Aug. 29th, and that BLU is pushing excitement with a chance to win one of three Pure XR's that it's giving away. The contest will end on Sept. 2nd, so head over to the sign up page if you're enticed.

What do you guys think about the Pure XR so far? Would you give BLU a chance if it were to offer a better value than OnePlus, or no way Jose? Let us know your thoughts in the comments.

Next: Best Cheap Android Phones (July 2016)



from Android Authority http://ift.tt/2aZ6j3A
via IFTTT

Take Three! | Podcast 076

AAPodcastfeatured_imageAAP076

Join Joshua Vergara, Joe Hindy, Jonathan Feist, Nirave Gondhia and Lanh Nguyen for a for more talk about Android and the tech world on the Android Authority Podcast. This week we discuss the latest renders of the LG V20, a spiritual successor to the V10, but a physical successor to the G5. We chat the latest BlackBerry phone, the Android powered DTEK50, before Jonathan goes on a rant about the USB Type-C firefight, this time OnePlus promotes their rapid charge tech, but still on non-standard USB Type-C cables. The topic expands to other rapid charge tech, particularly from Samsung. The discussion rounds out with discussion on what iOS apps we want to see on Android.

Thank you for joining us. If you have not already, be sure to subscribe to the channel on your favorite podcast app, and subscribe to our YouTube channel. Also check out our partner sites – SoundGuys cover the best mobile audio gear and TabTimes talks all things tablet. Finally, a huge welcome to VR Source, the home of all our virtual reality coverage, from gear to games, check out VR Source for all kinds of reality. Sign up for our various newsletters and enter for your chance to win one of our many giveaways.

Be sure to check out all of our great new giveaways this month. Running for the month of August 2016, we've got a pair of Bose SoundSport Wireless Earbuds on SoundGuys, a Samsung Galaxy Tab S2 on TabTimes, and a Sapphire Radeon RX 480 graphics card and a $100 Steam gift card on VR Source.

The Android Authority Podcast – discussing topics in Android every week.

Links to Podcast

RSS Feed
iTunes
Stitcher
SoundCloud
Direct Download

Relevant Links

Android Authority Forums
LG V20 renders
BlackBerry DTEK50
OnePlus rapid charge vs Samsung
iOS apps for Android

SoundGuys is giving away a pair of Bose SoundSport Wireless Earbuds.
TabTimes Samsung Galaxy Tab S2 giveaway
VRSource is giving away a Sapphire Radeon RX 480 graphics card and a $100 Steam gift card.

Android Apps Weekly

Follow our Hosts


Joshua Vergara
Twitter | Google+

Joseph Hindy
Twitter | Google+

Andrew Grush
Twitter | Google+

Jonathan Feist
Twitter | Google+

Nirave Gondhia
Twitter | Google+

John Dye
Twitter | Facebook

Lanh Nguyen
Twitter | YouTube

Recorded on August 11th, 2016 – Hosted and produced by Joshua Vergara.

"Just add oxygen."



from Android Authority http://ift.tt/2aZ5lo0
via IFTTT

10 interesting facts about Huawei

Huawei-Logo-2015-3

Huawei may not be the first name you think of when talking about smartphones, but that doesn't mean it's not an important company. In fact, Huawei is massive, especially behind the scenes in the telecommunications market. Here are a few facts you may not have known about Huawei.

Ren Zhengfei was 42 when he founded Huawei

Ren Zhengfei Huawei CEOQZ

In the middle of a mid-life crisis? Who knows, you could found what will go on to be one of the largest companies in the world. That's what Ren Zhengfei did, anyway. Before founding the company, Zhengfei was in the People's Liberation Army, serving as a military technologist. While he didn't hold military rank, he was eventually chosen to be a delegate.

Now, at age 71, Zhengfei is still president of the company, and is the 556th richest person in China, according to Hurun Report.

The word 'Huawei' roughly translates to 'Chinese achievement'

The first character of Huawei's name in Chinese — 华 — is derived from the Chinese word for flower, but now often refers to 'China' or 'Chinese.' The second character — 为 — , means 'achievement' or 'action.' Combined, the two characters literally mean 'Chinese achievement.'

Huawei is the largest telecommunications equipment manufacturer in the world

huawei mate 8 review aa (33 of 34)

That's right — Huawei may not have been on your radar as a smartphone company until recently, but it turns out the company is the largest telecommunications equipment maker in the world, having overtaken the likes of Ericsson back in 2012. Of course, that's not just due to its smartphone business. The company also makes equipment for corporations, telecommunication companies, and so on.

  • Huawei P9 review
  • Huawei Mate 8 vs Nexus 6P
  • Huawei Mate 8 Review
  • Nexus 6P Review!

Huawei was first created to produce telephone exchange switches in the 1980s

Again, Huawei may not have surfaced in the western world until recently, but the company has been around for a long time… since the 1980s, in fact. Huawei first started in 1987 in Shenzhen, China. At the time, China and the People's Liberation Army were relying on telecom equipment from outside manufacturers. Ren wanted to focus on local research and development to build telephone exchange switches because, as he said, "switching equipment technology was related to international security, and that a nation that did not have its own switching equipment was like one that lacked its own military."

Huawei has partnered with approximately 80% of the world's top telecommunications companies

Huawei Ascend P7 Arsenal FC

Some of the major companies Huawei has worked with include the likes of Vodafone, Motorola, T-Mobile, and so on. Beyond simply making its own smartphones, Huawei is known as a partner for other companies too, showing just how influential in the industry the company is. Huawei has also sponsored a number of major events and sports teams, including Arsenal F.C., Paris Saint-Germain, the Ghana Football Association, and more.

Huawei invested over a million dollars in a university in Canada

The company has invested $1.4 million in Carleton University in Canada. Why? The goal was to establish a research lab dedicated largely to the development of cloud computing services and technology. Of course, in the end this could greatly benefit the company, but it's still a nice thing to see.

In fact, Huawei has donated money to a number of services in the name of education. The company has also sponsored MIT's Communications Futures Program, which studies the future of the telecommunications industry as a whole.

Huawei is a largely employee-owned company

Huawei employees north america

Huawei is an employee-owned company, which is something it uses as a way to distance itself from claims that it's under government control. What that basically means is that employees own stock in the company, with around 64 percent of employees participating in the employee ownership scheme. These employees own "virtual restricted shares," or shares that are not tradable, and are awarded based on performance. When an employee leaves the company, those shares are reverted back to Huawei, and the employees are compensated for their holding.

Huawei-interview-2See also: Interview with Huawei at CES talks challenges, successes and more10

It's important to note that just because employees generally own Huawei doesn't mean they control it. Huawei is still controlled and managed by a subset of management, and Ren actually has the power to veto any major decision as he sees fit. Huawei does say, however, that the Union votes every five years to elect 51 representatives who then select the board of 17 directors.

Huawei has had a rough history with U.S. security

Huawei has long been challenged by the U.S. government because of concerns that the company may be working with the Chinese government to spy on the U.S. Huawei has argued that these claims are 'unfounded', and has even called on the U.S. government to perform an investigation to prove that there is no spying going on. Despite not finding anything in those investigations, the U.S. House Intelligence Committee issues a report describing the company as a 'national security threat' in 2012, due to its ties with the Chinese government.

In 2014, documents leaked by Edward Snowden revealed that the NSA has been carrying out a covert program against Huawei, including breaking into the company's networks and even tapping founder Ren Zhengfei's communications.

Over 75,000 Huawei employees are in R&D

Huawei R&D

Huawei is a big company, but its research and development team is huge — 76,000 employee-strong, in fact. This explains how they've been able to become so large, as it invests huge amounts of money in staying on top of the latest technology trends. Around 10% of the company's income is put straight back into R&D, which helps the company develop its latest and greatest products.

Huawei increased its earnings by 30% in 2010

That's a lot of income increase. Part of the massive increase had to do with significant growth overseas including in the U.S., and sales outside of China became the company's main business. In fact, Huawei accounted for as much as 15.7 percent of the $78.56 billion global carrier-network-infrastructure market in 2010, according to Gartner.

Joonsuh Kim Huawei Design 2015 -8See also: Huawei's focus on design, making great products & 'true value'13

Whether you're a fan of Huawei or not, there's no denying that the company has had an interesting past. Know of any other interesting facts we missed? Be sure to leave a comment below!



from Android Authority http://ift.tt/2aYSXEC
via IFTTT

LG V20 pre-orders may kick off on Sept. 14th, with modular extras in tow

The Note 7 is on everyone's mind at the moment, but we shouldn't forget that LG's phablet opponent is just around the corner. We already know that its official announcement is slated for September 6th. Not only that, but in the midst of the Note 7 hublub, LG couldn't help but trickle little tidbits information regarding the promising device. Among these were that the V20 will launch with Android 7.0 Nougat out of the box and that an updated 32-bit Quad DAC will be driving the Hi-Fi tunes out of the headphone jack.

LGV20-AA-exclusive-render-3See also: Exclusive LG V20 renders: every angle of LG's next flagship349

However, if you were wondering what to look at in regard to a release date, we now have a hint (although, unconfirmed). A Reddit user who claims to have the inside info stated that LG V20 pre-orders on T-Mobile will begin on Sept. 14th, and that a release date of Sept. 23rd is 'more than likely', but not yet set in stone. The user also responds to a commenter's question about pricing, suggesting that the retail price will be $650 ($200 less than the Note 7). There's no word about the other carriers.

That's not all we're told to expect. LG and T-Mobile will allegedly offer 3 options of incentives: an extra battery and 'Enhanced Hand Grip', a 'Memory Module Attachment', or a year of Hulu and 3 Vudu rentals. We're not given any more details, so don't know exactly what those add-ons mean. The enhanced hand grip could merely be a textured case in order to make the V20's metal body grippy like its predecessor, while the memory module could utilize LG's modularity hardware to expand RAM or storage (although, a microSD slot seems simpler).

We'll just have to wait until September for the whole story. Who's passing on the Note 7 and waiting out for the V20? Are you cool with the thought of LG continuing its modular design? Let us know what you think in the comments below!



from Android Authority http://ift.tt/2aWV1ts
via IFTTT

Samsung Gear S3 teaser confirms August 31 launch date

samsung-new-gear-launch-invitation
With IFA 2016 fast approaching, it's time for teasers and invitations to high-profile product announcements to be made at the event. Samsung has just released an image suggesting that the launch of the Gear S3 smartwatch will take place on August 31, which will be followed by its main press conference for the IFA event on September 1.

The latest version of Samsung's Tizen-based smartwatch will succeed the Gear S2, which was launched in 2015 at the same event. Samsung delivered its best smartwatch ever with the Gear S2, which came with a round design, an attractive interface, and a rotating bezel for navigation.

So far, the Korea-based tech giant has kept the Gear S3 well under wraps and not much is known about the upcoming smartwatch, except that it is rumored to retain the design and rotary bezel of its predecessor, but will be available in three versions, the Gear S3 Classic, Gear S3 Frontier, and Gear S3 Explorer.

samsung gear s2 review aa (19 of 24)

Samsung Gear S2

The Gear S3 Explorer edition will reportedly feature a crown, additional buttons and changeable watch bands. Apart from sharing the same design, all the three versions will also have some common features, such as sensors, including an integrated GPS, speedometer, barometer, and altimeter. Like its predecessor, you can count on the Gear S3 to also feature IP68 certification and sensor for measuring the heart rate.

If you can't be in Germany for the Gear S3 launch, Samsung will be live streaming the event and you can follow all the action on its website. In any case, we'll be there at the IFA 2016 to bring you all the details as they unfold, and you can follow our coverage here.

Do you think the Gear S3 will be even better than the Gear S2 and are you looking forward to buy it? Let us know in the comments below!



from Android Authority http://ift.tt/2bCXjUu
via IFTTT

Deal Alert: iOttie car mounts on sale today at Amazon

iOttie car holder deal Amazon

Android handsets come packed with plenty of hands-free features these days, making them useful companions when you're on the road. Of course, these days you'll want a handset mount. If you haven't picked one up yet, iOttie car smartphone holders are currently on sale with 35 percent off over at Amazon.

Four different models are currently on sale at Amazon, offering up a selection of mount types, extension features, and even Qi wireless charging features for your top of the line models. These holders should be able to grip pretty much every smartphone size, even accommodating larger 6-inch display models. Just be sure to check the dimensions of your phone and the car holder.

The cheapest model can be yours for just $12.89 right now, reaching all the way up to $35.99 for the Qi wireless charging model. Here's the list of products:

  • iOttie Easy One Touch 2 Car Mount – $19.95 $12.89 (35% off)
  • iOttie Easy One Touch Mini CD Slot – $19.95 $12.89 (35% off)
  • iOttie Easy One TOuch Mini Air Vent – $19.95 $12.89 (35% off)
  • iOttie HLCRIO132 Wireless Qi – $54.95 $35.99 (35% off)

The iOttie Amazon offer ends today, so you'll have to hurry if you want one. Just click the button below to see the complete deal selection.

Buy from Amazon!


from Android Authority http://ift.tt/2aXFREP
via IFTTT

Data Binding in Android

android-data-binding
Virtually every application works with some form of data. This data can be fetched from the Internet, a database on the target device, or even created by the application user. Typically, developers need to assign this data to the UI elements that present this data to the user. For Android apps, this is normally achieved by inflating the Activity (or Fragment) layout, locating the target UI element using findViewById, and finally assigning the appropriate data value to the element.

At Google I/O 2015, the new data binding support library was demonstrated, which can help developers perform all the above steps seamlessly using layouts (and properly defined classes and variables) only.

For this tutorial, we are going to delve into some of the features of the data binding library, and show how much more efficient and easy it can make android app development.

Getting Ready

The data binding library is a support library, and is available for android platforms from Android 2.1 (API 7) and newer. To use this library in your app, you must download the support repository using the SDK manager, and add the dataBinding element to your app build.gradle file, as shown in the snippet below

  android {      compileSdkVersion 24      buildToolsVersion "24.0.0"      dataBinding.enabled = true      ...  }  

The sample app built for this tutorial is made up of three Activity classes, with each one using increasingly more complex uses of the data binding features.

Data Binding Layout

Data binding layout files must be configured slightly differently from default layout files. There are a couple of files that could be generated automatically, and if the project doesn't use data binding, the files would be needlessly generated. The power of this is that in an app, some layout files could use data binding, and have the auto generated classes, while others do not use data binding, and have no auto generated classes.

All layout files that intend to use data binding techniques must have a layout root tag. For a basic MainActivity class, a simple activity_main.xml layout would be something like this:

  <?xml version="1.0" encoding="utf-8"?>  <layout xmlns:android="http://ift.tt/nIICcg"      xmlns:tools="http://ift.tt/LrGmb4">        <RelativeLayout          android:layout_width="match_parent"          android:layout_height="match_parent"          android:paddingBottom="@dimen/activity_vertical_margin"          android:paddingLeft="@dimen/activity_horizontal_margin"          android:paddingRight="@dimen/activity_horizontal_margin"          android:paddingTop="@dimen/activity_vertical_margin"          tools:context="com.sample.foo.databindingsample.MainActivity">            <Button              android:id="@+id/updateButton"              android:layout_width="wrap_content"              android:layout_height="wrap_content"              android:padding="@dimen/activity_horizontal_margin"              android:text="@string/button1"/>            <Button              android:id="@+id/nextActivityButton"              android:layout_width="wrap_content"              android:layout_height="wrap_content"              android:padding="@dimen/activity_vertical_margin"              android:layout_alignParentBottom="true"              android:layout_alignParentRight="true"              android:text="@string/next_activity"/>            <TextView              android:id="@+id/text_view1"              android:layout_width="wrap_content"              android:layout_height="wrap_content"              android:layout_toRightOf="@id/nextActivityButton"              android:layout_alignBaseline="@id/nextActivityButton"              android:padding="@dimen/activity_horizontal_margin"              android:text="@string/text1a"/>      </RelativeLayout>  </layout>  

Normal layout files begin by declaring the target root View, however, to declare a layout that supports data binding, the root tag is the layout tag. The actual UI View (in this case a RelativeLayout) is defined within the layout tag.

The layout tag is a special tag, that simply indicates to the build system that this layout file should be processed for data binding. Note that any layout file in your application without the layout root tag will not be processed for data binding.

Data Binding Activity

At the moment, we have a layout file that is data binding capable. However, to utilize its data binding ability, we have to load it in a different way.

Previously, you would load your layout like this:

      setContentView(R.layout.activity_main);      final Button button1 = (Button)findViewById(R.id.button1);      button.setOnClickListener(...);  

With data binding, a Binding class is auto generated from your layout file. The class is named using your layout file name by default. The default name is generated by capitalizing the first letter of each word after an underscore, removing all underscores, and adding 'Binding' to the name. As such, activity_main.xml will result in a class called ActivityMainBinding.

To associate this auto generated binding class in your code, you invoke DataBindingUtil's setContentView

      final ActivityMainBinding activityMainBinding = DataBindingUtil.setContentView(          this, R.layout.activity_main);      activityMainBinding.updateButton.setOnClickListener(new View.OnClickListener() {          @Override          public void onClick(View view) {              activityMainBinding.textView1.setText(R.string.text1b);          }      });  

In the code snippet above, you will notice that we can access the updateButton Button directly. All views with an '@+id' in a data binding layout are automatically assigned to a final field of the correct type. So Button updateButton is created for the layout Button with '@+id/updateButton', and TextView textView1 is created for the id/text_view1 TextView.

That's it. No more findViewById, and no more type casting returned views. Also, using data binding results in faster code. This is because findViewById traverses the view hierarchy every time it's called, looking for the specified view. With data binding however, the entire layout is traversed a single time, and all relevant widgets and components are assigned to fields.

Note also the change in variable name. Each variable name is camel cased, and the underscores striped. So text_view1 becomes textView1.

Binding Objects

While the ability to work without findViewById is a bonus, and the faster code is also nice, the real power of data binding becomes apparent when you begin to bind objects. Which brings us to the second activity.

Assume you have a User object. Your activity has TextViews that display the properties of the current User object, such as the firstname, lastname, etc. To achieve this, you would use findViewById in your activity, and then use setText on each field for each corresponding TextView.

With data binding, we can bind the User object to the layout file, and then assign the appropriate user fields right from the layout file.

  <?xml version="1.0" encoding="utf-8"?>  <layout xmlns:android="http://ift.tt/nIICcg"      xmlns:tools="http://ift.tt/LrGmb4"      tools:context="com.sample.foo.databindingsample.SecondActivity">        <data>          <variable              name="user"              type="com.sample.foo.databindingsample.User" />      </data>        <RelativeLayout          android:layout_width="match_parent"          android:layout_height="match_parent"          android:paddingBottom="@dimen/activity_vertical_margin"          android:paddingLeft="@dimen/activity_horizontal_margin"          android:paddingRight="@dimen/activity_horizontal_margin"          android:paddingTop="@dimen/activity_vertical_margin">            <TextView              android:id="@+id/firstnameLabel"              android:layout_width="wrap_content"              android:layout_height="wrap_content"              android:padding="@dimen/activity_horizontal_margin"              android:text="@string/firstname" />            <TextView              android:id="@+id/firstnameTextView"              android:layout_width="wrap_content"              android:layout_height="wrap_content"              android:layout_alignBaseline="@id/firstnameLabel"              android:layout_toRightOf="@id/firstnameLabel"              android:padding="@dimen/activity_horizontal_margin"              android:text="@{user.firstname}" />            <TextView              android:id="@+id/lastnameLabel"              android:layout_width="wrap_content"              android:layout_height="wrap_content"              android:layout_below="@id/firstnameLabel"              android:padding="@dimen/activity_horizontal_margin"              android:text="@string/lastname" />            <TextView              android:id="@+id/lastnameTextView"              android:layout_width="wrap_content"              android:layout_height="wrap_content"              android:layout_alignBaseline="@id/lastnameLabel"              android:layout_toRightOf="@id/lastnameLabel"              android:padding="@dimen/activity_horizontal_margin"              android:text="@{user.lastname}" />      </RelativeLayout>  </layout>  

Within the layout tag, we added a data tag before the UI view root. This data element can have variable's within it that describes a property that can be used within the layout. There can be as many variable elements within the layout data, as necessary.

In the layout above, you can see that we set the text of two TextViews using string constants (@string/firstname and @string/lastname), while the other two TextViews have their text set using the data binding "@{}" syntax (@{user.firstname} and @{user.lastname}).

The Data Object

Amazingly, the data objects that can be used for data binding do not really need to be a special type. The target object (in this case User) can be a plain old Java object

  public class User {      public String firstname;      public String lastname;      public int age;      public String gender;        public User(String firstname, String lastname, int age, String gender){          this.firstname = firstname;          this.lastname = lastname;          this.age = age;          this.gender = gender;      }  }  

or it can be a JavaBeans object

  public class User {      private String firstname;      private String lastname;      private int age;      private String gender;        public User(String firstname, String lastname, int age, String gender){          this.firstname = firstname;          this.lastname = lastname;          this.age = age;          this.gender = gender;      }      public String getFirstName() {          return this.firstName;      }      public String getLastName() {          return this.lastName;      }      public int getAge() {  return this.age;      }      public String getGender() {  return this.gender;      }  }  

As far as the data binding library is concerned, the above classes are the same. The @{user.firstname} expression that's evaluated for the above android:text attribute accesses the public firstname field for the plain old Java object above, or the getFirstname() method in the JavaBeans class.

To bind the User object in an activity, a method is automatically generated in your Binding class (set[VariableName]). In our sample, the layout data variable is named 'user', and so the method setUser() is automatically generated. The following demonstrates how to create and bind a User object in the Activity. (Note that the layout file in this case is called activity_second.xml)

      final ActivitySecondBinding secondBinding = DataBindingUtil.setContentView(          this, R.layout.activity_second);      User myUser = new User("Android", "Authority", 22, "Corporate body");      secondBinding.setUser(myUser);  

And that is all. Run the application at this point, and you'll find that the firstname is set to Android, and the lastname to Authority.

Binding Integers

Recall that our User object has an age property that is an int. We know that TextView's setText doesn't accept Integers. So how do we display the int in a TextView? By using the String.valueOf() method.

          <TextView              android:id="@+id/ageTextView"              android:layout_width="wrap_content"              android:layout_height="wrap_content"              android:layout_toRightOf="@id/ageLabel"              android:layout_alignBaseline="@id/ageLabel"              android:padding="@dimen/activity_horizontal_margin"              android:text="@{String.valueOf(user.age)}"/>  

Yes. Go ahead and try it. And let it sink in that you are actually using a Java static method call in your xml layout file.

Data binding activity sample

Imports

The above static method call magic is possible because, with the data binding library, you can actually import classes to your layout, just like in Java, and the java.lang.* package is imported automatically. Imported classes can be referenced within your layout file, for example

  <data>      <import type="android.view.View"/>  </data>  ...  <TextView     android:text="@{user.lastName}"     android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:visibility="@{user.isAdult ? View.VISIBLE : View.GONE}"/>  

As in the example above, where we called the String.valueOf method, static methods and static fields can be used in expressions.

Another example of a really cool use of imports:

  <data>  <import type="com.example.User"/>  <import type="java.util.List"/>  <variable name="user" type="User"/>  <variable name="userList" type="List<User>"/>  </data>  

Data binding expressions

The expressions used for data binding are very identical to Java expressions. Some of the Java expressions available include

  • Mathematical (+ – / * %)
  • String concatenation (+)
  • Logical (&& ||)
  • Binary (& | ^)
  • Unary (+ – ! ~)
  • Comparison (== > = > >>> <<)
  • instanceof

Another very interesting and useful operator is the null coalescing operator (??), which evaluates to the left operand if it isn't null, or the right if the left is null.

  android:text="@{user.displayname ?? user.firstname}"  

Updating Data binding objects

It's all well and good that we can easily display objects using data binding, including Lists and Maps, and virtually any other object available to our application. However, what happens if we want to update these objects. How do updates to the bound object reflect in the UI.

If you run the Activity samples above, you will notice that if you update the bound objects, the UI doesn't update as well. To unlock the full power of data binding, you will want to update the UI automatically, in response to changes to the bound object.

ObservableFields

The easiest way to achieve this, is to use an ObservableField for properties that can change.

  public class User {      public final ObservableField<String> firstname = new ObservableField<>();      public final ObservableField<String> lastname = new ObservableField<>();      public final ObservableField<Integer> age = new ObservableField<>();      public final ObservableField<String> gender = new ObservableField<>();  

Rather than accessing the values directly, you use the set age get accessor methods provided by ObservableField:

  user.firstName.set("Google");  int age = user.age.get();  

Observable data binding

Observable Objects

Another way to achieve data change notifications involves the use of Observable objects. These are objects that either implement the Observable interface, or extend the BaseObservable class. In our sample code, we implement an Observable object as shown below. In each setter method, we called the notifyPropertyChanged method, and for each getter, we added the @Bindable annotation.

  private static class User extends BaseObservable {     private String firstName;     private String lastName;     @Bindable     public String getFirstName() {     return this.firstName;     }     @Bindable     public String getLastName() {     return this.lastName;     }     public void setFirstName(String firstName) {     this.firstName = firstName;     notifyPropertyChanged(BR.firstName);     }     public void setLastName(String lastName) {     this.lastName = lastName;     notifyPropertyChanged(BR.lastName);     }  }  

Event Handling

Using data binding, you can also handle events right from the layout xml using either Method references, or Listener bindings. For the sample application, we implemented event handling using the method references technique. Your target method must conform to the signature of the listener method, while data binding performs the magic of wrapping your method reference and the owner in a listener and setting the listener on the target view.

For example, we create a class which we named ThirdActivityHandler, with a simple method called onClickButton to handle button clicks. On each click, we call getTag on the button to know how many times it has been clicked, increment by 1, display the current number of clicks on the button and call setTag to set the new number of clicks.

  public class ThirdActivityHandler {        public void onClickButton(View view) {          if(view instanceof Button){              int times = Integer.parseInt(view.getTag().toString());              times += 1;              ((Button) view).setText("Clicked " + times + " times");              view.setTag(times);          }      }    }  

In the layout file, we declare our ThirdActivityHandler variable, and set the Button android:onClick using "@{buttonHandler::onClickButton}".

  <?xml version="1.0" encoding="utf-8"?>  <layout xmlns:android="http://ift.tt/nIICcg"      xmlns:tools="http://ift.tt/LrGmb4"      tools:context="com.sample.foo.databindingsample.ThirdActivity">        <data>          <variable              name="user"              type="com.sample.foo.databindingsample.ObservableUser"/>          <variable              name="buttonHandler"              type="com.sample.foo.databindingsample.ThirdActivityHandler"/>      </data>        <RelativeLayout>      ...            <Button              android:id="@+id/nextActivityButton"              android:layout_width="wrap_content"              android:layout_height="wrap_content"              android:layout_alignParentBottom="true"              android:layout_alignParentRight="true"              android:text="@string/clicked_count"              android:tag="0"              android:onClick="@{buttonHandler::onClickButton}"/>        </RelativeLayout>  </layout>  

observablefield_databinding

Conclusion

We have barely scratched the surface of the capabilities of data binding in this tutorial. For a more in depth and longer discussion, check out the data binding android developer article. Using data binding can lead to faster development times, faster execution times and easier to read (and maintain) code.

The complete source for the app developed during this tutorial is available on github. We would love to hear some of your favorite ways to use the new library and/or questions on implementation. Happy coding.



from Android Authority http://ift.tt/2aYAxUr
via IFTTT