diff --git a/android/res/layout-land/fragment_suggest_country_download.xml b/android/res/layout-land/fragment_suggest_country_download.xml index 1f4359eca9..9564bccb2a 100644 --- a/android/res/layout-land/fragment_suggest_country_download.xml +++ b/android/res/layout-land/fragment_suggest_country_download.xml @@ -127,7 +127,7 @@ android:layout_height="@dimen/progress_wheel_height" android:layout_marginTop="@dimen/margin_half_plus" android:background="?clickableBackground" - wheel:progressColor="@color/base_green" + wheel:wheelColor="@color/base_green" wheel:secondaryColor="@color/downloader_progress_bg" wheel:wheelThickness="@dimen/margin_quarter"/> diff --git a/android/res/layout/download_item_country.xml b/android/res/layout/download_item_country.xml index 19efeb0582..53f2e5615e 100644 --- a/android/res/layout/download_item_country.xml +++ b/android/res/layout/download_item_country.xml @@ -28,7 +28,7 @@ android:layout_marginRight="@dimen/progress_wheel_width_neg" android:paddingLeft="@dimen/margin_quarter" android:paddingRight="@dimen/margin_quarter" - wheel:progressColor="@color/downloader_blue" + wheel:wheelColor="@color/downloader_blue" wheel:secondaryColor="@color/downloader_progress_bg" wheel:wheelThickness="@dimen/margin_eighth"/> @@ -49,7 +49,7 @@ android:layout_centerVertical="true" android:paddingLeft="@dimen/margin_quarter" android:paddingRight="@dimen/margin_quarter" - wheel:progressColor="@color/downloader_blue" + wheel:wheelColor="@color/downloader_blue" wheel:secondaryColor="@color/downloader_progress_bg" wheel:wheelThickness="@dimen/margin_eighth"/> diff --git a/android/res/layout/fragment_suggest_country_download.xml b/android/res/layout/fragment_suggest_country_download.xml index 08120040af..41a545eba3 100644 --- a/android/res/layout/fragment_suggest_country_download.xml +++ b/android/res/layout/fragment_suggest_country_download.xml @@ -132,7 +132,7 @@ android:layout_height="@dimen/progress_wheel_height" android:layout_marginTop="@dimen/margin_half_plus" android:background="?clickableBackground" - wheel:progressColor="@color/base_green" + wheel:wheelColor="@color/base_green" wheel:secondaryColor="@color/downloader_progress_bg" wheel:wheelThickness="@dimen/margin_quarter"/> diff --git a/android/res/values/attrs.xml b/android/res/values/attrs.xml index 0d859512a6..c1fe0cbc7e 100644 --- a/android/res/values/attrs.xml +++ b/android/res/values/attrs.xml @@ -1,7 +1,7 @@ - + @@ -16,6 +16,14 @@ + + + + + + + + false diff --git a/android/src/com/mapswithme/maps/widget/FlatProgressView.java b/android/src/com/mapswithme/maps/widget/FlatProgressView.java new file mode 100644 index 0000000000..a856495954 --- /dev/null +++ b/android/src/com/mapswithme/maps/widget/FlatProgressView.java @@ -0,0 +1,162 @@ +package com.mapswithme.maps.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 com.mapswithme.maps.R; + +public class FlatProgressView extends View +{ + private int mThickness; + private int mHeadRadius; + private int mProgress; + + private final Paint mProgressPaint = 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) + { + TypedArray ta = getContext().obtainStyledAttributes(attrs, R.styleable.FlatProgressView, defStyleAttr, 0); + setThickness(ta.getDimensionPixelSize(R.styleable.FlatProgressView_progressThickness, 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_headColor, Color.BLUE); + mHeadPaint.setColor(color); + + ta.recycle(); + } + + @Override + protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) + { + super.onMeasure(widthMeasureSpec, heightMeasureSpec); + setMeasuredDimension(getMeasuredWidth(), + Math.max(mThickness, mHeadRadius * 2) + getPaddingTop() + getPaddingBottom()); + } + + @Override + protected void onDraw(Canvas canvas) + { + mReady = true; + canvas.save(); + + int intWidth = getWidth() - getPaddingLeft() - getPaddingRight(); + canvas.translate(getPaddingLeft(), 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 (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(); + } +} diff --git a/android/src/com/mapswithme/maps/widget/WheelProgressView.java b/android/src/com/mapswithme/maps/widget/WheelProgressView.java index 3a30e0f4e0..98e444457a 100644 --- a/android/src/com/mapswithme/maps/widget/WheelProgressView.java +++ b/android/src/com/mapswithme/maps/widget/WheelProgressView.java @@ -53,7 +53,7 @@ public class WheelProgressView extends View { final TypedArray typedArray = getContext().obtainStyledAttributes(attrs, R.styleable.WheelProgressView, 0, 0); mStrokeWidth = typedArray.getDimensionPixelSize(R.styleable.WheelProgressView_wheelThickness, DEFAULT_THICKNESS); - final int color = typedArray.getColor(R.styleable.WheelProgressView_progressColor, getResources().getColor(R.color.downloader_progress_bg)); + final int color = typedArray.getColor(R.styleable.WheelProgressView_wheelColor, getResources().getColor(R.color.downloader_progress_bg)); final int secondaryColor = typedArray.getColor(R.styleable.WheelProgressView_secondaryColor, getResources().getColor(R.color.text_green)); typedArray.recycle();