Add ability to import osf profile via aidl
This commit is contained in:
parent
65123d43f1
commit
78b9f80c47
9 changed files with 179 additions and 48 deletions
|
@ -11,6 +11,7 @@
|
|||
Thx - Hardy
|
||||
|
||||
-->
|
||||
<string name="add_new_profile_q">Add new profile \'%1$s\'?</string>
|
||||
<string name="save_heading">Save heading</string>
|
||||
<string name="save_heading_descr">Save heading to each trackpoint while recording.</string>
|
||||
<string name="rendering_value_walkingRoutesOSMCNodes_name">Node networks</string>
|
||||
|
|
|
@ -73,6 +73,7 @@ import net.osmand.aidl.customization.SetWidgetsParams;
|
|||
import net.osmand.aidl.customization.OsmandSettingsParams;
|
||||
import net.osmand.aidl.customization.OsmandSettingsInfoParams;
|
||||
import net.osmand.aidl.customization.CustomizationInfoParams;
|
||||
import net.osmand.aidl.customization.ProfileSettingsParams;
|
||||
|
||||
import net.osmand.aidl.gpx.AGpxFile;
|
||||
import net.osmand.aidl.gpx.AGpxFileDetails;
|
||||
|
@ -846,4 +847,6 @@ interface IOsmAndAidlInterface {
|
|||
*
|
||||
*/
|
||||
boolean getGpxColor(inout GpxColorParams params);
|
||||
|
||||
boolean importProfile(in ProfileSettingsParams params);
|
||||
}
|
||||
|
|
|
@ -54,6 +54,7 @@ import net.osmand.plus.OsmandApplication;
|
|||
import net.osmand.plus.OsmandPlugin;
|
||||
import net.osmand.plus.OsmandSettings;
|
||||
import net.osmand.plus.SQLiteTileSource;
|
||||
import net.osmand.plus.SettingsHelper;
|
||||
import net.osmand.plus.activities.MapActivity;
|
||||
import net.osmand.plus.audionotes.AudioVideoNotesPlugin;
|
||||
import net.osmand.plus.dialogs.ConfigureMapMenu;
|
||||
|
@ -2205,6 +2206,17 @@ public class OsmandAidlApi {
|
|||
|
||||
private Map<String, FileCopyInfo> copyFilesCache = new ConcurrentHashMap<>();
|
||||
|
||||
public boolean importProfile(final Uri profileUri, String latestChanges, int version) {
|
||||
if (profileUri != null) {
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putString(SettingsHelper.SETTINGS_LATEST_CHANGES_KEY, latestChanges);
|
||||
bundle.putInt(SettingsHelper.SETTINGS_VERSION_KEY, version);
|
||||
|
||||
MapActivity.launchMapActivityMoveToTop(app, null, profileUri, bundle);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private class FileCopyInfo {
|
||||
long startTime;
|
||||
|
|
|
@ -22,6 +22,7 @@ import net.osmand.aidl.copyfile.CopyFileParams;
|
|||
import net.osmand.aidl.customization.CustomizationInfoParams;
|
||||
import net.osmand.aidl.customization.OsmandSettingsInfoParams;
|
||||
import net.osmand.aidl.customization.OsmandSettingsParams;
|
||||
import net.osmand.aidl.customization.ProfileSettingsParams;
|
||||
import net.osmand.aidl.customization.SetWidgetsParams;
|
||||
import net.osmand.aidl.favorite.AFavorite;
|
||||
import net.osmand.aidl.favorite.AddFavoriteParams;
|
||||
|
@ -1280,6 +1281,17 @@ public class OsmandAidlService extends Service implements AidlCallbackListener {
|
|||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean importProfile(ProfileSettingsParams params) {
|
||||
try {
|
||||
OsmandAidlApi api = getApi("importProfile");
|
||||
return api != null && api.importProfile(params.getProfileSettingsUri(), params.getLatestChanges(), params.getVersion());
|
||||
} catch (Exception e) {
|
||||
handleException(e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
private void setCustomization(OsmandAidlApi api, CustomizationInfoParams params) {
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
package net.osmand.aidl.customization;
|
||||
|
||||
parcelable ProfileSettingsParams;
|
|
@ -0,0 +1,64 @@
|
|||
package net.osmand.aidl.customization;
|
||||
|
||||
import android.net.Uri;
|
||||
import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
|
||||
public class ProfileSettingsParams implements Parcelable {
|
||||
|
||||
private Uri profileSettingsUri;
|
||||
private String latestChanges;
|
||||
private int version;
|
||||
|
||||
public ProfileSettingsParams(Uri profileSettingsUri, String latestChanges, int version) {
|
||||
this.profileSettingsUri = profileSettingsUri;
|
||||
this.latestChanges = latestChanges;
|
||||
this.version = version;
|
||||
}
|
||||
|
||||
public ProfileSettingsParams(Parcel in) {
|
||||
readFromParcel(in);
|
||||
}
|
||||
|
||||
public static final Creator<ProfileSettingsParams> CREATOR = new Creator<ProfileSettingsParams>() {
|
||||
@Override
|
||||
public ProfileSettingsParams createFromParcel(Parcel in) {
|
||||
return new ProfileSettingsParams(in);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ProfileSettingsParams[] newArray(int size) {
|
||||
return new ProfileSettingsParams[size];
|
||||
}
|
||||
};
|
||||
|
||||
public int getVersion() {
|
||||
return version;
|
||||
}
|
||||
|
||||
public String getLatestChanges() {
|
||||
return latestChanges;
|
||||
}
|
||||
|
||||
public Uri getProfileSettingsUri() {
|
||||
return profileSettingsUri;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToParcel(Parcel out, int flags) {
|
||||
out.writeInt(version);
|
||||
out.writeString(latestChanges);
|
||||
out.writeParcelable(profileSettingsUri, flags);
|
||||
}
|
||||
|
||||
private void readFromParcel(Parcel in) {
|
||||
version = in.readInt();
|
||||
latestChanges = in.readString();
|
||||
profileSettingsUri = in.readParcelable(Uri.class.getClassLoader());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int describeContents() {
|
||||
return 0;
|
||||
}
|
||||
}
|
|
@ -69,6 +69,9 @@ import static net.osmand.IndexConstants.OSMAND_SETTINGS_FILE_EXT;
|
|||
|
||||
public class SettingsHelper {
|
||||
|
||||
public static final String SETTINGS_LATEST_CHANGES_KEY = "settings_latest_changes";
|
||||
public static final String SETTINGS_VERSION_KEY = "settings_version";
|
||||
|
||||
private static final Log LOG = PlatformUtil.getLog(SettingsHelper.class);
|
||||
private static final int BUFFER = 1024;
|
||||
|
||||
|
@ -889,6 +892,9 @@ public class SettingsHelper {
|
|||
private class ImportAsyncTask extends AsyncTask<Void, Void, List<SettingsItem>> {
|
||||
|
||||
private File file;
|
||||
private String latestChanges;
|
||||
private int version;
|
||||
|
||||
private SettingsImportListener listener;
|
||||
private SettingsImporter importer;
|
||||
private List<SettingsItem> items;
|
||||
|
@ -896,10 +902,11 @@ public class SettingsHelper {
|
|||
private SettingsItem currentItem;
|
||||
private AlertDialog dialog;
|
||||
|
||||
ImportAsyncTask(@NonNull File settingsFile,
|
||||
@Nullable SettingsImportListener listener) {
|
||||
ImportAsyncTask(@NonNull File settingsFile, String latestChanges, int version, @Nullable SettingsImportListener listener) {
|
||||
this.file = settingsFile;
|
||||
this.listener = listener;
|
||||
this.latestChanges = latestChanges;
|
||||
this.version = version;
|
||||
importer = new SettingsImporter(app);
|
||||
}
|
||||
|
||||
|
@ -959,28 +966,8 @@ public class SettingsHelper {
|
|||
if (item.exists()) {
|
||||
switch (item.getType()) {
|
||||
case PROFILE: {
|
||||
AlertDialog.Builder b = new AlertDialog.Builder(activity);
|
||||
b.setMessage(activity.getString(R.string.overwrite_profile_q, item.getPublicName(app)));
|
||||
b.setPositiveButton(R.string.shared_string_yes, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
acceptItem(item);
|
||||
}
|
||||
});
|
||||
b.setNegativeButton(R.string.shared_string_no, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
processNextItem();
|
||||
}
|
||||
});
|
||||
b.setOnDismissListener(new DialogInterface.OnDismissListener() {
|
||||
@Override
|
||||
public void onDismiss(DialogInterface dialog) {
|
||||
ImportAsyncTask.this.dialog = null;
|
||||
}
|
||||
});
|
||||
b.setCancelable(false);
|
||||
dialog = b.show();
|
||||
String title = activity.getString(R.string.overwrite_profile_q, item.getPublicName(app));
|
||||
dialog = showConfirmDialog(item, title, latestChanges);
|
||||
break;
|
||||
}
|
||||
case FILE:
|
||||
|
@ -992,13 +979,44 @@ public class SettingsHelper {
|
|||
break;
|
||||
}
|
||||
} else {
|
||||
acceptItem(item);
|
||||
if (item.getType() == SettingsItemType.PROFILE) {
|
||||
String title = activity.getString(R.string.add_new_profile_q, item.getPublicName(app));
|
||||
dialog = showConfirmDialog(item, title, latestChanges);
|
||||
} else {
|
||||
acceptItem(item);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
processNextItem();
|
||||
}
|
||||
}
|
||||
|
||||
private AlertDialog showConfirmDialog(final SettingsItem item, String title, String message) {
|
||||
AlertDialog.Builder b = new AlertDialog.Builder(activity);
|
||||
b.setTitle(title);
|
||||
b.setMessage(message);
|
||||
b.setPositiveButton(R.string.shared_string_yes, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
acceptItem(item);
|
||||
}
|
||||
});
|
||||
b.setNegativeButton(R.string.shared_string_no, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
processNextItem();
|
||||
}
|
||||
});
|
||||
b.setOnDismissListener(new DialogInterface.OnDismissListener() {
|
||||
@Override
|
||||
public void onDismiss(DialogInterface dialog) {
|
||||
ImportAsyncTask.this.dialog = null;
|
||||
}
|
||||
});
|
||||
b.setCancelable(false);
|
||||
return b.show();
|
||||
}
|
||||
|
||||
private void suspendImport() {
|
||||
if (dialog != null) {
|
||||
dialog.dismiss();
|
||||
|
@ -1097,9 +1115,8 @@ public class SettingsHelper {
|
|||
}
|
||||
}
|
||||
|
||||
public void importSettings(@NonNull File settingsFile,
|
||||
@Nullable SettingsImportListener listener) {
|
||||
new ImportAsyncTask(settingsFile, listener).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
public void importSettings(@NonNull File settingsFile, String latestChanges, int version, @Nullable SettingsImportListener listener) {
|
||||
new ImportAsyncTask(settingsFile, latestChanges, version, listener).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
}
|
||||
|
||||
public void exportSettings(@NonNull File fileDir, @NonNull String fileName,
|
||||
|
|
|
@ -816,11 +816,11 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven
|
|||
if ("file".equals(scheme)) {
|
||||
final String path = data.getPath();
|
||||
if (path != null) {
|
||||
importHelper.handleFileImport(data, new File(path).getName(), true);
|
||||
importHelper.handleFileImport(data, new File(path).getName(), intent.getExtras(), true);
|
||||
}
|
||||
clearIntent(intent);
|
||||
} else if ("content".equals(scheme)) {
|
||||
importHelper.handleContentImport(data, true);
|
||||
importHelper.handleContentImport(data, intent.getExtras(), true);
|
||||
clearIntent(intent);
|
||||
} else if ("google.navigation".equals(scheme) || "osmand.navigation".equals(scheme)) {
|
||||
parseNavigationIntent(data);
|
||||
|
@ -1773,7 +1773,7 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven
|
|||
return mapLayers;
|
||||
}
|
||||
|
||||
public static void launchMapActivityMoveToTop(Context activity, Bundle intentParams) {
|
||||
public static void launchMapActivityMoveToTop(Context activity, Bundle prevIntentParams, Uri intentData, Bundle intentParams) {
|
||||
if (activity instanceof MapActivity) {
|
||||
if (((MapActivity) activity).getDashboard().isVisible()) {
|
||||
((MapActivity) activity).getDashboard().hideDashboard();
|
||||
|
@ -1785,9 +1785,9 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven
|
|||
Intent intent = ((Activity) activity).getIntent();
|
||||
if (intent != null) {
|
||||
prevActivityIntent = new Intent(intent);
|
||||
if (intentParams != null) {
|
||||
prevActivityIntent.putExtra(INTENT_PARAMS, intentParams);
|
||||
prevActivityIntent.putExtras(intentParams);
|
||||
if (prevIntentParams != null) {
|
||||
prevActivityIntent.putExtra(INTENT_PARAMS, prevIntentParams);
|
||||
prevActivityIntent.putExtras(prevIntentParams);
|
||||
}
|
||||
prevActivityIntent.putExtra(INTENT_KEY_PARENT_MAP_ACTIVITY, true);
|
||||
} else {
|
||||
|
@ -1801,6 +1801,14 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven
|
|||
Intent newIntent = new Intent(activity, ((OsmandApplication) activity.getApplicationContext())
|
||||
.getAppCustomization().getMapActivity());
|
||||
newIntent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT | Intent.FLAG_ACTIVITY_CLEAR_TOP | additionalFlags);
|
||||
if (intentData != null) {
|
||||
newIntent.setAction(Intent.ACTION_VIEW);
|
||||
newIntent.setData(intentData);
|
||||
}
|
||||
if (intentParams != null) {
|
||||
newIntent.putExtra(INTENT_PARAMS, intentParams);
|
||||
newIntent.putExtras(intentParams);
|
||||
}
|
||||
activity.startActivity(newIntent);
|
||||
}
|
||||
}
|
||||
|
@ -1809,6 +1817,10 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven
|
|||
launchMapActivityMoveToTop(activity, null);
|
||||
}
|
||||
|
||||
public static void launchMapActivityMoveToTop(Context activity, Bundle intentParams) {
|
||||
launchMapActivityMoveToTop(activity, intentParams, null, null);
|
||||
}
|
||||
|
||||
public static void clearPrevActivityIntent() {
|
||||
prevActivityIntent = null;
|
||||
}
|
||||
|
|
|
@ -37,6 +37,7 @@ import net.osmand.plus.GPXDatabase;
|
|||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.OsmandPlugin;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.SettingsHelper;
|
||||
import net.osmand.plus.SettingsHelper.SettingsImportListener;
|
||||
import net.osmand.plus.activities.MapActivity;
|
||||
import net.osmand.plus.activities.TrackActivity;
|
||||
|
@ -99,13 +100,13 @@ public class ImportHelper {
|
|||
this.gpxImportCompleteListener = gpxImportCompleteListener;
|
||||
}
|
||||
|
||||
public void handleContentImport(final Uri contentUri, final boolean useImportDir) {
|
||||
final String name = getNameFromContentUri(contentUri);
|
||||
handleFileImport(contentUri, name, useImportDir);
|
||||
public void handleContentImport(final Uri contentUri, Bundle extras, final boolean useImportDir) {
|
||||
final String name = getNameFromContentUri(app, contentUri);
|
||||
handleFileImport(contentUri, name, extras, useImportDir);
|
||||
}
|
||||
|
||||
public boolean handleGpxImport(final Uri contentUri, final boolean useImportDir) {
|
||||
String name = getNameFromContentUri(contentUri);
|
||||
String name = getNameFromContentUri(app, contentUri);
|
||||
boolean isOsmandSubdir = isSubDirectory(app.getAppPath(IndexConstants.GPX_INDEX_DIR), new File(contentUri.getPath()));
|
||||
if (!isOsmandSubdir && name != null) {
|
||||
String nameLC = name.toLowerCase();
|
||||
|
@ -136,12 +137,12 @@ public class ImportHelper {
|
|||
if (isFileIntent) {
|
||||
fileName = new File(uri.getPath()).getName();
|
||||
} else if (isContentIntent) {
|
||||
fileName = getNameFromContentUri(uri);
|
||||
fileName = getNameFromContentUri(app, uri);
|
||||
}
|
||||
handleFavouritesImport(uri, fileName, saveFile, false, true);
|
||||
}
|
||||
|
||||
public void handleFileImport(final Uri intentUri, final String fileName, final boolean useImportDir) {
|
||||
public void handleFileImport(Uri intentUri, String fileName, Bundle extras, boolean useImportDir) {
|
||||
final boolean isFileIntent = "file".equals(intentUri.getScheme());
|
||||
final boolean isOsmandSubdir = isSubDirectory(app.getAppPath(IndexConstants.GPX_INDEX_DIR), new File(intentUri.getPath()));
|
||||
|
||||
|
@ -156,13 +157,19 @@ public class ImportHelper {
|
|||
} else if (fileName != null && fileName.endsWith(IndexConstants.SQLITE_EXT)) {
|
||||
handleSqliteTileImport(intentUri, fileName);
|
||||
} else if (fileName != null && fileName.endsWith(IndexConstants.OSMAND_SETTINGS_FILE_EXT)) {
|
||||
handleOsmAndSettingsImport(intentUri, fileName);
|
||||
if (extras != null && extras.containsKey(SettingsHelper.SETTINGS_VERSION_KEY) && extras.containsKey(SettingsHelper.SETTINGS_LATEST_CHANGES_KEY)) {
|
||||
int version = extras.getInt(SettingsHelper.SETTINGS_VERSION_KEY, -1);
|
||||
String latestChanges = extras.getString(SettingsHelper.SETTINGS_LATEST_CHANGES_KEY);
|
||||
handleOsmAndSettingsImport(intentUri, fileName, latestChanges, version);
|
||||
} else {
|
||||
handleOsmAndSettingsImport(intentUri, fileName, null, -1);
|
||||
}
|
||||
} else {
|
||||
handleFavouritesImport(intentUri, fileName, saveFile, useImportDir, false);
|
||||
}
|
||||
}
|
||||
|
||||
private String getNameFromContentUri(Uri contentUri) {
|
||||
public static String getNameFromContentUri(OsmandApplication app, Uri contentUri) {
|
||||
final String name;
|
||||
final Cursor returnCursor = app.getContentResolver().query(contentUri, new String[] {OpenableColumns.DISPLAY_NAME}, null, null, null);
|
||||
if (returnCursor != null && returnCursor.moveToFirst()) {
|
||||
|
@ -434,7 +441,7 @@ public class ImportHelper {
|
|||
|
||||
@Override
|
||||
protected String doInBackground(Void... voids) {
|
||||
String error = copyFile(getObfDestFile(name), obfFile, false);
|
||||
String error = copyFile(app, getObfDestFile(name), obfFile, false);
|
||||
if (error == null) {
|
||||
app.getResourceManager().reloadIndexes(IProgress.EMPTY_PROGRESS, new ArrayList<String>());
|
||||
app.getDownloadThread().updateLoadedFiles();
|
||||
|
@ -464,7 +471,7 @@ public class ImportHelper {
|
|||
}
|
||||
|
||||
@Nullable
|
||||
private String copyFile(@NonNull File dest, @NonNull Uri uri, boolean overwrite) {
|
||||
public static String copyFile(OsmandApplication app, @NonNull File dest, @NonNull Uri uri, boolean overwrite) {
|
||||
if (dest.exists() && !overwrite) {
|
||||
return app.getString(R.string.file_with_name_already_exists);
|
||||
}
|
||||
|
@ -521,7 +528,7 @@ public class ImportHelper {
|
|||
|
||||
@Override
|
||||
protected String doInBackground(Void... voids) {
|
||||
return copyFile(app.getAppPath(IndexConstants.TILES_INDEX_DIR + name), uri, false);
|
||||
return copyFile(app, app.getAppPath(IndexConstants.TILES_INDEX_DIR + name), uri, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -547,7 +554,7 @@ public class ImportHelper {
|
|||
}
|
||||
|
||||
@SuppressLint("StaticFieldLeak")
|
||||
private void handleOsmAndSettingsImport(final Uri uri, final String name) {
|
||||
private void handleOsmAndSettingsImport(final Uri uri, final String name, final String latestChanges, final int version) {
|
||||
final AsyncTask<Void, Void, String> settingsImportTask = new AsyncTask<Void, Void, String>() {
|
||||
|
||||
ProgressDialog progress;
|
||||
|
@ -564,7 +571,7 @@ public class ImportHelper {
|
|||
tempDir.mkdirs();
|
||||
}
|
||||
File dest = new File(tempDir, name);
|
||||
return copyFile(dest, uri, true);
|
||||
return copyFile(app, dest, uri, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -572,7 +579,7 @@ public class ImportHelper {
|
|||
File tempDir = app.getAppPath(IndexConstants.TEMP_DIR);
|
||||
File file = new File(tempDir, name);
|
||||
if (error == null && file.exists()) {
|
||||
app.getSettingsHelper().importSettings(file, new SettingsImportListener() {
|
||||
app.getSettingsHelper().importSettings(file, latestChanges, version, new SettingsImportListener() {
|
||||
@Override
|
||||
public void onSettingsImportFinished(boolean succeed, boolean empty) {
|
||||
if (isActivityNotDestroyed(activity)) {
|
||||
|
|
Loading…
Reference in a new issue