Smart recover when we are in following mode

This commit is contained in:
Victor Shcherb 2012-07-19 00:15:57 +02:00
parent 18303be61c
commit dc57d3929a
4 changed files with 92 additions and 25 deletions

View file

@ -9,6 +9,7 @@
1. All your modified/created strings are in the top of the file (to make easier find what's translated).
PLEASE: Have a look at http://code.google.com/p/osmand/wiki/UIConsistency, it may really improve your and our work :-) Thx - Hardy
-->
<string name="continue_follow_previous_route_auto">Previous navigation was unfinished. Continue following it? (%1$s seconds)</string>
<string name="route_updated_loc_found">Route will be recalculated when location will be found</string>
<string name="osmand_parking_hours">Hours</string>
<string name="osmand_parking_minutes">Minutes</string>
@ -759,7 +760,6 @@ You can enable (online or cached) tile map sources, tracking settings, and many
<string name="layer_poi">POI&#8230;</string>
<string name="layer_map">Map source&#8230;</string>
<string name="menu_layers">Define view</string>
<string name="continue_follow_previous_route">Previous navigation was unfinished. Continue following it?</string>
<string name="context_menu_item_search_poi">Search POI</string>
<string name="context_menu_item_show_route">Show route from here</string>
<string name="use_trackball_descr">Use trackball to move map</string>

View file

@ -15,16 +15,12 @@ import net.osmand.FavouritePoint;
import net.osmand.GPXUtilities;
import net.osmand.GPXUtilities.GPXFile;
import net.osmand.GPXUtilities.WptPt;
import net.osmand.plus.FavouritesDbHelper;
import net.osmand.plus.NavigationService;
import net.osmand.plus.OsmandSettings;
import net.osmand.plus.PoiFiltersHelper;
import net.osmand.plus.ProgressDialogImplementation;
import net.osmand.LogUtil;
import net.osmand.access.AccessibilityMode;
import net.osmand.access.AccessibleToast;
import net.osmand.plus.activities.DayNightHelper;
import net.osmand.plus.activities.LiveMonitoringHelper;
import net.osmand.plus.activities.OsmandIntents;
import net.osmand.plus.activities.SavingTrackHelper;
import net.osmand.plus.activities.SettingsActivity;
import net.osmand.plus.render.NativeOsmandLibrary;
@ -35,9 +31,11 @@ import net.osmand.plus.voice.CommandPlayerException;
import net.osmand.plus.voice.CommandPlayerFactory;
import net.osmand.render.RenderingRulesStorage;
import android.app.Activity;
import android.app.AlarmManager;
import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.app.Application;
import android.app.PendingIntent;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.DialogInterface;
@ -483,9 +481,12 @@ public class OsmandApplication extends Application {
private class DefaultExceptionHandler implements UncaughtExceptionHandler {
private UncaughtExceptionHandler defaultHandler;
private PendingIntent intent;
public DefaultExceptionHandler() {
defaultHandler = Thread.getDefaultUncaughtExceptionHandler();
intent = PendingIntent.getActivity(OsmandApplication.this.getBaseContext(), 0,
new Intent(OsmandApplication.this.getBaseContext(), OsmandIntents.getMainMenuActivity()), 0);
}
@Override
@ -506,6 +507,11 @@ public class OsmandApplication extends Application {
writer.write(msg.toString());
writer.close();
}
if(routingHelper.isFollowingMode()) {
AlarmManager mgr = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
mgr.set(AlarmManager.RTC, System.currentTimeMillis() + 2000, intent);
System.exit(2);
}
defaultHandler.uncaughtException(thread, ex);
} catch (Exception e) {
// swallow all exceptions

View file

@ -235,7 +235,13 @@ public class MainMenuActivity extends Activity {
if(exit){
return;
}
OsmandApplication app = ((OsmandApplication) getApplication());
// restore follow route mode
if(app.getSettings().FOLLOW_THE_ROUTE.get() && !app.getRoutingHelper().isRouteCalculated()){
final Intent mapIndent = new Intent(this, OsmandIntents.getMapActivity());
startActivityForResult(mapIndent, 0);
return;
}
startProgressDialog = new ProgressDialog(this);
getMyApplication().checkApplicationIsBeingInitialized(this, startProgressDialog);
SharedPreferences pref = getPreferences(MODE_WORLD_WRITEABLE);

View file

@ -34,6 +34,7 @@ import net.osmand.plus.views.AnimateDraggingMapThread;
import net.osmand.plus.views.OsmandMapTileView;
import net.osmand.plus.views.PointLocationLayer;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.app.Dialog;
import android.app.Notification;
@ -41,6 +42,8 @@ import android.app.NotificationManager;
import android.app.PendingIntent;
import android.app.ProgressDialog;
import android.content.DialogInterface;
import android.content.DialogInterface.OnCancelListener;
import android.content.DialogInterface.OnDismissListener;
import android.content.Intent;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
@ -71,6 +74,9 @@ import android.view.Window;
import android.view.animation.AccelerateInterpolator;
import android.view.animation.Animation;
import android.view.animation.Transformation;
import android.widget.FrameLayout.LayoutParams;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;
public class MapActivity extends AccessibleActivity implements IMapLocationListener, SensorEventListener {
@ -169,6 +175,7 @@ public class MapActivity extends AccessibleActivity implements IMapLocationListe
startProgressDialog.setOnDismissListener(new DialogInterface.OnDismissListener() {
@Override
public void onDismiss(DialogInterface dialog) {
getMyApplication().getResourceManager().getRenderer().clearCache();
mapView.refreshMap(true);
}
});
@ -324,11 +331,65 @@ public class MapActivity extends AccessibleActivity implements IMapLocationListe
if (pointToNavigate == null && gpxPath == null) {
notRestoreRoutingMode();
} else {
Builder builder = new AccessibleAlertBuilder(MapActivity.this);
builder.setMessage(R.string.continue_follow_previous_route);
builder.setPositiveButton(R.string.default_buttons_yes, new DialogInterface.OnClickListener() {
Runnable encapsulate = new Runnable() {
int delay = 7;
boolean quit = false;
Runnable delayDisplay = null;
@Override
public void onClick(DialogInterface dialog, int which) {
public void run() {
Builder builder = new AccessibleAlertBuilder(MapActivity.this);
final TextView tv = new TextView(MapActivity.this);
tv.setText(getString(R.string.continue_follow_previous_route_auto, delay + ""));
tv.setPadding(7, 5, 7, 5);
builder.setView(tv);
builder.setPositiveButton(R.string.default_buttons_yes, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
restoreRoutingMode();
}
});
builder.setNegativeButton(R.string.default_buttons_no, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
notRestoreRoutingMode();
quit = true;
}
});
final AlertDialog dlg = builder.show();
dlg.setOnDismissListener(new OnDismissListener() {
@Override
public void onDismiss(DialogInterface dialog) {
quit = true;
}
});
dlg.setOnCancelListener(new OnCancelListener() {
@Override
public void onCancel(DialogInterface dialog) {
quit = true;
}
});
delayDisplay = new Runnable() {
@Override
public void run() {
if(!quit) {
delay --;
tv.setText(getString(R.string.continue_follow_previous_route_auto, delay + ""));
if(delay <= 0) {
dlg.dismiss();
restoreRoutingMode();
} else {
uiHandler.postDelayed(delayDisplay, 1000);
}
}
}
};
delayDisplay.run();
}
private void restoreRoutingMode() {
quit = true;
AsyncTask<String, Void, GPXFile> task = new AsyncTask<String, Void, GPXFile>() {
@Override
protected GPXFile doInBackground(String... params) {
@ -361,14 +422,8 @@ public class MapActivity extends AccessibleActivity implements IMapLocationListe
task.execute(gpxPath);
}
});
builder.setNegativeButton(R.string.default_buttons_no, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
notRestoreRoutingMode();
}
});
builder.show();
};
encapsulate.run();
}
}
@ -383,13 +438,13 @@ public class MapActivity extends AccessibleActivity implements IMapLocationListe
@Override
protected Dialog onCreateDialog(int id) {
Dialog dialog = null;
for (DialogProvider dp : dialogProviders) {
dialog = dp.onCreateDialog(id);
if (dialog != null) {
return dialog;
Dialog dialog = null;
for (DialogProvider dp : dialogProviders) {
dialog = dp.onCreateDialog(id);
if (dialog != null) {
return dialog;
}
}
}
if (id == OsmandApplication.PROGRESS_DIALOG) {
return startProgressDialog;
}