forked from organicmaps/organicmaps
[android] Added displaying the elevation profile properties from elevation info data structure
This commit is contained in:
parent
4a975dfc45
commit
cb8d26b40f
5 changed files with 154 additions and 39 deletions
|
@ -1,12 +1,17 @@
|
|||
package com.mapswithme.maps.bookmarks.data;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import com.mapswithme.maps.widget.placepage.UserMarkInterface;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class ElevationInfo
|
||||
public class ElevationInfo implements Parcelable, UserMarkInterface
|
||||
{
|
||||
private final long mId;
|
||||
@NonNull
|
||||
|
@ -18,7 +23,7 @@ public class ElevationInfo
|
|||
private final int mMinAltitude;
|
||||
private final int mMaxAltitude;
|
||||
private final int mDifficulty;
|
||||
private final long m_duration;
|
||||
private final long mDuration;
|
||||
|
||||
public ElevationInfo(long trackId, @NonNull String name, @NonNull Point[] points,
|
||||
int ascent, int descent, int minAltitude, int maxAltitude, int difficulty,
|
||||
|
@ -32,7 +37,28 @@ public class ElevationInfo
|
|||
mMinAltitude = minAltitude;
|
||||
mMaxAltitude = maxAltitude;
|
||||
mDifficulty = difficulty;
|
||||
this.m_duration = m_duration;
|
||||
this.mDuration = m_duration;
|
||||
}
|
||||
|
||||
protected ElevationInfo(Parcel in)
|
||||
{
|
||||
mId = in.readLong();
|
||||
mName = in.readString();
|
||||
mAscent = in.readInt();
|
||||
mDescent = in.readInt();
|
||||
mMinAltitude = in.readInt();
|
||||
mMaxAltitude = in.readInt();
|
||||
mDifficulty = in.readInt();
|
||||
mDuration = in.readLong();
|
||||
mPoints = readPoints(in);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
private static List<Point> readPoints(@NonNull Parcel in)
|
||||
{
|
||||
List<Point> points = new ArrayList<>();
|
||||
in.readTypedList(points, Point.CREATOR);
|
||||
return points;
|
||||
}
|
||||
|
||||
public long getId()
|
||||
|
@ -77,12 +103,34 @@ public class ElevationInfo
|
|||
return mDifficulty;
|
||||
}
|
||||
|
||||
public long getM_duration()
|
||||
public long getDuration()
|
||||
{
|
||||
return m_duration;
|
||||
return mDuration;
|
||||
}
|
||||
|
||||
public static class Point
|
||||
@Override
|
||||
public int describeContents()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToParcel(Parcel dest, int flags)
|
||||
{
|
||||
dest.writeLong(mId);
|
||||
dest.writeString(mName);
|
||||
dest.writeInt(mAscent);
|
||||
dest.writeInt(mDescent);
|
||||
dest.writeInt(mMinAltitude);
|
||||
dest.writeInt(mMaxAltitude);
|
||||
dest.writeInt(mDifficulty);
|
||||
dest.writeLong(mDuration);
|
||||
// All collections are deserialized AFTER non-collection and primitive type objects,
|
||||
// so collections must be always serialized at the end.
|
||||
dest.writeList(mPoints);
|
||||
}
|
||||
|
||||
public static class Point implements Parcelable
|
||||
{
|
||||
private final double mDistance;
|
||||
private final int mAltitude;
|
||||
|
@ -93,6 +141,27 @@ public class ElevationInfo
|
|||
mAltitude = altitude;
|
||||
}
|
||||
|
||||
protected Point(Parcel in)
|
||||
{
|
||||
mDistance = in.readDouble();
|
||||
mAltitude = in.readInt();
|
||||
}
|
||||
|
||||
public static final Creator<Point> CREATOR = new Creator<Point>()
|
||||
{
|
||||
@Override
|
||||
public Point createFromParcel(Parcel in)
|
||||
{
|
||||
return new Point(in);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Point[] newArray(int size)
|
||||
{
|
||||
return new Point[size];
|
||||
}
|
||||
};
|
||||
|
||||
public double getDistance()
|
||||
{
|
||||
return mDistance;
|
||||
|
@ -102,5 +171,33 @@ public class ElevationInfo
|
|||
{
|
||||
return mAltitude;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int describeContents()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToParcel(Parcel dest, int flags)
|
||||
{
|
||||
dest.writeDouble(mDistance);
|
||||
dest.writeInt(mAltitude);
|
||||
}
|
||||
}
|
||||
|
||||
public static final Creator<ElevationInfo> CREATOR = new Creator<ElevationInfo>()
|
||||
{
|
||||
@Override
|
||||
public ElevationInfo createFromParcel(Parcel in)
|
||||
{
|
||||
return new ElevationInfo(in);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ElevationInfo[] newArray(int size)
|
||||
{
|
||||
return new ElevationInfo[size];
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
@ -1,17 +1,22 @@
|
|||
package com.mapswithme.maps.widget.placepage;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.res.Resources;
|
||||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import com.mapswithme.maps.R;
|
||||
import com.mapswithme.maps.bookmarks.data.MapObject;
|
||||
import com.mapswithme.maps.bookmarks.data.ElevationInfo;
|
||||
import com.mapswithme.maps.routing.RoutingController;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public class ElevationProfileViewRenderer implements PlacePageViewRenderer<MapObject>
|
||||
public class ElevationProfileViewRenderer implements PlacePageViewRenderer<UserMarkInterface>
|
||||
{
|
||||
private static final String EXTRA_ELEVATION_INFO = "extra_elevation_info";
|
||||
private static final int MAX_DIFFICULTY_LEVEL = 3;
|
||||
|
||||
@SuppressWarnings("NullableProblems")
|
||||
|
@ -34,18 +39,25 @@ public class ElevationProfileViewRenderer implements PlacePageViewRenderer<MapOb
|
|||
private TextView mTime;
|
||||
@NonNull
|
||||
private final View[] mDifficultyLevels = new View[MAX_DIFFICULTY_LEVEL];
|
||||
@Nullable
|
||||
private ElevationInfo mElevationInfo;
|
||||
|
||||
@SuppressLint("SetTextI18n")
|
||||
@Override
|
||||
public void render(@NonNull MapObject object)
|
||||
public void render(@NonNull UserMarkInterface userMark)
|
||||
{
|
||||
mTitle.setText(object.getTitle());
|
||||
// TODO: just for testing.
|
||||
setDifficulty(2);
|
||||
mAscent.setText("980 m");
|
||||
mDescent.setText("1000 m");
|
||||
mMaxAltitude.setText("2243 m");
|
||||
mMinAltitude.setText("20 m");
|
||||
mTime.setText("3 h 45 min");
|
||||
mElevationInfo = (ElevationInfo) userMark;
|
||||
Resources resources = mTitle.getResources();
|
||||
String meters = " " + resources.getString(R.string.elevation_profile_m);
|
||||
mTitle.setText(mElevationInfo.getName());
|
||||
setDifficulty(mElevationInfo.getDifficulty());
|
||||
mAscent.setText(mElevationInfo.getAscent() + meters);
|
||||
mDescent.setText(mElevationInfo.getDescent() + meters);
|
||||
mMaxAltitude.setText(mElevationInfo.getMaxAltitude() + meters);
|
||||
mMinAltitude.setText(mElevationInfo.getMinAltitude() + meters);
|
||||
mTime.setText(RoutingController.formatRoutingTime(mTitle.getContext(),
|
||||
(int) mElevationInfo.getDuration(),
|
||||
R.dimen.text_size_body_2));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -77,4 +89,18 @@ public class ElevationProfileViewRenderer implements PlacePageViewRenderer<MapOb
|
|||
for (int i = 0; i < level; i++)
|
||||
mDifficultyLevels[i].setEnabled(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSave(@NonNull Bundle outState)
|
||||
{
|
||||
outState.putParcelable(EXTRA_ELEVATION_INFO, mElevationInfo);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRestore(@NonNull Bundle inState)
|
||||
{
|
||||
mElevationInfo = inState.getParcelable(EXTRA_ELEVATION_INFO);
|
||||
if (mElevationInfo != null)
|
||||
render(mElevationInfo);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,11 +1,13 @@
|
|||
package com.mapswithme.maps.widget.placepage;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import com.mapswithme.maps.base.Initializable;
|
||||
import com.mapswithme.maps.base.Savable;
|
||||
|
||||
public interface PlacePageViewRenderer<Data> extends Initializable<View>
|
||||
public interface PlacePageViewRenderer<Data> extends Initializable<View>, Savable<Bundle>
|
||||
{
|
||||
void render(@NonNull Data data);
|
||||
}
|
||||
|
|
|
@ -567,9 +567,8 @@ public class RichPlacePageController implements PlacePageController, LocationLis
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean support(@NonNull UserMarkInterface object)
|
||||
public boolean support(@NonNull UserMarkInterface userMark)
|
||||
{
|
||||
// TODO: only for tests.
|
||||
return !((MapObject) object).getTitle().equals("Петровский Путевой Дворец");
|
||||
return userMark instanceof MapObject;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,7 +12,7 @@ import androidx.annotation.Nullable;
|
|||
import androidx.core.view.GestureDetectorCompat;
|
||||
import com.mapswithme.maps.Framework;
|
||||
import com.mapswithme.maps.R;
|
||||
import com.mapswithme.maps.bookmarks.data.MapObject;
|
||||
import com.mapswithme.maps.bookmarks.data.ElevationInfo;
|
||||
import com.mapswithme.util.UiUtils;
|
||||
import com.trafi.anchorbottomsheetbehavior.AnchorBottomSheetBehavior;
|
||||
|
||||
|
@ -33,10 +33,8 @@ public class SimplePlacePageController implements PlacePageController
|
|||
private final SlideListener mSlideListener;
|
||||
private int mViewportMinHeight;
|
||||
private int mViewPortMinWidth;
|
||||
@Nullable
|
||||
private MapObject mMapObject;
|
||||
@NonNull
|
||||
private final PlacePageViewRenderer<MapObject> mViewRenderer;
|
||||
private final PlacePageViewRenderer<UserMarkInterface> mViewRenderer;
|
||||
@NonNull
|
||||
private final BottomSheetChangedListener mBottomSheetChangedListener =
|
||||
new BottomSheetChangedListener()
|
||||
|
@ -95,17 +93,16 @@ public class SimplePlacePageController implements PlacePageController
|
|||
private boolean mDeactivateMapSelection = true;
|
||||
|
||||
SimplePlacePageController(@NonNull SlideListener slideListener,
|
||||
@NonNull PlacePageViewRenderer<MapObject> renderer)
|
||||
@NonNull PlacePageViewRenderer<UserMarkInterface> renderer)
|
||||
{
|
||||
mSlideListener = slideListener;
|
||||
mViewRenderer = renderer;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void openFor(@NonNull UserMarkInterface object)
|
||||
public void openFor(@NonNull UserMarkInterface userMark)
|
||||
{
|
||||
mMapObject = (MapObject) object;
|
||||
mViewRenderer.render(mMapObject);
|
||||
mViewRenderer.render(userMark);
|
||||
if (mSheetBehavior.getSkipCollapsed())
|
||||
mSheetBehavior.setState(AnchorBottomSheetBehavior.STATE_EXPANDED);
|
||||
else
|
||||
|
@ -194,7 +191,7 @@ public class SimplePlacePageController implements PlacePageController
|
|||
@Override
|
||||
public void onSave(@NonNull Bundle outState)
|
||||
{
|
||||
outState.putParcelable(PlacePageUtils.EXTRA_MAP_OBJECT, mMapObject);
|
||||
mViewRenderer.onSave(outState);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -209,12 +206,7 @@ public class SimplePlacePageController implements PlacePageController
|
|||
return;
|
||||
}
|
||||
|
||||
MapObject object = inState.getParcelable(PlacePageUtils.EXTRA_MAP_OBJECT);
|
||||
if (object == null)
|
||||
return;
|
||||
|
||||
mMapObject = object;
|
||||
mViewRenderer.render(object);
|
||||
mViewRenderer.onRestore(inState);
|
||||
if (UiUtils.isLandscape(mApplication))
|
||||
{
|
||||
// In case when bottom sheet was collapsed for vertical orientation then after rotation
|
||||
|
@ -246,8 +238,7 @@ public class SimplePlacePageController implements PlacePageController
|
|||
@Override
|
||||
public boolean support(@NonNull UserMarkInterface object)
|
||||
{
|
||||
// TODO: only for tests.
|
||||
return ((MapObject) object).getTitle().equals("Петровский Путевой Дворец");
|
||||
return object instanceof ElevationInfo;
|
||||
}
|
||||
|
||||
private static class SimplePlacePageGestureListener extends PlacePageGestureListener
|
||||
|
|
Loading…
Add table
Reference in a new issue