- use AsyncTask

- only show gpx route
This commit is contained in:
Koen Rabaey 2014-04-22 22:46:36 +02:00
parent 3536f44f4c
commit 011ebf7b25

View file

@ -7,7 +7,7 @@ import java.util.LinkedHashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import net.osmand.CallbackWithObject; import android.os.AsyncTask;
import net.osmand.Location; import net.osmand.Location;
import net.osmand.StateChangedListener; import net.osmand.StateChangedListener;
import net.osmand.access.AccessibilityPlugin; import net.osmand.access.AccessibilityPlugin;
@ -53,6 +53,7 @@ import android.content.DialogInterface;
import android.content.Intent; import android.content.Intent;
import android.media.AudioManager; import android.media.AudioManager;
import android.net.Uri; import android.net.Uri;
import android.os.AsyncTask;
import android.os.Bundle; import android.os.Bundle;
import android.os.Environment; import android.os.Environment;
import android.os.Handler; import android.os.Handler;
@ -67,7 +68,6 @@ import android.view.Window;
import android.widget.FrameLayout; import android.widget.FrameLayout;
import android.widget.ProgressBar; import android.widget.ProgressBar;
import android.widget.Toast; import android.widget.Toast;
import org.apache.http.client.protocol.ClientContext;
public class MapActivity extends AccessibleActivity { public class MapActivity extends AccessibleActivity {
@ -329,7 +329,7 @@ public class MapActivity extends AccessibleActivity {
final Uri data = intent.getData(); final Uri data = intent.getData();
if ("file".equalsIgnoreCase(data.getScheme())) if ("file".equalsIgnoreCase(data.getScheme()))
{ {
navigateImportedGpx(data.getPath()); showImportedGpx(data.getPath());
} }
} }
@ -682,49 +682,41 @@ public class MapActivity extends AccessibleActivity {
getMapView().refreshMap(); getMapView().refreshMap();
} }
private void navigateImportedGpx(final String gpxFile) private void showImportedGpx(final String gpxFile)
{ {
final CallbackWithObject<GPXFile> callback = new CallbackWithObject<GPXUtilities.GPXFile>() new AsyncTask<Void, Void, GPXFile>()
{ {
@Override ProgressDialog progress = null;
public boolean processResult(GPXFile result)
{
getMyApplication().setGpxFileToDisplay(result, true);
getMapActions().setGPXRouteParams(result);
getMyApplication().getTargetPointsHelper().updateRoutingHelper();
getRoutingHelper().recalculateRouteDueToSettingsChange();
return true;
}
};
final ProgressDialog dlg = ProgressDialog.show(this, getString(R.string.loading), getString(R.string.loading_data));
new Thread(new Runnable()
{
@Override @Override
public void run() protected void onPreExecute()
{ {
final GPXFile res = GPXUtilities.loadGPXFile(getApplication(), new File(gpxFile)); progress = ProgressDialog.show(MapActivity.this, getString(R.string.loading), getString(R.string.loading_data));
dlg.dismiss(); }
if (res != null)
@Override
protected GPXFile doInBackground(Void... nothing)
{
return GPXUtilities.loadGPXFile(getMyApplication(), new File(gpxFile));
}
@Override
protected void onPostExecute(GPXFile result)
{
progress.dismiss();
if (result != null)
{ {
MapActivity.this.runOnUiThread(new Runnable() if (result.warning != null)
{ {
@Override AccessibleToast.makeText(MapActivity.this, result.warning, Toast.LENGTH_LONG).show();
public void run() }
{ else
if (res.warning != null) {
{ getMyApplication().setGpxFileToDisplay(result, true);
AccessibleToast.makeText(MapActivity.this, res.warning, Toast.LENGTH_LONG).show(); }
}
else
{
callback.processResult(res);
}
}
});
} }
} }
}.execute();
}, "Loading gpx").start(); //$NON-NLS-1$
} }
} }