@@ -5,19 +5,12 @@ import android.graphics.Canvas
55import android.graphics.Color
66import android.graphics.Paint
77import android.graphics.Rect
8- import android.util.Log
98import android.view.SurfaceView
109import android.view.View
1110import com.onyx.android.sdk.data.note.TouchPoint
1211import com.onyx.android.sdk.pen.RawInputCallback
1312import com.onyx.android.sdk.pen.TouchHelper
1413import com.onyx.android.sdk.pen.data.TouchPointList
15- import com.onyx.android.sdk.pen.NeoBrushPen
16- import com.onyx.android.sdk.pen.NeoCharcoalPenV2
17- import com.onyx.android.sdk.pen.NeoMarkerPen
18- import com.onyx.android.sdk.pen.NeoFountainPen
19- import com.onyx.android.sdk.pen.NeoPen
20- import com.onyx.android.sdk.api.device.epd.EpdController
2114import io.flutter.plugin.platform.PlatformView
2215import io.flutter.plugin.common.MethodChannel
2316import io.flutter.plugin.common.MethodChannel.MethodCallHandler
@@ -29,72 +22,88 @@ import java.util.TimerTask
2922import androidx.annotation.NonNull
3023
3124internal class OnyxsdkPenArea (context : Context , messenger : BinaryMessenger , id : Int , creationParams : Map <String ?, Any ?>? ) : PlatformView, MethodCallHandler {
25+
3226 enum class StrokeStyle (val Id : Int ) {
33- FountainPen (0 ),
34- Pen (1 ),
35- Brush (2 ),
36- Pencil (3 ),
37- Marker (4 )
27+ FountainPen (0 ),
28+ Pen (1 ),
29+ Brush (2 ),
30+ Pencil (3 ),
31+ Marker (4 )
3832 }
33+
3934 private val channel: MethodChannel = MethodChannel (messenger, " onyxsdk_pen_area" )
35+
4036 companion object {
4137 private val pointsToRedraw = 20
42-
4338 }
39+
4440 private var strokeWidth = 0.0f
45- var strokeColor = Color .BLACK
46- var strokeStyle = StrokeStyle .FountainPen
41+ private var strokeColor = Color .BLACK
42+ private var strokeStyle = StrokeStyle .FountainPen
4743
4844 private fun updateStroke (paramsRef : Map <String , Any >? ) {
49- /*
50- Flutter ints are variable width
51- Personally, I think it is utterly dumb. I hope there is a way to fix
52- int size in flutter (why would you need 64 bits to store srgb??),
53- but unless or until there isn't, this stupidity should be performed
54- */
55- val pureColor = (paramsRef?.get(" strokeColor" ) as ? Long )?.toInt()
56- ? : paramsRef?.get(" strokeColor" ) as ? Int
57- ? : Color .BLACK
58- /*
59- ONYXSDK Pen saturates the colors. Whatever it deems as "light" (luma < 128?)
60- gets automagically turned to white. Transparency is also accounted apparently.
61- Unless this is some case-by-case situation, if resulting color, assuming
62- being drawn on absolutely white background, with a fully opaque brush
63- is lighter than a certain unknown arbitrary threshold, it turns white,
64- otherwise, is saturated to max.
65- These thoughts are, however, purely observational. Nothing in documentation
66- says this and no binary artifacts have been decompiled to come to these
67- conclusions. Thus, feel free to correct my incompetence if I turn out wrong
68- */
69- var dest = FloatArray (3 )
70- Color .RGBToHSV (
71- Color .red(pureColor),
72- Color .green(pureColor),
73- Color .blue(pureColor),
74- dest
75- )
76- dest[1 ] = 1.0f /* saturation */
77- /*
78- I suppose rounding value is reasonable, but I want color to show
79- So clamp to black if it's visually indistinguishable from black
80- and to colorful otherwise. E.g. brown will look red instead of black
81- */
82- if (dest[2 ] < 0.2 ) {
83- dest[2 ] = 0.0f
84- } else {
85- dest[2 ] = 1.0f
86- }
87- strokeColor = Color .HSVToColor (dest)
88- strokeWidth = (paramsRef?.get(" strokeWidth" ) as ? Double ? : 3.0 ).toFloat()
89- strokeStyle = when (paramsRef?.get(" strokeStyle" ) as ? Int ? : 0 ) {
90- 0 -> StrokeStyle .FountainPen
91- 1 -> StrokeStyle .Pen
92- 2 -> StrokeStyle .Brush
93- 3 -> StrokeStyle .Pencil
94- 4 -> StrokeStyle .Marker
95- else -> StrokeStyle .Pen
96- }
97- Log .d(" SABERSTROKEUPDATE" , " color: %d, width: %f, style: %s" .format(strokeColor, strokeWidth, strokeStyle.name))
45+ /*
46+ Flutter ints are variable width
47+ Personally, I think it is utterly dumb. I hope there is a way to fix
48+ int size in flutter (why would you need 64 bits to store srgb??),
49+ but unless or until there isn't, this stupidity should be performed
50+ */
51+ val pureColor = (paramsRef?.get(" strokeColor" ) as ? Long )?.toInt()
52+ ? : paramsRef?.get(" strokeColor" ) as ? Int
53+ ? : Color .BLACK
54+ /*
55+ ONYXSDK Pen saturates the colors. Whatever it deems as "light" (luma < 128?)
56+ gets automagically turned to white. Transparency is also accounted apparently.
57+ Unless this is some case-by-case situation, if resulting color, assuming
58+ being drawn on absolutely white background, with a fully opaque brush
59+ is lighter than a certain unknown arbitrary threshold, it turns white,
60+ otherwise, is saturated to max.
61+ These thoughts are, however, purely observational. Nothing in documentation
62+ says this and no binary artifacts have been decompiled to come to these
63+ conclusions. Thus, feel free to correct my incompetence if I turn out wrong
64+ */
65+ var dest = FloatArray (3 )
66+ Color .RGBToHSV (
67+ Color .red(pureColor),
68+ Color .green(pureColor),
69+ Color .blue(pureColor),
70+ dest
71+ )
72+ /*
73+ Saturation
74+ I suppose clamping is a sound idea, but the extremes to which the lib
75+ takes them are unacceptable. Make it white if visually indistinguishable
76+ from white and colorful otherwise.
77+ */
78+ if (dest[1 ] < 0.05 ) {
79+ dest[1 ] = 0.0f
80+ } else {
81+ dest[1 ] = 1.0f
82+ }
83+ /*
84+ Value
85+ I want color to show
86+ So clamp to black if it's visually indistinguishable from black
87+ and to colorful otherwise. E.g. brown will look red instead of black
88+ */
89+ if (dest[2 ] < 0.2 ) {
90+ dest[2 ] = 0.0f
91+ } else {
92+ dest[2 ] = 1.0f
93+ }
94+ strokeColor = Color .HSVToColor (dest)
95+ strokeWidth = (paramsRef?.get(" strokeWidth" ) as ? Double ? : 3.0 ).toFloat()
96+ strokeStyle = when (paramsRef?.get(" strokeStyle" ) as ? Int ? : 0 ) {
97+ 0 -> StrokeStyle .FountainPen
98+ 1 -> StrokeStyle .Pen
99+ 2 -> StrokeStyle .Brush
100+ 3 -> StrokeStyle .Pencil
101+ 4 -> StrokeStyle .Marker
102+ else -> StrokeStyle .Pen
103+ }
104+ touchHelper.setStrokeStyle(strokeStyleToOnyx(strokeStyle))
105+ touchHelper.setStrokeWidth(strokeWidth)
106+ touchHelper.setStrokeColor(strokeColor)
98107 }
99108
100109
@@ -106,7 +115,6 @@ internal class OnyxsdkPenArea(context: Context, messenger: BinaryMessenger, id:
106115 }
107116
108117 private val paint: Paint = Paint ()
109- private val deviceMaxPressure = EpdController .getMaxTouchPressure()
110118 private var pointsSinceLastRedraw = 0
111119
112120 private val currentStroke: ArrayList <TouchPoint > = ArrayList ()
@@ -116,10 +124,6 @@ internal class OnyxsdkPenArea(context: Context, messenger: BinaryMessenger, id:
116124
117125 private val callback: RawInputCallback = object : RawInputCallback () {
118126 fun reset () {
119- touchHelper.setStrokeStyle(strokeStyleToOnyx(strokeStyle))
120- touchHelper.setStrokeWidth(strokeWidth)
121- touchHelper.setStrokeColor(strokeColor)
122-
123127 currentStroke.clear()
124128 pointsSinceLastRedraw = 0
125129 drawPreview()
@@ -184,21 +188,21 @@ internal class OnyxsdkPenArea(context: Context, messenger: BinaryMessenger, id:
184188 }
185189
186190 private fun strokeStyleToOnyx (style : StrokeStyle ): Int {
187- return when (style) {
188- StrokeStyle .FountainPen -> TouchHelper .STROKE_STYLE_FOUNTAIN
189- StrokeStyle .Pen -> TouchHelper .STROKE_STYLE_PENCIL
190- StrokeStyle .Brush -> TouchHelper .STROKE_STYLE_NEO_BRUSH
191- StrokeStyle .Pencil -> TouchHelper .STROKE_STYLE_CHARCOAL_V2
192- StrokeStyle .Marker -> TouchHelper .STROKE_STYLE_MARKER
193- }
191+ return when (style) {
192+ StrokeStyle .FountainPen -> TouchHelper .STROKE_STYLE_FOUNTAIN
193+ StrokeStyle .Pen -> TouchHelper .STROKE_STYLE_PENCIL
194+ StrokeStyle .Brush -> TouchHelper .STROKE_STYLE_NEO_BRUSH
195+ StrokeStyle .Pencil -> TouchHelper .STROKE_STYLE_CHARCOAL
196+ StrokeStyle .Marker -> TouchHelper .STROKE_STYLE_MARKER
197+ }
194198 }
195199
196200 fun drawPreview () {
197- currentStroke.clear()
201+ currentStroke.clear()
198202 }
199203
200204 init {
201- channel.setMethodCallHandler(this )
205+ channel.setMethodCallHandler(this )
202206 view.addOnLayoutChangeListener { _, _, _, _, _, _, _, _, _ ->
203207 val limit = Rect ()
204208 val exclude = emptyList<Rect >()
@@ -220,13 +224,13 @@ internal class OnyxsdkPenArea(context: Context, messenger: BinaryMessenger, id:
220224 }
221225
222226 override fun onMethodCall (@NonNull call : MethodCall , @NonNull result : Result ) {
223- if (call.method == " updateStroke" ) {
224- val params = call.arguments<Map <String , Any >? > ()
225- updateStroke(params)
226- result.success(null )
227- } else {
228- result.notImplemented()
229- }
227+ if (call.method == " updateStroke" ) {
228+ val params = call.arguments<Map <String , Any >? > ()
229+ updateStroke(params)
230+ result.success(null )
231+ } else {
232+ result.notImplemented()
233+ }
230234 }
231235
232236 override fun dispose () {
0 commit comments