Skip to content

Commit 2f4b35f

Browse files
committed
提供更多的手势监听
1 parent 5d59876 commit 2f4b35f

File tree

6 files changed

+101
-12
lines changed

6 files changed

+101
-12
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@ Data.loadDayData(this, 0) { kEntities: List<IKEntity> ->
154154
|gridLineStrokeWidth|背景网格线条宽度|
155155
|chartMainDisplayAreaPaddingLeft|主数据显示区域的左内间距,主数据一般指数据线|
156156
|chartMainDisplayAreaPaddingRight|主数据显示区域的右内间距,主数据一般指数据线|
157+
|onGestureListener|手势监听|
157158

158159

159160
### K线图配置`KChartConfig`
@@ -183,7 +184,7 @@ Data.loadDayData(this, 0) { kEntities: List<IKEntity> ->
183184
|costPriceLineWidth|成本线宽度|
184185
|indexStrokeWidth|指标线条宽度|
185186
|barSpaceRatio|柱子之间的空间占比柱子宽度|
186-
|index|需要展示的指标类型|
187+
|index|需要展示的指标类型,目前只有MA、EMA、BOLL|
187188
|indexColors|指标线的颜色|
188189
|leftLabelConfig|左侧标签配置|
189190
|rightLabelConfig|右侧标签配置|

lib/src/main/java/com/github/wangyiqian/stockchart/StockChart.kt

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ class StockChart @JvmOverloads constructor(context: Context, attrs: AttributeSet
282282

283283
for (i in 1..config.gridHorizontalLineCount) {
284284
canvas.drawLine(
285-
config.horizontalGridLineLeftOffsetCalculator?.invoke(this)?:0f,
285+
config.horizontalGridLineLeftOffsetCalculator?.invoke(this) ?: 0f,
286286
top,
287287
width.toFloat(),
288288
top,
@@ -312,6 +312,7 @@ class StockChart @JvmOverloads constructor(context: Context, attrs: AttributeSet
312312
if (getConfig().scaleAble) {
313313
requestDisallowInterceptTouchEvent(true)
314314
matrixHelper.handleTouchScaleBegin(focusX)
315+
getConfig().getOnGestureListeners().forEach { it.onScaleBegin(focusX) }
315316
}
316317
}
317318

@@ -327,11 +328,13 @@ class StockChart @JvmOverloads constructor(context: Context, attrs: AttributeSet
327328
if (getConfig().scrollAble) {
328329
requestDisallowInterceptTouchEvent(true)
329330
matrixHelper.handleTouchScroll(distanceX)
331+
getConfig().getOnGestureListeners().forEach { it.onHScrolling() }
330332
}
331333
}
332334

333335
override fun onTriggerFling(velocityX: Float, velocityY: Float) {
334336
matrixHelper.handleFlingStart(velocityX, velocityY)
337+
getConfig().getOnGestureListeners().forEach { it.onFlingBegin() }
335338
}
336339

337340
override fun onLongPressMove(x: Float, y: Float) {
@@ -369,9 +372,11 @@ class StockChart @JvmOverloads constructor(context: Context, attrs: AttributeSet
369372
highlightMap.keys.forEach {
370373
it.getConfig().onHighlightListener?.onHighlightEnd()
371374
}
375+
getConfig().getOnGestureListeners().forEach { it.onTouchLeave() }
372376
highlightMap.clear()
373377
notifyChanged()
374378
matrixHelper.checkScrollBack()
379+
375380
}
376381

377382
override fun onTap(x: Float, y: Float) {
@@ -386,6 +391,19 @@ class StockChart @JvmOverloads constructor(context: Context, attrs: AttributeSet
386391
val gestureEvent = GestureEvent(childChartX, childChartY, valueX, valueY)
387392
childChart.onTap(gestureEvent)
388393
}
394+
getConfig().getOnGestureListeners().forEach { it.onTap(x, y) }
395+
}
396+
397+
override fun onLongPressBegin(x: Float, y: Float) {
398+
getConfig().getOnGestureListeners().forEach { it.onLongPressBegin(x, y) }
399+
}
400+
401+
override fun onLongPressing(x: Float, y: Float) {
402+
getConfig().getOnGestureListeners().forEach { it.onLongPressing(x, y) }
403+
}
404+
405+
override fun onLongPressEnd(x: Float, y: Float) {
406+
getConfig().getOnGestureListeners().forEach { it.onLongPressEnd(x, y) }
389407
}
390408

391409
}

lib/src/main/java/com/github/wangyiqian/stockchart/TouchHelper.kt

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,21 +61,29 @@ internal class TouchHelper(private val stockChart: IStockChart, private val call
6161
MotionEvent.ACTION_MOVE -> {
6262
if (isLongPressing && event.getPointerId(event.actionIndex) == inLongPressingPointerId) {
6363
callBack.onLongPressMove(event.x, event.y)
64+
callBack.onLongPressing(event.x, event.y)
6465
}
6566
}
6667
MotionEvent.ACTION_UP -> {
67-
isLongPressing = false
68+
if (isLongPressing) {
69+
isLongPressing = false
70+
callBack.onLongPressEnd(event.x, event.y)
71+
}
6872
isTouchScalePointersLeave = true
6973
callBack.onTouchLeave()
7074
}
7175
MotionEvent.ACTION_CANCEL -> {
72-
isLongPressing = false
76+
if (isLongPressing) {
77+
isLongPressing = false
78+
callBack.onLongPressEnd(event.x, event.y)
79+
}
7380
isTouchScalePointersLeave = true
7481
callBack.onTouchLeave()
7582
}
7683
MotionEvent.ACTION_POINTER_UP -> {
7784
if (isLongPressing && event.getPointerId(event.actionIndex) == inLongPressingPointerId) {
7885
isLongPressing = false
86+
callBack.onLongPressEnd(event.x, event.y)
7987
}
8088
}
8189
}
@@ -97,7 +105,12 @@ internal class TouchHelper(private val stockChart: IStockChart, private val call
97105
}
98106

99107
override fun onLongPress(e: MotionEvent) {
100-
isLongPressing = true
108+
if (!isLongPressing) {
109+
isLongPressing = true
110+
callBack.onLongPressBegin(e.x, e.y)
111+
} else {
112+
callBack.onLongPressing(e.x, e.y)
113+
}
101114
inLongPressingPointerId = e.getPointerId(0)
102115
callBack.onLongPressMove(e.x, e.y)
103116
super.onLongPress(e)
@@ -190,5 +203,20 @@ internal class TouchHelper(private val stockChart: IStockChart, private val call
190203
* 点击
191204
*/
192205
fun onTap(x: Float, y: Float)
206+
207+
/**
208+
* 开始长按
209+
*/
210+
fun onLongPressBegin(x: Float, y: Float) {}
211+
212+
/**
213+
* 长按中
214+
*/
215+
fun onLongPressing(x: Float, y: Float) {}
216+
217+
/**
218+
* 结束长按
219+
*/
220+
fun onLongPressEnd(x: Float, y: Float) {}
193221
}
194222
}

lib/src/main/java/com/github/wangyiqian/stockchart/childchart/macdchart/MacdChartConfig.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,13 @@ class MacdChartConfig(
3636
// dif线颜色
3737
var difLineColor: Int = DEFAULT_MACD_DIF_LINE_COLOR,
3838
// dif线宽度
39-
val difLineStrokeWidth: Float = DEFAULT_MACD_DIF_LINE_STROKE_WIDTH,
39+
var difLineStrokeWidth: Float = DEFAULT_MACD_DIF_LINE_STROKE_WIDTH,
4040
// dea线颜色
4141
var deaLineColor: Int = DEFAULT_MACD_DEA_LINE_COLOR,
4242
// dea线宽度
43-
val deaLineStrokeWidth: Float = DEFAULT_MACD_DEA_LINE_STROKE_WIDTH,
43+
var deaLineStrokeWidth: Float = DEFAULT_MACD_DEA_LINE_STROKE_WIDTH,
4444
// macd文字颜色
45-
val macdTextColor: Int = DEFAULT_MACD_TEXT_COLOR,
45+
var macdTextColor: Int = DEFAULT_MACD_TEXT_COLOR,
4646
// 柱子之间的空间占比柱子宽度
4747
var barSpaceRatio: Float = DEFAULT_MACD_BAR_SPACE_RATIO,
4848
// 需要展示的指标配置

lib/src/main/java/com/github/wangyiqian/stockchart/listener/OnGestureListener.kt

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,56 @@
1313

1414
package com.github.wangyiqian.stockchart.listener
1515

16+
import com.github.wangyiqian.stockchart.entities.GestureEvent
17+
1618
/**
1719
* @author wangyiqian E-mail: wangyiqian9891@gmail.com
1820
* @version 创建时间: 2021/11/29
1921
*/
2022
interface OnGestureListener {
2123

2224
/**
23-
* 是否正在缩放
25+
* 滑动中
26+
*/
27+
fun onHScrolling() {}
28+
29+
/**
30+
* 开始fling
31+
*/
32+
fun onFlingBegin() {}
33+
34+
/**
35+
* 手指离开屏幕
36+
*/
37+
fun onTouchLeave() {}
38+
39+
/**
40+
* 开始缩放
41+
*/
42+
fun onScaleBegin(focusX: Float) {}
43+
44+
/**
45+
* 缩放中
46+
*/
47+
fun onScaling(totalScaleX: Float) {}
48+
49+
/**
50+
* 单击
51+
*/
52+
fun onTap(x: Float, y: Float) {}
53+
54+
/**
55+
* 开始长按
56+
*/
57+
fun onLongPressBegin(x: Float, y: Float) {}
58+
59+
/**
60+
* 长按中
61+
*/
62+
fun onLongPressing(x: Float, y: Float) {}
63+
64+
/**
65+
* 结束长按
2466
*/
25-
fun onScaling(totalScaleX: Float){}
67+
fun onLongPressEnd(x: Float, y: Float) {}
2668
}

samples/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,6 @@ dependencies {
7070
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
7171
implementation 'com.google.android:flexbox:2.0.1'
7272

73-
// implementation project(':lib')
74-
implementation 'com.github.wangyiqian:StockChart:1.1.11'
73+
implementation project(':lib')
74+
// implementation 'com.github.wangyiqian:StockChart:1.1.11'
7575
}

0 commit comments

Comments
 (0)