Change director for Google android 19

This commit is contained in:
vshcherb 2014-03-02 21:13:11 +02:00
parent a16882f672
commit 2f7a78e6fc
4 changed files with 52 additions and 5 deletions

View file

@ -9,6 +9,9 @@
3. All your modified/created strings are in the top of the file (to make easier find what\'s translated). 3. 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 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="android_19_location_disabled">Since KitKat release Android, you can\'t download and update map in previous storage location (%s). Do you want to change to allowed one and copy all files?
\n Note : old files will stay untouched.
\n Note : it will not be possible to share files between OsmAnd and OsmAnd+. </string>
<string name="application_dir_change_warning2">OsmAnd could try to move the data to new destination. Do you want it?</string> <string name="application_dir_change_warning2">OsmAnd could try to move the data to new destination. Do you want it?</string>
<string name="copying_osmand_one_file_descr">Copying file (%s) to new destination...</string> <string name="copying_osmand_one_file_descr">Copying file (%s) to new destination...</string>
<string name="copying_osmand_files_descr">Copying OsmAnd files to new destination (%s)</string> <string name="copying_osmand_files_descr">Copying OsmAnd files to new destination (%s)</string>

View file

@ -993,8 +993,17 @@ public class OsmandSettings {
public static final String EXTERNAL_STORAGE_DIR = "external_storage_dir"; //$NON-NLS-1$ public static final String EXTERNAL_STORAGE_DIR = "external_storage_dir"; //$NON-NLS-1$
public File getExternalStorageDirectory() { public File getExternalStorageDirectory() {
String defaultLocation = getDefaultExternalStorageLocation();
return new File(settingsAPI.getString(globalPreferences, EXTERNAL_STORAGE_DIR, return new File(settingsAPI.getString(globalPreferences, EXTERNAL_STORAGE_DIR,
ctx.getExternalServiceAPI().getExternalStorageDirectory())); defaultLocation));
}
public String getDefaultExternalStorageLocation() {
String defaultLocation = ctx.getExternalServiceAPI().getExternalStorageDirectory();
if(Build.VERSION.SDK_INT >= 19) {
defaultLocation += "/Android/data/" + ctx.getPackageName();
}
return defaultLocation;
} }
public boolean setExternalStorageDirectory(String externalStorageDir) { public boolean setExternalStorageDirectory(String externalStorageDir) {

View file

@ -11,6 +11,7 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.TimeZone; import java.util.TimeZone;
import net.osmand.access.AccessibleAlertBuilder;
import net.osmand.access.AccessibleToast; import net.osmand.access.AccessibleToast;
import net.osmand.plus.ClientContext; import net.osmand.plus.ClientContext;
import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandApplication;
@ -18,6 +19,7 @@ import net.osmand.plus.OsmandPlugin;
import net.osmand.plus.OsmandSettings; import net.osmand.plus.OsmandSettings;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.plus.Version; import net.osmand.plus.Version;
import net.osmand.plus.activities.SettingsGeneralActivity.MoveFilesToDifferentDirectory;
import net.osmand.plus.base.BasicProgressAsyncTask; import net.osmand.plus.base.BasicProgressAsyncTask;
import net.osmand.plus.base.SuggestExternalDirectoryDialog; import net.osmand.plus.base.SuggestExternalDirectoryDialog;
import net.osmand.plus.download.DownloadActivityType; import net.osmand.plus.download.DownloadActivityType;
@ -36,6 +38,7 @@ import android.content.DialogInterface.OnClickListener;
import android.content.Intent; import android.content.Intent;
import android.net.Uri; import android.net.Uri;
import android.os.AsyncTask.Status; import android.os.AsyncTask.Status;
import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.text.Editable; import android.text.Editable;
import android.text.TextWatcher; import android.text.TextWatcher;
@ -162,7 +165,10 @@ public class DownloadIndexActivity extends OsmandExpandableListActivity {
DownloadIndexAdapter adapter = new DownloadIndexAdapter(this, list); DownloadIndexAdapter adapter = new DownloadIndexAdapter(this, list);
setListAdapter(adapter); setListAdapter(adapter);
if(getMyApplication().getResourceManager().getIndexFileNames().isEmpty()) { if(getMyApplication().getResourceManager().getIndexFileNames().isEmpty()) {
boolean showedDialog = SuggestExternalDirectoryDialog.showDialog(this, null, null); boolean showedDialog = false;
if(Build.VERSION.SDK_INT < 19) {
SuggestExternalDirectoryDialog.showDialog(this, null, null);
}
if(!showedDialog) { if(!showedDialog) {
showDialogOfFreeDownloadsIfNeeded(); showDialogOfFreeDownloadsIfNeeded();
} }
@ -182,7 +188,36 @@ public class DownloadIndexActivity extends OsmandExpandableListActivity {
return true; return true;
} }
}); });
if(Build.VERSION.SDK_INT >= 19) {
if(!settings.getExternalStorageDirectory().equals(settings.getDefaultExternalStorageLocation())) {
AccessibleAlertBuilder ab = new AccessibleAlertBuilder(this);
ab.setMessage(getString(R.string.android_19_location_disabled, settings.getExternalStorageDirectory()));
ab.setPositiveButton(R.string.default_buttons_yes, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
copyFilesForAndroid19();
}
});
ab.setNegativeButton(R.string.default_buttons_cancel, null);
}
}
}
private void copyFilesForAndroid19() {
File newLoc = new File(settings.getDefaultExternalStorageLocation());
MoveFilesToDifferentDirectory task =
new MoveFilesToDifferentDirectory(DownloadIndexActivity.this, settings.getExternalStorageDirectory(), newLoc) {
protected Boolean doInBackground(Void[] params) {
Boolean result = super.doInBackground(params);
if(result) {
settings.setExternalStorageDirectory(settings.getDefaultExternalStorageLocation());
getMyApplication().getResourceManager().resetStoreDirectory();
getMyApplication().getResourceManager().reloadIndexes(progress) ;
}
return result;
};
};
task.execute();
} }
@Override @Override

View file

@ -279,7 +279,7 @@ public class SettingsGeneralActivity extends SettingsBaseActivity {
private File to; private File to;
private Context ctx; private Context ctx;
private File from; private File from;
private ProgressDialogImplementation progress; protected ProgressDialogImplementation progress;
private Runnable runOnSuccess; private Runnable runOnSuccess;
public MoveFilesToDifferentDirectory(Context ctx, File from, File to) { public MoveFilesToDifferentDirectory(Context ctx, File from, File to) {