forked from organicmaps/organicmaps
Migrate FlatProgressView to LinearProgressIndicator
Signed-off-by: Jean-BaptisteC <jeanbaptiste.charron@outlook.fr>
This commit is contained in:
parent
a4d62e6022
commit
76fbc30a2c
6 changed files with 15 additions and 227 deletions
|
@ -132,7 +132,7 @@ public class DownloadResourcesLegacyActivity extends BaseMwmFragmentActivity
|
|||
public void onProgress(final int percent)
|
||||
{
|
||||
if (!isFinishing())
|
||||
mProgress.setProgress(percent);
|
||||
mProgress.setProgressCompat(percent, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -179,7 +179,7 @@ public class DownloadResourcesLegacyActivity extends BaseMwmFragmentActivity
|
|||
@Override
|
||||
public void onProgress(String countryId, long localSize, long remoteSize)
|
||||
{
|
||||
mProgress.setProgress((int)localSize);
|
||||
mProgress.setProgressCompat((int) localSize, true);
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -264,7 +264,7 @@ public class DownloadResourcesLegacyActivity extends BaseMwmFragmentActivity
|
|||
setDownloadMessage(bytes);
|
||||
|
||||
mProgress.setMax(bytes);
|
||||
mProgress.setProgress(0);
|
||||
mProgress.setProgressCompat(0, true);
|
||||
}
|
||||
else
|
||||
finishFilesDownload(bytes);
|
||||
|
@ -380,7 +380,7 @@ public class DownloadResourcesLegacyActivity extends BaseMwmFragmentActivity
|
|||
UiUtils.hide(mChbDownloadCountry);
|
||||
mTvMessage.setText(getString(R.string.downloading_country_can_proceed, item.name));
|
||||
mProgress.setMax((int)item.totalSize);
|
||||
mProgress.setProgress(0);
|
||||
mProgress.setProgressCompat(0, true);
|
||||
|
||||
mCountryDownloadListenerSlot = MapManager.nativeSubscribe(mCountryDownloadListener);
|
||||
MapManager.nativeDownload(mCurrentCountry);
|
||||
|
|
|
@ -1,202 +0,0 @@
|
|||
package app.organicmaps.widget;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.TypedArray;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.Paint;
|
||||
import android.graphics.RectF;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.View;
|
||||
|
||||
import app.organicmaps.R;
|
||||
|
||||
public class FlatProgressView extends View
|
||||
{
|
||||
private int mThickness;
|
||||
private int mSecondaryThickness;
|
||||
private int mHeadRadius;
|
||||
private int mProgress;
|
||||
|
||||
private final Paint mProgressPaint = new Paint();
|
||||
private final Paint mSecondaryProgressPaint = new Paint();
|
||||
private final Paint mHeadPaint = new Paint();
|
||||
private final RectF mHeadRect = new RectF();
|
||||
|
||||
private boolean mReady;
|
||||
|
||||
|
||||
public FlatProgressView(Context context)
|
||||
{
|
||||
super(context);
|
||||
init(null, 0);
|
||||
}
|
||||
|
||||
public FlatProgressView(Context context, AttributeSet attrs)
|
||||
{
|
||||
super(context, attrs);
|
||||
init(attrs, 0);
|
||||
}
|
||||
|
||||
public FlatProgressView(Context context, AttributeSet attrs, int defStyleAttr)
|
||||
{
|
||||
super(context, attrs, defStyleAttr);
|
||||
init(attrs, defStyleAttr);
|
||||
}
|
||||
|
||||
private void init(AttributeSet attrs, int defStyleAttr)
|
||||
{
|
||||
if (isInEditMode())
|
||||
return;
|
||||
|
||||
TypedArray ta = getContext().obtainStyledAttributes(attrs, R.styleable.FlatProgressView, defStyleAttr, 0);
|
||||
setThickness(ta.getDimensionPixelSize(R.styleable.FlatProgressView_progressThickness, 1));
|
||||
setSecondaryThickness(ta.getDimensionPixelSize(R.styleable.FlatProgressView_secondaryProgressThickness, 1));
|
||||
setHeadRadius(ta.getDimensionPixelSize(R.styleable.FlatProgressView_headRadius, 4));
|
||||
setProgress(ta.getInteger(R.styleable.FlatProgressView_progress, 0));
|
||||
|
||||
int color = ta.getColor(R.styleable.FlatProgressView_progressColor, Color.BLUE);
|
||||
mProgressPaint.setColor(color);
|
||||
color = ta.getColor(R.styleable.FlatProgressView_secondaryProgressColor, Color.GRAY);
|
||||
mSecondaryProgressPaint.setColor(color);
|
||||
color = ta.getColor(R.styleable.FlatProgressView_headColor, Color.BLUE);
|
||||
mHeadPaint.setColor(color);
|
||||
|
||||
ta.recycle();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec)
|
||||
{
|
||||
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
|
||||
setMeasuredDimension(getMeasuredWidth(),
|
||||
Math.max(mSecondaryThickness, Math.max(mThickness, mHeadRadius * 2)) + getPaddingTop() + getPaddingBottom());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDraw(Canvas canvas)
|
||||
{
|
||||
mReady = true;
|
||||
canvas.save();
|
||||
|
||||
int intWidth = getWidth() - getPaddingStart() - getPaddingEnd();
|
||||
int intHeight = getHeight() - getPaddingTop() - getPaddingBottom();
|
||||
canvas.translate(getPaddingStart(), getPaddingTop());
|
||||
|
||||
int progressWidth = (intWidth * mProgress / 100);
|
||||
if (progressWidth > 0)
|
||||
{
|
||||
int top = ((mHeadRadius * 2) > mThickness ? (mHeadRadius - mThickness / 2) : 0);
|
||||
canvas.drawRect(0, top, progressWidth, top + mThickness, mProgressPaint);
|
||||
}
|
||||
|
||||
if (mProgress < 100)
|
||||
{
|
||||
int top = (intHeight - mSecondaryThickness) / 2;
|
||||
canvas.drawRect(progressWidth, top, intWidth, top + mSecondaryThickness, mSecondaryProgressPaint);
|
||||
}
|
||||
|
||||
if (mHeadRadius > 0)
|
||||
{
|
||||
int top = ((mHeadRadius * 2) > mThickness ? 0 : (mThickness / 2 - mHeadRadius));
|
||||
canvas.translate(progressWidth - mHeadRadius, top);
|
||||
canvas.drawOval(mHeadRect, mHeadPaint);
|
||||
}
|
||||
|
||||
canvas.restore();
|
||||
}
|
||||
|
||||
public int getProgress()
|
||||
{
|
||||
return mProgress;
|
||||
}
|
||||
|
||||
public void setProgress(int progress)
|
||||
{
|
||||
if (mProgress == progress)
|
||||
return;
|
||||
|
||||
if (progress < 0 || progress > 100)
|
||||
throw new IllegalArgumentException("Progress must be within interval [0..100]");
|
||||
|
||||
mProgress = progress;
|
||||
if (mReady)
|
||||
invalidate();
|
||||
}
|
||||
|
||||
public int getThickness()
|
||||
{
|
||||
return mThickness;
|
||||
}
|
||||
|
||||
public void setThickness(int thickness)
|
||||
{
|
||||
if (thickness == mThickness)
|
||||
return;
|
||||
|
||||
mThickness = thickness;
|
||||
if (mReady)
|
||||
invalidate();
|
||||
}
|
||||
|
||||
public int getHeadRadius()
|
||||
{
|
||||
return mHeadRadius;
|
||||
}
|
||||
|
||||
public void setHeadRadius(int headRadius)
|
||||
{
|
||||
if (headRadius == mHeadRadius)
|
||||
return;
|
||||
|
||||
mHeadRadius = headRadius;
|
||||
mHeadRect.set(0.0f, 0.0f, mHeadRadius * 2, mHeadRadius * 2);
|
||||
if (mReady)
|
||||
invalidate();
|
||||
}
|
||||
|
||||
public void setProgressColor(int color)
|
||||
{
|
||||
if (color == mProgressPaint.getColor())
|
||||
return;
|
||||
|
||||
mProgressPaint.setColor(color);
|
||||
if (mReady)
|
||||
invalidate();
|
||||
}
|
||||
|
||||
public void setHeadColor(int color)
|
||||
{
|
||||
if (color == mHeadPaint.getColor())
|
||||
return;
|
||||
|
||||
mHeadPaint.setColor(color);
|
||||
if (mReady)
|
||||
invalidate();
|
||||
}
|
||||
|
||||
public void setSecondaryProgressColor(int color)
|
||||
{
|
||||
if (color == mSecondaryProgressPaint.getColor())
|
||||
return;
|
||||
|
||||
mSecondaryProgressPaint.setColor(color);
|
||||
if (mReady)
|
||||
invalidate();
|
||||
}
|
||||
|
||||
public void setSecondaryThickness(int secondaryThickness)
|
||||
{
|
||||
if (secondaryThickness == mSecondaryThickness)
|
||||
return;
|
||||
|
||||
mSecondaryThickness = secondaryThickness;
|
||||
if (mReady)
|
||||
invalidate();
|
||||
}
|
||||
|
||||
public int getSecondaryThickness()
|
||||
{
|
||||
return mSecondaryThickness;
|
||||
}
|
||||
}
|
|
@ -14,10 +14,10 @@ import app.organicmaps.R;
|
|||
import app.organicmaps.location.LocationHelper;
|
||||
import app.organicmaps.routing.RoutingInfo;
|
||||
import app.organicmaps.sound.TtsPlayer;
|
||||
import app.organicmaps.widget.FlatProgressView;
|
||||
import app.organicmaps.util.Graphics;
|
||||
import app.organicmaps.util.StringUtils;
|
||||
import app.organicmaps.util.UiUtils;
|
||||
import com.google.android.material.progressindicator.LinearProgressIndicator;
|
||||
|
||||
import java.text.DateFormat;
|
||||
import java.text.SimpleDateFormat;
|
||||
|
@ -42,7 +42,7 @@ public class NavMenu
|
|||
private final TextView mTimeEstimate;
|
||||
private final TextView mDistanceValue;
|
||||
private final TextView mDistanceUnits;
|
||||
private final FlatProgressView mRouteProgress;
|
||||
private final LinearProgressIndicator mRouteProgress;
|
||||
|
||||
private final AppCompatActivity mActivity;
|
||||
private final NavMenuListener mNavMenuListener;
|
||||
|
@ -229,7 +229,7 @@ public class NavMenu
|
|||
updateTime(info.totalTimeInSeconds);
|
||||
mDistanceValue.setText(info.distToTarget.mDistanceStr);
|
||||
mDistanceUnits.setText(info.distToTarget.getUnitsStr(mActivity.getApplicationContext()));
|
||||
mRouteProgress.setProgress((int) info.completionPercent);
|
||||
mRouteProgress.setProgressCompat((int) info.completionPercent, true);
|
||||
}
|
||||
|
||||
public interface NavMenuListener
|
||||
|
|
|
@ -25,7 +25,8 @@
|
|||
android:layout_marginEnd="@dimen/margin_base_plus"
|
||||
android:layout_marginBottom="@dimen/margin_base"
|
||||
android:indeterminate="false"
|
||||
app:indicatorColor="?android:colorAccent"/>
|
||||
app:indicatorColor="?android:colorAccent"
|
||||
app:trackColor="@color/bg_routing_progress"/>
|
||||
<Button
|
||||
android:id="@+id/btn_download_resources"
|
||||
style="@style/MwmWidget.Button.Primary"
|
||||
|
|
|
@ -21,16 +21,15 @@
|
|||
<include layout="@layout/bottom_sheet_handle" />
|
||||
<include layout="@layout/layout_nav_bottom_numbers" />
|
||||
|
||||
<app.organicmaps.widget.FlatProgressView
|
||||
<com.google.android.material.progressindicator.LinearProgressIndicator
|
||||
android:id="@+id/navigation_progress"
|
||||
style="@style/Widget.MaterialComponents.LinearProgressIndicator"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
app:headColor="?colorAccent"
|
||||
app:headRadius="@dimen/nav_progress_head"
|
||||
app:progressColor="?colorAccent"
|
||||
app:progressThickness="@dimen/nav_progress"
|
||||
app:secondaryProgressColor="@color/bg_routing_progress"
|
||||
app:secondaryProgressThickness="@dimen/nav_progress" />
|
||||
app:indicatorColor="?colorAccent"
|
||||
app:trackCornerRadius="@dimen/nav_progress_head"
|
||||
app:trackThickness="@dimen/nav_progress"
|
||||
app:trackColor="@color/bg_routing_progress" />
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
|
|
|
@ -16,16 +16,6 @@
|
|||
<attr name="floating" format="boolean"/>
|
||||
</declare-styleable>
|
||||
|
||||
<declare-styleable name="FlatProgressView">
|
||||
<attr name="progressColor" format="color"/>
|
||||
<attr name="progressThickness" format="dimension"/>
|
||||
<attr name="secondaryProgressColor" format="color"/>
|
||||
<attr name="secondaryProgressThickness" format="dimension"/>
|
||||
<attr name="headColor" format="color"/>
|
||||
<attr name="headRadius" format="dimension"/>
|
||||
<attr name="progress" format="integer"/>
|
||||
</declare-styleable>
|
||||
|
||||
<declare-styleable name="TransitStepView">
|
||||
<attr name="android:textSize"/>
|
||||
<attr name="android:textColor"/>
|
||||
|
|
Loading…
Add table
Reference in a new issue