Android Jetpack Weekly #7

Review of the most interesting updates in Android Jetpack libraries

If you now Russian and want to know more about Android development you can subscribe to Android Broadcast Telegram Channel

Update in AndroidX for period September 1–8 2019. The week was very rich and many stable versions were released:

Fragment

1.1.0 (compare to 1.0.0)

  • FragmentScenario class for testing Fragment in isolation
  • Now you can set a FragmentFractory on a FragmentManager to override creation of fragment. Now default constructor isn’t required for Fragment. Welcome injection into constructors with Dagger 2!
  • Kotlin Property Delegates for ViewModels: by viewModels() and by activityViewModels()
  • Max Lifecycle state for a Fragment by calling setMaxLifecycle() on a FragmentTransaction. It allows setting a ceiling for the state of an active fragment in this FragmentManager.
    The new API replace deprecatedsetUserVisibleHint(). ViewPager 1 added support of Max Lifecycle in FragmentPagerAdapter and FragmentStatePagerAdapter in constructors.
  • Set layout id for Fragment and FragmentActivity via new constructors. No need to override Fragment.onCreateView() or call Activity.sentContentView()
  • Postpone Fragment transaction with a timeout using postponeEnterTransition().

1.2.0-alpha03 (compare to 1.2.0-alpha02)

  • API changes
  • Bug fixes

Preference

1.1.0

  • PreferenceFragment and other classes using framework Fragments have been deprecated; you should use PreferenceFragmentCompat and other *compat classes instead
  • You can now set a SummaryProvider on a Preference to dynamically configure its summary (second text) whenever the Preference is updated or becomes visible to the user. See the guide for more information.
  • Added EditTextPreference.OnBindEditTextListener interface that allows customizing the EditText displayed in the corresponding dialog after the dialog has been bound. This is a direct replacement for using attributes such as android:inputType directly on the EditTextPreference, which is not supported in the AndroidX library. See the guide for more information.
  • Added possibility to show a context menu when long pressing on the Preference that allows copying the summary of the Preference. Use Preference.setCopyingEnabled() to enable/disable that.
  • Updated SeekBarPreference styling to match Material specifications: the value label is now hidden by default; the value label now updates while the SeekBar is being dragged, instead of when it is released; you should avoid setting a summary on a SeekBarPreference
  • SeekBarPreference: Added support for continuous updates, allowing the SeekBar to update its saved value
  • A large number of bug fixes, style updates, API level compatibility fixes, and general QOL (quality of life) improvements.

Lifecycle

2.1.0 (compare to 2.0.0)

2.2.0-alpha04

Activity

1.0.0

  • New ComponentActivity servers as the new base class for FragmentActivity
  • Kotlin Property Delegates for ViewModels: by viewModels()
  • As a composable alternative to overriding onBackPressed(), you can now register a OnBackPressedCallback from any LifecycleOwner (such as a Fragment) to intercept system back button events.
  • onRetainCustomNonConfigurationInstance() and the related getLastCustomNonConfigurationInstance() APIs have been deprecated. Use ViewModel instead.

1.1.0-alpha03 (compare to 1.1.0-alpha02)

  • Dependencies updates
  • Bug fixes

AppCompat

1.1.0 (compare to 1.0.0)

  • Dark Mode Improvements: MODE_NIGHT_AUTO_BATTERY was replaced with MODE_NIGHT_AUTO
  • AppCompatActivity now transitively extends from ComponentActivity
  • Set layout id for AppComponentActivity via new constructors. No need to call Activity.sentContentView()

SavedState

1.0.0

This is a set of APIs that allow developers to plugin components into the restore / saveInstanceState process. That API provides a single way to how to save the state of any class without keeping a direct reference to it.

CameraX

Camera2 & Core 1.0.0-alpha05

  • APIs refactoring
  • Added CameraControl API w/Tap-to-Focus APIs
  • Enforce calling some API methods on the Main (UI) thread
  • API improvements
  • Bug fixes

Core

1.1.0

  • Updated accessibility APIs to match the Android 10 platform accessibility APIs
  • Added improvements to Nested Scrolling; see NestedScrollingChild3 and NestedScrollingParent3.
  • This library no longer depends on the androidx.collection dependency as part of its API
  • Worked around an IPC compatibility issue caused by refactor to androidx
  • Added a variety of fixes for AppCompat DayNight

Media

1.1.0

Media2

Media2 is the next generation of following Media APIs: MediaSession, MediaController, MediaBrowser, MediaBrowserService, VideoView, and MediaControlView.

1.0.0

  • Base on ExoPlayer
  • Support of custom layout in MediaSessions
  • Better look and feel
  • New possibilities compare to original Media API

MediaRouter

1.1.0

Dynamic group support was added:

  • Allows users to add or remove route devices dynamically.
  • To enable a dynamic group, call MediaRouteButton.enableDynamicGroup(); the app shows a new dialog for the dynamic group
  • The installed MediaRouteProvider should also support dynamic group to actually enable the functionality.

Navigation

2.1.0

  • Scoping ViewModels to a navigation graph: You can now create ViewModels that are scoped at the navigation graph level using the by navGraphViewModels() property delegate for Kotlin users or by using the NavController.getViewModelStoreOwner() . See Share UI-related data between destinations.
  • Dialog destinations: You can now create <dialog> destinations that will show a DialogFragment when you navigate to them. NavHostFragment supports dialog destinations by default. See Create a destination from a DialogFragment.
  • Navigating by Uri: You can now navigate using a Uri, which uses the <deepLink> you’ve added to a destination to navigate there. It helps to organizae navigation in multimodule projects. See Navigate using Uri.
  • NavHostController: APIs used specifically for constructing a custom NavHost have been moved to NavHostController, allowing implementations to connect their NavController to the hosting LifecycleOwner, OnBackPressedDispatcher, and ViewModelStore.

2.2.0-alpha02

  • Deep links with query parameters now support reordered query parameters: arguments that have a default value or are nullable are now optional when matching deep links.
  • You can now call NavController.getBackStackEntry(), passing in the ID of a destination or navigation graph on the back stack. The returned NavBackStackEntry provides a Navigation-driven LifecycleOwner, ViewModelStoreOwner (the same returned by NavController.getViewModelStoreOwner()), and SavedStateRegistryOwner, in addition to providing the arguments used to start that destination.
  • Bug fixes

ShareTarget

1.0.0-beta01

VectorDrawable

1.1.0 (since 1.0.0)

  • fillType is now supported in ClipPath
  • Tinting is now supported using ColorStateLists defined with theme attrs in VectorDrawableCompat
  • Bug fixes

WebKit

1.1.0-beta01

  • New InternalStoragePathHandler in WebViewAssetLoader to load files from the app's data directory.
  • Small API changes
  • Bug fixe

Tech PR Manager at Surf, Android Developer, GDE, creator of androidbroadcast.dev