Java源码示例:com.amap.api.maps.offlinemap.OfflineMapCity
示例1
/**
* 继续下载所有暂停中
*/
private void startAllInPause() {
if (amapManager == null) {
return;
}
for (OfflineMapCity mapCity : amapManager.getDownloadingCityList()) {
if (mapCity.getState() == OfflineMapStatus.PAUSE) {
try {
amapManager.downloadByCityName(mapCity.getCity());
} catch (AMapException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
示例2
@Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder viewHolder;
if (convertView != null) {
viewHolder = (ViewHolder) convertView.getTag();
} else {
viewHolder = new ViewHolder();
currentOfflineChild = new OfflineChild(mContext,
mOfflineMapManager);
convertView = currentOfflineChild.getOffLineChildView();
viewHolder.mOfflineChild = currentOfflineChild;
convertView.setTag(viewHolder);
}
OfflineMapCity offlineMapCity = (OfflineMapCity) getItem(position);
viewHolder.mOfflineChild.setOffLineCity(offlineMapCity);
return convertView;
}
示例3
public void getList() {
if (null != amapManager) {
List<OfflineMapCity> list = new ArrayList<>();
list.addAll(amapManager.getDownloadOfflineMapCityList());
list.addAll(amapManager.getDownloadingCityList());
if (null == cityAdapter) {
cityAdapter = new AmapDownloadCityAdapter(getActivity(), list);
cityAdapter.setOnClickAmapDownloadOptionsListener(this);
listOffline.setAdapter(cityAdapter);
} else {
cityAdapter.setList(list, true);
cityAdapter.notifyDataSetChanged();
}
}
}
示例4
@Override
public void onClickAmapDownloadOptions(String option, OfflineMapCity city) {
if ("删除".equals(option)){
delCity(city);
}else if ("更新".equals(option)){
updateCity(city);
}else if ("开始".equals(option)){
try {
amapManager.downloadByCityCode(city.getCode());
} catch (AMapException e) {
e.printStackTrace();
onMessage("下载失败");
}
}else if ("暂停".equals(option)){
amapManager.pause();
}
}
示例5
public void getList() {
if (null != amapManager) {
List<OfflineMapCity> list = new ArrayList<>();
list.addAll(amapManager.getDownloadOfflineMapCityList());
list.addAll(amapManager.getDownloadingCityList());
if (null == cityAdapter) {
cityAdapter = new AmapDownloadCityAdapter(getActivity(), list);
cityAdapter.setOnClickAmapDownloadOptionsListener(this);
listOffline.setAdapter(cityAdapter);
} else {
cityAdapter.setList(list, true);
cityAdapter.notifyDataSetChanged();
}
}
}
示例6
@Override
public void onClickAmapDownloadOptions(String option, OfflineMapCity city) {
if ("删除".equals(option)){
delCity(city);
}else if ("更新".equals(option)){
updateCity(city);
}else if ("开始".equals(option)){
try {
amapManager.downloadByCityCode(city.getCode());
} catch (AMapException e) {
e.printStackTrace();
onMessage("下载失败");
}
}else if ("暂停".equals(option)){
amapManager.pause();
}
}
示例7
public OfflineListAdapter(List<OfflineMapProvince> provinceList,
HashMap<Object, List<OfflineMapCity>> cityMap,
OfflineMapManager amapManager, Context mContext) {
this.provinceList = provinceList;
// this.cityMap = cityMap;
this.amapManager = amapManager;
this.mContext = mContext;
isOpen = new boolean[provinceList.size()];
}
示例8
/**
* 对一级标签下的二级标签进行设置
*/
@Override
public View getChildView(int groupPosition,
int childPosition, boolean isLastChild, View convertView,
ViewGroup parent) {
ViewHolder viewHolder;
if (convertView != null) {
viewHolder = (ViewHolder) convertView.getTag();
} else {
viewHolder = new ViewHolder();
OfflineChild offLineChild = new OfflineChild(mContext, amapManager);
convertView = offLineChild.getOffLineChildView();
viewHolder.mOfflineChild = offLineChild;
convertView.setTag(viewHolder);
}
// OfflineMapCity mapCity = cityMap.get(groupPosition).get(
// childPosition);
OfflineMapCity mapCity = null;
viewHolder.mOfflineChild.setProvince(false);
if(isNormalProvinceGroup(groupPosition)) {
if(isProvinceItem(groupPosition,childPosition)) {
// 如果是省份,为了方便,进行一下处理
mapCity = getCicy(provinceList.get(groupPosition));
viewHolder.mOfflineChild.setProvince(true);
} else {
// 减1处理,第一个被放置了省份
mapCity = provinceList.get(groupPosition).getCityList().get(childPosition - 1);
}
} else {
mapCity = provinceList.get(groupPosition).getCityList().get(childPosition);
}
viewHolder.mOfflineChild.setOffLineCity(mapCity);
return convertView;
}
示例9
/**
* 把一个省的对象转化为一个市的对象
*/
public OfflineMapCity getCicy(OfflineMapProvince aMapProvince) {
OfflineMapCity aMapCity = new OfflineMapCity();
aMapCity.setCity(aMapProvince.getProvinceName());
aMapCity.setSize(aMapProvince.getSize());
aMapCity.setCompleteCode(aMapProvince.getcompleteCode());
aMapCity.setState(aMapProvince.getState());
aMapCity.setUrl(aMapProvince.getUrl());
return aMapCity;
}
示例10
/**
* 取消所有<br>
* 即:删除下载列表中除了已完成的所有<br>
* 会在OfflineMapDownloadListener.onRemove接口中回调是否取消(删除)成功
*/
private void cancelAll() {
if (amapManager == null) {
return;
}
for (OfflineMapCity mapCity : amapManager.getDownloadingCityList()) {
if (mapCity.getState() == OfflineMapStatus.PAUSE) {
amapManager.remove(mapCity.getCity());
}
}
}
示例11
public void setOffLineCity(OfflineMapCity mapCity) {
if (mapCity != null) {
mMapCity = mapCity;
mOffLineCityName.setText(mapCity.getCity());
double size = ((int) (mapCity.getSize() / 1024.0 / 1024.0 * 100)) / 100.0;
mOffLineCitySize.setText(String.valueOf(size) + " M");
notifyViewDisplay(mMapCity.getState(), mMapCity.getcompleteCode(),
mIsDownloading);
}
}
示例12
private void updateCity(OfflineMapCity city) {
try {
amapManager.downloadByCityCode(city.getCode());
} catch (AMapException e) {
e.printStackTrace();
onMessage("更新失败");
}
}
示例13
@Override
public View getView(int position, View convertView, ViewGroup parent) {
if (null == convertView) {
convertView = getInflater().inflate(R.layout.item_download_city, parent, false);
}
TextView textCity = ViewHolder.get(convertView, R.id.text_city);
final Button btnOptions = ViewHolder.get(convertView, R.id.btn_options);
final OfflineMapCity city = getList().get(position);
textCity.setText(city.getCity() + ",大小:" + formatDataSize((int) city.getSize()) + ((city.getcompleteCode() != 100 && city.getState() != OfflineMapStatus.SUCCESS)? (" ("+ city.getcompleteCode() + "%)") : "") + ((city.getState() == OfflineMapStatus.NEW_VERSION) ? " [可更新]" : "") + (city.getState() == OfflineMapStatus.ERROR ? " [错误]" : ""));
if (city.getState() == OfflineMapStatus.NEW_VERSION){
btnOptions.setText("更新");
}else if (city.getState() == OfflineMapStatus.PAUSE || city.getState() == OfflineMapStatus.STOP){
btnOptions.setText("开始");
}else if (city.getState() == OfflineMapStatus.LOADING){
btnOptions.setText("暂停");
}else {
btnOptions.setText("删除");
}
btnOptions.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (null != onClickAmapDownloadOptionsListener){
onClickAmapDownloadOptionsListener.onClickAmapDownloadOptions(btnOptions.getText().toString().trim(), city);
}
}
});
return convertView;
}
示例14
private void updateCity(OfflineMapCity city) {
try {
amapManager.downloadByCityCode(city.getCode());
} catch (AMapException e) {
e.printStackTrace();
onMessage("更新失败");
}
}
示例15
@Override
public View getView(int position, View convertView, ViewGroup parent) {
if (null == convertView) {
convertView = getInflater().inflate(R.layout.item_download_city, parent, false);
}
TextView textCity = ViewHolder.get(convertView, R.id.text_city);
final Button btnOptions = ViewHolder.get(convertView, R.id.btn_options);
final OfflineMapCity city = getList().get(position);
textCity.setText(city.getCity() + ",大小:" + formatDataSize((int) city.getSize()) + ((city.getcompleteCode() != 100 && city.getState() != OfflineMapStatus.SUCCESS)? (" ("+ city.getcompleteCode() + "%)") : "") + ((city.getState() == OfflineMapStatus.NEW_VERSION) ? " [可更新]" : "") + (city.getState() == OfflineMapStatus.ERROR ? " [错误]" : ""));
if (city.getState() == OfflineMapStatus.NEW_VERSION){
btnOptions.setText("更新");
}else if (city.getState() == OfflineMapStatus.PAUSE || city.getState() == OfflineMapStatus.STOP){
btnOptions.setText("开始");
}else if (city.getState() == OfflineMapStatus.LOADING){
btnOptions.setText("暂停");
}else {
btnOptions.setText("删除");
}
btnOptions.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (null != onClickAmapDownloadOptionsListener){
onClickAmapDownloadOptionsListener.onClickAmapDownloadOptions(btnOptions.getText().toString().trim(), city);
}
}
});
return convertView;
}
示例16
/**
* 把一个省的对象转化为一个市的对象
*/
public OfflineMapCity getCicy(OfflineMapProvince aMapProvince) {
OfflineMapCity aMapCity = new OfflineMapCity();
aMapCity.setCity(aMapProvince.getProvinceName());
aMapCity.setSize(aMapProvince.getSize());
aMapCity.setCompleteCode(aMapProvince.getcompleteCode());
aMapCity.setState(aMapProvince.getState());
aMapCity.setUrl(aMapProvince.getUrl());
return aMapCity;
}
示例17
/**
* sdk内部存放形式为<br>
* 省份 - 各自子城市<br>
* 北京-北京<br>
* ...<br>
* 澳门-澳门<br>
* 概要图-概要图<br>
* <br>
* 修改一下存放结构:<br>
* 概要图-概要图<br>
* 直辖市-四个直辖市<br>
* 港澳-澳门香港<br>
* 省份-各自子城市<br>
*/
private void initProvinceListAndCityMap() {
List<OfflineMapProvince> lists = amapManager
.getOfflineMapProvinceList();
provinceList.add(null);
provinceList.add(null);
provinceList.add(null);
// 添加3个null 以防后面添加出现 index out of bounds
ArrayList<OfflineMapCity> cityList = new ArrayList<OfflineMapCity>();// 以市格式保存直辖市、港澳、全国概要图
ArrayList<OfflineMapCity> gangaoList = new ArrayList<OfflineMapCity>();// 保存港澳城市
ArrayList<OfflineMapCity> gaiyaotuList = new ArrayList<OfflineMapCity>();// 保存概要图
for (int i = 0; i < lists.size(); i++) {
OfflineMapProvince province = lists.get(i);
if (province.getCityList().size() != 1) {
// 普通省份
provinceList.add(i + 3, province);
// cityMap.put(i + 3, cities);
} else {
String name = province.getProvinceName();
if (name.contains("香港")) {
gangaoList.addAll(province.getCityList());
} else if (name.contains("澳门")) {
gangaoList.addAll(province.getCityList());
} else if (name.contains("全国概要图")) {
gaiyaotuList.addAll(province.getCityList());
} else {
// 直辖市
cityList.addAll(province.getCityList());
}
}
}
// 添加,概要图,直辖市,港口
OfflineMapProvince gaiyaotu = new OfflineMapProvince();
gaiyaotu.setProvinceName("概要图");
gaiyaotu.setCityList(gaiyaotuList);
provinceList.set(0, gaiyaotu);// 使用set替换掉刚开始的null
OfflineMapProvince zhixiashi = new OfflineMapProvince();
zhixiashi.setProvinceName("直辖市");
zhixiashi.setCityList(cityList);
provinceList.set(1, zhixiashi);
OfflineMapProvince gaogao = new OfflineMapProvince();
gaogao.setProvinceName("港澳");
gaogao.setCityList(gangaoList);
provinceList.set(2, gaogao);
// cityMap.put(0, gaiyaotuList);// 在HashMap中第0位置添加全国概要图
// cityMap.put(1, cityList);// 在HashMap中第1位置添加直辖市
// cityMap.put(2, gangaoList);// 在HashMap中第2位置添加港澳
}
示例18
public AmapDownloadCityAdapter(Context context, List<OfflineMapCity> list) {
super(context, list);
}
示例19
public AmapDownloadCityAdapter(Context context, List<OfflineMapCity> list) {
super(context, list);
}
示例20
void onClickAmapDownloadOptions(String option, OfflineMapCity city);
示例21
void onClickAmapDownloadOptions(String option, OfflineMapCity city);