Introduction to android studio 2.0 and Data Binding Library Kaushal Dhruw @drulabs
Data binding library (Beta) • Write apps faster. • Minimize glue code for UI. • No more findViewById(R.id…) • Bind data and UI with minimum lines of code. • Move basic UI logic from java class to xml layout file. • Bind data (custom variables) and events. Define custom attributes. • Supported all the way back to Android 2.1 • Available on android studio 1.3+ (Gradle plugin 1.5+ required)
Setting up studio for DBL • Prerequisites - Android studio 1.3 +, Gradle plugin 1.5.0-alpha1 + • Project gradle file: • Module gradle file • And done...
Writing Data Bind layouts Change the root element of layout… To this Old_sample_layout.xml Dbl_layout.xml
Writing Data Bind layouts… • What happens when an xml layout is defined with layout root tag? • A binding file is generated. For prev example it will be DblLayoutBinding.java • This contains references to all the child views (as public final fields). • This binding file can now be used to populate data • What is that <data> tag? • In data tag we tell the layout processor that a java class will be used to populate data. • We can import custom or android classes inside data element. • Multiple variable declaration and imports are possible inside data tag. • Custom attributes and more in Demo…
Without DBL… With DBL
Some Data binding expressions android:visibility="@{vItem.even ? View.VISIBLE : View.INVISIBLE}" android:text=@{vItem.shortName.substring(0,7)}; android:text="@{user.displayName ?? user.lastName}" android:text="@{@string/nameFormat(firstName, lastName)}" android:text="@{@plurals/banana(bananaCount)}“ app:ImageURL="@{vItem.imageUrl}“ app:loadingImage="@drawable/img_loading“ Binding Custom attributes @BindingAdapter("bind:imageURL") /*can add more attributes here*/ public static void loadImage(ImageView img, String url) { Picasso.with(img.getContext()).load(url).into(img); }
Android studio 2.0 Preview 6 (released on Jan 20, 2016)
What is android studio??? • Google’s IDE for android development. • Built in support for Google cloud platform. • Flexible Gradle-based build system. • Built on top of latest IntelliJ IDEA platform. • Multi screen app development. • Latest version 1.5.1. • Available on android developer site. http://developer.android.com/sdk/index.html
Some changes since studio 1.0 (DEC 2014) • New Memory / GPU / CPU monitor • Vector asset studio. • Theme editor • Integrated SDK manager. • Data binding support and HAXM optimizations • Enable AdMob and Analytics from within android studio. • Live templates for quick code insertion. • And many more…
• Available in stable build channel. • http://tools.android.com/download/studio/builds/2-0-preview. • Not recommended (still in preview stage). • Canary channel (Preview 6 available on Jan-20,2016). • http://tools.android.com/download/studio/canary/latest • Download a separate build. How to get the 2.0 preview?
• IDE Enhancements • Build System • Android Emulators What’s new in studio 2.0 (preview)
• IntelliJ 15 support (15.0.2). • New GPU profiler (experimental preview). • Google search deep linking support in built. • Instant Run (Continued…) • Lot of UI improvements. IDE Enhancements
• Improved dx merger (Build tools 23.0.2+, Gradle 2.0). • Pre-dexing dependencies. Gradle build 2-2.5 times faster. • New experimental shrinker for debug mode. • Shrinking only. No Obfuscation No Optimization. • Overall build – deploy – install cycle is ~1.5 times faster. • New protocol for ADB push / pull. • Huge speed improvement. • Instant Run (Gradle 2.0-alpha5+, gradlew 2.10). • Hot swap, cold swap, freeze swap Build System
• Completely new UI with extended controls. • Control almost every feature of emulated device • Drag and drop APKs and files. • Send SMS, receive calls. • System keyboard support & Resizing. • Finger printing support. • Select number of cores (experimental and based on number of cores in system) • And more in demo. Emulator 2.0 (requires SDK tools 25.0+)
How long would it take to develop this? Divide that time by 2 with DBL Even lesser with instant run
Introduction to android studio 2.0 and data binding library

Introduction to android studio 2.0 and data binding library

  • 1.
    Introduction to androidstudio 2.0 and Data Binding Library Kaushal Dhruw @drulabs
  • 2.
    Data binding library(Beta) • Write apps faster. • Minimize glue code for UI. • No more findViewById(R.id…) • Bind data and UI with minimum lines of code. • Move basic UI logic from java class to xml layout file. • Bind data (custom variables) and events. Define custom attributes. • Supported all the way back to Android 2.1 • Available on android studio 1.3+ (Gradle plugin 1.5+ required)
  • 3.
    Setting up studiofor DBL • Prerequisites - Android studio 1.3 +, Gradle plugin 1.5.0-alpha1 + • Project gradle file: • Module gradle file • And done...
  • 4.
    Writing Data Bindlayouts Change the root element of layout… To this Old_sample_layout.xml Dbl_layout.xml
  • 5.
    Writing Data Bindlayouts… • What happens when an xml layout is defined with layout root tag? • A binding file is generated. For prev example it will be DblLayoutBinding.java • This contains references to all the child views (as public final fields). • This binding file can now be used to populate data • What is that <data> tag? • In data tag we tell the layout processor that a java class will be used to populate data. • We can import custom or android classes inside data element. • Multiple variable declaration and imports are possible inside data tag. • Custom attributes and more in Demo…
  • 6.
  • 7.
    Some Data bindingexpressions android:visibility="@{vItem.even ? View.VISIBLE : View.INVISIBLE}" android:text=@{vItem.shortName.substring(0,7)}; android:text="@{user.displayName ?? user.lastName}" android:text="@{@string/nameFormat(firstName, lastName)}" android:text="@{@plurals/banana(bananaCount)}“ app:ImageURL="@{vItem.imageUrl}“ app:loadingImage="@drawable/img_loading“ Binding Custom attributes @BindingAdapter("bind:imageURL") /*can add more attributes here*/ public static void loadImage(ImageView img, String url) { Picasso.with(img.getContext()).load(url).into(img); }
  • 8.
    Android studio 2.0Preview 6 (released on Jan 20, 2016)
  • 9.
    What is androidstudio??? • Google’s IDE for android development. • Built in support for Google cloud platform. • Flexible Gradle-based build system. • Built on top of latest IntelliJ IDEA platform. • Multi screen app development. • Latest version 1.5.1. • Available on android developer site. http://developer.android.com/sdk/index.html
  • 10.
    Some changes sincestudio 1.0 (DEC 2014) • New Memory / GPU / CPU monitor • Vector asset studio. • Theme editor • Integrated SDK manager. • Data binding support and HAXM optimizations • Enable AdMob and Analytics from within android studio. • Live templates for quick code insertion. • And many more…
  • 11.
    • Available instable build channel. • http://tools.android.com/download/studio/builds/2-0-preview. • Not recommended (still in preview stage). • Canary channel (Preview 6 available on Jan-20,2016). • http://tools.android.com/download/studio/canary/latest • Download a separate build. How to get the 2.0 preview?
  • 12.
    • IDE Enhancements •Build System • Android Emulators What’s new in studio 2.0 (preview)
  • 13.
    • IntelliJ 15support (15.0.2). • New GPU profiler (experimental preview). • Google search deep linking support in built. • Instant Run (Continued…) • Lot of UI improvements. IDE Enhancements
  • 14.
    • Improved dxmerger (Build tools 23.0.2+, Gradle 2.0). • Pre-dexing dependencies. Gradle build 2-2.5 times faster. • New experimental shrinker for debug mode. • Shrinking only. No Obfuscation No Optimization. • Overall build – deploy – install cycle is ~1.5 times faster. • New protocol for ADB push / pull. • Huge speed improvement. • Instant Run (Gradle 2.0-alpha5+, gradlew 2.10). • Hot swap, cold swap, freeze swap Build System
  • 15.
    • Completely newUI with extended controls. • Control almost every feature of emulated device • Drag and drop APKs and files. • Send SMS, receive calls. • System keyboard support & Resizing. • Finger printing support. • Select number of cores (experimental and based on number of cores in system) • And more in demo. Emulator 2.0 (requires SDK tools 25.0+)
  • 16.
    How long wouldit take to develop this? Divide that time by 2 with DBL Even lesser with instant run

Editor's Notes

  • #2 Welcome!!! Introduction
  • #3 The idea is to connect data model to UI elements Binds data to UI view model No Reflection. Preprocessing is done at run time It is a support library
  • #5 Migrating from old layouts to Data bind layouts is very easy
  • #10 Also explain some of the new features since earlier versions of android studio
  • #11 Also explain some of the new features since earlier versions of android studio
  • #12 Do not upgrade your current IDE, instead have a separate copy of studio 2.0 till it is in preview stage
  • #13 Significant huge improvements in android studio 2.0. Eclipse users please switch to android studio now. Much faster and developer friendly
  • #14 Other UI improvements like Project structure Welcome screen Deployment targets AVD manager Instant run is the ability to deploy code changes on the fly, more will be covered in later. Discussion topic: How does it work
  • #15 Hot swap – deploy code changes without app restart (App is running) Cold swap – deploy incremental changes with app restart (App is running) Freeze swap – build and deploy incrementally (app is not running) Freeze swap is out of scope DBL supported by instant run
  • #16 With this release emulators will be preferred over actual devices Get the latest SDK tools from tools preview channel in SDK manager Send SMS and receive calls, without having a second emulator What can be controlled: GPS location, signal strength, battery, data roaming 2G/3G/No service Power button