use of com.peterlaurence.trekadvisor.core.map.Map in project TrekAdvisor by peterLaurence.
the class MapCalibrationFragment method updateCoordinateFieldsFromData.
private void updateCoordinateFieldsFromData(int calibrationPointNumber) {
/* Get the calibration points */
Map map = mMapWeakReference.get();
if (map == null)
return;
List<MapGson.Calibration.CalibrationPoint> calibrationPointList = map.getCalibrationPoints();
if (calibrationPointList != null && calibrationPointList.size() > calibrationPointNumber) {
MapGson.Calibration.CalibrationPoint calibrationPoint = calibrationPointList.get(calibrationPointNumber);
Projection projection = mMapWeakReference.get().getProjection();
if (rootView.isWgs84() && projection != null) {
double[] wgs84 = projection.undoProjection(calibrationPoint.proj_x, calibrationPoint.proj_y);
if (wgs84 != null && wgs84.length == 2) {
rootView.updateCoordinateFields(wgs84[0], wgs84[1]);
}
} else {
rootView.updateCoordinateFields(calibrationPoint.proj_x, calibrationPoint.proj_y);
}
}
}
use of com.peterlaurence.trekadvisor.core.map.Map in project TrekAdvisor by peterLaurence.
the class MapUpdateTask method doInBackground.
@Override
protected Void doInBackground(File... dirs) {
/* Search for json files */
for (File dir : dirs) {
findMaps(dir, 1);
}
/* Now parse the json files found */
for (File f : mapFilesFoundList) {
/* Get json file content as String */
String jsonString;
try {
jsonString = FileUtils.getStringFromFile(f);
} catch (Exception e) {
// Error while decoding the json file
Log.e(TAG, e.getMessage(), e);
continue;
}
try {
/* json deserialization */
MapGson mapGson = mGson.fromJson(jsonString, MapGson.class);
/* Map creation */
Map map = mapGson.thumbnail == null ? new Map(mapGson, f, null) : new Map(mapGson, f, new File(f.getParent(), mapGson.thumbnail));
/* Calibration */
map.calibrate();
/* Set BitMapProvider */
map.setBitmapProvider(MapLoader.makeBitmapProvider(map));
mMapList.add(map);
} catch (JsonSyntaxException | NullPointerException e) {
Log.e(TAG, e.getMessage(), e);
}
}
return null;
}
use of com.peterlaurence.trekadvisor.core.map.Map in project TrekAdvisor by peterLaurence.
the class MapViewFragment method updateMapIfNecessary.
/**
* Only update the map if its a new one. <br>
* Once the map is updated, a {@link TileViewExtended} instance is created, so layers can be
* updated.
*/
private void updateMapIfNecessary() {
Map map = mMapProvider.getCurrentMap();
if (map != null) {
if (mMap != null && mMap.equals(map)) {
Map.MapBounds newBounds = map.getMapBounds();
if (mTileView != null) {
CoordinateTranslater c = mTileView.getCoordinateTranslater();
if (newBounds != null && !newBounds.compareTo(c.getLeft(), c.getTop(), c.getRight(), c.getBottom())) {
setTileViewBounds(mTileView, map);
}
}
} else {
setMap(map);
updateLayers();
}
}
}
use of com.peterlaurence.trekadvisor.core.map.Map in project TrekAdvisor by peterLaurence.
the class MapListFragment method onSaveMapEvent.
/**
* Process a request to archive a {@link Map}. This is typically called from a
* {@link ArchiveMapDialog}. <p>
* A {@link Notification} is sent to the user showing the progression in percent. The
* {@link NotificationManager} only process one notification at a time, which is handy since
* it prevents the application from using too much cpu.
*
* @param event The {@link com.peterlaurence.trekadvisor.menu.maplist.dialogs.ArchiveMapDialog.SaveMapEvent}
* which contains the id of the {@link Map}.
*/
@Subscribe
public void onSaveMapEvent(ArchiveMapDialog.SaveMapEvent event) {
Map map = MapLoader.getInstance().getMap(event.mapId);
if (map == null)
return;
final String notificationChannelId = "trekadvisor_map_save";
/* Build the notification and issue it */
final Notification.Builder builder = new Notification.Builder(getActivity()).setSmallIcon(R.drawable.ic_map_black_24dp).setContentTitle(getString(R.string.archive_dialog_title)).setContentText(String.format(getString(R.string.archive_notification_msg), map.getName()));
final int notificationId = event.mapId;
final NotificationManager notifyMgr = (NotificationManager) getActivity().getSystemService(NOTIFICATION_SERVICE);
if (android.os.Build.VERSION.SDK_INT >= 26) {
// This only needs to be run on Devices on Android O and above
NotificationChannel mChannel = new NotificationChannel(notificationChannelId, getText(R.string.service_description), NotificationManager.IMPORTANCE_LOW);
mChannel.enableLights(true);
mChannel.setLightColor(Color.YELLOW);
if (notifyMgr != null) {
notifyMgr.createNotificationChannel(mChannel);
}
builder.setChannelId(notificationChannelId);
}
if (notifyMgr != null) {
notifyMgr.notify(notificationId, builder.build());
}
/* Effectively launch the archive task */
map.zip(new ZipTask.ZipProgressionListener() {
@Override
public void fileListAcquired() {
}
@Override
public void onProgress(int p) {
builder.setProgress(100, p, false);
notifyMgr.notify(notificationId, builder.build());
}
@Override
public void onZipFinished(File outputDirectory) {
String archiveOkMsg = getContext().getString(R.string.archive_snackbar_finished);
/* When the loop is finished, updates the notification */
builder.setContentText(archiveOkMsg).setProgress(0, 0, false);
notifyMgr.notify(notificationId, builder.build());
View view = getView();
if (view != null) {
Snackbar snackbar = Snackbar.make(view, archiveOkMsg, Snackbar.LENGTH_SHORT);
snackbar.show();
}
}
@Override
public void onZipError() {
}
});
}
use of com.peterlaurence.trekadvisor.core.map.Map in project TrekAdvisor by peterLaurence.
the class MapCalibrationFragment method onCreateView.
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
rootView = new MapCalibrationLayout(getContext());
rootView.setCalibrationModel(this);
/* Set the map to calibrate */
Map map = mMapProvider.getSettingsMap();
setMap(map);
/* If the fragment is created for the first time (e.g not re-created after a configuration
* change), init the layout to its default.
* Otherwise, restore the last position of the calibration marker.
*/
if (savedInstanceState == null) {
rootView.setDefault();
} else {
double relativeX = savedInstanceState.getDouble(CALIBRATION_MARKER_X);
double relativeY = savedInstanceState.getDouble(CALIBRATION_MARKER_Y);
moveCalibrationMarker(mTileView, mCalibrationMarker, relativeX, relativeY);
}
return rootView;
}
Aggregations