[android] Fixed floating marker view inflation to get the system elevation attribute work

This commit is contained in:
Александр Зацепин 2020-04-03 01:01:55 +03:00 committed by Vladimir Byko-Ianko
parent 8091817031
commit 5fe947f2eb
4 changed files with 126 additions and 60 deletions

View file

@ -9,6 +9,11 @@
android:id="@+id/elevation_profile_chart"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<com.mapswithme.maps.widget.placepage.FloatingMarkerView
android:id="@+id/floating_marker"
android:visibility="gone"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<TextView
android:id="@+id/highest_altitude"
android:layout_width="wrap_content"

View file

@ -16,73 +16,70 @@
android:id="@+id/info_floating_container"
android:layout_width="wrap_content"
android:layout_height="@dimen/elevation_profile_height"
android:elevation="@dimen/margin_eighth"
android:layout_marginStart="@dimen/margin_eighth"
android:layout_marginEnd="@dimen/margin_eighth"
android:layout_toEndOf="@id/image"
android:clipChildren="false"
tools:ignore="UnusedAttribute">
<ImageView
android:id="@+id/floating_triangle"
android:layout_width="@dimen/margin_half"
android:layout_height="@dimen/margin_base"
android:elevation="@dimen/margin_eighth"
android:layout_centerVertical="true"
android:src="?elevationProfileFloatingTriangle"/>
android:src="?elevationProfileFloatingTriangle" />
<RelativeLayout
android:id="@+id/floating_text_container"
android:layout_width="wrap_content"
android:layout_height="@dimen/elevation_profile_half_height"
android:layout_alignParentBottom="true"
android:layout_centerVertical="true"
android:layout_marginTop="@dimen/margin_half"
android:layout_marginBottom="@dimen/margin_half"
android:layout_toEndOf="@id/floating_triangle">
<RelativeLayout
android:id="@+id/sliding_container"
android:layout_toEndOf="@id/floating_triangle"
android:background="?elevationProfileSelectedPointBg"
android:elevation="@dimen/margin_eighth"
android:maxWidth="@dimen/dialog_min_height"
android:padding="@dimen/margin_quarter_plus"
tools:ignore="UnusedAttribute">
<TextView
android:id="@+id/distance_text"
android:layout_width="wrap_content"
android:layout_height="@dimen/elevation_profile_half_height"
android:layout_centerVertical="true"
android:background="?elevationProfileSelectedPointBg"
android:layout_height="wrap_content"
android:ellipsize="end"
android:maxWidth="@dimen/dialog_min_height"
android:padding="@dimen/margin_quarter_plus"
tools:ignore="UnusedAttribute">
android:singleLine="true"
android:textSize="@dimen/margin_half_plus_eight" />
<TextView
android:id="@+id/distance_value"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/distance_text"
android:ellipsize="end"
android:maxWidth="@dimen/dialog_min_height"
android:singleLine="true"
android:textSize="@dimen/margin_half_plus_eight" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/distance_value"
android:layout_marginTop="@dimen/margin_quarter_plus"
android:gravity="center_vertical"
android:orientation="horizontal">
<ImageView
android:id="@+id/triangle"
android:layout_width="@dimen/margin_half_plus"
android:layout_height="@dimen/margin_half_plus"
android:src="?elevationProfileSelectedPointTriangle" />
<TextView
android:id="@+id/distance_text"
android:id="@+id/altitude"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="@dimen/margin_half_plus_eight"
android:singleLine="true"
android:layout_marginStart="@dimen/margin_quarter"
android:ellipsize="end"
android:maxWidth="@dimen/dialog_min_height" />
<TextView
android:id="@+id/distance_value"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/distance_text"
android:textSize="@dimen/margin_half_plus_eight"
android:singleLine="true"
android:ellipsize="end"
android:maxWidth="@dimen/dialog_min_height" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/distance_value"
android:layout_marginTop="@dimen/margin_quarter_plus"
android:gravity="center_vertical"
android:orientation="horizontal">
<ImageView
android:id="@+id/triangle"
android:layout_width="@dimen/margin_half_plus"
android:layout_height="@dimen/margin_half_plus"
android:src="?elevationProfileSelectedPointTriangle" />
<TextView
android:id="@+id/altitude"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/margin_quarter"
android:textSize="@dimen/margin_half_plus_eight"
android:singleLine="true"
android:ellipsize="end" />
</LinearLayout>
</RelativeLayout>
android:textSize="@dimen/margin_half_plus_eight" />
</LinearLayout>
</RelativeLayout>
</RelativeLayout>
</RelativeLayout>

View file

@ -82,7 +82,7 @@ public class ChartController implements OnChartValueSelectedListener, Initializa
final Resources resources = mContext.getResources();
mChart = view.findViewById(R.id.elevation_profile_chart);
mFloatingMarkerView = new FloatingMarkerView(mContext);
mFloatingMarkerView = view.findViewById(R.id.floating_marker);
mCurrentLocationMarkerView = new CurrentLocationMarkerView(mContext);
mFloatingMarkerView.setChartView(mChart);
mCurrentLocationMarkerView.setChartView(mChart);

View file

@ -3,12 +3,19 @@ package com.mapswithme.maps.widget.placepage;
import android.annotation.SuppressLint;
import android.content.Context;
import android.graphics.Canvas;
import android.os.Build;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.RelativeLayout;
import android.widget.TextView;
import androidx.annotation.NonNull;
import com.github.mikephil.charting.components.MarkerView;
import androidx.annotation.Nullable;
import androidx.annotation.RequiresApi;
import com.github.mikephil.charting.charts.Chart;
import com.github.mikephil.charting.components.IMarker;
import com.github.mikephil.charting.data.Entry;
import com.github.mikephil.charting.highlight.Highlight;
import com.github.mikephil.charting.utils.MPPointF;
@ -17,36 +24,77 @@ import com.mapswithme.maps.R;
import com.mapswithme.util.StringUtils;
@SuppressLint("ViewConstructor")
public class FloatingMarkerView extends MarkerView
public class FloatingMarkerView extends RelativeLayout implements IMarker
{
@Nullable
private Chart mChart;
private static final int TRIANGLE_ROTATION_ANGLE = 180;
@SuppressWarnings("NullableProblems")
@NonNull
private final View mImage;
private View mImage;
@SuppressWarnings("NullableProblems")
@NonNull
private final View mInfoFloatingContainer;
private View mInfoFloatingContainer;
@SuppressWarnings("NullableProblems")
@NonNull
private final View mSlidingContainer;
private TextView mAltitudeView;
@SuppressWarnings("NullableProblems")
@NonNull
private final TextView mAltitudeView;
private TextView mDistanceTextView;
@SuppressWarnings("NullableProblems")
@NonNull
private final TextView mDistanceTextView;
private TextView mDistanceValueView;
@SuppressWarnings("NullableProblems")
@NonNull
private final TextView mDistanceValueView;
private View mFloatingTriangle;
@SuppressWarnings("NullableProblems")
@NonNull
private final View mFloatingTriangle;
@NonNull
private final View mTextContentContainer;
private View mTextContentContainer;
private float mOffset;
public FloatingMarkerView(@NonNull Context context)
{
super(context, R.layout.floating_marker_view);
super(context);
LayoutInflater.from(getContext()).inflate(R.layout.floating_marker_view, this, true);
}
public FloatingMarkerView(Context context, AttributeSet attrs)
{
super(context, attrs);
LayoutInflater.from(getContext()).inflate(R.layout.floating_marker_view, this, true);
}
public FloatingMarkerView(Context context, AttributeSet attrs, int defStyleAttr)
{
super(context, attrs, defStyleAttr);
LayoutInflater.from(getContext()).inflate(R.layout.floating_marker_view, this, true);
}
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
public FloatingMarkerView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes)
{
super(context, attrs, defStyleAttr, defStyleRes);
LayoutInflater.from(getContext()).inflate(R.layout.floating_marker_view, this, true);
}
public void setChartView(@NonNull Chart chart) {
mChart = chart;
}
@Nullable
public Chart getChartView() {
return mChart;
}
@Override
protected void onFinishInflate()
{
super.onFinishInflate();
mInfoFloatingContainer = findViewById(R.id.info_floating_container);
mTextContentContainer = findViewById(R.id.floating_text_container);
mFloatingTriangle = findViewById(R.id.floating_triangle);
mImage = findViewById(R.id.image);
mSlidingContainer = findViewById(R.id.sliding_container);
mDistanceTextView = findViewById(R.id.distance_text);
mAltitudeView = findViewById(R.id.altitude);
mDistanceValueView = findViewById(R.id.distance_value);
@ -59,7 +107,9 @@ public class FloatingMarkerView extends MarkerView
{
updatePointValues(e);
super.refreshContent(e, highlight);
measure(MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED),
MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
layout(0, 0, getMeasuredWidth(), getMeasuredHeight());
}
@Override
@ -102,7 +152,7 @@ public class FloatingMarkerView extends MarkerView
float height = getChartView().getContentRect().height();
float delta = getChartView().getYMax() - getChartView().getYMin();
float factor = delta / height;
return factor * mSlidingContainer.getHeight();
return factor * mTextContentContainer.getHeight();
}
private void updateVertical(@NonNull Entry entry)
@ -129,6 +179,7 @@ public class FloatingMarkerView extends MarkerView
layoutParams.removeRule(ALIGN_PARENT_TOP);
layoutParams.removeRule(ALIGN_PARENT_BOTTOM);
}
mTextContentContainer.setLayoutParams(layoutParams);
}
@ -171,4 +222,17 @@ public class FloatingMarkerView extends MarkerView
mFloatingTriangle.setLayoutParams(triangleParams);
mTextContentContainer.setLayoutParams(textContentParams);
}
@Override
public void draw(Canvas canvas, float posX, float posY)
{
MPPointF offset = getOffsetForDrawingAtPoint(posX, posY);
int saveId = canvas.save();
// translate to the correct position and draw
canvas.translate(posX + offset.x, posY + offset.y);
draw(canvas);
canvas.restoreToCount(saveId);
}
}