mirror of
https://github.com/ArcaneChat/android.git
synced 2026-07-03 14:05:24 +02:00
implement bottom sheet and a slider for filtering tracks
This commit is contained in:
Executable
BIN
Binary file not shown.
|
After Width: | Height: | Size: 410 B |
Executable
BIN
Binary file not shown.
|
After Width: | Height: | Size: 522 B |
Executable
BIN
Binary file not shown.
|
After Width: | Height: | Size: 829 B |
Executable
BIN
Binary file not shown.
|
After Width: | Height: | Size: 1.1 KiB |
@@ -1,6 +1,5 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<android.support.v7.widget.LinearLayoutCompat xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
@@ -11,4 +10,6 @@
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"/>
|
||||
|
||||
</android.support.v7.widget.LinearLayoutCompat>
|
||||
<include layout="@layout/bottom_map_sheet" />
|
||||
|
||||
</android.support.design.widget.CoordinatorLayout>
|
||||
|
||||
@@ -0,0 +1,79 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:orientation="vertical"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="150dp"
|
||||
android:id="@+id/bottom_sheet"
|
||||
app:behavior_hideable="false"
|
||||
app:behavior_peekHeight="35dp"
|
||||
app:layout_behavior="android.support.design.widget.BottomSheetBehavior"
|
||||
android:background="@color/transparent"
|
||||
>
|
||||
|
||||
<RelativeLayout
|
||||
android:id="@+id/bottomSheetSlider"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="70dp"
|
||||
android:layout_gravity="end"
|
||||
android:layout_marginRight="15dp"
|
||||
android:layout_marginEnd="15dp"
|
||||
>
|
||||
<ImageView
|
||||
android:layout_width="70dp"
|
||||
android:layout_height="70dp"
|
||||
android:background="@drawable/ic_location_dot"
|
||||
android:layout_centerHorizontal="true"
|
||||
/>
|
||||
|
||||
<ImageView
|
||||
android:layout_width="40dp"
|
||||
android:layout_height="40dp"
|
||||
android:src="@drawable/ic_timeline"
|
||||
android:layout_centerHorizontal="true"
|
||||
/>
|
||||
</RelativeLayout>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="135dp"
|
||||
android:orientation="vertical"
|
||||
android:clickable="true"
|
||||
android:focusable="false"
|
||||
android:background="@android:color/white"
|
||||
android:layout_marginTop="-35dp"
|
||||
>
|
||||
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center"
|
||||
android:text="Show location traces in time frame"
|
||||
android:paddingTop="8dp"
|
||||
android:background="@color/white"
|
||||
android:textColor="@android:color/black" />
|
||||
|
||||
|
||||
|
||||
<org.thoughtcrime.securesms.components.rangeslider.TimeRangeSlider
|
||||
|
||||
android:layout_marginTop="10dp"
|
||||
android:layout_marginBottom="10dp"
|
||||
|
||||
android:paddingStart="32dp"
|
||||
android:paddingEnd="32dp"
|
||||
android:paddingLeft="32dp"
|
||||
android:paddingRight="32dp"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
/>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
|
||||
|
||||
</LinearLayout>
|
||||
@@ -239,4 +239,19 @@
|
||||
<attr name="conversationThumbnail_maxHeight" format="dimension" />
|
||||
</declare-styleable>
|
||||
|
||||
<declare-styleable name="RangeSliderView">
|
||||
<attr name="trackTintColor" format="color|reference"/>
|
||||
<attr name="trackHighlightTintColor" format="color|reference"/>
|
||||
<attr name="trackHeight" format="dimension|reference"/>
|
||||
<attr name="thumbRadius" format="dimension|reference"/>
|
||||
<attr name="thumbOutlineSize" format="dimension|reference"/>
|
||||
<attr name="displayTextFontSize" format="dimension|reference"/>
|
||||
<attr name="minValue" format="integer"/>
|
||||
<attr name="maxValue" format="integer"/>
|
||||
</declare-styleable>
|
||||
|
||||
<declare-styleable name="TimeRangeSlider">
|
||||
<attr name="timeFrame" format="integer"/>
|
||||
</declare-styleable>
|
||||
|
||||
</resources>
|
||||
|
||||
@@ -50,4 +50,8 @@
|
||||
|
||||
<color name="universal_overlay">#44000000</color>
|
||||
|
||||
<color name="trackTintColor">#552090ea</color>
|
||||
<color name="trackHighlightTintColor">#ff2090ea</color>
|
||||
|
||||
|
||||
</resources>
|
||||
|
||||
@@ -53,4 +53,12 @@
|
||||
|
||||
<dimen name="scribble_stroke_size">2dp</dimen>
|
||||
|
||||
<dimen name="slider_trackHeight">6dp</dimen>
|
||||
<dimen name="slider_thumbRadius">14dp</dimen>
|
||||
<dimen name="slider_thumbOutlineSize">4dp</dimen>
|
||||
<dimen name="slider_displayTextFontSize">12sp</dimen>
|
||||
<dimen name="slider_displayTextBasicOffsetY">6dp</dimen>
|
||||
<integer name="slider_minValue">100</integer>
|
||||
<integer name="slider_maxValue">100</integer>
|
||||
|
||||
</resources>
|
||||
|
||||
@@ -0,0 +1,275 @@
|
||||
package org.thoughtcrime.securesms.components.rangeslider;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.Resources;
|
||||
import android.content.res.TypedArray;
|
||||
import android.graphics.Canvas;
|
||||
import android.support.v4.content.ContextCompat;
|
||||
import android.util.AttributeSet;
|
||||
import android.util.Log;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
|
||||
import org.thoughtcrime.securesms.R;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class RangeSliderView extends View {
|
||||
|
||||
private static final String TAG = RangeSliderView.class.getName();
|
||||
private int trackTintColor;
|
||||
private int trackHighlightTintColor;
|
||||
private float trackHeight;
|
||||
private float thumbRadius;
|
||||
private float thumbOutlineSize;
|
||||
private float displayTextFontSize;
|
||||
private float displayTextBasicOffsetY;
|
||||
private int sliderPaddingLeft;
|
||||
private int sliderPaddingRight;
|
||||
|
||||
private ThumbLayer minValueThumb;
|
||||
private TextLayer minValueDisplayLabel;
|
||||
|
||||
private ThumbLayer maxValueThumb;
|
||||
private TextLayer maxValueDisplayLabel;
|
||||
|
||||
private TrackLayer track;
|
||||
|
||||
private ArrayList<Integer> values;
|
||||
|
||||
protected int minValue;
|
||||
protected int maxValue;
|
||||
protected int steps;
|
||||
|
||||
private float beginTrackOffsetX;
|
||||
|
||||
private OnValueChangedListener onValueChangedListener;
|
||||
|
||||
public interface OnValueChangedListener {
|
||||
void onValueChanged(int minValue, int maxValue);
|
||||
String parseMinValueDisplayText(int minValue);
|
||||
String parseMaxValueDisplayText(int maxValue);
|
||||
}
|
||||
|
||||
public RangeSliderView(Context context) {
|
||||
this(context, null);
|
||||
}
|
||||
|
||||
public RangeSliderView(Context context, AttributeSet attrs) {
|
||||
this(context, attrs, 0);
|
||||
}
|
||||
|
||||
public RangeSliderView(Context context, AttributeSet attrs, int defStyleAttr) {
|
||||
super(context, attrs, defStyleAttr);
|
||||
|
||||
int [] attributes = new int [] {android.R.attr.paddingLeft,
|
||||
android.R.attr.paddingStart,
|
||||
android.R.attr.paddingRight,
|
||||
android.R.attr.paddingEnd};
|
||||
|
||||
TypedArray arr = context.obtainStyledAttributes(attrs, attributes);
|
||||
|
||||
sliderPaddingLeft = arr.getDimensionPixelOffset(0,
|
||||
arr.getDimensionPixelOffset(1, -1));
|
||||
sliderPaddingRight = arr.getDimensionPixelOffset(2,
|
||||
arr.getDimensionPixelOffset(3, -1));
|
||||
|
||||
TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.RangeSliderView);
|
||||
trackTintColor = typedArray.getColor(
|
||||
R.styleable.RangeSliderView_trackTintColor,
|
||||
ContextCompat.getColor(context, R.color.trackTintColor)
|
||||
);
|
||||
trackHighlightTintColor = typedArray.getColor(
|
||||
R.styleable.RangeSliderView_trackHighlightTintColor,
|
||||
ContextCompat.getColor(context, R.color.trackHighlightTintColor)
|
||||
);
|
||||
|
||||
Resources resources = context.getResources();
|
||||
trackHeight = typedArray.getDimension(
|
||||
R.styleable.RangeSliderView_trackHeight,
|
||||
resources.getDimension(R.dimen.slider_trackHeight)
|
||||
);
|
||||
thumbRadius = typedArray.getDimension(
|
||||
R.styleable.RangeSliderView_thumbRadius,
|
||||
resources.getDimension(R.dimen.slider_thumbRadius)
|
||||
);
|
||||
thumbOutlineSize = typedArray.getDimension(
|
||||
R.styleable.RangeSliderView_thumbOutlineSize,
|
||||
resources.getDimension(R.dimen.slider_thumbOutlineSize)
|
||||
);
|
||||
displayTextFontSize = typedArray.getDimension(
|
||||
R.styleable.RangeSliderView_displayTextFontSize,
|
||||
resources.getDimension(R.dimen.slider_displayTextFontSize)
|
||||
);
|
||||
displayTextBasicOffsetY = resources.getDimension(R.dimen.slider_displayTextBasicOffsetY);
|
||||
minValue = typedArray.getInt(
|
||||
R.styleable.RangeSliderView_minValue,
|
||||
100
|
||||
);
|
||||
maxValue = typedArray.getInt(
|
||||
R.styleable.RangeSliderView_maxValue,
|
||||
100
|
||||
);
|
||||
|
||||
minValueThumb = new ThumbLayer(thumbRadius, thumbOutlineSize, trackHighlightTintColor, trackTintColor);
|
||||
minValueDisplayLabel = new TextLayer(displayTextFontSize, trackHighlightTintColor);
|
||||
|
||||
maxValueThumb = new ThumbLayer(thumbRadius, thumbOutlineSize, trackHighlightTintColor, trackTintColor);
|
||||
maxValueDisplayLabel = new TextLayer(displayTextFontSize, trackHighlightTintColor);
|
||||
|
||||
track = new TrackLayer(sliderPaddingLeft, sliderPaddingRight, trackHeight, trackTintColor, trackHighlightTintColor);
|
||||
|
||||
values = new ArrayList<>();
|
||||
for (int index = 1; index <= 100; index++) {
|
||||
values.add(index);
|
||||
}
|
||||
}
|
||||
|
||||
public void setOnValueChangedListener(OnValueChangedListener onValueChangedListener) {
|
||||
this.onValueChangedListener = onValueChangedListener;
|
||||
invalidate();
|
||||
}
|
||||
|
||||
public void setRangeValues(ArrayList<Integer> values) {
|
||||
this.values = values;
|
||||
setMinAndMaxValue(this.values.get(0), this.values.get(this.values.size() - 1));
|
||||
}
|
||||
|
||||
public void setMinAndMaxValue(int minValue, int maxValue) {
|
||||
this.minValue = minValue;
|
||||
this.maxValue = maxValue;
|
||||
invalidate();
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDraw(Canvas canvas) {
|
||||
super.onDraw(canvas);
|
||||
|
||||
float offsetY = getHeight() / 2;
|
||||
float minValueOffsetX = getPositionFromIndex(minValue);
|
||||
float maxValueOffsetX = getPositionFromIndex(maxValue);
|
||||
float displayLabelOffsetY = offsetY - thumbRadius - displayTextBasicOffsetY;
|
||||
|
||||
Log.d(TAG, "onDraw minValueOffsetX: " + minValueOffsetX + ", maxValueOffsetX: " + maxValueOffsetX);
|
||||
track.draw(canvas, getWidth(), minValueOffsetX, maxValueOffsetX, offsetY - trackHeight / 2);
|
||||
|
||||
minValueThumb.draw(canvas, minValueOffsetX, offsetY);
|
||||
if (onValueChangedListener != null) {
|
||||
minValueDisplayLabel.draw(
|
||||
canvas,
|
||||
onValueChangedListener.parseMinValueDisplayText(minValue),
|
||||
minValueOffsetX,
|
||||
displayLabelOffsetY
|
||||
);
|
||||
} else {
|
||||
minValueDisplayLabel.draw(canvas, String.valueOf(minValue), minValueOffsetX, displayLabelOffsetY);
|
||||
}
|
||||
|
||||
maxValueThumb.draw(canvas, maxValueOffsetX, offsetY);
|
||||
if (onValueChangedListener != null) {
|
||||
maxValueDisplayLabel.draw(
|
||||
canvas,
|
||||
onValueChangedListener.parseMaxValueDisplayText(maxValue),
|
||||
maxValueOffsetX,
|
||||
displayLabelOffsetY
|
||||
);
|
||||
} else {
|
||||
maxValueDisplayLabel.draw(canvas, String.valueOf(maxValue), maxValueOffsetX, displayLabelOffsetY);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onTouchEvent(MotionEvent event) {
|
||||
if (event.getAction() == MotionEvent.ACTION_CANCEL || event.getAction() == MotionEvent.ACTION_UP) {
|
||||
minValueThumb.isHighlight = false;
|
||||
maxValueThumb.isHighlight = false;
|
||||
invalidate();
|
||||
return true;
|
||||
}
|
||||
|
||||
int offsetX = (int) event.getX();
|
||||
if (offsetX < sliderPaddingLeft || offsetX > getWidth() - sliderPaddingRight) {
|
||||
Log.d(TAG, "ignore touch in padding");
|
||||
return true;
|
||||
}
|
||||
|
||||
float radius = getThumbRadius();
|
||||
switch (event.getAction()) {
|
||||
case MotionEvent.ACTION_DOWN:
|
||||
float minValuePosition = getPositionFromIndex(minValue);
|
||||
Log.d(TAG, "action_down minVal: " + minValue + ", " + minValuePosition );
|
||||
if (offsetX >= minValuePosition - radius && offsetX <= minValuePosition + radius) {
|
||||
minValueThumb.isHighlight = true;
|
||||
} else {
|
||||
float maxValuePosition = getPositionFromIndex(maxValue);
|
||||
if (offsetX >= maxValuePosition - radius && offsetX <= maxValuePosition + radius) {
|
||||
maxValueThumb.isHighlight = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (minValueThumb.isHighlight || maxValueThumb.isHighlight) {
|
||||
beginTrackOffsetX = offsetX;
|
||||
invalidate();
|
||||
} else {
|
||||
beginTrackOffsetX = -1;
|
||||
}
|
||||
break;
|
||||
case MotionEvent.ACTION_MOVE:
|
||||
if (minValue == maxValue && beginTrackOffsetX > -1 && offsetX > beginTrackOffsetX && !maxValueThumb.isHighlight) {
|
||||
minValueThumb.isHighlight = false;
|
||||
maxValueThumb.isHighlight = true;
|
||||
}
|
||||
int count = values.size();
|
||||
int index = getIndexFromPosition(offsetX);
|
||||
Log.d(TAG, "move - index: " + index + ", offsetX: " + offsetX);
|
||||
if (index < 0) {
|
||||
index = 0;
|
||||
} else if (index > count - 1) {
|
||||
index = count - 1;
|
||||
}
|
||||
|
||||
if (minValueThumb.isHighlight) {
|
||||
if (index > values.indexOf(maxValue)) {
|
||||
minValue = maxValue;
|
||||
} else {
|
||||
minValue = values.get(index);
|
||||
}
|
||||
} else if (maxValueThumb.isHighlight) {
|
||||
if (index < values.indexOf(minValue)) {
|
||||
maxValue = minValue;
|
||||
} else {
|
||||
maxValue = values.get(index);
|
||||
}
|
||||
}
|
||||
|
||||
if (minValueThumb.isHighlight || maxValueThumb.isHighlight) {
|
||||
if (onValueChangedListener != null) {
|
||||
onValueChangedListener.onValueChanged(minValue, maxValue);
|
||||
}
|
||||
invalidate();
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
protected int getIndexFromPosition(int offsetX) {
|
||||
int count = values.size();
|
||||
return ((offsetX - sliderPaddingLeft) * count / getSliderWidth());
|
||||
}
|
||||
protected float getPositionFromIndex(int value) {
|
||||
int count = values.size();
|
||||
Log.d(TAG, "value: " + value +", position: " + (getSliderWidth() / count) * value + sliderPaddingLeft);
|
||||
return (getSliderWidth() / count) * value + sliderPaddingLeft;
|
||||
}
|
||||
|
||||
public int getSliderWidth() {
|
||||
return getWidth() - sliderPaddingLeft - sliderPaddingRight;
|
||||
}
|
||||
|
||||
private int getThumbRadius() {
|
||||
return (int) (thumbRadius + thumbOutlineSize / 2);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package org.thoughtcrime.securesms.components.rangeslider;
|
||||
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Paint;
|
||||
|
||||
class TextLayer {
|
||||
|
||||
private Paint paint;
|
||||
|
||||
TextLayer(float fontSize, int color) {
|
||||
paint = new Paint();
|
||||
paint.setAntiAlias(true);
|
||||
paint.setColor(color);
|
||||
paint.setTextSize(fontSize);
|
||||
paint.setTextAlign(Paint.Align.CENTER);
|
||||
}
|
||||
|
||||
void draw(Canvas canvas, String text, float offsetX, float offsetY) {
|
||||
canvas.drawText(text, offsetX, offsetY, paint);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
package org.thoughtcrime.securesms.components.rangeslider;
|
||||
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.Paint;
|
||||
|
||||
class ThumbLayer {
|
||||
|
||||
private float radius;
|
||||
private float outlineSize;
|
||||
|
||||
private int highlightColor;
|
||||
|
||||
private Paint outlinePaint;
|
||||
private Paint fillPaint;
|
||||
|
||||
boolean isHighlight = false;
|
||||
|
||||
ThumbLayer(float radius, float outlineSize, int outlineColor, int highlightColor) {
|
||||
this.radius = radius;
|
||||
this.outlineSize = outlineSize;
|
||||
this.highlightColor = highlightColor;
|
||||
|
||||
outlinePaint = new Paint();
|
||||
outlinePaint.setAntiAlias(true);
|
||||
outlinePaint.setColor(outlineColor);
|
||||
outlinePaint.setStyle(Paint.Style.STROKE);
|
||||
outlinePaint.setStrokeWidth(outlineSize);
|
||||
|
||||
fillPaint = new Paint();
|
||||
fillPaint.setAntiAlias(true);
|
||||
fillPaint.setStyle(Paint.Style.FILL);
|
||||
fillPaint.setStrokeWidth(0);
|
||||
}
|
||||
|
||||
void draw(Canvas canvas, float cx, float cy) {
|
||||
canvas.drawCircle(cx, cy, radius, outlinePaint);
|
||||
|
||||
if (isHighlight) {
|
||||
fillPaint.setColor(highlightColor);
|
||||
} else {
|
||||
fillPaint.setColor(Color.WHITE);
|
||||
}
|
||||
canvas.drawCircle(cx, cy, radius - outlineSize / 2, fillPaint);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
package org.thoughtcrime.securesms.components.rangeslider;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.TypedArray;
|
||||
import android.util.AttributeSet;
|
||||
|
||||
import org.thoughtcrime.securesms.R;
|
||||
import org.thoughtcrime.securesms.util.DateUtils;
|
||||
import org.thoughtcrime.securesms.util.DynamicLanguage;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
/**
|
||||
* Created by cyberta on 24.03.19.
|
||||
*/
|
||||
|
||||
public class TimeRangeSlider extends RangeSliderView implements RangeSliderView.OnValueChangedListener {
|
||||
// timeframe in seconds
|
||||
private static final int DEFAULT_TIMEFRAME_2D = 60 * 60 * 24 * 2;
|
||||
private static final int DEFAULT_STEPS = 60 * 10;
|
||||
int timeFrame;
|
||||
Locale locale;
|
||||
OnTimestampChangedListener listener;
|
||||
|
||||
|
||||
public TimeRangeSlider(Context context) {
|
||||
this(context, null, 0);
|
||||
}
|
||||
|
||||
public TimeRangeSlider(Context context, AttributeSet attrs) {
|
||||
this(context, attrs, 0);
|
||||
}
|
||||
|
||||
public TimeRangeSlider(Context context, AttributeSet attrs, int defStyleAttr) {
|
||||
super(context, attrs, defStyleAttr);
|
||||
|
||||
TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.RangeSliderView);
|
||||
timeFrame = typedArray.getInt(
|
||||
R.styleable.TimeRangeSlider_timeFrame,
|
||||
DEFAULT_TIMEFRAME_2D
|
||||
);
|
||||
|
||||
locale = DynamicLanguage.getSelectedLocale(context);
|
||||
super.setOnValueChangedListener(this);
|
||||
}
|
||||
|
||||
public interface OnTimestampChangedListener {
|
||||
void onValueChanged(long startTimestamp, long stopTimestamp);
|
||||
}
|
||||
|
||||
|
||||
public void setOnTimestampChangedListener(OnTimestampChangedListener timestampChangedListener) {
|
||||
listener = timestampChangedListener;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onValueChanged(int minValue, int maxValue) {
|
||||
if (listener != null) {
|
||||
listener.onValueChanged(getTimestampForValue(minValue), getTimestampForValue(maxValue));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String parseMinValueDisplayText(int minValue) {
|
||||
return getStringForValue(minValue);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String parseMaxValueDisplayText(int maxValue) {
|
||||
return getStringForValue(maxValue);
|
||||
}
|
||||
|
||||
|
||||
private String getStringForValue(int value) {
|
||||
return DateUtils.getExtendedRelativeTimeSpanString(this.getContext(), locale, getTimestampForValue(value));
|
||||
}
|
||||
|
||||
private long getTimestampForValue(int value) {
|
||||
return System.currentTimeMillis() - ((timeFrame / 100) * (100 - value) * 1000);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
package org.thoughtcrime.securesms.components.rangeslider;
|
||||
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Paint;
|
||||
import android.graphics.RectF;
|
||||
|
||||
class TrackLayer {
|
||||
|
||||
private float height;
|
||||
private float radius;
|
||||
private int paddingLeft = 0;
|
||||
private int paddingRight = 0;
|
||||
|
||||
private Paint centerPaint;
|
||||
private Paint backgoundPaint;
|
||||
|
||||
TrackLayer(int paddingLeft, int paddingRight, float height, int color, int highlightColor) {
|
||||
this.height = height;
|
||||
radius = this.height / 2;
|
||||
|
||||
centerPaint = new Paint();
|
||||
centerPaint.setAntiAlias(true);
|
||||
centerPaint.setColor(highlightColor);
|
||||
centerPaint.setStyle(Paint.Style.FILL);
|
||||
|
||||
backgoundPaint = new Paint();
|
||||
backgoundPaint.setAntiAlias(true);
|
||||
backgoundPaint.setColor(color);
|
||||
backgoundPaint.setStyle(Paint.Style.FILL);
|
||||
|
||||
this.paddingLeft = paddingLeft;
|
||||
this.paddingRight = paddingRight;
|
||||
}
|
||||
|
||||
void draw(Canvas canvas, int width, float offsetLeft, float offsetRight, float offsetY) {
|
||||
draw(canvas, backgoundPaint, paddingLeft, width - paddingRight, offsetY);
|
||||
draw(canvas, centerPaint, offsetLeft, offsetRight, offsetY);
|
||||
}
|
||||
|
||||
void draw(Canvas canvas, Paint paint, float startX, float endX, float offsetY) {
|
||||
canvas.drawRoundRect(
|
||||
new RectF(startX, offsetY, endX, offsetY + height),
|
||||
radius,
|
||||
radius,
|
||||
paint
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user