Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Whats new in the support library (Google IO 2016)

Whats new in the support library (Google IO 2016)

Talk with Alan Viverette and Tenghui Zhu

Compatibility with older versions of Android is a must-have for most applications. Join members of the Android Support Library team as they walk through recent advances in backwards compatibility, explain important changes, and discuss the future of the support libraries.

Video: https://chris.banes.me/talks/2016/whats-new-in-support-library/

Chris Banes

May 17, 2016
Tweet

More Decks by Chris Banes

Other Decks in Technology

Transcript

  1. What’s New in Support Lib 23.2.0 through 24.0.0 and beyond

    +ChrisBanes @chrisbanes +AlanViverette @alanviverette +TenghuiZhu1
  2. Fragments Lifecycle improvements Synchronous commit via commitNow() • Alternative to

    commit/executePending • Preferred if not modifying back stack See What The Fragment talk for in-depth coverage Added: 24.0
  3. Notifications New visual style for conversations NotificationCompat.MessagingStyle • Large-format style

    for multi-party conversations • Compatible with Wear 2.0 devices Added: 24.0
  4. Notifications More information about what users think NotificationManagerCompat • areNotificationsEnabled()

    works on API 19+ • getImportance() for user-specified importance See What’s new with Notifications talk for more Added: 24.0
  5. Media Browsing and playback across devices MediaBrowserServiceCompat • Expose media

    content and playback controls MediaBrowserCompat • Browse content exposed by service See Universal Android Music Player for example Added: 23.2
  6. Custom Tabs Minimum SDK: 15 Alternative to embedded WebView Shares

    state with browser Customize & receive callbacks
  7. MyActivity.java // Warm up default custom tabs service in the

    background. CustomTabsClient.connectAndInitialize( this, CustomTabsClient.getPackageName(this, null)); ... // Launch a custom tab using the default service. new CustomTabsIntent.Builder() .build() .launchUrl(this, uri);
  8. // Connect to the default service. String tabSvc = CustomTabsClient.getPackageName(this,

    null); CustomTabsClient.bindCustomTabsService(this, tabSvc, new CustomTabsServiceConnection() { // Handle connect & disconnect. }); ... // Following connect, warm-up the service // and start a new session. client.warmup(0); CustomTabsSession session = client.newSession(null);
  9. // Instruct the session to pre-render likely (>50%) URLs. String

    target = "https://developer.android.com"; String[] likely = { "https://developer.android.com/preview/index.html", "https://developer.android.com/samples/index.html" }; List<Bundle> likelyList = new ArrayList<>(); for (String url : likely) { Bundle urlBundle = new Bundle(); urlBundle.putParcelable( CustomTabsService.KEY_URL, Uri.parse(likelyUrl)); likelyList.add(urlBundle); } session.mayLaunchUrl(Uri.parse(target), null, likelyList);
  10. New XML Bundle Format Merge related XML files into one

    <animated-vector android:drawable=“@drawable/icon”> ... </animated-vector>
  11. New XML Bundle Format <vector> <group> ... </group> </vector> <animated-vector

    android:drawable=“@drawable/icon”> ... </animated-vector> Merge related XML files into one
  12. New XML Bundle Format Merge related XML files into one

    <vector> <group> ... </group> </vector> <animated-vector> <aapt:attr name=“android:drawable”> </aapt:attr> </animated-vector> ...
  13. Merge related XML files into one New XML Bundle Format

    <vector> <group> ... </group> </vector> </aapt:attr> </animated-vector> <animated-vector> <aapt:attr name=“android:drawable”>
  14. PNG generation by Gradle + Simple adoption + Default gradle

    setting + Smart detection on minSdkVersion
  15. PNG generation by Gradle - No AnimatedVectorDrawable - Limited features

    of VectorDrawable - Generated PNG files sits inside APK
  16. Support Library + Static and animated VectorDrawable + XML files

    only + Full VectorDrawable features Added: 23.2
  17. Support Library - Turn on a Gradle flag android {

    defaultConfig { ... vectorDrawables.useSupportLibrary = true } }
  18. How do I use it? We had to remove it

    in 23.3.0 AppCompat (magic) Around 23.2.0 I wrote about an experimental way of using <vector> in DrawableContainers
  19. How do I use it? Around 23.2.0 I wrote about

    an experimental way of using <vector> in DrawableContainers But it’s back in 23.4.0* AppCompat (magic)
  20. How do I use it? In 23.4.0, you need to

    manually enable this: AppCompatDelegate .setCompatVectorFromResourcesEnabled(true); How do I use it? AppCompat (magic)
  21. How do I use it? Works by creating a special

    Resources instance per Context • Increased memory usage + GC
 (every instance has a drawable cache) • Can interfere with updateConfiguration() calls AppCompat (magic)
  22. MyActivity.java public class MyActivity extends AppCompatActivity { public void onCreate()

    { ... } } static { AppCompatDelegate .setCompatVectorFromResourcesEnabled(true); }
  23. How do I use it? Allows you to reference <vector>

    in DrawableContainers Works with: AppCompat (magic) • StateListDrawable <selector> • InsetDrawable
 <inset> • LayerDrawable
 <layer> • LevelListDrawable
 <level-list>
  24. MODE_NIGHT_FOLLOW_SYSTEM Follows the system night mode DEFAULT MODE_NIGHT_YES Always night

    mode MODE_NIGHT_NO Never night mode (aka day mode) MODE_NIGHT_AUTO Switches based on time of day
  25. MODE_NIGHT_FOLLOW_SYSTEM Follows the system night mode DEFAULT MODE_NIGHT_YES Always night

    mode MODE_NIGHT_NO Never night mode (aka day mode) MODE_NIGHT_AUTO Switches based on time of day
  26. MODE_NIGHT_FOLLOW_SYSTEM Follows the system night mode DEFAULT MODE_NIGHT_YES Always night

    mode MODE_NIGHT_NO Never night mode (aka day mode) MODE_NIGHT_AUTO Switches based on time of day
  27. ColorStateLists Added: 24.0 Added to the framework in API 23

    Handy when for drawable tints ...with added theme attributes
  28. <android.support.design.widget.CoordinatorLayout> <!-- Non-bottom sheet content —> </...> <LinearLayout > <!--

    Bottom sheet content --> </LinearLayout> app:layout_behavior="@string/bottom_sheet_behavior" app:behavior_peekHeight=“...” res/layout/persistent_sheet_ui.xml
  29. <android.support.design.widget.CoordinatorLayout> <!-- Non-bottom sheet content —> </...> <LinearLayout > <!--

    Bottom sheet content --> </LinearLayout> app:layout_behavior="@string/bottom_sheet_behavior" app:behavior_peekHeight=“...” res/layout/persistent_sheet_ui.xml
  30. <android.support.design.widget.CoordinatorLayout> <!-- Non-bottom sheet content —> </...> <LinearLayout > <!--

    Bottom sheet content --> </LinearLayout> app:layout_behavior="@string/bottom_sheet_behavior" app:behavior_peekHeight=“...” res/layout/persistent_sheet_ui.xml
  31. <android.support.design.widget.CoordinatorLayout> <!-- Non-bottom sheet content —> </...> <LinearLayout > <!--

    Bottom sheet content --> </LinearLayout> app:layout_behavior="@string/bottom_sheet_behavior" app:behavior_peekHeight=“...” res/layout/persistent_sheet_ui.xml
  32. <android.support.design.widget.CoordinatorLayout> <!-- Non-bottom sheet content —> </...> <LinearLayout > <!--

    Bottom sheet content --> </LinearLayout> app:layout_behavior="@string/bottom_sheet_behavior" app:behavior_peekHeight=“...” res/layout/persistent_sheet_ui.xml
  33. public class MyModalFragment { public View onCreateView(...) { // return

    content } } extends BottomSheetDialogFragment MyModalFragment.java
  34. AppBarLayout Elevation Now uses a StateListAnimator to control all elevation

    changes Similar to Button Added: 24.0 state_collapsible state_collapsed
  35. <selector ...> <item app:state_collapsible="true" app:state_collapsed="true"> <objectAnimator android:propertyName="elevation" android:valueTo="8dp" android:valueType="floatType"/> </item>

    <item> <objectAnimator android:propertyName="elevation" android:valueTo="0" android:valueType="floatType"/> </item> </selector> res/anim-v21/appbar_elevated_collapsed.xml
  36. <selector ...> <item app:state_collapsible="true" app:state_collapsed="true"> <objectAnimator android:propertyName="elevation" android:valueTo="8dp" android:valueType="floatType"/> </item>

    <item> <objectAnimator android:propertyName="elevation" android:valueTo="0" android:valueType="floatType"/> </item> </selector> res/anim-v21/appbar_elevated_collapsed.xml
  37. <selector ...> <item app:state_collapsible="true" app:state_collapsed="true"> <objectAnimator android:propertyName="elevation" android:valueTo="8dp" android:valueType="floatType"/> </item>

    <item> <objectAnimator android:propertyName="elevation" android:valueTo="0" android:valueType="floatType"/> </item> </selector> res/anim-v21/appbar_elevated_collapsed.xml
  38. Only 0.1% of devices are running API <9 Reduces v4

    method count by ~130 Improves release cycle Same package names Dropping older platforms