xref: /aosp_15_r20/external/androidplot/AndroidPlot-Core/src/main/java/com/androidplot/util/PaintUtils.java (revision e67b5c11b0a39d07706faa2f5faf820db3848005)
1 /*
2  * Copyright 2012 AndroidPlot.com
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.androidplot.util;
18 import android.graphics.Paint;
19 
20 /**
21  * Convenience methods that operate on Paint instances.  These methods primarily deal with
22  * converting pixel values to/from dp values.
23  */
24 public class PaintUtils {
25 
26     /*public static Paint getPaint() {
27         Paint p = new Paint();
28         return p;
29     }*/
30 
31     /**
32      * Sets a paint instance's line stroke size in dp
33      * @param paint
34      * @param lineSizeDp
35      */
setLineSizeDp(Paint paint, float lineSizeDp)36     public static void setLineSizeDp(Paint paint, float lineSizeDp){
37         paint.setStrokeWidth(PixelUtils.dpToPix(lineSizeDp));
38     }
39 
40     /**
41      * Sets a paint instance's font size in dp
42      * @param paint
43      * @param fontSizeDp
44      */
setFontSizeDp(Paint paint, float fontSizeDp)45     public static void setFontSizeDp(Paint paint, float fontSizeDp){
46         paint.setTextSize(PixelUtils.dpToPix(fontSizeDp));
47     }
48 
49     /**
50      * Set a paint instance's shadowing using dp values
51      * @param paint
52      * @param radiusDp
53      * @param dxDp
54      * @param dyDp
55      * @param color
56      */
setShadowDp(Paint paint, float radiusDp, float dxDp, float dyDp, int color)57     public static void setShadowDp(Paint paint, float radiusDp, float dxDp, float dyDp, int color) {
58         float radius = PixelUtils.dpToPix(radiusDp);
59         float dx = PixelUtils.dpToPix(dxDp);
60         float dy = PixelUtils.dpToPix(dyDp);
61         paint.setShadowLayer(radius, dx, dy, color);
62     }
63 
64 
65 }
66