左晓为主开发手持机充值管理机
zuoxiao
2024-03-26 878049b939a839da6d713d43d435a2f6b93a410a
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
package com.kernal.passportreader.sdk.utils;
 
import android.content.Context;
import android.content.res.Configuration;
import android.graphics.Point;
import android.os.Build;
 
import java.util.HashMap;
 
/**
 * 用于特殊机型预览图像与正常图像不一致和获取屏幕宽高不变化的情况
 */
public class SpecialMobileAdaptation {
    private HashMap<String, SpecialMobile> specialMobileHashMap = new HashMap<>();
    public static SpecialMobileAdaptation instance = new SpecialMobileAdaptation();
 
    private SpecialMobileAdaptation() {
        /**
         * vivo X50 pro
         */
        specialMobileHashMap.put("vivo-V2005A", new SpecialMobile(0, 90));
    }
 
    /**
     * 返回特殊机型对应的旋转角度
     *
     * @param
     * @return
     */
    public int getOrientation(Context context) {
        String deviceName = getDeviceName();
        int orientation = -1;
        if (specialMobileHashMap.containsKey(deviceName)) {
            orientation = context.getResources().getConfiguration().orientation; //获取设置的配置信息;
            orientation = orientation == Configuration.ORIENTATION_LANDSCAPE ? specialMobileHashMap.get(deviceName).RotationAngle_LANDSCAPE
                    : specialMobileHashMap.get(deviceName).RotationAngle_PORTRAIT;
        }
        return orientation;
    }
 
    /**
     * 是否为特殊机型
     *
     * @return
     */
    public boolean isSpecialModel() {
        String deviceName = getDeviceName();
        return specialMobileHashMap.containsKey(deviceName);
    }
 
    private String getDeviceName() {
        return Build.BRAND + "-" + Build.MODEL;
    }
 
    /**
     * @param context
     * @param screenResolution
     * @return
     */
    public Point getScreenResolution(Context context, Point screenResolution) {
        /**
         * 如果没有命中特殊机型直接返回传入的参数值
         */
        if (!isSpecialModel()) return screenResolution;
        Configuration mConfiguration = context.getResources().getConfiguration(); //获取设置的配置信息
        Point point = new Point();
        /**
         *获取屏幕方向
         */
        switch (mConfiguration.orientation) {
            case Configuration.ORIENTATION_LANDSCAPE:
                point.x = Math.max(screenResolution.x, screenResolution.y);
                point.y = Math.min(screenResolution.x, screenResolution.y);
                break;
            case Configuration.ORIENTATION_PORTRAIT:
                point.x = Math.min(screenResolution.x, screenResolution.y);
                point.y = Math.max(screenResolution.x, screenResolution.y);
                break;
            default:
                break;
        }
        return point;
    }
 
    /**
     * 特殊机型(厂商-型号)
     */
    class SpecialMobile {
        /**
         * 强制横屏情况下相机应该设置的正确预览角度
         * 强制竖屏情况下相机应该设置的正确预览角度
         */
        private int RotationAngle_LANDSCAPE, RotationAngle_PORTRAIT;
 
        public SpecialMobile(int RotationAngle_LANDSCAPE, int RotationAngle_PORTRAIT) {
            this.RotationAngle_LANDSCAPE = RotationAngle_LANDSCAPE;
            this.RotationAngle_PORTRAIT = RotationAngle_PORTRAIT;
        }
    }
}