• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2018 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.android.egg.paint
18 
19 import android.content.Context
20 import android.graphics.*
21 import android.graphics.PixelFormat.TRANSLUCENT
22 import android.graphics.drawable.Drawable
23 import android.util.DisplayMetrics
24 
25 class BrushPropertyDrawable : Drawable {
<lambda>null26     val framePaint = Paint(Paint.ANTI_ALIAS_FLAG).also {
27         it.color = Color.BLACK
28         it.style = Paint.Style.FILL
29     }
<lambda>null30     val wellPaint = Paint(Paint.ANTI_ALIAS_FLAG).also {
31         it.color = Color.RED
32         it.style = Paint.Style.FILL
33     }
34 
35     constructor(context: Context) {
36         _size = (24 * context.resources.displayMetrics.density).toInt()
37     }
38 
39     private var _size = 24
40     private var _scale = 1f
41 
setFrameColornull42     fun setFrameColor(color: Int) {
43         framePaint.color = color
44         invalidateSelf()
45     }
46 
setWellColornull47     fun setWellColor(color: Int) {
48         wellPaint.color = color
49         invalidateSelf()
50     }
51 
setWellScalenull52     fun setWellScale(scale: Float) {
53         _scale = scale
54         invalidateSelf()
55     }
56 
getIntrinsicWidthnull57     override fun getIntrinsicWidth(): Int {
58         return _size
59     }
60 
getIntrinsicHeightnull61     override fun getIntrinsicHeight(): Int {
62         return _size
63     }
64 
drawnull65     override fun draw(c: Canvas?) {
66         c?.let {
67             val w = bounds.width().toFloat()
68             val h = bounds.height().toFloat()
69             val inset = _size / 12 // 2dp in a 24x24 icon
70             val r = Math.min(w, h) / 2
71 
72             c.drawCircle(w/2, h/2, (r - inset) * _scale + 1 , wellPaint)
73 
74             val p = Path()
75             p.addCircle(w/2, h/2, r, Path.Direction.CCW)
76             p.addCircle(w/2, h/2, r - inset, Path.Direction.CW)
77             c.drawPath(p, framePaint)
78         }
79     }
80 
setAlphanull81     override fun setAlpha(p0: Int) {
82         //
83     }
84 
getOpacitynull85     override fun getOpacity(): Int {
86         return TRANSLUCENT
87     }
88 
setColorFilternull89     override fun setColorFilter(p0: ColorFilter?) {
90         //
91     }
92 
93 }