左晓为主开发手持机充值管理机
zuoxiao
2024-08-09 9450bcb197c2de53982368d5c2059b31abed3b87
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
package com.kernal.passportreader.sdk.utils;
 
import android.content.Context;
import android.graphics.Point;
import android.os.Build;
import android.util.TypedValue;
import android.view.Display;
import android.view.WindowManager;
 
import com.kernal.passportreader.sdk.view.ViewfinderView;
 
 
public class CardScreenUtil {
    public static final int ORIENTATION_PORTRAIT = 0;
    public static final int ORIENTATION_LANDSCAPE = 1;
 
 
    public static final int getScreenOrientation(Context context) {
        Point screenResolution = getScreenResolution(context);
        return screenResolution.x > screenResolution.y ? ORIENTATION_LANDSCAPE : ORIENTATION_PORTRAIT;
    }
 
 
    public static int getPicOrientation(Context context){
        WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
        Display display = wm.getDefaultDisplay();
        int ScreenOrientation=display.getRotation();
        switch (ScreenOrientation){
            case 0:
                if(ViewfinderView.isSameScreen){
                    return 1;
                }else{
                    return 0;
                }
            case 1:
                return 0;
            case 2:
                if(ViewfinderView.isSameScreen){
                    return 3;
                }else{
                    return 2;
                }
            case 3:
                return 2;
 
        }
        return 0;
    }
 
    public static Point getScreenResolution(Context context) {
        WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
        Display display = wm.getDefaultDisplay();
        Point screenResolution = new Point();
        if (android.os.Build.VERSION.SDK_INT >= 13) {
            if(Build.VERSION.SDK_INT>=19){
                display.getRealSize(screenResolution);
            }else {
                display.getSize(screenResolution);
            }
 
        } else {
            screenResolution.set(display.getWidth(), display.getHeight());
        }
        return SpecialMobileAdaptation.instance.getScreenResolution(context, screenResolution);
    }
 
    public static int dp2px(Context context, float dpValue) {
        return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dpValue, context.getResources().getDisplayMetrics());
    }
 
    public static int sp2px(Context context, float spValue) {
        return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, spValue, context.getResources().getDisplayMetrics());
    }
 
 }