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));
}
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;
});
}
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);
}
}
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();
}
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);
}
Aggregations