我可以从一个外部库导入和编辑代码吗? (例如 google-maps-utils)

Can i import and edit code from one external library ? (e.g. google-maps-utils)

我正在使用 google-maps-utils(仅标记聚类)并且代码是只读的。

dependencies {
    compile 'com.google.maps.android:android-maps-utils:0.5+'
}

我想在ClusterManager.java

中评论3行
    /**
     * Might re-cluster.
     */
    @Override
    public void onCameraIdle() {
        if (mRenderer instanceof GoogleMap.OnCameraIdleListener) {
            ((GoogleMap.OnCameraIdleListener) mRenderer).onCameraIdle();
        }

        // Don't re-compute clusters if the map has just been panned/tilted/rotated.
        CameraPosition position = mMap.getCameraPosition();
//        if (mPreviousCameraPosition != null && mPreviousCameraPosition.zoom == position.zoom) {
//            return;
//        }
        mPreviousCameraPosition = mMap.getCameraPosition();

        cluster();
    }
  1. 我可以将此代码导入我的应用程序并编辑这些行吗?
  2. 如果是,我该怎么做? (一步一步)

我正在尝试导入模块,但我做错了。

如果这是您将直接使用的高级 class,您可以简单地扩展此 class 并覆盖方法:

public class MyClusterManager<T extends ClusterItem> extends ClusterManager<T> {
  @Override
  public void onCameraIdle() {
    if (mRenderer instanceof GoogleMap.OnCameraIdleListener) {
      ((GoogleMap.OnCameraIdleListener) mRenderer).onCameraIdle();
    }
    CameraPosition position = mMap.getCameraPosition();
    mPreviousCameraPosition = mMap.getCameraPosition();
    cluster();
  }
}

然后:

ClusterManager<MyClusterItem> clusterManager = new MyClusterManager<MyClusterItem>();
// do something with your own clusterManager ...