• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java OfflineRegion类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中com.mapbox.mapboxsdk.offline.OfflineRegion的典型用法代码示例。如果您正苦于以下问题:Java OfflineRegion类的具体用法?Java OfflineRegion怎么用?Java OfflineRegion使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



OfflineRegion类属于com.mapbox.mapboxsdk.offline包,在下文中一共展示了OfflineRegion类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: createDownload

import com.mapbox.mapboxsdk.offline.OfflineRegion; //导入依赖的package包/类
private void createDownload(final OfflineDownload offlineDownload) {
  final OfflineTilePyramidRegionDefinition definition = offlineDownload.getRegionDefinition();
  final byte[] metadata = offlineDownload.getMetadata();
  OfflineManager.getInstance(getApplicationContext())
    .createOfflineRegion(
      definition,
      metadata,
      new OfflineManager.CreateOfflineRegionCallback() {
        @Override
        public void onCreate(OfflineRegion offlineRegion) {
          offlineDownload.setRegionId(offlineRegion.getID());
          OfflineDownloadStateReceiver.dispatchStartBroadcast(getApplicationContext(), offlineDownload);
          regionLongSparseArray.put(offlineDownload.getServiceId(), offlineRegion);

          launchDownload(offlineDownload, offlineRegion);
          showNotification(offlineDownload);
        }

        @Override
        public void onError(String error) {
          OfflineDownloadStateReceiver.dispatchErrorBroadcast(getApplicationContext(), offlineDownload, error);
        }
      });
}
 
开发者ID:mapbox,项目名称:mapbox-plugins-android,代码行数:25,代码来源:OfflineDownloadService.java


示例2: cancelDownload

import com.mapbox.mapboxsdk.offline.OfflineRegion; //导入依赖的package包/类
private void cancelDownload(final OfflineDownload offlineDownload) {
  int serviceId = offlineDownload.getServiceId();
  OfflineRegion offlineRegion = regionLongSparseArray.get(serviceId);
  offlineRegion.setDownloadState(OfflineRegion.STATE_INACTIVE);
  offlineRegion.setObserver(null);
  offlineRegion.delete(new OfflineRegion.OfflineRegionDeleteCallback() {
    @Override
    public void onDelete() {
    }

    @Override
    public void onError(String error) {
      OfflineDownloadStateReceiver.dispatchErrorBroadcast(getApplicationContext(), offlineDownload, error);
    }
  });
  OfflineDownloadStateReceiver.dispatchCancelBroadcast(getApplicationContext(), offlineDownload);
  notificationManager.cancel(serviceId);
  stopSelf(serviceId);
}
 
开发者ID:mapbox,项目名称:mapbox-plugins-android,代码行数:20,代码来源:OfflineDownloadService.java


示例3: loadOfflineRegion

import com.mapbox.mapboxsdk.offline.OfflineRegion; //导入依赖的package包/类
private void loadOfflineRegion(final long id) {
  OfflineManager.getInstance(this)
    .listOfflineRegions(new OfflineManager.ListOfflineRegionsCallback() {

      @Override
      public void onList(OfflineRegion[] offlineRegions) {
        for (OfflineRegion region : offlineRegions) {
          if (region.getID() == id) {
            offlineRegion = region;
            OfflineTilePyramidRegionDefinition definition =
              (OfflineTilePyramidRegionDefinition) region.getDefinition();
            setupUI(definition);
            return;
          }
        }
      }

      @Override
      public void onError(String error) {
        Timber.e(error);
      }
    });
}
 
开发者ID:mapbox,项目名称:mapbox-plugins-android,代码行数:24,代码来源:OfflineRegionDetailActivity.java


示例4: startDownload

import com.mapbox.mapboxsdk.offline.OfflineRegion; //导入依赖的package包/类
private static void startDownload(List<Place> places, Map<OfflineRegion, OfflineRegionStatus> regionStatusMap, @SuppressWarnings("UnusedParameters") int numberOfErrors) {
    for (Place place : places) {
        if (place != null && place.hasLocation()) {
            Map.Entry<OfflineRegion, OfflineRegionStatus> regionStatus = findRegionsStatusEntry(place.getId(), regionStatusMap);
            if (regionStatus == null) {
                offlinePlaceStartDownload(place);
                Timber.i("%s map download started", place.getName());
            } else if (regionStatus.getValue() != null && !regionStatus.getValue().isComplete() && regionStatus.getValue().getDownloadState() == OfflineRegion.STATE_INACTIVE) {
                offlinePlaceResumeDownload(place, regionStatus.getKey());
                Timber.i("%s map download resumed", place.getName());
            } else {
                Timber.i("%s map already offlined", place.getName());
            }
        }
    }
}
 
开发者ID:Turistforeningen,项目名称:SjekkUT,代码行数:17,代码来源:OfflineHelper.java


示例5: setOfflineRegions

import com.mapbox.mapboxsdk.offline.OfflineRegion; //导入依赖的package包/类
public void setOfflineRegions(OfflineRegion[] offlineRegions) {
    mRegionAndStatus.clear();
    for (final OfflineRegion region : offlineRegions) {
        mRegionAndStatus.add(Pair.<OfflineRegion, OfflineRegionStatus>create(region, null));
        region.getStatus(new OfflineRegion.OfflineRegionStatusCallback() {
            @Override
            public void onStatus(OfflineRegionStatus status) {
                updateStatus(region, status);
            }

            @Override
            public void onError(String error) {
            }
        });
    }
    notifyDataSetChanged();
}
 
开发者ID:Turistforeningen,项目名称:SjekkUT,代码行数:18,代码来源:OfflineRegionAdapter.java


示例6: getRegionName

import com.mapbox.mapboxsdk.offline.OfflineRegion; //导入依赖的package包/类
private String getRegionName(OfflineRegion offlineRegion) {
    // Get the region name from the offline region metadata
    String regionName;

    try {
        byte[] metadata = offlineRegion.getMetadata();
        String json = new String(metadata, JSON_CHARSET);
        JSONObject jsonObject = new JSONObject(json);
        regionName = jsonObject.getString(JSON_FIELD_REGION_NAME);
    } catch (Exception exception) {
        Crashlytics.log("Failed to decode metadata.");
        Crashlytics.logException(exception);
        regionName = String.format(getString(R.string.region_name), offlineRegion.getID());
    }
    return regionName;
}
 
开发者ID:Hitchwiki,项目名称:MyHitchhikingSpots-for-Android,代码行数:17,代码来源:OfflineManagerActivity.java


示例7: startDownloadIfNeeded

import com.mapbox.mapboxsdk.offline.OfflineRegion; //导入依赖的package包/类
private void startDownloadIfNeeded(Intent intent, final List<OfflineRegion> presentOfflineRegions) {
    if (intent == null) {
        return;
    }
    final int size = intent.getIntExtra(SIZE_PARAM, -1);
    if (size != -1) {
        int c = 0;
        // There is some regions to download
        for (int i = 0; i < size; i++) {
            ArrayList<String> areasString = intent.getStringArrayListExtra(LIST_PARAM + i);
            LatLngBounds bounds = convertToLatLngBounds(areasString);
            OfflineRegion presentOfflineRegion = containsInOfflineRegion(presentOfflineRegions, bounds);
            if (presentOfflineRegion == null) {
                // The region has never been downloaded
                String regionName = intent.getStringExtra(REGION_NAME_PARAM);
                regionName = regionName == null ? "Region " + (presentOfflineRegions.size() + c)
                        : regionName;
                c++;
                downloadOfflineRegion(bounds, regionName);
            } else {
                //The region is already downloaded, we check if it was completed
                checkIfRegionDownloadIsCompleted(presentOfflineRegion);
            }
        }
    }
}
 
开发者ID:jawg,项目名称:osm-contributor,代码行数:27,代码来源:OfflineRegionDownloadService.java


示例8: refreshOfflineRegions

import com.mapbox.mapboxsdk.offline.OfflineRegion; //导入依赖的package包/类
private void refreshOfflineRegions() {
    offlineRegionManager.listOfflineRegions(new OfflineRegionManager.OnOfflineRegionsListedListener() {
        @Override
        public void onOfflineRegionsListed(List<OfflineRegion> offlineRegions) {
            for (final OfflineRegion region : offlineRegions) {
                region.getStatus(new OfflineRegion.OfflineRegionStatusCallback() {
                    @Override
                    public void onStatus(OfflineRegionStatus status) {
                        OfflineRegionItem regionItem = new OfflineRegionItem(region, status);
                        if (!adapter.getOfflineRegionItems().contains(regionItem)) {
                            adapter.addOfflineRegion(regionItem);
                            if (adapter.getItemCount() == 1) {
                                selectOfflineRegion(0);
                            }
                        }
                    }

                    @Override
                    public void onError(String error) {
                        Log.e(TAG, "Refresh Offline Regions error: " + error);
                    }
                });
            }
        }
    });
}
 
开发者ID:jawg,项目名称:osm-contributor,代码行数:27,代码来源:OfflineRegionsActivity.java


示例9: createOfflineRegion

import com.mapbox.mapboxsdk.offline.OfflineRegion; //导入依赖的package包/类
public void createOfflineRegion(OfflineRegionDefinition definition,
                                final String regionName,
                                final OnOfflineRegionCreatedListener listener) {
    offlineManager.createOfflineRegion(definition,
            encodeRegionName(regionName),
            new OfflineManager.CreateOfflineRegionCallback() {
        @Override
        public void onCreate(OfflineRegion offlineRegion) {
            listener.onOfflineRegionCreated(offlineRegion, regionName);
        }

        @Override
        public void onError(String error) {
            Log.e(TAG, "Create offline region error: " + error);
        }
    });
}
 
开发者ID:jawg,项目名称:osm-contributor,代码行数:18,代码来源:OfflineRegionManager.java


示例10: launchDownload

import com.mapbox.mapboxsdk.offline.OfflineRegion; //导入依赖的package包/类
private void launchDownload(final OfflineDownload offlineDownload, final OfflineRegion offlineRegion) {
  offlineRegion.setObserver(new OfflineRegion.OfflineRegionObserver() {
    @Override
    public void onStatusChanged(OfflineRegionStatus status) {
      if (status.isComplete()) {
        finishDownload(offlineDownload, offlineRegion);
        return;
      }
      progressDownload(offlineDownload, status);
    }

    @Override
    public void onError(OfflineRegionError error) {
      OfflineDownloadStateReceiver.dispatchErrorBroadcast(getApplicationContext(), offlineDownload,
        error.getReason(), error.getMessage());
      stopSelf(offlineDownload.getServiceId());
    }

    @Override
    public void mapboxTileCountLimitExceeded(long limit) {
      OfflineDownloadStateReceiver.dispatchErrorBroadcast(getApplicationContext(), offlineDownload,
        "Mapbox tile count limit exceeded:" + limit);
    }
  });

  // Change the region state
  offlineRegion.setDownloadState(OfflineRegion.STATE_ACTIVE);
}
 
开发者ID:mapbox,项目名称:mapbox-plugins-android,代码行数:29,代码来源:OfflineDownloadService.java


示例11: finishDownload

import com.mapbox.mapboxsdk.offline.OfflineRegion; //导入依赖的package包/类
private void finishDownload(OfflineDownload offlineDownload, OfflineRegion offlineRegion) {
  if (notificationBuilder != null) {
    notificationManager.cancel(offlineDownload.getServiceId());
  }
  OfflineDownloadStateReceiver.dispatchSuccessBroadcast(this, offlineDownload);
  offlineRegion.setDownloadState(OfflineRegion.STATE_INACTIVE);
  offlineRegion.setObserver(null);
  regionLongSparseArray.remove(offlineDownload.getServiceId());
  stopSelf(offlineDownload.getServiceId());
}
 
开发者ID:mapbox,项目名称:mapbox-plugins-android,代码行数:11,代码来源:OfflineDownloadService.java


示例12: getActiveDownloadForOfflineRegion

import com.mapbox.mapboxsdk.offline.OfflineRegion; //导入依赖的package包/类
/**
 * Get the OfflineDownload for an offline region, returns null if no download is active for region.
 *
 * @param offlineRegion the offline region to get related offline download for
 * @return the active offline download, null if not downloading the region.
 */
@Nullable
public OfflineDownload getActiveDownloadForOfflineRegion(OfflineRegion offlineRegion) {
  OfflineDownload offlineDownload = null;
  if (!offlineDownloads.isEmpty()) {
    for (OfflineDownload download : offlineDownloads) {
      if (download.getRegionId() == offlineRegion.getID()) {
        offlineDownload = download;
      }
    }
  }
  return offlineDownload;
}
 
开发者ID:mapbox,项目名称:mapbox-plugins-android,代码行数:19,代码来源:OfflinePlugin.java


示例13: onItemClick

import com.mapbox.mapboxsdk.offline.OfflineRegion; //导入依赖的package包/类
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
  OfflineRegion region = adapter.getItem(position);
  Intent intent = new Intent(this, OfflineRegionDetailActivity.class);
  intent.putExtra(OfflineRegionDetailActivity.KEY_REGION_ID_BUNDLE, region.getID());
  startActivity(intent);
}
 
开发者ID:mapbox,项目名称:mapbox-plugins-android,代码行数:8,代码来源:OfflineRegionListActivity.java


示例14: loadOfflineRegions

import com.mapbox.mapboxsdk.offline.OfflineRegion; //导入依赖的package包/类
private void loadOfflineRegions() {
  OfflineManager.getInstance(this).listOfflineRegions(new OfflineManager.ListOfflineRegionsCallback() {
    @Override
    public void onList(OfflineRegion[] offlineRegions) {
      if (offlineRegions != null) {
        adapter.setOfflineRegions(Arrays.asList(offlineRegions));
      }
    }

    @Override
    public void onError(String error) {
      Toast.makeText(OfflineRegionListActivity.this, "Error loading regions " + error, Toast.LENGTH_LONG).show();
    }
  });
}
 
开发者ID:mapbox,项目名称:mapbox-plugins-android,代码行数:16,代码来源:OfflineRegionListActivity.java


示例15: offlinePlaceStartDownload

import com.mapbox.mapboxsdk.offline.OfflineRegion; //导入依赖的package包/类
private static void offlinePlaceStartDownload(final Place place) {
    final Context context = SjekkUTApplication.getContext();

    // Set up the OfflineManager
    OfflineManager offlineManager = OfflineManager.getInstance(context.getApplicationContext());

    // Create a bounding box for the offline region
    LatLngBounds latLngBounds = Utils.getLatLngBounds(place.getLocation(), MAP_OFFLINE_RADIUS);

    // Define the offline region
    OfflineTilePyramidRegionDefinition definition = new OfflineTilePyramidRegionDefinition(
            context.getString(R.string.mapbox_style),
            latLngBounds,
            MAP_OFFLINE_MINZOOM,
            MAP_OFFLINE_MAXZOOM,
            context.getResources().getDisplayMetrics().density);

    byte[] metaData = GsonSingleton.gson().toJson(new OfflineRegionMetadata(place)).getBytes(Charset.defaultCharset());

    // Create the region asynchronously
    offlineManager.createOfflineRegion(definition, metaData, new OfflineManager.CreateOfflineRegionCallback() {
        @Override
        public void onCreate(OfflineRegion offlineRegion) {
            sOfflineRegionExecutor.schedule(new OfflineRegionTask(place, offlineRegion), OFFLINE_REGIONTASK_DELAY, TimeUnit.SECONDS);
        }

        @Override
        public void onError(String error) {
            Timber.e("Error: %s", error);
        }
    });
}
 
开发者ID:Turistforeningen,项目名称:SjekkUT,代码行数:33,代码来源:OfflineHelper.java


示例16: findRegionsStatusEntry

import com.mapbox.mapboxsdk.offline.OfflineRegion; //导入依赖的package包/类
private static Map.Entry<OfflineRegion, OfflineRegionStatus> findRegionsStatusEntry(String placeId, Map<OfflineRegion, OfflineRegionStatus> regionStatusMap) {
    for (Map.Entry<OfflineRegion, OfflineRegionStatus> entry : regionStatusMap.entrySet()) {
        if (entry.getKey() == null)
            continue;
        try {
            OfflineRegionMetadata metadata = GsonSingleton.gson().fromJson(new String(entry.getKey().getMetadata(), Charset.defaultCharset()), OfflineRegionMetadata.class);
            if (metadata.placeId != null && metadata.placeId.equals(placeId))
                return entry;
        } catch (JsonSyntaxException ignored) {
        }
    }
    return null;
}
 
开发者ID:Turistforeningen,项目名称:SjekkUT,代码行数:14,代码来源:OfflineHelper.java


示例17: OfflineRegionTask

import com.mapbox.mapboxsdk.offline.OfflineRegion; //导入依赖的package包/类
OfflineRegionTask(Place place, OfflineRegion offlineRegion) {
    Context context = SjekkUTApplication.getContext();
    mLatch = new CountDownLatch(1);
    mOfflineRegion = offlineRegion;
    mOfflineRegion.setDeliverInactiveMessages(true);
    mOfflineRegion.setObserver(new DownloadNotificationObserver(
            context,
            context.getString(R.string.offlinemap_content_progress, place.getName()),
            mLatch));
}
 
开发者ID:Turistforeningen,项目名称:SjekkUT,代码行数:11,代码来源:OfflineHelper.java


示例18: onStatusChanged

import com.mapbox.mapboxsdk.offline.OfflineRegion; //导入依赖的package包/类
@Override
public void onStatusChanged(OfflineRegionStatus status) {
    long currentMillis = System.currentTimeMillis();
    long delta = currentMillis - lastUpdateMillis;
    if (status.isComplete()) {
        mLatch.countDown();
        if (sOfflineRegionExecutor.getQueue().isEmpty()) {
            notificationManager.cancel(R.id.download_notification);
        }
    } else {
        switch (status.getDownloadState()) {
            case OfflineRegion.STATE_INACTIVE:
                mLatch.countDown();
                break;
            case OfflineRegion.STATE_ACTIVE:
                if (status.isRequiredResourceCountPrecise() && delta > PROGRESS_UPDATE_DELTA_MS) {
                    lastUpdateMillis = currentMillis;
                    double percentage = status.getRequiredResourceCount() >= 0
                            ? (100.0 * status.getCompletedResourceCount() / status.getRequiredResourceCount()) :
                            0.0;
                    notificationBuilder.setContentTitle(mContext.getString(R.string.offlinemap_title, getPendingAndActiveMapDownloads()));
                    notificationBuilder.setProgress(100, (int) percentage, false);
                    notificationManager.notify(R.id.download_notification, notificationBuilder.build());
                }
                break;
        }
    }
}
 
开发者ID:Turistforeningen,项目名称:SjekkUT,代码行数:29,代码来源:OfflineHelper.java


示例19: onBindViewHolder

import com.mapbox.mapboxsdk.offline.OfflineRegion; //导入依赖的package包/类
@Override
public void onBindViewHolder(final ViewHolder holder, int position) {
    Context context = holder.itemView.getContext();
    Pair<OfflineRegion, OfflineRegionStatus> pair = mRegionAndStatus.get(position);
    String unknown = context.getString(R.string.offlineregion_unknown);
    String regionName = context.getString(R.string.offlineregion_name, unknown);
    String regionId = context.getString(R.string.offlineregion_regionid, unknown);
    String placeId = context.getString(R.string.offlineregion_placeid, unknown);
    String downloadState = context.getString(R.string.offlineregion_downloadState, unknown);
    String downloadComplete = context.getString(R.string.offlineregion_downloadComplete, unknown);
    String regionSize = context.getString(R.string.offlineregion_sizeMB, unknown);
    OfflineRegion region = pair.first;
    if (region != null) {
        regionId = context.getString(R.string.offlineregion_regionid, Long.toString(region.getID()));
        try {
            OfflineRegionMetadata metadata = GsonSingleton.gson().fromJson(new String(region.getMetadata(), Charset.defaultCharset()), OfflineRegionMetadata.class);
            regionName = context.getString(R.string.offlineregion_name, metadata.placeName);
            placeId = context.getString(R.string.offlineregion_placeid, metadata.placeId);
        } catch (JsonSyntaxException ignored) {
        }
    }
    OfflineRegionStatus status = pair.second;
    if (status != null) {
        downloadState = status.getDownloadState() == OfflineRegion.STATE_ACTIVE ?
                context.getString(R.string.offlineregion_downloadState, "Aktiv") :
                context.getString(R.string.offlineregion_downloadState, "Inaktiv");
        downloadComplete = status.isComplete() ?
                context.getString(R.string.offlineregion_downloadComplete, "Ja") :
                context.getString(R.string.offlineregion_downloadComplete, "Nei");
        regionSize = context.getString(R.string.offlineregion_sizeMB, String.format(Locale.getDefault(), "%.2f", status.getCompletedResourceSize() / (1024.0 * 1024.0)));
    }
    holder.mRegionName.setText(regionName);
    holder.mRegionId.setText(regionId);
    holder.mPlaceId.setText(placeId);
    holder.mDownloadState.setText(downloadState);
    holder.mDownloadComplete.setText(downloadComplete);
    holder.mRegionSize.setText(regionSize);
}
 
开发者ID:Turistforeningen,项目名称:SjekkUT,代码行数:39,代码来源:OfflineRegionAdapter.java


示例20: updateStatus

import com.mapbox.mapboxsdk.offline.OfflineRegion; //导入依赖的package包/类
private void updateStatus(OfflineRegion region, OfflineRegionStatus status) {
    boolean dirty = false;
    for (int i = 0; i < mRegionAndStatus.size(); ++i) {
        Pair<OfflineRegion, OfflineRegionStatus> pair = mRegionAndStatus.get(i);
        if (pair.first != null && pair.first.getID() == region.getID()) {
            mRegionAndStatus.set(i, Pair.create(region, status));
            dirty = true;
        }
    }
    if (dirty) {
        notifyDataSetChanged();
    }
}
 
开发者ID:Turistforeningen,项目名称:SjekkUT,代码行数:14,代码来源:OfflineRegionAdapter.java



注:本文中的com.mapbox.mapboxsdk.offline.OfflineRegion类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java KeyboardShortcutGroup类代码示例发布时间:2022-05-23
下一篇:
Java Book类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap