mirror of
https://github.com/ArcaneChat/android.git
synced 2026-07-03 14:05:24 +02:00
remove unused relicts from Mapbox -> Leaflet move
This commit is contained in:
@@ -1018,12 +1018,6 @@ JNIEXPORT jboolean Java_com_b44t_messenger_DcContext_setLocation(JNIEnv *env, jo
|
||||
}
|
||||
|
||||
|
||||
JNIEXPORT jlong Java_com_b44t_messenger_DcContext_getLocationsCPtr(JNIEnv *env, jobject obj, jint chat_id, jint contact_id, jlong timestamp_start, jlong timestamp_end)
|
||||
{
|
||||
return (jlong)dc_get_locations(get_dc_context(env, obj), chat_id, contact_id, CTIMESTAMP(timestamp_start), CTIMESTAMP(timestamp_end));
|
||||
}
|
||||
|
||||
|
||||
JNIEXPORT void Java_com_b44t_messenger_DcContext_deleteAllLocations(JNIEnv *env, jobject obj)
|
||||
{
|
||||
dc_delete_all_locations(get_dc_context(env, obj));
|
||||
@@ -1128,91 +1122,6 @@ JNIEXPORT jint Java_com_b44t_messenger_DcEvent_getAccountId(JNIEnv *env, jobject
|
||||
}
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
* DcArray
|
||||
******************************************************************************/
|
||||
|
||||
|
||||
static dc_array_t* get_dc_array(JNIEnv *env, jobject obj)
|
||||
{
|
||||
static jfieldID fid = 0;
|
||||
if (fid==0) {
|
||||
jclass cls = (*env)->GetObjectClass(env, obj);
|
||||
fid = (*env)->GetFieldID(env, cls, "arrayCPtr", "J" /*Signature, J=long*/);
|
||||
}
|
||||
if (fid) {
|
||||
return (dc_array_t*)(*env)->GetLongField(env, obj, fid);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
JNIEXPORT void Java_com_b44t_messenger_DcArray_unrefArrayCPtr(JNIEnv *env, jobject obj)
|
||||
{
|
||||
dc_array_unref(get_dc_array(env, obj));
|
||||
}
|
||||
|
||||
|
||||
JNIEXPORT jint Java_com_b44t_messenger_DcArray_getCnt(JNIEnv *env, jobject obj)
|
||||
{
|
||||
return dc_array_get_cnt(get_dc_array(env, obj));
|
||||
}
|
||||
|
||||
|
||||
JNIEXPORT jfloat Java_com_b44t_messenger_DcArray_getLatitude(JNIEnv *env, jobject obj, jint index)
|
||||
{
|
||||
return (jfloat)dc_array_get_latitude(get_dc_array(env, obj), index);
|
||||
}
|
||||
|
||||
|
||||
JNIEXPORT jfloat Java_com_b44t_messenger_DcArray_getLongitude(JNIEnv *env, jobject obj, jint index)
|
||||
{
|
||||
return (jfloat)dc_array_get_longitude(get_dc_array(env, obj), index);
|
||||
}
|
||||
|
||||
|
||||
JNIEXPORT jfloat Java_com_b44t_messenger_DcArray_getAccuracy(JNIEnv *env, jobject obj, jint index)
|
||||
{
|
||||
return (jfloat)dc_array_get_accuracy(get_dc_array(env, obj), index);
|
||||
}
|
||||
|
||||
|
||||
JNIEXPORT jlong Java_com_b44t_messenger_DcArray_getTimestamp(JNIEnv *env, jobject obj, jint index)
|
||||
{
|
||||
return JTIMESTAMP(dc_array_get_timestamp(get_dc_array(env, obj), index));
|
||||
}
|
||||
|
||||
|
||||
JNIEXPORT jint Java_com_b44t_messenger_DcArray_getMsgId(JNIEnv *env, jobject obj, jint index)
|
||||
{
|
||||
return dc_array_get_msg_id(get_dc_array(env, obj), index);
|
||||
}
|
||||
|
||||
|
||||
JNIEXPORT jint Java_com_b44t_messenger_DcArray_getLocationId(JNIEnv *env, jobject obj, jint index)
|
||||
{
|
||||
return dc_array_get_id(get_dc_array(env, obj), index);
|
||||
}
|
||||
|
||||
|
||||
JNIEXPORT jstring Java_com_b44t_messenger_DcArray_getMarker(JNIEnv *env, jobject obj, jint index)
|
||||
{
|
||||
char* temp = dc_array_get_marker(get_dc_array(env, obj), index);
|
||||
jstring ret = NULL;
|
||||
if (temp) {
|
||||
ret = JSTRING_NEW(temp);
|
||||
}
|
||||
dc_str_unref(temp);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
JNIEXPORT jboolean Java_com_b44t_messenger_DcArray_isIndependent(JNIEnv *env, jobject obj, jint index)
|
||||
{
|
||||
return (dc_array_is_independent(get_dc_array(env, obj), index)!=0);
|
||||
}
|
||||
|
||||
|
||||
/*******************************************************************************
|
||||
* DcChatlist
|
||||
******************************************************************************/
|
||||
|
||||
@@ -223,23 +223,6 @@
|
||||
<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"/>
|
||||
<attr name="paddingLeft" format="dimension|reference"/>
|
||||
<attr name="paddingRight" format="dimension|reference"/>
|
||||
</declare-styleable>
|
||||
|
||||
<declare-styleable name="TimeRangeSlider">
|
||||
<attr name="timeFrame" format="integer"/>
|
||||
</declare-styleable>
|
||||
|
||||
<declare-styleable name="QuoteView">
|
||||
<attr name="message_type" format="enum">
|
||||
<enum name="preview" value="0" />
|
||||
|
||||
@@ -1,28 +0,0 @@
|
||||
package com.b44t.messenger;
|
||||
|
||||
public class DcArray {
|
||||
|
||||
public DcArray(long arrayCPtr) {
|
||||
this.arrayCPtr = arrayCPtr;
|
||||
}
|
||||
|
||||
@Override protected void finalize() throws Throwable {
|
||||
super.finalize();
|
||||
unrefArrayCPtr();
|
||||
arrayCPtr = 0;
|
||||
}
|
||||
|
||||
public native int getCnt ();
|
||||
public native float getLatitude (int index);
|
||||
public native float getLongitude (int index);
|
||||
public native float getAccuracy (int index);
|
||||
public native long getTimestamp (int index);
|
||||
public native int getMsgId (int index);
|
||||
public native int getLocationId(int index);
|
||||
public native String getMarker (int index);
|
||||
public native boolean isIndependent(int index);
|
||||
|
||||
// working with raw c-data
|
||||
private long arrayCPtr; // CAVE: the name is referenced in the JNI
|
||||
private native void unrefArrayCPtr();
|
||||
}
|
||||
@@ -212,7 +212,6 @@ public class DcContext {
|
||||
public native int joinSecurejoin (String qr);
|
||||
public native void sendLocationsToChat (int chat_id, int seconds);
|
||||
public native boolean isSendingLocationsToChat(int chat_id);
|
||||
public DcArray getLocations (int chat_id, int contact_id, long timestamp_start, long timestamp_end) { return new DcArray(getLocationsCPtr(chat_id, contact_id, timestamp_start, timestamp_end)); }
|
||||
public native void deleteAllLocations ();
|
||||
public DcProvider getProviderFromEmailWithDns (String email) { long cptr = getProviderFromEmailWithDnsCPtr(email); return cptr!=0 ? new DcProvider(cptr) : null; }
|
||||
|
||||
@@ -250,7 +249,6 @@ public class DcContext {
|
||||
private native long getMsgCPtr (int id);
|
||||
private native long getDraftCPtr (int id);
|
||||
private native long getContactCPtr (int id);
|
||||
private native long getLocationsCPtr (int chat_id, int contact_id, long timestamp_start, long timestamp_end);
|
||||
private native long checkQrCPtr (String qr);
|
||||
private native long getProviderFromEmailWithDnsCPtr (String addr);
|
||||
private native long newBackupProviderCPtr();
|
||||
|
||||
@@ -1,327 +0,0 @@
|
||||
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 androidx.core.content.ContextCompat;
|
||||
|
||||
import android.util.AttributeSet;
|
||||
import android.util.Log;
|
||||
import android.view.GestureDetector;
|
||||
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();
|
||||
|
||||
protected final int trackTintColor;
|
||||
protected final int trackHighlightTintColor;
|
||||
protected final float trackHeight;
|
||||
protected final float thumbInnerRadius;
|
||||
protected final float thumbOutlineSize;
|
||||
protected final float displayTextFontSize;
|
||||
protected final float displayTextBasicOffsetY;
|
||||
protected final int sliderPaddingLeft;
|
||||
protected final int sliderPaddingRight;
|
||||
|
||||
private final ThumbLayer minValueThumb;
|
||||
private final TextLayer minValueDisplayLabel;
|
||||
|
||||
private final ThumbLayer maxValueThumb;
|
||||
private final TextLayer maxValueDisplayLabel;
|
||||
|
||||
private final TrackLayer track;
|
||||
|
||||
private ArrayList<Integer> values;
|
||||
|
||||
protected int minValue;
|
||||
protected int maxValue;
|
||||
protected float deltaValue;
|
||||
|
||||
protected float offsetY;
|
||||
protected float maxValueDisplayLabelOffsetY;
|
||||
protected float minValueDisplayLabelOffsetY;
|
||||
protected float trackOffsetY;
|
||||
protected float thumbRadius;
|
||||
protected float sliderWidth;
|
||||
|
||||
private float beginTrackOffsetX;
|
||||
private boolean isThumbViewLocked;
|
||||
|
||||
private OnValueChangedListener onValueChangedListener;
|
||||
final GestureDetector longPressDetector;
|
||||
|
||||
|
||||
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);
|
||||
|
||||
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)
|
||||
);
|
||||
thumbInnerRadius = 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
|
||||
);
|
||||
|
||||
sliderPaddingRight = typedArray.getDimensionPixelOffset(R.styleable.RangeSliderView_paddingRight, 20);
|
||||
sliderPaddingLeft = typedArray.getDimensionPixelOffset(R.styleable.RangeSliderView_paddingLeft, 20);
|
||||
|
||||
typedArray.recycle();
|
||||
|
||||
minValueThumb = new ThumbLayer(thumbInnerRadius, thumbOutlineSize, trackHighlightTintColor, trackTintColor);
|
||||
minValueDisplayLabel = new TextLayer(displayTextFontSize, trackHighlightTintColor);
|
||||
|
||||
maxValueThumb = new ThumbLayer(thumbInnerRadius, 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);
|
||||
}
|
||||
deltaValue = 0;
|
||||
|
||||
longPressDetector = new GestureDetector(new GestureDetector.SimpleOnGestureListener() {
|
||||
public void onLongPress(MotionEvent e) {
|
||||
if (minValue == maxValue && (minValueThumb.isHighlight || maxValueThumb.isHighlight)) {
|
||||
isThumbViewLocked = true;
|
||||
minValueThumb.isHighlight = true;
|
||||
maxValueThumb.isHighlight = true;
|
||||
invalidate();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
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 onSizeChanged(int w, int h, int oldw, int oldh) {
|
||||
super.onSizeChanged(w, h, oldw, oldh);
|
||||
this.offsetY = getHeight() / 5 * 3;
|
||||
maxValueDisplayLabelOffsetY = offsetY - thumbInnerRadius - thumbOutlineSize - trackHeight / 2 - displayTextBasicOffsetY - displayTextFontSize;
|
||||
minValueDisplayLabelOffsetY = maxValueDisplayLabelOffsetY + displayTextFontSize + displayTextFontSize / 2;
|
||||
trackOffsetY = offsetY - trackHeight / 2;
|
||||
sliderWidth = getWidth() - sliderPaddingLeft - sliderPaddingRight;
|
||||
thumbRadius = thumbInnerRadius + thumbOutlineSize / 2;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDraw(Canvas canvas) {
|
||||
super.onDraw(canvas);
|
||||
|
||||
float minValueOffsetX = getPositionFromIndex(minValue);
|
||||
float maxValueOffsetX = getPositionFromIndex(maxValue);
|
||||
track.draw(canvas, getWidth(), minValueOffsetX, maxValueOffsetX, trackOffsetY, getDeltaInPixel());
|
||||
minValueThumb.draw(canvas, minValueOffsetX, offsetY);
|
||||
maxValueThumb.draw(canvas, maxValueOffsetX, offsetY);
|
||||
|
||||
if (onValueChangedListener != null) {
|
||||
minValueDisplayLabel.draw(
|
||||
canvas,
|
||||
onValueChangedListener.parseMinValueDisplayText(minValue),
|
||||
minValueOffsetX,
|
||||
minValueDisplayLabelOffsetY
|
||||
);
|
||||
maxValueDisplayLabel.draw(
|
||||
canvas,
|
||||
onValueChangedListener.parseMaxValueDisplayText(maxValue),
|
||||
maxValueOffsetX,
|
||||
maxValueDisplayLabelOffsetY
|
||||
);
|
||||
} else {
|
||||
minValueDisplayLabel.draw(canvas, String.valueOf(minValue), minValueOffsetX, minValueDisplayLabelOffsetY);
|
||||
maxValueDisplayLabel.draw(canvas, String.valueOf(maxValue), maxValueOffsetX, maxValueDisplayLabelOffsetY);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onTouchEvent(MotionEvent event) {
|
||||
longPressDetector.onTouchEvent(event);
|
||||
|
||||
if (event.getAction() == MotionEvent.ACTION_CANCEL) {
|
||||
if (onValueChangedListener != null) {
|
||||
onValueChangedListener.onValueChanged(minValue, maxValue);
|
||||
}
|
||||
minValueThumb.isHighlight = false;
|
||||
maxValueThumb.isHighlight = false;
|
||||
isThumbViewLocked = false;
|
||||
invalidate();
|
||||
return true;
|
||||
}
|
||||
|
||||
if (event.getAction() == MotionEvent.ACTION_UP) {
|
||||
isThumbViewLocked = false;
|
||||
if (minValueThumb.isHighlight || maxValueThumb.isHighlight) {
|
||||
if (onValueChangedListener != null) {
|
||||
onValueChangedListener.onValueChanged(minValue, maxValue);
|
||||
}
|
||||
minValueThumb.isHighlight = false;
|
||||
maxValueThumb.isHighlight = false;
|
||||
invalidate();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
int offsetX = (int) event.getX();
|
||||
if (offsetX < (sliderPaddingLeft - thumbRadius) || offsetX > getWidth() - sliderPaddingRight + thumbRadius) {
|
||||
//Log.d(TAG, "ignore touch in padding");
|
||||
return true;
|
||||
}
|
||||
|
||||
switch (event.getAction()) {
|
||||
case MotionEvent.ACTION_DOWN:
|
||||
float minValuePosition = getPositionFromIndex(minValue);
|
||||
Log.d(TAG, "action_down minVal: " + minValue + ", " + minValuePosition );
|
||||
if (offsetX >= minValuePosition - thumbRadius && offsetX <= minValuePosition + thumbRadius) {
|
||||
minValueThumb.isHighlight = true;
|
||||
} else {
|
||||
float maxValuePosition = getPositionFromIndex(maxValue);
|
||||
if (offsetX >= maxValuePosition - thumbRadius && offsetX <= maxValuePosition + thumbRadius) {
|
||||
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 (isThumbViewLocked) {
|
||||
minValue = values.get(index);
|
||||
maxValue = values.get(index);
|
||||
} else 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) {
|
||||
invalidate();
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
protected int getIndexFromPosition(int offsetX) {
|
||||
return (int) (((offsetX - sliderPaddingLeft) * getCount()) / sliderWidth);
|
||||
}
|
||||
|
||||
protected float getPositionFromIndex(int value) {
|
||||
return ((sliderWidth / (float) getCount()) * value) + sliderPaddingLeft;
|
||||
}
|
||||
|
||||
/**
|
||||
* When filtering for a point (in time) a delta (time) span is added to improve the search results.
|
||||
* This method converts the delta to pixel related to the slider width.
|
||||
* @return
|
||||
*/
|
||||
public float getDeltaInPixel() {
|
||||
float deltaInPixel = (sliderWidth / getCount()) * deltaValue;
|
||||
if (deltaInPixel >= 2 * (thumbInnerRadius + thumbOutlineSize)) {
|
||||
return deltaInPixel;
|
||||
}
|
||||
// for better visibility return a minimum limit of the diameter of the thumb element
|
||||
return 2 * thumbInnerRadius + thumbOutlineSize;
|
||||
}
|
||||
|
||||
public int getCount() {
|
||||
return values.size();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,21 +0,0 @@
|
||||
package org.thoughtcrime.securesms.components.rangeslider;
|
||||
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Paint;
|
||||
|
||||
class TextLayer {
|
||||
|
||||
private final 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);
|
||||
}
|
||||
}
|
||||
@@ -1,46 +0,0 @@
|
||||
package org.thoughtcrime.securesms.components.rangeslider;
|
||||
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.Paint;
|
||||
|
||||
class ThumbLayer {
|
||||
|
||||
private final float radius;
|
||||
private final float outlineSize;
|
||||
|
||||
private final int highlightColor;
|
||||
|
||||
private final Paint outlinePaint;
|
||||
private final 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);
|
||||
}
|
||||
}
|
||||
@@ -1,161 +0,0 @@
|
||||
package org.thoughtcrime.securesms.components.rangeslider;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.TypedArray;
|
||||
import android.graphics.Canvas;
|
||||
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 {
|
||||
private static final int DEFAULT_TIMEFRAME_2D = 60 * 60 * 24 * 2; // 2d
|
||||
private static final float DEFAULT_DELTA = 1000 * 60 * 30; // 30 min
|
||||
final int timeFrame; // timeframe in seconds
|
||||
|
||||
final Locale locale;
|
||||
OnTimestampChangedListener listener;
|
||||
private final TextLayer minRangeDisplayLabel;
|
||||
private final TextLayer maxRangeDisplayLabel;
|
||||
|
||||
float displayLabelOffsetBelow;
|
||||
|
||||
|
||||
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);
|
||||
minRangeDisplayLabel = new TextLayer(displayTextFontSize, trackHighlightTintColor);
|
||||
maxRangeDisplayLabel = new TextLayer(displayTextFontSize, trackHighlightTintColor);
|
||||
deltaValue = getDelta();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
|
||||
super.onSizeChanged(w, h, oldw, oldh);
|
||||
displayLabelOffsetBelow = offsetY + thumbInnerRadius + thumbOutlineSize + trackHeight / 2 + displayTextBasicOffsetY;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDraw(Canvas canvas) {
|
||||
super.onDraw(canvas);
|
||||
|
||||
float minValueOffsetX = getPositionFromIndex(minValue);
|
||||
float maxValueOffsetX = getPositionFromIndex(maxValue);
|
||||
|
||||
deltaValue = getDelta();
|
||||
if (minValue == maxValue) {
|
||||
if (minValueOffsetX - getDeltaInPixel() >= sliderPaddingLeft) {
|
||||
minRangeDisplayLabel.draw(
|
||||
canvas,
|
||||
getDeltaInTime(getContext()),
|
||||
minValueOffsetX - getDeltaInPixel(),
|
||||
displayLabelOffsetBelow
|
||||
);
|
||||
}
|
||||
|
||||
if (maxValueOffsetX + getDeltaInPixel() <= (getWidth() - sliderPaddingRight)) {
|
||||
maxRangeDisplayLabel.draw(
|
||||
canvas,
|
||||
getDeltaInTime(getContext()),
|
||||
maxValueOffsetX + getDeltaInPixel(),
|
||||
displayLabelOffsetBelow
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public interface OnTimestampChangedListener {
|
||||
void onTimestampChanged(long startTimestamp, long stopTimestamp);
|
||||
|
||||
/**
|
||||
* filter for lastPosition beginning from startTimestamp to now
|
||||
* @param startTimestamp begin of time frame
|
||||
*/
|
||||
void onFilterLastPosition(long startTimestamp);
|
||||
}
|
||||
|
||||
|
||||
public void setOnTimestampChangedListener(OnTimestampChangedListener timestampChangedListener) {
|
||||
listener = timestampChangedListener;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onValueChanged(int minValue, int maxValue) {
|
||||
if (listener != null) {
|
||||
long minTimeStamp = getTimestampForValue(minValue);
|
||||
if (maxValue == getCount()) {
|
||||
if (minValue == maxValue) {
|
||||
listener.onFilterLastPosition(System.currentTimeMillis() - (long) DEFAULT_DELTA);
|
||||
} else {
|
||||
listener.onFilterLastPosition(minTimeStamp);
|
||||
}
|
||||
} else if (minValue == maxValue) {
|
||||
// filter for time of event with delta before and after
|
||||
listener.onTimestampChanged(minTimeStamp - (long) DEFAULT_DELTA, minTimeStamp + (long) DEFAULT_DELTA);
|
||||
} else {
|
||||
//filter for time span
|
||||
listener.onTimestampChanged(minTimeStamp, getTimestampForValue(maxValue));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String parseMinValueDisplayText(int minValue) {
|
||||
if (minValue == maxValue) {
|
||||
return "";
|
||||
}
|
||||
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 / getCount()) * (getCount() - value) * 1000);
|
||||
}
|
||||
|
||||
public String getDeltaInTime(Context context) {
|
||||
return DateUtils.getFormattedTimespan(context, (int) (timeFrame * 1000 / getCount() * getDelta()));
|
||||
}
|
||||
|
||||
/**
|
||||
* When filtering for a point in time a delta time span is added to improve the search results.
|
||||
* @return normalized delta
|
||||
*/
|
||||
private float getDelta() {
|
||||
return DEFAULT_DELTA / (timeFrame * 1000) * getCount();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -1,65 +0,0 @@
|
||||
package org.thoughtcrime.securesms.components.rangeslider;
|
||||
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Paint;
|
||||
import android.graphics.RectF;
|
||||
|
||||
class TrackLayer {
|
||||
|
||||
private final float height;
|
||||
private final float radius;
|
||||
private int paddingLeft = 0;
|
||||
private int paddingRight = 0;
|
||||
|
||||
private final Paint centerPaint;
|
||||
private final 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, float delta) {
|
||||
draw(canvas, backgoundPaint, paddingLeft, width - paddingRight, offsetY);
|
||||
if (offsetLeft == offsetRight) {
|
||||
float maxEndX = width - paddingRight;
|
||||
float minStartX = paddingLeft;
|
||||
float offsetDeltaLeft = offsetLeft - delta;
|
||||
float offsetDeltaRight = offsetRight + delta;
|
||||
|
||||
if (offsetLeft - delta < minStartX) {
|
||||
offsetDeltaLeft = minStartX;
|
||||
} else if (offsetRight + delta > maxEndX) {
|
||||
offsetDeltaRight = maxEndX;
|
||||
}
|
||||
|
||||
draw(canvas, centerPaint, offsetDeltaLeft, offsetDeltaRight, offsetY);
|
||||
}
|
||||
else {
|
||||
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