Search in sources :

Example 1 with CustomOsmandPlugin

use of net.osmand.plus.plugins.CustomOsmandPlugin in project Osmand by osmandapp.

the class ExternalApiHelper method getPluginAndProfileVersions.

@NonNull
public static Bundle getPluginAndProfileVersions() {
    Bundle bundle = new Bundle();
    List<CustomOsmandPlugin> plugins = OsmandPlugin.getCustomPlugins();
    if (!Algorithms.isEmpty(plugins)) {
        HashMap<String, Integer> map = new HashMap<>();
        for (CustomOsmandPlugin plugin : plugins) {
            map.put(plugin.getId(), plugin.getVersion());
        }
        bundle.putSerializable(PARAM_PLUGINS_VERSIONS, map);
    }
    for (ApplicationMode mode : ApplicationMode.allPossibleValues()) {
        HashMap<String, Integer> map = new HashMap<>();
        map.put(mode.getStringKey(), mode.getVersion());
        bundle.putSerializable(PARAM_PROFILES_VERSIONS, map);
    }
    return bundle;
}
Also used : HashMap(java.util.HashMap) Bundle(android.os.Bundle) CustomOsmandPlugin(net.osmand.plus.plugins.CustomOsmandPlugin) ApplicationMode(net.osmand.plus.settings.backend.ApplicationMode) NonNull(androidx.annotation.NonNull)

Example 2 with CustomOsmandPlugin

use of net.osmand.plus.plugins.CustomOsmandPlugin in project Osmand by osmandapp.

the class PluginSettingsItem method readFromJson.

@Override
void readFromJson(@NonNull JSONObject json) throws JSONException {
    super.readFromJson(json);
    plugin = new CustomOsmandPlugin(app, json);
}
Also used : CustomOsmandPlugin(net.osmand.plus.plugins.CustomOsmandPlugin)

Example 3 with CustomOsmandPlugin

use of net.osmand.plus.plugins.CustomOsmandPlugin in project Osmand by osmandapp.

the class SettingsImportTask method handlePluginImport.

private void handlePluginImport(final PluginSettingsItem pluginItem, final File file) {
    FragmentActivity activity = activityRef.get();
    final ProgressDialog progress;
    if (AndroidUtils.isActivityNotDestroyed(activity)) {
        progress = new ProgressDialog(activity);
        progress.setTitle(app.getString(R.string.loading_smth, ""));
        progress.setMessage(app.getString(R.string.importing_from, pluginItem.getPublicName(app)));
        progress.setIndeterminate(true);
        progress.setCancelable(false);
        progress.show();
    } else {
        progress = null;
    }
    final ImportListener importListener = new ImportListener() {

        @Override
        public void onImportItemStarted(@NonNull String type, @NonNull String fileName, int work) {
        }

        @Override
        public void onImportItemProgress(@NonNull String type, @NonNull String fileName, int value) {
        }

        @Override
        public void onImportItemFinished(@NonNull String type, @NonNull String fileName) {
        }

        @Override
        public void onImportFinished(boolean succeed, boolean needRestart, @NonNull List<SettingsItem> items) {
            FragmentActivity activity = activityRef.get();
            if (progress != null && AndroidUtils.isActivityNotDestroyed(activity)) {
                progress.dismiss();
            }
            AudioVideoNotesPlugin pluginAudioVideo = OsmandPlugin.getPlugin(AudioVideoNotesPlugin.class);
            if (pluginAudioVideo != null) {
                pluginAudioVideo.indexingFiles(true, true);
            }
            CustomOsmandPlugin plugin = pluginItem.getPlugin();
            plugin.loadResources();
            if (!Algorithms.isEmpty(plugin.getDownloadMaps())) {
                app.getDownloadThread().runReloadIndexFilesSilent();
            }
            if (!Algorithms.isEmpty(plugin.getRendererNames())) {
                app.getRendererRegistry().updateExternalRenderers();
            }
            if (!Algorithms.isEmpty(plugin.getRouterNames())) {
                loadRoutingFiles(app, null);
            }
            if (!silentImport && activity != null) {
                plugin.onInstall(app, activity);
            }
            String pluginId = pluginItem.getPluginId();
            File pluginDir = app.getAppPath(IndexConstants.PLUGINS_DIR + pluginId);
            if (!pluginDir.exists()) {
                pluginDir.mkdirs();
            }
            app.getFileSettingsHelper().exportSettings(pluginDir, "items", null, items, false);
        }
    };
    List<SettingsItem> pluginItems = new ArrayList<>(pluginItem.getPluginDependentItems());
    pluginItems.add(0, pluginItem);
    app.getFileSettingsHelper().checkDuplicates(file, pluginItems, pluginItems, new CheckDuplicatesListener() {

        @Override
        public void onDuplicatesChecked(@NonNull List<Object> duplicates, List<SettingsItem> items) {
            for (SettingsItem item : items) {
                item.setShouldReplace(true);
            }
            app.getFileSettingsHelper().importSettings(file, items, "", 1, importListener);
        }
    });
}
Also used : AudioVideoNotesPlugin(net.osmand.plus.plugins.audionotes.AudioVideoNotesPlugin) CustomOsmandPlugin(net.osmand.plus.plugins.CustomOsmandPlugin) ArrayList(java.util.ArrayList) ProgressDialog(android.app.ProgressDialog) ImportListener(net.osmand.plus.settings.backend.backup.SettingsHelper.ImportListener) FragmentActivity(androidx.fragment.app.FragmentActivity) SettingsItem(net.osmand.plus.settings.backend.backup.items.SettingsItem) PluginSettingsItem(net.osmand.plus.settings.backend.backup.items.PluginSettingsItem) NonNull(androidx.annotation.NonNull) ArrayList(java.util.ArrayList) List(java.util.List) CallbackWithObject(net.osmand.CallbackWithObject) File(java.io.File) CheckDuplicatesListener(net.osmand.plus.settings.backend.backup.SettingsHelper.CheckDuplicatesListener)

Example 4 with CustomOsmandPlugin

use of net.osmand.plus.plugins.CustomOsmandPlugin in project Osmand by osmandapp.

the class ProfileSettingsItem method updatePluginResPrefs.

private void updatePluginResPrefs() {
    String pluginId = getPluginId();
    if (Algorithms.isEmpty(pluginId)) {
        return;
    }
    OsmandPlugin plugin = OsmandPlugin.getPlugin(pluginId);
    if (plugin instanceof CustomOsmandPlugin) {
        CustomOsmandPlugin customPlugin = (CustomOsmandPlugin) plugin;
        String resDirPath = IndexConstants.PLUGINS_DIR + pluginId + "/" + customPlugin.getResourceDirName();
        for (Iterator<String> it = additionalPrefsJson.keys(); it.hasNext(); ) {
            try {
                String prefId = it.next();
                Object value = additionalPrefsJson.get(prefId);
                if (value instanceof JSONObject) {
                    JSONObject jsonObject = (JSONObject) value;
                    for (Iterator<String> iterator = jsonObject.keys(); iterator.hasNext(); ) {
                        String key = iterator.next();
                        Object val = jsonObject.get(key);
                        if (val instanceof String) {
                            val = checkPluginResPath((String) val, resDirPath);
                        }
                        jsonObject.put(key, val);
                    }
                } else if (value instanceof String) {
                    value = checkPluginResPath((String) value, resDirPath);
                    additionalPrefsJson.put(prefId, value);
                }
            } catch (JSONException e) {
                SettingsHelper.LOG.error(e);
            }
        }
    }
}
Also used : JSONObject(org.json.JSONObject) CustomOsmandPlugin(net.osmand.plus.plugins.CustomOsmandPlugin) JSONException(org.json.JSONException) JSONObject(org.json.JSONObject) CustomOsmandPlugin(net.osmand.plus.plugins.CustomOsmandPlugin) OsmandPlugin(net.osmand.plus.plugins.OsmandPlugin)

Aggregations

CustomOsmandPlugin (net.osmand.plus.plugins.CustomOsmandPlugin)4 NonNull (androidx.annotation.NonNull)2 ProgressDialog (android.app.ProgressDialog)1 Bundle (android.os.Bundle)1 FragmentActivity (androidx.fragment.app.FragmentActivity)1 File (java.io.File)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 CallbackWithObject (net.osmand.CallbackWithObject)1 OsmandPlugin (net.osmand.plus.plugins.OsmandPlugin)1 AudioVideoNotesPlugin (net.osmand.plus.plugins.audionotes.AudioVideoNotesPlugin)1 ApplicationMode (net.osmand.plus.settings.backend.ApplicationMode)1 CheckDuplicatesListener (net.osmand.plus.settings.backend.backup.SettingsHelper.CheckDuplicatesListener)1 ImportListener (net.osmand.plus.settings.backend.backup.SettingsHelper.ImportListener)1 PluginSettingsItem (net.osmand.plus.settings.backend.backup.items.PluginSettingsItem)1 SettingsItem (net.osmand.plus.settings.backend.backup.items.SettingsItem)1 JSONException (org.json.JSONException)1 JSONObject (org.json.JSONObject)1