遷移至 ProtoLayout 命名空間

自 1.2 版起,大多數的資訊方塊版面配置 API 都位於 androidx.wear.protolayout 命名空間中。如要使用最新的 API,請完成下列程式碼遷移步驟。

更新依附元件

在應用程式模組的建構檔案中進行下列變更:

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")

更新命名空間

在應用程式的 Kotlin 和 Java 程式碼檔案中進行下列更新。或者,您也可以執行這段命名空間重新命名指令碼

  1. 將所有的 androidx.wear.tiles.material.* 匯入項目替換為 androidx.wear.protolayout.material.*。請同時為 androidx.wear.tiles.material.layouts 程式庫完成這個步驟。
  2. 將大多數其他 androidx.wear.tiles.* 匯入項目替換為 androidx.wear.protolayout.*

    androidx.wear.tiles.EventBuildersandroidx.wear.tiles.RequestBuildersandroidx.wear.tiles.TileBuildersandroidx.wear.tiles.TileService 的匯入項目應維持不變。

  3. 重新命名 TileService 和 TileBuilder 類別的幾個已淘汰的方法:

    1. TileBuilders:將 getTimeline() 重新命名為 getTileTimeline()setTimeline() 重新命名為 setTileTimeline()
    2. TileService:將 onResourcesRequest() 重新命名為 onTileResourcesRequest()
    3. RequestBuilders.TileRequest:將 getDeviceParameters() 重新命名為 getDeviceConfiguration()setDeviceParameters() 重新命名為 setDeviceConfiguration()getState() 重新命名為 getCurrentState(),以及 setState() 重新命名為 setCurrentState()