Search in sources :

Example 6 with Map

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);
        }
    }
}
Also used : MapGson(com.peterlaurence.trekadvisor.core.map.gson.MapGson) Projection(com.peterlaurence.trekadvisor.core.projection.Projection) Map(com.peterlaurence.trekadvisor.core.map.Map)

Example 7 with Map

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;
}
Also used : JsonSyntaxException(com.google.gson.JsonSyntaxException) MapGson(com.peterlaurence.trekadvisor.core.map.gson.MapGson) File(java.io.File) Map(com.peterlaurence.trekadvisor.core.map.Map) JsonSyntaxException(com.google.gson.JsonSyntaxException)

Example 8 with Map

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();
        }
    }
}
Also used : CoordinateTranslater(com.qozix.tileview.geom.CoordinateTranslater) Map(com.peterlaurence.trekadvisor.core.map.Map)

Example 9 with Map

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() {
        }
    });
}
Also used : NotificationManager(android.app.NotificationManager) ZipTask(com.peterlaurence.trekadvisor.util.ZipTask) View(android.view.View) RecyclerView(android.support.v7.widget.RecyclerView) Notification(android.app.Notification) NotificationChannel(android.app.NotificationChannel) Map(com.peterlaurence.trekadvisor.core.map.Map) File(java.io.File) Snackbar(android.support.design.widget.Snackbar) Subscribe(org.greenrobot.eventbus.Subscribe)

Example 10 with Map

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;
}
Also used : Map(com.peterlaurence.trekadvisor.core.map.Map)

Aggregations

Map (com.peterlaurence.trekadvisor.core.map.Map)10 MapGson (com.peterlaurence.trekadvisor.core.map.gson.MapGson)4 EditTextPreference (android.preference.EditTextPreference)2 ListPreference (android.preference.ListPreference)2 Preference (android.preference.Preference)2 View (android.view.View)2 Projection (com.peterlaurence.trekadvisor.core.projection.Projection)2 File (java.io.File)2 AlertDialog (android.app.AlertDialog)1 Dialog (android.app.Dialog)1 DialogFragment (android.app.DialogFragment)1 Notification (android.app.Notification)1 NotificationChannel (android.app.NotificationChannel)1 NotificationManager (android.app.NotificationManager)1 Context (android.content.Context)1 DialogInterface (android.content.DialogInterface)1 SharedPreferences (android.content.SharedPreferences)1 Bundle (android.os.Bundle)1 PreferenceFragment (android.preference.PreferenceFragment)1 Snackbar (android.support.design.widget.Snackbar)1