Fix possible IllegalArgumentException and ClassCastException
This commit is contained in:
parent
d90b2956c5
commit
93ce36c0ff
2 changed files with 21 additions and 20 deletions
|
@ -25,6 +25,7 @@
|
||||||
android:id="@+id/ZoomToDownload"
|
android:id="@+id/ZoomToDownload"
|
||||||
style="@style/Widget.Styled.Slider"
|
style="@style/Widget.Styled.Slider"
|
||||||
android:layout_width="fill_parent"
|
android:layout_width="fill_parent"
|
||||||
|
android:stepSize="1"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginLeft="@dimen/content_padding"
|
android:layout_marginLeft="@dimen/content_padding"
|
||||||
android:layout_marginRight="@dimen/content_padding"
|
android:layout_marginRight="@dimen/content_padding"
|
||||||
|
|
|
@ -51,11 +51,12 @@ public class DownloadTilesDialog {
|
||||||
|
|
||||||
public void openDialog(){
|
public void openDialog(){
|
||||||
BaseMapLayer mainLayer = mapView.getMainLayer();
|
BaseMapLayer mainLayer = mapView.getMainLayer();
|
||||||
if(!(mainLayer instanceof MapTileLayer) || !((MapTileLayer) mainLayer).isVisible()){
|
if (!(mainLayer instanceof MapTileLayer) || !((MapTileLayer) mainLayer).isVisible()) {
|
||||||
Toast.makeText(ctx, R.string.maps_could_not_be_downloaded, Toast.LENGTH_SHORT).show();
|
Toast.makeText(ctx, R.string.maps_could_not_be_downloaded, Toast.LENGTH_SHORT).show();
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
final ITileSource mapSource = ((MapTileLayer) mainLayer).getMap();
|
final ITileSource mapSource = ((MapTileLayer) mainLayer).getMap();
|
||||||
if(mapSource == null || !mapSource.couldBeDownloadedFromInternet()){
|
if (mapSource == null || !mapSource.couldBeDownloadedFromInternet()) {
|
||||||
Toast.makeText(ctx, R.string.maps_could_not_be_downloaded, Toast.LENGTH_SHORT).show();
|
Toast.makeText(ctx, R.string.maps_could_not_be_downloaded, Toast.LENGTH_SHORT).show();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -66,29 +67,28 @@ public class DownloadTilesDialog {
|
||||||
|
|
||||||
// calculate pixel rectangle
|
// calculate pixel rectangle
|
||||||
AlertDialog.Builder builder = new AlertDialog.Builder(ctx);
|
AlertDialog.Builder builder = new AlertDialog.Builder(ctx);
|
||||||
LayoutInflater inflater = (LayoutInflater)ctx.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
LayoutInflater inflater = (LayoutInflater) ctx.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
||||||
View view = inflater.inflate(R.layout.download_tiles, null);
|
View view = inflater.inflate(R.layout.download_tiles, null);
|
||||||
|
|
||||||
|
((TextView) view.findViewById(R.id.MinZoom)).setText(String.valueOf(zoom));
|
||||||
|
((TextView) view.findViewById(R.id.MaxZoom)).setText(String.valueOf(max));
|
||||||
((TextView)view.findViewById(R.id.MinZoom)).setText(zoom+""); //$NON-NLS-1$
|
|
||||||
((TextView)view.findViewById(R.id.MaxZoom)).setText(max+""); //$NON-NLS-1$
|
|
||||||
final Slider slider = (Slider) view.findViewById(R.id.ZoomToDownload);
|
final Slider slider = (Slider) view.findViewById(R.id.ZoomToDownload);
|
||||||
slider.setValueTo(max - zoom);
|
|
||||||
int progress = (max - zoom) / 2;
|
|
||||||
slider.setValue(progress);
|
|
||||||
|
|
||||||
final TextView downloadText = ((TextView) view.findViewById(R.id.DownloadDescription));
|
final TextView downloadText = ((TextView) view.findViewById(R.id.DownloadDescription));
|
||||||
final String template = ctx.getString(R.string.tiles_to_download_estimated_size);
|
final String template = ctx.getString(R.string.tiles_to_download_estimated_size);
|
||||||
|
|
||||||
|
|
||||||
updateLabel(zoom, rb.getLatLonBounds(), downloadText, template, (int) slider.getValue());
|
updateLabel(zoom, rb.getLatLonBounds(), downloadText, template, (int) slider.getValue());
|
||||||
slider.addOnChangeListener(new Slider.OnChangeListener() {
|
if (max > zoom) {
|
||||||
@Override
|
slider.setValueTo(max - zoom);
|
||||||
public void onValueChange(@NonNull Slider slider, float value, boolean fromUser) {
|
int progress = (max - zoom) / 2;
|
||||||
updateLabel(zoom, rb.getLatLonBounds(), downloadText, template, (int) value);
|
slider.setValue(progress);
|
||||||
}
|
slider.addOnChangeListener(new Slider.OnChangeListener() {
|
||||||
});
|
@Override
|
||||||
|
public void onValueChange(@NonNull Slider slider, float value, boolean fromUser) {
|
||||||
|
updateLabel(zoom, rb.getLatLonBounds(), downloadText, template, (int) value);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
builder.setPositiveButton(R.string.shared_string_download, new DialogInterface.OnClickListener(){
|
builder.setPositiveButton(R.string.shared_string_download, new DialogInterface.OnClickListener(){
|
||||||
@Override
|
@Override
|
||||||
|
|
Loading…
Reference in a new issue