Di chuyển sang không gian tên ProtoLayout

Kể từ phiên bản 1.2, hầu hết API Bố cục thẻ thông tin đều nằm trong không gian tên androidx.wear.protolayout. Để sử dụng các API mới nhất, hãy hoàn tất các bước di chuyển sau đây trong mã của bạn.

Cập nhật phần phụ thuộc

Trong tệp bản dựng của mô-đun ứng dụng, hãy thực hiện các thay đổi sau:

Groovy

  // Remove
  implementation 'androidx.wear.tiles:tiles-material:version'

  // Include additional dependencies
  implementation "androidx.wear.protolayout:1.2.0-alpha01"
  implementation "androidx.wear.protolayout-material:1.2.0-alpha01"
  implementation "androidx.wear.protolayout-expression:1.2.0-alpha01"

  // Update
  implementation "androidx.wear.tiles:tiles:1.4.0-alpha01"

Kotlin

  // Remove
  implementation("androidx.wear.tiles:tiles-material:version")

  // Include additional dependencies
  implementation("androidx.wear.protolayout:1.2.0-alpha01")
  implementation("androidx.wear.protolayout-material:1.2.0-alpha01")
  implementation("androidx.wear.protolayout-expression:1.2.0-alpha01")

  // Update
  implementation("androidx.wear.tiles:tiles:1.4.0-alpha01")

Cập nhật không gian tên

Trong các tệp mã dựa trên Kotlin và Java của ứng dụng, hãy cập nhật như sau. Ngoài ra, bạn có thể thực thi tập lệnh đổi tên không gian tên này.

  1. Thay thế tất cả các lệnh nhập androidx.wear.tiles.material.* bằng androidx.wear.protolayout.material.*. Bạn cũng cần hoàn tất bước này cho thư viện androidx.wear.tiles.material.layouts.
  2. Thay thế hầu hết các lệnh nhập androidx.wear.tiles.* khác bằng androidx.wear.protolayout.*.

    Các lệnh nhập cho androidx.wear.tiles.EventBuilders, androidx.wear.tiles.RequestBuilders, androidx.wear.tiles.TileBuildersandroidx.wear.tiles.TileService sẽ giữ nguyên.

  3. Đổi tên một vài phương thức không dùng nữa trong các lớp TileService và TileBuilder:

    1. TileBuilders: getTimeline() thành getTileTimeline()setTimeline() thành setTileTimeline()
    2. TileService: onResourcesRequest() thành onTileResourcesRequest()
    3. RequestBuilders.TileRequest: getDeviceParameters() thành getDeviceConfiguration(), setDeviceParameters() thành setDeviceConfiguration(), getState() thành getCurrentState()setState() thành setCurrentState()