add online source from url
This commit is contained in:
parent
26c4bd276b
commit
b6c8ab7362
2 changed files with 25 additions and 5 deletions
|
@ -11,6 +11,7 @@ import net.osmand.PlatformUtil;
|
||||||
import net.osmand.data.LatLon;
|
import net.osmand.data.LatLon;
|
||||||
import net.osmand.data.PointDescription;
|
import net.osmand.data.PointDescription;
|
||||||
import net.osmand.map.TileSourceManager;
|
import net.osmand.map.TileSourceManager;
|
||||||
|
import net.osmand.plus.mapsource.EditMapSourceDialogFragment;
|
||||||
import net.osmand.plus.settings.backend.ApplicationMode;
|
import net.osmand.plus.settings.backend.ApplicationMode;
|
||||||
import net.osmand.plus.MapMarkersHelper;
|
import net.osmand.plus.MapMarkersHelper;
|
||||||
import net.osmand.plus.OsmandApplication;
|
import net.osmand.plus.OsmandApplication;
|
||||||
|
@ -109,8 +110,8 @@ public class IntentHelper {
|
||||||
if (!attrs.isEmpty()) {
|
if (!attrs.isEmpty()) {
|
||||||
try {
|
try {
|
||||||
TileSourceManager.TileSourceTemplate r = TileSourceManager.createTileSourceTemplate(attrs);
|
TileSourceManager.TileSourceTemplate r = TileSourceManager.createTileSourceTemplate(attrs);
|
||||||
if (r != null && settings.installTileSource(r)) {
|
if (r != null) {
|
||||||
app.showShortToastMessage(app.getString(R.string.edit_tilesource_successfully, r.getName()));
|
EditMapSourceDialogFragment.showInstance(mapActivity.getSupportFragmentManager(), r);
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
LOG.error("parseAddTileSourceIntent error", e);
|
LOG.error("parseAddTileSourceIntent error", e);
|
||||||
|
|
|
@ -77,6 +77,7 @@ public class EditMapSourceDialogFragment extends BaseOsmAndDialogFragment
|
||||||
private static final String EXPIRE_TIME_KEY = "expire_time_key";
|
private static final String EXPIRE_TIME_KEY = "expire_time_key";
|
||||||
private static final String ELLIPTIC_KEY = "elliptic_key";
|
private static final String ELLIPTIC_KEY = "elliptic_key";
|
||||||
private static final String SQLITE_DB_KEY = "sqlite_db_key";
|
private static final String SQLITE_DB_KEY = "sqlite_db_key";
|
||||||
|
private static final String FROM_TEMPLATE_KEY = "from_template_key";
|
||||||
private OsmandApplication app;
|
private OsmandApplication app;
|
||||||
private TextInputEditText nameEditText;
|
private TextInputEditText nameEditText;
|
||||||
private TextInputEditText urlEditText;
|
private TextInputEditText urlEditText;
|
||||||
|
@ -93,6 +94,7 @@ public class EditMapSourceDialogFragment extends BaseOsmAndDialogFragment
|
||||||
private boolean elliptic = false;
|
private boolean elliptic = false;
|
||||||
private boolean sqliteDB = false;
|
private boolean sqliteDB = false;
|
||||||
private boolean nightMode;
|
private boolean nightMode;
|
||||||
|
private boolean fromTemplate = false;
|
||||||
|
|
||||||
public static void showInstance(@NonNull FragmentManager fm,
|
public static void showInstance(@NonNull FragmentManager fm,
|
||||||
@Nullable Fragment targetFragment,
|
@Nullable Fragment targetFragment,
|
||||||
|
@ -103,6 +105,14 @@ public class EditMapSourceDialogFragment extends BaseOsmAndDialogFragment
|
||||||
fragment.show(fm, TAG);
|
fragment.show(fm, TAG);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void showInstance(@NonNull FragmentManager fm,
|
||||||
|
@NonNull TileSourceTemplate template) {
|
||||||
|
EditMapSourceDialogFragment fragment = new EditMapSourceDialogFragment();
|
||||||
|
fragment.setTemplate(template);
|
||||||
|
fragment.fromTemplate = true;
|
||||||
|
fragment.show(fm, TAG);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
@ -119,6 +129,7 @@ public class EditMapSourceDialogFragment extends BaseOsmAndDialogFragment
|
||||||
expireTimeMinutes = savedInstanceState.getInt(EXPIRE_TIME_KEY);
|
expireTimeMinutes = savedInstanceState.getInt(EXPIRE_TIME_KEY);
|
||||||
elliptic = savedInstanceState.getBoolean(ELLIPTIC_KEY);
|
elliptic = savedInstanceState.getBoolean(ELLIPTIC_KEY);
|
||||||
sqliteDB = savedInstanceState.getBoolean(SQLITE_DB_KEY);
|
sqliteDB = savedInstanceState.getBoolean(SQLITE_DB_KEY);
|
||||||
|
fromTemplate = savedInstanceState.getBoolean(FROM_TEMPLATE_KEY);
|
||||||
}
|
}
|
||||||
View root = UiUtilities.getMaterialInflater(requireContext(), nightMode).inflate(R.layout.fragment_edit_map_source, container, false);
|
View root = UiUtilities.getMaterialInflater(requireContext(), nightMode).inflate(R.layout.fragment_edit_map_source, container, false);
|
||||||
Toolbar toolbar = root.findViewById(R.id.toolbar);
|
Toolbar toolbar = root.findViewById(R.id.toolbar);
|
||||||
|
@ -172,8 +183,10 @@ public class EditMapSourceDialogFragment extends BaseOsmAndDialogFragment
|
||||||
dismiss();
|
dismiss();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
if (template == null) {
|
||||||
template = new TileSourceTemplate("", "", PNG_EXT, MAX_ZOOM, MIN_ZOOM, TILE_SIZE, BIT_DENSITY, AVG_SIZE);
|
template = new TileSourceTemplate("", "", PNG_EXT, MAX_ZOOM, MIN_ZOOM, TILE_SIZE, BIT_DENSITY, AVG_SIZE);
|
||||||
if (editedLayerName != null) {
|
}
|
||||||
|
if (editedLayerName != null && !fromTemplate) {
|
||||||
if (!editedLayerName.endsWith(IndexConstants.SQLITE_EXT)) {
|
if (!editedLayerName.endsWith(IndexConstants.SQLITE_EXT)) {
|
||||||
File f = app.getAppPath(IndexConstants.TILES_INDEX_DIR + editedLayerName);
|
File f = app.getAppPath(IndexConstants.TILES_INDEX_DIR + editedLayerName);
|
||||||
template = TileSourceManager.createTileSourceTemplate(f);
|
template = TileSourceManager.createTileSourceTemplate(f);
|
||||||
|
@ -194,6 +207,7 @@ public class EditMapSourceDialogFragment extends BaseOsmAndDialogFragment
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (savedInstanceState == null) {
|
if (savedInstanceState == null) {
|
||||||
|
editedLayerName = template.getName();
|
||||||
urlToLoad = template.getUrlTemplate();
|
urlToLoad = template.getUrlTemplate();
|
||||||
expireTimeMinutes = template.getExpirationTimeMinutes();
|
expireTimeMinutes = template.getExpirationTimeMinutes();
|
||||||
minZoom = template.getMinimumZoomSupported();
|
minZoom = template.getMinimumZoomSupported();
|
||||||
|
@ -212,6 +226,7 @@ public class EditMapSourceDialogFragment extends BaseOsmAndDialogFragment
|
||||||
outState.putInt(EXPIRE_TIME_KEY, expireTimeMinutes);
|
outState.putInt(EXPIRE_TIME_KEY, expireTimeMinutes);
|
||||||
outState.putBoolean(ELLIPTIC_KEY, elliptic);
|
outState.putBoolean(ELLIPTIC_KEY, elliptic);
|
||||||
outState.putBoolean(SQLITE_DB_KEY, sqliteDB);
|
outState.putBoolean(SQLITE_DB_KEY, sqliteDB);
|
||||||
|
outState.putBoolean(FROM_TEMPLATE_KEY, fromTemplate);
|
||||||
super.onSaveInstanceState(outState);
|
super.onSaveInstanceState(outState);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -408,7 +423,7 @@ public class EditMapSourceDialogFragment extends BaseOsmAndDialogFragment
|
||||||
InputZoomLevelsBottomSheet.showInstance(
|
InputZoomLevelsBottomSheet.showInstance(
|
||||||
fm, EditMapSourceDialogFragment.this,
|
fm, EditMapSourceDialogFragment.this,
|
||||||
R.string.map_source_zoom_levels, R.string.map_source_zoom_levels_descr,
|
R.string.map_source_zoom_levels, R.string.map_source_zoom_levels_descr,
|
||||||
minZoom, maxZoom, editedLayerName == null
|
minZoom, maxZoom, editedLayerName == null && !fromTemplate
|
||||||
);
|
);
|
||||||
break;
|
break;
|
||||||
case EXPIRE_TIME:
|
case EXPIRE_TIME:
|
||||||
|
@ -464,6 +479,10 @@ public class EditMapSourceDialogFragment extends BaseOsmAndDialogFragment
|
||||||
this.editedLayerName = editedLayerName;
|
this.editedLayerName = editedLayerName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setTemplate(TileSourceTemplate template) {
|
||||||
|
this.template = template;
|
||||||
|
}
|
||||||
|
|
||||||
public interface OnMapSourceUpdateListener {
|
public interface OnMapSourceUpdateListener {
|
||||||
void onMapSourceUpdated();
|
void onMapSourceUpdated();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue