2

我必须在 Xamarin 的 Android 绑定项目中绑定通用 Java 类。下面是我添加的普通类绑定的代码metadata.xml

<add-node path="/api/package[@name='com.phunware.mapping.manager']">
    <interface abstract="true" deprecated="not deprecated" extends="java.lang.Object" extends-generic-aware="java.lang.Object" final="false" name="Callback" static="false" visibility="public">
      <method abstract="true" deprecated="not deprecated" final="false" name="onSuccess" native="false" return="void" static="false" synchronized="false" visibility="public">
        <parameter name="building" type="com.phunware.mapping.model.Building"/>
      </method>
    </interface>
  </add-node>

<add-node path="/api/package[@name='com.phunware.mapping.manager']/class[@name='PhunwareMapManager']">
    <method abstract="false" deprecated="not deprecated" final="false" name="addBuilding" native="false" return="com.phunware.mapping.manager.PhunwareMapManager" static="false" synchronized="false" visibility="public">
      <parameter name="buildingId" type="long"/>
      <parameter name="callback" type="com.phunware.mapping.manager.Callback"/>
    </method>
  </add-node>

等效的 java 类和方法被绑定如下。

package com.phunware.mapping.manager;

public interface Callback<T> {
    void onSuccess(T var1);

    void onFailure(Throwable var1);
}

mapManager.addBuilding(buildingId,
                new Callback<Building>() {
                    @Override
                    public void onSuccess(Building building) {
                        Log.d(TAG, "Building loaded successfully");
                        currentBuilding = building;

                        // Populate floor spinner
                        spinnerAdapter.clear();
                        spinnerAdapter.addAll(building.getBuildingOptions().getFloors());

                        // Set building to initial floor value
                        FloorOptions initialFloor = building.initialFloor();
                        building.selectFloor(initialFloor.getLevel());

                        // Animate the camera to the building at an appropriate zoom level
                        CameraUpdate cameraUpdate = CameraUpdateFactory
                                .newLatLngBounds(initialFloor.getBounds(), 4);
                        phunwareMap.getGoogleMap().animateCamera(cameraUpdate);
                    }

如果我尝试将此回调类绑定为普通类,addBuilding则方法不可见,因为它将泛型类作为参数。

请求帮助我找到一种方法来处理metadata.xml.

4

0 回答 0