huangcm
2025-04-09 02d4ce54b909bd733f12e9f3fa4c1b03cf2d6f45
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package com.DeviceTest.view;
 
import android.R.color;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Paint.Style;
import android.graphics.Rect;
import android.util.AttributeSet;
import android.view.View;
 
public class LcdTestView extends View {
 
   private boolean grayScale = false;
   private boolean paneBorder = false;
   private Paint mPaint = new Paint();
   private Rect mRect = new Rect();
 
   public LcdTestView(Context context) {
       this(context, null, 0);
   }
 
   public LcdTestView(Context context, AttributeSet attrs) {
       this(context, attrs, 0);
   }
 
   public LcdTestView(Context context, AttributeSet attrs, int defStyle) {
       super(context, attrs, defStyle);
   }
 
   public void grayScale(boolean enable) {
       grayScale = enable;
   }
 
   public void paneBorder(boolean enable) {
       paneBorder = enable;
   }
 
   
   public void onDraw(Canvas canvas) {
       super.onDraw(canvas);
       if (grayScale) {
           mPaint.setStyle(Style.FILL);
           getDrawingRect(mRect);
           final int width = getWidth();
           final int scale = 16;
           final int scaleWidth = width / scale;
           final int left = 0;
 
           for (int i = 0; i < scale; i++) {
               int gray = i * 16;
               gray = gray > 255 ? 255 : gray;
               mPaint.setColor(Color.rgb(gray, gray, gray));
               mRect.left = left + i * scaleWidth;
               mRect.right = left + (i + 1) * scaleWidth;
               canvas.drawRect(mRect, mPaint);
           }
 
           canvas.drawRect(mRect, mPaint);
       }
       if (paneBorder) {
           canvas.drawColor(Color.BLACK);
           mPaint.setColor(Color.WHITE);
           mPaint.setStyle(Style.STROKE);
           mPaint.setStrokeWidth(5);
           getDrawingRect(mRect);
           canvas.drawRect(mRect, mPaint);
       }
 
   }
}