左晓为主开发手持机充值管理机
zuoxiao
2023-12-08 aadcaabdf5fc8b3b1b941fef47300d666ae6876a
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
package com.dayu.recharge.view;
 
 
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Rect;
import android.os.Handler;
import android.util.AttributeSet;
import android.util.Log;
import android.view.Display;
import android.view.View;
import android.view.WindowManager;
 
import com.dayu.recharge.R;
 
 
/**
 * 视频取景器控件
 *
 * @author fangcm 2012-09-06
 */
public class ViewfinderView extends View {
 
    private int width, height;
    private Paint paint;
    private Context mContext;
    private int mWidth, mHeight;
    private float lineLeft, lineRight, lineTop, lineBottom;
    private int lineModel = 0;
    private float marginW = 0f;
    private float marginH = 0f;
    private float marginT = 0f;
    private int dLineWidth = 12;
    private int dLen = 60;
    private int m_nImageWidth;
    private int m_nImageHeight;
 
    boolean l = false, r = false, t = false, b = false, L = false;
 
    public ViewfinderView(Context context, AttributeSet attrs) {
        super(context, attrs);
        // TODO Auto-generated constructor stub
        this.mContext = context;
    }
 
 
    public ViewfinderView(Context context) {
        super(context);
        // TODO Auto-generated constructor stub
        this.mContext = context;
    }
 
    public ViewfinderView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        // TODO Auto-generated constructor stub
        this.mContext = context;
    }
 
    /**
     * 大小  85.6*54
     * 长是宽的1.58倍
     *
     * @param pWidth
     * @param pHeight
     */
    public float[] initFinder(int pWidth, int pHeight, Handler mHandler, int typeFront) {
        m_nImageWidth = pWidth;
        m_nImageHeight = pHeight;
        WindowManager manager = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE);
        Display display = manager.getDefaultDisplay();
        width = display.getWidth();
        height = display.getHeight();
        Log.d("tag", "-1-------->>" + width);
 
        marginT = mContext.getResources().getDimension(R.dimen.public_46_dp);
 
        marginW = (float) ((width - pWidth) / 2.0);
        marginH = (float) ((height - pHeight) / 2.0);
 
        mWidth = width / 2;
        mHeight = height / 2;
 
        float g = height - marginT * 2;
        float k = g * 1.58f;
        float x = 10.0f;
        Log.d("ocr", k + "<<--k---高度----g--1---->>" + g);
        while (k > pWidth) {
            x--;
            k = k * (x / 10.0f);
            g = g * (x / 10.0f);
        }
        Log.d("ocr", k + "<<--k---高度----g--2---->>" + g);
        lineLeft = (float) (mWidth - k / 2.0);
        lineRight = (float) (mWidth + k / 2.0);
        lineTop = (float) (mHeight - g / 2.0);
        lineBottom = (float) (mHeight + g / 2.0);
 
 
        int nDisplayWidth = display.getWidth();
        int nDisplayHeight = display.getHeight();
 
        int nImageWidth = m_nImageWidth;
        int nImageHeight = m_nImageHeight;
        double nFitWidth;
        double nFitHeight;
        double nUseWidth = 0;
        double nUseHeight = 0;
        double dRealRegionWidth = 0;
//        double dRealRegionHeight = 0;
        if (nImageWidth * nDisplayHeight < nDisplayWidth * nImageHeight) {
            nFitHeight = nDisplayHeight;
            nFitWidth = (nImageWidth / (double) nImageHeight) * nFitHeight;
        } else {
            nFitWidth = nDisplayWidth;
            nFitHeight = nFitWidth * (nImageHeight / (double) nImageWidth);
        }
        if (nFitWidth / nFitHeight >= 4 / 3) {
            nUseHeight = nFitHeight;
            nUseWidth = 4 * nUseHeight / 3.0f;
        } else {
            nUseWidth = nFitWidth;
            nUseHeight = 3 * nUseWidth / 4.0f;
        }
        dRealRegionWidth = nUseWidth / 480.0f * 420.0f;
//        dRealRegionHeight = nUseHeight/360.0f*270.0f;
 
//        lineLeft = (int)((nDisplayWidth - dRealRegionWidth)/2.0f);//- (nDisplayWidth - nFitWidth)/2.0f);
//        lineRight = (int)( nDisplayWidth - lineLeft);//- (nDisplayWidth - nFitWidth) );
//        lineTop = (int)(nDisplayHeight - dRealRegionHeight)/2.0f;
//        lineBottom = nDisplayHeight - lineTop;
 
 
        paint = new Paint();
        dLineWidth = (int) dRealRegionWidth / 28; //30
        dLineWidth = 4;
        paint.setStrokeWidth(dLineWidth);
        dLen = (int) dRealRegionWidth / 6; //160
 
 
        float imgX = 10000;
        float imgY = 10000;
        switch (typeFront) {
            case 1:
                imgX = (mWidth - k / 2) + k * 0.56f;
                imgY = lineTop + g * 0.18f;
                break;
            case 2:
                imgX = lineLeft + k * 0.1f;
                imgY = lineTop + g * 0.1f;
                break;
 
            default:
                break;
        }
        float[] img = {imgY, imgX};
        return img;
    }
 
 
    public void initFinder(int w, int h, int d) {
    }
 
    public Rect getFinder() {
        return new Rect((int) (lineLeft - marginW), (int) (lineTop - marginH), (int) (lineRight + marginW), (int) (lineBottom + marginH));
    }
 
 
    public void setLineRect(int model) {
        lineModel = model;
        invalidate();
    }
 
 
    @Override
    public void draw(Canvas canvas) {
        // TODO Auto-generated method stub
        super.draw(canvas);
 
        paint.setColor(Color.GREEN);
 
 
        canvas.drawLine(lineLeft - dLineWidth / 2, lineTop, lineLeft + dLen, lineTop, paint);
        canvas.drawLine(lineLeft, lineTop - dLineWidth / 2, lineLeft, lineTop + dLen, paint);
 
        canvas.drawLine(lineRight, lineTop - dLineWidth / 2, lineRight, lineTop + dLen, paint);
        canvas.drawLine(lineRight + dLineWidth / 2, lineTop, lineRight - dLen, lineTop, paint);
 
        canvas.drawLine(lineLeft, lineBottom + dLineWidth / 2, lineLeft, lineBottom - dLen, paint);
        canvas.drawLine(lineLeft - dLineWidth / 2, lineBottom, lineLeft + dLen, lineBottom, paint);
 
        canvas.drawLine(lineRight + dLineWidth / 2, lineBottom, lineRight - dLen, lineBottom, paint);
        canvas.drawLine(lineRight, lineBottom + dLineWidth / 2, lineRight, lineBottom - dLen, paint);
 
        switch (lineModel) {
            case 0:
 
                break;
            case 1://左边框线
                canvas.drawLine(lineLeft, lineTop, lineLeft, lineBottom, paint);
                break;
            case 2://右边框线
                canvas.drawLine(lineRight, lineTop, lineRight, lineBottom, paint);
                break;
            case 3://左右
                canvas.drawLine(lineLeft, lineTop, lineLeft, lineBottom, paint);
                canvas.drawLine(lineRight, lineTop, lineRight, lineBottom, paint);
                break;
            case 4://上边框
                canvas.drawLine(lineLeft, lineTop, lineRight, lineTop, paint);
                break;
            case 5://左上
                canvas.drawLine(lineLeft, lineTop, lineLeft, lineBottom, paint);
                canvas.drawLine(lineLeft, lineTop, lineRight, lineTop, paint);
                break;
            case 6://右上
                canvas.drawLine(lineRight, lineTop, lineRight, lineBottom, paint);
                canvas.drawLine(lineLeft, lineTop, lineRight, lineTop, paint);
                break;
            case 7://左右上
                canvas.drawLine(lineLeft, lineTop, lineLeft, lineBottom, paint);
                canvas.drawLine(lineRight, lineTop, lineRight, lineBottom, paint);
                canvas.drawLine(lineLeft, lineTop, lineRight, lineTop, paint);
                break;
            case 8://下边框
                canvas.drawLine(lineLeft, lineBottom, lineRight, lineBottom, paint);
                break;
            case 9://左下
                canvas.drawLine(lineLeft, lineTop, lineLeft, lineBottom, paint);
                canvas.drawLine(lineLeft, lineBottom, lineRight, lineBottom, paint);
                break;
            case 10://右下边框
                canvas.drawLine(lineRight, lineTop, lineRight, lineBottom, paint);
                canvas.drawLine(lineLeft, lineBottom, lineRight, lineBottom, paint);
                break;
            case 11://左右下
                canvas.drawLine(lineLeft, lineTop, lineLeft, lineBottom, paint);
                canvas.drawLine(lineRight, lineTop, lineRight, lineBottom, paint);
                canvas.drawLine(lineLeft, lineBottom, lineRight, lineBottom, paint);
                break;
            case 12://上下
                canvas.drawLine(lineLeft, lineTop, lineRight, lineTop, paint);
                canvas.drawLine(lineLeft, lineBottom, lineRight, lineBottom, paint);
                break;
            case 13://上下左
                canvas.drawLine(lineLeft, lineTop, lineRight, lineTop, paint);
                canvas.drawLine(lineLeft, lineBottom, lineRight, lineBottom, paint);
                canvas.drawLine(lineLeft, lineTop, lineLeft, lineBottom, paint);
                break;
            case 14://上下右
                canvas.drawLine(lineLeft, lineTop, lineRight, lineTop, paint);
                canvas.drawLine(lineLeft, lineBottom, lineRight, lineBottom, paint);
                canvas.drawLine(lineRight, lineTop, lineRight, lineBottom, paint);
                break;
            case 15://全
                canvas.drawLine(lineLeft, lineTop, lineLeft, lineBottom, paint);
                canvas.drawLine(lineRight, lineTop, lineRight, lineBottom, paint);
                canvas.drawLine(lineLeft, lineTop, lineRight, lineTop, paint);
                canvas.drawLine(lineLeft, lineBottom, lineRight, lineBottom, paint);
                break;
 
            default:
 
                break;
        }
        paint.setColor(Color.BLACK);
        paint.setAlpha(100);
//        canvas.drawRect(lineLeft + dLineWidth / 2, lineTop + dLineWidth / 2, lineRight - dLineWidth / 2, lineBottom - dLineWidth / 2, paint);
 
        //画四周
        canvas.drawRect(0, 0, width, lineTop - dLineWidth / 2, paint);
 
        canvas.drawRect(0, lineTop - dLineWidth / 2, lineLeft - dLineWidth / 2, lineBottom + dLineWidth / 2, paint);
 
        canvas.drawRect(0, lineBottom + dLineWidth / 2, width, height, paint);
 
        canvas.drawRect(lineRight + dLineWidth / 2, lineTop - dLineWidth / 2, width, lineBottom + dLineWidth / 2, paint);
 
    }
 
 
}