Search in sources :

Example 1 with Map

use of com.peterlaurence.trekadvisor.core.map.Map in project TrekAdvisor by peterLaurence.

the class MapAdapter method onBindViewHolder.

@Override
public void onBindViewHolder(MapViewHolder holder, int position) {
    final Map map = maps.get(position);
    holder.mapImage.setImageBitmap(map.getImage());
    holder.mapName.setText(map.getName());
    holder.calibrationStatus.setText(map.getDescription());
    if (holder.getLayoutPosition() == selectedMapIndex) {
        holder.cardView.setCardBackgroundColor(mColorAccent);
        holder.mapName.setTextColor(mColorWhiteText);
        holder.editButton.setTextColor(mColorWhiteText);
        holder.saveButton.setColorFilter(mColorWhiteText);
        holder.calibrationStatus.setTextColor(mColorWhiteText);
    } else {
        holder.cardView.setCardBackgroundColor(Color.WHITE);
        holder.mapName.setTextColor(mColorBlackText);
        holder.editButton.setTextColor(mColorAccent);
        holder.saveButton.setColorFilter(mColorAccent);
    }
    switch(map.getCalibrationStatus()) {
        case OK:
            holder.calibrationStatus.setText(R.string.calibration_status_ok);
            break;
        case NONE:
            holder.calibrationStatus.setText(R.string.calibration_status_none);
            break;
        case ERROR:
            holder.calibrationStatus.setText(R.string.calibration_status_error);
            break;
    }
    /* Set click listeners */
    holder.itemView.setOnClickListener(new MapViewHolderClickListener(holder, this));
    holder.editButton.setOnClickListener(new SettingsButtonClickListener(holder, this));
    holder.saveButton.setOnClickListener(new ArchiveButtonClickListener(holder, this));
}
Also used : Map(com.peterlaurence.trekadvisor.core.map.Map)

Example 2 with Map

use of com.peterlaurence.trekadvisor.core.map.Map in project TrekAdvisor by peterLaurence.

the class MapSettingsFragment method initComponents.

private void initComponents() {
    ListPreference mCalibrationListPreference = (ListPreference) getPreferenceManager().findPreference(getString(R.string.preference_projection_key));
    ListPreference mCalibrationPointsNumberPreference = (ListPreference) getPreferenceManager().findPreference(getString(R.string.preference_numpoints_key));
    EditTextPreference mapNamePreference = (EditTextPreference) getPreferenceManager().findPreference(getString(R.string.preference_map_title_key));
    Preference calibrationButton = getPreferenceManager().findPreference(getString(R.string.preference_calibration_button_key));
    Preference deleteButton = getPreferenceManager().findPreference(getString(R.string.preference_delete_button_key));
    /* Set the summaries and the values of preferences according to the Map object */
    final Map map = mMapWeakReference.get();
    if (map != null) {
        String projectionName;
        if ((projectionName = map.getProjectionName()) == null) {
            projectionName = getString(R.string.projection_none);
        }
        setListPreferenceSummaryAndValue(mCalibrationListPreference, projectionName);
        setListPreferenceSummaryAndValue(mCalibrationPointsNumberPreference, String.valueOf(map.getCalibrationPointsNumber()));
        setEditTextPreferenceSummaryAndValue(mapNamePreference, map.getName());
    }
    calibrationButton.setOnPreferenceClickListener(preference -> {
        mMapCalibrationRequestListener.onMapCalibrationRequest();
        return true;
    });
    mCalibrationPointsNumberPreference.setOnPreferenceChangeListener(((preference, newValue) -> {
        Map map_ = mMapWeakReference.get();
        if (map_ != null) {
            switch((String) newValue) {
                case "2":
                    map_.setCalibrationMethod(MapLoader.CALIBRATION_METHOD.SIMPLE_2_POINTS);
                    break;
                case "3":
                    map_.setCalibrationMethod(MapLoader.CALIBRATION_METHOD.CALIBRATION_3_POINTS);
                    break;
                case "4":
                    map_.setCalibrationMethod(MapLoader.CALIBRATION_METHOD.CALIBRATION_4_POINTS);
                    break;
                default:
                    map_.setCalibrationMethod(MapLoader.CALIBRATION_METHOD.SIMPLE_2_POINTS);
            }
            return true;
        }
        return false;
    }));
    mapNamePreference.setOnPreferenceChangeListener((preference, newValue) -> {
        try {
            mMapWeakReference.get().setName((String) newValue);
            return true;
        } catch (Exception e) {
            return false;
        }
    });
    mCalibrationListPreference.setOnPreferenceChangeListener((preference, projectionName) -> {
        try {
            /* If the projection is set to none */
            if (getString(R.string.projection_none).equals(projectionName)) {
                mMapWeakReference.get().setProjection(null);
                return true;
            }
            if (MapLoader.getInstance().mutateMapProjection(mMapWeakReference.get(), (String) projectionName)) {
                String saveOkMsg = getString(R.string.calibration_projection_saved_ok);
                Toast toast = Toast.makeText(getContext(), saveOkMsg, Toast.LENGTH_SHORT);
                toast.show();
            } else {
            // TODO : show some warning ("Wrong Projection name").
            }
            return true;
        } catch (Exception e) {
            return false;
        }
    });
    deleteButton.setOnPreferenceClickListener(preference -> {
        ConfirmDeleteFragment f = new ConfirmDeleteFragment();
        f.setMapWeakRef(mMapWeakReference);
        f.setDeleteMapListener(mDeleteMapListener);
        f.show(getFragmentManager(), "delete");
        return true;
    });
}
Also used : Context(android.content.Context) LinearLayout(android.widget.LinearLayout) Bundle(android.os.Bundle) LayoutInflater(android.view.LayoutInflater) MapLoader(com.peterlaurence.trekadvisor.core.map.maploader.MapLoader) Dialog(android.app.Dialog) ViewGroup(android.view.ViewGroup) AlertDialog(android.app.AlertDialog) EditTextPreference(android.preference.EditTextPreference) Map(com.peterlaurence.trekadvisor.core.map.Map) ListPreference(android.preference.ListPreference) SharedPreferences(android.content.SharedPreferences) Preference(android.preference.Preference) PreferenceFragment(android.preference.PreferenceFragment) R(com.peterlaurence.trekadvisor.R) Toast(android.widget.Toast) View(android.view.View) DialogFragment(android.app.DialogFragment) WeakReference(java.lang.ref.WeakReference) DialogInterface(android.content.DialogInterface) Toast(android.widget.Toast) EditTextPreference(android.preference.EditTextPreference) ListPreference(android.preference.ListPreference) Preference(android.preference.Preference) ListPreference(android.preference.ListPreference) EditTextPreference(android.preference.EditTextPreference) Map(com.peterlaurence.trekadvisor.core.map.Map)

Example 3 with Map

use of com.peterlaurence.trekadvisor.core.map.Map in project TrekAdvisor by peterLaurence.

the class MapSettingsFragment method onSharedPreferenceChanged.

@Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
    Preference pref = findPreference(key);
    if (pref != null) {
        pref.setSummary(sharedPreferences.getString(key, "default"));
        /* Save the Map content */
        Map map = mMapWeakReference.get();
        MapLoader.getInstance().saveMap(map);
    }
}
Also used : EditTextPreference(android.preference.EditTextPreference) ListPreference(android.preference.ListPreference) Preference(android.preference.Preference) Map(com.peterlaurence.trekadvisor.core.map.Map)

Example 4 with Map

use of com.peterlaurence.trekadvisor.core.map.Map in project TrekAdvisor by peterLaurence.

the class MapCalibrationFragment method onSave.

/**
 * Save the current calibration point. Its index is saved in {@code mCurrentCalibrationPoint}.
 */
@Override
public void onSave() {
    double x = rootView.getXValue();
    double y = rootView.getYValue();
    if (x == Double.MAX_VALUE || y == Double.MAX_VALUE) {
        return;
    }
    /* Get the calibration points */
    Map map = mMapWeakReference.get();
    if (map == null)
        return;
    List<MapGson.Calibration.CalibrationPoint> calibrationPointList = map.getCalibrationPoints();
    MapGson.Calibration.CalibrationPoint calibrationPoint;
    if (calibrationPointList.size() > mCurrentCalibrationPoint) {
        calibrationPoint = calibrationPointList.get(mCurrentCalibrationPoint);
    } else {
        calibrationPoint = new MapGson.Calibration.CalibrationPoint();
        map.addCalibrationPoint(calibrationPoint);
    }
    Projection projection = map.getProjection();
    if (rootView.isWgs84() && projection != null) {
        double[] projectedValues = projection.doProjection(y, x);
        if (projectedValues != null) {
            calibrationPoint.proj_x = projectedValues[0];
            calibrationPoint.proj_y = projectedValues[1];
        } else {
            displayErrorMessage(R.string.projected_instead_of_wgs84);
            return;
        }
    } else {
        /* If no projection is defined or no mistake is detected, we continue */
        if (projection == null || projection.undoProjection(x, y) != null) {
            calibrationPoint.proj_x = x;
            calibrationPoint.proj_y = y;
        } else {
            /* ..else, show error message and stop */
            displayErrorMessage(R.string.wgs84_instead_of_projected);
            return;
        }
    }
    /* Save relative position */
    calibrationPoint.x = mCalibrationMarker.getRelativeX();
    calibrationPoint.y = mCalibrationMarker.getRelativeY();
    /* Update calibration */
    map.calibrate();
    /* Save */
    MapLoader.getInstance().saveMap(map);
    showSaveConfirmation();
}
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 5 with Map

use of com.peterlaurence.trekadvisor.core.map.Map in project TrekAdvisor by peterLaurence.

the class MapCalibrationFragment method moveToCalibrationPoint.

private void moveToCalibrationPoint(int calibrationPointNumber, double relativeX, double relativeY) {
    /* 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);
        moveCalibrationMarker(mTileView, mCalibrationMarker, calibrationPoint.x, calibrationPoint.y);
    } else {
        /* No calibration point defined */
        moveCalibrationMarker(mTileView, mCalibrationMarker, relativeX, relativeY);
    }
    mTileView.moveToMarker(mCalibrationMarker, true);
}
Also used : MapGson(com.peterlaurence.trekadvisor.core.map.gson.MapGson) 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