Fix possible IllegalArgumentException and ClassCastException

This commit is contained in:
Vitaliy 2020-05-18 18:02:55 +03:00
parent d90b2956c5
commit 93ce36c0ff
2 changed files with 21 additions and 20 deletions

View file

@ -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"

View file

@ -53,6 +53,7 @@ public class DownloadTilesDialog {
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()) {
@ -69,26 +70,25 @@ public class DownloadTilesDialog {
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());
if (max > zoom) {
slider.setValueTo(max - zoom);
int progress = (max - zoom) / 2;
slider.setValue(progress);
slider.addOnChangeListener(new Slider.OnChangeListener() { slider.addOnChangeListener(new Slider.OnChangeListener() {
@Override @Override
public void onValueChange(@NonNull Slider slider, float value, boolean fromUser) { public void onValueChange(@NonNull Slider slider, float value, boolean fromUser) {
updateLabel(zoom, rb.getLatLonBounds(), downloadText, template, (int) value); 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