Never cache activities they could be not active

Conflicts:
	OsmAnd/src/net/osmand/plus/OsmAndAppCustomization.java
	OsmAnd/src/net/osmand/plus/download/DownloadActivity.java
This commit is contained in:
Victor Shcherb 2015-01-04 20:57:20 +01:00 committed by Alexey Pelykh
parent 630bea44a2
commit 3856a67a01
8 changed files with 64 additions and 47 deletions

View file

@ -16,6 +16,7 @@ import java.util.regex.Pattern;
import android.app.AlertDialog;
import android.content.ActivityNotFoundException;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.net.Uri;
@ -151,9 +152,6 @@ public class FavouritesDbHelper {
}
FavoriteGroup group = getOrCreateGroup(p, 0);
//making sure that dublicated names will not occur in favorites
checkDublicates(p);
if (!p.getName().equals("")) {
p.setVisible(group.visible);
p.setColor(group.color);
@ -167,45 +165,45 @@ public class FavouritesDbHelper {
return true;
}
private void checkDublicates(FavouritePoint p){
boolean fl = true;
public static AlertDialog.Builder checkDublicates(FavouritePoint p, FavouritesDbHelper fdb, Context uiContext) {
boolean emoticons = false;
String index = "";
int number = 0;
String name = checkEmoticons(p.getName());
String category = checkEmoticons(p.getCategory());
p.setCategory(category);
if (name.length() != p.getName().length()){
if (name.length() != p.getName().length()) {
emoticons = true;
}
while (fl){
boolean fl = true;
while (fl) {
fl = false;
for (FavouritePoint fp : cachedFavoritePoints){
if (fp.getName().equals(name)){
for (FavouritePoint fp : fdb.getFavouritePoints()) {
if (fp.getName().equals(name)) {
number++;
index = " (" + number + ")";
name = p.getName() + index;
fl=true;
fl = true;
break;
}
}
}
if ((index.length() > 0 || emoticons)&&
context.getMapActivity() != null){
AlertDialog.Builder builder = new AlertDialog.Builder(context.getMapActivity());
if ((index.length() > 0 || emoticons) ) {
AlertDialog.Builder builder = new AlertDialog.Builder(uiContext);
builder.setTitle(R.string.fav_point_dublicate);
if (emoticons){
builder.setMessage(context.getString(R.string.fav_point_emoticons_message, name));
if (emoticons) {
builder.setMessage(uiContext.getString(R.string.fav_point_emoticons_message, name));
} else {
builder.setMessage(context.getString(R.string.fav_point_dublicate_message, name));
builder.setMessage(uiContext.getString(R.string.fav_point_dublicate_message, name));
}
builder.setPositiveButton(R.string.default_buttons_ok, null);
p.setName(name);
builder.show();
return builder;
}
return null;
}
public String checkEmoticons(String name){
public static String checkEmoticons(String name){
char[] chars = name.toCharArray();
int index;
char ch1;

View file

@ -152,5 +152,14 @@ public class OsmAndAppCustomization {
public boolean showNavigationControls() { return true;}
public boolean onlyTourDownload() { return false;}
public boolean onlyTourDownload() {
return false;
}
public <T> void resumeActivity(Class<T> class1, T d) {
}
public <T> void pauseActivity(Class<T> class1) {
}
}

View file

@ -118,9 +118,6 @@ public class OsmandApplication extends Application {
SQLiteAPI sqliteAPI;
BRouterServiceConnection bRouterServiceConnection;
MapActivity mapActivity;
DownloadActivity downloadActivity;
@Override
public void onCreate() {
long timeToStart = System.currentTimeMillis();
@ -911,19 +908,5 @@ public class OsmandApplication extends Application {
}
}
public MapActivity getMapActivity() {
return mapActivity;
}
public void setMapActivity(MapActivity mapActivity) {
this.mapActivity = mapActivity;
}
public void setDownloadActivity(DownloadActivity downloadActivity) {
this.downloadActivity = downloadActivity;
}
public DownloadActivity getDownloadActivity() {
return downloadActivity;
}
}

View file

@ -346,7 +346,6 @@ public class MapActivity extends AccessibleActivity implements
}
settings.MAP_ACTIVITY_ENABLED.set(true);
app.setMapActivity(this);
checkExternalStorage();
showAndHideMapPosition();
@ -420,6 +419,7 @@ public class MapActivity extends AccessibleActivity implements
if(glSurfaceView != null) {
glSurfaceView.onResume();
}
getMyApplication().getAppCustomization().resumeActivity(MapActivity.class, this);
}
@ -623,7 +623,7 @@ public class MapActivity extends AccessibleActivity implements
settings.setLastKnownMapZoom(mapView.getZoom());
settings.MAP_ACTIVITY_ENABLED.set(false);
app.setMapActivity(null);
getMyApplication().getAppCustomization().pauseActivity(MapActivity.class);
app.getResourceManager().interruptRendering();
app.getResourceManager().setBusyIndicator(null);
OsmandPlugin.onMapActivityPause(this);

View file

@ -12,17 +12,17 @@ import net.osmand.AndroidUtils;
import net.osmand.access.AccessibleToast;
import net.osmand.data.FavouritePoint;
import net.osmand.plus.FavouritesDbHelper;
import net.osmand.plus.FavouritesDbHelper.FavoriteGroup;
import net.osmand.plus.OsmAndFormatter;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
import net.osmand.plus.FavouritesDbHelper.FavoriteGroup;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.base.FavoriteImageDrawable;
import net.osmand.util.MapUtils;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.app.AlertDialog.Builder;
import android.app.Dialog;
import android.content.DialogInterface;
import android.content.res.Resources;
import android.os.Build;
@ -202,13 +202,27 @@ public class FavoriteDialogs {
builder.setPositiveButton(R.string.default_buttons_add, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
FavouritePoint point = (FavouritePoint) args.getSerializable(KEY_FAVORITE);
final FavouritePoint point = (FavouritePoint) args.getSerializable(KEY_FAVORITE);
OsmandApplication app = (OsmandApplication) activity.getApplication();
String categoryStr = cat.getText().toString().trim();
final FavouritesDbHelper helper = app.getFavorites();
app.getSettings().LAST_FAV_CATEGORY_ENTERED.set(categoryStr);
point.setName(editText.getText().toString().trim());
point.setCategory(categoryStr);
Builder bld = FavouritesDbHelper.checkDublicates(point, helper, activity);
if(bld != null) {
bld.setPositiveButton(R.string.default_buttons_ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
addFavorite(activity, point, helper);
}
});
} else {
addFavorite(activity, point, helper);
}
}
protected void addFavorite(final Activity activity, FavouritePoint point, final FavouritesDbHelper helper) {
boolean added = helper.addFavourite(point);
if (added) {
AccessibleToast.makeText(activity, MessageFormat.format(

View file

@ -217,8 +217,7 @@ public class DownloadActivity extends SherlockFragmentActivity {
@Override
protected void onResume() {
super.onResume();
getMyApplication().setDownloadActivity(this);
BasicProgressAsyncTask<?, ?, ?> t = downloadListIndexThread.getCurrentRunningTask();
getMyApplication().getAppCustomization().resumeActivity(DownloadActivity.class, this);
}
@ -289,7 +288,7 @@ public class DownloadActivity extends SherlockFragmentActivity {
@Override
public void onPause() {
super.onPause();
(getMyApplication()).setDownloadActivity(null);
getMyApplication().getAppCustomization().pauseActivity(DownloadActivity.class);
}
protected void downloadFilesCheckFreeVersion() {

View file

@ -65,7 +65,8 @@ public class GpxImportHelper {
if (fileName != null && fileName.endsWith(KML_SUFFIX)) {
handleKmlImport(intentUri, fileName, saveFile);
} else if (fileName != null && fileName.endsWith("favourites.gpx")) {
} else if (fileName != null && (fileName.contains("favourite")||
fileName.contains("favorite"))) {
handleFavouritesImport(intentUri, fileName, saveFile);
} else {
handleGpxImport(intentUri, fileName, saveFile);

View file

@ -5,6 +5,7 @@ import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
@ -84,6 +85,7 @@ public class SherpafyCustomization extends OsmAndAppCustomization {
public static final String TOUR_SERVER = "download.osmand.net";
private static final String SAVE_GPX_FOLDER = "save_gpx_folder";
private Object originalGlobal;
private Map<Class<Object>, Object> activities = new HashMap<Class<Object>, Object>();
@Override
public void setup(OsmandApplication app) {
@ -230,7 +232,7 @@ public class SherpafyCustomization extends OsmAndAppCustomization {
}
this.tourPresent = tourPresent;
if(!suggestToDownloadMap.isEmpty()) {
final DownloadActivity da = app.getDownloadActivity();
final DownloadActivity da = (DownloadActivity) activities.get(DownloadActivity.class);
if (da != null) {
app.runInUIThread(new Runnable() {
@ -687,7 +689,7 @@ public class SherpafyCustomization extends OsmAndAppCustomization {
}
public boolean onDestinationReached() {
final MapActivity map = app.getMapActivity();
final MapActivity map = (MapActivity) activities.get(MapActivity.class);
if(map != null && getSelectedStage() != null) {
app.runInUIThread(new Runnable() {
@ -700,6 +702,17 @@ public class SherpafyCustomization extends OsmAndAppCustomization {
return true;
}
@Override
public <T> void pauseActivity(Class<T> class1) {
super.pauseActivity(class1);
}
@Override
@SuppressWarnings("unchecked")
public <T> void resumeActivity(Class<T> class1, T d) {
activities.put((Class<Object>) class1, d);
}
public void runStage(Activity a, TourInformation tour, StageInformation stage, boolean startOver) {
WptPt point = null;
GPXFile gpx = null;